Example usage for android.graphics.drawable LayerDrawable findDrawableByLayerId

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

Introduction

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

Prototype

public Drawable findDrawableByLayerId(int id) 

Source Link

Document

Looks for a layer with the given ID and returns its Drawable .

Usage

From source file:com.justplay1.shoppist.shared.base.adapters.BaseGroupSwipeableItemAdapter.java

@Override
public void onSetChildItemSwipeBackground(CVH holder, int groupPosition, int childPosition, int type) {
    int bgResId = R.drawable.bg_swipe_item_neutral;
    LayerDrawable drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId);
    switch (type) {
    case SwipeableItemConstants.DRAWABLE_SWIPE_LEFT_BACKGROUND:
        switch (getLeftSwipeActionType()) {
        case SwipeActionType.MOVE_ITEM:
            if (getChildItem(groupPosition, childPosition).getStatus()) {
                bgResId = getMoveToStatusNotDoneIcon();
            } else {
                bgResId = getMoveToStatusDoneIcon();
            }/*from   w w w.  ja  v a 2 s  .co m*/
            break;
        case SwipeActionType.DELETE_ITEM:
            bgResId = R.drawable.bg_swipe_item_delete_action;
            break;
        case SwipeActionType.EDIT_ITEM:
            bgResId = R.drawable.bg_swipe_item_edit_action;
            break;
        }
        drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId);
        ((BitmapDrawable) drawable.findDrawableByLayerId(R.id.image))
                .setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
        break;
    case SwipeableItemConstants.DRAWABLE_SWIPE_RIGHT_BACKGROUND:
        bgResId = R.drawable.bg_swipe_item_move_to_cart_action;
        switch (getRightSwipeActionType()) {
        case SwipeActionType.MOVE_ITEM:
            if (getChildItem(groupPosition, childPosition).getStatus()) {
                bgResId = getMoveToStatusNotDoneIcon();
            } else {
                bgResId = getMoveToStatusDoneIcon();
            }
            break;
        case SwipeActionType.DELETE_ITEM:
            bgResId = R.drawable.bg_swipe_item_delete_action;
            break;
        case SwipeActionType.EDIT_ITEM:
            bgResId = R.drawable.bg_swipe_item_edit_action;
            break;
        }
        drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId);
        ((BitmapDrawable) drawable.findDrawableByLayerId(R.id.image))
                .setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
        break;
    }
    DrawableUtils.setViewDrawable(holder.itemView, drawable);
}

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from  w  w w.ja  va  2s  .c  o  m
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    view.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return onTouchEvent(event);
        }
    });
    ButterKnife.bind(this, view);

    if (LocaleUtils.isRTL(LocaleUtils.getCurrent())) {
        Drawable forward = mForwardButton.getDrawable();
        Drawable rewind = mRewindButton.getDrawable();
        mRewindButton.setImageDrawable(forward);
        mForwardButton.setImageDrawable(rewind);
    }

    int color = getResources().getColor(R.color.primary);
    LayerDrawable progressDrawable;
    if (!VersionUtils.isLollipop()) {
        progressDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.scrubber_progress_horizontal);
    } else {
        if (mControlBar.getProgressDrawable() instanceof StateListDrawable) {
            StateListDrawable stateListDrawable = (StateListDrawable) mControlBar.getProgressDrawable();
            progressDrawable = (LayerDrawable) stateListDrawable.getCurrent();
        } else {
            progressDrawable = (LayerDrawable) mControlBar.getProgressDrawable();
        }
    }
    progressDrawable.findDrawableByLayerId(android.R.id.progress).setColorFilter(color, PorterDuff.Mode.SRC_IN);
    progressDrawable.findDrawableByLayerId(android.R.id.secondaryProgress).setColorFilter(color,
            PorterDuff.Mode.SRC_IN);

    mControlBar.setProgressDrawable(progressDrawable);
    mControlBar.getThumbDrawable().setColorFilter(color, PorterDuff.Mode.SRC_IN);
}

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();/*  w ww.j  a va  2  s  .com*/
    backgroundDrawable = (ColorDrawable) layerDrawable.findDrawableByLayerId(R.id.bbn_background);
    setBackground(layerDrawable);

    // 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();//from w w  w  .  ja  v  a2 s.  c  o m
    backgroundDrawable = (ColorDrawable) layerDrawable.findDrawableByLayerId(R.id.bbn_background);
    setBackground(layerDrawable);

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

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

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//  w w  w .j  a  v a  2s.  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");

    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/*from www  .  java 2s.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);
}