Java Code Examples for android.graphics.drawable.Drawable#setLevel()
The following examples show how to use
android.graphics.drawable.Drawable#setLevel() .
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: ProgressBar.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Convert a AnimationDrawable for use as a barberpole animation. * Each frame of the animation is wrapped in a ClipDrawable and * given a tiling BitmapShader. */ private Drawable tileifyIndeterminate(Drawable drawable) { if (drawable instanceof AnimationDrawable) { AnimationDrawable background = (AnimationDrawable) drawable; final int N = background.getNumberOfFrames(); AnimationDrawable newBg = new AnimationDrawable(); newBg.setOneShot(background.isOneShot()); for (int i = 0; i < N; i++) { Drawable frame = tileify(background.getFrame(i), true); frame.setLevel(10000); newBg.addFrame(frame, background.getDuration(i)); } newBg.setLevel(10000); drawable = newBg; } return drawable; }
Example 2
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 3
Source File: IcsProgressBar.java From android-apps with MIT License | 6 votes |
/** * Convert a AnimationDrawable for use as a barberpole animation. * Each frame of the animation is wrapped in a ClipDrawable and * given a tiling BitmapShader. */ private Drawable tileifyIndeterminate(Drawable drawable) { if (drawable instanceof AnimationDrawable) { AnimationDrawable background = (AnimationDrawable) drawable; final int N = background.getNumberOfFrames(); AnimationDrawable newBg = new AnimationDrawable(); newBg.setOneShot(background.isOneShot()); for (int i = 0; i < N; i++) { Drawable frame = tileify(background.getFrame(i), true); frame.setLevel(10000); newBg.addFrame(frame, background.getDuration(i)); } newBg.setLevel(10000); drawable = newBg; } return drawable; }
Example 4
Source File: OmegaExpandableRecyclerView.java From OmegaRecyclerView with MIT License | 6 votes |
private void updateBackground() { if (isBackgroundSet) { Drawable background = itemView.getBackground(); if (background != null) { background.setLevel(isExpanded() ? expandedResLevel : collapsedResLevel); } } else { if (isExpanded()) { changeBackground(itemView, defaultGroupDrawable, recyclerView.mItemsBackgroundRes, expandedResLevel); } else { changeBackground(itemView, defaultGroupDrawable, recyclerView.mItemsBackgroundRes, collapsedResLevel); } } isBackgroundSet = true; }
Example 5
Source File: SwitchViewHolder.java From home-assistant-Android with GNU General Public License v3.0 | 6 votes |
private void updateColor() { Drawable leftDrawable = name.getCompoundDrawablesRelative()[0]; String domain = entity.getDomain(); if (leftDrawable != null && (domain.equals(LIGHT) || domain.equals(SWITCH))) { if (!(leftDrawable instanceof LevelListDrawable)) { LevelListDrawable levelListDrawable = new LevelListDrawable(); // Add states levelListDrawable.addLevel(1, 1, leftDrawable); BitmapDrawable enabledDrawable = (BitmapDrawable) leftDrawable.getConstantState().newDrawable().mutate(); enabledDrawable.setTintList(ColorStateList.valueOf(ContextCompat.getColor(name.getContext(), R.color.color_activated))); levelListDrawable.addLevel(2, 2, enabledDrawable); // Restore bounds levelListDrawable.setBounds(0, 0, name.getResources().getDimensionPixelSize(R.dimen.icon_size), name.getResources().getDimensionPixelSize(R.dimen.icon_size)); // Set drawable name.setCompoundDrawablesRelative(levelListDrawable, null, null, null); leftDrawable = levelListDrawable; } leftDrawable.setLevel(entity.state.equals(HassUtils.getOnState(entity, false)) ? 1 : 2); } }
Example 6
Source File: SkinCompatProgressBarHelper.java From Android-skin-support with MIT License | 6 votes |
/** * Convert a AnimationDrawable for use as a barberpole animation. * Each frame of the animation is wrapped in a ClipDrawable and * given a tiling BitmapShader. */ private Drawable tileifyIndeterminate(Drawable drawable) { if (drawable instanceof AnimationDrawable) { AnimationDrawable background = (AnimationDrawable) drawable; final int N = background.getNumberOfFrames(); AnimationDrawable newBg = new AnimationDrawable(); newBg.setOneShot(background.isOneShot()); for (int i = 0; i < N; i++) { Drawable frame = tileify(background.getFrame(i), true); frame.setLevel(10000); newBg.addFrame(frame, background.getDuration(i)); } newBg.setLevel(10000); drawable = newBg; } return drawable; }
Example 7
Source File: IcsProgressBar.java From zhangshangwuda with Apache License 2.0 | 6 votes |
/** * Convert a AnimationDrawable for use as a barberpole animation. * Each frame of the animation is wrapped in a ClipDrawable and * given a tiling BitmapShader. */ private Drawable tileifyIndeterminate(Drawable drawable) { if (drawable instanceof AnimationDrawable) { AnimationDrawable background = (AnimationDrawable) drawable; final int N = background.getNumberOfFrames(); AnimationDrawable newBg = new AnimationDrawable(); newBg.setOneShot(background.isOneShot()); for (int i = 0; i < N; i++) { Drawable frame = tileify(background.getFrame(i), true); frame.setLevel(10000); newBg.addFrame(frame, background.getDuration(i)); } newBg.setLevel(10000); drawable = newBg; } return drawable; }
Example 8
Source File: BottomBar.java From Camera2 with Apache License 2.0 | 6 votes |
private LayerDrawable applyCircleDrawableToShutterBackground(LayerDrawable shutterBackground) { // the background for video has a circle_item drawable placeholder // that gets replaced by an AnimatedCircleDrawable for the cool // shrink-down-to-a-circle effect // all other modes need not do this replace Drawable d = shutterBackground.findDrawableByLayerId(R.id.circle_item); if (d != null) { Drawable animatedCircleDrawable = new AnimatedCircleDrawable((int) mCircleRadius); shutterBackground .setDrawableByLayerId(R.id.circle_item, animatedCircleDrawable); animatedCircleDrawable.setLevel(DRAWABLE_MAX_LEVEL); } return shutterBackground; }
Example 9
Source File: IcsProgressBar.java From Libraries-for-Android-Developers with MIT License | 6 votes |
/** * Convert a AnimationDrawable for use as a barberpole animation. * Each frame of the animation is wrapped in a ClipDrawable and * given a tiling BitmapShader. */ private Drawable tileifyIndeterminate(Drawable drawable) { if (drawable instanceof AnimationDrawable) { AnimationDrawable background = (AnimationDrawable) drawable; final int N = background.getNumberOfFrames(); AnimationDrawable newBg = new AnimationDrawable(); newBg.setOneShot(background.isOneShot()); for (int i = 0; i < N; i++) { Drawable frame = tileify(background.getFrame(i), true); frame.setLevel(10000); newBg.addFrame(frame, background.getDuration(i)); } newBg.setLevel(10000); drawable = newBg; } return drawable; }
Example 10
Source File: ProgressButton.java From progress-button with Apache License 2.0 | 5 votes |
@Override protected void onDraw( Canvas canvas ) { super.onDraw( canvas ); if ( loading ) { long time = getDrawingTime(); int i; Drawable d; for (i=0; i < loadingDrawables.length; i++) { d = loadingDrawables[i]; if (d != null) { if ( !(d instanceof Animatable) ) { animation.getTransformation( time, transformation ); float scale = transformation.getAlpha(); try { d.setLevel( (int) (scale * MAX_LEVEL) ); } finally { } ViewCompat.postInvalidateOnAnimation( this ); } if ( mShouldStartAnimationDrawable && d instanceof Animatable ) { ((Animatable) d).start(); mShouldStartAnimationDrawable = false; } } } } }
Example 11
Source File: DrawableUtils.java From ImageLoader with Apache License 2.0 | 5 votes |
/** * Copies various properties from one drawable to the other. * @param to drawable to copy properties to * @param from drawable to copy properties from */ public static void copyProperties(Drawable to, Drawable from) { if (from == null || to == null || to == from) { return; } to.setBounds(from.getBounds()); to.setChangingConfigurations(from.getChangingConfigurations()); to.setLevel(from.getLevel()); to.setVisible(from.isVisible(), /* restart */ false); to.setState(from.getState()); }
Example 12
Source File: LayerDrawable.java From Carbon with Apache License 2.0 | 5 votes |
ChildDrawable(ChildDrawable orig, LayerDrawable owner, Resources res) { final Drawable dr = orig.mDrawable; final Drawable clone; if (dr != null) { final ConstantState cs = dr.getConstantState(); if (res != null) { clone = cs.newDrawable(res); } else { clone = cs.newDrawable(); } clone.setCallback(owner); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) clone.setLayoutDirection(dr.getLayoutDirection()); clone.setBounds(dr.getBounds()); clone.setLevel(dr.getLevel()); } else { clone = null; } mDrawable = clone; mThemeAttrs = orig.mThemeAttrs; mInsetL = orig.mInsetL; mInsetT = orig.mInsetT; mInsetR = orig.mInsetR; mInsetB = orig.mInsetB; mInsetS = orig.mInsetS; mInsetE = orig.mInsetE; mWidth = orig.mWidth; mHeight = orig.mHeight; mGravity = orig.mGravity; mId = orig.mId; }
Example 13
Source File: DrawableUtils.java From fresco with MIT License | 5 votes |
/** * Copies various properties from one drawable to the other. * * @param to drawable to copy properties to * @param from drawable to copy properties from */ public static void copyProperties(@Nullable Drawable to, @Nullable Drawable from) { if (from == null || to == null || to == from) { return; } to.setBounds(from.getBounds()); to.setChangingConfigurations(from.getChangingConfigurations()); to.setLevel(from.getLevel()); to.setVisible(from.isVisible(), /* restart */ false); to.setState(from.getState()); }
Example 14
Source File: IcsProgressBar.java From Libraries-for-Android-Developers with MIT License | 5 votes |
@Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); Drawable d = mCurrentDrawable; if (d != null) { // Translate canvas so a indeterminate circular progress bar with padding // rotates properly in its animation canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop); long time = getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time, mTransformation); float scale = mTransformation.getAlpha(); try { mInDrawing = true; d.setLevel((int) (scale * MAX_LEVEL)); } finally { mInDrawing = false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime = SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable) d).start(); mShouldStartAnimationDrawable = false; } } }
Example 15
Source File: FixedTabIndicator.java From DropDownMenu with Apache License 2.0 | 5 votes |
private void switchTab(int pos) { TextView tv = getChildAtCurPos(pos); Drawable drawable = tv.getCompoundDrawables()[2]; int level = drawable.getLevel(); if (mOnItemClickListener != null) { mOnItemClickListener.onItemClick(tv, pos, level == 1); } if (mLastIndicatorPosition == pos) { // 点击同一个条目时 tv.setTextColor(level == 0 ? mTabSelectedColor : mTabDefaultColor); drawable.setLevel(1 - level); return; } mCurrentIndicatorPosition = pos; resetPos(mLastIndicatorPosition); //highLightPos(pos); tv.setTextColor(mTabSelectedColor); tv.getCompoundDrawables()[2].setLevel(1); mLastIndicatorPosition = pos; }
Example 16
Source File: IcsProgressBar.java From zhangshangwuda with Apache License 2.0 | 5 votes |
@Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); Drawable d = mCurrentDrawable; if (d != null) { // Translate canvas so a indeterminate circular progress bar with padding // rotates properly in its animation canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop); long time = getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time, mTransformation); float scale = mTransformation.getAlpha(); try { mInDrawing = true; d.setLevel((int) (scale * MAX_LEVEL)); } finally { mInDrawing = false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime = SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable) d).start(); mShouldStartAnimationDrawable = false; } } }
Example 17
Source File: IcsProgressBar.java From android-apps with MIT License | 5 votes |
@Override protected synchronized void onDraw(Canvas canvas) { super.onDraw(canvas); Drawable d = mCurrentDrawable; if (d != null) { // Translate canvas so a indeterminate circular progress bar with padding // rotates properly in its animation canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop); long time = getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time, mTransformation); float scale = mTransformation.getAlpha(); try { mInDrawing = true; d.setLevel((int) (scale * MAX_LEVEL)); } finally { mInDrawing = false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime = SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable) d).start(); mShouldStartAnimationDrawable = false; } } }
Example 18
Source File: DrawableContainerCompat.java From MaterialProgressBar with Apache License 2.0 | 4 votes |
/** * Initializes a drawable for display in this container. * * @param d The drawable to initialize. */ private void initializeDrawableForDisplay(Drawable d) { if (mBlockInvalidateCallback == null) { mBlockInvalidateCallback = new BlockInvalidateCallback(); } // Temporary fix for suspending callbacks during initialization. We // don't want any of these setters causing an invalidate() since that // may call back into DrawableContainer. d.setCallback(mBlockInvalidateCallback.wrap(d.getCallback())); try { if (mDrawableContainerState.mEnterFadeDuration <= 0 && mHasAlpha) { d.setAlpha(mAlpha); } if (mDrawableContainerState.mHasColorFilter) { // Color filter always overrides tint. d.setColorFilter(mDrawableContainerState.mColorFilter); } else { if (mDrawableContainerState.mHasTintList) { DrawableCompat.setTintList(d, mDrawableContainerState.mTintList); } if (mDrawableContainerState.mHasTintMode) { DrawableCompat.setTintMode(d, mDrawableContainerState.mTintMode); } } d.setVisible(isVisible(), true); d.setDither(mDrawableContainerState.mDither); d.setState(getState()); d.setLevel(getLevel()); d.setBounds(getBounds()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { d.setLayoutDirection(getLayoutDirection()); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { d.setAutoMirrored(mDrawableContainerState.mAutoMirrored); } final Rect hotspotBounds = mHotspotBounds; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && hotspotBounds != null) { d.setHotspotBounds(hotspotBounds.left, hotspotBounds.top, hotspotBounds.right, hotspotBounds.bottom); } } finally { d.setCallback(mBlockInvalidateCallback.unwrap()); } }
Example 19
Source File: NotificationFixer.java From container with GNU General Public License v3.0 | 4 votes |
void fixIconImage(Resources resources, RemoteViews remoteViews, boolean hasIconBitmap, Notification notification) { if (remoteViews == null) return; if (!mNotificationCompat.isSystemLayout(remoteViews)) { VLog.w(TAG, "ignore not system contentView"); return; } // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { try { //noinspection deprecation int id = R_Hide.id.icon.get(); if (!hasIconBitmap) { Drawable drawable = resources.getDrawable(android.R.drawable.sym_def_app_icon);//notification.icon); drawable.setLevel(notification.iconLevel); Bitmap bitmap = drawableToBitMap(drawable); // Log.i(NotificationHandler.TAG, "den" + resources.getConfiguration().densityDpi); remoteViews.setImageViewBitmap(id, bitmap); } if (Build.VERSION.SDK_INT >= 21) { remoteViews.setInt(id, "setBackgroundColor", Color.TRANSPARENT); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { remoteViews.setViewPadding(id, 0, 0, 0, 0); } } catch (Exception e) { e.printStackTrace(); VLog.w(TAG, "fix icon", e); } // } else { // try { // int id = R_Hide.id.icon.get(); // Icon icon = notification.getLargeIcon(); // if (icon == null) { // icon = notification.getSmallIcon(); // } // remoteViews.setImageViewIcon(id, icon); // if (Build.VERSION.SDK_INT >= 21) { // remoteViews.setInt(id, "setBackgroundColor", Color.TRANSPARENT); // } // if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // remoteViews.setViewPadding(id, 0, 0, 0, 0); // } // } catch (Exception e) { // e.printStackTrace(); // } // } }
Example 20
Source File: DrawerView.java From material-drawer with MIT License | 4 votes |
@Override public void set(Drawable object, Integer value) { object.setLevel(value); }