android.graphics.drawable.LayerDrawable#setDrawableByLayerId()源码实例Demo

下面列出了android.graphics.drawable.LayerDrawable#setDrawableByLayerId() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Common   文件: RoundedDrawable.java
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 项目: Camera2   文件: BottomBar.java
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;
}
 
源代码3 项目: o2oa   文件: SelectableRoundedImageView.java
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 项目: Android   文件: RoundedDrawable.java
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;
}
 
源代码5 项目: DMusic   文件: RoundedDrawable.java
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;
}
 
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;
}
 
源代码7 项目: BigApp_Discuz_Android   文件: RoundedDrawable.java
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;
}
 
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;
        }
 
源代码9 项目: RetailStore   文件: BaseActivity.java
public void setBadgeCount(Context context, LayerDrawable icon, int count) {

        MenuCounterDrawable badge;

        // Reuse drawable if possible
        Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
        if (reuse != null && reuse instanceof MenuCounterDrawable) {
            badge = (MenuCounterDrawable) reuse;
        } else {
            badge = new MenuCounterDrawable(context);
        }

        badge.setCount(count);
        icon.mutate();
        icon.setDrawableByLayerId(R.id.ic_badge, badge);
    }
 
源代码10 项目: ClipCircleHeadLikeQQ   文件: RoundedDrawable.java
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;
}
 
源代码11 项目: Loop   文件: RoundedDrawable.java
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;
}
 
源代码12 项目: android-common-utils   文件: RoundedDrawable.java
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;
}
 
源代码13 项目: RackMonthPicker   文件: MonthAdapter.java
private void setMonthBackgroundSelected(int color) {
    LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.month_selected);
    GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(1);
    gradientDrawable.setColor(color);
    layerDrawable.setDrawableByLayerId(1, gradientDrawable);

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[]{android.R.attr.state_selected}, gradientDrawable);
    states.addState(new int[]{android.R.attr.state_pressed}, gradientDrawable);
    states.addState(new int[]{}, ContextCompat.getDrawable(context, R.drawable.month_default));
    layoutMain.setBackground(states);
}
 
源代码14 项目: q-municate-android   文件: RoundedDrawable.java
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;
}
 
源代码15 项目: RackMonthPicker   文件: MonthAdapter.java
private void setMonthBackgroundSelected(int color) {
    LayerDrawable layerDrawable = (LayerDrawable) ContextCompat.getDrawable(context, R.drawable.month_selected);
    GradientDrawable gradientDrawable = (GradientDrawable) layerDrawable.getDrawable(1);
    gradientDrawable.setColor(color);
    layerDrawable.setDrawableByLayerId(1, gradientDrawable);

    StateListDrawable states = new StateListDrawable();
    states.addState(new int[]{android.R.attr.state_selected}, gradientDrawable);
    states.addState(new int[]{android.R.attr.state_pressed}, gradientDrawable);
    states.addState(new int[]{}, ContextCompat.getDrawable(context, R.drawable.month_default));
    layoutMain.setBackground(states);
}
 
源代码16 项目: zhizhihu   文件: MaterialProgressBar.java
private void createIndeterminateProgressDrawable(@ColorInt int backgroundColour, @ColorInt int progressColour) {
    LayerDrawable layerDrawable = (LayerDrawable) getProgressDrawable();
    if (layerDrawable != null) {
        layerDrawable.mutate();
        layerDrawable.setDrawableByLayerId(android.R.id.background, createShapeDrawable(backgroundColour));
        layerDrawable.setDrawableByLayerId(android.R.id.progress, createClipDrawable(backgroundColour));
        layerDrawable.setDrawableByLayerId(android.R.id.secondaryProgress, createClipDrawable(progressColour));
    }
}
 
源代码17 项目: UltimateAndroid   文件: RoundedDrawable.java
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;
}
 
源代码18 项目: MyBlogDemo   文件: RoundedDrawable.java
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;
}
 
源代码19 项目: GreenDamFileExploere   文件: FlatSeekBar.java
private void init(AttributeSet attrs) {

		if (attributes == null)
			attributes = new Attributes(this, getResources());

		if (attrs != null) {
			TypedArray a = getContext().obtainStyledAttributes(attrs,
					R.styleable.fl_FlatSeekBar);

			// getting common attributes
			int customTheme = a.getResourceId(
					R.styleable.fl_FlatSeekBar_fl_theme,
					Attributes.DEFAULT_THEME);
			attributes.setThemeSilent(customTheme, getResources());

			attributes.setSize(a.getDimensionPixelSize(
					R.styleable.fl_FlatSeekBar_fl_size,
					Attributes.DEFAULT_SIZE_PX));

			a.recycle();
		}

		// setting thumb
		PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
		thumb.setCornerRadius(attributes.getSize() * 9 / 8);
		thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
		thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
		setThumb(thumb);

		// progress
		PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
		progress.setCornerRadius(attributes.getSize());
		progress.setIntrinsicHeight(attributes.getSize());
		progress.setIntrinsicWidth(attributes.getSize());
		progress.setDither(true);
		ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT,
				ClipDrawable.HORIZONTAL);

		// secondary progress
		PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
		secondary.setCornerRadius(attributes.getSize());
		secondary.setIntrinsicHeight(attributes.getSize());
		ClipDrawable secondaryProgressClip = new ClipDrawable(secondary,
				Gravity.LEFT, ClipDrawable.HORIZONTAL);

		// background
		PaintDrawable background = new PaintDrawable(attributes.getColor(3));
		background.setCornerRadius(attributes.getSize());
		background.setIntrinsicHeight(attributes.getSize());

		// applying drawable
		LayerDrawable ld = (LayerDrawable) getProgressDrawable();
		ld.setDrawableByLayerId(android.R.id.background, background);
		ld.setDrawableByLayerId(android.R.id.progress, progressClip);
		ld.setDrawableByLayerId(android.R.id.secondaryProgress,
				secondaryProgressClip);
	}
 
源代码20 项目: FamilyChat   文件: FlatSeekBar.java
private void init(AttributeSet attrs) {

        if (attributes == null)
            attributes = new Attributes(this, getResources());

        if (attrs != null) {
            TypedArray a = getContext().obtainStyledAttributes(attrs, com.cengalabs.flatui.R.styleable.fl_FlatSeekBar);

            // getting common attributes
            int customTheme = a.getResourceId(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_theme, Attributes.DEFAULT_THEME);
            attributes.setThemeSilent(customTheme, getResources());

            attributes.setSize(a.getDimensionPixelSize(com.cengalabs.flatui.R.styleable.fl_FlatSeekBar_fl_size, Attributes.DEFAULT_SIZE_PX));

            a.recycle();
        }

        // setting thumb
        PaintDrawable thumb = new PaintDrawable(attributes.getColor(0));
        thumb.setCornerRadius(attributes.getSize() * 9 / 8);
        thumb.setIntrinsicWidth(attributes.getSize() * 9 / 4);
        thumb.setIntrinsicHeight(attributes.getSize() * 9 / 4);
        setThumb(thumb);

        // progress
        PaintDrawable progress = new PaintDrawable(attributes.getColor(1));
        progress.setCornerRadius(attributes.getSize());
        progress.setIntrinsicHeight(attributes.getSize());
        progress.setIntrinsicWidth(attributes.getSize());
        progress.setDither(true);
        ClipDrawable progressClip = new ClipDrawable(progress, Gravity.LEFT, ClipDrawable.HORIZONTAL);

        // secondary progress
        PaintDrawable secondary = new PaintDrawable(attributes.getColor(2));
        secondary.setCornerRadius(attributes.getSize());
        secondary.setIntrinsicHeight(attributes.getSize());
        ClipDrawable secondaryProgressClip = new ClipDrawable(secondary, Gravity.LEFT, ClipDrawable.HORIZONTAL);

        // background
        PaintDrawable background = new PaintDrawable(attributes.getColor(3));
        background.setCornerRadius(attributes.getSize());
        background.setIntrinsicHeight(attributes.getSize());

        // applying drawable
        LayerDrawable ld = (LayerDrawable) getProgressDrawable();
        ld.setDrawableByLayerId(R.id.background, background);
        ld.setDrawableByLayerId(R.id.progress, progressClip);
        ld.setDrawableByLayerId(R.id.secondaryProgress, secondaryProgressClip);
    }