Search in sources :

Example 1 with RoundingParams

use of com.facebook.drawee.generic.RoundingParams 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 2 with RoundingParams

use of com.facebook.drawee.generic.RoundingParams in project remusic by aa112901.

the class RoundFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_roundimage, container, false);
    ((ViewGroup) rootView).setAnimationCacheEnabled(false);
    if (getArguments() != null) {
        albumPath = getArguments().getString("album");
    }
    // CircleImageView  circleImageView = (CircleImageView) rootView.findViewById(R.id.circle);
    sdv = (SimpleDraweeView) rootView.findViewById(R.id.sdv);
    // 初始化圆角圆形参数对象
    RoundingParams rp = new RoundingParams();
    // 设置图像是否为圆形
    rp.setRoundAsCircle(true);
    // 设置圆角半径
    // rp.setCornersRadius(20);
    // 分别设置左上角、右上角、左下角、右下角的圆角半径
    // rp.setCornersRadii(20,25,30,35);
    // 分别设置(前2个)左上角、(3、4)右上角、(5、6)左下角、(7、8)右下角的圆角半径
    // rp.setCornersRadii(new float[]{20,25,30,35,40,45,50,55});
    // 设置边框颜色及其宽度
    rp.setBorder(Color.BLACK, 6);
    // 获取GenericDraweeHierarchy对象
    GenericDraweeHierarchy hierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()).setRoundingParams(rp).setFadeDuration(300).build();
    // 设置Hierarchy
    sdv.setHierarchy(hierarchy);
    // Log.e("music id",musicId + "");
    // String uri = MusicUtils.getAlbumdata(getContext().getApplicationContext(), musicId);
    // 
    // if (musicId != -1 && uri != null) {
    // //circleImageView.setImageBitmap(bitmap);
    // //circleImageView.setImageURI(Uri.parse(uri));
    // Uri ur = MusicUtils.getAlbumUri(getContext().getApplicationContext(), musicId);
    // sdv.setImageURI(ur);
    // } else {
    // 
    // // circleImageView.setImageResource(R.drawable.placeholder_disk_play_song);
    // Uri urr = Uri.parse("res:/" + R.drawable.placeholder_disk_play_song);
    // sdv.setImageURI(urr);
    // }
    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) {
            sdv.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_play_song));
        }
    };
    if (albumPath == null) {
        sdv.setImageURI(Uri.parse("res:/" + R.drawable.placeholder_disk_play_song));
    } else {
        try {
            ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(albumPath)).build();
            DraweeController controller = Fresco.newDraweeControllerBuilder().setOldController(sdv.getController()).setImageRequest(request).setControllerListener(controllerListener).build();
            sdv.setController(controller);
        // sdv.setImageBitmap(BitmapFactory.decodeStream(HttpUtil.getFromCache(getActivity(),getAlbumPath())));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) DraweeController(com.facebook.drawee.interfaces.DraweeController) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ControllerListener(com.facebook.drawee.controller.ControllerListener) QualityInfo(com.facebook.imagepipeline.image.QualityInfo) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) BaseControllerListener(com.facebook.drawee.controller.BaseControllerListener) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) Animatable(android.graphics.drawable.Animatable) ImageInfo(com.facebook.imagepipeline.image.ImageInfo) RoundingParams(com.facebook.drawee.generic.RoundingParams) Nullable(android.support.annotation.Nullable)

Example 3 with RoundingParams

use of com.facebook.drawee.generic.RoundingParams in project fresco by facebook.

the class DraweeHierarchyFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    final Uri uriSuccess = sampleUris().createSampleUri(ImageUriProvider.ImageSize.XL, ImageUriProvider.Orientation.ANY, ImageUriProvider.UriModification.CACHE_BREAKER);
    final Uri uriFailure = sampleUris().getNonExistingUri();
    final SimpleDraweeView draweeView = view.findViewById(R.id.drawee);
    final SwitchCompat retrySwitch = view.findViewById(R.id.retry_enabled);
    // noinspection deprecation
    final Drawable failureDrawable = getResources().getDrawable(R.drawable.ic_error_black_96dp);
    DrawableCompat.setTint(failureDrawable, Color.RED);
    final ProgressBarDrawable progressBarDrawable = new ProgressBarDrawable();
    progressBarDrawable.setColor(getResources().getColor(R.color.accent));
    progressBarDrawable.setBackgroundColor(getResources().getColor(R.color.primary));
    progressBarDrawable.setRadius(getResources().getDimensionPixelSize(R.dimen.drawee_hierarchy_progress_radius));
    draweeView.getHierarchy().setProgressBarImage(progressBarDrawable);
    draweeView.getHierarchy().setFailureImage(failureDrawable, ScaleType.CENTER_INSIDE);
    view.findViewById(R.id.load_success).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setUri(draweeView, uriSuccess, retrySwitch.isChecked());
        }
    });
    view.findViewById(R.id.load_fail).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setUri(draweeView, uriFailure, retrySwitch.isChecked());
        }
    });
    view.findViewById(R.id.clear).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            draweeView.setController(null);
            Fresco.getImagePipeline().evictFromCache(uriSuccess);
        }
    });
    final SwitchCompat roundCorners = view.findViewById(R.id.switch_rounded);
    roundCorners.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            RoundingParams roundingParams = new RoundingParams().setCornersRadius(isChecked ? buttonView.getResources().getDimensionPixelSize(R.dimen.drawee_hierarchy_corner_radius) : 0);
            draweeView.getHierarchy().setRoundingParams(roundingParams);
        }
    });
    final SwitchCompat useNinePatch = view.findViewById(R.id.switch_ninepatch);
    useNinePatch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            draweeView.getHierarchy().setPlaceholderImage(isChecked ? R.drawable.ninepatch : R.drawable.logo, isChecked ? ScaleType.FIT_XY : ScaleType.CENTER_INSIDE);
        }
    });
}
Also used : SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Drawable(android.graphics.drawable.Drawable) ProgressBarDrawable(com.facebook.drawee.drawable.ProgressBarDrawable) Uri(android.net.Uri) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) CompoundButton(android.widget.CompoundButton) RoundingParams(com.facebook.drawee.generic.RoundingParams) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Example 4 with RoundingParams

use of com.facebook.drawee.generic.RoundingParams in project fresco by facebook.

the class DraweeRoundedCornersFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    findDrawees(view);
    initColors();
    final ImageUriProvider imageUriProvider = sampleUris();
    mDraweeRound.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeRadius.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeSome.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeSomeRtl.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    mDraweeFancy.setImageURI(imageUriProvider.createSampleUri(ImageSize.L));
    final Spinner scaleType = view.findViewById(R.id.scaleType);
    final SimpleScaleTypeAdapter scaleTypeAdapter = SimpleScaleTypeAdapter.createForAllScaleTypes();
    scaleType.setAdapter(scaleTypeAdapter);
    scaleType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final SimpleScaleTypeAdapter.Entry spinnerEntry = (SimpleScaleTypeAdapter.Entry) scaleTypeAdapter.getItem(position);
            final ScaleType scaleType = spinnerEntry.scaleType;
            changeDraweeViewScaleType(mDraweeRound, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeRadius, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeSome, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeSomeRtl, scaleType, spinnerEntry.focusPoint);
            changeDraweeViewScaleType(mDraweeFancy, scaleType, spinnerEntry.focusPoint);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mShowBordersCheck = view.findViewById(R.id.borders);
    mShowBordersCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    mScaleInsideBordersCheck = view.findViewById(R.id.scaleInside);
    mScaleInsideBordersCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    mColorOverlayCheck = view.findViewById(R.id.color_overlay);
    mColorOverlayCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    mFixRepeatedEdgesCheck = view.findViewById(R.id.fix_repeated_edges);
    mFixRepeatedEdgesCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateRounding();
        }
    });
    final Resources res = getResources();
    final RoundingParams fancyRoundingParams = RoundingParams.fromCornersRadii(res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_top_left), res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_top_right), res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_bottom_right), res.getDimensionPixelSize(R.dimen.drawee_rounded_corners_fancy_bottom_left));
    mDraweeFancy.getHierarchy().setRoundingParams(fancyRoundingParams);
}
Also used : Spinner(android.widget.Spinner) ScaleType(com.facebook.drawee.drawable.ScalingUtils.ScaleType) SimpleScaleTypeAdapter(com.facebook.fresco.samples.showcase.common.SimpleScaleTypeAdapter) ImageUriProvider(com.facebook.fresco.samples.showcase.misc.ImageUriProvider) SimpleDraweeView(com.facebook.drawee.view.SimpleDraweeView) View(android.view.View) AdapterView(android.widget.AdapterView) AdapterView(android.widget.AdapterView) Resources(android.content.res.Resources) CompoundButton(android.widget.CompoundButton) RoundingParams(com.facebook.drawee.generic.RoundingParams)

Example 5 with RoundingParams

use of com.facebook.drawee.generic.RoundingParams in project fresco by facebook.

the class DraweeRoundedCornersFragment method setShowBorder.

private void setShowBorder(SimpleDraweeView draweeView, boolean show, boolean scaleInside) {
    final RoundingParams roundingParams = Preconditions.checkNotNull(draweeView.getHierarchy().getRoundingParams());
    if (show) {
        roundingParams.setBorder(mColorPrimary, getResources().getDimensionPixelSize(R.dimen.drawee_rounded_corners_border_width));
        roundingParams.setScaleDownInsideBorders(scaleInside);
    } else {
        roundingParams.setBorder(Color.TRANSPARENT, 0);
    }
    if (mColorOverlayCheck.isChecked()) {
        roundingParams.setOverlayColor(mCornerBackgroundColor);
    } else {
        roundingParams.setRoundingMethod(RoundingParams.RoundingMethod.BITMAP_ONLY);
    }
    roundingParams.setRepeatEdgePixels(!mFixRepeatedEdgesCheck.isChecked());
    draweeView.getHierarchy().setRoundingParams(roundingParams);
}
Also used : RoundingParams(com.facebook.drawee.generic.RoundingParams)

Aggregations

RoundingParams (com.facebook.drawee.generic.RoundingParams)11 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)7 View (android.view.View)5 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)5 GenericDraweeHierarchyBuilder (com.facebook.drawee.generic.GenericDraweeHierarchyBuilder)4 Resources (android.content.res.Resources)2 Animatable (android.graphics.drawable.Animatable)2 Uri (android.net.Uri)2 ViewGroup (android.view.ViewGroup)2 CompoundButton (android.widget.CompoundButton)2 BaseControllerListener (com.facebook.drawee.controller.BaseControllerListener)2 ControllerListener (com.facebook.drawee.controller.ControllerListener)2 DraweeController (com.facebook.drawee.interfaces.DraweeController)2 ApplicationInfo (android.content.pm.ApplicationInfo)1 PackageManager (android.content.pm.PackageManager)1 PointF (android.graphics.PointF)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Nullable (android.support.annotation.Nullable)1