Search in sources :

Example 6 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project fresco by facebook.

the class MediaVariationsFragment method setDraweeControllerForRequest.

private void setDraweeControllerForRequest(ImageRequest imageRequest) {
    DraweeController controller = Fresco.newDraweeControllerBuilder().setImageRequest(imageRequest).setOldController(mMainImageDraweeView.getController()).setRetainImageOnFailure(true).build();
    mMainImageDraweeView.setController(controller);
}
Also used : DraweeController(com.facebook.drawee.interfaces.DraweeController)

Example 7 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project GitTest by xiaoxige.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    testView = (TestView) findViewById(R.id.testView);
    testView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MainActivityPermissionsDispatcher.showCameraWithPermissionCheck(MainActivity.this);
        }
    });
    try {
        ApplicationInfo appInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
        String appMV = appInfo.metaData.getString("MTA_CHANNEL");
        Toast.makeText(MainActivity.this, "appMV = " + appMV, Toast.LENGTH_SHORT).show();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    simpleDraweeView = (SimpleDraweeView) findViewById(R.id.simpleDraweeView);
    testView.setProgress(100, false);
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            testView.setProgress(3, true);
        }
    }, 2000);
    GenericDraweeHierarchy hierarchy = simpleDraweeView.getHierarchy();
    RoundingParams roundingParams = new RoundingParams();
    roundingParams.setBorder(Color.RED, 10);
    roundingParams.setRoundAsCircle(true);
    hierarchy.setRoundingParams(roundingParams);
    simpleDraweeView.setHierarchy(hierarchy);
    ControllerListener listener = new BaseControllerListener() {

        @Override
        public void onFinalImageSet(String id, @Nullable Object imageInfo, @Nullable Animatable animatable) {
            super.onFinalImageSet(id, imageInfo, animatable);
        }
    };
    DraweeController controller = Fresco.newDraweeControllerBuilder().setUri(new Uri.Builder().scheme(UriUtil.LOCAL_RESOURCE_SCHEME).path(String.valueOf(R.mipmap.ic_launcher)).build()).setOldController(simpleDraweeView.getController()).setControllerListener(listener).build();
    simpleDraweeView.setController(controller);
    /**
     * 网络相关(retrofit+rxjava+rxlife+stetho)
     */
    OkHttpClient client = new OkHttpClient.Builder().connectTimeout(5000, TimeUnit.SECONDS).readTimeout(5000, TimeUnit.SECONDS).writeTimeout(5000, TimeUnit.SECONDS).addNetworkInterceptor(new Interceptor() {

        @Override
        public okhttp3.Response intercept(Chain chain) throws IOException {
            Request request = chain.request();
            Headers headers = request.headers();
            Headers build = headers.newBuilder().add("version", "1.0").add("token", "xiaoxige").build();
            request = request.newBuilder().headers(build).build();
            Log.e("TAG", "url = " + request.url().uri().toString());
            String method = request.method();
            if (method.equals("GET") || method.equals("DELETE")) {
                HttpUrl url = request.url();
                HttpUrl httpUrl = url.newBuilder().addQueryParameter("xiaoxige", "one").addQueryParameter("zhuxiaoan", "two").build();
                request = request.newBuilder().url(httpUrl).build();
            } else {
                RequestBody body = request.body();
                if (body != null) {
                    Buffer buffer = new Buffer();
                    body.writeTo(buffer);
                    String readUtf8 = buffer.readUtf8();
                    // 可能需要对body进行加密
                    // TODO: 2017/11/3
                    RequestBody requestBody = RequestBody.create(body.contentType(), readUtf8);
                    request = request.newBuilder().method(method, requestBody).build();
                }
            }
            return chain.proceed(request);
        }
    }).addNetworkInterceptor(new StethoInterceptor()).build();
    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://www.baidu.com").addConverterFactory(ScalarsConverterFactory.create()).addConverterFactory(GsonConverterFactory.create()).client(client).build();
    final NetApi api = retrofit.create(NetApi.class);
    Flowable flowable = Flowable.create(new FlowableOnSubscribe<String>() {

        @Override
        public void subscribe(@NonNull FlowableEmitter<String> flowableEmitter) throws Exception {
            String response = MainActivity.execute(api.getBaiduWeb());
            if (TextUtils.isEmpty(response)) {
                flowableEmitter.onError(new Exception());
                return;
            }
            flowableEmitter.onNext(response);
            flowableEmitter.onComplete();
        }
    }, BackpressureStrategy.LATEST).compose(bindUntilEvent(ActivityEvent.DESTROY)).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io());
    flowable.subscribe(new XXGSubscriber<String>() {

        @Override
        public void xxgNext(String o) {
            super.xxgNext(o);
            Log.e("TAG", "o = " + o);
        }

        @Override
        public void xxgError(Throwable t) {
            super.xxgError(t);
            Log.e("TAG", "t = " + t.getMessage());
        }

        @Override
        public void xxgComplete() {
            super.xxgComplete();
            Log.e("TAG", "Complete");
        }
    });
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) DraweeController(com.facebook.drawee.interfaces.DraweeController) Headers(okhttp3.Headers) ApplicationInfo(android.content.pm.ApplicationInfo) Uri(android.net.Uri) PackageManager(android.content.pm.PackageManager) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) NonNull(io.reactivex.annotations.NonNull) FlowableEmitter(io.reactivex.FlowableEmitter) Interceptor(okhttp3.Interceptor) StethoInterceptor(com.facebook.stetho.okhttp3.StethoInterceptor) RoundingParams(com.facebook.drawee.generic.RoundingParams) RequestBody(okhttp3.RequestBody) Buffer(okio.Buffer) FlowableOnSubscribe(io.reactivex.FlowableOnSubscribe) Request(okhttp3.Request) Handler(android.os.Handler) ControllerListener(com.facebook.drawee.controller.ControllerListener) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) IOException(java.io.IOException) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) HttpUrl(okhttp3.HttpUrl) IOException(java.io.IOException) Response(retrofit2.Response) Retrofit(retrofit2.Retrofit) Animatable(android.graphics.drawable.Animatable) StethoInterceptor(com.facebook.stetho.okhttp3.StethoInterceptor) Nullable(javax.annotation.Nullable) Flowable(io.reactivex.Flowable)

Example 8 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project DevRing by LJYcoder.

the class FrescoManager method load.

private void load(Uri uri, ImageView imageView, LoadOption loadOption) {
    Preconditions.checkNotNull(imageView, "加载图片的控件不能为空!");
    if (imageView instanceof SimpleDraweeView) {
        SimpleDraweeView simpleDraweeView = (SimpleDraweeView) imageView;
        setHierarchay(simpleDraweeView.getHierarchy(), loadOption);
        ImageRequest imageRequest = getImageRequest(uri, simpleDraweeView, loadOption);
        DraweeController draweeController = getController(imageRequest, simpleDraweeView.getController());
        simpleDraweeView.setController(draweeController);
    } else {
        throw new IllegalArgumentException("Fresco加载图片的控件需为SimpleDraweeView");
    }
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) DraweeController(com.facebook.drawee.interfaces.DraweeController) ImageRequest(com.facebook.imagepipeline.request.ImageRequest)

Example 9 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project lzc_app_lib by httplzc.

the class ImgControlGif method setDataToGifImg.

/**
 * 给gif 图片赋值
 */
private void setDataToGifImg(WrapperUri wrapperUri) {
    DraweeController controller = Fresco.newDraweeControllerBuilder().setLowResImageRequest(ImageRequest.fromUri(wrapperUri.getLowUri())).setImageRequest(ImageRequest.fromUri(wrapperUri.getUri())).setAutoPlayAnimations(true).setOldController(simpleDraweeView.getController()).build();
    simpleDraweeView.setController(controller);
}
Also used : DraweeController(com.facebook.drawee.interfaces.DraweeController)

Example 10 with DraweeController

use of com.facebook.drawee.interfaces.DraweeController in project remusic by aa112901.

the class LoodView method initUI.

/**
 * 初始化UI
 *
 * @param context
 */
private void initUI(Context context) {
    LayoutInflater.from(context).inflate(R.layout.load_view, this, true);
    for (String imagesID : imageNet) {
        final SimpleDraweeView mAlbumArt = new SimpleDraweeView(context);
        ControllerListener controllerListener = new BaseControllerListener<ImageInfo>() {

            @Override
            public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable anim) {
                if (imageInfo == null) {
                    return;
                }
                QualityInfo qualityInfo = imageInfo.getQualityInfo();
                FLog.d("Final image received! " + "Size %d x %d", "Quality level %d, good enough: %s, full quality: %s", imageInfo.getWidth(), imageInfo.getHeight(), qualityInfo.getQuality(), qualityInfo.isOfGoodEnoughQuality(), qualityInfo.isOfFullQuality());
            }

            @Override
            public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
            // FLog.d("Intermediate image received");
            }

            @Override
            public void onFailure(String id, Throwable throwable) {
                mAlbumArt.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_210));
            }
        };
        Uri uri = null;
        try {
            uri = Uri.parse(imagesID);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (uri != null) {
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).build();
            DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(mAlbumArt.getController()).setImageRequest(request).setControllerListener(controllerListener).build();
            mAlbumArt.setController(controller);
        } else {
            mAlbumArt.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_210));
        }
        // view.setImageURI(Uri.parse(imagesID));
        // view.setImageResource(imagesID);
        // view.setImageResource(imagesID);
        mAlbumArt.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageViewList.add(mAlbumArt);
    }
    dotViewList.add(findViewById(R.id.v_dot1));
    dotViewList.add(findViewById(R.id.v_dot2));
    dotViewList.add(findViewById(R.id.v_dot3));
    dotViewList.add(findViewById(R.id.v_dot4));
    dotViewList.add(findViewById(R.id.v_dot5));
    dotViewList.add(findViewById(R.id.v_dot6));
    dotViewList.add(findViewById(R.id.v_dot7));
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setFocusable(true);
    fPagerAdapter = new FPagerAdapter();
    viewPager.setAdapter(fPagerAdapter);
    viewPager.addOnPageChangeListener(new MyPageChangeListener());
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) DraweeController(com.facebook.drawee.interfaces.DraweeController) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ControllerListener(com.facebook.drawee.controller.ControllerListener) QualityInfo(com.facebook.imagepipeline.image.QualityInfo) Uri(android.net.Uri) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) Nullable(android.support.annotation.Nullable)

Aggregations

DraweeController (com.facebook.drawee.interfaces.DraweeController)53 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)25 ResizeOptions (com.facebook.imagepipeline.common.ResizeOptions)10 Uri (android.net.Uri)8 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)8 Animatable (android.graphics.drawable.Animatable)7 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)6 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)5 ImageInfo (com.facebook.imagepipeline.image.ImageInfo)5 ControllerListener (com.facebook.drawee.controller.ControllerListener)4 QualityInfo (com.facebook.imagepipeline.image.QualityInfo)4 Drawable (android.graphics.drawable.Drawable)3 Nullable (android.support.annotation.Nullable)3 Canvas (android.graphics.Canvas)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 AbstractDraweeController (com.facebook.drawee.controller.AbstractDraweeController)2 ProgressBarDrawable (com.facebook.drawee.drawable.ProgressBarDrawable)2 GenericDraweeHierarchyBuilder (com.facebook.drawee.generic.GenericDraweeHierarchyBuilder)2