Java Code Examples for android.content.Context#getDrawable()

The following examples show how to use android.content.Context#getDrawable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListViewItem.java    From odyssey with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Extracts the information from a playlist model.
 *
 * @param playlist The current playlist model.
 */
public void setPlaylist(final PlaylistModel playlist) {
    final Context context = getContext();

    // title
    String playlistTitle = playlist.getPlaylistName();

    // get icon
    Drawable icon = context.getDrawable(R.drawable.ic_queue_music_48dp);

    if (icon != null) {
        // get tint color
        int tintColor = ThemeUtils.getThemeColor(context, R.attr.odyssey_color_text_background_secondary);
        // tint the icon
        DrawableCompat.setTint(icon, tintColor);
    }

    setTitle(playlistTitle);
    setIcon(icon);
}
 
Example 2
Source File: AppSecurityPermissions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public Drawable loadGroupIcon(Context context, PackageManager pm) {
    if (icon != 0) {
        return loadUnbadgedIcon(pm);
    } else {
        return context.getDrawable(R.drawable.ic_perm_device_info);
    }
}
 
Example 3
Source File: Views.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
@TargetApi(LOLLIPOP)
@SuppressWarnings("deprecation")
public static Drawable getDrawable(Context context, @DrawableRes int id) {
    if (App.isCompatible(LOLLIPOP)) {
        return context.getDrawable(id);
    } else {
        return context.getResources().getDrawable(id);
    }
}
 
Example 4
Source File: Compat.java    From geopaparazzi with GNU General Public License v3.0 5 votes vote down vote up
public static Drawable getDrawable(Context context, int id) {
        Drawable drawable = null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            drawable = context.getDrawable(id);
        } else {
            drawable = AppCompatResources.getDrawable(context, id);
//            drawable = context.getResources().getDrawable(id);
        }
        return drawable;
    }
 
Example 5
Source File: Utils.java    From picasso-transformations with Apache License 2.0 5 votes vote down vote up
public static Drawable getMaskDrawable(Context context, int maskId) {
  Drawable drawable;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    drawable = context.getDrawable(maskId);
  } else {
    drawable = context.getResources().getDrawable(maskId);
  }

  if (drawable == null) {
    throw new IllegalArgumentException("maskId is invalid");
  }

  return drawable;
}
 
Example 6
Source File: DrawableUtils.java    From ChangeTabLayout with Apache License 2.0 5 votes vote down vote up
static Drawable getDrawable(Context context, int drawableResId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.getDrawable(drawableResId);
    } else {
        try {
            return VectorDrawableCompat.create(context.getResources(), drawableResId, null);
        }catch (Resources.NotFoundException e){
            return ContextCompat.getDrawable(context, drawableResId);
        }
    }
}
 
Example 7
Source File: MouseFragment.java    From wearmouse with Apache License 2.0 5 votes vote down vote up
@Override
public Drawable getItemDrawable(int i) {
    Context context = getContext();
    switch (i) {
        case HandMode.LEFT:
            return context.getDrawable(R.drawable.ic_am_hand_left);
        case HandMode.CENTER:
            return context.getDrawable(R.drawable.ic_am_hand_center);
        case HandMode.RIGHT:
            return context.getDrawable(R.drawable.ic_am_hand_right);
        default:
            break;
    }
    return null;
}
 
Example 8
Source File: CompatUtils.java    From AndroidPicker with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static Drawable getDrawable(Context context, @DrawableRes int drawableRes) {
    if (Build.VERSION.SDK_INT < 21) {
        //noinspection deprecation
        return context.getResources().getDrawable(drawableRes);
    } else {
        return context.getDrawable(drawableRes);
    }
}
 
Example 9
Source File: UiUtil.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@SuppressWarnings("deprecation")
public static Drawable getDrawable(@NonNull Context context, @DrawableRes int drawableId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return context.getDrawable(drawableId);

    //noinspection deprecation
    return context.getResources().getDrawable(drawableId);
}
 
Example 10
Source File: TextSelectionHandleView.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
public static Drawable getDrawable(Context context, boolean rightHandle) {
    int resId = StyledAttributesHelper.getResourceId(context, rightHandle ?
            android.R.attr.textSelectHandleRight : android.R.attr.textSelectHandleLeft, -1);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return context.getDrawable(resId);
    else
        return context.getResources().getDrawable(resId);
}
 
Example 11
Source File: AnalogComplicationConfigRecyclerViewAdapter.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
public void setDefaultComplicationDrawable(int resourceId) {
    Context context = mWatchFaceArmsAndTicksView.getContext();
    mDefaultComplicationDrawable = context.getDrawable(resourceId);

    mLeftComplication.setImageDrawable(mDefaultComplicationDrawable);
    mLeftComplicationBackground.setVisibility(View.INVISIBLE);

    mRightComplication.setImageDrawable(mDefaultComplicationDrawable);
    mRightComplicationBackground.setVisibility(View.INVISIBLE);
}
 
Example 12
Source File: DividerItemDecoration.java    From NanoIconPack with Apache License 2.0 5 votes vote down vote up
/**
     * Creates a divider {@link RecyclerView.ItemDecoration} that can be used with a
     * {@link LinearLayoutManager}.
     *
     * @param context Current context, it will be used to access resources.
     * @param orientation Divider orientation. Should be {@link #HORIZONTAL} or {@link #VERTICAL}.
     */
    public DividerItemDecoration(Context context, int orientation) {
//        final TypedArray a = context.obtainStyledAttributes(ATTRS);
//        mDivider = a.getDrawable(0);
//        a.recycle();
        // @By_syk
        mDivider = context.getDrawable(R.drawable.app_list_divider);
        setOrientation(orientation);
    }
 
Example 13
Source File: SeekBarForegroundThumb.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
private void init(Context context) {
    this.context = context;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        tickMark = context.getDrawable(R.drawable.seekbar_tickmark);
    } else {
        tickMark = context.getResources().getDrawable(R.drawable.seekbar_tickmark);
    }
}
 
Example 14
Source File: SendScreen.java    From smartcoins-wallet with MIT License 5 votes vote down vote up
public static Drawable getDrawable(Context context, int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //>= API 21
        return context.getDrawable(id);
    } else {
        return context.getResources().getDrawable(id);
    }
}
 
Example 15
Source File: TintedDrawableSpan.java    From LaunchEnr with GNU General Public License v3.0 4 votes vote down vote up
public TintedDrawableSpan(Context context, int resourceId) {
    super(ALIGN_BOTTOM);
    mDrawable = context.getDrawable(resourceId);
    mOldTint = 0;
}
 
Example 16
Source File: ServerStatusPreference.java    From FCM-for-Mojo with GNU General Public License v3.0 4 votes vote down vote up
private void updateStatus(String error) {
    Context context = getContext();
    Drawable icon = context.getDrawable(R.drawable.ic_status_error_24dp);
    updateStatus(context.getString(R.string.status_cannot_connect_server_error, error), R.attr.colorAlert, icon);
}
 
Example 17
Source File: CustomKeyboardView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
public CustomKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;
    mKeyBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mKeyCapStartBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mVerticalCorrection = 0;
    previewLayout = 0;
    mPreviewOffset = 0;
    mPreviewHeight = 80;
    mKeyTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_text_size);
    mKeyTextColor = 0xFFFFFFFF;
    mLabelTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_longtext_size);
    mPopupLayout = R.layout.keyboard;
    mShadowColor = 0;
    mShadowRadius = 0;
    mBackgroundDimAmount = 0.5f;
    clearHover();

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);
    mPaint.setTypeface(Typeface.create("sans-serif",Typeface.NORMAL));

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<>();
    mKeyBackground.getPadding(mPadding);
    mKeyboardHoveredPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_hovered_padding);
    mKeyboardPressedPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_pressed_padding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = false;

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();

    mForegroundColor = context.getColor(R.color.asphalt);
    mSelectedForegroundColor = context.getColor(R.color.fog);
}
 
Example 18
Source File: ToastyUtils.java    From Bus-Tracking-Parent with GNU General Public License v3.0 4 votes vote down vote up
static Drawable getDrawable(@NonNull Context context, @DrawableRes int id) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return context.getDrawable(id);
    else
        return context.getResources().getDrawable(id);
}
 
Example 19
Source File: DividerGridItemDecoration.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public DividerGridItemDecoration(Context context, @DrawableRes int widthDividerRes, @DrawableRes int heightDividerRes) {
    mWidthDivider = context.getDrawable(widthDividerRes);
    mHeightDivider = context.getDrawable(heightDividerRes);
}
 
Example 20
Source File: Utils.java    From MaterialSpinner with Apache License 2.0 3 votes vote down vote up
/**
 * Return a drawable object associated with a particular resource ID.
 *
 * <p>Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the returned drawable will be styled for the
 * specified Context's theme.</p>
 *
 * @param id The desired resource identifier, as generated by the aapt tool.
 * This integer encodes the package, type, and resource entry.
 * The value 0 is an invalid identifier.
 * @return Drawable An object that can be used to draw this resource.
 */
static Drawable getDrawable(Context context, int id) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    return context.getDrawable(id);
  }
  return context.getResources().getDrawable(id);
}