├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── toryang
│ │ └── sampledemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── toryang
│ │ │ └── sampledemo
│ │ │ ├── App.java
│ │ │ ├── api
│ │ │ ├── InitRetrofit.java
│ │ │ └── NetService.java
│ │ │ ├── common
│ │ │ ├── OkHttp3Downloader.java
│ │ │ └── OkhttpUtil.java
│ │ │ ├── config
│ │ │ └── IPAddress.java
│ │ │ ├── entities
│ │ │ ├── movieEntitiy
│ │ │ │ ├── Avatars.java
│ │ │ │ ├── Avatars_.java
│ │ │ │ ├── Cast.java
│ │ │ │ ├── Director.java
│ │ │ │ ├── Images.java
│ │ │ │ ├── Rating.java
│ │ │ │ ├── Subject.java
│ │ │ │ └── movieinfo.java
│ │ │ └── usbox
│ │ │ │ ├── Avatars.java
│ │ │ │ ├── Avatars_.java
│ │ │ │ ├── Cast.java
│ │ │ │ ├── Director.java
│ │ │ │ ├── Images.java
│ │ │ │ ├── Rating.java
│ │ │ │ ├── Subject.java
│ │ │ │ ├── Subject_.java
│ │ │ │ └── UsBoxEntity.java
│ │ │ ├── loading
│ │ │ ├── MyLoading.java
│ │ │ └── SingleBall.java
│ │ │ ├── presenter
│ │ │ ├── BasePresenter.java
│ │ │ ├── HotMoviePresenterImpl.java
│ │ │ ├── Presenter.java
│ │ │ └── Top250PresenterImpl.java
│ │ │ ├── ui
│ │ │ ├── BaseActivity.java
│ │ │ ├── BaseFragment.java
│ │ │ ├── activity
│ │ │ │ ├── GridMovieActivity.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MovieInfoActivity.java
│ │ │ ├── adapter
│ │ │ │ ├── GridAdapter.java
│ │ │ │ ├── GridItemClick.java
│ │ │ │ ├── GridSpacingItemDecoration.java
│ │ │ │ ├── LoopAdapter.java
│ │ │ │ ├── OutRecyclerAdapter.java
│ │ │ │ └── ViewpagerAdapter.java
│ │ │ ├── fragment
│ │ │ │ ├── HotMovieFragment.java
│ │ │ │ └── TopMovFragment.java
│ │ │ └── view
│ │ │ │ ├── DataView.java
│ │ │ │ ├── MvpView.java
│ │ │ │ └── TopDataView.java
│ │ │ └── utils
│ │ │ ├── Log.java
│ │ │ ├── NetworkUtils.java
│ │ │ └── Util.java
│ └── res
│ │ ├── anim
│ │ ├── left_out.xml
│ │ └── right_in.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-xxhdpi
│ │ ├── img1.jpg
│ │ ├── img2.jpg
│ │ ├── img3.jpg
│ │ ├── img4.jpg
│ │ ├── img5.jpg
│ │ ├── point_focus.png
│ │ ├── point_normal.png
│ │ └── side_nav_bar.xml
│ │ ├── layout
│ │ ├── activity_gridmovie.xml
│ │ ├── activity_main.xml
│ │ ├── activity_movieinfo.xml
│ │ ├── app_bar_main.xml
│ │ ├── content_main.xml
│ │ ├── custom_viewpager.xml
│ │ ├── fragment_hotmovie.xml
│ │ ├── item_movie.xml
│ │ ├── menu_movie.xml
│ │ ├── nav_header_main.xml
│ │ └── single_ball_loading.xml
│ │ ├── menu
│ │ ├── activity_main_drawer.xml
│ │ └── main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── movie.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── arrays.xml
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── drawables.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── toryang
│ └── sampledemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── 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 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | SampleDemo
--------------------------------------------------------------------------------
/.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/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 从零开始开发一款Android App
2 |
3 | MVP project Demo with some open Source Tools
4 |
5 |
6 | [原文链接](http://www.jianshu.com/p/a58d15ef5c8b)
7 |
8 | >最近准备开始写一个系列的Android开发blogs,算是对之前开发做一些总结,预计会写十一篇,以下为文章目录:(持续更新中!)
9 |
10 | **入门篇:**
11 | [第一篇:开发环境篇](http://www.jianshu.com/p/b20c9c6993f5)
12 | [第二篇:材料设计篇](http://www.jianshu.com/p/47b81f3a0b31)
13 | [第三篇:规范开发篇](http://www.jianshu.com/p/be0d9c0908f2)
14 | [第四篇:从项目开发到上架篇](http://www.jianshu.com/p/8b0483510bf9)(篇章调整,最后更新)
15 |
16 | **进阶篇:**
17 | [第五篇:设计模式篇](http://www.jianshu.com/p/fa92ca51bdb0)
18 | [第六篇:网络请求篇(上)](http://www.jianshu.com/p/b084b6d91260)
19 | [网络请求篇(下)](http://www.jianshu.com/p/4c0b9793d0b7)
20 | [第七篇:图片处理篇](http://www.jianshu.com/p/9b93737bfa88)
21 | [第八篇:数据库篇](http://www.jianshu.com/p/260dda970e19)
22 | [第九篇:开源资源篇](http://www.jianshu.com/p/bf78e484fc4e)
23 |
24 | **高阶篇:**
25 | [第十篇:自定义控件篇](http://www.jianshu.com/p/2266c6b82cb3)
26 | [第十一篇:跨进程篇](http://www.jianshu.com/p/a4a5ca43ce97)
27 |
28 | ##关于Demo
29 | * 写这个系列的文章的同时,也在做一个小Demo。功能很简单,利用豆瓣电影Api实现一款基于Android的电影集合的App。[star me on GitHub!](https://github.com/ToryangChen/SampleDemo)
30 |
31 | * 该项目的数据源来自于[豆瓣](https://developers.douban.com/wiki/?title=guide);
32 |
33 | * 项目用到的第三方类库(博客中写到的类库):[ButterKnife](http://jakewharton.github.io/butterknife/), [RxJava](https://github.com/ReactiveX/RxJava/wiki), [Volley](https://github.com/mcxiaoke/android-volley), [Retrofit2.0](http://square.github.io/retrofit/), [OkHttp](http://square.github.io/okhttp/), [Picasso](http://square.github.io/picasso/), [Fresco](https://github.com/facebook/fresco)等
34 |
35 | 看看目前的效果:
36 |
37 | 
38 |
39 | ##最后的话
40 |
41 | 该系列的文章对Android开发的内容涉及较广,从最基础的开发工具的使用到项目的打包发布,从Android材料设计到网络开发,从数据库的应用到自定义控件。本文也许不能面面俱到地将Android开发的内容全部罗列,但是这一定是对初学者的一份学习大纲。如果读者对其他方面的开发内容有需求,可以在评论留言,我将整理出来分享给大家。感谢大家的支持!
42 |
43 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'com.neenbedankt.android-apt'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.3"
7 |
8 | signingConfigs {
9 | release {
10 | storeFile file("SampleDemo.jks")
11 | storePassword "123456"
12 | keyAlias "Demo"
13 | keyPassword "123456"
14 | }
15 | }
16 | defaultConfig {
17 | applicationId "com.toryang.sampledemo"
18 | minSdkVersion 15
19 | targetSdkVersion 23
20 | versionCode 1
21 | versionName "1.0"
22 | }
23 | buildTypes {
24 | debug {
25 | signingConfig signingConfigs.release
26 | }
27 | release {
28 | signingConfig signingConfigs.release
29 | minifyEnabled true
30 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
31 | }
32 | }
33 | }
34 |
35 | dependencies {
36 | compile fileTree(dir: 'libs', include: ['*.jar'])
37 | testCompile 'junit:junit:4.12'
38 | compile 'com.android.support:appcompat-v7:23.3.0'
39 | compile 'com.android.support:design:23.3.0'
40 | compile 'com.android.support:cardview-v7:23.3.0'
41 |
42 | compile 'com.jakewharton:butterknife:8.0.0'
43 | apt 'com.jakewharton:butterknife-compiler:8.0.0'
44 | compile 'com.jude:rollviewpager:1.2.9'
45 |
46 | compile 'io.reactivex:rxandroid:1.1.0'
47 | compile 'io.reactivex:rxjava:1.1.3'
48 |
49 | compile 'com.squareup.retrofit2:retrofit:2.0.2'
50 | compile 'com.squareup.retrofit2:converter-gson:2.0.2'
51 | compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
52 |
53 | compile 'com.squareup.okhttp3:okhttp:3.2.0'
54 | compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
55 | compile 'com.squareup.okio:okio:1.8.0'
56 |
57 |
58 | compile 'com.mcxiaoke.volley:library:1.0.19'
59 |
60 | compile 'com.squareup.picasso:picasso:2.5.2'
61 | compile 'com.facebook.fresco:fresco:0.10.0'
62 | compile 'de.hdodenhof:circleimageview:2.0.0'
63 | }
64 |
--------------------------------------------------------------------------------
/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 /Users/toryang/Library/Android/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/toryang/sampledemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/App.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo;
2 |
3 | import android.app.Application;
4 |
5 | import com.facebook.drawee.backends.pipeline.Fresco;
6 | import com.squareup.picasso.Picasso;
7 | import com.toryang.sampledemo.common.OkHttp3Downloader;
8 |
9 | import okhttp3.OkHttpClient;
10 |
11 | /**
12 | * Created by toryang on 16/4/28.
13 | */
14 | public class App extends Application {
15 |
16 | private static App instace;
17 |
18 | public static App getInstace(){
19 | return instace;
20 | }
21 |
22 | public static Picasso mPicasso;
23 | @Override
24 | public void onCreate() {
25 | super.onCreate();
26 | instace = this;
27 | setUpPicasso();
28 | Fresco.initialize(this);
29 | }
30 |
31 | public void setUpPicasso(){
32 |
33 | Picasso picasso = new Picasso.Builder(this)
34 | .downloader(new OkHttp3Downloader(new OkHttpClient()))
35 | .build();
36 | Picasso.setSingletonInstance(picasso);
37 | mPicasso = picasso;
38 | }
39 |
40 | public static Picasso getPicasso(){
41 | return mPicasso;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/api/InitRetrofit.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.api;
2 |
3 | import com.toryang.sampledemo.config.IPAddress;
4 | import com.toryang.sampledemo.utils.Log;
5 |
6 | import java.io.IOException;
7 |
8 | import okhttp3.Interceptor;
9 | import okhttp3.MediaType;
10 | import okhttp3.OkHttpClient;
11 | import okhttp3.Request;
12 | import okhttp3.RequestBody;
13 | import okhttp3.Response;
14 | import okhttp3.logging.HttpLoggingInterceptor;
15 | import okio.BufferedSink;
16 | import okio.GzipSink;
17 | import okio.Okio;
18 | import retrofit2.Retrofit;
19 | import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
20 | import retrofit2.converter.gson.GsonConverterFactory;
21 |
22 | /**
23 | * Created by toryang on 16/4/26.
24 | */
25 | public class InitRetrofit {
26 |
27 | static Log log = Log.YLog();
28 |
29 | private static OkHttpClient client = new OkHttpClient
30 | .Builder()
31 | // .addNetworkInterceptor(new HeaderInterceptor())
32 | .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
33 | .addInterceptor(new GzipRequsetInterceptor())
34 | .build();
35 |
36 | private static Retrofit retrofit = new Retrofit.Builder()
37 | .baseUrl(IPAddress.url)
38 | .client(client)
39 | .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
40 | .addConverterFactory(GsonConverterFactory.create())
41 | .build();
42 |
43 |
44 | static class LoggingIntercepter implements Interceptor {
45 |
46 | @Override
47 | public Response intercept(Chain chain) throws IOException {
48 | Request request = chain.request();
49 |
50 | long t1 = System.nanoTime();
51 | log.d(String.format("Sending request %s on %s%n%s",
52 | request.url(),chain.connection(),request.headers()));
53 |
54 | Response response = chain.proceed(request);
55 | long t2 = System.nanoTime();
56 | log.d(String.format("Received response for %s in %.1fms%n%s",
57 | response.request().url(),(t2-t1)/1e6d, response.headers()));
58 | return response;
59 | }
60 | }
61 | static class HeaderInterceptor implements Interceptor{
62 |
63 | @Override
64 | public Response intercept(Chain chain) throws IOException {
65 | Request originalRequest = chain.request();
66 | Request compressedRequest = originalRequest.newBuilder()
67 | .addHeader("User-Agent", "SampleDemo/"+ " (android;" + android.os.Build.VERSION.RELEASE + ";" + android.os.Build.MODEL + ")")
68 | .addHeader("Content-Type", "application/x-www-form-urlencoded")
69 | .addHeader("Accept", "*/*")
70 | .build();
71 | return chain.proceed(compressedRequest);
72 | }
73 | }
74 |
75 |
76 | static class GzipRequsetInterceptor implements Interceptor{
77 |
78 | @Override
79 | public Response intercept(Chain chain) throws IOException {
80 | Request originalRequest = chain.request();
81 | if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {
82 | return chain.proceed(originalRequest);
83 | }
84 |
85 | Request compressedRequest = originalRequest.newBuilder()
86 | .header("Content-Encoding","gzip")
87 | .method(originalRequest.method(),gzip(originalRequest.body()))
88 | .build();
89 | return chain.proceed(compressedRequest);
90 | }
91 |
92 | private RequestBody gzip(final RequestBody body){
93 | return new RequestBody() {
94 | @Override
95 | public MediaType contentType() {
96 | log.d("gzip!");
97 | return body.contentType();
98 | }
99 |
100 | @Override
101 | public long contentLength() throws IOException {
102 | return -1;
103 | }
104 |
105 | @Override
106 | public void writeTo(BufferedSink sink) throws IOException {
107 | BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));
108 | body.writeTo(gzipSink);
109 | gzipSink.close();
110 | }
111 | };
112 | }
113 |
114 | }
115 |
116 |
117 |
118 | private InitRetrofit(){
119 |
120 | }
121 |
122 | public static T createApi(Class mClass){
123 |
124 | return retrofit.create(mClass);
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/api/NetService.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.api;
2 |
3 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
4 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
5 |
6 | import retrofit2.http.GET;
7 | import rx.Observable;
8 |
9 | /**
10 | * Created by toryang on 16/4/26.
11 | */
12 | public interface NetService {
13 |
14 | @GET("/v2/movie/us_box")
15 | Observable getHotMovie();
16 |
17 | @GET("/v2/movie/in_theaters")
18 | Observable getInTheaters ();
19 |
20 | @GET("/v2/movie/coming_soon")
21 | Observable getComingSoon();
22 |
23 | @GET("/v2/movie/top250")
24 | Observable getTop250();
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/common/OkHttp3Downloader.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.common;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.os.StatFs;
6 |
7 | import com.squareup.picasso.Downloader;
8 | import com.squareup.picasso.NetworkPolicy;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 |
13 | import okhttp3.Cache;
14 | import okhttp3.CacheControl;
15 | import okhttp3.Call;
16 | import okhttp3.OkHttpClient;
17 | import okhttp3.Request;
18 | import okhttp3.ResponseBody;
19 |
20 | /**
21 | * Created by toryang on 16/4/28.
22 | */
23 | public class OkHttp3Downloader implements Downloader{
24 |
25 | private static final String PICASSO_CACHE = "picasso-cache";
26 | private static final int MIN_DISK_CACHE_SIZE = 5 * 1024 * 1024; // 5MB
27 | private static final int MAX_DISK_CACHE_SIZE = 50 * 1024 * 1024; // 50MB
28 |
29 |
30 | private static File createDefaultCacheDir(Context context){
31 | File cache = new File(context.getApplicationContext().getCacheDir(),PICASSO_CACHE);
32 | if (!cache.exists()){
33 | cache.mkdirs();
34 | }
35 | return cache;
36 | }
37 |
38 | private static long calculateDiskCacheSize(File dir){
39 | long size = MIN_DISK_CACHE_SIZE;
40 |
41 | try{
42 | StatFs statFs = new StatFs(dir.getAbsolutePath());
43 | long available = ((long)statFs.getBlockCount()) * statFs.getBlockSize();
44 | size = available / 50;
45 | }catch (IllegalArgumentException ignored){}
46 |
47 | return Math.max(Math.min(size,MAX_DISK_CACHE_SIZE),MIN_DISK_CACHE_SIZE);
48 | }
49 |
50 |
51 | private static OkHttpClient defaultOkHttpClient(File cacheDir, long maxSize){
52 | return new OkHttpClient.Builder()
53 | .cache(new okhttp3.Cache(cacheDir,maxSize))
54 | .build();
55 | }
56 |
57 | private final Call.Factory client;
58 | private final Cache cache;
59 |
60 | public OkHttp3Downloader(Context context){
61 | this(createDefaultCacheDir(context));
62 | }
63 |
64 |
65 | public OkHttp3Downloader(File cacheDir){
66 | this(cacheDir,calculateDiskCacheSize(cacheDir));
67 | }
68 |
69 | public OkHttp3Downloader(final Context context, final long maxSize) {
70 | this(createDefaultCacheDir(context), maxSize);
71 | }
72 |
73 | public OkHttp3Downloader(File cacheDir, long maxSize) {
74 | this(defaultOkHttpClient(cacheDir, maxSize));
75 | }
76 |
77 | public OkHttp3Downloader(OkHttpClient client) {
78 | this.client = client;
79 | this.cache = client.cache();
80 | }
81 |
82 | public OkHttp3Downloader(Call.Factory client) {
83 | this.client = client;
84 | this.cache = null;
85 | }
86 |
87 | @Override
88 | public Response load(Uri uri, int networkPolicy) throws IOException {
89 | CacheControl cacheControl = null;
90 | if (networkPolicy != 0){
91 | if (NetworkPolicy.isOfflineOnly(networkPolicy)){
92 | cacheControl = CacheControl.FORCE_CACHE;
93 | }else {
94 | CacheControl.Builder builder = new CacheControl.Builder();
95 | if (!NetworkPolicy.shouldReadFromDiskCache(networkPolicy)){
96 | builder.noCache();
97 | }
98 |
99 | if (!NetworkPolicy.shouldWriteToDiskCache(networkPolicy)){
100 | builder.noStore();
101 | }
102 | cacheControl = builder.build();
103 | }
104 | }
105 |
106 | Request.Builder builder = new Request.Builder().url(uri.toString());
107 | if (cacheControl != null){
108 | builder.cacheControl(cacheControl);
109 | }
110 |
111 | okhttp3.Response response = client.newCall(builder.build()).execute();
112 | int responseCode = response.code();
113 | if (responseCode >= 300){
114 | response.body().close();
115 | throw new ResponseException(responseCode + " " + response.message(),networkPolicy,
116 | responseCode);
117 | }
118 |
119 | boolean fromCache = response.cacheResponse() != null;
120 |
121 | ResponseBody responseBody = response.body();
122 | return new Response(responseBody.byteStream(),fromCache,responseBody.contentLength());
123 | }
124 |
125 | @Override
126 | public void shutdown() {
127 | if (cache != null){
128 | try{
129 | cache.close();
130 | }catch (IOException ignored){
131 |
132 | }
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/common/OkhttpUtil.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.common;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 | import android.graphics.drawable.Drawable;
6 | import android.os.Environment;
7 |
8 | import com.toryang.sampledemo.utils.Log;
9 |
10 | import java.io.File;
11 | import java.io.FileOutputStream;
12 | import java.io.IOException;
13 | import java.io.InputStream;
14 | import java.io.OutputStream;
15 | import java.util.Collections;
16 |
17 | import okhttp3.OkHttpClient;
18 | import okhttp3.Protocol;
19 | import okhttp3.Request;
20 | import okhttp3.Response;
21 | import rx.Observable;
22 | import rx.Subscriber;
23 | import rx.android.schedulers.AndroidSchedulers;
24 | import rx.functions.Action1;
25 | import rx.schedulers.Schedulers;
26 |
27 | /**
28 | * Created by toryang on 5/15/16.
29 | */
30 | public class OkhttpUtil {
31 | Log log = Log.YLog();
32 | String url;
33 | public OkhttpUtil(String url){
34 | this.url = url;
35 | }
36 | public void run() throws IOException{
37 | OkHttpClient client = new OkHttpClient();
38 | Request request = new Request.Builder()
39 | .url(url)
40 | .build();
41 | Response response = client.newCall(request).execute();
42 |
43 | log.d(response.body().string());
44 | }
45 |
46 |
47 |
48 | /**
49 | * download bitmap image;
50 | */
51 | public Observable downloadDrawble = Observable.create(new Observable.OnSubscribe() {
52 | @Override
53 | public void call(Subscriber super Bitmap> subscriber) {
54 | OkHttpClient client = new OkHttpClient();
55 | Request request = new Request.Builder()
56 | .url(url)
57 | .build();
58 |
59 | try {
60 | Response response = client.newCall(request).execute();
61 | if (response.isSuccessful()){
62 | InputStream input = response.body().byteStream();
63 | Bitmap bitmap = BitmapFactory.decodeStream(input);
64 | subscriber.onNext(bitmap);
65 | }
66 | }catch (IOException e){
67 | subscriber.onError(e);
68 | }
69 | }
70 | });
71 |
72 |
73 | File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
74 | File file = new File(path,"/pathtofile");
75 |
76 | /**
77 | * download file with OkHttp and RxJava (rate)
78 | */
79 | public Observable downloadObservable = Observable.create(new Observable.OnSubscribe() {
80 | @Override
81 | public void call(Subscriber super String> subscriber) {
82 | InputStream inputStream = null;
83 | OutputStream outputStream = null;
84 | OkHttpClient client = new OkHttpClient();
85 | Request request = new Request.Builder()
86 | .url(url)
87 | .build();
88 | try{
89 | Response response = client.newCall(request).execute();
90 | if (response.isSuccessful()){
91 | inputStream = response.body().byteStream();
92 | long length = response.body().contentLength();
93 | outputStream = new FileOutputStream(file);
94 | byte data[] = new byte[1024];
95 | subscriber.onNext("0%");
96 | long total = 0;
97 | int count;
98 | while ((count = inputStream.read(data)) != -1){
99 | total += count;
100 | subscriber.onNext(String.valueOf(total*100/length) + "%");
101 | outputStream.write(data,0,count);
102 | }
103 | outputStream.flush();
104 | outputStream.close();
105 | inputStream.close();
106 |
107 | }
108 |
109 | }catch (IOException e){
110 | subscriber.onError(e);
111 | }finally {
112 | if (inputStream != null){
113 | try{
114 | inputStream.close();
115 | }catch (IOException e){}
116 | }
117 | if (outputStream != null){
118 | try {
119 | outputStream.close();
120 | }catch (IOException e){}
121 | }
122 | }
123 | subscriber.onCompleted();
124 | }
125 | });
126 | }
127 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/config/IPAddress.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.config;
2 |
3 | /**
4 | * Created by toryang on 16/4/26.
5 | */
6 | public class IPAddress {
7 |
8 | public static final String url = "https://api.douban.com";
9 | public static final String totalUrl = "https://api.douban.com/v2/movie/us_box";
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Avatars.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Avatars_.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars_ {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Cast.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Cast {
8 |
9 | @SerializedName("alt")
10 | @Expose
11 | private String alt;
12 | @SerializedName("avatars")
13 | @Expose
14 | private Avatars avatars;
15 | @SerializedName("name")
16 | @Expose
17 | private String name;
18 | @SerializedName("id")
19 | @Expose
20 | private String id;
21 |
22 | /**
23 | *
24 | * @return
25 | * The alt
26 | */
27 | public String getAlt() {
28 | return alt;
29 | }
30 |
31 | /**
32 | *
33 | * @param alt
34 | * The alt
35 | */
36 | public void setAlt(String alt) {
37 | this.alt = alt;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The avatars
44 | */
45 | public Avatars getAvatars() {
46 | return avatars;
47 | }
48 |
49 | /**
50 | *
51 | * @param avatars
52 | * The avatars
53 | */
54 | public void setAvatars(Avatars avatars) {
55 | this.avatars = avatars;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The name
62 | */
63 | public String getName() {
64 | return name;
65 | }
66 |
67 | /**
68 | *
69 | * @param name
70 | * The name
71 | */
72 | public void setName(String name) {
73 | this.name = name;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The id
80 | */
81 | public String getId() {
82 | return id;
83 | }
84 |
85 | /**
86 | *
87 | * @param id
88 | * The id
89 | */
90 | public void setId(String id) {
91 | this.id = id;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Director.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Director {
8 |
9 | @SerializedName("alt")
10 | @Expose
11 | private String alt;
12 | @SerializedName("avatars")
13 | @Expose
14 | private Avatars_ avatars;
15 | @SerializedName("name")
16 | @Expose
17 | private String name;
18 | @SerializedName("id")
19 | @Expose
20 | private String id;
21 |
22 | /**
23 | *
24 | * @return
25 | * The alt
26 | */
27 | public String getAlt() {
28 | return alt;
29 | }
30 |
31 | /**
32 | *
33 | * @param alt
34 | * The alt
35 | */
36 | public void setAlt(String alt) {
37 | this.alt = alt;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The avatars
44 | */
45 | public Avatars_ getAvatars() {
46 | return avatars;
47 | }
48 |
49 | /**
50 | *
51 | * @param avatars
52 | * The avatars
53 | */
54 | public void setAvatars(Avatars_ avatars) {
55 | this.avatars = avatars;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The name
62 | */
63 | public String getName() {
64 | return name;
65 | }
66 |
67 | /**
68 | *
69 | * @param name
70 | * The name
71 | */
72 | public void setName(String name) {
73 | this.name = name;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The id
80 | */
81 | public String getId() {
82 | return id;
83 | }
84 |
85 | /**
86 | *
87 | * @param id
88 | * The id
89 | */
90 | public void setId(String id) {
91 | this.id = id;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Images.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Images {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Rating.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Rating {
8 |
9 | @SerializedName("max")
10 | @Expose
11 | private Integer max;
12 | @SerializedName("average")
13 | @Expose
14 | private Double average;
15 | @SerializedName("stars")
16 | @Expose
17 | private String stars;
18 | @SerializedName("min")
19 | @Expose
20 | private Integer min;
21 |
22 | /**
23 | *
24 | * @return
25 | * The max
26 | */
27 | public Integer getMax() {
28 | return max;
29 | }
30 |
31 | /**
32 | *
33 | * @param max
34 | * The max
35 | */
36 | public void setMax(Integer max) {
37 | this.max = max;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The average
44 | */
45 | public Double getAverage() {
46 | return average;
47 | }
48 |
49 | /**
50 | *
51 | * @param average
52 | * The average
53 | */
54 | public void setAverage(Double average) {
55 | this.average = average;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The stars
62 | */
63 | public String getStars() {
64 | return stars;
65 | }
66 |
67 | /**
68 | *
69 | * @param stars
70 | * The stars
71 | */
72 | public void setStars(String stars) {
73 | this.stars = stars;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The min
80 | */
81 | public Integer getMin() {
82 | return min;
83 | }
84 |
85 | /**
86 | *
87 | * @param min
88 | * The min
89 | */
90 | public void setMin(Integer min) {
91 | this.min = min;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/Subject.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class Subject {
11 |
12 | @SerializedName("rating")
13 | @Expose
14 | private Rating rating;
15 | @SerializedName("genres")
16 | @Expose
17 | private List genres = new ArrayList();
18 | @SerializedName("title")
19 | @Expose
20 | private String title;
21 | @SerializedName("casts")
22 | @Expose
23 | private List casts = new ArrayList();
24 | @SerializedName("collect_count")
25 | @Expose
26 | private Integer collectCount;
27 | @SerializedName("original_title")
28 | @Expose
29 | private String originalTitle;
30 | @SerializedName("subtype")
31 | @Expose
32 | private String subtype;
33 | @SerializedName("directors")
34 | @Expose
35 | private List directors = new ArrayList();
36 | @SerializedName("year")
37 | @Expose
38 | private String year;
39 | @SerializedName("images")
40 | @Expose
41 | private Images images;
42 | @SerializedName("alt")
43 | @Expose
44 | private String alt;
45 | @SerializedName("id")
46 | @Expose
47 | private String id;
48 |
49 | /**
50 | *
51 | * @return
52 | * The rating
53 | */
54 | public Rating getRating() {
55 | return rating;
56 | }
57 |
58 | /**
59 | *
60 | * @param rating
61 | * The rating
62 | */
63 | public void setRating(Rating rating) {
64 | this.rating = rating;
65 | }
66 |
67 | /**
68 | *
69 | * @return
70 | * The genres
71 | */
72 | public List getGenres() {
73 | return genres;
74 | }
75 |
76 | /**
77 | *
78 | * @param genres
79 | * The genres
80 | */
81 | public void setGenres(List genres) {
82 | this.genres = genres;
83 | }
84 |
85 | /**
86 | *
87 | * @return
88 | * The title
89 | */
90 | public String getTitle() {
91 | return title;
92 | }
93 |
94 | /**
95 | *
96 | * @param title
97 | * The title
98 | */
99 | public void setTitle(String title) {
100 | this.title = title;
101 | }
102 |
103 | /**
104 | *
105 | * @return
106 | * The casts
107 | */
108 | public List getCasts() {
109 | return casts;
110 | }
111 |
112 | /**
113 | *
114 | * @param casts
115 | * The casts
116 | */
117 | public void setCasts(List casts) {
118 | this.casts = casts;
119 | }
120 |
121 | /**
122 | *
123 | * @return
124 | * The collectCount
125 | */
126 | public Integer getCollectCount() {
127 | return collectCount;
128 | }
129 |
130 | /**
131 | *
132 | * @param collectCount
133 | * The collect_count
134 | */
135 | public void setCollectCount(Integer collectCount) {
136 | this.collectCount = collectCount;
137 | }
138 |
139 | /**
140 | *
141 | * @return
142 | * The originalTitle
143 | */
144 | public String getOriginalTitle() {
145 | return originalTitle;
146 | }
147 |
148 | /**
149 | *
150 | * @param originalTitle
151 | * The original_title
152 | */
153 | public void setOriginalTitle(String originalTitle) {
154 | this.originalTitle = originalTitle;
155 | }
156 |
157 | /**
158 | *
159 | * @return
160 | * The subtype
161 | */
162 | public String getSubtype() {
163 | return subtype;
164 | }
165 |
166 | /**
167 | *
168 | * @param subtype
169 | * The subtype
170 | */
171 | public void setSubtype(String subtype) {
172 | this.subtype = subtype;
173 | }
174 |
175 | /**
176 | *
177 | * @return
178 | * The directors
179 | */
180 | public List getDirectors() {
181 | return directors;
182 | }
183 |
184 | /**
185 | *
186 | * @param directors
187 | * The directors
188 | */
189 | public void setDirectors(List directors) {
190 | this.directors = directors;
191 | }
192 |
193 | /**
194 | *
195 | * @return
196 | * The year
197 | */
198 | public String getYear() {
199 | return year;
200 | }
201 |
202 | /**
203 | *
204 | * @param year
205 | * The year
206 | */
207 | public void setYear(String year) {
208 | this.year = year;
209 | }
210 |
211 | /**
212 | *
213 | * @return
214 | * The images
215 | */
216 | public Images getImages() {
217 | return images;
218 | }
219 |
220 | /**
221 | *
222 | * @param images
223 | * The images
224 | */
225 | public void setImages(Images images) {
226 | this.images = images;
227 | }
228 |
229 | /**
230 | *
231 | * @return
232 | * The alt
233 | */
234 | public String getAlt() {
235 | return alt;
236 | }
237 |
238 | /**
239 | *
240 | * @param alt
241 | * The alt
242 | */
243 | public void setAlt(String alt) {
244 | this.alt = alt;
245 | }
246 |
247 | /**
248 | *
249 | * @return
250 | * The id
251 | */
252 | public String getId() {
253 | return id;
254 | }
255 |
256 | /**
257 | *
258 | * @param id
259 | * The id
260 | */
261 | public void setId(String id) {
262 | this.id = id;
263 | }
264 |
265 | }
266 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/movieEntitiy/movieinfo.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.movieEntitiy;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class Movieinfo {
11 |
12 | @SerializedName("count")
13 | @Expose
14 | private Integer count;
15 | @SerializedName("start")
16 | @Expose
17 | private Integer start;
18 | @SerializedName("total")
19 | @Expose
20 | private Integer total;
21 |
22 | @SerializedName("subjects")
23 | @Expose
24 | private List subjects = new ArrayList();
25 | @SerializedName("title")
26 | @Expose
27 | private String title;
28 |
29 |
30 | /**
31 | *
32 | * @return
33 | * The count
34 | */
35 | public Integer getCount() {
36 | return count;
37 | }
38 |
39 | /**
40 | *
41 | * @param count
42 | * The count
43 | */
44 | public void setCount(Integer count) {
45 | this.count = count;
46 | }
47 |
48 | /**
49 | *
50 | * @return
51 | * The start
52 | */
53 | public Integer getStart() {
54 | return start;
55 | }
56 |
57 | /**
58 | *
59 | * @param start
60 | * The start
61 | */
62 | public void setStart(Integer start) {
63 | this.start = start;
64 | }
65 |
66 | /**
67 | *
68 | * @return
69 | * The total
70 | */
71 | public Integer getTotal() {
72 | return total;
73 | }
74 |
75 | /**
76 | *
77 | * @param total
78 | * The total
79 | */
80 | public void setTotal(Integer total) {
81 | this.total = total;
82 | }
83 |
84 | /**
85 | *
86 | * @return
87 | * The subjects
88 | */
89 | public List getSubjects() {
90 | return subjects;
91 | }
92 |
93 | /**
94 | *
95 | * @param subjects
96 | * The subject
97 | */
98 | public void setSubjects(List subjects) {
99 | this.subjects = subjects;
100 | }
101 |
102 | /**
103 | *
104 | * @return
105 | * The title
106 | */
107 | public String getTitle() {
108 | return title;
109 | }
110 |
111 | /**
112 | *
113 | * @param title
114 | * The title
115 | */
116 | public void setTitle(String title) {
117 | this.title = title;
118 | }
119 |
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Avatars.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Avatars_.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Avatars_ {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Cast.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 |
8 | public class Cast {
9 |
10 | @SerializedName("alt")
11 | @Expose
12 | private String alt;
13 | @SerializedName("avatars")
14 | @Expose
15 | private Avatars avatars;
16 | @SerializedName("name")
17 | @Expose
18 | private String name;
19 | @SerializedName("id")
20 | @Expose
21 | private String id;
22 |
23 | /**
24 | *
25 | * @return
26 | * The alt
27 | */
28 | public String getAlt() {
29 | return alt;
30 | }
31 |
32 | /**
33 | *
34 | * @param alt
35 | * The alt
36 | */
37 | public void setAlt(String alt) {
38 | this.alt = alt;
39 | }
40 |
41 | /**
42 | *
43 | * @return
44 | * The avatars
45 | */
46 | public Avatars getAvatars() {
47 | return avatars;
48 | }
49 |
50 | /**
51 | *
52 | * @param avatars
53 | * The avatars
54 | */
55 | public void setAvatars(Avatars avatars) {
56 | this.avatars = avatars;
57 | }
58 |
59 | /**
60 | *
61 | * @return
62 | * The name
63 | */
64 | public String getName() {
65 | return name;
66 | }
67 |
68 | /**
69 | *
70 | * @param name
71 | * The name
72 | */
73 | public void setName(String name) {
74 | this.name = name;
75 | }
76 |
77 | /**
78 | *
79 | * @return
80 | * The id
81 | */
82 | public String getId() {
83 | return id;
84 | }
85 |
86 | /**
87 | *
88 | * @param id
89 | * The id
90 | */
91 | public void setId(String id) {
92 | this.id = id;
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Director.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Director {
8 |
9 | @SerializedName("alt")
10 | @Expose
11 | private String alt;
12 | @SerializedName("avatars")
13 | @Expose
14 | private Avatars_ avatars;
15 | @SerializedName("name")
16 | @Expose
17 | private String name;
18 | @SerializedName("id")
19 | @Expose
20 | private String id;
21 |
22 | /**
23 | *
24 | * @return
25 | * The alt
26 | */
27 | public String getAlt() {
28 | return alt;
29 | }
30 |
31 | /**
32 | *
33 | * @param alt
34 | * The alt
35 | */
36 | public void setAlt(String alt) {
37 | this.alt = alt;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The avatars
44 | */
45 | public Avatars_ getAvatars() {
46 | return avatars;
47 | }
48 |
49 | /**
50 | *
51 | * @param avatars
52 | * The avatars
53 | */
54 | public void setAvatars(Avatars_ avatars) {
55 | this.avatars = avatars;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The name
62 | */
63 | public String getName() {
64 | return name;
65 | }
66 |
67 | /**
68 | *
69 | * @param name
70 | * The name
71 | */
72 | public void setName(String name) {
73 | this.name = name;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The id
80 | */
81 | public String getId() {
82 | return id;
83 | }
84 |
85 | /**
86 | *
87 | * @param id
88 | * The id
89 | */
90 | public void setId(String id) {
91 | this.id = id;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Images.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Images {
8 |
9 | @SerializedName("small")
10 | @Expose
11 | private String small;
12 | @SerializedName("large")
13 | @Expose
14 | private String large;
15 | @SerializedName("medium")
16 | @Expose
17 | private String medium;
18 |
19 | /**
20 | *
21 | * @return
22 | * The small
23 | */
24 | public String getSmall() {
25 | return small;
26 | }
27 |
28 | /**
29 | *
30 | * @param small
31 | * The small
32 | */
33 | public void setSmall(String small) {
34 | this.small = small;
35 | }
36 |
37 | /**
38 | *
39 | * @return
40 | * The large
41 | */
42 | public String getLarge() {
43 | return large;
44 | }
45 |
46 | /**
47 | *
48 | * @param large
49 | * The large
50 | */
51 | public void setLarge(String large) {
52 | this.large = large;
53 | }
54 |
55 | /**
56 | *
57 | * @return
58 | * The medium
59 | */
60 | public String getMedium() {
61 | return medium;
62 | }
63 |
64 | /**
65 | *
66 | * @param medium
67 | * The medium
68 | */
69 | public void setMedium(String medium) {
70 | this.medium = medium;
71 | }
72 |
73 | }
74 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Rating.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Rating {
8 |
9 | @SerializedName("max")
10 | @Expose
11 | private Integer max;
12 | @SerializedName("average")
13 | @Expose
14 | private Double average;
15 | @SerializedName("stars")
16 | @Expose
17 | private String stars;
18 | @SerializedName("min")
19 | @Expose
20 | private Integer min;
21 |
22 | /**
23 | *
24 | * @return
25 | * The max
26 | */
27 | public Integer getMax() {
28 | return max;
29 | }
30 |
31 | /**
32 | *
33 | * @param max
34 | * The max
35 | */
36 | public void setMax(Integer max) {
37 | this.max = max;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The average
44 | */
45 | public Double getAverage() {
46 | return average;
47 | }
48 |
49 | /**
50 | *
51 | * @param average
52 | * The average
53 | */
54 | public void setAverage(Double average) {
55 | this.average = average;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The stars
62 | */
63 | public String getStars() {
64 | return stars;
65 | }
66 |
67 | /**
68 | *
69 | * @param stars
70 | * The stars
71 | */
72 | public void setStars(String stars) {
73 | this.stars = stars;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The min
80 | */
81 | public Integer getMin() {
82 | return min;
83 | }
84 |
85 | /**
86 | *
87 | * @param min
88 | * The min
89 | */
90 | public void setMin(Integer min) {
91 | this.min = min;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Subject.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Subject {
8 |
9 | @SerializedName("box")
10 | @Expose
11 | private Integer box;
12 | @SerializedName("new")
13 | @Expose
14 | private Boolean _new;
15 | @SerializedName("rank")
16 | @Expose
17 | private Integer rank;
18 | @SerializedName("subject")
19 | @Expose
20 | private Subject_ subject;
21 |
22 | /**
23 | *
24 | * @return
25 | * The box
26 | */
27 | public Integer getBox() {
28 | return box;
29 | }
30 |
31 | /**
32 | *
33 | * @param box
34 | * The box
35 | */
36 | public void setBox(Integer box) {
37 | this.box = box;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The _new
44 | */
45 | public Boolean getNew() {
46 | return _new;
47 | }
48 |
49 | /**
50 | *
51 | * @param _new
52 | * The new
53 | */
54 | public void setNew(Boolean _new) {
55 | this._new = _new;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The rank
62 | */
63 | public Integer getRank() {
64 | return rank;
65 | }
66 |
67 | /**
68 | *
69 | * @param rank
70 | * The rank
71 | */
72 | public void setRank(Integer rank) {
73 | this.rank = rank;
74 | }
75 |
76 | /**
77 | *
78 | * @return
79 | * The subject
80 | */
81 | public Subject_ getSubject() {
82 | return subject;
83 | }
84 |
85 | /**
86 | *
87 | * @param subject
88 | * The subject
89 | */
90 | public void setSubject(Subject_ subject) {
91 | this.subject = subject;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/Subject_.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class Subject_ {
11 |
12 | @SerializedName("rating")
13 | @Expose
14 | private Rating rating;
15 | @SerializedName("genres")
16 | @Expose
17 | private List genres = new ArrayList();
18 | @SerializedName("title")
19 | @Expose
20 | private String title;
21 | @SerializedName("casts")
22 | @Expose
23 | private List casts = new ArrayList();
24 | @SerializedName("collect_count")
25 | @Expose
26 | private Integer collectCount;
27 | @SerializedName("original_title")
28 | @Expose
29 | private String originalTitle;
30 | @SerializedName("subtype")
31 | @Expose
32 | private String subtype;
33 | @SerializedName("directors")
34 | @Expose
35 | private List directors = new ArrayList();
36 | @SerializedName("year")
37 | @Expose
38 | private String year;
39 | @SerializedName("images")
40 | @Expose
41 | private Images images;
42 | @SerializedName("alt")
43 | @Expose
44 | private String alt;
45 | @SerializedName("id")
46 | @Expose
47 | private String id;
48 |
49 | /**
50 | *
51 | * @return
52 | * The rating
53 | */
54 | public Rating getRating() {
55 | return rating;
56 | }
57 |
58 | /**
59 | *
60 | * @param rating
61 | * The rating
62 | */
63 | public void setRating(Rating rating) {
64 | this.rating = rating;
65 | }
66 |
67 | /**
68 | *
69 | * @return
70 | * The genres
71 | */
72 | public List getGenres() {
73 | return genres;
74 | }
75 |
76 | /**
77 | *
78 | * @param genres
79 | * The genres
80 | */
81 | public void setGenres(List genres) {
82 | this.genres = genres;
83 | }
84 |
85 | /**
86 | *
87 | * @return
88 | * The title
89 | */
90 | public String getTitle() {
91 | return title;
92 | }
93 |
94 | /**
95 | *
96 | * @param title
97 | * The title
98 | */
99 | public void setTitle(String title) {
100 | this.title = title;
101 | }
102 |
103 | /**
104 | *
105 | * @return
106 | * The casts
107 | */
108 | public List getCasts() {
109 | return casts;
110 | }
111 |
112 | /**
113 | *
114 | * @param casts
115 | * The casts
116 | */
117 | public void setCasts(List casts) {
118 | this.casts = casts;
119 | }
120 |
121 | /**
122 | *
123 | * @return
124 | * The collectCount
125 | */
126 | public Integer getCollectCount() {
127 | return collectCount;
128 | }
129 |
130 | /**
131 | *
132 | * @param collectCount
133 | * The collect_count
134 | */
135 | public void setCollectCount(Integer collectCount) {
136 | this.collectCount = collectCount;
137 | }
138 |
139 | /**
140 | *
141 | * @return
142 | * The originalTitle
143 | */
144 | public String getOriginalTitle() {
145 | return originalTitle;
146 | }
147 |
148 | /**
149 | *
150 | * @param originalTitle
151 | * The original_title
152 | */
153 | public void setOriginalTitle(String originalTitle) {
154 | this.originalTitle = originalTitle;
155 | }
156 |
157 | /**
158 | *
159 | * @return
160 | * The subtype
161 | */
162 | public String getSubtype() {
163 | return subtype;
164 | }
165 |
166 | /**
167 | *
168 | * @param subtype
169 | * The subtype
170 | */
171 | public void setSubtype(String subtype) {
172 | this.subtype = subtype;
173 | }
174 |
175 | /**
176 | *
177 | * @return
178 | * The directors
179 | */
180 | public List getDirectors() {
181 | return directors;
182 | }
183 |
184 | /**
185 | *
186 | * @param directors
187 | * The directors
188 | */
189 | public void setDirectors(List directors) {
190 | this.directors = directors;
191 | }
192 |
193 | /**
194 | *
195 | * @return
196 | * The year
197 | */
198 | public String getYear() {
199 | return year;
200 | }
201 |
202 | /**
203 | *
204 | * @param year
205 | * The year
206 | */
207 | public void setYear(String year) {
208 | this.year = year;
209 | }
210 |
211 | /**
212 | *
213 | * @return
214 | * The images
215 | */
216 | public Images getImages() {
217 | return images;
218 | }
219 |
220 | /**
221 | *
222 | * @param images
223 | * The images
224 | */
225 | public void setImages(Images images) {
226 | this.images = images;
227 | }
228 |
229 | /**
230 | *
231 | * @return
232 | * The alt
233 | */
234 | public String getAlt() {
235 | return alt;
236 | }
237 |
238 | /**
239 | *
240 | * @param alt
241 | * The alt
242 | */
243 | public void setAlt(String alt) {
244 | this.alt = alt;
245 | }
246 |
247 | /**
248 | *
249 | * @return
250 | * The id
251 | */
252 | public String getId() {
253 | return id;
254 | }
255 |
256 | /**
257 | *
258 | * @param id
259 | * The id
260 | */
261 | public void setId(String id) {
262 | this.id = id;
263 | }
264 |
265 | }
266 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/entities/usbox/UsBoxEntity.java:
--------------------------------------------------------------------------------
1 |
2 | package com.toryang.sampledemo.entities.usbox;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | public class UsBoxEntity {
11 |
12 | @SerializedName("date")
13 | @Expose
14 | private String date;
15 | @SerializedName("subjects")
16 | @Expose
17 | private List subjects = new ArrayList();
18 | @SerializedName("title")
19 | @Expose
20 | private String title;
21 |
22 | /**
23 | *
24 | * @return
25 | * The date
26 | */
27 | public String getDate() {
28 | return date;
29 | }
30 |
31 | /**
32 | *
33 | * @param date
34 | * The date
35 | */
36 | public void setDate(String date) {
37 | this.date = date;
38 | }
39 |
40 | /**
41 | *
42 | * @return
43 | * The subjects
44 | */
45 | public List getSubjects() {
46 | return subjects;
47 | }
48 |
49 | /**
50 | *
51 | * @param subjects
52 | * The subjects
53 | */
54 | public void setSubjects(List subjects) {
55 | this.subjects = subjects;
56 | }
57 |
58 | /**
59 | *
60 | * @return
61 | * The title
62 | */
63 | public String getTitle() {
64 | return title;
65 | }
66 |
67 | /**
68 | *
69 | * @param title
70 | * The title
71 | */
72 | public void setTitle(String title) {
73 | this.title = title;
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/loading/MyLoading.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.loading;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.view.LayoutInflater;
6 | import android.view.animation.Animation;
7 | import android.view.animation.CycleInterpolator;
8 | import android.view.animation.LinearInterpolator;
9 | import android.view.animation.RotateAnimation;
10 | import android.view.animation.TranslateAnimation;
11 | import android.widget.LinearLayout;
12 |
13 | import com.toryang.sampledemo.R;
14 | import com.toryang.sampledemo.utils.Log;
15 |
16 | /**
17 | * Created by toryang on 5/26/16.
18 | */
19 | public class MyLoading extends LinearLayout {
20 |
21 | Log log = Log.YLog();
22 | private SingleBall cradleBallOne;
23 | private SingleBall cradleBallTwo;
24 | private SingleBall cradleBallThree;
25 | private SingleBall cradleBallFour;
26 | private SingleBall cradleBallFive;
27 |
28 | private static final int DURATION = 400;
29 | private static final int SHAKE_DISTANCE = 2;
30 | private static final float PIVOT_X = 0.5f;
31 | private static final float PIVOT_Y = -3f;
32 | private static final int DEGREE = 30;
33 |
34 |
35 | private boolean isStart = false;
36 |
37 | public MyLoading(Context context) {
38 | super(context);
39 | initView(context);
40 | }
41 |
42 | public MyLoading(Context context, AttributeSet attrs) {
43 | super(context, attrs);
44 | initView(context);
45 | }
46 |
47 | public MyLoading(Context context, AttributeSet attrs, int defStyleAttr) {
48 | super(context, attrs, defStyleAttr);
49 | initView(context);
50 | }
51 |
52 | private void initView(Context context) {
53 | LayoutInflater.from(context).inflate(R.layout.single_ball_loading, this, true);
54 | }
55 |
56 |
57 | @Override
58 | protected void onFinishInflate() {
59 | super.onFinishInflate();
60 | cradleBallOne = (SingleBall) findViewById(R.id.ball_one);
61 | cradleBallTwo = (SingleBall) findViewById(R.id.ball_two);
62 | cradleBallThree = (SingleBall) findViewById(R.id.ball_three);
63 | cradleBallFour = (SingleBall) findViewById(R.id.ball_four);
64 | cradleBallFive = (SingleBall) findViewById(R.id.ball_five);
65 |
66 | initAnim();
67 | }
68 |
69 | RotateAnimation rotateLeftAnimation;//cradleBallOne left to right
70 | RotateAnimation rotateRightAnimation;//cradleBallFive right to left
71 | TranslateAnimation shakeLeftAnimation;
72 | TranslateAnimation shakeRightAnimation;
73 |
74 |
75 | private void initAnim() {
76 | rotateRightAnimation = new RotateAnimation(0, -DEGREE, RotateAnimation.RELATIVE_TO_SELF, PIVOT_X, RotateAnimation.RELATIVE_TO_SELF, PIVOT_Y);
77 | rotateRightAnimation.setRepeatCount(1);
78 | rotateRightAnimation.setRepeatMode(Animation.REVERSE);
79 | rotateRightAnimation.setDuration(DURATION);
80 | rotateRightAnimation.setInterpolator(new LinearInterpolator());
81 | rotateRightAnimation.setAnimationListener(new Animation.AnimationListener() {
82 | @Override
83 | public void onAnimationStart(Animation animation) {
84 | }
85 |
86 | @Override
87 | public void onAnimationEnd(Animation animation) {
88 | if (isStart)
89 | startRightAnim();
90 | }
91 |
92 | @Override
93 | public void onAnimationRepeat(Animation animation) {
94 | }
95 | });
96 |
97 | shakeLeftAnimation = new TranslateAnimation(0, SHAKE_DISTANCE, 0, 0);
98 | shakeLeftAnimation.setDuration(DURATION);
99 | shakeLeftAnimation.setInterpolator(new CycleInterpolator(2));
100 |
101 | rotateLeftAnimation = new RotateAnimation(0, DEGREE, RotateAnimation.RELATIVE_TO_SELF, PIVOT_X, RotateAnimation.RELATIVE_TO_SELF, PIVOT_Y);
102 | rotateLeftAnimation.setRepeatCount(1);
103 | rotateLeftAnimation.setRepeatMode(Animation.REVERSE);
104 | rotateLeftAnimation.setDuration(DURATION);
105 | rotateLeftAnimation.setInterpolator(new LinearInterpolator());
106 | rotateLeftAnimation.setAnimationListener(new Animation.AnimationListener() {
107 | @Override
108 | public void onAnimationStart(Animation animation) {
109 |
110 | }
111 |
112 | @Override
113 | public void onAnimationEnd(Animation animation) {
114 | if (isStart) {
115 | cradleBallTwo.startAnimation(shakeLeftAnimation);
116 | cradleBallThree.startAnimation(shakeLeftAnimation);
117 | cradleBallFour.startAnimation(shakeLeftAnimation);
118 |
119 | cradleBallFive.startAnimation(rotateRightAnimation);
120 | }
121 | }
122 |
123 | @Override
124 | public void onAnimationRepeat(Animation animation) {
125 |
126 | }
127 | });
128 |
129 |
130 | shakeRightAnimation = new TranslateAnimation(0, -SHAKE_DISTANCE, 0, 0);
131 | shakeRightAnimation.setDuration(DURATION);
132 | shakeRightAnimation.setInterpolator(new CycleInterpolator(2));
133 | shakeRightAnimation.setAnimationListener(new Animation.AnimationListener() {
134 | @Override
135 | public void onAnimationStart(Animation animation) {
136 | if (isStart)
137 | startLeftAnim();
138 | }
139 |
140 | @Override
141 | public void onAnimationEnd(Animation animation) {
142 |
143 | }
144 |
145 | @Override
146 | public void onAnimationRepeat(Animation animation) {
147 |
148 | }
149 | });
150 | }
151 |
152 | private void startLeftAnim() {
153 | cradleBallOne.startAnimation(rotateLeftAnimation);
154 | }
155 |
156 | private void startRightAnim() {
157 | cradleBallTwo.startAnimation(shakeRightAnimation);
158 | cradleBallThree.startAnimation(shakeRightAnimation);
159 | cradleBallFour.startAnimation(shakeRightAnimation);
160 | }
161 |
162 | public void start() {
163 | if (!isStart) {
164 | isStart = true;
165 | startLeftAnim();
166 | }
167 | }
168 |
169 | public void stop() {
170 | isStart = false;
171 | cradleBallOne.clearAnimation();
172 | cradleBallTwo.clearAnimation();
173 | cradleBallThree.clearAnimation();
174 | cradleBallFour.clearAnimation();
175 | cradleBallFive.clearAnimation();
176 | }
177 |
178 | public boolean isStart() {
179 | return isStart;
180 | }
181 |
182 | public void setLoadingColor(int color) {
183 | cradleBallOne.setLoadingColor(color);
184 | cradleBallTwo.setLoadingColor(color);
185 | cradleBallThree.setLoadingColor(color);
186 | cradleBallFour.setLoadingColor(color);
187 | cradleBallFive.setLoadingColor(color);
188 | }
189 | }
190 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/loading/SingleBall.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.loading;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Color;
7 | import android.graphics.Paint;
8 | import android.util.AttributeSet;
9 | import android.view.View;
10 |
11 | import com.toryang.sampledemo.R;
12 |
13 | /**
14 | * Created by toryang on 5/26/16.
15 | */
16 | public class SingleBall extends View {
17 |
18 | private int width;
19 | private int height;
20 |
21 | private Paint paint;
22 |
23 | private int loadingColor = Color.BLUE;
24 |
25 |
26 | public SingleBall(Context context) {
27 | super(context);
28 | initView(null);
29 | }
30 |
31 | public SingleBall(Context context, AttributeSet attrs) {
32 | super(context, attrs);
33 | initView(attrs);
34 | }
35 |
36 | public SingleBall(Context context, AttributeSet attrs, int defStyleAttr) {
37 | super(context, attrs, defStyleAttr);
38 | initView(attrs);
39 | }
40 |
41 | private void initView(AttributeSet attrs){
42 | if (null != attrs){
43 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SingleBall);
44 | loadingColor = typedArray.getColor(R.styleable.SingleBall_single_ball_color,Color.BLUE);
45 | typedArray.recycle();
46 | }
47 | paint = new Paint();
48 | paint.setColor(loadingColor);
49 | paint.setStyle(Paint.Style.FILL);
50 | paint.setAntiAlias(true);
51 | }
52 |
53 | @Override
54 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
55 | super.onSizeChanged(w, h, oldw, oldh);
56 | width = w;
57 | height = h;
58 | }
59 |
60 | @Override
61 | protected void onDraw(Canvas canvas) {
62 | super.onDraw(canvas);
63 | canvas.drawCircle(width/2, height/2, width/2, paint);
64 | }
65 |
66 | public void setLoadingColor(int color){
67 | loadingColor = color;
68 | paint.setColor(color);
69 | postInvalidate();
70 | }
71 |
72 | public int getLoadingColor(){
73 | return loadingColor;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/presenter/BasePresenter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.presenter;
2 |
3 | import com.toryang.sampledemo.ui.view.MvpView;
4 |
5 | /**
6 | * Created by toryang on 16/4/27.
7 | */
8 | public class BasePresenter implements Presenter {
9 |
10 | private T mMvpView;
11 |
12 | @Override
13 | public void attachView(T mvpView) {
14 | mMvpView = mvpView;
15 | }
16 |
17 | @Override
18 | public void detachView() {
19 | mMvpView = null;
20 | }
21 |
22 | public boolean isViewAttached() {
23 | return mMvpView != null;
24 | }
25 |
26 | public T getMvpView() {
27 | return mMvpView;
28 | }
29 |
30 | public void checkViewAttached() {
31 | if (!isViewAttached()) throw new MvpViewNotAttachedException();
32 | }
33 |
34 |
35 | public static class MvpViewNotAttachedException extends RuntimeException{
36 | public MvpViewNotAttachedException(){
37 | super("Please call Presenter.attachView(MvpView) before" +
38 | " requesting data to the Presenter");
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/presenter/HotMoviePresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.presenter;
2 |
3 |
4 | import android.content.Context;
5 |
6 | import com.android.volley.RequestQueue;
7 | import com.android.volley.Response;
8 | import com.android.volley.VolleyError;
9 | import com.android.volley.toolbox.JsonObjectRequest;
10 | import com.android.volley.toolbox.Volley;
11 | import com.toryang.sampledemo.api.InitRetrofit;
12 | import com.toryang.sampledemo.api.NetService;
13 | import com.toryang.sampledemo.config.IPAddress;
14 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
15 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
16 | import com.toryang.sampledemo.ui.view.DataView;
17 | import com.toryang.sampledemo.utils.Log;
18 |
19 | import org.json.JSONObject;
20 |
21 | import rx.Observer;
22 | import rx.android.schedulers.AndroidSchedulers;
23 | import rx.functions.Action0;
24 | import rx.schedulers.Schedulers;
25 |
26 | /**
27 | * Created by toryang on 16/4/26.
28 | */
29 | public class HotMoviePresenterImpl extends BasePresenter{
30 |
31 | private boolean USBOX_FINISHED = false;
32 | private boolean HOTMO_FINISHED = false;
33 | private boolean RECENT_FINISHED = false;
34 |
35 | Log log = Log.YLog();
36 | Context context;
37 |
38 | UsBoxEntity usBoxentity;
39 | Movieinfo comingSoonEntity,inThreatentity;
40 | public HotMoviePresenterImpl(Context context){
41 | this.context = context;
42 | }
43 |
44 | @Override
45 | public void attachView(DataView mvpView) {
46 | super.attachView(mvpView);
47 | }
48 |
49 | @Override
50 | public void detachView() {
51 | super.detachView();
52 | }
53 |
54 | public void loadData(){
55 | getMvpView().startLoading();
56 | usBoxMovie();
57 | loadUsBox();
58 | recentMovie();
59 | }
60 |
61 | public void usBoxMovie(){
62 | InitRetrofit.createApi(NetService.class)
63 | .getHotMovie()
64 | .subscribeOn(Schedulers.io())
65 | .observeOn(AndroidSchedulers.mainThread())
66 | .subscribe(new Observer() {
67 | @Override
68 | public void onCompleted() {
69 | HOTMO_FINISHED = true;
70 | log.d("finished");
71 | update();
72 | }
73 |
74 | @Override
75 | public void onError(Throwable e) {
76 | getMvpView().showError(null);
77 | HOTMO_FINISHED = true;
78 | log.e(e.toString());
79 | }
80 |
81 | @Override
82 | public void onNext(UsBoxEntity usBoxEntity) {
83 | usBoxentity = usBoxEntity;
84 | log.d(usBoxEntity.getTitle()+"");
85 | }
86 | });
87 | }
88 |
89 | public void loadUsBox(){
90 | InitRetrofit.createApi(NetService.class)
91 | .getInTheaters()
92 | .subscribeOn(Schedulers.io())
93 | .observeOn(AndroidSchedulers.mainThread())
94 | .subscribe(new Observer() {
95 | @Override
96 | public void onCompleted() {
97 | USBOX_FINISHED = true;
98 | log.d("finished");
99 | update();
100 | }
101 |
102 | @Override
103 | public void onError(Throwable e) {
104 | getMvpView().showError(null);
105 | USBOX_FINISHED = true;
106 | log.e(e.toString());
107 | }
108 |
109 | @Override
110 | public void onNext(Movieinfo inThreatEntity ) {
111 | inThreatentity = inThreatEntity;
112 |
113 | }
114 | });
115 |
116 | }
117 |
118 | public void recentMovie(){
119 | InitRetrofit.createApi(NetService.class)
120 | .getComingSoon()
121 | .subscribeOn(Schedulers.io())
122 | .observeOn(AndroidSchedulers.mainThread())
123 | .subscribe(new Observer() {
124 | @Override
125 | public void onCompleted() {
126 | log.d("finished");
127 | RECENT_FINISHED = true;
128 | update();
129 | }
130 |
131 | @Override
132 | public void onError(Throwable e) {
133 | getMvpView().showError(null);
134 | RECENT_FINISHED = true;
135 | log.e(e.toString());
136 | }
137 |
138 | @Override
139 | public void onNext(Movieinfo comingSoon) {
140 | comingSoonEntity = comingSoon;
141 | }
142 | });
143 | }
144 |
145 | public void update(){
146 | if (USBOX_FINISHED && RECENT_FINISHED && HOTMO_FINISHED){
147 | getMvpView().loadData(usBoxentity,comingSoonEntity,inThreatentity);
148 | getMvpView().hideLoading();
149 | }
150 | }
151 |
152 |
153 | public void loadHotMovieWithVolley(){
154 |
155 | RequestQueue mQueue = Volley.newRequestQueue(context);
156 | // StringRequest request = new StringRequest("http://www.baidu.com", new Response.Listener() {
157 | // @Override
158 | // public void onResponse(String response) {
159 | // log.d(response);
160 | // }
161 | // }, new Response.ErrorListener() {
162 | // @Override
163 | // public void onErrorResponse(VolleyError error) {
164 | // log.e(error);
165 | // }
166 | // });
167 | JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(IPAddress.totalUrl, null,
168 | new Response.Listener() {
169 | @Override
170 | public void onResponse(JSONObject response) {
171 | log.d(response.toString());
172 | }
173 | }, new Response.ErrorListener() {
174 | @Override
175 | public void onErrorResponse(VolleyError error) {
176 | log.e(error);
177 | }
178 | });
179 | // mQueue.add(request);
180 | mQueue.add(jsonObjectRequest);
181 | }
182 |
183 |
184 |
185 | }
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/presenter/Presenter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.presenter;
2 |
3 | import com.toryang.sampledemo.ui.view.MvpView;
4 |
5 | /**
6 | * Created by toryang on 16/4/27.
7 | */
8 | public interface Presenter {
9 |
10 | void attachView(V mvpView);
11 |
12 | void detachView();
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/presenter/Top250PresenterImpl.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.presenter;
2 |
3 | import android.content.Context;
4 |
5 | import com.toryang.sampledemo.api.InitRetrofit;
6 | import com.toryang.sampledemo.api.NetService;
7 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
8 | import com.toryang.sampledemo.ui.view.TopDataView;
9 | import com.toryang.sampledemo.utils.Log;
10 |
11 | import rx.Observer;
12 | import rx.android.schedulers.AndroidSchedulers;
13 | import rx.functions.Action0;
14 | import rx.schedulers.Schedulers;
15 |
16 | /**
17 | * Created by toryang on 5/24/16.
18 | */
19 | public class Top250PresenterImpl extends BasePresenter {
20 |
21 | Log log = Log.YLog();
22 | Context context;
23 | public Top250PresenterImpl(Context context){
24 | this.context = context;
25 | }
26 |
27 | @Override
28 | public void attachView(TopDataView topDataView) {
29 | super.attachView(topDataView);
30 | }
31 |
32 | @Override
33 | public void detachView() {
34 | super.detachView();
35 | }
36 |
37 | public void getTop250(){
38 | InitRetrofit.createApi(NetService.class)
39 | .getTop250()
40 | .subscribeOn(Schedulers.io())
41 | .doOnSubscribe(new Action0() {
42 | @Override
43 | public void call() {
44 | getMvpView().startLoading();
45 | }
46 | })
47 | .observeOn(AndroidSchedulers.mainThread())
48 | .subscribe(new Observer() {
49 | @Override
50 | public void onCompleted() {
51 | getMvpView().hideLoading();
52 | }
53 |
54 | @Override
55 | public void onError(Throwable e) {
56 | log.e(e.getStackTrace());
57 | }
58 |
59 | @Override
60 | public void onNext(Movieinfo top250Entity) {
61 | getMvpView().dataBack(top250Entity);
62 | }
63 | });
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 |
7 | import butterknife.ButterKnife;
8 |
9 | /**
10 | * Created by toryang on 16/4/25.
11 | */
12 | public abstract class BaseActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(@Nullable Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | }
18 |
19 | @Override
20 | protected void onResume() {
21 | super.onResume();
22 | }
23 |
24 | public abstract void operateView();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/BaseFragment.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui;
2 |
3 | import android.support.v4.app.Fragment;
4 | import android.view.View;
5 |
6 | import com.toryang.sampledemo.loading.MyLoading;
7 | import com.toryang.sampledemo.ui.view.MvpView;
8 |
9 | /**
10 | * Created by toryang on 16/4/26.
11 | */
12 | public class BaseFragment extends Fragment implements MvpView {
13 |
14 | MyLoading myLoading;
15 |
16 | public void setMyLoading(MyLoading myLoading) {
17 | this.myLoading = myLoading;
18 | }
19 | @Override
20 | public void startLoading() {
21 | myLoading.start();
22 | }
23 |
24 | @Override
25 | public void hideLoading() {
26 | myLoading.stop();
27 | myLoading.setVisibility(View.GONE);
28 | }
29 |
30 | @Override
31 | public void showError(String msg) {
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/activity/GridMovieActivity.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.widget.GridLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 |
12 | import com.toryang.sampledemo.R;
13 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
14 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
15 | import com.toryang.sampledemo.ui.BaseActivity;
16 | import com.toryang.sampledemo.ui.adapter.GridAdapter;
17 | import com.toryang.sampledemo.ui.adapter.GridItemClick;
18 | import com.toryang.sampledemo.ui.adapter.GridSpacingItemDecoration;
19 | import com.toryang.sampledemo.utils.Log;
20 |
21 | import butterknife.BindArray;
22 | import butterknife.BindView;
23 | import butterknife.ButterKnife;
24 |
25 | /**
26 | * Created by toryang on 5/24/16.
27 | */
28 | public class GridMovieActivity extends BaseActivity {
29 |
30 | Log log = Log.YLog();
31 |
32 | public static UsBoxEntity mUsBoxEntity;
33 | public static Movieinfo mMovieinfo;
34 |
35 | @BindView(R.id.rv_movieinfo)
36 | RecyclerView rvMovieinfo;
37 | @BindArray(R.array.movie_title)
38 | String[] movie;
39 |
40 | public static void startActivity(Context context, UsBoxEntity usBoxEntity) {
41 | mUsBoxEntity = usBoxEntity;
42 | Intent intent = new Intent(context, GridMovieActivity.class);
43 | context.startActivity(intent);
44 | }
45 |
46 | public static void startActivity(Context context, Movieinfo movieinfo) {
47 | mMovieinfo = movieinfo;
48 | Intent intent = new Intent(context, GridMovieActivity.class);
49 | context.startActivity(intent);
50 | }
51 | @Override
52 | protected void onCreate(@Nullable Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.activity_gridmovie);
55 | ButterKnife.bind(this);
56 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
57 | operateView();
58 | }
59 |
60 | @Override
61 | protected void onResume() {
62 | super.onResume();
63 | }
64 |
65 | @Override
66 | public void operateView() {
67 | int spanCount = 3;
68 | int spacing = 30;
69 | GridLayoutManager gridLayoutManager = new GridLayoutManager(this,spanCount);
70 | rvMovieinfo.setLayoutManager(gridLayoutManager);
71 | rvMovieinfo.addItemDecoration(new GridSpacingItemDecoration(spanCount,spacing,true ));
72 | rvMovieinfo.setHasFixedSize(true);
73 | final GridAdapter gridAdapter;
74 |
75 | if (mUsBoxEntity != null) {
76 | gridAdapter= new GridAdapter(this,mUsBoxEntity);
77 | getSupportActionBar().setTitle(mUsBoxEntity.getTitle());
78 | } else {
79 | gridAdapter = new GridAdapter(this,mMovieinfo);
80 | getSupportActionBar().setTitle(mMovieinfo.getTitle());
81 | }
82 | rvMovieinfo.setAdapter(gridAdapter);
83 | rvMovieinfo.addOnItemTouchListener(new GridItemClick(this,new GridItemClick.OnItemClickListener(){
84 | @Override
85 | public void onItemClick(View view, int position) {
86 | if (mUsBoxEntity != null) {
87 | MovieInfoActivity.startActivity(GridMovieActivity.this,mUsBoxEntity.getSubjects().get(position).getSubject());
88 | } else {
89 | MovieInfoActivity.startActivity(GridMovieActivity.this,mMovieinfo.getSubjects().get(position));
90 | }
91 | }
92 | })
93 | );
94 | }
95 |
96 |
97 | @Override
98 | public boolean onOptionsItemSelected(MenuItem item) {
99 | switch (item.getItemId()){
100 | case android.R.id.home:
101 | finish();
102 | break;
103 | }
104 | return true;
105 | }
106 |
107 | @Override
108 | protected void onDestroy() {
109 | super.onDestroy();
110 | mUsBoxEntity = null;
111 | mMovieinfo = null;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.activity;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.FloatingActionButton;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.design.widget.TabLayout;
7 | import android.support.v4.view.ViewPager;
8 | import android.view.View;
9 | import android.support.design.widget.NavigationView;
10 | import android.support.v4.view.GravityCompat;
11 | import android.support.v4.widget.DrawerLayout;
12 | import android.support.v7.app.ActionBarDrawerToggle;
13 | import android.support.v7.widget.Toolbar;
14 | import android.view.Menu;
15 | import android.view.MenuItem;
16 |
17 | import com.facebook.drawee.backends.pipeline.Fresco;
18 | import com.toryang.sampledemo.R;
19 | import com.toryang.sampledemo.ui.BaseActivity;
20 | import com.toryang.sampledemo.ui.adapter.ViewpagerAdapter;
21 | import com.toryang.sampledemo.ui.fragment.HotMovieFragment;
22 | import com.toryang.sampledemo.ui.fragment.TopMovFragment;
23 |
24 | import butterknife.BindArray;
25 | import butterknife.BindString;
26 | import butterknife.BindView;
27 | import butterknife.ButterKnife;
28 |
29 | public class MainActivity extends BaseActivity
30 | implements NavigationView.OnNavigationItemSelectedListener{
31 |
32 | @BindView(R.id.toolbar)Toolbar toolbar;
33 | @BindView(R.id.fab)FloatingActionButton fab;
34 | @BindView(R.id.viewpager_tab)ViewPager mViewpagerTab;
35 | @BindView(R.id.tab_top)TabLayout mTabTop;
36 | @BindView(R.id.drawer_layout)DrawerLayout drawer;
37 | @BindView(R.id.nav_view)NavigationView navigationView;
38 |
39 | @BindArray(R.array.tab_titles)String[] strs;
40 | @BindString(R.string.app_name)String name;
41 |
42 | @Override
43 | protected void onCreate(Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_main);
46 | ButterKnife.bind(this);
47 | operateView();
48 | }
49 |
50 | public void operateView() {
51 | setSupportActionBar(toolbar);
52 | toolbar.setTitle(name);
53 | fab.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View view) {
56 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
57 | .setAction("Action", null).show();
58 | }
59 | });
60 |
61 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
62 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
63 | drawer.setDrawerListener(toggle);
64 | toggle.syncState();
65 | navigationView.setNavigationItemSelectedListener(this);
66 | if (mViewpagerTab != null){
67 | setUpViewPager(mViewpagerTab);
68 | }
69 | mTabTop.setupWithViewPager(mViewpagerTab);
70 |
71 | }
72 |
73 | private void setUpViewPager(ViewPager viewPager){
74 | // String[] strs = getResources().getStringArray(R.array.tab_titles);
75 | ViewpagerAdapter adapter = new ViewpagerAdapter(getSupportFragmentManager());
76 | adapter.addFragments(new HotMovieFragment(),strs[0]);
77 | adapter.addFragments(new TopMovFragment(),strs[1]);
78 | viewPager.setAdapter(adapter);
79 | }
80 |
81 | @Override
82 | public void onBackPressed() {
83 | if (drawer.isDrawerOpen(GravityCompat.START)) {
84 | drawer.closeDrawer(GravityCompat.START);
85 | } else {
86 | super.onBackPressed();
87 | }
88 | }
89 |
90 |
91 | @Override
92 | public boolean onCreateOptionsMenu(Menu menu) {
93 | // Inflate the menu; this adds items to the action bar if it is present.
94 | getMenuInflater().inflate(R.menu.main, menu);
95 | return true;
96 | }
97 |
98 |
99 | @Override
100 | public boolean onOptionsItemSelected(MenuItem item) {
101 | // Handle action bar item clicks here. The action bar will
102 | // automatically handle clicks on the Home/Up button, so long
103 | // as you specify a parent activity in AndroidManifest.xml.
104 | int id = item.getItemId();
105 |
106 | //noinspection SimplifiableIfStatement
107 | if (id == R.id.action_settings) {
108 | return true;
109 | }
110 |
111 | return super.onOptionsItemSelected(item);
112 | }
113 |
114 | @SuppressWarnings("StatementWithEmptyBody")
115 | @Override
116 | public boolean onNavigationItemSelected(MenuItem item) {
117 | // Handle navigation view item clicks here.
118 | int id = item.getItemId();
119 |
120 | if (id == R.id.nav_camera) {
121 | // Handle the camera action
122 | } else if (id == R.id.nav_gallery) {
123 |
124 | } else if (id == R.id.nav_slideshow) {
125 |
126 | } else if (id == R.id.nav_manage) {
127 |
128 | } else if (id == R.id.nav_share) {
129 |
130 | } else if (id == R.id.nav_send) {
131 |
132 | }
133 | drawer.closeDrawer(GravityCompat.START);
134 | return true;
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/activity/MovieInfoActivity.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.activity;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.design.widget.CollapsingToolbarLayout;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.MenuItem;
10 | import android.widget.ImageView;
11 |
12 | import com.squareup.picasso.Picasso;
13 | import com.toryang.sampledemo.App;
14 | import com.toryang.sampledemo.R;
15 |
16 | import com.toryang.sampledemo.entities.movieEntitiy.Subject;
17 | import com.toryang.sampledemo.entities.usbox.Subject_;
18 | import com.toryang.sampledemo.ui.BaseActivity;
19 |
20 | import butterknife.BindView;
21 | import butterknife.ButterKnife;
22 |
23 | /**
24 | * Created by toryang on 5/25/16.
25 | */
26 | public class MovieInfoActivity extends BaseActivity {
27 |
28 |
29 | public static Subject_ mUsBoxSubject;
30 | public static Subject subject;
31 |
32 | Picasso picasso = App.getPicasso();
33 |
34 |
35 | public static void startActivity(Context context, Subject_ usBoxSubject) {
36 | mUsBoxSubject = usBoxSubject;
37 | Intent intent = new Intent(context, MovieInfoActivity.class);
38 | context.startActivity(intent);
39 | }
40 |
41 | public static void startActivity(Context context, Subject movieSubject) {
42 | subject = movieSubject;
43 | Intent intent = new Intent(context, MovieInfoActivity.class);
44 | context.startActivity(intent);
45 | }
46 |
47 |
48 |
49 | @BindView(R.id.image)
50 | ImageView image;
51 | @BindView(R.id.collapsing_toolbar)
52 | CollapsingToolbarLayout collapsingToolbar;
53 | @BindView(R.id.toolbar)
54 | Toolbar toolbar;
55 |
56 | @Override
57 | protected void onCreate(@Nullable Bundle savedInstanceState) {
58 | super.onCreate(savedInstanceState);
59 | setContentView(R.layout.activity_movieinfo);
60 | ButterKnife.bind(this);
61 | operateView();
62 | }
63 |
64 | @Override
65 | public void operateView() {
66 | setSupportActionBar(toolbar);
67 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
68 | if (mUsBoxSubject != null){
69 | collapsingToolbar.setTitle(mUsBoxSubject.getTitle());
70 | picasso.with(this).load(mUsBoxSubject.getImages().getLarge()).into(image);
71 | }else {
72 | collapsingToolbar.setTitle(subject.getTitle());
73 | picasso.with(this).load(subject.getImages().getLarge()).into(image);
74 | }
75 |
76 | }
77 | @Override
78 | public boolean onOptionsItemSelected(MenuItem item) {
79 | switch (item.getItemId()){
80 | case android.R.id.home:
81 | onBackPressed();
82 | break;
83 | }
84 | return true;
85 | }
86 |
87 | @Override
88 | protected void onDestroy() {
89 | super.onDestroy();
90 | mUsBoxSubject = null;
91 | subject = null;
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/GridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.support.v7.widget.CardView;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.TextView;
11 |
12 | import com.facebook.drawee.view.SimpleDraweeView;
13 | import com.toryang.sampledemo.R;
14 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
15 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
16 | import com.toryang.sampledemo.utils.Log;
17 |
18 | import butterknife.BindView;
19 | import butterknife.ButterKnife;
20 |
21 | /**
22 | * Created by toryang on 5/24/16.
23 | */
24 | public class GridAdapter extends RecyclerView.Adapter {
25 |
26 | Log log = Log.YLog();
27 | private Context mContext;
28 |
29 | private UsBoxEntity usBoxEntity;
30 | private Movieinfo movieinfo;
31 |
32 | public GridAdapter(Context context, Movieinfo movieinfo){
33 | mContext = context ;
34 | this.movieinfo = movieinfo;
35 | }
36 | public GridAdapter(Context context,UsBoxEntity usBoxEntity){
37 | mContext = context;
38 | this.usBoxEntity = usBoxEntity;
39 | }
40 |
41 | @Override
42 | public GridViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_movie,null);
44 | GridViewHolder gridViewHolder = new GridViewHolder(view);
45 | return gridViewHolder;
46 | }
47 |
48 | @Override
49 | public void onBindViewHolder(GridViewHolder holder, int position) {
50 | // log.d(position);
51 | if (usBoxEntity !=null){
52 | // App.getPicasso().with(mContext).load(usBoxEntity.getSubjects().get(position).getSubject().getImages().getLarge()).into(holder.imageView);
53 | holder.simpleDraweeView.setImageURI(getUri(usBoxEntity.getSubjects().get(position).getSubject().getImages().getLarge()));
54 | holder.textView.setText(usBoxEntity.getSubjects().get(position).getSubject().getTitle());
55 | }else{
56 | // App.getPicasso().with(mContext).load(top250Entity.getSubjects().get(position).getImages().getLarge()).into(holder.imageView);
57 | holder.simpleDraweeView.setImageURI(getUri(movieinfo.getSubjects().get(position).getImages().getLarge()));
58 | holder.textView.setText(movieinfo.getSubjects().get(position).getTitle());
59 | }
60 | }
61 |
62 | @Override
63 | public int getItemCount() {
64 | return usBoxEntity!=null ? usBoxEntity.getSubjects().size():movieinfo.getSubjects().size();
65 | }
66 |
67 | public class GridViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
68 |
69 | @BindView(R.id.rl_cardview)
70 | CardView mRlCardview;
71 | @BindView(R.id.image_movie)
72 | SimpleDraweeView simpleDraweeView;
73 | @BindView(R.id.tv_movie_name)
74 | TextView textView;
75 |
76 | public GridViewHolder(View itemView) {
77 | super(itemView);
78 | ButterKnife.bind(this,itemView);
79 | }
80 |
81 | @Override
82 | public void onClick(View v) {
83 | if (v.getId() == R.id.rl_cardview){
84 | log.d(getPosition());
85 | }
86 |
87 | }
88 | }
89 |
90 | private Uri getUri(String uri){
91 | return Uri.parse(uri);
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/GridItemClick.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.GestureDetector;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 |
9 | /**
10 | * Created by toryang on 5/25/16.
11 | */
12 | public class GridItemClick implements RecyclerView.OnItemTouchListener {
13 |
14 | private OnItemClickListener mListener;
15 | public interface OnItemClickListener{
16 | public void onItemClick(View view,int position);
17 | }
18 |
19 | GestureDetector mGestureDetector;
20 |
21 | public GridItemClick(Context context, OnItemClickListener listener){
22 | mListener = listener;
23 | mGestureDetector = new GestureDetector(context,new GestureDetector.SimpleOnGestureListener(){
24 | @Override
25 | public boolean onSingleTapUp(MotionEvent e) {
26 | return true;
27 | }
28 | });
29 | }
30 |
31 | @Override
32 | public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
33 | View childView = rv.findChildViewUnder(e.getX(),e.getY());
34 | if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)){
35 | mListener.onItemClick(childView,rv.getChildAdapterPosition(childView));
36 | }
37 | return false;
38 | }
39 |
40 | @Override
41 | public void onTouchEvent(RecyclerView rv, MotionEvent e) {
42 |
43 | }
44 |
45 | @Override
46 | public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
47 |
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/GridSpacingItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.graphics.Rect;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by toryang on 5/25/16.
9 | */
10 | public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
11 | private int spanCount;
12 | private int spacing;
13 | private boolean includeEdge;
14 |
15 | public GridSpacingItemDecoration(int spanCount,int spacing,boolean includeEdge){
16 | this.spacing = spacing;
17 | this.spanCount = spanCount;
18 | this.includeEdge = includeEdge;
19 | }
20 |
21 | @Override
22 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
23 | int position = parent.getChildAdapterPosition(view);
24 | int column = position % spanCount;
25 | if (includeEdge){
26 | outRect.left = spacing-column*spacing / spanCount;
27 | outRect.right = (column + 1)*spacing / spanCount;
28 |
29 | if (position < spanCount){
30 | outRect.top = spacing;
31 | }
32 | outRect.bottom = spacing;
33 | }else {
34 | outRect.left = column*spacing/spanCount;
35 | outRect.right = spacing - (column + 1)*spacing/spanCount;
36 | if (position >= spanCount){
37 | outRect.top = spacing;
38 | }
39 | }
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/LoopAdapter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.drawable.BitmapDrawable;
6 | import android.graphics.drawable.Drawable;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 |
11 | import com.jude.rollviewpager.RollPagerView;
12 | import com.jude.rollviewpager.adapter.LoopPagerAdapter;
13 | import com.toryang.sampledemo.R;
14 | import com.toryang.sampledemo.common.OkhttpUtil;
15 | import com.toryang.sampledemo.utils.Log;
16 |
17 | import java.io.IOException;
18 |
19 | import rx.Observable;
20 | import rx.Subscriber;
21 | import rx.android.schedulers.AndroidSchedulers;
22 | import rx.schedulers.Schedulers;
23 |
24 | /**
25 | * Created by toryang on 16/4/26.
26 | */
27 | public class LoopAdapter extends LoopPagerAdapter {
28 | Log log = Log.YLog();
29 | private int[] imgs = {
30 | R.drawable.img1,
31 | R.drawable.img2,
32 | R.drawable.img3,
33 | R.drawable.img4,
34 | R.drawable.img5
35 | };
36 | private String[] imageUri;
37 | Context context;
38 |
39 | public LoopAdapter(Context context,RollPagerView viewPager, String[] imageUri) {
40 | super(viewPager);
41 | this.context = context;
42 | this.imageUri = imageUri;
43 | }
44 |
45 | @Override
46 | public View getView(ViewGroup container, int position) {
47 | ImageView view = new ImageView(container.getContext());
48 | view.setImageResource(imgs[position]);
49 | // log.d(imageUri[position]);
50 | // downLoadImage(new OkhttpUtil(imageUri[position]).downloadDrawble);
51 | // view.setImageDrawable(downLoadImage(new OkhttpUtil(imageUri[position]).downloadDrawble));
52 | view.setScaleType(ImageView.ScaleType.CENTER_CROP);
53 | view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
54 | return view;
55 | }
56 |
57 | @Override
58 | protected int getRealCount() {
59 | return imageUri.length;
60 | }
61 |
62 |
63 | public Drawable downLoadImage(Observable observable){
64 | final Drawable[] drawables = {null};
65 | observable.subscribeOn(Schedulers.io())
66 | .observeOn(AndroidSchedulers.mainThread())
67 | .subscribe(new Subscriber() {
68 | @Override
69 | public void onCompleted() {
70 |
71 | }
72 |
73 | @Override
74 | public void onError(Throwable e) {
75 | log.e(e.toString());
76 | }
77 |
78 | @Override
79 | public void onNext(Bitmap bitmap) {
80 | Drawable drawable = new BitmapDrawable(context.getResources(),bitmap);
81 | drawables[0] =drawable;
82 | }
83 | });
84 |
85 | return drawables[0];
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/java/com/toryang/sampledemo/ui/adapter/OutRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.toryang.sampledemo.ui.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.RelativeLayout;
10 | import android.widget.TextView;
11 |
12 | import com.toryang.sampledemo.App;
13 | import com.toryang.sampledemo.R;
14 | import com.toryang.sampledemo.entities.movieEntitiy.Movieinfo;
15 | import com.toryang.sampledemo.entities.usbox.Subject;
16 | import com.toryang.sampledemo.entities.usbox.UsBoxEntity;
17 | import com.toryang.sampledemo.ui.activity.GridMovieActivity;
18 | import com.toryang.sampledemo.utils.Log;
19 |
20 | import java.util.List;
21 |
22 | import butterknife.BindView;
23 | import butterknife.ButterKnife;
24 |
25 | /**
26 | * Created by toryang on 5/12/16.
27 | */
28 | public class OutRecyclerAdapter extends RecyclerView.Adapter {
29 | Log log = Log.YLog();
30 |
31 | private Context mContext;
32 | private LayoutInflater mLayoutInflater;
33 | // private UsBoxEntity usBoxEntity;
34 | // private ComingSoon comingSoon;
35 | // private InThreatEntity inThreatEntity;
36 | private String[] title;
37 | private List