本文整理匯總了Java中android.graphics.drawable.Drawable.setLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.setLevel方法的具體用法?Java Drawable.setLevel怎麽用?Java Drawable.setLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.setLevel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setProgress
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void setProgress(float progress) {
Drawable progressBarDrawable = mFadeDrawable.getDrawable(PROGRESS_BAR_IMAGE_INDEX);
if (progressBarDrawable == null) {
return;
}
// display progressbar when not fully loaded, hide otherwise
if (progress >= 0.999f) {
if (progressBarDrawable instanceof Animatable) {
((Animatable) progressBarDrawable).stop();
}
fadeOutLayer(PROGRESS_BAR_IMAGE_INDEX);
} else {
if (progressBarDrawable instanceof Animatable) {
((Animatable) progressBarDrawable).start();
}
fadeInLayer(PROGRESS_BAR_IMAGE_INDEX);
}
// set drawable level, scaled to [0, 10000] per drawable specification
progressBarDrawable.setLevel(Math.round(progress * 10000));
}
示例2: tileifyIndeterminate
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* 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;
}
示例3: fixIconImage
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void fixIconImage(Resources resources, RemoteViews remoteViews, boolean hasIconBitmap, Notification notification) {
if (remoteViews == null) return;
if (!mNotificationCompat.isSystemLayout(remoteViews)) {
return;
}
try {
//noinspection deprecation
int id = R_Hide.id.icon.get();
//only fake small icon
if (!hasIconBitmap && notification.largeIcon == null) {
Drawable drawable = resources.getDrawable(notification.icon);
drawable.setLevel(notification.iconLevel);
Bitmap bitmap = drawableToBitMap(drawable);
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();
}
}
示例4: tileifyIndeterminate
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Drawable tileifyIndeterminate(Drawable drawable) {
if (!(drawable instanceof AnimationDrawable)) {
return drawable;
}
AnimationDrawable background = (AnimationDrawable) drawable;
int N = background.getNumberOfFrames();
Drawable 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);
return newBg;
}
示例5: setWrappedDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
public final void setWrappedDrawable(Drawable dr) {
if (this.mDrawable != null) {
this.mDrawable.setCallback(null);
}
this.mDrawable = dr;
if (dr != null) {
dr.setCallback(this);
dr.setVisible(isVisible(), true);
dr.setState(getState());
dr.setLevel(getLevel());
dr.setBounds(getBounds());
if (this.mState != null) {
this.mState.mDrawableState = dr.getConstantState();
}
}
invalidateSelf();
}
示例6: fixIconImage
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
void fixIconImage(Resources resources, RemoteViews remoteViews, boolean hasIconBitmap, Notification notification) {
if (remoteViews == null || notification.icon == 0) return;
if (!mNotificationCompat.isSystemLayout(remoteViews)) {
return;
}
try {
//noinspection deprecation
int id = R_Hide.id.icon.get();
//only fake small icon
if (!hasIconBitmap && notification.largeIcon == null) {
Drawable drawable = resources.getDrawable(notification.icon);
drawable.setLevel(notification.iconLevel);
Bitmap bitmap = drawableToBitMap(drawable);
remoteViews.setImageViewBitmap(id, bitmap);
//emui
if(OSUtils.getInstance().isEmui()) {
if (notification.largeIcon == null) {
notification.largeIcon = bitmap;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: updateColor
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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);
}
}
示例8: onLevelChange
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@Override
protected boolean onLevelChange(int level) {
boolean levelChanged = false;
for (int i = 0; i < mLayers.length; i++) {
Drawable drawable = mLayers[i];
if (drawable != null && drawable.setLevel(level)) {
levelChanged = true;
}
}
return levelChanged;
}
示例9: copyProperties
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* 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());
}
示例10: onDraw
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
@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;
}
}
}
示例11: updateDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void updateDrawable(Drawable d) {
if (mDrawable != null) {
mDrawable.setCallback(null);
unscheduleDrawable(mDrawable);
if (isAttachedWindow) {
mDrawable.setVisible(false, false);
}
}
mDrawable = d;
if (d != null) {
d.setCallback(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
d.setLayoutDirection(getLayoutDirection());
}
if (d.isStateful()) {
d.setState(getDrawableState());
}
if (isAttachedWindow) {
d.setVisible(getWindowVisibility() == VISIBLE && isShown(), true);
}
d.setLevel(mLevel);
mDrawableWidth = d.getIntrinsicWidth();
mDrawableHeight = d.getIntrinsicHeight();
// applyImageTint();
// applyColorMod();
//
// configureBounds();
} else {
mDrawableWidth = mDrawableHeight = -1;
}
}
示例12: updateDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private void updateDrawable(Drawable d) {
boolean sameDrawable = false;
boolean sCompatDrawableVisibilityDispatch = false;
if (mDrawable != null) {
sameDrawable = mDrawable == d;
mDrawable.setCallback(null);
unscheduleDrawable(mDrawable);
if (!sCompatDrawableVisibilityDispatch && !sameDrawable && isAttachedWindow) {
mDrawable.setVisible(false, false);
}
}
mDrawable = d;
if (d != null) {
d.setCallback(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
d.setLayoutDirection(getLayoutDirection());
}
if (d.isStateful()) {
d.setState(getDrawableState());
}
if (!sameDrawable || sCompatDrawableVisibilityDispatch) {
final boolean visible = sCompatDrawableVisibilityDispatch
? getVisibility() == VISIBLE
: isAttachedWindow && getWindowVisibility() == VISIBLE && isShown();
d.setVisible(visible, true);
}
d.setLevel(mLevel);
mDrawableWidth = d.getIntrinsicWidth();
mDrawableHeight = d.getIntrinsicHeight();
// applyImageTint();
// applyColorMod();
//
// configureBounds();
} else {
mDrawableWidth = mDrawableHeight = -1;
}
}
示例13: fixIconImage
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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();
// }
// }
}
示例14: updateDrawableScale
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Updates a scale level of the given <var>drawable</var> according to the specified scale
* value.
*
* @param drawable The drawable of which scale level to update.
* @param scale The scale value from the range {@code [0.0, 1.0]}.
*/
private void updateDrawableScale(Drawable drawable, float scale) {
if (drawable instanceof ScaleDrawable) drawable.setLevel(Math.round(scale * MAX_LEVEL));
}
示例15: updateProgressDrawableLevel
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* If one the drawable layers of the wrapped drawable is {@link android.R.id#progress} this will
* update its current level to the specified one.
*
* @param level The level to be set to the progress layer (if presented).
* @return {@code True} if the given level has been set and it actually changed to the current
* level of the progress layer, {@code false} otherwise.
*/
private boolean updateProgressDrawableLevel(int level) {
final Drawable progressDrawable = ((LayerDrawable) mDrawable).findDrawableByLayerId(android.R.id.progress);
return progressDrawable != null && progressDrawable.setLevel(level);
}