├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── gx │ │ └── learn │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── gx │ │ │ └── learn │ │ │ ├── adapter │ │ │ ├── BlogViewHolder.java │ │ │ ├── Blogadapter.java │ │ │ ├── MeiziViewHolder.java │ │ │ ├── Meiziadapter.java │ │ │ ├── MyFragmentPagerAdapter.java │ │ │ ├── ZhihuViewHolder.java │ │ │ └── Zhihuadapter.java │ │ │ ├── model │ │ │ ├── Android.java │ │ │ ├── Blog.java │ │ │ ├── Gril.java │ │ │ ├── Meizi.java │ │ │ ├── Zhihu.java │ │ │ ├── Zhihunews.java │ │ │ └── Zhiitem.java │ │ │ ├── net │ │ │ ├── GetData.java │ │ │ ├── Network.java │ │ │ └── api │ │ │ │ ├── BlogApi.java │ │ │ │ ├── GankApi.java │ │ │ │ └── ZhihuApi.java │ │ │ ├── util │ │ │ ├── ClipboardUtils.java │ │ │ └── ImgSaveUtil.java │ │ │ └── view │ │ │ ├── CircularAnim.java │ │ │ ├── TouchImageView.java │ │ │ ├── activity │ │ │ ├── AboutActivity.java │ │ │ ├── BaseActivity.java │ │ │ ├── FirstActivity.java │ │ │ ├── ImageActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── WebActivity.java │ │ │ ├── ZhihuActivity.java │ │ │ └── ZhihunewsActivity.java │ │ │ └── fragment │ │ │ ├── BaseFragment.java │ │ │ ├── BlogFragment.java │ │ │ └── MeiziFragment.java │ └── res │ │ ├── anim │ │ ├── slide_in_right.xml │ │ └── slide_out_left.xml │ │ ├── drawable-v21 │ │ ├── ic_menu_camera.xml │ │ ├── ic_menu_gallery.xml │ │ ├── ic_menu_manage.xml │ │ ├── ic_menu_send.xml │ │ ├── ic_menu_share.xml │ │ └── ic_menu_slideshow.xml │ │ ├── drawable │ │ ├── about_icon.png │ │ ├── about_img.jpg │ │ ├── copy.png │ │ ├── firstonegril.jpg │ │ ├── header.jpg │ │ ├── logo_one.jpg │ │ ├── save.png │ │ ├── share.png │ │ ├── side_nav_bar.xml │ │ └── zhihu_icon.png │ │ ├── layout │ │ ├── activity_about.xml │ │ ├── activity_image.xml │ │ ├── activity_main.xml │ │ ├── activity_web.xml │ │ ├── activity_zhihu.xml │ │ ├── activity_zhihunews.xml │ │ ├── androidblog_item.xml │ │ ├── app_bar_main.xml │ │ ├── content_about.xml │ │ ├── fragment_blog.xml │ │ ├── fragment_meizi.xml │ │ ├── girl_item.xml │ │ ├── nav_header_main.xml │ │ ├── view_more.xml │ │ ├── zhihu_item.xml │ │ └── zhihuheader.xml │ │ ├── menu │ │ ├── activity_main_drawer.xml │ │ ├── main.xml │ │ ├── main_meizi.xml │ │ ├── main_web.xml │ │ └── menu_about.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── drawables.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── gx │ └── learn │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── readme1.jpg ├── readme2.jpg └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Learn 2 | ### 项目简介
3 | version:1.0

4 | 该项目包含 mvc + retrofit2.1.0 + rxJava1.1.6 + okhttp3.2.0 + photoview + cardview + glide ... ...

5 | 后期可能会更新到 MVP 模式

6 | ![](https://github.com/developergx/LearnProject/blob/master/readme1.jpg) 7 |    ![](https://github.com/developergx/LearnProject/blob/master/readme2.jpg)

8 | ### 声明
9 | 妹子图和 Android 博客的 API 来自于 [gank.io](http://gank.io/) 感谢干货集中营!
10 | 感谢 [阿里巴巴矢量图标库](http://www.iconfont.cn/plus/collections/index?type=3&spm=a313x.7781069.1998910419.6.PBPGns) 提供素材! 11 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 24 5 | buildToolsVersion "24.0.2" 6 | defaultConfig { 7 | applicationId "com.gx.learn" 8 | minSdkVersion 21 9 | targetSdkVersion 24 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:24.2.1' 28 | 29 | compile 'com.android.support:support-v4:24.2.1' 30 | 31 | compile 'com.android.support:design:24.2.1' 32 | /** 33 | * cardview 34 | * http://blog.csdn.net/jdsjlzx/article/details/49511215 35 | * CardView Android 5.0 新特性,属于Support v7 里面的新的 Widget, 扩展于FrameLayout, 36 | * UI显示主要包括 37 | * 1.边框圆角 38 | * 2.有阴影Shadow 39 | * 用来突出个性,比如展览,相册等。 40 | */ 41 | compile'com.android.support:cardview-v7:24.0.0' 42 | 43 | /** easyrecyclerview http://blog.csdn.net/qq_16430735/article/details/49341563#easyrecyclerview 44 | * 将开发中常用的RecyclerView的各种需求封装进库。提升开发效率。 45 | * 重点在Adapter与viewholder的封装。他们之间彻底解耦。 46 | * adapter工作更少,仅负责业务逻辑。所以如果你使用mvp架构可以放进presenter层。 47 | * viewholder负责View展示与Adapter没有任何耦合,将可以到处复用。并不会影响运行效率。 48 | * 并且adapter支持数据管理,Header与Footer添加、加载更多、没有更多、加载错误 49 | */ 50 | compile 'com.jude:easyrecyclerview:4.2.3' 51 | 52 | /** 53 | * glide 54 | * http://blog.csdn.net/shangmingchao/article/details/51125554/ 55 | */ 56 | compile 'com.github.bumptech.glide:glide:3.7.0' 57 | 58 | /** rollviewpager http://www.2cto.com/kf/201605/506583.html 59 | * 支持无限循环。 60 | * 触摸时会暂停播放,直到结束触摸一个延迟周期以后继续播放。 61 | * 指示器可以为点可以为数字还可以自定义,位置也可以变。 62 | */ 63 | compile 'com.jude:rollviewpager:1.4.5' 64 | 65 | /** photoview http://blog.csdn.net/zhaihaohao1/article/details/50673071 66 | * 这是一个图片查看库,实现图片浏览功能,支持pinch(捏合)手势或者点击放大缩小。 67 | * 支持在ViewPager中翻页浏览图片。 68 | * PhotoView 是一款扩展自 ImageView 的控件,支持通过单点/多点触摸来进行图片缩放的智能控件。功能实用和强大。 69 | */ 70 | compile 'com.bm.photoview:library:1.4.1' 71 | 72 | testCompile 'junit:junit:4.12' 73 | 74 | compile 'com.squareup.picasso:picasso:2.3.2' 75 | compile 'com.google.code.gson:gson:2.4' 76 | 77 | compile 'io.reactivex:rxjava:1.1.6' 78 | compile 'io.reactivex:rxandroid:1.2.1' 79 | compile 'com.squareup.retrofit2:retrofit:2.1.0' 80 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' 81 | compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' 82 | compile 'com.squareup.okhttp3:okhttp:3.2.0' 83 | 84 | } 85 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in E:\androidstudio\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/gx/learn/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.gx.learn", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 17 | 21 | 22 | 23 | 27 | 31 | 35 | 39 | 43 | 44 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/adapter/BlogViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.adapter; 2 | 3 | import android.view.ViewGroup; 4 | import android.widget.TextView; 5 | 6 | import com.gx.learn.R; 7 | import com.gx.learn.model.Android; 8 | import com.jude.easyrecyclerview.adapter.BaseViewHolder; 9 | 10 | 11 | /** 12 | * Created by gx on 16/11/3. 13 | */ 14 | 15 | public class BlogViewHolder extends BaseViewHolder { 16 | private TextView textView; 17 | private TextView textView2; 18 | public BlogViewHolder(ViewGroup parent) { 19 | super(parent, R.layout.androidblog_item); 20 | textView = $(R.id.androidblog_title); 21 | textView2 = $(R.id.androidblog_who); 22 | } 23 | @Override 24 | public void setData(Android data) { 25 | super.setData(data); 26 | //Log.e("GirlViewHolder",data.imageUrl); 27 | textView.setText(data.desc); 28 | textView2.setText(data.who); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/adapter/Blogadapter.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | 6 | import com.gx.learn.model.Android; 7 | import com.jude.easyrecyclerview.adapter.BaseViewHolder; 8 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter; 9 | 10 | /** 11 | * Created by gx on 16/11/3. 12 | */ 13 | 14 | public class Blogadapter extends RecyclerArrayAdapter { 15 | public Blogadapter(Context context) { 16 | super(context); 17 | } 18 | 19 | @Override 20 | public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { 21 | return new BlogViewHolder(parent); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/adapter/MeiziViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.adapter; 2 | 3 | import android.view.ViewGroup; 4 | import android.widget.ImageView; 5 | 6 | import com.bumptech.glide.Glide; 7 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 8 | import com.gx.learn.R; 9 | import com.gx.learn.model.Gril; 10 | import com.jude.easyrecyclerview.adapter.BaseViewHolder; 11 | 12 | /** 13 | * Created by gx on 16/11/2. 14 | */ 15 | 16 | public class MeiziViewHolder extends BaseViewHolder { 17 | private ImageView image; 18 | public MeiziViewHolder(ViewGroup parent) { 19 | super(parent, R.layout.girl_item); 20 | image = $(R.id.image); 21 | } 22 | @Override 23 | public void setData(Gril data) { 24 | super.setData(data); 25 | //Log.e("GirlViewHolder",data.imageUrl); 26 | Glide.with(getContext()) 27 | .load(data.Url) 28 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 29 | .into(image); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/adapter/Meiziadapter.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | 6 | import com.gx.learn.model.Gril; 7 | import com.jude.easyrecyclerview.adapter.BaseViewHolder; 8 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter; 9 | 10 | /** 11 | * Created by gx on 16/11/2. 12 | */ 13 | 14 | public class Meiziadapter extends RecyclerArrayAdapter { 15 | 16 | public Meiziadapter(Context context) { 17 | super(context); 18 | } 19 | 20 | @Override 21 | public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { 22 | return new MeiziViewHolder(parent); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/adapter/MyFragmentPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentPagerAdapter; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by gx on 16/11/2. 11 | */ 12 | 13 | public class MyFragmentPagerAdapter extends FragmentPagerAdapter { 14 | public MyFragmentPagerAdapter(FragmentManager fm, List fragmentList, List titles) { 15 | super(fm); 16 | this.fragmentList = fragmentList; 17 | this.titles = titles; 18 | } 19 | 20 | private ListfragmentList; 21 | private List titles; 22 | 23 | 24 | 25 | 26 | 27 | @Override 28 | public Fragment getItem(int position) { 29 | return fragmentList.get(position); 30 | } 31 | 32 | @Override 33 | public int getCount() { 34 | return titles.size(); 35 | } 36 | @Override 37 | public CharSequence getPageTitle(int position) { 38 | return titles.get(position); 39 | } 40 | } -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/adapter/ZhihuViewHolder.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.adapter; 2 | 3 | import android.view.ViewGroup; 4 | import android.widget.ImageView; 5 | import android.widget.TextView; 6 | 7 | import com.bumptech.glide.Glide; 8 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 9 | import com.gx.learn.R; 10 | import com.gx.learn.model.Zhiitem; 11 | import com.jude.easyrecyclerview.adapter.BaseViewHolder; 12 | 13 | /** 14 | * Created by gx on 16/11/5. 15 | */ 16 | 17 | public class ZhihuViewHolder extends BaseViewHolder { 18 | private ImageView imageView; 19 | private TextView textView; 20 | public ZhihuViewHolder(ViewGroup parent) { 21 | super(parent, R.layout.zhihu_item); 22 | imageView = $(R.id.zhihu_image); 23 | textView = $(R.id.zhihu_title); 24 | } 25 | 26 | @Override 27 | public void setData(Zhiitem data) { 28 | super.setData(data); 29 | Glide.with(getContext()) 30 | .load(data.images) 31 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 32 | .into(imageView); 33 | textView.setText(data.title); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/adapter/Zhihuadapter.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.ViewGroup; 5 | 6 | import com.gx.learn.model.Zhiitem; 7 | import com.jude.easyrecyclerview.adapter.BaseViewHolder; 8 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter; 9 | 10 | /** 11 | * Created by gx on 16/11/5. 12 | */ 13 | 14 | public class Zhihuadapter extends RecyclerArrayAdapter { 15 | public Zhihuadapter(Context context) { 16 | super(context); 17 | } 18 | 19 | @Override 20 | public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { 21 | return new ZhihuViewHolder(parent); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/model/Android.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.model; 2 | 3 | /** 4 | * Created by gx on 16/11/3. 5 | */ 6 | 7 | public class Android { 8 | public String desc; 9 | public String url; 10 | public String who; 11 | } 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/model/Blog.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by gx on 16/11/3. 7 | */ 8 | 9 | public class Blog { 10 | private boolean error; 11 | private List results ; 12 | 13 | public boolean isError() { 14 | return error; 15 | } 16 | 17 | public void setError(boolean error) { 18 | this.error = error; 19 | } 20 | 21 | public List getResult() { 22 | return results; 23 | } 24 | 25 | public void setResult(List result) { 26 | this.results = result; 27 | } 28 | 29 | 30 | public class Result { 31 | private String _id; 32 | 33 | private String createdAt; 34 | 35 | private String desc; 36 | 37 | private List images; 38 | 39 | private String publishedAt; 40 | 41 | private String source; 42 | 43 | private String type; 44 | 45 | private String url; 46 | 47 | private boolean used; 48 | 49 | private String who; 50 | 51 | public void set_id(String _id) { 52 | this._id = _id; 53 | } 54 | 55 | public String get_id() { 56 | return this._id; 57 | } 58 | 59 | public void setCreatedAt(String createdAt) { 60 | this.createdAt = createdAt; 61 | } 62 | 63 | public String getCreatedAt() { 64 | return this.createdAt; 65 | } 66 | 67 | public void setDesc(String desc) { 68 | this.desc = desc; 69 | } 70 | 71 | public String getDesc() { 72 | return this.desc; 73 | } 74 | 75 | public void setString(List images) { 76 | this.images = images; 77 | } 78 | 79 | public List getString() { 80 | return this.images; 81 | } 82 | 83 | public void setPublishedAt(String publishedAt) { 84 | this.publishedAt = publishedAt; 85 | } 86 | 87 | public String getPublishedAt() { 88 | return this.publishedAt; 89 | } 90 | 91 | public void setSource(String source) { 92 | this.source = source; 93 | } 94 | 95 | public String getSource() { 96 | return this.source; 97 | } 98 | 99 | public void setType(String type) { 100 | this.type = type; 101 | } 102 | 103 | public String getType() { 104 | return this.type; 105 | } 106 | 107 | public void setUrl(String url) { 108 | this.url = url; 109 | } 110 | 111 | public String getUrl() { 112 | return this.url; 113 | } 114 | 115 | public void setUsed(boolean used) { 116 | this.used = used; 117 | } 118 | 119 | public boolean getUsed() { 120 | return this.used; 121 | } 122 | 123 | public void setWho(String who) { 124 | this.who = who; 125 | } 126 | 127 | public String getWho() { 128 | return this.who; 129 | } 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/model/Gril.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.model; 2 | 3 | /** 4 | * Created by gx on 16/11/2. 5 | */ 6 | 7 | public class Gril { 8 | public String descr; 9 | public String Url; 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/model/Meizi.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by gx on 16/11/2. 7 | */ 8 | 9 | public class Meizi { 10 | private boolean error; 11 | 12 | private List results ; 13 | 14 | public void setError(boolean error){ 15 | this.error = error; 16 | } 17 | public boolean getError(){ 18 | return this.error; 19 | } 20 | public void setResults(List results){ 21 | this.results = results; 22 | } 23 | public List getResults(){ 24 | return this.results; 25 | } 26 | 27 | 28 | public class Results { 29 | private String _id; 30 | 31 | private String createdAt; 32 | 33 | private String desc; 34 | 35 | private String publishedAt; 36 | 37 | private String source; 38 | 39 | private String type; 40 | 41 | private String url; 42 | 43 | private boolean used; 44 | 45 | private String who; 46 | 47 | public void set_id(String _id){ 48 | this._id = _id; 49 | } 50 | public String get_id(){ 51 | return this._id; 52 | } 53 | public void setCreatedAt(String createdAt){ 54 | this.createdAt = createdAt; 55 | } 56 | public String getCreatedAt(){ 57 | return this.createdAt; 58 | } 59 | public void setDesc(String desc){ 60 | this.desc = desc; 61 | } 62 | public String getDesc(){ 63 | return this.desc; 64 | } 65 | public void setPublishedAt(String publishedAt){ 66 | this.publishedAt = publishedAt; 67 | } 68 | public String getPublishedAt(){ 69 | return this.publishedAt; 70 | } 71 | public void setSource(String source){ 72 | this.source = source; 73 | } 74 | public String getSource(){ 75 | return this.source; 76 | } 77 | public void setType(String type){ 78 | this.type = type; 79 | } 80 | public String getType(){ 81 | return this.type; 82 | } 83 | public void setUrl(String url){ 84 | this.url = url; 85 | } 86 | public String getUrl(){ 87 | return this.url; 88 | } 89 | public void setUsed(boolean used){ 90 | this.used = used; 91 | } 92 | public boolean getUsed(){ 93 | return this.used; 94 | } 95 | public void setWho(String who){ 96 | this.who = who; 97 | } 98 | public String getWho(){ 99 | return this.who; 100 | } 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/model/Zhihu.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.model; 2 | 3 | /** 4 | * Created by gx on 16/10/14. 5 | */ 6 | 7 | import java.util.List; 8 | 9 | public class Zhihu { 10 | private String date; 11 | 12 | private List stories ; 13 | 14 | private List top_stories ; 15 | 16 | public void setDate(String date){ 17 | this.date = date; 18 | } 19 | public String getDate(){ 20 | return this.date; 21 | } 22 | public void setStories(List stories){ 23 | this.stories = stories; 24 | } 25 | public List getStories(){ 26 | return this.stories; 27 | } 28 | public void setTop_stories(List top_stories){ 29 | this.top_stories = top_stories; 30 | } 31 | public List getTop_stories(){ 32 | return this.top_stories; 33 | } 34 | public class Top_stories { 35 | private String image; 36 | 37 | private int type; 38 | 39 | private int id; 40 | 41 | private String ga_prefix; 42 | 43 | private String title; 44 | 45 | public void setImage(String image){ 46 | this.image = image; 47 | } 48 | public String getImage(){ 49 | return this.image; 50 | } 51 | public void setType(int type){ 52 | this.type = type; 53 | } 54 | public int getType(){ 55 | return this.type; 56 | } 57 | public void setId(int id){ 58 | this.id = id; 59 | } 60 | public int getId(){ 61 | return this.id; 62 | } 63 | public void setGa_prefix(String ga_prefix){ 64 | this.ga_prefix = ga_prefix; 65 | } 66 | public String getGa_prefix(){ 67 | return this.ga_prefix; 68 | } 69 | public void setTitle(String title){ 70 | this.title = title; 71 | } 72 | public String getTitle(){ 73 | return this.title; 74 | } 75 | 76 | } 77 | public class Stories { 78 | private List images; 79 | 80 | private int type; 81 | 82 | private int id; 83 | 84 | private String ga_prefix; 85 | 86 | private String title; 87 | 88 | public void setString(List images) { 89 | this.images = images; 90 | } 91 | 92 | public List getString() { 93 | return this.images; 94 | } 95 | 96 | public void setType(int type) { 97 | this.type = type; 98 | } 99 | 100 | public int getType() { 101 | return this.type; 102 | } 103 | 104 | public void setId(int id) { 105 | this.id = id; 106 | } 107 | 108 | public int getId() { 109 | return this.id; 110 | } 111 | 112 | public void setGa_prefix(String ga_prefix) { 113 | this.ga_prefix = ga_prefix; 114 | } 115 | 116 | public String getGa_prefix() { 117 | return this.ga_prefix; 118 | } 119 | 120 | public void setTitle(String title) { 121 | this.title = title; 122 | } 123 | 124 | public String getTitle() { 125 | return this.title; 126 | } 127 | 128 | 129 | } 130 | 131 | } -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/model/Zhihunews.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.model; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by gx on 16/10/16. 7 | */ 8 | 9 | public class Zhihunews { 10 | private String body; 11 | 12 | private String image_source; 13 | 14 | private String title; 15 | 16 | private String image; 17 | 18 | private String share_url; 19 | 20 | private List js ; 21 | 22 | private String ga_prefix; 23 | 24 | 25 | 26 | private List images ; 27 | 28 | private int type; 29 | 30 | private int id; 31 | 32 | private List css ; 33 | 34 | public String getBody() { 35 | return body; 36 | } 37 | 38 | public void setBody(String body) { 39 | this.body = body; 40 | } 41 | public void setImage_source(String image_source){ 42 | this.image_source = image_source; 43 | } 44 | public String getImage_source(){ 45 | return this.image_source; 46 | } 47 | public void setTitle(String title){ 48 | this.title = title; 49 | } 50 | public String getTitle(){ 51 | return this.title; 52 | } 53 | public void setImage(String image){ 54 | this.image = image; 55 | } 56 | public String getImage(){ 57 | return this.image; 58 | } 59 | public void setShare_url(String share_url){ 60 | this.share_url = share_url; 61 | } 62 | public String getShare_url(){ 63 | return this.share_url; 64 | } 65 | public void setJs(List js){ 66 | this.js = js; 67 | } 68 | public List getJs(){ 69 | return this.js; 70 | } 71 | public void setGa_prefix(String ga_prefix){ 72 | this.ga_prefix = ga_prefix; 73 | } 74 | public String getGa_prefix(){ 75 | return this.ga_prefix; 76 | } 77 | 78 | 79 | public void setImages(List images){ 80 | this.images = images; 81 | } 82 | public List getImages(){ 83 | return this.images; 84 | } 85 | public void setType(int type){ 86 | this.type = type; 87 | } 88 | public int getType(){ 89 | return this.type; 90 | } 91 | public void setId(int id){ 92 | this.id = id; 93 | } 94 | public int getId(){ 95 | return this.id; 96 | } 97 | public void setcss(List css){ 98 | this.css = css; 99 | } 100 | public List getcss(){ 101 | return this.css; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/model/Zhiitem.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.model; 2 | 3 | /** 4 | * Created by gx on 16/11/5. 5 | */ 6 | 7 | public class Zhiitem { 8 | public int id; 9 | public String title; 10 | public String images; 11 | public String data; 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/net/GetData.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.net; 2 | 3 | import android.util.Log; 4 | 5 | import com.gx.learn.model.Android; 6 | import com.gx.learn.model.Blog; 7 | import com.gx.learn.model.Gril; 8 | import com.gx.learn.model.Meizi; 9 | import com.gx.learn.model.Zhihu; 10 | import com.gx.learn.model.Zhihunews; 11 | 12 | import java.util.ArrayList; 13 | import java.util.List; 14 | 15 | import rx.Subscriber; 16 | import rx.android.schedulers.AndroidSchedulers; 17 | import rx.functions.Func1; 18 | import rx.schedulers.Schedulers; 19 | 20 | /** 21 | * Created by gx on 16/11/2. 22 | */ 23 | 24 | public class GetData { 25 | private static final String TAG = "GetData"; 26 | 27 | private GetData(){ 28 | 29 | } 30 | 31 | public static GetData getInstance(){ 32 | return SingletonHolder.INSTANCE; 33 | } 34 | 35 | private static class SingletonHolder{ 36 | private static final GetData INSTANCE = new GetData(); 37 | } 38 | 39 | public void getmeizidata(Subscriber> subscriber ,final int page){ 40 | Log.e(TAG,page + ""); 41 | Network.getGankApi() 42 | .getmeizi(page) 43 | .subscribeOn(Schedulers.io()) 44 | .map(new Func1>() { 45 | @Override 46 | public List call(Meizi meizi) { 47 | List results = meizi.getResults(); 48 | List grils = new ArrayList<>(); 49 | for (Meizi.Results result : results) { 50 | Gril gril = new Gril(); 51 | gril.descr = result.getDesc(); 52 | gril.Url = result.getUrl(); 53 | grils.add(gril); 54 | } 55 | return grils; 56 | } 57 | }) 58 | .observeOn(AndroidSchedulers.mainThread()) 59 | .subscribe(subscriber); 60 | 61 | } 62 | 63 | public void getblogdata(Subscriber> subscriber2 , final int page){ 64 | Log.e(TAG,page + ""); 65 | Network.getBlogApi() 66 | .getblog(page) 67 | .subscribeOn(Schedulers.io()) 68 | .map(new Func1>() { 69 | @Override 70 | public List call(Blog blog) { 71 | List results = blog.getResult(); 72 | List androids = new ArrayList<>(); 73 | for (Blog.Result result : results) { 74 | Android android = new Android(); 75 | android.desc = result.getDesc(); 76 | android.url = result.getUrl(); 77 | android.who = result.getWho(); 78 | androids.add(android); 79 | } 80 | return androids; 81 | } 82 | }) 83 | .observeOn(AndroidSchedulers.mainThread()) 84 | .subscribe(subscriber2); 85 | 86 | } 87 | 88 | public void getzhihudatafirst(Subscriber subscriber , final String latest){ 89 | // Log.e(TAG,page + ""); 90 | Network.getZhihuApi() 91 | .getzhihufirst(latest) 92 | .subscribeOn(Schedulers.io()) 93 | .observeOn(AndroidSchedulers.mainThread()) 94 | .subscribe(subscriber); 95 | 96 | } 97 | 98 | 99 | public void getzhihudata(Subscriber subscriber , final String data){ 100 | // Log.e(TAG,page + ""); 101 | Network.getZhihuApi() 102 | .getzhihu(data) 103 | .subscribeOn(Schedulers.io()) 104 | .observeOn(AndroidSchedulers.mainThread()) 105 | .subscribe(subscriber); 106 | 107 | } 108 | 109 | public void getzhihudnews(Subscriber subscriber , final int data){ 110 | // Log.e(TAG,page + ""); 111 | Network.getZhihuApi() 112 | .getzhihunews(data) 113 | .subscribeOn(Schedulers.io()) 114 | .observeOn(AndroidSchedulers.mainThread()) 115 | .subscribe(subscriber); 116 | 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/net/Network.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.net; 2 | 3 | import com.gx.learn.net.api.BlogApi; 4 | import com.gx.learn.net.api.GankApi; 5 | import com.gx.learn.net.api.ZhihuApi; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | import okhttp3.OkHttpClient; 10 | import retrofit2.Retrofit; 11 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory; 12 | import retrofit2.converter.gson.GsonConverterFactory; 13 | 14 | /** 15 | * Created by gx on 16/11/2. 16 | */ 17 | 18 | public class Network { 19 | private static GankApi gankApi; 20 | private static BlogApi blogApi; 21 | private static ZhihuApi zhihuApi; 22 | private static OkHttpClient okHttpClient; 23 | 24 | public static OkHttpClient initOkHttp(){ 25 | okHttpClient = new OkHttpClient.Builder() 26 | .retryOnConnectionFailure(true) 27 | .connectTimeout(15, TimeUnit.SECONDS) 28 | .build(); 29 | return okHttpClient; 30 | } 31 | 32 | public static GankApi getGankApi() { 33 | if (gankApi == null) { 34 | Retrofit retrofit = new Retrofit.Builder() 35 | .client(initOkHttp()) 36 | .baseUrl(GankApi.GANK_API) 37 | .addConverterFactory(GsonConverterFactory.create()) 38 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 39 | .build(); 40 | gankApi = retrofit.create(GankApi.class); 41 | } 42 | return gankApi; 43 | } 44 | 45 | 46 | public static BlogApi getBlogApi() { 47 | if (blogApi == null) { 48 | Retrofit retrofit = new Retrofit.Builder() 49 | .client(initOkHttp()) 50 | .baseUrl(BlogApi.GANK_API) 51 | .addConverterFactory(GsonConverterFactory.create()) 52 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 53 | .build(); 54 | blogApi = retrofit.create(BlogApi.class); 55 | } 56 | return blogApi; 57 | } 58 | public static ZhihuApi getZhihuApi() { 59 | if (zhihuApi == null) { 60 | Retrofit retrofit = new Retrofit.Builder() 61 | .client(initOkHttp()) 62 | .baseUrl(ZhihuApi.ZHIHU_API) 63 | .addConverterFactory(GsonConverterFactory.create()) 64 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) 65 | .build(); 66 | zhihuApi = retrofit.create(ZhihuApi.class); 67 | } 68 | return zhihuApi; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/net/api/BlogApi.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.net.api; 2 | 3 | 4 | import com.gx.learn.model.Blog; 5 | 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Path; 8 | import rx.Observable; 9 | 10 | /** 11 | * Created by gx on 16/11/3. 12 | */ 13 | 14 | public interface BlogApi { 15 | String GANK_API = "http://gank.io/api/"; 16 | @GET("data/Android/10/{page}") 17 | Observable getblog(@Path("page") int page); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/net/api/GankApi.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.net.api; 2 | 3 | 4 | import com.gx.learn.model.Meizi; 5 | 6 | import retrofit2.http.GET; 7 | import retrofit2.http.Path; 8 | import rx.Observable; 9 | 10 | /** 11 | * Created by gx on 16/11/2. 12 | */ 13 | 14 | public interface GankApi { 15 | String GANK_API = "http://gank.io/api/"; 16 | @GET("data/福利/10/{page}") 17 | Observable getmeizi(@Path("page") int page); 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/net/api/ZhihuApi.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.net.api; 2 | 3 | 4 | import com.gx.learn.model.Zhihu; 5 | import com.gx.learn.model.Zhihunews; 6 | 7 | import retrofit2.http.GET; 8 | import retrofit2.http.Path; 9 | import rx.Observable; 10 | 11 | /** 12 | * Created by gx on 16/11/4. 13 | */ 14 | 15 | public interface ZhihuApi { 16 | String ZHIHU_API = "http://news-at.zhihu.com/api/"; 17 | @GET("4/news/{latest}") 18 | Observablegetzhihufirst(@Path("latest") String latest); 19 | 20 | @GET("4/news/before/{data}") 21 | Observablegetzhihu(@Path("data") String data); 22 | 23 | @GET("4/news/{data}") 24 | Observablegetzhihunews(@Path("data") int data); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/util/ClipboardUtils.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.util; 2 | 3 | import android.content.ClipData; 4 | import android.content.ClipboardManager; 5 | import android.content.Context; 6 | import android.os.Build; 7 | 8 | /** 9 | * 复制链接工具类 10 | */ 11 | public class ClipboardUtils 12 | { 13 | 14 | private static ClipboardManager mClipboardManager; 15 | 16 | private static ClipboardManager mNewCliboardManager; 17 | 18 | 19 | private static boolean isNew() 20 | { 21 | 22 | return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; 23 | } 24 | 25 | private static void instance(Context context) 26 | { 27 | 28 | if (isNew()) 29 | { 30 | if (mNewCliboardManager == null) 31 | mNewCliboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 32 | } else 33 | { 34 | if (mClipboardManager == null) 35 | mClipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 36 | } 37 | } 38 | 39 | /** 40 | * 为剪切板设置内容 41 | * 42 | * @param context 43 | * @param text 44 | */ 45 | public static void setText(Context context, CharSequence text) 46 | { 47 | 48 | if (isNew()) 49 | { 50 | instance(context); 51 | // Creates a new text clip to put on the clipboard 52 | ClipData clip = ClipData.newPlainText("simple text", text); 53 | 54 | // Set the clipboard's primary clip. 55 | mNewCliboardManager.setPrimaryClip(clip); 56 | } else 57 | { 58 | instance(context); 59 | mClipboardManager.setText(text); 60 | } 61 | } 62 | 63 | /** 64 | * 获取剪切板的内容 65 | * 66 | * @param context 67 | * @return 68 | */ 69 | public static CharSequence getText(Context context) 70 | { 71 | 72 | StringBuilder sb = new StringBuilder(); 73 | if (isNew()) 74 | { 75 | instance(context); 76 | if (!mNewCliboardManager.hasPrimaryClip()) 77 | { 78 | return sb.toString(); 79 | } else 80 | { 81 | ClipData clipData = (mNewCliboardManager).getPrimaryClip(); 82 | int count = clipData.getItemCount(); 83 | 84 | for (int i = 0; i < count; ++i) 85 | { 86 | 87 | ClipData.Item item = clipData.getItemAt(i); 88 | CharSequence str = item.coerceToText(context); 89 | sb.append(str); 90 | } 91 | } 92 | } else 93 | { 94 | instance(context); 95 | sb.append(mClipboardManager.getText()); 96 | } 97 | return sb.toString(); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/util/ImgSaveUtil.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.util; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.net.Uri; 7 | import android.os.Environment; 8 | import android.widget.ImageView; 9 | 10 | import java.io.File; 11 | import java.io.FileNotFoundException; 12 | import java.io.FileOutputStream; 13 | import java.io.IOException; 14 | 15 | /** 16 | * Created by gx on 2016/6/19. 17 | * 18 | * Here reference is https://github.com/gaolonglong/GankGirl/blob/master/app/src/main/java/com/app/gaolonglong/gankgirl/util/ImageUtil.java 19 | */ 20 | public class ImgSaveUtil { 21 | 22 | public static Uri saveImage(Context context, String url, Bitmap bitmap, ImageView imageView, String tag){ 23 | //妹纸保存路径 24 | String imgDir = Environment.getExternalStorageDirectory().getPath() + "/OnegrilOneblog"; 25 | //图片名称处理 26 | String[] fileNameArr = url.substring(url.lastIndexOf("/") + 1).split("\\."); 27 | String fileName = fileNameArr[0] + ".png"; 28 | //创建文件路径 29 | File fileDir = new File(imgDir); 30 | if (!fileDir.exists()){ 31 | fileDir.mkdir(); 32 | } 33 | //创建文件 34 | File imageFile = new File(fileDir,fileName); 35 | try { 36 | FileOutputStream fos = new FileOutputStream(imageFile); 37 | boolean compress = bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); 38 | 39 | fos.flush(); 40 | fos.close(); 41 | } catch (FileNotFoundException e) { 42 | e.printStackTrace(); 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | 47 | Uri uri = Uri.fromFile(imageFile); 48 | //发送广播,通知图库更新 49 | context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,uri)); 50 | return uri; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/CircularAnim.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view; 2 | 3 | import android.animation.Animator; 4 | import android.animation.AnimatorListenerAdapter; 5 | import android.annotation.SuppressLint; 6 | import android.app.Activity; 7 | import android.view.View; 8 | import android.view.ViewAnimationUtils; 9 | import android.view.ViewGroup; 10 | import android.widget.ImageView; 11 | 12 | /** 13 | * Created on gx 16/8/5. 14 | *

15 | * 对 ViewAnimationUtils.createCircularReveal() 方法的封装. 16 | *

17 | * GitHub: https://github.com/XunMengWinter 18 | * 19 | * @author ice 20 | */ 21 | public class CircularAnim { 22 | 23 | public static final long PERFECT_MILLS = 618; 24 | public static final int MINI_RADIUS = 0; 25 | 26 | private static Long sPerfectMills; 27 | private static Long sFullActivityPerfectMills; 28 | private static Integer sColorOrImageRes; 29 | 30 | private static long getPerfectMills() { 31 | if (sPerfectMills != null) 32 | return sPerfectMills; 33 | else 34 | return PERFECT_MILLS; 35 | } 36 | 37 | private static long getFullActivityMills() { 38 | if (sFullActivityPerfectMills != null) 39 | return sFullActivityPerfectMills; 40 | else 41 | return PERFECT_MILLS; 42 | } 43 | 44 | private static int getColorOrImageRes() { 45 | if (sColorOrImageRes != null) 46 | return sColorOrImageRes; 47 | else 48 | return android.R.color.white; 49 | } 50 | 51 | 52 | public interface OnAnimationEndListener { 53 | void onAnimationEnd(); 54 | } 55 | 56 | @SuppressLint("NewApi") 57 | public static class VisibleBuilder { 58 | 59 | private View mAnimView, mTriggerView; 60 | 61 | private Float mStartRadius, mEndRadius; 62 | 63 | private long mDurationMills = getPerfectMills(); 64 | 65 | private boolean isShow; 66 | 67 | private OnAnimationEndListener mOnAnimationEndListener; 68 | 69 | public VisibleBuilder(View animView, boolean isShow) { 70 | mAnimView = animView; 71 | this.isShow = isShow; 72 | 73 | if (isShow) { 74 | mStartRadius = MINI_RADIUS + 0F; 75 | } else { 76 | mEndRadius = MINI_RADIUS + 0F; 77 | } 78 | } 79 | 80 | public VisibleBuilder triggerView(View triggerView) { 81 | mTriggerView = triggerView; 82 | return this; 83 | } 84 | 85 | public VisibleBuilder startRadius(float startRadius) { 86 | mStartRadius = startRadius; 87 | return this; 88 | } 89 | 90 | public VisibleBuilder endRadius(float endRadius) { 91 | mEndRadius = endRadius; 92 | return this; 93 | } 94 | 95 | public VisibleBuilder duration(long durationMills) { 96 | mDurationMills = durationMills; 97 | return this; 98 | } 99 | 100 | @Deprecated //You can use method - go(OnAnimationEndListener onAnimationEndListener). 101 | public VisibleBuilder onAnimationEndListener(OnAnimationEndListener onAnimationEndListener) { 102 | mOnAnimationEndListener = onAnimationEndListener; 103 | return this; 104 | } 105 | 106 | public void go() { 107 | go(null); 108 | } 109 | 110 | public void go(OnAnimationEndListener onAnimationEndListener) { 111 | mOnAnimationEndListener = onAnimationEndListener; 112 | 113 | // 版本判断 114 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { 115 | doOnEnd(); 116 | return; 117 | } 118 | 119 | int rippleCX, rippleCY, maxRadius; 120 | if (mTriggerView != null) { 121 | int[] tvLocation = new int[2]; 122 | mTriggerView.getLocationInWindow(tvLocation); 123 | final int tvCX = tvLocation[0] + mTriggerView.getWidth() / 2; 124 | final int tvCY = tvLocation[1] + mTriggerView.getHeight() / 2; 125 | 126 | int[] avLocation = new int[2]; 127 | mAnimView.getLocationInWindow(avLocation); 128 | final int avLX = avLocation[0]; 129 | final int avTY = avLocation[1]; 130 | 131 | int triggerX = Math.max(avLX, tvCX); 132 | triggerX = Math.min(triggerX, avLX + mAnimView.getWidth()); 133 | 134 | int triggerY = Math.max(avTY, tvCY); 135 | triggerY = Math.min(triggerY, avTY + mAnimView.getHeight()); 136 | 137 | // 以上全为绝对坐标 138 | 139 | int avW = mAnimView.getWidth(); 140 | int avH = mAnimView.getHeight(); 141 | 142 | rippleCX = triggerX - avLX; 143 | rippleCY = triggerY - avTY; 144 | 145 | // 计算水波中心点至 @mAnimView 边界的最大距离 146 | int maxW = Math.max(rippleCX, avW - rippleCX); 147 | int maxH = Math.max(rippleCY, avH - rippleCY); 148 | maxRadius = (int) Math.sqrt(maxW * maxW + maxH * maxH) + 1; 149 | } else { 150 | rippleCX = (mAnimView.getLeft() + mAnimView.getRight()) / 2; 151 | rippleCY = (mAnimView.getTop() + mAnimView.getBottom()) / 2; 152 | 153 | int w = mAnimView.getWidth(); 154 | int h = mAnimView.getHeight(); 155 | 156 | // 勾股定理 & 进一法 157 | maxRadius = (int) Math.sqrt(w * w + h * h) + 1; 158 | } 159 | 160 | if (isShow && mEndRadius == null) 161 | mEndRadius = maxRadius + 0F; 162 | else if (!isShow && mStartRadius == null) 163 | mStartRadius = maxRadius + 0F; 164 | 165 | try { 166 | Animator anim = ViewAnimationUtils.createCircularReveal( 167 | mAnimView, rippleCX, rippleCY, mStartRadius, mEndRadius); 168 | 169 | 170 | mAnimView.setVisibility(View.VISIBLE); 171 | anim.setDuration(mDurationMills); 172 | 173 | anim.addListener(new AnimatorListenerAdapter() { 174 | @Override 175 | public void onAnimationEnd(Animator animation) { 176 | super.onAnimationEnd(animation); 177 | doOnEnd(); 178 | } 179 | }); 180 | 181 | anim.start(); 182 | } catch (Exception e) { 183 | e.printStackTrace(); 184 | doOnEnd(); 185 | } 186 | } 187 | 188 | private void doOnEnd() { 189 | if (isShow) 190 | mAnimView.setVisibility(View.VISIBLE); 191 | else 192 | mAnimView.setVisibility(View.INVISIBLE); 193 | 194 | if (mOnAnimationEndListener != null) 195 | mOnAnimationEndListener.onAnimationEnd(); 196 | } 197 | 198 | } 199 | 200 | @SuppressLint("NewApi") 201 | public static class FullActivityBuilder { 202 | private Activity mActivity; 203 | private View mTriggerView; 204 | private float mStartRadius = MINI_RADIUS; 205 | private int mColorOrImageRes = getColorOrImageRes(); 206 | private Long mDurationMills; 207 | private OnAnimationEndListener mOnAnimationEndListener; 208 | private int mEnterAnim = android.R.anim.fade_in, mExitAnim = android.R.anim.fade_out; 209 | 210 | public FullActivityBuilder(Activity activity, View triggerView) { 211 | mActivity = activity; 212 | mTriggerView = triggerView; 213 | } 214 | 215 | public FullActivityBuilder startRadius(float startRadius) { 216 | mStartRadius = startRadius; 217 | return this; 218 | } 219 | 220 | public FullActivityBuilder colorOrImageRes(int colorOrImageRes) { 221 | mColorOrImageRes = colorOrImageRes; 222 | return this; 223 | } 224 | 225 | public FullActivityBuilder duration(long durationMills) { 226 | mDurationMills = durationMills; 227 | return this; 228 | } 229 | 230 | public FullActivityBuilder overridePendingTransition(int enterAnim, int exitAnim) { 231 | mEnterAnim = enterAnim; 232 | mExitAnim = exitAnim; 233 | return this; 234 | } 235 | 236 | public void go(OnAnimationEndListener onAnimationEndListener) { 237 | mOnAnimationEndListener = onAnimationEndListener; 238 | 239 | // 版本判断,小于5.0则无动画. 240 | if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.LOLLIPOP) { 241 | doOnEnd(); 242 | return; 243 | } 244 | 245 | int[] location = new int[2]; 246 | mTriggerView.getLocationInWindow(location); 247 | final int cx = location[0] + mTriggerView.getWidth() / 2; 248 | final int cy = location[1] + mTriggerView.getHeight() / 2; 249 | final ImageView view = new ImageView(mActivity); 250 | view.setScaleType(ImageView.ScaleType.CENTER_CROP); 251 | view.setImageResource(mColorOrImageRes); 252 | final ViewGroup decorView = (ViewGroup) mActivity.getWindow().getDecorView(); 253 | int w = decorView.getWidth(); 254 | int h = decorView.getHeight(); 255 | decorView.addView(view, w, h); 256 | 257 | // 计算中心点至view边界的最大距离 258 | int maxW = Math.max(cx, w - cx); 259 | int maxH = Math.max(cy, h - cy); 260 | final int finalRadius = (int) Math.sqrt(maxW * maxW + maxH * maxH) + 1; 261 | 262 | try { 263 | Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, mStartRadius, finalRadius); 264 | 265 | int maxRadius = (int) Math.sqrt(w * w + h * h) + 1; 266 | // 若未设置时长,则以PERFECT_MILLS为基准根据水波扩散的距离来计算实际时间 267 | if (mDurationMills == null) { 268 | // 算出实际边距与最大边距的比率 269 | double rate = 1d * finalRadius / maxRadius; 270 | // 为了让用户便于感触到水波,速度应随最大边距的变小而越慢,扩散时间应随最大边距的变小而变小,因此比率应在 @rate 与 1 之间。 271 | mDurationMills = (long) (getFullActivityMills() * Math.sqrt(rate)); 272 | } 273 | final long finalDuration = mDurationMills; 274 | // 由于thisActivity.startActivity()会有所停顿,所以进入的水波动画应比退出的水波动画时间短才能保持视觉上的一致。 275 | anim.setDuration((long) (finalDuration * 0.9)); 276 | anim.addListener(new AnimatorListenerAdapter() { 277 | @Override 278 | public void onAnimationEnd(Animator animation) { 279 | super.onAnimationEnd(animation); 280 | 281 | doOnEnd(); 282 | 283 | mActivity.overridePendingTransition(mEnterAnim, mExitAnim); 284 | 285 | // 默认显示返回至当前Activity的动画. 286 | mTriggerView.postDelayed(new Runnable() { 287 | @Override 288 | public void run() { 289 | if (mActivity.isFinishing()) return; 290 | try { 291 | Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 292 | finalRadius, mStartRadius); 293 | anim.setDuration(finalDuration); 294 | anim.addListener(new AnimatorListenerAdapter() { 295 | @Override 296 | public void onAnimationEnd(Animator animation) { 297 | super.onAnimationEnd(animation); 298 | try { 299 | decorView.removeView(view); 300 | } catch (Exception e) { 301 | e.printStackTrace(); 302 | } 303 | } 304 | }); 305 | anim.start(); 306 | } catch (Exception e) { 307 | e.printStackTrace(); 308 | try { 309 | decorView.removeView(view); 310 | } catch (Exception e1) { 311 | e1.printStackTrace(); 312 | } 313 | } 314 | } 315 | }, 1000); 316 | 317 | } 318 | }); 319 | anim.start(); 320 | } catch (Exception e) { 321 | e.printStackTrace(); 322 | doOnEnd(); 323 | } 324 | } 325 | 326 | private void doOnEnd() { 327 | mOnAnimationEndListener.onAnimationEnd(); 328 | } 329 | } 330 | 331 | 332 | /* 上面为实现逻辑,下面为外部调用方法 */ 333 | 334 | 335 | /* 伸展并显示@animView */ 336 | public static VisibleBuilder show(View animView) { 337 | return new VisibleBuilder(animView, true); 338 | } 339 | 340 | /* 收缩并隐藏@animView */ 341 | public static VisibleBuilder hide(View animView) { 342 | return new VisibleBuilder(animView, false); 343 | } 344 | 345 | /* 以@triggerView 为触发点铺满整个@activity */ 346 | public static FullActivityBuilder fullActivity(Activity activity, View triggerView) { 347 | return new FullActivityBuilder(activity, triggerView); 348 | } 349 | 350 | /* 设置默认时长,设置充满activity的默认颜色或图片资源 */ 351 | public static void init(long perfectMills, long fullActivityPerfectMills, int colorOrImageRes) { 352 | sPerfectMills = perfectMills; 353 | sFullActivityPerfectMills = fullActivityPerfectMills; 354 | sColorOrImageRes = colorOrImageRes; 355 | } 356 | 357 | } -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/TouchImageView.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view; 2 | 3 | 4 | import android.content.Context; 5 | import android.graphics.Matrix; 6 | import android.graphics.PointF; 7 | import android.graphics.drawable.Drawable; 8 | import android.util.AttributeSet; 9 | import android.util.Log; 10 | import android.view.MotionEvent; 11 | import android.view.ScaleGestureDetector; 12 | import android.view.View; 13 | import android.widget.ImageView; 14 | 15 | public class TouchImageView extends ImageView { 16 | 17 | Matrix matrix; 18 | 19 | // We can be in one of these 3 states 20 | static final int NONE = 0; 21 | static final int DRAG = 1; 22 | static final int ZOOM = 2; 23 | int mode = NONE; 24 | 25 | // Remember some things for zooming 26 | PointF last = new PointF(); 27 | PointF start = new PointF(); 28 | float minScale = 1f; 29 | float maxScale = 3f; 30 | float[] m; 31 | 32 | 33 | int viewWidth, viewHeight; 34 | static final int CLICK = 3; 35 | float saveScale = 1f; 36 | protected float origWidth, origHeight; 37 | int oldMeasuredWidth, oldMeasuredHeight; 38 | 39 | 40 | ScaleGestureDetector mScaleDetector; 41 | 42 | Context context; 43 | 44 | public TouchImageView(Context context) { 45 | super(context); 46 | sharedConstructing(context); 47 | } 48 | 49 | public TouchImageView(Context context, AttributeSet attrs) { 50 | super(context, attrs); 51 | sharedConstructing(context); 52 | } 53 | 54 | private void sharedConstructing(Context context) { 55 | super.setClickable(true); 56 | this.context = context; 57 | mScaleDetector = new ScaleGestureDetector(context, new ScaleListener()); 58 | matrix = new Matrix(); 59 | m = new float[9]; 60 | setImageMatrix(matrix); 61 | setScaleType(ScaleType.MATRIX); 62 | 63 | setOnTouchListener(new OnTouchListener() { 64 | 65 | @Override 66 | public boolean onTouch(View v, MotionEvent event) { 67 | mScaleDetector.onTouchEvent(event); 68 | PointF curr = new PointF(event.getX(), event.getY()); 69 | 70 | switch (event.getAction()) { 71 | case MotionEvent.ACTION_DOWN: 72 | last.set(curr); 73 | start.set(last); 74 | mode = DRAG; 75 | break; 76 | 77 | case MotionEvent.ACTION_MOVE: 78 | if (mode == DRAG) { 79 | float deltaX = curr.x - last.x; 80 | float deltaY = curr.y - last.y; 81 | float fixTransX = getFixDragTrans(deltaX, viewWidth, origWidth * saveScale); 82 | float fixTransY = getFixDragTrans(deltaY, viewHeight, origHeight * saveScale); 83 | matrix.postTranslate(fixTransX, fixTransY); 84 | fixTrans(); 85 | last.set(curr.x, curr.y); 86 | } 87 | break; 88 | 89 | case MotionEvent.ACTION_UP: 90 | mode = NONE; 91 | int xDiff = (int) Math.abs(curr.x - start.x); 92 | int yDiff = (int) Math.abs(curr.y - start.y); 93 | if (xDiff < CLICK && yDiff < CLICK) 94 | performClick(); 95 | break; 96 | 97 | case MotionEvent.ACTION_POINTER_UP: 98 | mode = NONE; 99 | break; 100 | } 101 | 102 | setImageMatrix(matrix); 103 | invalidate(); 104 | return true; // indicate event was handled 105 | } 106 | 107 | }); 108 | } 109 | 110 | public void setMaxZoom(float x) { 111 | maxScale = x; 112 | } 113 | 114 | private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { 115 | @Override 116 | public boolean onScaleBegin(ScaleGestureDetector detector) { 117 | mode = ZOOM; 118 | return true; 119 | } 120 | 121 | @Override 122 | public boolean onScale(ScaleGestureDetector detector) { 123 | float mScaleFactor = detector.getScaleFactor(); 124 | float origScale = saveScale; 125 | saveScale *= mScaleFactor; 126 | if (saveScale > maxScale) { 127 | saveScale = maxScale; 128 | mScaleFactor = maxScale / origScale; 129 | } else if (saveScale < minScale) { 130 | saveScale = minScale; 131 | mScaleFactor = minScale / origScale; 132 | } 133 | 134 | if (origWidth * saveScale <= viewWidth || origHeight * saveScale <= viewHeight) 135 | matrix.postScale(mScaleFactor, mScaleFactor, viewWidth / 2, viewHeight / 2); 136 | else 137 | matrix.postScale(mScaleFactor, mScaleFactor, detector.getFocusX(), detector.getFocusY()); 138 | 139 | fixTrans(); 140 | return true; 141 | } 142 | } 143 | 144 | void fixTrans() { 145 | matrix.getValues(m); 146 | float transX = m[Matrix.MTRANS_X]; 147 | float transY = m[Matrix.MTRANS_Y]; 148 | 149 | float fixTransX = getFixTrans(transX, viewWidth, origWidth * saveScale); 150 | float fixTransY = getFixTrans(transY, viewHeight, origHeight * saveScale); 151 | 152 | if (fixTransX != 0 || fixTransY != 0) 153 | matrix.postTranslate(fixTransX, fixTransY); 154 | } 155 | 156 | float getFixTrans(float trans, float viewSize, float contentSize) { 157 | float minTrans, maxTrans; 158 | 159 | if (contentSize <= viewSize) { 160 | minTrans = 0; 161 | maxTrans = viewSize - contentSize; 162 | } else { 163 | minTrans = viewSize - contentSize; 164 | maxTrans = 0; 165 | } 166 | 167 | if (trans < minTrans) 168 | return -trans + minTrans; 169 | if (trans > maxTrans) 170 | return -trans + maxTrans; 171 | return 0; 172 | } 173 | 174 | float getFixDragTrans(float delta, float viewSize, float contentSize) { 175 | if (contentSize <= viewSize) { 176 | return 0; 177 | } 178 | return delta; 179 | } 180 | 181 | @Override 182 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 183 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 184 | viewWidth = MeasureSpec.getSize(widthMeasureSpec); 185 | viewHeight = MeasureSpec.getSize(heightMeasureSpec); 186 | 187 | // 188 | // Rescales image on rotation 189 | // 190 | if (oldMeasuredHeight == viewWidth && oldMeasuredHeight == viewHeight 191 | || viewWidth == 0 || viewHeight == 0) 192 | return; 193 | oldMeasuredHeight = viewHeight; 194 | oldMeasuredWidth = viewWidth; 195 | 196 | if (saveScale == 1) { 197 | //Fit to screen. 198 | float scale; 199 | 200 | Drawable drawable = getDrawable(); 201 | if (drawable == null || drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) 202 | return; 203 | int bmWidth = drawable.getIntrinsicWidth(); 204 | int bmHeight = drawable.getIntrinsicHeight(); 205 | 206 | Log.d("bmSize", "bmWidth: " + bmWidth + " bmHeight : " + bmHeight); 207 | 208 | float scaleX = (float) viewWidth / (float) bmWidth; 209 | float scaleY = (float) viewHeight / (float) bmHeight; 210 | scale = Math.min(scaleX, scaleY); 211 | matrix.setScale(scale, scale); 212 | 213 | // Center the image 214 | float redundantYSpace = (float) viewHeight - (scale * (float) bmHeight); 215 | float redundantXSpace = (float) viewWidth - (scale * (float) bmWidth); 216 | redundantYSpace /= (float) 2; 217 | redundantXSpace /= (float) 2; 218 | 219 | matrix.postTranslate(redundantXSpace, redundantYSpace); 220 | 221 | origWidth = viewWidth - 2 * redundantXSpace; 222 | origHeight = viewHeight - 2 * redundantYSpace; 223 | setImageMatrix(matrix); 224 | } 225 | fixTrans(); 226 | } 227 | } 228 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/activity/AboutActivity.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.activity; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.support.v7.widget.Toolbar; 6 | import android.view.MenuItem; 7 | 8 | import com.gx.learn.R; 9 | 10 | 11 | public class AboutActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_about); 17 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 18 | toolbar.setTitle("关于"); 19 | setSupportActionBar(toolbar); 20 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 21 | 22 | 23 | } 24 | @Override 25 | public boolean onOptionsItemSelected(MenuItem item) { 26 | if (item.getItemId() == android.R.id.home) { 27 | finish(); 28 | return true; 29 | } 30 | return super.onOptionsItemSelected(item); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/activity/BaseActivity.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.activity; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | 5 | /** 6 | * Created by gx on 16/11/2. 7 | */ 8 | 9 | public class BaseActivity extends AppCompatActivity { 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/activity/FirstActivity.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.os.Handler; 6 | import android.os.Looper; 7 | import android.os.Message; 8 | import android.support.v7.app.AppCompatActivity; 9 | 10 | import java.lang.ref.WeakReference; 11 | 12 | public class FirstActivity extends AppCompatActivity { 13 | 14 | private SwitchHandler mHandler = new SwitchHandler(Looper.getMainLooper(), this); 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | mHandler.sendEmptyMessageDelayed(1, 100); 20 | } 21 | 22 | class SwitchHandler extends Handler { 23 | private WeakReference mWeakReference; 24 | 25 | public SwitchHandler(Looper mLooper, FirstActivity activity) { 26 | super(mLooper); 27 | mWeakReference = new WeakReference(activity); 28 | } 29 | 30 | @Override 31 | public void handleMessage(Message msg) { 32 | super.handleMessage(msg); 33 | 34 | Intent i = new Intent(FirstActivity.this, MainActivity.class); 35 | FirstActivity.this.startActivity(i); 36 | //activity切换的淡入淡出效果 37 | overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); 38 | FirstActivity.this.finish(); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/activity/ImageActivity.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.activity; 2 | 3 | import android.graphics.Bitmap; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.Toolbar; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import android.widget.Toast; 9 | 10 | import com.bm.library.PhotoView; 11 | import com.bumptech.glide.Glide; 12 | import com.bumptech.glide.load.engine.DiskCacheStrategy; 13 | import com.bumptech.glide.request.animation.GlideAnimation; 14 | import com.bumptech.glide.request.target.SimpleTarget; 15 | import com.gx.learn.R; 16 | import com.gx.learn.util.ImgSaveUtil; 17 | import com.gx.learn.view.TouchImageView; 18 | 19 | public class ImageActivity extends BaseActivity { 20 | private String url = "url"; 21 | private String desc = "desc"; 22 | private TouchImageView img; 23 | private Bitmap bitmap; 24 | private PhotoView photoView; 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_image); 29 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 30 | setSupportActionBar(toolbar); 31 | desc = getIntent().getStringExtra(desc); 32 | url = getIntent().getStringExtra(url); 33 | getSupportActionBar().setTitle(desc); 34 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 35 | initView(); 36 | 37 | 38 | } 39 | 40 | private void initView() { 41 | // img = (TouchImageView) findViewById(R.id.image_touch); 42 | // img.setMaxZoom(4f); 43 | photoView = (PhotoView) findViewById(R.id.photoview); 44 | photoView.enable(); 45 | photoView.setMaxScale(5); 46 | 47 | Glide.with(this) 48 | .load(url) 49 | .asBitmap() 50 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 51 | .into(new SimpleTarget() {// 先下载图片然后再做一些合成的功能,比如项目中出现的图文混排 52 | @Override 53 | public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) { 54 | photoView.setImageBitmap(resource); 55 | bitmap = resource; 56 | } 57 | }); 58 | } 59 | public boolean onCreateOptionsMenu(Menu menu) { 60 | // Inflate the menu; this adds items to the action bar if it is present. 61 | getMenuInflater().inflate(R.menu.main_meizi, menu); 62 | return true; 63 | } 64 | @Override 65 | public boolean onOptionsItemSelected(MenuItem item) { 66 | if (item.getItemId() == android.R.id.home) { 67 | onBackPressed(); 68 | return true; 69 | } 70 | if (item.getItemId() == R.id.action_save) { 71 | ImgSaveUtil.saveImage(this,url,bitmap,img,"saveImg"); 72 | Toast.makeText(this,"已保存至图库",Toast.LENGTH_SHORT ).show(); 73 | return true; 74 | } 75 | return super.onOptionsItemSelected(item); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.design.widget.NavigationView; 6 | import android.support.design.widget.TabLayout; 7 | import android.support.v4.app.Fragment; 8 | import android.support.v4.view.GravityCompat; 9 | import android.support.v4.view.ViewPager; 10 | import android.support.v4.widget.DrawerLayout; 11 | import android.support.v7.app.ActionBarDrawerToggle; 12 | import android.support.v7.widget.Toolbar; 13 | import android.view.MenuItem; 14 | import android.widget.Toast; 15 | 16 | 17 | import com.gx.learn.R; 18 | import com.gx.learn.adapter.MyFragmentPagerAdapter; 19 | import com.gx.learn.view.fragment.BlogFragment; 20 | import com.gx.learn.view.fragment.MeiziFragment; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | public class MainActivity extends BaseActivity 26 | implements NavigationView.OnNavigationItemSelectedListener { 27 | private TabLayout tabLayout; 28 | private ViewPager viewPager; 29 | private MyFragmentPagerAdapter myFragmentPagerAdapter; 30 | private List fragmentList; 31 | private List titles; 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 37 | setSupportActionBar(toolbar); 38 | initview(); 39 | 40 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 41 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 42 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 43 | drawer.setDrawerListener(toggle); 44 | toggle.syncState(); 45 | 46 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 47 | navigationView.setNavigationItemSelectedListener(this); 48 | } 49 | private void initview() { 50 | viewPager = (ViewPager) findViewById(R.id.viewPager); 51 | titles = new ArrayList<>(); 52 | titles.add("妹子"); 53 | titles.add("Android"); 54 | 55 | fragmentList = new ArrayList<>(); 56 | fragmentList.add(new MeiziFragment()); 57 | fragmentList.add(new BlogFragment()); 58 | myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),fragmentList,titles); 59 | viewPager.setAdapter(myFragmentPagerAdapter); 60 | tabLayout = (TabLayout) findViewById(R.id.tablayout); 61 | tabLayout.setupWithViewPager(viewPager); 62 | for (int i = 0; i < tabLayout.getTabCount(); i++) { 63 | TabLayout.Tab tab = tabLayout.getTabAt(i); 64 | } 65 | } 66 | @SuppressWarnings("StatementWithEmptyBody") 67 | @Override 68 | public boolean onNavigationItemSelected(MenuItem item) { 69 | // Handle navigation view item clicks here. 70 | int id = item.getItemId(); 71 | 72 | if (id == R.id.about) { 73 | startActivity(new Intent(MainActivity.this,AboutActivity.class)); 74 | } 75 | if (id == R.id.nav_zhihu) { 76 | startActivity(new Intent(MainActivity.this,ZhihuActivity.class)); 77 | } 78 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 79 | drawer.closeDrawer(GravityCompat.START); 80 | return true; 81 | } 82 | 83 | private long exitTime = 0; 84 | @Override//抽屉的返回按键点击事件 85 | public void onBackPressed() { 86 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 87 | if (drawer.isDrawerOpen(GravityCompat.START)) { 88 | drawer.closeDrawer(GravityCompat.START); 89 | } else { 90 | //super.onBackPressed(); 91 | if ((System.currentTimeMillis() - exitTime) > 2000) { 92 | Toast.makeText(MainActivity.this,"再按一次退出程序",Toast.LENGTH_SHORT).show(); 93 | exitTime = System.currentTimeMillis(); 94 | } else { 95 | finish(); 96 | } 97 | } 98 | 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/activity/WebActivity.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.activity; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.Toolbar; 6 | import android.view.KeyEvent; 7 | import android.view.Menu; 8 | import android.view.MenuItem; 9 | import android.webkit.WebSettings; 10 | import android.webkit.WebView; 11 | import android.webkit.WebViewClient; 12 | import android.widget.Toast; 13 | 14 | 15 | import com.gx.learn.R; 16 | import com.gx.learn.util.ClipboardUtils; 17 | 18 | import static android.view.KeyEvent.KEYCODE_BACK; 19 | 20 | public class WebActivity extends BaseActivity { 21 | private String url = "url"; 22 | private String title = "title"; 23 | private WebView webView; 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_web); 28 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 29 | setSupportActionBar(toolbar); 30 | url = getIntent().getStringExtra(url); 31 | title = getIntent().getStringExtra(title); 32 | getSupportActionBar().setTitle(title); 33 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 34 | initView(); 35 | 36 | 37 | } 38 | 39 | private void initView() { 40 | webView = (WebView) findViewById(R.id.web); 41 | webView.canGoBack(); 42 | WebSettings settings = webView.getSettings(); 43 | settings.setJavaScriptEnabled(true); 44 | settings.setLoadWithOverviewMode(true); 45 | settings.setAppCacheEnabled(true); 46 | settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); 47 | settings.setSupportZoom(true); 48 | settings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放 49 | settings.setDisplayZoomControls(false); 50 | settings.setJavaScriptCanOpenWindowsAutomatically(true); 51 | webView.loadUrl(url); 52 | webView.setWebViewClient(new WebViewClient(){ 53 | @Override 54 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 55 | view.loadUrl(url); 56 | return true; 57 | } 58 | }); 59 | } 60 | public boolean onKeyDown(int keyCode, KeyEvent event) { 61 | if ((keyCode == KEYCODE_BACK) && webView.canGoBack()) { 62 | webView.goBack(); 63 | return true; 64 | } 65 | return super.onKeyDown(keyCode, event); 66 | } 67 | public boolean onCreateOptionsMenu(Menu menu) { 68 | getMenuInflater().inflate(R.menu.main_web, menu); 69 | return true; 70 | } 71 | @Override 72 | public boolean onOptionsItemSelected(MenuItem item) { 73 | int itemId = item.getItemId(); 74 | switch (itemId) 75 | { 76 | case android.R.id.home: 77 | onBackPressed(); 78 | return true; 79 | 80 | case R.id.action_share: 81 | share(); 82 | return true; 83 | 84 | case R.id.action_copy: 85 | ClipboardUtils.setText(WebActivity.this, url); 86 | Toast.makeText(this,"已复制到粘贴板",Toast.LENGTH_SHORT).show(); 87 | return true; 88 | } 89 | 90 | 91 | return super.onOptionsItemSelected(item); 92 | } 93 | private void share() 94 | { 95 | 96 | Intent intent = new Intent(Intent.ACTION_SEND); 97 | intent.setType("text/plain"); 98 | intent.putExtra(Intent.EXTRA_SUBJECT, "分享"); 99 | intent.putExtra(Intent.EXTRA_TEXT, "来自「Gank.IO」的分享:" + url); 100 | startActivity(Intent.createChooser(intent, title)); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/activity/ZhihuActivity.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.activity; 2 | 3 | import android.content.Intent; 4 | import android.graphics.Color; 5 | import android.os.Bundle; 6 | import android.support.v4.widget.SwipeRefreshLayout; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.LayoutInflater; 11 | import android.view.MenuItem; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.ImageView; 15 | 16 | import com.bumptech.glide.Glide; 17 | import com.gx.learn.R; 18 | import com.gx.learn.adapter.Zhihuadapter; 19 | import com.gx.learn.model.Zhihu; 20 | import com.gx.learn.model.Zhiitem; 21 | import com.gx.learn.net.GetData; 22 | import com.gx.learn.view.CircularAnim; 23 | import com.jude.easyrecyclerview.EasyRecyclerView; 24 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter; 25 | import com.jude.rollviewpager.RollPagerView; 26 | import com.jude.rollviewpager.adapter.LoopPagerAdapter; 27 | import com.jude.rollviewpager.hintview.ColorPointHintView; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | import rx.Subscriber; 33 | 34 | public class ZhihuActivity extends AppCompatActivity { 35 | private String latest = "latest" ; 36 | private SwipeRefreshLayout swipeRefreshLayout; 37 | private EasyRecyclerView recyclerView; 38 | private Zhihuadapter zhihuadapter; 39 | private LinearLayoutManager linearLayoutManager; 40 | private List topStories; 41 | private List zhiitems ; 42 | private RollPagerView rollViewPager; 43 | private String data = ""; 44 | private TestLoopAdapter testLoopAdapter; 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_zhihu); 49 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 50 | setSupportActionBar(toolbar); 51 | getSupportActionBar().setTitle("知乎日报"); 52 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 53 | 54 | recyclerView = (EasyRecyclerView) findViewById(R.id.recycleview); 55 | linearLayoutManager = new LinearLayoutManager(ZhihuActivity.this, LinearLayoutManager.VERTICAL,false); 56 | recyclerView.setLayoutManager(linearLayoutManager); 57 | zhihuadapter = new Zhihuadapter(ZhihuActivity.this); 58 | recyclerView.setAdapter(zhihuadapter); 59 | swipeRefreshLayout=(SwipeRefreshLayout)findViewById(R.id.swiprefresh_zhihu) ; 60 | swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light); 61 | 62 | init(); 63 | } 64 | 65 | private void init() { 66 | swipeRefreshLayout.postDelayed(new Runnable() { 67 | @Override 68 | public void run() { 69 | swipeRefreshLayout.setRefreshing(true); 70 | getZhihudDatafirst(); 71 | } 72 | },10); 73 | 74 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 75 | @Override 76 | public void onRefresh() { 77 | swipeRefreshLayout.postDelayed(new Runnable() { 78 | @Override 79 | public void run() { 80 | swipeRefreshLayout.setRefreshing(true); 81 | zhihuadapter.clear(); 82 | 83 | getZhihudDatafirst(); 84 | System.out.println(zhiitems.get(0).title); 85 | 86 | } 87 | },300); 88 | } 89 | }); 90 | zhihuadapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() { 91 | @Override 92 | public void onMoreShow() { 93 | getZhihuData(); 94 | } 95 | 96 | @Override 97 | public void onMoreClick() { 98 | 99 | } 100 | }); 101 | zhihuadapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() { 102 | @Override 103 | public void onItemClick(int position) { 104 | Intent intent = new Intent(ZhihuActivity.this,ZhihunewsActivity.class); 105 | intent.putExtra("title",zhihuadapter.getItem(position).title); 106 | intent.putExtra("images",zhihuadapter.getItem(position).images); 107 | intent.putExtra("id",String.valueOf(zhihuadapter.getItem(position).id)); 108 | startActivity(intent); 109 | } 110 | }); 111 | } 112 | private class TestLoopAdapter extends LoopPagerAdapter 113 | { 114 | private List data; 115 | public TestLoopAdapter(RollPagerView viewPager, List topStories) 116 | { 117 | super(viewPager); 118 | this.data = topStories; 119 | } 120 | 121 | @Override 122 | public View getView(ViewGroup container, final int position) 123 | { 124 | final ImageView view = new ImageView(container.getContext()); 125 | Glide.with(container.getContext()).load(data.get(position).getImage()).into(view); 126 | view.setScaleType(ImageView.ScaleType.CENTER_CROP); 127 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); 128 | view.setOnClickListener(new View.OnClickListener() // 点击事件 129 | { 130 | @Override 131 | public void onClick(View v) 132 | { 133 | final Intent intent = new Intent(ZhihuActivity.this,ZhihunewsActivity.class); 134 | 135 | intent.putExtra("id",String.valueOf(topStories.get(position).getId())); 136 | intent.putExtra("title",topStories.get(position).getTitle()); 137 | CircularAnim.fullActivity(ZhihuActivity.this, view) 138 | .colorOrImageRes(R.color.colorPrimary) 139 | .duration(150) 140 | .go(new CircularAnim.OnAnimationEndListener() { 141 | @Override 142 | public void onAnimationEnd() { 143 | startActivity(intent); 144 | } 145 | }); 146 | 147 | 148 | } 149 | 150 | }); 151 | 152 | return view; 153 | } 154 | 155 | @Override 156 | public int getRealCount() 157 | { 158 | return 5; 159 | } 160 | 161 | } 162 | 163 | 164 | private void getZhihudDatafirst() { 165 | Subscriber subscriber = new Subscriber() { 166 | @Override 167 | public void onCompleted() { 168 | if (testLoopAdapter == null){ 169 | zhihuadapter.addHeader(new RecyclerArrayAdapter.ItemView() { 170 | @Override 171 | public View onCreateView(ViewGroup parent) { 172 | rollViewPager = (RollPagerView) LayoutInflater.from(ZhihuActivity.this).inflate(R.layout.zhihuheader, recyclerView, false); 173 | testLoopAdapter = new TestLoopAdapter(rollViewPager,topStories); 174 | rollViewPager.setAdapter(testLoopAdapter); 175 | rollViewPager.setHintView(new ColorPointHintView(ZhihuActivity.this, Color.WHITE, Color.GRAY));// 设置圆点指示器颜色 176 | return rollViewPager; 177 | } 178 | 179 | @Override 180 | public void onBindView(View headerView) { 181 | 182 | } 183 | }); 184 | } 185 | zhihuadapter.notifyDataSetChanged(); 186 | swipeRefreshLayout.setRefreshing(false); 187 | } 188 | 189 | @Override 190 | public void onError(Throwable e) { 191 | System.out.println("555555"); 192 | } 193 | 194 | @Override 195 | public void onNext(Zhihu zhihu) { 196 | data = zhihu.getDate(); 197 | List stories = zhihu.getStories(); 198 | topStories = zhihu.getTop_stories(); 199 | zhiitems = new ArrayList<>(); 200 | for (int i = 0; i subscriber = new Subscriber() { 220 | @Override 221 | public void onCompleted() { 222 | swipeRefreshLayout.setRefreshing(false); 223 | } 224 | 225 | @Override 226 | public void onError(Throwable e) { 227 | System.out.println("666666"); 228 | } 229 | 230 | @Override 231 | public void onNext(Zhihu zhihu) { 232 | data = zhihu.getDate(); 233 | List stories = zhihu.getStories(); 234 | zhiitems = new ArrayList<>(); 235 | for (int i = 0; i subscriber = new Subscriber() { 61 | @Override 62 | public void onCompleted() { 63 | 64 | } 65 | 66 | @Override 67 | public void onError(Throwable e) { 68 | 69 | } 70 | 71 | @Override 72 | public void onNext(Zhihunews zhihunews) { 73 | System.out.println(zhihunews.getTitle()); 74 | Glide.with(ZhihunewsActivity.this) 75 | .load(zhihunews.getImage()) 76 | .diskCacheStrategy(DiskCacheStrategy.SOURCE) 77 | .into(imageView); 78 | String css = ""; 80 | String html = "" + css + "" + zhihunews.getBody() + ""; 81 | html = html.replace("

", ""); 82 | webView.loadDataWithBaseURL("x-data://base", html, "text/html", "UTF-8", null); 83 | // webView.setWebViewClient(new WebViewClient(){ 84 | // @Override 85 | // public boolean shouldOverrideUrlLoading(WebView view, String url) { 86 | // view.loadUrl(url); 87 | // return true; 88 | // } 89 | // }); 90 | } 91 | 92 | 93 | }; 94 | 95 | GetData.getInstance().getzhihudnews(subscriber,newsid); 96 | } 97 | 98 | public boolean onKeyDown(int keyCode, KeyEvent event) { 99 | if ((keyCode == KEYCODE_BACK) && webView.canGoBack()) { 100 | webView.goBack(); 101 | return true; 102 | } 103 | return super.onKeyDown(keyCode, event); 104 | } 105 | 106 | @Override 107 | public boolean onOptionsItemSelected(MenuItem item) { 108 | switch (item.getItemId()) { 109 | case android.R.id.home: 110 | onBackPressed(); 111 | return true; 112 | default: 113 | break; 114 | } 115 | return super.onOptionsItemSelected(item); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/fragment/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.fragment; 2 | 3 | import android.app.Fragment; 4 | 5 | /** 6 | * Created by gz on 16/11/2. 7 | */ 8 | 9 | public class BaseFragment extends Fragment { 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/fragment/BlogFragment.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.fragment; 2 | 3 | 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.LinearLayoutManager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import com.gx.learn.R; 14 | import com.gx.learn.adapter.Blogadapter; 15 | import com.gx.learn.model.Android; 16 | import com.gx.learn.net.GetData; 17 | import com.gx.learn.view.activity.WebActivity; 18 | import com.jude.easyrecyclerview.EasyRecyclerView; 19 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter; 20 | 21 | import java.util.List; 22 | 23 | import rx.Subscriber; 24 | 25 | /** 26 | * A simple {@link Fragment} subclass. 27 | */ 28 | public class BlogFragment extends Fragment { 29 | private static final String TAG = "BlogFragment"; 30 | private EasyRecyclerView recyclerView; 31 | private SwipeRefreshLayout swipeRefreshLayout; 32 | private Blogadapter blogadapter; 33 | private LinearLayoutManager linearLayoutManager; 34 | private int page = 1; 35 | 36 | public BlogFragment() { 37 | } 38 | @Override 39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 40 | Bundle savedInstanceState) { 41 | View view = inflater.inflate(R.layout.fragment_blog, container, false); 42 | recyclerView = (EasyRecyclerView) view.findViewById(R.id.recycleview); 43 | linearLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL,false); 44 | recyclerView.setLayoutManager(linearLayoutManager); 45 | blogadapter = new Blogadapter(getContext()); 46 | recyclerView.setAdapter(blogadapter); 47 | swipeRefreshLayout=(SwipeRefreshLayout)view.findViewById(R.id.swiprefresh2) ; 48 | swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light); 49 | init(); 50 | return view; 51 | 52 | } 53 | 54 | private void init() { 55 | swipeRefreshLayout.post(new Runnable() { 56 | @Override 57 | public void run() { 58 | swipeRefreshLayout.setRefreshing(true); 59 | getBlogData(); 60 | } 61 | }); 62 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 63 | @Override 64 | public void onRefresh() { 65 | swipeRefreshLayout.postDelayed(new Runnable() { 66 | @Override 67 | public void run() { 68 | swipeRefreshLayout.setRefreshing(true); 69 | blogadapter.clear(); 70 | page = 1; 71 | getBlogData(); 72 | } 73 | },1000); 74 | } 75 | }); 76 | blogadapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() { 77 | @Override 78 | public void onMoreShow() { 79 | getBlogData(); 80 | } 81 | 82 | @Override 83 | public void onMoreClick() { 84 | 85 | } 86 | }); 87 | blogadapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() { 88 | @Override 89 | public void onItemClick(int position) { 90 | Intent intent = new Intent(getActivity(),WebActivity.class); 91 | intent.putExtra("url",blogadapter.getItem(position).url); 92 | intent.putExtra("title",blogadapter.getItem(position).desc); 93 | startActivity(intent); 94 | } 95 | }); 96 | } 97 | 98 | private void getBlogData() { 99 | Subscriber> subscriber2 = new Subscriber>() { 100 | @Override 101 | public void onCompleted() { 102 | swipeRefreshLayout.setRefreshing(false); 103 | } 104 | 105 | @Override 106 | public void onError(Throwable e) { 107 | System.out.println("88888"); 108 | } 109 | 110 | @Override 111 | public void onNext(List androids) { 112 | // System.out.println(androids.get(0).url); 113 | blogadapter.addAll(androids); 114 | } 115 | }; 116 | GetData.getInstance() 117 | .getblogdata(subscriber2,page); 118 | page++; 119 | } 120 | 121 | 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/java/com/gx/learn/view/fragment/MeiziFragment.java: -------------------------------------------------------------------------------- 1 | package com.gx.learn.view.fragment; 2 | 3 | 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.widget.SwipeRefreshLayout; 8 | import android.support.v7.widget.StaggeredGridLayoutManager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import com.gx.learn.R; 14 | import com.gx.learn.adapter.Meiziadapter; 15 | import com.gx.learn.model.Gril; 16 | import com.gx.learn.net.GetData; 17 | import com.gx.learn.view.activity.ImageActivity; 18 | import com.jude.easyrecyclerview.EasyRecyclerView; 19 | import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter; 20 | 21 | import java.util.List; 22 | 23 | import rx.Subscriber; 24 | 25 | /** 26 | * A simple {@link Fragment} subclass. 27 | */ 28 | public class MeiziFragment extends Fragment { 29 | private static final String TAG = "MeiziFragment"; 30 | private EasyRecyclerView recyclerView; 31 | private SwipeRefreshLayout swipeRefreshLayout; 32 | private Meiziadapter meiziadapter; 33 | private StaggeredGridLayoutManager staggeredGridLayoutManager; 34 | private int page = 1; 35 | 36 | public MeiziFragment() { 37 | } 38 | @Override 39 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 40 | Bundle savedInstanceState) { 41 | View view = inflater.inflate(R.layout.fragment_meizi, container, false); 42 | recyclerView = (EasyRecyclerView) view.findViewById(R.id.recycleview); 43 | staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); 44 | recyclerView.setLayoutManager(staggeredGridLayoutManager); 45 | meiziadapter = new Meiziadapter(getContext()); 46 | recyclerView.setAdapter(meiziadapter); 47 | swipeRefreshLayout=(SwipeRefreshLayout)view.findViewById(R.id.swiprefresh) ; 48 | swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light); 49 | init(); 50 | return view; 51 | } 52 | 53 | private void init() { 54 | swipeRefreshLayout.post(new Runnable() { 55 | @Override 56 | public void run() { 57 | swipeRefreshLayout.setRefreshing(true); 58 | getGirlData(); 59 | } 60 | }); 61 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 62 | @Override 63 | public void onRefresh() { 64 | swipeRefreshLayout.postDelayed(new Runnable() { 65 | @Override 66 | public void run() { 67 | swipeRefreshLayout.setRefreshing(true); 68 | meiziadapter.clear(); 69 | page = 1; 70 | getGirlData(); 71 | } 72 | },1000); 73 | } 74 | }); 75 | meiziadapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() { 76 | @Override 77 | public void onMoreShow() { 78 | getGirlData(); 79 | } 80 | 81 | @Override 82 | public void onMoreClick() { 83 | 84 | } 85 | }); 86 | meiziadapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() { 87 | @Override 88 | public void onItemClick(int position) { 89 | Intent intent = new Intent(getActivity(), ImageActivity.class); 90 | intent.putExtra("url",meiziadapter.getItem(position).Url); 91 | intent.putExtra("desc",meiziadapter.getItem(position).descr); 92 | startActivity(intent); 93 | 94 | } 95 | }); 96 | } 97 | 98 | 99 | private void getGirlData() { 100 | Subscriber> subscriber = new Subscriber>() { 101 | @Override 102 | public void onCompleted() { 103 | swipeRefreshLayout.setRefreshing(false); 104 | } 105 | 106 | @Override 107 | public void onError(Throwable e) { 108 | System.out.println("2222"); 109 | } 110 | 111 | @Override 112 | public void onNext(List grils) { 113 | meiziadapter.addAll(grils); 114 | //System.out.println(grils.get(0).Url); 115 | } 116 | }; 117 | GetData.getInstance() 118 | .getmeizidata(subscriber,page); 119 | page++; 120 | 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_camera.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_gallery.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_send.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_share.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/ic_menu_slideshow.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/about_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/about_icon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/about_img.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/about_img.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/copy.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/firstonegril.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/firstonegril.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/header.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/logo_one.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/logo_one.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/save.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/share.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/share.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/zhihu_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/drawable/zhihu_icon.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 17 | 24 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_image.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 27 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 16 | 17 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_web.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 24 | 29 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_zhihu.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 21 | 22 | 23 | 24 | 30 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_zhihunews.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 15 | 16 | 24 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 47 | 48 | 52 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/res/layout/androidblog_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 17 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 17 | 18 | 31 | 32 | 43 | 44 | 45 | 55 | 56 | 57 | 67 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_blog.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_meizi.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/girl_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/layout/nav_header_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/layout/view_more.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/zhihu_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 18 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/layout/zhihuheader.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_main_drawer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main_meizi.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/menu/main_web.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | 11 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_about.xml: -------------------------------------------------------------------------------- 1 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GxYuqi/LearnProject/4d3cf3ab2eec7b511fa7a15571769955ff5b5d8c/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #5F5F62 5 | #008fed 6 | #FF4081 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 160dp 5 | 6 | 16dp 7 | 16dp 8 | 16dp 9 | 180dp 10 | 16dp 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/values/drawables.xml: -------------------------------------------------------------------------------- 1 | 2 | @android:drawable/ic_menu_camera 3 | @android:drawable/ic_menu_gallery 4 | @android:drawable/ic_menu_slideshow 5 | @android:drawable/ic_menu_manage 6 | @android:drawable/ic_menu_share 7 | @android:drawable/ic_menu_send 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Learn 3 | 4 | Open navigation drawer 5 | Close navigation drawer 6 | 7 | Settings 8 | 9 | Hello blank fragment 10 | 知乎 11 | 关于 12 | who 13 | ImageActivity 14 | save 15 | WebActivity 16 | AboutActivity 17 | 版本号:1.0 \n网络请求:Retrofit + Rxjava + RxAndroid \n框架: MVC 设计模式 \ngithub地址: ↓↓↓\nhttps://github.com/developergx/LearnProject 18 | Gx练手小项目 19 | 该项目是本人练习 MVC 结合 Retrofit+RxJava 的一个产物\n后期可能会更新到 MVP 设计模式 20 | 妹子图和 Android 博客的 API 来自于 Gank.io\n感谢干货集中营!\n知乎日报 API 并非知乎官方提供,如有侵权,本人会立即删除,感谢 21 | 感谢 iconfont 提供素材! 22 | ZhihuActivity 23 | ZhihunewsActivity 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 | 20 | 21 |