Drawable drawable = notificationBackgroundDrawable.getConstantState().newDrawable(); notification.setBackground(drawable); } else {
@RequiresApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean canApplyTheme() { final int count = mNumChildren; final Drawable[] drawables = mDrawables; for (int i = 0; i < count; i++) { final Drawable d = drawables[i]; if (d != null) { if (d.canApplyTheme()) { return true; } } else { final ConstantState future = mDrawableFutures.get(i); if (future != null && future.canApplyTheme()) { return true; } } } return false; }
alert.setIcon(icon.getConstantState().newDrawable());
newDrawable = chipDrawable.getConstantState().newDrawable();
Drawable.ConstantState cs = miniFabTextBackground.mutate().getConstantState(); if (cs != null) { ViewCompat.setBackground(label, cs.newDrawable());
mRefineView.setBackground(itemBackground.getConstantState().newDrawable()); mRefineView.setId(R.id.refine_view_id); mRefineView.setClickable(true);
mItemBackground.getConstantState().newDrawable() : null); NavigationMenuTextItem item = (NavigationMenuTextItem) mItems.get(position); itemView.setNeedsEmptyIcon(item.needsEmptyIcon);
mErrorBackground = mOriginalBackground.getConstantState().newDrawable(); mErrorBackground.mutate().setColorFilter( ApiCompatibilityUtils.getColor(getResources(), R.color.input_underline_error_color),
Drawable icon; if (file.isDirectory()) { icon = _defaultFolderIcon.getConstantState().newDrawable(); tvSize.setText(""); if (file.lastModified() != 0L) { d = _defaultFileIcon; icon = d.getConstantState().newDrawable(); tvSize.setText(FileUtil.getReadableFileSize(file.length())); tvDate.setText(_formatter.format(new Date(file.lastModified())));
params1.bottomMargin = padding / 4; Button btnToast = new Button(this); btnToast.setBackground(constantState == null ? null : constantState.newDrawable()); btnToast.setTextColor(Color.WHITE); btnToast.setText("Show Toast"); params2.bottomMargin = padding / 4; Button btnCancel = new Button(this); btnCancel.setBackground(constantState == null ? null : constantState.newDrawable()); btnCancel.setTextColor(Color.WHITE); btnCancel.setText("Cancel");
background.getPadding(bgPadding); mContainerView.setBackground(background); mRevealView.setBackground(background.getConstantState().newDrawable()); mAppsRecyclerView.updateBackgroundPadding(bgPadding); mAdapter.updateBackgroundPadding(bgPadding);
Drawable newDrawable = state.newDrawable().mutate(); newDrawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); newDrawable.setBounds(drawable.getBounds());
} else { mView.setSelected(false); mView.setBackgroundDrawable(mAdapter.mChannelBackground.getConstantState().newDrawable()); mName.setTextColor(mAdapter.mDefaultForegroundColor);
final Drawable copy = drawable.getConstantState().newDrawable().mutate(); copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); return copy;
currentLinkSymbol = linkSymbol.mutate(); } else { currentLinkSymbol = linkSymbol.getConstantState().newDrawable().mutate();
LayerState(LayerState orig, LayerDrawable owner) { if (orig != null) { final Rec[] origRec = orig.mArray; final int N = orig.mNum; mNum = N; mArray = new Rec[N]; mChangingConfigurations = orig.mChangingConfigurations; mChildrenChangingConfigurations = orig.mChildrenChangingConfigurations; for (int i = 0; i < N; i++) { final Rec r = mArray[i] = new Rec(); final Rec or = origRec[i]; r.mDrawable = or.mDrawable.getConstantState().newDrawable(); r.mDrawable.setCallback(owner); r.mInsetL = or.mInsetL; r.mInsetT = or.mInsetT; r.mInsetR = or.mInsetR; r.mInsetB = or.mInsetB; r.mId = or.mId; } mHaveOpacity = orig.mHaveOpacity; mOpacity = orig.mOpacity; mHaveStateful = orig.mHaveStateful; mStateful = orig.mStateful; mCheckedConstantState = mCanConstantState = true; } else { mNum = 0; mArray = null; } }
@Override public boolean expandItemActionView(MenuBuilder menu, MenuItemImpl item) { mExpandedActionView = item.getActionView(); mExpandedHomeLayout.setIcon(mIcon.getConstantState().newDrawable(/* TODO getResources() */)); mCurrentExpandedItem = item; if (mExpandedActionView.getParent() != ActionBarView.this) { addView(mExpandedActionView); } if (mExpandedHomeLayout.getParent() != ActionBarView.this) { addView(mExpandedHomeLayout); } mHomeLayout.setVisibility(GONE); if (mTitleLayout != null) mTitleLayout.setVisibility(GONE); if (mTabScrollView != null) mTabScrollView.setVisibility(GONE); if (mSpinner != null) mSpinner.setVisibility(GONE); if (mCustomNavView != null) mCustomNavView.setVisibility(GONE); requestLayout(); item.setActionViewExpanded(true); if (mExpandedActionView instanceof CollapsibleActionView) { ((CollapsibleActionView) mExpandedActionView).onActionViewExpanded(); } return true; }
/** * Gets the activity or application icon for an activity. * Uses the local icon cache for fast repeated lookups. * * @param component Name of an activity. * @return A drawable, or {@code null} if neither the activity nor the application * has an icon set. */ private Drawable getActivityIconWithCache(ComponentName component) { // First check the icon cache String componentIconKey = component.flattenToShortString(); // Using containsKey() since we also store null values. if (mOutsideDrawablesCache.containsKey(componentIconKey)) { Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey); return cached == null ? null : cached.newDrawable(mProviderContext.getResources()); } // Then try the activity or application icon Drawable drawable = getActivityIcon(component); // Stick it in the cache so we don't do this lookup again. Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState(); mOutsideDrawablesCache.put(componentIconKey, toCache); return drawable; }
private void setThumbDrawable(Thumb thumb, Drawable thumbDrawable, int thumbColor) { requireNonNull(thumbDrawable); Drawable nThumbDrawable = getTintedDrawable(thumbDrawable.getConstantState().newDrawable(), thumbColor); nThumbDrawable.setCallback(this); // Assuming the thumb drawable is symmetric, set the thumb offset // such that the thumb will hang halfway off either edge of the // progress bar. thumb.setThumbOffset(thumbDrawable.getIntrinsicWidth() / 2); // If we're updating get the new states if (thumb.getThumb() != null && (nThumbDrawable.getIntrinsicWidth() != thumb.getThumb() .getIntrinsicWidth() || nThumbDrawable.getIntrinsicHeight() != thumb.getThumb().getIntrinsicHeight())) { requestLayout(); } thumb.setThumb(nThumbDrawable); invalidate(); if (nThumbDrawable != null && nThumbDrawable.isStateful()) { // Note that if the states are different this won't work. // For now, let's consider that an app bug. int[] state = getDrawableState(); nThumbDrawable.setState(state); } }
/** * Returns a shader to set on a Paint that will draw the notification icon in a badge. * * The shader is cached until {@link #setNotificationToShow(NotificationInfo)} is called. */ @Nullable Shader getNotificationIconForBadge(Context context, int badgeColor, int badgeSize, int badgePadding) { if (mNotificationInfo == null) { return null; } if (mNotificationIcon == null) { Drawable icon = mNotificationInfo.getIconForBackground(context, badgeColor) .getConstantState().newDrawable(); int iconSize = badgeSize - badgePadding * 2; icon.setBounds(0, 0, iconSize, iconSize); Bitmap iconBitmap = Bitmap.createBitmap(badgeSize, badgeSize, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(iconBitmap); canvas.translate(badgePadding, badgePadding); icon.draw(canvas); mNotificationIcon = new BitmapShader(iconBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); } return mNotificationIcon; }