Example usage for android.graphics.drawable LayerDrawable getDrawable

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

Introduction

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

Prototype

public Drawable getDrawable(int index) 

Source Link

Document

Returns the drawable for the layer at the specified index.

Usage

From source file:Main.java

public static Drawable getLastDrawable(Drawable drawable) {
    if (drawable == null) {
        return null;
    }/*ww  w  .j av  a2s . c  o  m*/

    if (!(drawable instanceof LayerDrawable)) {
        return drawable;
    }

    LayerDrawable layerDrawable = (LayerDrawable) drawable;
    for (int i = layerDrawable.getNumberOfLayers() - 1; i >= 0; i--) {
        Drawable childDrawable = getLastDrawable(layerDrawable.getDrawable(i));
        if (childDrawable != null) {
            return childDrawable;
        }
    }
    return null;
}

From source file:Main.java

/**
 * Returns the View's {@link ColorDrawable} background in case it has one.
 * The {@link ColorDrawable} may be set directly as the View's background,
 * or nested within a {@link LayerDrawable}. In case of a
 * {@link LayerDrawable}, the method will return the first color-drawable it
 * finds.//from  w  w w  .  j  a v a 2 s  .c o m
 * 
 * @param view
 * @return A {@link ColorDrawable}, or <code>null</code> in case not found.
 */
private static ColorDrawable getColorDrawableBackground(View view) {
    if (view != null) {
        Drawable background = view.getBackground();
        if (background instanceof ColorDrawable) {
            return (ColorDrawable) background;
        }
        if (background instanceof LayerDrawable) {
            LayerDrawable layeredBG = (LayerDrawable) background;
            int numberOfLayers = layeredBG.getNumberOfLayers();
            for (int i = 0; i < numberOfLayers; i++) {
                if (layeredBG.getDrawable(i) instanceof ColorDrawable) {
                    return (ColorDrawable) layeredBG.getDrawable(i);
                }
            }
        }
    }
    return null;
}

From source file:com.android.tv.guide.ProgramItemView.java

private static void setProgress(Drawable drawable, int id, int progress) {
    if (drawable instanceof StateListDrawable) {
        StateListDrawable stateDrawable = (StateListDrawable) drawable;
        for (int i = 0; i < getStateCount(stateDrawable); ++i) {
            setProgress(getStateDrawable(stateDrawable, i), id, progress);
        }//from  w  w w. j  a v  a2s  .  co  m
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        for (int i = 0; i < layerDrawable.getNumberOfLayers(); ++i) {
            setProgress(layerDrawable.getDrawable(i), id, progress);
            if (layerDrawable.getId(i) == id) {
                layerDrawable.getDrawable(i).setLevel(progress);
            }
        }
    }
}

From source file:com.vrem.wifianalyzer.wifi.channelrating.ChannelRatingAdapter.java

private void setRatingBarColor(Drawable drawable, int color) {
    try {/*www  . j  av a  2 s .c  o m*/
        int background = ContextCompat.getColor(getContext(), R.color.connected_background);
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        layerDrawable.getDrawable(0).setColorFilter(background, PorterDuff.Mode.SRC_ATOP);
        layerDrawable.getDrawable(1).setColorFilter(background, PorterDuff.Mode.SRC_ATOP);
        layerDrawable.getDrawable(2).setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    } catch (Exception e) {
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }
}

From source file:com.z299studio.pb.PasswordGenerator.java

private void tintSeekBar(SeekBar sb) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable thumb = ContextCompat.getDrawable(getContext(), R.drawable.thumb);
        LayerDrawable progress = (LayerDrawable) ContextCompat.getDrawable(getContext(), R.drawable.progress);
        progress.getDrawable(0).setColorFilter(C.ThemedColors[C.colorIconNormal], PorterDuff.Mode.SRC_ATOP);
        progress.getDrawable(1).setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
        sb.setProgressDrawable(progress);
        thumb.setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
        sb.setThumb(thumb);/* w  w w  . j  a v  a 2 s .c  o  m*/
    }
}

From source file:com.mindorks.framework.mvp.ui.main.rating.RateUsDialog.java

@Override
protected void setUp(View view) {

    mRatingMessageView.setVisibility(View.GONE);
    mPlayStoreRatingView.setVisibility(View.GONE);

    LayerDrawable stars = (LayerDrawable) mRatingBar.getProgressDrawable();
    stars.getDrawable(2).setColorFilter(ContextCompat.getColor(getContext(), R.color.yellow),
            PorterDuff.Mode.SRC_ATOP);/*from  w  w  w  . java2  s. c  o  m*/
    stars.getDrawable(0).setColorFilter(ContextCompat.getColor(getContext(), R.color.shadow),
            PorterDuff.Mode.SRC_ATOP);
    stars.getDrawable(1).setColorFilter(ContextCompat.getColor(getContext(), R.color.shadow),
            PorterDuff.Mode.SRC_ATOP);

    mSubmitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mPresenter.onRatingSubmitted(mRatingBar.getRating(), mMessage.getText().toString());
        }
    });

}

From source file:net.basilwang.ui.widget.BlockView.java

public BlockView(Context context, Curriculum c, String blockId, String title, int startTime, int endTime,
        boolean containsStarred, int column) {
    super(context);

    this.curriculum = c;
    this.mContext = context;
    mBlockId = blockId;//  www.  j a v  a  2  s.  co m
    mTitle = title;
    mStartTime = startTime;
    mEndTime = endTime;
    mContainsStarred = containsStarred;
    mColumn = column;

    setText(mTitle);

    int textColor = -1;
    int accentColor = -1;
    switch (mColumn % 3) {
    case 0:
        // blue
        textColor = Color.WHITE;
        accentColor = Color.parseColor("#18b6e6");
        break;
    case 1:
        // red
        textColor = Color.WHITE;
        accentColor = Color.parseColor("#df1831");
        break;
    case 2:
        // green
        textColor = Color.WHITE;
        accentColor = Color.parseColor("#00a549");
        break;
    }

    LayerDrawable buttonDrawable = (LayerDrawable) context.getResources().getDrawable(R.drawable.btn_block);
    buttonDrawable.getDrawable(0).setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
    buttonDrawable.getDrawable(1).setAlpha(mContainsStarred ? 255 : 0);

    setTextColor(textColor);
    setBackgroundDrawable(buttonDrawable);
    // DisplayMetrics dm = new DisplayMetrics();
    // WindowManager wm = (WindowManager)
    // context.getSystemService(Context.WINDOW_SERVICE);
    // //2012-11-30 basilwang we use sp
    // wm.getDefaultDisplay().getMetrics(dm);
    // float pixelSize = (int)TEXT_SIZE * dm.scaledDensity;
    float pixelSize = TEXT_SIZE;
    setTextSize(pixelSize);
    //
    /**
    this.setOnLongClickListener(new OnLongClickListener() {
            
       @Override
       public boolean onLongClick(View v) {
    switchFragment(new EditCurriculumFragment(curriculum));
    return false;
       }
    });**/
}

From source file:com.quran.labs.androidquran.ui.preference.SeekBarPreference.java

private void styleSeekBar() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        final Drawable progressDrawable = mSeekBar.getProgressDrawable();
        if (progressDrawable != null) {
            if (progressDrawable instanceof LayerDrawable) {
                LayerDrawable ld = (LayerDrawable) progressDrawable;
                int layers = ld.getNumberOfLayers();
                for (int i = 0; i < layers; i++) {
                    ld.getDrawable(i).mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
                }/*  ww  w. j av  a2s.c  om*/
            } else {
                progressDrawable.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
            }
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            final Drawable thumb = mSeekBar.getThumb();
            if (thumb != null) {
                thumb.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
            }
        }
    }
}

From source file:net.peterkuterna.android.apps.devoxxfrsched.ui.BlockScheduleItemsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    if (!data.moveToFirst()) {
        return;//  w w w  .j  a va  2s .c  om
    }

    mDay.scheduleItemsView.removeAllBlocks();

    final ArrayList<BlockScheduleItem> blocksList = Lists.newArrayList();
    BlockScheduleItem.loadBlocks(getActivity(), data, blocksList);
    for (BlockScheduleItem block : blocksList) {
        final ScheduleItemView view = new ScheduleItemView(getActivity(), block);

        if (block.getSessionsCount() == 1) {
            final Uri uri = Blocks.buildSessionUri(block.getId());
            mHandler.startQuery(uri, null, null, null, null, block);
        }

        if (block.getSessionsCount() > 0) {
            view.setOnClickListener(this);
        } else {
            view.setFocusable(false);
            view.setEnabled(false);
            LayerDrawable buttonDrawable = (LayerDrawable) view.getBackground();
            buttonDrawable.getDrawable(0).setAlpha(DISABLED_BLOCK_ALPHA);
            buttonDrawable.getDrawable(11).setAlpha(DISABLED_BLOCK_ALPHA);
        }

        mDay.scheduleItemsView.addBlock(view);
    }

    if (getView() != null) {
        if (isResumed()) {
            setContentShown(true);
        } else {
            setContentShownNoAnimation(true);
        }
    }
}

From source file:com.z299studio.pb.DetailFragment.java

private void setupToolbar(View rootView, String title) {
    Toolbar toolbar;//  w  ww. j  a  v a2s  . co  m
    TextView titleView;
    toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
    View close = rootView.findViewById(R.id.close);
    close.setOnClickListener(this);
    View header = rootView.findViewById(R.id.header);
    ImageButton fab = (ImageButton) rootView.findViewById(R.id.fab);
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
        LayerDrawable background = (LayerDrawable) fab.getBackground();
        background.getDrawable(1).setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP);
    }
    fab.setOnClickListener(this);
    header.setBackgroundColor(mColor);
    titleView = (TextView) rootView.findViewById(android.R.id.title);
    titleView.setText(title);
    // Elevation to minus 1 so that fab would not be covered on 5.0
    float elevation = getResources().getDimension(R.dimen.fab_small_elevation) - 0.5f;
    ViewCompat.setElevation(header, elevation);
    if (rootView.findViewById(R.id.frame_box) == null) {
        MainActivity ma = (MainActivity) getActivity();
        ma.setStatusBarColor(mColor, 200, false);
    }
    toolbar.inflateMenu(R.menu.menu_detail);
    toolbar.getMenu().getItem(0).getIcon().setColorFilter(C.ThemedColors[C.colorTextNormal],
            PorterDuff.Mode.SRC_ATOP);
    toolbar.setOnMenuItemClickListener(this);
}