• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DrawableWrapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.support.v4.graphics.drawable.DrawableWrapper的典型用法代码示例。如果您正苦于以下问题:Java DrawableWrapper类的具体用法?Java DrawableWrapper怎么用?Java DrawableWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DrawableWrapper类属于android.support.v4.graphics.drawable包,在下文中一共展示了DrawableWrapper类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: colorUnknownDrawable

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
/**
 * Tries to clone and just color filter the drawable. Uses mode SRC_ATOP.
 *
 * @param drawable Which drawable to color
 * @param color Which color to use
 * @return A colored drawable ready for use
 */
@SuppressWarnings("RedundantCast")
public Drawable colorUnknownDrawable(@Nullable Drawable drawable, int color) {
    if (drawable instanceof DrawableWrapper || drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, color);
        DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP);
        drawable = DrawableCompat.unwrap(drawable);
        return drawable;
    } else {
        try {
            // noinspection ConstantConditions
            Drawable copy = drawable.getConstantState().newDrawable();
            copy.mutate();
            copy.setColorFilter(color, SRC_ATOP);
            return copy;
        } catch (Exception e) {
            if (drawable != null) {
                Log.d(LOG_TAG, "Failed to color unknown drawable: " + drawable.getClass().getSimpleName());
            }
            return drawable;
        }
    }
}
 
开发者ID:milosmns,项目名称:actual-number-picker,代码行数:31,代码来源:Coloring.java


示例2: colorUnknownDrawable

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
/**
 * Tries to clone and simply color-filter the drawable. Uses {@link PorterDuff.Mode#SRC_ATOP}.
 * <b>Note</b>: Use this when you don't know which drawable you have.
 *
 * @param drawable Which drawable to color
 * @param color    Which color to use
 * @return A colored drawable ready for use
 */
@NonNull
public static Drawable colorUnknownDrawable(@NonNull final Drawable drawable, @ColorInt final int color) {
    // check if this is a drawable wrapper, then do coloring by drawable wrapping
    if (drawable instanceof DrawableWrapper || drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
        final Drawable wrapResult = colorDrawableWrapped(drawable, color);
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2) {
            // there is a bug for JellyBean MR2 when this won't work, so.. set the tint filter manually
            wrapResult.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
        }
        return wrapResult;
    }

    // wrapping failed, do a plain constant state clone
    try {
        final Drawable.ConstantState state = drawable.getConstantState();
        if (state == null) {
            // well done android.
            throw new IllegalStateException("Constant state is unavailable");
        }
        final Drawable copy = drawable.getConstantState().newDrawable().mutate();
        copy.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        return copy;
    } catch (Exception ignored) {
        return drawable;
    }
}
 
开发者ID:milosmns,项目名称:silly-android,代码行数:35,代码来源:Coloring.java


示例3: tileify

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        bitmapDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        return (clip) ? new ClipDrawable(bitmapDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : bitmapDrawable;
    }

    return drawable;
}
 
开发者ID:ukiy2010,项目名称:BetterRatingBar,代码行数:35,代码来源:BetterRatingBar.java


示例4: getDrawableWrapper

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
public static DrawableWrapper getDrawableWrapper(Drawable drawable) {
    if (drawable instanceof DrawableWrapper) {
        return (DrawableWrapper) drawable;
    } else {
        Drawable.Callback callback = drawable.getCallback();
        if (callback instanceof Drawable) {
            return getDrawableWrapper((Drawable) callback);
        }
    }

    return null;
}
 
开发者ID:Leao,项目名称:CodeColors,代码行数:13,代码来源:CcTintManager.java


示例5: tileify

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        final BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        final Bitmap tileBitmap = bitmapDrawable.getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        shapeDrawable.getPaint().setColorFilter(bitmapDrawable.getPaint().getColorFilter());
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}
 
开发者ID:wutongke,项目名称:AndroidSkinAnimator,代码行数:48,代码来源:SkinCompatProgressBarHelper.java


示例6: canSafelyMutateDrawable

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
static boolean canSafelyMutateDrawable(@NonNull Drawable drawable) {
    if (drawable instanceof LayerDrawable) {
        if (VERSION.SDK_INT >= 16) {
            return true;
        }
        return false;
    } else if (drawable instanceof InsetDrawable) {
        if (VERSION.SDK_INT < 14) {
            return false;
        }
        return true;
    } else if (drawable instanceof StateListDrawable) {
        if (VERSION.SDK_INT < 8) {
            return false;
        }
        return true;
    } else if (drawable instanceof GradientDrawable) {
        if (VERSION.SDK_INT < 14) {
            return false;
        }
        return true;
    } else if (drawable instanceof DrawableContainer) {
        ConstantState state = drawable.getConstantState();
        if (!(state instanceof DrawableContainerState)) {
            return true;
        }
        for (Drawable child : ((DrawableContainerState) state).getChildren()) {
            if (!canSafelyMutateDrawable(child)) {
                return false;
            }
        }
        return true;
    } else if (drawable instanceof DrawableWrapper) {
        return canSafelyMutateDrawable(((DrawableWrapper) drawable).getWrappedDrawable());
    } else {
        if (drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
            return canSafelyMutateDrawable(((android.support.v7.graphics.drawable.DrawableWrapper) drawable).getWrappedDrawable());
        }
        return true;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:42,代码来源:DrawableUtils.java


示例7: tileify

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
/**
 * Converts a drawable to a tiled version of itself. It will recursively
 * traverse layer and state list drawables.
 */
private Drawable tileify(Drawable drawable, boolean clip) {
    if (drawable instanceof DrawableWrapper) {
        Drawable inner = ((DrawableWrapper) drawable).getWrappedDrawable();
        if (inner != null) {
            inner = tileify(inner, clip);
            ((DrawableWrapper) drawable).setWrappedDrawable(inner);
        }
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable background = (LayerDrawable) drawable;
        final int N = background.getNumberOfLayers();
        Drawable[] outDrawables = new Drawable[N];

        for (int i = 0; i < N; i++) {
            int id = background.getId(i);
            outDrawables[i] = tileify(background.getDrawable(i),
                    (id == android.R.id.progress || id == android.R.id.secondaryProgress));
        }
        LayerDrawable newBg = new LayerDrawable(outDrawables);

        for (int i = 0; i < N; i++) {
            newBg.setId(i, background.getId(i));
        }

        return newBg;

    } else if (drawable instanceof BitmapDrawable) {
        final Bitmap tileBitmap = ((BitmapDrawable) drawable).getBitmap();
        if (mSampleTile == null) {
            mSampleTile = tileBitmap;
        }

        final ShapeDrawable shapeDrawable = new ShapeDrawable(getDrawableShape());
        final BitmapShader bitmapShader = new BitmapShader(tileBitmap,
                Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
        shapeDrawable.getPaint().setShader(bitmapShader);
        return (clip) ? new ClipDrawable(shapeDrawable, Gravity.LEFT,
                ClipDrawable.HORIZONTAL) : shapeDrawable;
    }

    return drawable;
}
 
开发者ID:StraaS,项目名称:StraaS-android-sdk-sample,代码行数:46,代码来源:SeekBar.java


示例8: tileify

import android.support.v4.graphics.drawable.DrawableWrapper; //导入依赖的package包/类
private Drawable tileify(Drawable paramDrawable, boolean paramBoolean)
{
  if ((paramDrawable instanceof DrawableWrapper))
  {
    Drawable localDrawable2 = ((DrawableWrapper)paramDrawable).getWrappedDrawable();
    if (localDrawable2 != null)
    {
      Drawable localDrawable3 = tileify(localDrawable2, paramBoolean);
      ((DrawableWrapper)paramDrawable).setWrappedDrawable(localDrawable3);
    }
  }
  do
  {
    Object localObject = paramDrawable;
    for (;;)
    {
      return localObject;
      if (!(paramDrawable instanceof LayerDrawable)) {
        break;
      }
      LayerDrawable localLayerDrawable = (LayerDrawable)paramDrawable;
      int i = localLayerDrawable.getNumberOfLayers();
      Drawable[] arrayOfDrawable = new Drawable[i];
      int j = 0;
      if (j < i)
      {
        int m = localLayerDrawable.getId(j);
        Drawable localDrawable1 = localLayerDrawable.getDrawable(j);
        if ((m == 16908301) || (m == 16908303)) {}
        for (boolean bool = true;; bool = false)
        {
          arrayOfDrawable[j] = tileify(localDrawable1, bool);
          j++;
          break;
        }
      }
      localObject = new LayerDrawable(arrayOfDrawable);
      for (int k = 0; k < i; k++) {
        ((LayerDrawable)localObject).setId(k, localLayerDrawable.getId(k));
      }
    }
  } while (!(paramDrawable instanceof BitmapDrawable));
  Bitmap localBitmap = ((BitmapDrawable)paramDrawable).getBitmap();
  if (this.mSampleTile == null) {
    this.mSampleTile = localBitmap;
  }
  ShapeDrawable localShapeDrawable = new ShapeDrawable(new RoundRectShape(new float[] { 5.0F, 5.0F, 5.0F, 5.0F, 5.0F, 5.0F, 5.0F, 5.0F }, null, null));
  BitmapShader localBitmapShader = new BitmapShader(localBitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP);
  localShapeDrawable.getPaint().setShader(localBitmapShader);
  if (paramBoolean) {
    return new ClipDrawable(localShapeDrawable, 3, 1);
  }
  return localShapeDrawable;
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:55,代码来源:AppCompatProgressBarHelper.java



注:本文中的android.support.v4.graphics.drawable.DrawableWrapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BoundedOutOfOrdernessTimestampExtractor类代码示例发布时间:2022-05-22
下一篇:
Java X509IssuerSerialResolver类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap