Java Code Examples for android.support.v4.content.ContextCompat#getDrawable()
The following examples show how to use
android.support.v4.content.ContextCompat#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: MessageInternalUserTextViewHolder.java From SlyceMessaging with MIT License | 6 votes |
public MessageInternalUserTextViewHolder(View itemView, CustomSettings customSettings) { super(itemView, customSettings); avatar = (ImageView) itemView.findViewById(R.id.message_user_text_image_view_avatar); carrot = (ImageView) itemView.findViewById(R.id.message_user_text_image_view_carrot); initials = (TextView) itemView.findViewById(R.id.message_user_text_text_view_initials); text = (TextView) itemView.findViewById(R.id.message_user_text_text_view_text); timestamp = (TextView) itemView.findViewById(R.id.message_user_text_text_view_timestamp); avatarContainer = (ViewGroup) itemView.findViewById(R.id.message_user_text_view_group_avatar); bubble = (FrameLayout) itemView.findViewById(R.id.message_user_text_view_group_bubble); Drawable drawable = ContextCompat.getDrawable(itemView.getContext(), R.drawable.shape_rounded_rectangle_white); // Drawable drawable = itemView.getContext().getDrawable(); drawable.setColorFilter(customSettings.localBubbleBackgroundColor, PorterDuff.Mode.SRC_ATOP); bubble.setBackground(drawable); carrot.setColorFilter(customSettings.localBubbleBackgroundColor); text.setTextColor(customSettings.localBubbleTextColor); timestamp.setTextColor(customSettings.timestampColor); }
Example 2
Source File: FloatingActionsMenu.java From android-chat-ui with Apache License 2.0 | 6 votes |
private void init(Context context, AttributeSet attributeSet) { mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset)); mLabelsMargin = getResources().getDimensionPixelSize(R.dimen.fab_labels_margin); mLabelsVerticalOffset = getResources().getDimensionPixelSize(R.dimen.fab_shadow_offset); mTouchDelegateGroup = new TouchDelegateGroup(this); setTouchDelegate(mTouchDelegateGroup); TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0); mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonPlusIconColor, getColor(android.R.color.white)); mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorNormal, getColor(android.R.color.holo_blue_dark)); mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_fab_addButtonColorPressed, getColor(android.R.color.holo_blue_light)); mAddButtonSize = attr.getInt(R.styleable.FloatingActionsMenu_fab_addButtonSize, FloatingActionButton.SIZE_NORMAL); mAddButtonStrokeVisible = attr.getBoolean(R.styleable.FloatingActionsMenu_fab_addButtonStrokeVisible, true); mExpandDirection = attr.getInt(R.styleable.FloatingActionsMenu_fab_expandDirection, EXPAND_UP); mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionsMenu_fab_labelStyle, 0); mLabelsPosition = attr.getInt(R.styleable.FloatingActionsMenu_fab_labelsPosition, LABELS_ON_LEFT_SIDE); attr.recycle(); if (mLabelsStyle != 0 && expandsHorizontally()) { throw new IllegalStateException("Action labels in horizontal expand orientation is not supported."); } mCloseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_close_drawable); createSendButton(context); }
Example 3
Source File: MyCompetitionsFragment.java From 1Rramp-Android with MIT License | 6 votes |
private void initializeList() { dataStore = new DataStore(); Drawable drawable = ContextCompat.getDrawable(mContext, R.drawable.post_item_divider_view); ViewItemDecoration viewItemDecoration = new ViewItemDecoration(drawable); viewItemDecoration.setWantTopOffset(false, 0); competitionsListRecyclerAdapter = new CompetitionsListRecyclerAdapter(mContext); competitionsListRecyclerAdapter.setDeleteListener(this); competitionsListRecyclerAdapter.setLoadMoreCallback(this); competitionList.setLayoutManager(new LinearLayoutManager(mContext)); competitionList.addItemDecoration(viewItemDecoration); competitionList.setAdapter(competitionsListRecyclerAdapter); swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refreshCompetitions(); } }); }
Example 4
Source File: EasyRatingBar.java From NovelReader with MIT License | 5 votes |
private Drawable getDrawable(WeakReference<Drawable> weak, int res){ Drawable drawable = null; if (weak == null || weak.get() == null){ drawable = ContextCompat.getDrawable(mContext,res); weak = new WeakReference<Drawable>(drawable); } else { drawable = weak.get(); } return drawable; }
Example 5
Source File: AppCompatCompoundButtonHelper.java From timecat with Apache License 2.0 | 5 votes |
@Override public void tint() { if (mCompoundButtonTintResId == 0 || !setSupportButtonDrawableTint(mCompoundButtonTintResId)) { Drawable drawable = mTintManager.getDrawable(mCompoundButtonResId); if (drawable == null) { drawable = mCompoundButtonResId == 0 ? null : ContextCompat.getDrawable(mView.getContext(), mCompoundButtonResId); } setButtonDrawable(drawable); } }
Example 6
Source File: ClearEditText.java From MyHearts with Apache License 2.0 | 5 votes |
private void init(final Context context) { final Drawable drawable = ContextCompat.getDrawable(context, R.drawable.icon_delete_32); final Drawable wrappedDrawable = DrawableCompat.wrap(drawable); //Wrap the drawable so that it can be tinted pre Lollipop DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor()); mClearTextIcon = wrappedDrawable; // mClearTextIcon= context.getResources().getDrawable(R.drawable.icon_delete_32); mClearTextIcon.setBounds(0, 0, mClearTextIcon.getIntrinsicHeight(), mClearTextIcon.getIntrinsicHeight()); setClearIconVisible(false); super.setOnTouchListener(this); super.setOnFocusChangeListener(this); addTextChangedListener(this); }
Example 7
Source File: ActionBarDrawerToggle.java From letv with Apache License 2.0 | 5 votes |
public void onConfigurationChanged(Configuration newConfig) { if (!this.mHasCustomUpIndicator) { this.mHomeAsUpIndicator = getThemeUpIndicator(); } this.mDrawerImage = ContextCompat.getDrawable(this.mActivity, this.mDrawerImageResource); syncState(); }
Example 8
Source File: PasscodeView.java From passcode with Apache License 2.0 | 5 votes |
private void initDefaultConfig() { setOrientation(HORIZONTAL); setGravity(Gravity.CENTER); passCodeViewsList = new ArrayList<>(); activeDrawable = ContextCompat.getDrawable(getContext(), R.drawable.bg_active); inActiveDrawable = ContextCompat.getDrawable(getContext(), R.drawable.bg_in_active); textColor = android.R.color.transparent; drawableSize = 72; passcodeItemMargin = 8; passcodeItems = new StringBuilder(); }
Example 9
Source File: DividerLinearItemDecoration.java From FlexItemDecoration with Apache License 2.0 | 5 votes |
public Builder setStickyDrawable(@DrawableRes int drawableId) { this.mStickyDrawable = ContextCompat.getDrawable(mContext.getApplicationContext(), drawableId); ; if (this.mStickyHeightOrWidth == 0) { this.mStickyHeightOrWidth = mStickyDrawable.getIntrinsicHeight(); } return this; }
Example 10
Source File: FrameAnimActivity.java From AndroidStudyDemo with GNU General Public License v2.0 | 5 votes |
private void initFrameAnimDrawable(boolean isLoadFromXml) { if (isLoadFromXml) { this.mFrameAnimDrawable = (AnimationDrawable) ContextCompat.getDrawable(getBaseContext(), R.drawable.sdd_frameanim); } else { this.mFrameAnimDrawable = new AnimationDrawable(); for (int i=0; i< mFramwAnimDrawableResIDs.length; i++) { this.mFrameAnimDrawable.addFrame(ContextCompat.getDrawable(getBaseContext(), mFramwAnimDrawableResIDs[i]), 100); } } this.mFrameAnimDrawable.setOneShot(false); this.mShowFrameAnimIV.setBackground(mFrameAnimDrawable); }
Example 11
Source File: ImageUtils.java From MediaNotification with Apache License 2.0 | 5 votes |
public static Bitmap getVectorBitmap(Context context, @DrawableRes int id) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { try { return drawableToBitmap(ContextCompat.getDrawable(context, id)); } catch (Resources.NotFoundException e) { return drawableToBitmap(null); } } Drawable drawable; try { drawable = VectorDrawableCompat.create(context.getResources(), id, context.getTheme()); } catch (Resources.NotFoundException e1) { try { drawable = ContextCompat.getDrawable(context, id); } catch (Resources.NotFoundException e2) { return drawableToBitmap(null); } } if (drawable != null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) drawable = (DrawableCompat.wrap(drawable)).mutate(); Bitmap result = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return result; } return null; }
Example 12
Source File: RegisteredApplication.java From MiPushFramework with GNU General Public License v3.0 | 5 votes |
@android.support.annotation.NonNull public Drawable getIcon (Context context) { PackageManager pm = context.getPackageManager(); try { return pm.getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES).loadIcon(pm); } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { return ContextCompat.getDrawable(context, android.R.mipmap.sym_def_app_icon); } }
Example 13
Source File: ClearEditText.java From AndroidUI with MIT License | 5 votes |
/** * 给图标染上当前提示文本的颜色并且转出Bitmap * @param resources * @param context * @return */ public Bitmap createBitmap(int resources,Context context) { final Drawable drawable = ContextCompat.getDrawable(context, resources); final Drawable wrappedDrawable = DrawableCompat.wrap(drawable); DrawableCompat.setTint(wrappedDrawable, getCurrentHintTextColor()); return drawableToBitamp(wrappedDrawable); }
Example 14
Source File: DividerItemDecoration.java From OmniList with GNU Affero General Public License v3.0 | 4 votes |
public DividerItemDecoration(Context context, int orientation, int resId) { mDivider = ContextCompat.getDrawable(context, resId); setOrientation(orientation); }
Example 15
Source File: CurrencyActivity.java From Travel-Mate with MIT License | 4 votes |
void setGraphData(JSONArray currencyRateTrends) { ArrayList<Entry> values = new ArrayList<>(); for (int i = 0; i < currencyRateTrends.length(); i++) { try { values.add(new Entry(i, (float) currencyRateTrends.getDouble(i))); } catch (JSONException e) { e.printStackTrace(); } } LineDataSet lineDataSet = new LineDataSet(values, GRAPH_LABEL_NAME); lineDataSet.setDrawIcons(false); lineDataSet.setColor(Color.RED); lineDataSet.setCircleColor(Color.BLUE); lineDataSet.setCircleRadius(1f); lineDataSet.setLineWidth(1f); lineDataSet.setCircleRadius(3f); lineDataSet.setDrawCircleHole(true); lineDataSet.setValueTextSize(10f); lineDataSet.setValueTextColor(Color.BLACK); lineDataSet.setDrawFilled(true); lineDataSet.setFormSize(10.f); if (Utils.getSDKInt() >= 18) { // fill drawable only supported on api level 18 and above Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_green); lineDataSet.setFillDrawable(drawable); } else { lineDataSet.setFillColor(Color.BLACK); } ArrayList<ILineDataSet> dataSets = new ArrayList<ILineDataSet>(); dataSets.add(lineDataSet); // create a data object with the datasets LineData data = new LineData(dataSets); // set data graph.setData(data); }
Example 16
Source File: Style.java From ChatKit with Apache License 2.0 | 4 votes |
protected final Drawable getDrawable(@DrawableRes int drawable) { return ContextCompat.getDrawable(context, drawable); }
Example 17
Source File: ChipView.java From MaterialChipsInput with Apache License 2.0 | 4 votes |
/** * Inflate the view according to attributes * * @param attrs the attributes */ private void init(AttributeSet attrs) { // inflate layout View rootView = inflate(getContext(), R.layout.chip_view, this); // butter knife ButterKnife.bind(this, rootView); // letter tile provider mLetterTileProvider = new LetterTileProvider(mContext); // attributes if(attrs != null) { TypedArray a = mContext.getTheme().obtainStyledAttributes( attrs, R.styleable.ChipView, 0, 0); try { // label mLabel = a.getString(R.styleable.ChipView_label); mLabelColor = a.getColorStateList(R.styleable.ChipView_labelColor); // avatar icon mHasAvatarIcon = a.getBoolean(R.styleable.ChipView_hasAvatarIcon, false); int avatarIconId = a.getResourceId(R.styleable.ChipView_avatarIcon, NONE); if(avatarIconId != NONE) mAvatarIconDrawable = ContextCompat.getDrawable(mContext, avatarIconId); if(mAvatarIconDrawable != null) mHasAvatarIcon = true; // delete icon mDeletable = a.getBoolean(R.styleable.ChipView_deletable, false); mDeleteIconColor = a.getColorStateList(R.styleable.ChipView_deleteIconColor); int deleteIconId = a.getResourceId(R.styleable.ChipView_deleteIcon, NONE); if(deleteIconId != NONE) mDeleteIcon = ContextCompat.getDrawable(mContext, deleteIconId); // background color mBackgroundColor = a.getColorStateList(R.styleable.ChipView_backgroundColor); } finally { a.recycle(); } } // inflate inflateWithAttributes(); }
Example 18
Source File: BitmapHelper.java From CameraButton with Apache License 2.0 | 4 votes |
static Bitmap getBitmap(Context context, @DrawableRes int drawableId) { Drawable drawable = ContextCompat.getDrawable(context, drawableId); return getBitmap(drawable); }
Example 19
Source File: DividerItemDecoration.java From droidkaigi2016 with Apache License 2.0 | 4 votes |
public DividerItemDecoration(Context context, int resId) { this.divider = ContextCompat.getDrawable(context, resId); }
Example 20
Source File: UiUtils.java From AccountBook with GNU General Public License v3.0 | 2 votes |
/** * 获取drawable资源 * * @param id 资源id * @return */ public static Drawable getDrawable(int id) { return ContextCompat.getDrawable(getContext(), id); }