Example usage for android.support.v4.content.res ResourcesCompat getDrawable

List of usage examples for android.support.v4.content.res ResourcesCompat getDrawable

Introduction

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

Prototype

public static Drawable getDrawable(Resources resources, int i, Theme theme) throws NotFoundException 

Source Link

Usage

From source file:com.example.angelina.travelapp.data.CategoryHelper.java

/**
 * Return appropriate drawable base on place type
 * @param p - Place item// www. ja  v  a2 s  . c o  m
 * @param a - Activity
 * @return - Drawable
 */
public static Drawable getDrawableForPlace(final Place p, final Activity a) {

    final String placeType = p.getType();
    final String category = CategoryHelper.getCategoryForFoodType(placeType);
    final Drawable d;
    switch (category) {
    case "Pizza":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_pizza_black_24dp, null);
        break;
    case "Hotel":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_hotel_black_24dp, null);
        break;
    case "Food":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_dining_black_24dp, null);
        break;
    case "Bar or Pub":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_bar_black_24dp, null);
        break;
    case "Coffee Shop":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_cafe_black_24dp, null);
        break;
    default:
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_place_black_24dp, null);
    }
    return d;
}

From source file:com.nttec.everychan.chans.mentachsu.MentachsuModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_02ch, null);
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeThemer.java

public Drawable getGroupCollapseDrawable() {
    if (mGroupCollapseDrawable == null) {
        mGroupCollapseDrawable = ResourcesCompat.getDrawable(mContext.getResources(), R.drawable.snv_collapse,
                mContext.getTheme());//from   ww  w.  j  a v a  2 s  .  c  o  m
    }

    // Return a new drawable since this method will be
    // called multiple times
    return mGroupCollapseDrawable.getConstantState().newDrawable();
}

From source file:com.findme.views.ExpandableTextView.java

private void init(AttributeSet attrs) {
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines,
            MAX_COLLAPSED_LINES);/*from w  w  w .j  ava2 s . c o  m*/
    mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mAnimAlphaStart = typedArray.getFloat(R.styleable.ExpandableTextView_animAlphaStart,
            DEFAULT_ANIM_ALPHA_START);
    mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);

    if (mExpandDrawable == null) {
        mExpandDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_expand, null);
    }
    if (mCollapseDrawable == null) {
        mCollapseDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_action_collapse, null);
    }

    typedArray.recycle();
}

From source file:com.mischivous.wormysharpyloggy.wsl.model.Tile.java

/**
 * Returns the Drawable representing the Tile.
 *
 * @param context The context to retrieve the Tile from
 * @return A Drawable representing the Tile
 *//*www  .ja  va 2  s .c om*/
@NonNull
public Drawable GetDrawable(@NonNull Context context) {
    if (context == null) {
        throw new NullPointerException("Context cannot be null.");
    }

    int id = context.getResources().getIdentifier(
            String.format("tile_%d%d%d%d", GetNum(), GetShapeVal(), GetColorVal(), GetFillVal()), "mipmap",
            context.getPackageName());

    return ResourcesCompat.getDrawable(context.getResources(), id, null);
}

From source file:com.nttec.everychan.chans.sevenchan.SevenchanModule.java

@Override
public Drawable getChanFavicon() {
    return ResourcesCompat.getDrawable(resources, R.drawable.favicon_7chan, null);
}

From source file:com.rockerhieu.emojicon.slidingTab.SlidingTabLayout.java

/**
 * Method which populates tab strip with icon tabs, which represent each page with icons.
 *///from  w ww . j  a v  a  2 s. c  o m
private void populateTabStrip() {
    final EmojisPagerAdapter adapter = (EmojisPagerAdapter) mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();
    View tabView;

    for (int i = 0; i < adapter.getCount(); i++) {
        ImageView tabIconView = null;

        /// Initialize tab view, get ImageView
        tabView = createDefaultImageView(getContext());
        if (ImageView.class.isInstance(tabView)) {
            tabIconView = (ImageView) tabView;
        }

        //Drawable draw = res.getDrawable(adapter.getDrawableId(i)); --> Deprecated
        Drawable draw = ResourcesCompat.getDrawable(getResources(), adapter.getDrawableId(i), null);

        /// Set icon for the tab...
        if (null != tabIconView) {
            tabIconView.setImageDrawable(draw);
            if (mViewPager.getCurrentItem() == i) {
                tabIconView.setSelected(true);
            }
        }

        /// Create new layout parameters for this tab which is ImageView element...
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.MATCH_PARENT);
        /// Set width for the element if its defined...
        if (0 < mTabWidth) {
            lp.width = mTabWidth;
        } else {
            lp.width = 0;
            lp.weight = 1;
        }
        /// Set layout parameters for this tab.
        tabView.setLayoutParams(lp);

        /// Attach on click listener and add tab to view...
        tabView.setOnClickListener(tabClickListener);
        mTabStrip.addView(tabView);
    }
}

From source file:com.squalala.tariki.ui.map.MapsActivity.java

@DebugLog
@Override/*from  w  ww  . ja  va2  s .c  o  m*/
public void showMarkers(List<Event> events) {

    for (Event event : events) {
        Marker poiMarker = new Marker(map);
        poiMarker.setPosition(event.getPosition());
        poiMarker.setTitle(event.getCategory());
        poiMarker.setSnippet(event.getDescription());
        poiMarkers.add(poiMarker);

        Drawable poiIcon;

        switch (event.getCategory()) {

        case "Travaux":
            poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.travaux, null);
            break;

        case "Pluie":
            poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.pluie, null);
            break;

        case "Accident":
            poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.accident, null);
            break;

        case "Chausse Glissante":
            poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.glissant, null);
            break;

        case "Chute de Neige":
            poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.neige, null);
            break;

        case "Faible visibilit":
            poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.eclairage, null);
            break;

        default:
            poiIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.marker_kml_point, null);
        }

        poiMarker.setIcon(poiIcon);
    }

}

From source file:android.support.design.internal.NavigationMenuItemView.java

@Override
public void setIcon(Drawable icon) {
    if (icon != null) {
        if (mHasIconTintList) {
            Drawable.ConstantState state = icon.getConstantState();
            icon = DrawableCompat.wrap(state == null ? icon : state.newDrawable()).mutate();
            DrawableCompat.setTintList(icon, mIconTintList);
        }//  w  ww  .j  a v a 2 s. c  o  m
        icon.setBounds(0, 0, mIconSize, mIconSize);
    } else if (mNeedsEmptyIcon) {
        if (mEmptyDrawable == null) {
            mEmptyDrawable = ResourcesCompat.getDrawable(getResources(), R.drawable.navigation_empty_icon,
                    getContext().getTheme());
            if (mEmptyDrawable != null) {
                mEmptyDrawable.setBounds(0, 0, mIconSize, mIconSize);
            }
        }
        icon = mEmptyDrawable;
    }
    TextViewCompat.setCompoundDrawablesRelative(mTextView, icon, null, null, null);
}

From source file:com.zphinx.sortattributes.SortDialogManager.java

/**
 * Sets the image to be shown by the drawable associated with the
 * StateTextview/*  www . j a  v  a  2s  .c  om*/
 *
 * @param text
 *            The state textview object whose image is to be set
 * @param draws
 *            The array of drawables used by the textview
 * @param activity
 *            - The activity which uses this dialog
 * @throws NotFoundException
 *             If an error occurs
 */

private static void setCurrentImage(final StateTextView text, Drawable[] draws, Activity activity)
        throws NotFoundException {
    Resources res = activity.getResources();
    Integer curState = text.getSortDirection();
    final Integer newState = (curState == StateTextView.SORT_UNINITIALIZED) ? StateTextView.SORT_DESC
            : (curState == StateTextView.SORT_DESC) ? StateTextView.SORT_ASC : StateTextView.SORT_DESC;

    switch (newState) {
    case StateTextView.SORT_DESC:
        draws[2] = ResourcesCompat.getDrawable(res, R.drawable.icon_bottom_arrow, null);
        break;
    case StateTextView.SORT_ASC:
        draws[2] = ResourcesCompat.getDrawable(res, R.drawable.icon_top_arrow, null);
        break;
    default:
        draws[2] = null;
        break;
    }

    Log.d(TAG, "The drawable to draw is: ........................." + draws[2] + " The oldState is: " + curState
            + " The new state is: " + newState);
    Rect bounds = new Rect(0, 0, draws[2].getIntrinsicWidth(), draws[2].getIntrinsicHeight());
    draws[2].setBounds(bounds);
    text.setCompoundDrawables(null, null, draws[2], null);
    text.setSortDirection(newState);

}