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:babbq.com.searchplace.SearchActivity.java

@OnClick({ R.id.scrim, R.id.searchback })
protected void dismiss() {
    // translate the icon to match position in the launching activity
    searchBackContainer.animate().translationX(searchBackDistanceX).setDuration(600L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in))
            .setListener(new AnimatorListenerAdapter() {

                @Override/*  w  w  w  .  j  a  va2s. c o  m*/
                public void onAnimationEnd(Animator animation) {
                    finishAfterTransition();
                }
            }).start();
    // transform from back icon to search icon
    AnimatedVectorDrawable backToSearch = (AnimatedVectorDrawable) ContextCompat.getDrawable(this,
            R.drawable.avd_back_to_search);
    searchBack.setImageDrawable(backToSearch);
    // clear the background else the touch ripple moves with the translation which looks bad
    searchBack.setBackground(null);
    backToSearch.start();
    // fade out the other search chrome
    searchView.animate().alpha(0f).setStartDelay(0L).setDuration(120L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
    searchBackground.animate().alpha(0f).setStartDelay(300L).setDuration(160L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
    if (searchToolbar.getZ() != 0f) {
        searchToolbar.animate().z(0f).setDuration(600L)
                .setInterpolator(
                        AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in))
                .start();
    }

    // if we're showing search results, circular hide them
    if (resultsContainer.getHeight() > 0) {
        Animator closeResults = ViewAnimationUtils.createCircularReveal(resultsContainer, searchIconCenterX, 0,
                (float) Math.hypot(searchIconCenterX, resultsContainer.getHeight()), 0f);
        closeResults.setDuration(500L);
        closeResults.setInterpolator(
                AnimationUtils.loadInterpolator(SearchActivity.this, android.R.interpolator.fast_out_slow_in));
        closeResults.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                resultsContainer.setVisibility(View.INVISIBLE);
            }
        });
        closeResults.start();
    }

    // fade out the scrim
    scrim.animate().alpha(0f).setDuration(400L)
            .setInterpolator(AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_linear_in))
            .setListener(null).start();
}

From source file:com.bhb27.isu.Props.java

private void updateState() {
    if (rootAccess) {
        mPropsScreen.removePreference(mPropsRemoveCat);
        String[] value = new String[Constants.props.length];
        String summary = "";
        for (int i = 0; i < Constants.props.length; i++) {
            value[i] = Tools.getprop(Constants.props[i]);
            if (value[i] == null || value[i].isEmpty()) {
                props[i].setValue("");
                summary = getString(R.string.unknown);
                props[i].setSummary(summary);
                props[i].setIcon(R.drawable.interrogation);
            } else {
                props[i].setValue(value[i]);
                summary = value[i];/*from ww  w. j  av  a  2 s. c om*/
                props[i].setSummary(summary);
                props[i].setIcon(summary.equals(Constants.props_OK[i]) ? R.drawable.ok : R.drawable.warning);
            }
        }
        String BuildFingerprint = Build.FINGERPRINT;
        String RoBuildFingerprint = Tools.getprop(Constants.robuildfingerprint);
        if (Tools.getprop(Constants.robuildfingerprint)
                .equals(Tools.getprop(Constants.robootbuildfingerprint))) {
            mBuildFingerprint.setSummary(Build.FINGERPRINT + getString(R.string.fingerprint_help));
            // use setIcon(Drawable) instead of setIcon(int) to avoid falls back to the previously-set in a new Drawable that is null
            mBuildFingerprint.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.warning));
        } else if (RoBuildFingerprint.equals(BuildFingerprint)) {
            mBuildFingerprint.setSummary(Build.FINGERPRINT);
            mBuildFingerprint.setIcon(originalIcon);
        } else {
            mBuildFingerprint.setSummary(RoBuildFingerprint + getString(R.string.fingerprint_apply));
            mBuildFingerprint.setIcon(ContextCompat.getDrawable(getActivity(), R.drawable.exclamation));
        }

        try {
            getActivity().registerReceiver(updatePropsReceiver, new IntentFilter("updatePropsReceiver"));
        } catch (NullPointerException ignored) {
        }
    } else {
        mPropsEdit.setEnabled(false);
        mPropsSpecial.setEnabled(false);
        mPropsKnown.setEnabled(false);
        mPropsKnownList.setEnabled(false);
    }
}

From source file:com.github.andrewlord1990.materialandroid.component.grid.GridItemView.java

/**
 * Set the icon to display at the end (on the right).
 *
 * @param iconRes The icon to display.//www .  ja  va  2 s.c  o  m
 */
public void setIcon(@DrawableRes int iconRes) {
    setIcon(ContextCompat.getDrawable(getContext(), iconRes));
}

From source file:android.support.design.widget.CoordinatorLayout.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
 *///w ww .ja  v a2 s.  c o m
public void setStatusBarBackgroundResource(@DrawableRes int resId) {
    setStatusBarBackground(resId != 0 ? ContextCompat.getDrawable(getContext(), resId) : null);
}

From source file:com.afeng.xf.widget.snackbarlight.Light.java

/**
 * Make a customized {@link Snackbar} to display a message without any action.
 * Method {@link Light#make(View, int, int, int, int, int, int, int)} is called internal.
 *
 * @param view The view to find a parent from.
 * @param textRes The message to display. String resource id required.
 * @param textIconRes The left icon of the message. Drawable resource id required.
 * @param backgroundColorRes The background color of the Snackbar. Color resource id required.
 * @param textColorRes The color of action message text. Color resource id required.
 * @param duration How long to show the message.
 *                 Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}.
 * @param actionIconRes The left icon of action message text. Drawable resource id required.
 * @param actionTextColorRes The color of action message text. Color resource id required.
 *
 * @return The customized Snackbar that will be displayed.
 *///from  w w w.ja  v  a 2 s.  com
public static Snackbar make(@NonNull View view, @StringRes int textRes, @DrawableRes int textIconRes,
        @ColorRes int backgroundColorRes, @ColorRes int textColorRes, int duration,
        @DrawableRes int actionIconRes, @ColorRes int actionTextColorRes) {
    Context context = view.getContext();
    return make(view, context.getString(textRes),
            // DO NOT use the resource id directly.
            // It should be a resolved drawable or color.
            ContextCompat.getDrawable(context, textIconRes),
            // getResources().getColor() is deprecated.
            ContextCompat.getColor(context, backgroundColorRes), ContextCompat.getColor(context, textColorRes),
            duration, ContextCompat.getDrawable(context, actionIconRes),
            ContextCompat.getColor(context, actionTextColorRes));
}

From source file:com.dm.wallpaper.board.activities.WallpaperBoardActivity.java

private void initNavigationView(Toolbar toolbar) {
    resetNavigationView(getResources().getConfiguration().orientation);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.txt_open,
            R.string.txt_close) {/*  w  w  w  . j  a  v  a 2 s  .c o  m*/

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if (mPosition == 4) {
                mPosition = mLastPosition;
                mNavigationView.getMenu().getItem(mPosition).setChecked(true);
                InAppBillingFragment.showInAppBillingDialog(mFragManager, mBillingProcessor, mLicenseKey,
                        mDonationProductsId);
                return;
            }

            if (mPosition != mLastPosition) {
                mLastPosition = mPosition;
                setFragment(getFragment(mPosition));
            }
        }
    };

    mDrawerLayout.setDrawerShadow(R.drawable.navigation_view_shadow, GravityCompat.START);
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    ColorStateList colorStateList = ContextCompat.getColorStateList(this,
            Preferences.get(this).isDarkTheme() ? R.color.navigation_view_item_highlight_dark
                    : R.color.navigation_view_item_highlight);
    mNavigationView.getMenu().getItem(mNavigationView.getMenu().size() - 2)
            .setVisible(getResources().getBoolean(R.bool.enable_donation));
    mNavigationView.setItemTextColor(colorStateList);
    mNavigationView.setItemIconTintList(colorStateList);
    Drawable background = ContextCompat.getDrawable(this,
            Preferences.get(this).isDarkTheme() ? R.drawable.navigation_view_item_background_dark
                    : R.drawable.navigation_view_item_background);
    mNavigationView.setItemBackground(background);
    mNavigationView.setNavigationItemSelectedListener(item -> {
        int id = item.getItemId();
        if (id == R.id.navigation_view_wallpapers)
            mPosition = 0;
        else if (id == R.id.navigation_view_favorites)
            mPosition = 1;
        else if (id == R.id.navigation_view_settings)
            mPosition = 2;
        else if (id == R.id.navigation_view_about)
            mPosition = 3;
        else if (id == R.id.navigation_view_donate)
            mPosition = 4;

        item.setChecked(true);
        mDrawerLayout.closeDrawers();
        return true;
    });
    ViewHelper.hideNavigationViewScrollBar(mNavigationView);
}

From source file:com.jun.elephant.ui.main.MainActivity.java

/**
 *  UI/*from   www  . j a  va 2s. com*/
 * ??view?
 */
private void refreshUI() {
    TypedValue themeColor = new TypedValue(); //
    TypedValue statusColor = new TypedValue(); //??
    TypedValue toolbarTextColor = new TypedValue(); //??
    TypedValue navIcon = new TypedValue(); //toolbar 
    TypedValue searchIcon = new TypedValue(); //toolbar ?
    TypedValue noticeIcon = new TypedValue(); //toolbar 
    TypedValue overFlowIcon = new TypedValue(); //toolbar 

    //????
    Resources.Theme theme = getTheme();
    theme.resolveAttribute(R.attr.elephantTheme, themeColor, true);
    theme.resolveAttribute(R.attr.elephantStatus, statusColor, true);
    theme.resolveAttribute(R.attr.elephantToolbarText, toolbarTextColor, true);
    theme.resolveAttribute(R.attr.navIcon, navIcon, true);
    theme.resolveAttribute(R.attr.menuSearch, searchIcon, true);
    theme.resolveAttribute(R.attr.menuNotice, noticeIcon, true);
    theme.resolveAttribute(R.attr.overFlowIcon, overFlowIcon, true);

    //??
    mToolBar.getMenu().findItem(R.id.action_search).setIcon(searchIcon.resourceId);
    mToolBar.getMenu().findItem(R.id.action_notice).setIcon(noticeIcon.resourceId);
    mToolBar.setNavigationIcon(navIcon.resourceId);
    mToolBar.setOverflowIcon(ContextCompat.getDrawable(this, overFlowIcon.resourceId));
    mToolBar.setBackgroundColor(ContextCompat.getColor(this, themeColor.resourceId));
    mToolBar.setTitleTextColor(ContextCompat.getColor(this, toolbarTextColor.resourceId));

    changeStatusColor(statusColor.resourceId);
}

From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarWrapper.java

/**
 * Set the icon at the start of the Snackbar.  If there is no icon it will be added, or if there is then it will be
 * replaced.//from  w ww.ja  v a2 s .  co m
 *
 * @param icon The icon drawable resource to display.
 * @return This instance.
 */
public SnackbarWrapper setIcon(@DrawableRes int icon) {
    return setIcon(ContextCompat.getDrawable(context, icon));
}

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

void switchToGrid() {
    IS_LIST = false;//from   w w w . j ava  2 s .  c  o m
    ic = new IconHolder(getActivity(), SHOW_THUMBS, !IS_LIST);
    folder = ContextCompat.getDrawable(getContext(), R.drawable.ic_grid_folder_new);
    fixIcons();

    if (theme1 == 1) {
        listView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.holo_dark_background));
    } else {
        if (IS_LIST)
            listView.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.background_light));
        else
            listView.setBackgroundColor(Color.parseColor("#f2f2f2"));
    }
    if (mLayoutManagerGrid == null)
        if (columns == -1 || columns == 0)
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), 3);
        else
            mLayoutManagerGrid = new GridLayoutManager(getActivity(), columns);
    listView.setLayoutManager(mLayoutManagerGrid);
    adapter = null;
}

From source file:com.afeng.xf.widget.snackbarlight.Light.java

/**
 * Make a customized {@link Snackbar} to display a message without any action.
 * Method {@link Light#make(View, CharSequence, Drawable, int, int, int)}.
 *
 * @param view The view to find a parent from.
 * @param text The message to display. Formatted text is supported.
 * @param textIconRes The left icon of the message. Drawable resource id required.
 * @param backgroundColorRes The background color of the Snackbar. Color resource id required.
 * @param textColorRes The color of action message text. Color resource id required.
 * @param duration How long to show the message.
 *                 Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}.
 *
 * @return The customized Snackbar that will be displayed.
 *///from w w  w . ja  v  a2  s .  c  o  m
public static Snackbar make(@NonNull View view, @NonNull CharSequence text, @DrawableRes int textIconRes,
        @ColorRes int backgroundColorRes, @ColorRes int textColorRes, int duration) {
    Context context = view.getContext();
    return make(view, text,
            // DO NOT use the resource id directly.
            // It should be a resolved drawable or color.
            ContextCompat.getDrawable(context, textIconRes),
            // getResources().getColor() is deprecated.
            ContextCompat.getColor(context, backgroundColorRes), ContextCompat.getColor(context, textColorRes),
            duration);
}