Java Code Examples for android.graphics.drawable.Drawable#setCallback()
The following examples show how to use
android.graphics.drawable.Drawable#setCallback() .
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: ViewCompat.java From support with Apache License 2.0 | 6 votes |
public static void setEdgeEffectColor(final EdgeEffect edgeEffect, @ColorRes final int color) { try { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { edgeEffect.setColor(color); return; } final Field edgeField = EdgeEffect.class.getDeclaredField("mEdge"); final Field glowField = EdgeEffect.class.getDeclaredField("mGlow"); edgeField.setAccessible(true); glowField.setAccessible(true); final Drawable edge = (Drawable) edgeField.get(edgeEffect); final Drawable glow = (Drawable) glowField.get(edgeEffect); edge.setColorFilter(color, PorterDuff.Mode.SRC_IN); glow.setColorFilter(color, PorterDuff.Mode.SRC_IN); edge.setCallback(null); // free up any references glow.setCallback(null); // free up any references } catch (final Exception ignored) { ignored.printStackTrace(); } }
Example 2
Source File: DropDown.java From Carbon with Apache License 2.0 | 6 votes |
/** * Set the button graphic to a given Drawable * * @param d The Drawable to use as the button graphic */ public void setButtonDrawable(Drawable d) { if (drawable != d) { if (drawable != null) { drawable.setCallback(null); unscheduleDrawable(drawable); } drawable = d; if (d != null) { drawable = DrawableCompat.wrap(d); d.setCallback(this); //d.setLayoutDirection(getLayoutDirection()); if (d.isStateful()) { d.setState(getDrawableState()); } d.setVisible(getVisibility() == VISIBLE, false); setMinHeight(d.getIntrinsicHeight()); updateButtonTint(); } } }
Example 3
Source File: UnikeryDrawable.java From MHViewer with Apache License 2.0 | 6 votes |
@Override public void setDrawable(Drawable drawable) { // Remove old callback Drawable oldDrawable = getDrawable(); if (oldDrawable != null) { oldDrawable.setCallback(null); } super.setDrawable(drawable); if (drawable != null) { drawable.setCallback(mTextView); } updateBounds(); if (drawable != null) { invalidateSelf(); } }
Example 4
Source File: Utils.java From Noyze with Apache License 2.0 | 6 votes |
public static Bitmap recolorBitmap(Drawable drawable, int color) { if (drawable == null) { return null; } int width = drawable.getIntrinsicWidth(); int height = drawable.getIntrinsicHeight(); if (width <= 0 || height <= 0) { return Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); } Bitmap outBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(outBitmap); drawable.setBounds(0, 0, outBitmap.getWidth(), outBitmap.getHeight()); drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); drawable.draw(canvas); drawable.setColorFilter(null); drawable.setCallback(null); // free up any references return outBitmap; }
Example 5
Source File: UnikeryDrawable.java From EhViewer with Apache License 2.0 | 6 votes |
@Override public void setDrawable(Drawable drawable) { // Remove old callback Drawable oldDrawable = getDrawable(); if (oldDrawable != null) { oldDrawable.setCallback(null); } super.setDrawable(drawable); if (drawable != null) { drawable.setCallback(mTextView); } updateBounds(); if (drawable != null) { invalidateSelf(); } }
Example 6
Source File: RangeSeekBar.java From RangeSeekBar with MIT License | 6 votes |
/** * Assign a new tick mark drawable * @param tickMark */ public void setTickMark(Drawable tickMark) { if (mTickMark != null) { mTickMark.setCallback(null); } mTickMark = tickMark; if (tickMark != null) { setProgressOffset(0); tickMark.setCallback(this); if (tickMark.isStateful()) { tickMark.setState(getDrawableState()); } final int w = tickMark.getIntrinsicWidth(); final int h = tickMark.getIntrinsicHeight(); final int halfW = w >= 0 ? w / 2 : 1; final int halfH = h >= 0 ? h / 2 : 1; tickMark.setBounds(-halfW, -halfH, halfW, halfH); applyTickMarkTint(); } invalidate(); }
Example 7
Source File: FlexibleToolbarLayout.java From AppCompat-Extension-Library with Apache License 2.0 | 6 votes |
/** * Set the drawable to use for the content scrim from resources. Providing null will disable * the scrim functionality. * * @param drawable the drawable to display * @attr ref R.styleable#FlexibleToolbarLayout_contentScrimColor * @see #getContentScrim() */ public void setContentScrim(@Nullable Drawable drawable) { if (mContentScrim != drawable) { if (mContentScrim != null) { mContentScrim.setCallback(null); } if (drawable != null) { mContentScrim = drawable.mutate(); drawable.setBounds(0, 0, getWidth(), getHeight()); drawable.setCallback(this); drawable.setAlpha(mScrimAlpha); } else { mContentScrim = null; } ViewCompat.postInvalidateOnAnimation(this); } }
Example 8
Source File: ChipDrawable.java From material-components-android with Apache License 2.0 | 6 votes |
/** Note: This should not change the size of the drawable. */ private void applyChildDrawable(@Nullable Drawable drawable) { if (drawable == null) { return; } drawable.setCallback(this); DrawableCompat.setLayoutDirection(drawable, DrawableCompat.getLayoutDirection(this)); drawable.setLevel(getLevel()); drawable.setVisible(isVisible(), false); if (drawable == closeIcon) { if (drawable.isStateful()) { drawable.setState(getCloseIconState()); } DrawableCompat.setTintList(drawable, closeIconTint); return; } if (drawable.isStateful()) { drawable.setState(getState()); } if (drawable == chipIcon && hasChipIconTint) { DrawableCompat.setTintList(chipIcon, chipIconTint); } }
Example 9
Source File: SimpleTextView.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public void setLeftDrawable(Drawable drawable) { if (leftDrawable == drawable) { return; } if (leftDrawable != null) { leftDrawable.setCallback(null); } leftDrawable = drawable; if (drawable != null) { drawable.setCallback(this); } if (!recreateLayoutMaybe()) { invalidate(); } }
Example 10
Source File: IcsProgressBar.java From Libraries-for-Android-Developers with MIT License | 5 votes |
/** * <p>Define the drawable used to draw the progress bar in * progress mode.</p> * * @param d the new drawable * * @see #getProgressDrawable() * @see #setIndeterminate(boolean) */ public void setProgressDrawable(Drawable d) { boolean needUpdate; if (mProgressDrawable != null && d != mProgressDrawable) { mProgressDrawable.setCallback(null); needUpdate = true; } else { needUpdate = false; } if (d != null) { d.setCallback(this); // Make sure the ProgressBar is always tall enough int drawableHeight = d.getMinimumHeight(); if (mMaxHeight < drawableHeight) { mMaxHeight = drawableHeight; requestLayout(); } } mProgressDrawable = d; if (!mIndeterminate) { mCurrentDrawable = d; postInvalidate(); } if (needUpdate) { updateDrawableBounds(getWidth(), getHeight()); updateDrawableState(); doRefreshProgress(android.R.id.progress, mProgress, false, false); doRefreshProgress(android.R.id.secondaryProgress, mSecondaryProgress, false, false); } }
Example 11
Source File: CombinedDrawable.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public CombinedDrawable(Drawable backgroundDrawable, Drawable iconDrawable) { background = backgroundDrawable; icon = iconDrawable; if (iconDrawable != null) { iconDrawable.setCallback(this); } }
Example 12
Source File: PLAAbsListView.java From SimplifyReader with Apache License 2.0 | 5 votes |
public void setSelector(Drawable sel) { if (mSelector != null) { mSelector.setCallback(null); unscheduleDrawable(mSelector); } mSelector = sel; Rect padding = new Rect(); sel.getPadding(padding); mSelectionLeftPadding = padding.left; mSelectionTopPadding = padding.top; mSelectionRightPadding = padding.right; mSelectionBottomPadding = padding.bottom; sel.setCallback(this); sel.setState(getDrawableState()); }
Example 13
Source File: FlashView.java From Social with Apache License 2.0 | 5 votes |
@SuppressWarnings("unused") private void destoryBitmaps() { for (int i = 0; i < imageViewsList.size(); i++) { ImageView imageView = imageViewsList.get(i); Drawable drawable = imageView.getDrawable(); if (drawable != null) { drawable.setCallback(null); } } }
Example 14
Source File: ComponentHost.java From litho with Apache License 2.0 | 5 votes |
private void unmountDrawable(Drawable drawable) { assertMainThread(); drawable.setCallback(null); invalidate(drawable.getBounds()); releaseScrapDataStructuresIfNeeded(); }
Example 15
Source File: DrawableUtils.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * Sets callback to the drawable. * @param drawable drawable to set callbacks to * @param callback standard Android Drawable.Callback * @param transformCallback TransformCallback used by TransformAwareDrawables */ public static void setCallbacks( Drawable drawable, @Nullable Drawable.Callback callback, @Nullable TransformCallback transformCallback) { if (drawable != null) { drawable.setCallback(callback); if (drawable instanceof TransformAwareDrawable) { ((TransformAwareDrawable) drawable).setTransformCallback(transformCallback); } } }
Example 16
Source File: CheckedTextView.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void setCheckMarkDrawableInternal(@Nullable Drawable d, @DrawableRes int resId) { if (mCheckMarkDrawable != null) { mCheckMarkDrawable.setCallback(null); unscheduleDrawable(mCheckMarkDrawable); } mNeedRequestlayout = (d != mCheckMarkDrawable); if (d != null) { d.setCallback(this); d.setVisible(getVisibility() == VISIBLE, false); d.setState(CHECKED_STATE_SET); // Record the intrinsic dimensions when in "checked" state. setMinHeight(d.getIntrinsicHeight()); mCheckMarkWidth = d.getIntrinsicWidth(); d.setState(getDrawableState()); } else { mCheckMarkWidth = 0; } mCheckMarkDrawable = d; mCheckMarkResource = resId; applyCheckMarkTint(); // Do padding resolution. This will call internalSetPadding() and do a // requestLayout() if needed. resolvePadding(); }
Example 17
Source File: CompositionAvatarView.java From CompositionAvatar with MIT License | 5 votes |
/** * 添加drawable, 如果id已经存在, drawable将会被替换 * * @param id the drawable id. * @param drawable the drawable. * @return <code>true</code> - 如果添加成功, <code>false</code> - 其他 */ public boolean addDrawable(int id, @NonNull Drawable drawable) { DrawableInfo old = findAvatarDrawableById(id); if (old != null) { Drawable d = old.mDrawable; old.mDrawable = drawable; if (!hasSameDrawable(d)) { cleanDrawable(d); } updateDrawableBounds(old); } else { if (getNumberOfDrawables() >= MAX_DRAWABLE_COUNT) { return false; } mDrawables.add(crateAvatarDrawable(id, drawable)); layoutDrawables(); } drawable.setCallback(this); drawable.setVisible(getWindowVisibility() == VISIBLE && isShown(), true); if (drawable.isStateful()) { drawable.setState(getDrawableState()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { drawable.setLayoutDirection(getLayoutDirection()); } invalidate(); return true; }
Example 18
Source File: ForegroundDelegate.java From ForegroundViews with Apache License 2.0 | 5 votes |
/** * Supply a Drawable that is to be rendered on top of all of the child * views in the frame layout. Any padding in the Drawable will be taken * into account by ensuring that the children are inset to be placed * inside of the padding area. * * @param drawable The Drawable to be drawn on top of the children. */ public void setForeground(@Nullable Drawable drawable) { if (mForeground != drawable) { if (mForeground != null) { mForeground.setCallback(null); mView.unscheduleDrawable(mForeground); } mForeground = drawable; if (drawable != null) { mView.setWillNotDraw(false); drawable.setCallback(mView); if (drawable.isStateful()) { drawable.setState(mView.getDrawableState()); } if (mForegroundGravity == Gravity.FILL) { Rect padding = new Rect(); drawable.getPadding(padding); } } else { mView.setWillNotDraw(true); } mView.requestLayout(); mView.invalidate(); } }
Example 19
Source File: EmojiSpan.java From aurora-imui with MIT License | 4 votes |
public EmojiSpan(Drawable drawable, View view) { super(drawable); drawable.setCallback(view); }
Example 20
Source File: CircularView.java From CircularView with Apache License 2.0 | 4 votes |
private void init(AttributeSet attrs, int defStyle) { // Load attributes final TypedArray a = getContext().obtainStyledAttributes( attrs, R.styleable.CircularView, defStyle, 0); final int centerBackgroundColor = a.getColor( R.styleable.CircularView_centerBackgroundColor, CircularViewObject.NO_COLOR); // Set up a default TextPaint object mTextPaint = new TextPaint(); mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTextAlign(Paint.Align.LEFT); mText = a.getString(R.styleable.CircularView_text); mTextPaint.setTextSize(a.getDimension( R.styleable.CircularView_textSize, 24f)); mTextPaint.setColor(a.getColor( R.styleable.CircularView_textColor, mTextPaint.getColor())); Drawable circleDrawable = null; if (a.hasValue(R.styleable.CircularView_centerDrawable)) { circleDrawable = a.getDrawable( R.styleable.CircularView_centerDrawable); circleDrawable.setCallback(this); } mHighlightedDegreeObjectAnimator = new ObjectAnimator(); mHighlightedDegreeObjectAnimator.setTarget(CircularView.this); mHighlightedDegreeObjectAnimator.setPropertyName("highlightedDegree"); mHighlightedDegreeObjectAnimator.addListener(mAnimatorListener); // Update TextPaint and text measurements from attributes invalidateTextPaintAndMeasurements(); mCirclePaint = new Paint(); mCirclePaint.setFlags(Paint.ANTI_ALIAS_FLAG); mCirclePaint.setStyle(Paint.Style.FILL); mCirclePaint.setColor(Color.RED); mDrawHighlightedMarkerOnTop = a.getBoolean(R.styleable.CircularView_drawHighlightedMarkerOnTop, false); mHighlightedMarker = null; mHighlightedMarkerPosition = -1; mHighlightedDegree = a.getFloat(R.styleable.CircularView_highlightedDegree, HIGHLIGHT_NONE); mMarkerStartingPoint = a.getFloat(R.styleable.CircularView_markerStartingPoint, 0f); mAnimateMarkersOnStillHighlight = a.getBoolean(R.styleable.CircularView_animateMarkersOnStillHighlight, false); mAnimateMarkersOnHighlightAnimation = false; mIsAnimating = false; mCircle = new CircularViewObject(getContext(), CIRCLE_TO_MARKER_PADDING, centerBackgroundColor); mCircle.setSrc(circleDrawable); mCircle.setFitToCircle(a.getBoolean(R.styleable.CircularView_fitToCircle, false)); mDefaultMarkerRadius = getResources().getInteger(R.integer.cv_default_marker_radius); mEditModeMarkerCount = a.getInt(R.styleable.CircularView_editMode_markerCount, 0); mEditModeMarkerRadius = a.getInt(R.styleable.CircularView_editMode_markerRadius, mDefaultMarkerRadius); a.recycle(); setOnLongClickListener(mOnLongClickListener); if (isInEditMode()) { mAdapter = new SimpleCircularViewAdapter() { @Override public int getCount() { return mEditModeMarkerCount; } @Override public void setupMarker(int position, Marker marker) { marker.setRadius(mEditModeMarkerRadius); marker.setCenterBackgroundColor(getResources().getColor(android.R.color.black)); } }; } }