本文整理匯總了Java中android.graphics.drawable.LayerDrawable.getNumberOfLayers方法的典型用法代碼示例。如果您正苦於以下問題:Java LayerDrawable.getNumberOfLayers方法的具體用法?Java LayerDrawable.getNumberOfLayers怎麽用?Java LayerDrawable.getNumberOfLayers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.LayerDrawable
的用法示例。
在下文中一共展示了LayerDrawable.getNumberOfLayers方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fromDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public static Drawable fromDrawable(Drawable drawable) {
if (drawable != null) {
if (drawable instanceof RoundedDrawable) {
// just return if it's already a RoundedDrawable
return drawable;
} else if (drawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) drawable;
int num = ld.getNumberOfLayers();
// loop through layers to and change to RoundedDrawables if possible
for (int i = 0; i < num; i++) {
Drawable d = ld.getDrawable(i);
ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
}
return ld;
}
// try to get a bitmap from the drawable and
Bitmap bm = drawableToBitmap(drawable);
if (bm != null) {
return new RoundedDrawable(bm);
}
}
return drawable;
}
示例2: styleSeekBar
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private void styleSeekBar() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
final Drawable progressDrawable = mSeekBar.getProgressDrawable();
if (progressDrawable != null) {
if (progressDrawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) progressDrawable;
int layers = ld.getNumberOfLayers();
for (int i = 0; i < layers; i++) {
ld.getDrawable(i).mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
} else {
progressDrawable.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
final Drawable thumb = mSeekBar.getThumb();
if (thumb != null) {
thumb.mutate().setColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
}
}
}
}
示例3: fromDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public static Drawable fromDrawable(Drawable drawable, Resources r) {
if (drawable != null) {
if (drawable instanceof SelectableRoundedCornerDrawable) {
return drawable;
} else if (drawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) drawable;
final int num = ld.getNumberOfLayers();
for (int i = 0; i < num; i++) {
Drawable d = ld.getDrawable(i);
ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d, r));
}
return ld;
}
Bitmap bm = drawableToBitmap(drawable);
if (bm != null) {
return new SelectableRoundedCornerDrawable(bm, r);
} else {
// Log.w(TAG, "Failed to create bitmap from drawable!");
}
}
return drawable;
}
示例4: updateAttrs
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private void updateAttrs(Drawable drawable) {
if (drawable == null) {
return;
}
if (drawable instanceof RoundedDrawable) {
((RoundedDrawable) drawable).setScaleType(mScaleType).setCornerRadius(cornerRadius)
.setBorderWidth(borderWidth).setBorderColor(borderColor).setOval(isOval);
} else if (drawable instanceof LayerDrawable) {
// loop through layers to and set drawable attrs
LayerDrawable ld = ((LayerDrawable) drawable);
for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
updateAttrs(ld.getDrawable(i));
}
}
}
示例5: updateAttrs
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private void updateAttrs(Drawable drawable)
{
if (drawable == null)
{
return;
}
if (drawable instanceof RoundedDrawable)
{
((RoundedDrawable) drawable).setScaleType(mScaleType).setCornerRadius(cornerRadius)
.setBorderWidth(borderWidth).setBorderColor(borderColor).setOval(isOval);
}
else if (drawable instanceof LayerDrawable)
{
// loop through layers to and set drawable attrs
LayerDrawable ld = ((LayerDrawable) drawable);
for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++)
{
updateAttrs(ld.getDrawable(i));
}
}
}
示例6: updateAttrs
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private void updateAttrs(Drawable drawable) {
if (drawable != null) {
if (drawable instanceof RoundedPagerDrawable) {
((RoundedPagerDrawable) drawable).setScaleType(this.mScaleType).setBorderWidth(this.mBorderWidth).setBorderColor(this.mBorderColor).setOval(this.mIsOval).setTileModeX(this.mTileModeX).setTileModeY(this.mTileModeY);
if (this.mCornerRadii != null) {
((RoundedPagerDrawable) drawable).setCornerRadius(this.mCornerRadii[0], this.mCornerRadii[1], this.mCornerRadii[2], this.mCornerRadii[3]);
}
applyColorMod();
} else if (drawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) drawable;
int layers = ld.getNumberOfLayers();
for (int i = 0; i < layers; i++) {
updateAttrs(ld.getDrawable(i));
}
}
}
}
示例7: fromDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
static Drawable fromDrawable(Drawable drawable, Resources r) {
if (drawable != null) {
if (drawable instanceof RoundedCornerDrawable) {
return drawable;
} else if (drawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) drawable;
final int num = ld.getNumberOfLayers();
for (int i = 0; i < num; i++) {
Drawable d = ld.getDrawable(i);
ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d, r));
}
return ld;
}
Bitmap bm = drawableToBitmap(drawable);
if (bm != null) return new RoundedCornerDrawable(bm, r);
}
return drawable;
}
示例8: fromDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public static Drawable fromDrawable(Drawable drawable, Resources r) {
if (drawable != null) {
if (drawable instanceof SelectableRoundedCornerDrawable) {
return drawable;
} else if (drawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) drawable;
final int num = ld.getNumberOfLayers();
for (int i = 0; i < num; i++) {
Drawable d = ld.getDrawable(i);
ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d, r));
}
return ld;
}
Bitmap bm = drawableToBitmap1(drawable);
if (bm != null) {
return new SelectableRoundedCornerDrawable(bm, r);
} else {
MyLg.w(TAG, "Failed to create bitmap from drawable!");
}
}
return drawable;
}
示例9: updateAttrs
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private void updateAttrs(Drawable drawable) {
if (drawable != null) {
if (drawable instanceof RoundedDrawable) {
((RoundedDrawable) drawable).setScaleType(this.mScaleType).setBorderWidth(this
.mBorderWidth).setBorderColor(this.mBorderColor).setOval(this.mIsOval)
.setTileModeX(this.mTileModeX).setTileModeY(this.mTileModeY);
if (this.mCornerRadii != null) {
((RoundedDrawable) drawable).setCornerRadius(this.mCornerRadii[0], this
.mCornerRadii[1], this.mCornerRadii[2], this.mCornerRadii[3]);
}
applyColorMod();
} else if (drawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) drawable;
int layers = ld.getNumberOfLayers();
for (int i = 0; i < layers; i++) {
updateAttrs(ld.getDrawable(i));
}
}
}
}
示例10: notifyDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
/**
* Notifies the drawable that it's displayed state has changed.
*
* @param drawable
* @param isDisplayed
*/
private static void notifyDrawable(Drawable drawable, final boolean isDisplayed) {
if (drawable instanceof RecyclingBitmapDrawable) {
// The drawable is a CountingBitmapDrawable, so notify it
((RecyclingBitmapDrawable) drawable).setIsDisplayed(isDisplayed);
} else if (drawable instanceof LayerDrawable) {
// The drawable is a LayerDrawable, so recurse on each layer
LayerDrawable layerDrawable = (LayerDrawable) drawable;
for (int i = 0, z = layerDrawable.getNumberOfLayers(); i < z; i++) {
notifyDrawable(layerDrawable.getDrawable(i), isDisplayed);
}
}
}
示例11: fixRepeatableDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
/**
* Fix the repeatable background of a drawable.
* This support both bitmap and layer drawables
* @param d the drawable to fix.
*/
public static void fixRepeatableDrawable(Drawable d) {
if(!needRepeatableFix()) {
return;
}
if (d instanceof LayerDrawable) {
LayerDrawable layer = (LayerDrawable) d;
for (int i = 0; i < layer.getNumberOfLayers(); i++) {
fixRepeatableDrawable(layer.getDrawable(i));
}
} else if (d instanceof BitmapDrawable) {
fixRepeatableBitmapDrawable((BitmapDrawable) d);
}
}
示例12: updateAttrs
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private void updateAttrs(Drawable drawable, ScaleType scaleType) {
if (drawable == null) { return; }
if (drawable instanceof RoundedDrawable) {
((RoundedDrawable) drawable)
.setScaleType(scaleType)
.setBorderWidth(mBorderWidth)
.setBorderColor(mBorderColor)
.setOval(mIsOval)
.setTileModeX(mTileModeX)
.setTileModeY(mTileModeY);
if (mCornerRadii != null) {
((RoundedDrawable) drawable).setCornerRadius(
mCornerRadii[Corner.TOP_LEFT],
mCornerRadii[Corner.TOP_RIGHT],
mCornerRadii[Corner.BOTTOM_RIGHT],
mCornerRadii[Corner.BOTTOM_LEFT]);
}
applyColorMod();
} else if (drawable instanceof LayerDrawable) {
// loop through layers to and set drawable attrs
LayerDrawable ld = ((LayerDrawable) drawable);
for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
updateAttrs(ld.getDrawable(i), scaleType);
}
}
}
示例13: fromDrawable
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
public static Drawable fromDrawable(Drawable drawable)
{
if (drawable != null)
{
if (drawable instanceof RoundedDrawable)
{
// just return if it's already a RoundedDrawable
return drawable;
}
else if (drawable instanceof LayerDrawable)
{
LayerDrawable ld = (LayerDrawable) drawable;
int num = ld.getNumberOfLayers();
// loop through layers to and change to RoundedDrawables if possible
for (int i = 0; i < num; i++)
{
Drawable d = ld.getDrawable(i);
ld.setDrawableByLayerId(ld.getId(i), fromDrawable(d));
}
return ld;
}
// try to get a bitmap from the drawable and
Bitmap bm = drawableToBitmap(drawable);
if (bm != null)
{
return new RoundedDrawable(bm);
}
else
{
Log.w(TAG, "Failed to create bitmap from drawable!");
}
}
return drawable;
}
示例14: updateAttrs
import android.graphics.drawable.LayerDrawable; //導入方法依賴的package包/類
private void updateAttrs(Drawable drawable, ScaleType scaleType) {
if (drawable == null) {
return;
}
if (drawable instanceof RoundedDrawable) {
((RoundedDrawable) drawable)
.setScaleType(scaleType)
.setBorderWidth(mBorderWidth)
.setBorderColor(mBorderColor)
.setOval(mIsOval)
.setTileModeX(mTileModeX)
.setTileModeY(mTileModeY);
if (mCornerRadii != null) {
((RoundedDrawable) drawable).setCornerRadius(
mCornerRadii[Corner.TOP_LEFT],
mCornerRadii[Corner.TOP_RIGHT],
mCornerRadii[Corner.BOTTOM_RIGHT],
mCornerRadii[Corner.BOTTOM_LEFT]);
}
applyColorMod();
} else if (drawable instanceof LayerDrawable) {
// loop through layers to and set drawable attrs
LayerDrawable ld = ((LayerDrawable) drawable);
for (int i = 0, layers = ld.getNumberOfLayers(); i < layers; i++) {
updateAttrs(ld.getDrawable(i), scaleType);
}
}
}
示例15: tileify
import android.graphics.drawable.LayerDrawable; //導入方法依賴的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 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 StateListDrawable) {
StateListDrawable in = (StateListDrawable) drawable;
StateListDrawable out = new StateListDrawable();
int numStates = in.getStateCount();
for (int i = 0; i < numStates; i++) {
out.addState(in.getStateSet(i), tileify(in.getStateDrawable(i), clip));
}
return out;
}*/ 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;
}