Example usage for android.graphics.drawable LayerDrawable mutate

List of usage examples for android.graphics.drawable LayerDrawable mutate

Introduction

In this page you can find the example usage for android.graphics.drawable LayerDrawable mutate.

Prototype

@Override
    public Drawable mutate() 

Source Link

Usage

From source file:com.github.dfa.diaspora_android.ui.BadgeDrawable.java

public static void setBadgeCount(Context context, LayerDrawable icon, String count) {

    BadgeDrawable badge;//from w  ww.  ja v  a 2 s .com

    // Reuse drawable if possible
    Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
    if (reuse != null && reuse instanceof BadgeDrawable) {
        badge = (BadgeDrawable) reuse;
    } else {
        badge = new BadgeDrawable(context);
    }

    badge.setCount(count);
    icon.mutate();
    icon.setDrawableByLayerId(R.id.ic_badge, badge);
}

From source file:com.crazymin2.retailstore.ui.BaseActivity.java

public void setBadgeCount(Context context, LayerDrawable icon, int count) {

    MenuCounterDrawable badge;//from   w w  w  .  ja  va2 s .  c  o m

    // Reuse drawable if possible
    Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
    if (reuse != null && reuse instanceof MenuCounterDrawable) {
        badge = (MenuCounterDrawable) reuse;
    } else {
        badge = new MenuCounterDrawable(context);
    }

    badge.setCount(count);
    icon.mutate();
    icon.setDrawableByLayerId(R.id.ic_badge, badge);
}

From source file:com.li.utils.ui.mdbottom.BottomNavigation.java

private void initializeUI(final int gravity) {
    final LayerDrawable layerDrawable;

    final boolean tablet = isTablet(gravity);
    final int elevation = getResources()
            .getDimensionPixelSize(!tablet ? R.dimen.bbn_elevation : R.dimen.bbn_elevation_tablet);
    final int bgResId = !tablet ? R.drawable.bbn_background
            : (MiscUtils.isGravityRight(gravity) ? R.drawable.bbn_background_tablet_right
                    : R.drawable.bbn_background_tablet_left);
    final int paddingBottom = !tablet ? shadowHeight : 0;

    // View elevation
    ViewCompat.setElevation(this, elevation);

    // Main background
    layerDrawable = (LayerDrawable) ContextCompat.getDrawable(getContext(), bgResId);
    layerDrawable.mutate();
    backgroundDrawable = (ColorDrawable) layerDrawable.findDrawableByLayerId(R.id.bbn_background);
    setBackground(layerDrawable);/*from w w  w.  j  av  a2 s  .  com*/

    // Padding bottom
    setPadding(0, paddingBottom, 0, 0);
}

From source file:it.sephiroth.android.library.bottomnavigation.BottomNavigation.java

private void initializeUI(final int gravity) {
    log(TAG, INFO, "initializeUI(%d)", gravity);
    final LayerDrawable layerDrawable;

    final boolean tablet = isTablet(gravity);
    final int elevation = getResources()
            .getDimensionPixelSize(!tablet ? R.dimen.bbn_elevation : R.dimen.bbn_elevation_tablet);
    final int bgResId = !tablet ? R.drawable.bbn_background
            : (MiscUtils.isGravityRight(gravity) ? R.drawable.bbn_background_tablet_right
                    : R.drawable.bbn_background_tablet_left);
    final int paddingBottom = !tablet ? shadowHeight : 0;

    // View elevation
    ViewCompat.setElevation(this, elevation);

    // Main background
    layerDrawable = (LayerDrawable) ContextCompat.getDrawable(getContext(), bgResId);
    layerDrawable.mutate();
    backgroundDrawable = (ColorDrawable) layerDrawable.findDrawableByLayerId(R.id.bbn_background);
    setBackground(layerDrawable);/*from   w ww.  j  a v  a 2  s. com*/

    // Padding bottom
    setPadding(0, paddingBottom, 0, 0);
}

From source file:im.ene.ribbon.BottomNavigationView.java

private void initializeUI(final int gravity) {
    log(TAG, INFO, "initializeUI(%d)", gravity);
    final LayerDrawable layerDrawable;

    final boolean tablet = isTablet(gravity);
    final int elevation = getResources()
            .getDimensionPixelSize(!tablet ? R.dimen.ribbon_elevation : R.dimen.ribbon_elevation_tablet);
    final int backgroundResId = !tablet ? R.drawable.ribbon_background
            : (MiscUtils.isGravityRight(gravity) ? R.drawable.ribbon_background_tablet_right
                    : R.drawable.ribbon_background_tablet_left);
    final int paddingTop = !tablet ? shadowHeight : 0;

    // View elevation
    ViewCompat.setElevation(this, elevation);

    // Main background
    layerDrawable = (LayerDrawable) ContextCompat.getDrawable(getContext(), backgroundResId);
    // layerDrawable.mutate();
    backgroundDrawable = (ColorDrawable) ((LayerDrawable) layerDrawable.mutate())
            .findDrawableByLayerId(R.id.bbn_background);
    setBackground(layerDrawable);/*  w  w w .j ava  2  s.  co m*/

    // Padding bottom
    setPadding(0, paddingTop, 0, 0);
}

From source file:pct.droid.fragments.BeamPlayerFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from   w  ww  .  j a  va2  s  .  co  m
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mActivity = (BeamPlayerActivity) getActivity();
    mActivity.setSupportActionBar(mToolbar);

    mLoadingDialog = LoadingBeamingDialogFragment.newInstance();
    mLoadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            closePlayer();
        }
    });
    mLoadingDialog.show(getChildFragmentManager(), "overlay_fragment");

    mStreamInfo = mActivity.getInfo();
    if (mStreamInfo.isShow()) {
        mMedia = mStreamInfo.getShow();
    } else {
        mMedia = mStreamInfo.getMedia();
    }

    if (mMedia == null) {
        mMedia = new Media(null, null);
        mMedia.color = getResources().getColor(R.color.primary);
    }

    LayerDrawable progressDrawable;
    LayerDrawable volumeDrawable;
    if (!VersionUtils.isLollipop()) {
        progressDrawable = (LayerDrawable) getResources()
                .getDrawable(R.drawable.scrubber_progress_horizontal_bigtrack);
        volumeDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.scrubber_progress_horizontal);
    } else {
        if (mVolumeBar.getProgressDrawable() instanceof StateListDrawable) {
            StateListDrawable stateListDrawable = (StateListDrawable) mVolumeBar.getProgressDrawable();
            volumeDrawable = (LayerDrawable) stateListDrawable.getCurrent();
        } else {
            volumeDrawable = (LayerDrawable) mVolumeBar.getProgressDrawable();
        }

        progressDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.progress_horizontal_material);
    }

    if (volumeDrawable == null) {
        volumeDrawable = (LayerDrawable) progressDrawable.mutate();
    }

    progressDrawable.findDrawableByLayerId(android.R.id.background)
            .setColorFilter(getResources().getColor(R.color.beamplayer_seekbar_track), PorterDuff.Mode.SRC_IN);
    progressDrawable.findDrawableByLayerId(android.R.id.progress).setColorFilter(mMedia.color,
            PorterDuff.Mode.SRC_IN);
    progressDrawable.findDrawableByLayerId(android.R.id.secondaryProgress).setColorFilter(mMedia.color,
            PorterDuff.Mode.SRC_IN);

    volumeDrawable.findDrawableByLayerId(android.R.id.background)
            .setColorFilter(getResources().getColor(R.color.beamplayer_seekbar_track), PorterDuff.Mode.SRC_IN);
    volumeDrawable.findDrawableByLayerId(android.R.id.progress).setColorFilter(mMedia.color,
            PorterDuff.Mode.SRC_IN);
    volumeDrawable.findDrawableByLayerId(android.R.id.secondaryProgress).setColorFilter(mMedia.color,
            PorterDuff.Mode.SRC_IN);

    mSeekBar.setProgressDrawable(progressDrawable);
    mSeekBar.getThumbDrawable().setColorFilter(mMedia.color, PorterDuff.Mode.SRC_IN);

    mVolumeBar.setProgressDrawable(volumeDrawable);
    mVolumeBar.getThumbDrawable().setColorFilter(mMedia.color, PorterDuff.Mode.SRC_IN);

    if (!VersionUtils.isJellyBean()) {
        mPlayButton.setBackgroundDrawable(PixelUtils.changeDrawableColor(mPlayButton.getContext(),
                R.drawable.play_button_circle, mMedia.color));
    } else {
        mPlayButton.setBackground(PixelUtils.changeDrawableColor(mPlayButton.getContext(),
                R.drawable.play_button_circle, mMedia.color));
    }

    if (mMedia.image != null && !mMedia.image.equals("")) {
        Picasso.with(mCoverImage.getContext()).load(mMedia.image).into(mCoverImage, new Callback() {
            @Override
            public void onSuccess() {
                AnimUtils.fadeIn(mCoverImage);
            }

            @Override
            public void onError() {
            }
        });
    }

    mActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mActivity.getSupportActionBar().setTitle("");

    try {
        if (!mBeamManager.getConnectedDevice().hasCapability(MediaControl.Position)
                || !mBeamManager.getConnectedDevice().hasCapability(MediaControl.Seek)
                || !mBeamManager.getConnectedDevice().hasCapability(MediaControl.Duration)) {
            mHasSeekControl = false;
            mSeekBar.setVisibility(View.INVISIBLE);
        }

        if (!mBeamManager.getConnectedDevice().hasCapability(VolumeControl.Volume_Get)
                || !mBeamManager.getConnectedDevice().hasCapability(VolumeControl.Volume_Set)
                || !mBeamManager.getConnectedDevice().hasCapability(VolumeControl.Volume_Subscribe)) {
            mHasVolumeControl = false;
            mPanel.setEnabled(false);
            mPanel.setTouchEnabled(false);
        }

        if (!mBeamManager.getConnectedDevice().hasCapability(MediaControl.Pause)) {
            mPlayButton.setEnabled(false);
        }

        startVideo();
    } catch (Exception e) {
        Toast.makeText(getActivity(), R.string.unknown_error, Toast.LENGTH_SHORT);
        getActivity().finish();
    }
}

From source file:butter.droid.fragments.BeamPlayerFragment.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override/* w w  w. ja  va2  s .c om*/
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mActivity = (BeamPlayerActivity) getActivity();
    mActivity.setSupportActionBar(mToolbar);

    mLoadingDialog = LoadingBeamingDialogFragment.newInstance();
    mLoadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
            closePlayer();
        }
    });
    mLoadingDialog.show(getChildFragmentManager(), "overlay_fragment");

    mResumePosition = mActivity.getResumePosition();

    mStreamInfo = mActivity.getInfo();
    int paletteColor = mStreamInfo.getPaletteColor();

    if (paletteColor == -1) {
        paletteColor = getResources().getColor(R.color.primary);
    }

    LayerDrawable progressDrawable;
    LayerDrawable volumeDrawable;
    if (!VersionUtils.isLollipop()) {
        progressDrawable = (LayerDrawable) getResources()
                .getDrawable(R.drawable.scrubber_progress_horizontal_bigtrack);
        volumeDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.scrubber_progress_horizontal);
    } else {
        if (mVolumeBar.getProgressDrawable() instanceof StateListDrawable) {
            StateListDrawable stateListDrawable = (StateListDrawable) mVolumeBar.getProgressDrawable();
            volumeDrawable = (LayerDrawable) stateListDrawable.getCurrent();
        } else {
            volumeDrawable = (LayerDrawable) mVolumeBar.getProgressDrawable();
        }

        progressDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.progress_horizontal_material);
    }

    if (volumeDrawable == null) {
        volumeDrawable = (LayerDrawable) progressDrawable.mutate();
    }

    progressDrawable.findDrawableByLayerId(android.R.id.background)
            .setColorFilter(getResources().getColor(R.color.beamplayer_seekbar_track), PorterDuff.Mode.SRC_IN);
    progressDrawable.findDrawableByLayerId(android.R.id.progress).setColorFilter(paletteColor,
            PorterDuff.Mode.SRC_IN);
    progressDrawable.findDrawableByLayerId(android.R.id.secondaryProgress).setColorFilter(paletteColor,
            PorterDuff.Mode.SRC_IN);

    volumeDrawable.findDrawableByLayerId(android.R.id.background)
            .setColorFilter(getResources().getColor(R.color.beamplayer_seekbar_track), PorterDuff.Mode.SRC_IN);
    volumeDrawable.findDrawableByLayerId(android.R.id.progress).setColorFilter(paletteColor,
            PorterDuff.Mode.SRC_IN);
    volumeDrawable.findDrawableByLayerId(android.R.id.secondaryProgress).setColorFilter(paletteColor,
            PorterDuff.Mode.SRC_IN);

    mSeekBar.setProgressDrawable(progressDrawable);
    mSeekBar.getThumbDrawable().setColorFilter(paletteColor, PorterDuff.Mode.SRC_IN);

    mVolumeBar.setProgressDrawable(volumeDrawable);
    mVolumeBar.getThumbDrawable().setColorFilter(paletteColor, PorterDuff.Mode.SRC_IN);

    if (!VersionUtils.isJellyBean()) {
        mPlayButton.setBackgroundDrawable(PixelUtils.changeDrawableColor(mPlayButton.getContext(),
                R.drawable.play_button_circle, paletteColor));
    } else {
        mPlayButton.setBackground(PixelUtils.changeDrawableColor(mPlayButton.getContext(),
                R.drawable.play_button_circle, paletteColor));
    }

    if (mStreamInfo.getImageUrl() != null && !mStreamInfo.getImageUrl().equals("")) {
        Picasso.with(mCoverImage.getContext()).load(mStreamInfo.getImageUrl()).into(mCoverImage,
                new Callback() {
                    @Override
                    public void onSuccess() {
                        AnimUtils.fadeIn(mCoverImage);
                    }

                    @Override
                    public void onError() {
                    }
                });
    }

    mActivity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mActivity.getSupportActionBar().setTitle("");

    try {
        if (!mBeamManager.getConnectedDevice().hasCapability(MediaControl.Position)
                || !mBeamManager.getConnectedDevice().hasCapability(MediaControl.Seek)
                || !mBeamManager.getConnectedDevice().hasCapability(MediaControl.Duration)) {
            mHasSeekControl = false;
            mSeekBar.setVisibility(View.INVISIBLE);
        }

        if (!mBeamManager.getConnectedDevice().hasCapability(VolumeControl.Volume_Get)
                || !mBeamManager.getConnectedDevice().hasCapability(VolumeControl.Volume_Set)
                || !mBeamManager.getConnectedDevice().hasCapability(VolumeControl.Volume_Subscribe)) {
            mHasVolumeControl = false;
            mPanel.setEnabled(false);
            mPanel.setTouchEnabled(false);
        }

        if (!mBeamManager.getConnectedDevice().hasCapability(MediaControl.Pause)) {
            mPlayButton.setEnabled(false);
        }

        startVideo();
    } catch (Exception e) {
        Snackbar.make(mRootView, R.string.unknown_error, Snackbar.LENGTH_SHORT).show();
        getActivity().finish();
    }

    Intent intent = new Intent(getActivity(), BeamPlayerNotificationService.class);
    intent.setAction(mIsPlaying ? BeamPlayerNotificationService.ACTION_PLAY
            : BeamPlayerNotificationService.ACTION_PAUSE);
    getActivity().startService(intent);
}