Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

/**
 * ?/*  w w  w.  ja  v a 2s .  c om*/
 *
 * @param interval ?
 */
@SuppressWarnings("unused")
public void setInterval(@DrawableRes int interval) {
    setInterval(ContextCompat.getDrawable(getContext(), interval));
}

From source file:android.support.v17.leanback.widget.GuidedActionsStylist.java

/**
 * Sets states of check mark view, called by {@link #onBindViewHolder(ViewHolder, GuidedAction)}
 * when action's checkset Id is other than {@link GuidedAction#NO_CHECK_SET}. Default
 * implementation assigns drawable loaded from theme attribute
 * {@link android.R.attr#listChoiceIndicatorMultiple} for checkbox or
 * {@link android.R.attr#listChoiceIndicatorSingle} for radio button. Subclass rarely needs
 * override the method, instead app can provide its own drawable that supports transition
 * animations, change theme attributes {@link android.R.attr#listChoiceIndicatorMultiple} and
 * {@link android.R.attr#listChoiceIndicatorSingle} in {android.support.v17.leanback.R.
 * styleable#LeanbackGuidedStepTheme}./*from  ww w  . j a  v  a 2  s  .co  m*/
 *
 * @param vh The view holder associated with the relevant action.
 * @param action The GuidedAction object to bind to.
 * @see #onAnimateItemChecked(ViewHolder, boolean)
 */
public void onBindCheckMarkView(ViewHolder vh, GuidedAction action) {
    if (action.getCheckSetId() != GuidedAction.NO_CHECK_SET) {
        vh.mCheckmarkView.setVisibility(View.VISIBLE);
        int attrId = action.getCheckSetId() == GuidedAction.CHECKBOX_CHECK_SET_ID
                ? android.R.attr.listChoiceIndicatorMultiple
                : android.R.attr.listChoiceIndicatorSingle;
        final Context context = vh.mCheckmarkView.getContext();
        Drawable drawable = null;
        TypedValue typedValue = new TypedValue();
        if (context.getTheme().resolveAttribute(attrId, typedValue, true)) {
            drawable = ContextCompat.getDrawable(context, typedValue.resourceId);
        }
        vh.mCheckmarkView.setImageDrawable(drawable);
        if (vh.mCheckmarkView instanceof Checkable) {
            ((Checkable) vh.mCheckmarkView).setChecked(action.isChecked());
        }
    } else {
        vh.mCheckmarkView.setVisibility(View.GONE);
    }
}

From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

/**
 * Set a drawable to draw in the insets area for the status bar.
 * Note that this will only be activated if this DrawerLayout fitsSystemWindows.
 *
 * @param resId Resource id of a background drawable to draw behind the status bar
 *//*from   w ww.  j a v  a2  s.  c o  m*/
public void setStatusBarBackground(int resId) {
    mStatusBarBackground = resId != 0 ? ContextCompat.getDrawable(getContext(), resId) : null;
    invalidate();
}

From source file:com.example.sky.test.view.ViewPager.java

/**
 * Set a drawable that will be used to fill the margin between pages.
 *
 * @param resId Resource ID of a drawable to display between pages
 *//* w  ww .  ja v a  2 s  .c om*/
public void setPageMarginDrawable(@DrawableRes int resId) {
    setPageMarginDrawable(ContextCompat.getDrawable(getContext(), resId));
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

/**
 * Tag/*  www.j a v  a2s  . co m*/
 *
 * @param background Tag
 */
@SuppressWarnings("unused")
public void setTagBackground(@DrawableRes int background) {
    setTagBackground(ContextCompat.getDrawable(getContext(), background));
}

From source file:android.support.v7.internal.view.menu.MenuBuilder.java

private void setHeaderInternal(final int titleRes, final CharSequence title, final int iconRes,
        final Drawable icon, final View view) {
    final Resources r = getResources();

    if (view != null) {
        mHeaderView = view;//from   www .j  av a  2 s  .  c  om

        // If using a custom view, then the title and icon aren't used
        mHeaderTitle = null;
        mHeaderIcon = null;
    } else {
        if (titleRes > 0) {
            mHeaderTitle = r.getText(titleRes);
        } else if (title != null) {
            mHeaderTitle = title;
        }

        if (iconRes > 0) {
            mHeaderIcon = ContextCompat.getDrawable(getContext(), iconRes);
        } else if (icon != null) {
            mHeaderIcon = icon;
        }

        // If using the title or icon, then a custom view isn't used
        mHeaderView = null;
    }

    // Notify of change
    onItemsChanged(false);
}

From source file:com.filemanager.free.fragments.Main.java

public void createViews(ArrayList<Layoutelements> bitmap, boolean back, String f, int openMode, boolean results,
        boolean grid) {
    try {/* www . jav  a  2  s  .c  om*/
        if (bitmap != null) {
            if (GO_BACK_ITEM)
                if (!f.equals("/") && (openMode == 0 || openMode == 3)) {
                    if (bitmap.size() == 0 || !bitmap.get(0).getSize().equals(goback))
                        bitmap.add(0,
                                utils.newElement(
                                        ContextCompat.getDrawable(getContext(),
                                                R.drawable.ic_arrow_back_white_36dp),
                                        "..", "", "", goback, 0, false, true, ""));
                }

            if (bitmap.size() == 0 && !results) {
                nofilesview.setVisibility(View.VISIBLE);
                listView.setVisibility(View.GONE);
                mSwipeRefreshLayout.setEnabled(false);
            } else {
                mSwipeRefreshLayout.setEnabled(true);
                nofilesview.setVisibility(View.GONE);
                listView.setVisibility(View.VISIBLE);

            }
            LIST_ELEMENTS = bitmap;
            if (grid && IS_LIST)
                switchToGrid();
            else if (!grid && !IS_LIST)
                switchToList();
            if (adapter == null)
                adapter = new Recycleradapter(ma, bitmap, ma.getActivity());
            else {
                adapter.generate(LIST_ELEMENTS);
            }
            stopAnims = true;
            this.openMode = openMode;
            if (openMode != 2)
                DataUtils.addHistoryFile(f);
            //mSwipeRefreshLayout.setRefreshing(false);
            try {
                listView.setAdapter(adapter);

                if (!addheader) {
                    listView.removeItemDecoration(headersDecor);
                    listView.removeItemDecoration(dividerItemDecoration);
                    addheader = true;
                }
                if (addheader && IS_LIST) {
                    dividerItemDecoration = new DividerItemDecoration(getActivity(),
                            DividerItemDecoration.VERTICAL_LIST, true, SHOW_DIVIDERS);
                    listView.addItemDecoration(dividerItemDecoration);
                    headersDecor = new StickyRecyclerHeadersDecoration(adapter);
                    listView.addItemDecoration(headersDecor);
                    addheader = false;
                }
                if (!results)
                    this.results = false;
                CURRENT_PATH = f;
                if (back) {
                    if (scrolls.containsKey(CURRENT_PATH)) {
                        Bundle b = scrolls.get(CURRENT_PATH);
                        if (IS_LIST)
                            mLayoutManager.scrollToPositionWithOffset(b.getInt("index"), b.getInt("top"));
                        else
                            mLayoutManagerGrid.scrollToPositionWithOffset(b.getInt("index"), b.getInt("top"));
                    }
                }
                //floatingActionButton.show();
                MAIN_ACTIVITY.updatepaths(no);
                listView.stopScroll();

                /*fastScroller.setRecyclerView(listView, IS_LIST ? 1 : columns);
                mToolbarContainer.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
                @Override
                public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
                    fastScroller.updateHandlePosition(verticalOffset, 112);
                    //    fastScroller.setPadding(fastScroller.getPaddingLeft(),fastScroller.getTop(),fastScroller.getPaddingRight(),112+verticalOffset);
                    //      fastScroller.updateHandlePosition();
                }
                });
                fastScroller.registerOnTouchListener(new FastScroller.onTouchListener() {
                @Override
                public void onTouch() {
                    if (stopAnims && adapter != null) {
                        stopAnimation();
                        stopAnims = false;
                    }
                }
                });*/

                if (buttons.getVisibility() == View.VISIBLE)
                    MAIN_ACTIVITY.bbar(this);
                //MAIN_ACTIVITY.invalidateFab(openMode);
            } catch (Exception ignored) {
            }
        } else {//Toast.makeText(getActivity(),res.getString(R.string.error),Toast.LENGTH_LONG).show();
            loadlist(home, true, 0);
        }
    } catch (Exception ignored) {
    }

}

From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java

/**
 * Set a drawable to use as a shadow cast by the right pane onto the left pane
 * during opening/closing./*from  w w  w. ja  va2s.  co  m*/
 *
 * @param resId Resource ID of a drawable to use
 */
public void setShadowResourceLeft(int resId) {
    setShadowDrawableLeft(ContextCompat.getDrawable(getContext(), resId));
}

From source file:cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout.java

/**
 * Set a drawable to use as a shadow cast by the left pane onto the right pane
 * during opening/closing to support right to left language.
 *
 * @param resId Resource ID of a drawable to use
 *//*from  w ww  .ja  va  2  s.c  o  m*/
public void setShadowResourceRight(int resId) {
    setShadowDrawableRight(ContextCompat.getDrawable(getContext(), resId));
}

From source file:com.example.android.recyclingbanks.MainActivity.java

private View prepareInfoView(final Marker marker) {
    // TODO change this to xml?
    //prepare InfoView programmatically
    final LinearLayout infoView = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams infoViewParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    infoView.setOrientation(LinearLayout.VERTICAL);
    // attach the above layout to the infoView
    infoView.setLayoutParams(infoViewParams);

    String markerLongitude = Double.toString(marker.getPosition().longitude);
    String markerLatitude = Double.toString(marker.getPosition().latitude);

    final String imageURL = "https://maps.googleapis.com/maps/api/streetview?size=" + "500x300&location="
            + markerLatitude + "," + markerLongitude + "&fov=120&heading=0&pitch=0";

    //create street view preview @ top
    ImageView streetViewPreviewIV = new ImageView(MainActivity.this);

    Log.wtf("comparing TAG", String.valueOf(marker.getTag()));

    if (marker.getTag() == null) {
        Log.i("prepareInfoView", "fetching image");
        Picasso.with(this).load(imageURL).fetch(new MarkerCallback(marker));
    } else {/*from   w ww.  j a  v a  2 s. c  o  m*/
        Log.wtf("prepareInfoView", "building info window");

        // this scales the image to match parents WIDTH?, but retain image's height??
        LinearLayout.LayoutParams streetViewImageViewParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        streetViewPreviewIV.setLayoutParams(streetViewImageViewParams);
        // TODO upon conversion to xml, the imageView needs these to scale image to box
        // android:scaleType="fitStart"
        // android:adjustViewBounds="true"
        Picasso.with(MainActivity.this).load(imageURL).into(streetViewPreviewIV);
        infoView.addView(streetViewPreviewIV);
        //Log.wtf("prepareInfoView, marker tag set?", String.valueOf(marker.getTag()));
        //Picasso.with(this).setLoggingEnabled(true);
    }

    // create text boxes
    LinearLayout subInfoView = new LinearLayout(MainActivity.this);
    LinearLayout.LayoutParams subInfoViewParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    subInfoView.setOrientation(LinearLayout.VERTICAL);
    subInfoView.setLayoutParams(subInfoViewParams);

    TextView titleTextView = new TextView(MainActivity.this);
    titleTextView.setText(marker.getTitle());
    TextView snippetTextView = new TextView(MainActivity.this);
    snippetTextView.setText(marker.getSnippet());
    subInfoView.addView(titleTextView);
    subInfoView.addView(snippetTextView);
    infoView.addView(subInfoView);

    // add the image on the right
    ImageView streetViewIcon = new ImageView(MainActivity.this);
    // this scales the image to match parents height.
    LinearLayout.LayoutParams imageViewParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    streetViewIcon.setLayoutParams(imageViewParams);
    Drawable drawable = ContextCompat.getDrawable(MainActivity.this, R.drawable.ic_streetview);
    streetViewIcon.setImageDrawable(drawable);
    infoView.addView(streetViewIcon);
    //Picasso.with(this).load(imageURL).into(streetViewPreviewIV, new MarkerCallback(marker));

    return infoView;
}