// Path: app/src/main/java/com/xd/demi/UrlService.java
// public interface UrlService {
// 
//     @GET("bd_logo1_31bdc765.png")
//     Call<Bitmap> getImage();
// 
//     @GET("{id}/daily-yields?")
//     Call<ResponseData<DailyYeildsInfo>> getDatas(@Path("id") String id , @Query("type") String type);
// 
//     @GET("bd_logo1_31bdc765.png")
//     Flowable<Bitmap> getRXImage();
// 
// }
// 
// Path: app/src/main/java/com/xd/demi/factory/BitmapConverterFactory.java
// public class BitmapConverterFactory  extends Converter.Factory{
// 
//     public static BitmapConverterFactory create() {
//         return new BitmapConverterFactory();
//     }
// 
// 
//     @Override
//     public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
//         return new BitmapResponseConverter<>(type);
//     }
// 
// 
// }
// 
// Path: app/src/main/java/com/xd/demi/utils/Platform.java
// public class Platform
// {
//     private static final Platform PLATFORM = findPlatform();
// 
//     public static Platform get()
//     {
//         L.e(PLATFORM.getClass().toString());
//         return PLATFORM;
//     }
// 
//     private static Platform findPlatform()
//     {
//         try
//         {
//             Class.forName("android.os.Build");
//             if (Build.VERSION.SDK_INT != 0)
//             {
//                 return new Android();
//             }
//         } catch (ClassNotFoundException ignored)
//         {
//         }
//         return new Platform();
//     }
// 
//     public Executor defaultCallbackExecutor()
//     {
//         return Executors.newCachedThreadPool();
//     }
// 
//     public void execute(Runnable runnable)
//     {
//         defaultCallbackExecutor().execute(runnable);
//     }
// 
// 
//     static class Android extends Platform
//     {
//         @Override
//         public Executor defaultCallbackExecutor()
//         {
//             return new MainThreadExecutor();
//         }
// 
//         static class MainThreadExecutor implements Executor
//         {
//             private final Handler handler = new Handler(Looper.getMainLooper());
// 
//             @Override
//             public void execute(Runnable r)
//             {
//                 handler.post(r);
//             }
//         }
//     }
// 
// 
// }


import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.xd.demi.R;
import com.xd.demi.UrlService;
import com.xd.demi.factory.BitmapConverterFactory;
import com.xd.demi.utils.Platform;
import org.reactivestreams.Subscription;
import io.reactivex.FlowableSubscriber;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
package com.xd.demi.activity;






/**
 * Created by demi on 2017/3/13.
 */

public class RetrofitOKHttpActivity extends Activity implements View.OnClickListener {
    ImageView image;
    Button button;
    private Platform mPlatform;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrofit);
        image = (ImageView) findViewById(R.id.image);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(this);
        mPlatform = Platform.get();

    }

    @Override
    public void onClick(View v) {
//        OkHttpClient okHttpClient = new OkHttpClient();
//        Request request = new Request.Builder()
//                .url("bd_logo1_31bdc765.png")
//                .build();
//       Call call= okHttpClient.newCall(request);
//        call.enqueue(new Callback()
//        {
//            @Override
//            public void onFailure(Call call, IOException e) {
//
//            }
//
//            @Override
//            public void onResponse(Call call, final Response response) throws IOException {
//                mPlatform.execute(new Runnable() {
//                    @Override
//                    public void run() {
//                        InputStream inputStream = response.body().byteStream();
//                        Bitmap bitmap= BitmapFactory.decodeStream(inputStream);
//                        image.setImageBitmap(bitmap);
//                    }
//                });
//
//            }
//
//        });
        OkHttpClient okHttpClient = new OkHttpClient();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/")
                .addConverterFactory(BitmapConverterFactory.create())
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        UrlService service = retrofit.create(UrlService.class);
//        Call<Bitmap> call = service.getImage();
//        call.enqueue(new retrofit2.Callback<Bitmap>() {
//            @Override
//            public void onResponse(Call<Bitmap> call, final retrofit2.Response<Bitmap> response) {
//                Bitmap bitmap = Bitmap.createBitmap(response.body(), 0, 0, response.body().getWidth(), response.body().getHeight() / 2);
//                image.setImageBitmap(bitmap);
//            }
//
//            @Override
//            public void onFailure(Call<Bitmap> call, Throwable t) {
//
//            }
//        });
        service.getRXImage()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
// Path: app/src/main/java/com/xd/demi/UrlService.java
// public interface UrlService {
// 
//     @GET("bd_logo1_31bdc765.png")
//     Call<Bitmap> getImage();
// 
//     @GET("{id}/daily-yields?")
//     Call<ResponseData<DailyYeildsInfo>> getDatas(@Path("id") String id , @Query("type") String type);
// 
//     @GET("bd_logo1_31bdc765.png")
//     Flowable<Bitmap> getRXImage();
// 
// }
// 
// Path: app/src/main/java/com/xd/demi/factory/BitmapConverterFactory.java
// public class BitmapConverterFactory  extends Converter.Factory{
// 
//     public static BitmapConverterFactory create() {
//         return new BitmapConverterFactory();
//     }
// 
// 
//     @Override
//     public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
//         return new BitmapResponseConverter<>(type);
//     }
// 
// 
// }
// 
// Path: app/src/main/java/com/xd/demi/utils/Platform.java
// public class Platform
// {
//     private static final Platform PLATFORM = findPlatform();
// 
//     public static Platform get()
//     {
//         L.e(PLATFORM.getClass().toString());
//         return PLATFORM;
//     }
// 
//     private static Platform findPlatform()
//     {
//         try
//         {
//             Class.forName("android.os.Build");
//             if (Build.VERSION.SDK_INT != 0)
//             {
//                 return new Android();
//             }
//         } catch (ClassNotFoundException ignored)
//         {
//         }
//         return new Platform();
//     }
// 
//     public Executor defaultCallbackExecutor()
//     {
//         return Executors.newCachedThreadPool();
//     }
// 
//     public void execute(Runnable runnable)
//     {
//         defaultCallbackExecutor().execute(runnable);
//     }
// 
// 
//     static class Android extends Platform
//     {
//         @Override
//         public Executor defaultCallbackExecutor()
//         {
//             return new MainThreadExecutor();
//         }
// 
//         static class MainThreadExecutor implements Executor
//         {
//             private final Handler handler = new Handler(Looper.getMainLooper());
// 
//             @Override
//             public void execute(Runnable r)
//             {
//                 handler.post(r);
//             }
//         }
//     }
// 
// 
// }


// Path: app/src/main/java/com/xd/demi/activity/RetrofitOKHttpActivity.java
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import com.xd.demi.R;
import com.xd.demi.UrlService;
import com.xd.demi.factory.BitmapConverterFactory;
import com.xd.demi.utils.Platform;
import org.reactivestreams.Subscription;
import io.reactivex.FlowableSubscriber;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

package com.xd.demi.activity;






/**
 * Created by demi on 2017/3/13.
 */

public class RetrofitOKHttpActivity extends Activity implements View.OnClickListener {
    ImageView image;
    Button button;
    private Platform mPlatform;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_retrofit);
        image = (ImageView) findViewById(R.id.image);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(this);
        mPlatform = Platform.get();

    }

    @Override
    public void onClick(View v) {
//        OkHttpClient okHttpClient = new OkHttpClient();
//        Request request = new Request.Builder()
//                .url("bd_logo1_31bdc765.png")
//                .build();
//       Call call= okHttpClient.newCall(request);
//        call.enqueue(new Callback()
//        {
//            @Override
//            public void onFailure(Call call, IOException e) {
//
//            }
//
//            @Override
//            public void onResponse(Call call, final Response response) throws IOException {
//                mPlatform.execute(new Runnable() {
//                    @Override
//                    public void run() {
//                        InputStream inputStream = response.body().byteStream();
//                        Bitmap bitmap= BitmapFactory.decodeStream(inputStream);
//                        image.setImageBitmap(bitmap);
//                    }
//                });
//
//            }
//
//        });
        OkHttpClient okHttpClient = new OkHttpClient();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/")
                .addConverterFactory(BitmapConverterFactory.create())
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        UrlService service = retrofit.create(UrlService.class);
//        Call<Bitmap> call = service.getImage();
//        call.enqueue(new retrofit2.Callback<Bitmap>() {
//            @Override
//            public void onResponse(Call<Bitmap> call, final retrofit2.Response<Bitmap> response) {
//                Bitmap bitmap = Bitmap.createBitmap(response.body(), 0, 0, response.body().getWidth(), response.body().getHeight() / 2);
//                image.setImageBitmap(bitmap);
//            }
//
//            @Override
//            public void onFailure(Call<Bitmap> call, Throwable t) {
//
//            }
//        });
        service.getRXImage()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new FlowableSubscriber<Bitmap>() {