本文整理汇总了Java中android.graphics.drawable.InsetDrawable类的典型用法代码示例。如果您正苦于以下问题:Java InsetDrawable类的具体用法?Java InsetDrawable怎么用?Java InsetDrawable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InsetDrawable类属于android.graphics.drawable包,在下文中一共展示了InsetDrawable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: containsNinePatch
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
public static boolean containsNinePatch(Drawable drawable) {
drawable = getWrapperDrawable(drawable);
if (drawable instanceof NinePatchDrawable
|| drawable instanceof InsetDrawable
|| drawable instanceof LayerDrawable) {
return true;
} else if (drawable instanceof StateListDrawable) {
final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
//can't getBaseApplication containState from drawable which is containing DrawableWrapperDonut
//https://code.google.com/p/android/issues/detail?id=169920
if (containerState == null) {
return true;
}
for (Drawable dr : containerState.getChildren()) {
dr = getWrapperDrawable(dr);
if (dr instanceof NinePatchDrawable
|| dr instanceof InsetDrawable
|| dr instanceof LayerDrawable) {
return true;
}
}
}
return false;
}
示例2: onCreateView
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final Context context = inflater.getContext();
final Resources res = context.getResources();
final View view = inflater.inflate(R.layout.fragment_directory, container, false);
mProgressBar = (MaterialProgressBar) view.findViewById(R.id.progressBar);
mEmptyView = (CompatTextView)view.findViewById(android.R.id.empty);
mListView = (ListView) view.findViewById(R.id.list);
mListView.setOnItemClickListener(mItemListener);
mListView.setMultiChoiceModeListener(mMultiListener);
mListView.setRecyclerListener(mRecycleListener);
// Indent our list divider to align with text
final Drawable divider = mListView.getDivider();
final boolean insetLeft = res.getBoolean(R.bool.list_divider_inset_left);
final int insetSize = res.getDimensionPixelSize(R.dimen.list_divider_inset);
if (insetLeft) {
mListView.setDivider(new InsetDrawable(divider, insetSize, 0, 0, 0));
} else {
mListView.setDivider(new InsetDrawable(divider, 0, 0, insetSize, 0));
}
mGridView = (GridView) view.findViewById(R.id.grid);
mGridView.setOnItemClickListener(mItemListener);
mGridView.setMultiChoiceModeListener(mMultiListener);
mGridView.setRecyclerListener(mRecycleListener);
return view;
}
示例3: containsNinePatch
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
public static boolean containsNinePatch(Drawable drawable) {
drawable = getWrapperDrawable(drawable);
if (drawable instanceof NinePatchDrawable
|| drawable instanceof InsetDrawable
|| drawable instanceof LayerDrawable) {
return true;
} else if (drawable instanceof StateListDrawable) {
final DrawableContainer.DrawableContainerState containerState = ((DrawableContainer.DrawableContainerState) drawable.getConstantState());
//can't get containState from drawable which is containing DrawableWrapperDonut
//https://code.google.com/p/android/issues/detail?id=169920
if (containerState == null) {
return true;
}
for (Drawable dr : containerState.getChildren()) {
dr = getWrapperDrawable(dr);
if (dr instanceof NinePatchDrawable
|| dr instanceof InsetDrawable
|| dr instanceof LayerDrawable) {
return true;
}
}
}
return false;
}
示例4: onUpdateBackgroundAndPaddings
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
@Override
protected void onUpdateBackgroundAndPaddings(Rect searchBarBounds, Rect padding) {
// Apply the top-bottom padding to the content itself so that the launcher transition is
// clipped correctly
mContent.setPadding(0, padding.top, 0, padding.bottom);
// TODO: Use quantum_panel_dark instead of quantum_panel_shape_dark.
InsetDrawable background = new InsetDrawable(
getResources().getDrawable(R.drawable.quantum_panel_shape_dark), padding.left, 0,
padding.right, 0);
Rect bgPadding = new Rect();
background.getPadding(bgPadding);
mView.setBackground(background);
getRevealView().setBackground(background.getConstantState().newDrawable());
mView.updateBackgroundPadding(bgPadding);
}
示例5: createButtonShape
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
private static Drawable createButtonShape(Context context, int color) {
// Translation of Lollipop's xml button-bg definition to Java
int paddingH = DensityUtil.dip2px(context, 8);
int paddingV = DensityUtil.dip2px(context, 4);
int insetH = DensityUtil.dip2px(context, 4);
int insetV = DensityUtil.dip2px(context, 6);
int corner_radius = DensityUtil.dip2px(context, 2);
float[] outerRadii = new float[8];
Arrays.fill(outerRadii, corner_radius);
RoundRectShape r = new RoundRectShape(outerRadii, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(r);
shapeDrawable.getPaint().setColor(color);
shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);
return new InsetDrawable(shapeDrawable,
insetH, insetV, insetH, insetV);
}
示例6: shouldMutateBackground
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
private static boolean shouldMutateBackground(Drawable drawable) {
if (Build.VERSION.SDK_INT >= 16) {
// For SDK 16+, we should be fine mutating the drawable
return true;
}
if (drawable instanceof LayerDrawable) {
return Build.VERSION.SDK_INT >= 16;
} else if (drawable instanceof InsetDrawable) {
return Build.VERSION.SDK_INT >= 14;
} else if (drawable instanceof DrawableContainer) {
// If we have a DrawableContainer, let's traverse it's child array
final Drawable.ConstantState state = drawable.getConstantState();
if (state instanceof DrawableContainer.DrawableContainerState) {
final DrawableContainer.DrawableContainerState containerState =
(DrawableContainer.DrawableContainerState) state;
for (Drawable child : containerState.getChildren()) {
if (!shouldMutateBackground(child)) {
return false;
}
}
}
}
return true;
}
示例7: createButtonShape
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
private static Drawable createButtonShape(Context context, int color) {
// Translation of Lollipop's xml button-bg definition to Java
int paddingH = context.getResources()
.getDimensionPixelSize(R.dimen.button_padding_horizontal_material);
int paddingV = context.getResources()
.getDimensionPixelSize(R.dimen.button_padding_vertical_material);
int insetH = context.getResources()
.getDimensionPixelSize(R.dimen.button_inset_horizontal_material);
int insetV = context.getResources()
.getDimensionPixelSize(R.dimen.button_inset_vertical_material);
float[] outerRadii = new float[8];
Arrays.fill(outerRadii, CORNER_RADIUS);
RoundRectShape r = new RoundRectShape(outerRadii, null, null);
ShapeDrawable shapeDrawable = new ShapeDrawable(r);
shapeDrawable.getPaint().setColor(color);
shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV);
return new InsetDrawable(shapeDrawable,
insetH, insetV, insetH, insetV);
}
示例8: onCreate
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_d__inset_drawable);
InsetDrawable insetDrawable=new InsetDrawable(getResources().getDrawable(R.drawable.animate_shower), 20, 30, 30, 20);
/*
* xml:
*
* <inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/image4"
android:insetLeft="50dp"
android:insetRight="50dp"
android:insetTop="20dp"
android:insetBottom="20dp">
</inset>
*/
findViewById(R.id.tv).setBackground(insetDrawable);
}
示例9: setSettingBackground
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private void setSettingBackground(int resid) {
int[] rect = new int[4];
rect[0] = getPaddingLeft();
rect[1] = getPaddingTop();
rect[2] = getPaddingRight();
rect[3] = getPaddingBottom();
if (isInsetDrawable()) {
setBackgroundDrawable(new InsetDrawable(getContext().getResources()
.getDrawable(resid), mInsetDrawableRect[0],
mInsetDrawableRect[1], mInsetDrawableRect[2],
mInsetDrawableRect[3]));
} else {
setBackgroundResource(resid);
}
setPadding(rect[0], rect[1], rect[2], rect[3]);
}
示例10: getRectWithCustomSize
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
public Drawable getRectWithCustomSize() {
String leftText = "I";
String rightText = "J";
TextDrawable.IBuilder builder = TextDrawable.builder().beginConfig()
.width(toPx(29)).withBorder(toPx(2)).endConfig().rect();
TextDrawable left = builder.build(leftText,
mGenerator.getColor(leftText));
TextDrawable right = builder.build(rightText,
mGenerator.getColor(rightText));
Drawable[] layerList = { new InsetDrawable(left, 0, 0, toPx(31), 0),
new InsetDrawable(right, toPx(31), 0, 0, 0) };
return new LayerDrawable(layerList);
}
示例11: getRectWithCustomSize
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
public Drawable getRectWithCustomSize() {
String leftText = "I";
String rightText = "J";
TextDrawable.IBuilder builder = TextDrawable.builder()
.beginConfig()
.width(toPx(29))
.withBorder(toPx(2))
.endConfig()
.rect();
TextDrawable left = builder
.build(leftText, mGenerator.getColor(leftText));
TextDrawable right = builder
.build(rightText, mGenerator.getColor(rightText));
Drawable[] layerList = {
new InsetDrawable(left, 0, 0, toPx(31), 0),
new InsetDrawable(right, toPx(31), 0, 0, 0)
};
return new LayerDrawable(layerList);
}
示例12: onUpdateBackgroundAndPaddings
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
private void onUpdateBackgroundAndPaddings(Rect padding) {
// Apply the top-bottom padding to itself so that the launcher transition is
// clipped correctly
setPadding(0, padding.top, 0, padding.bottom);
InsetDrawable background = new InsetDrawable(mRevealDrawable,
padding.left, 0, padding.right, 0);
mRevealView.setBackground(background.getConstantState().newDrawable());
mContent.setBackground(background);
// We let the content have a intent background, but still have full width.
// This allows the scroll bar to be used responsive outside the background bounds as well.
mContent.setPadding(0, 0, 0, 0);
Rect bgPadding = new Rect();
background.getPadding(bgPadding);
onUpdateBgPadding(padding, bgPadding);
}
示例13: init
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
private void init(Context context) {
setBackground(new InsetDrawable(new Triangle(context.getResources()
.getColor(R.color.vote_state_empty)),
(int) Views.convertDpToPixel(12, context),
(int) Views.convertDpToPixel(4, context),
(int) Views.convertDpToPixel(12, context),
(int) Views.convertDpToPixel(4, context)));
voteState = Vote.VoteState.EMPTY;
setOnClickListener(v -> {
if (onVoteClickListener != null) {
Vote.VoteState from = this.voteState;
Vote.VoteState to = (this.voteState == Vote.VoteState.EMPTY
? Vote.VoteState.UP
: Vote.VoteState.EMPTY);
onVoteClickListener.onVoteClicked(from, to);
}
});
}
示例14: assertEquals
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
public static void assertEquals(InsetDrawable a,InsetDrawable b)
{
assertEqualsDrawableWrapper(a, b);
assertEquals(a.isStateful(), b.isStateful());
// android:visible
assertEquals(a.isVisible(), b.isVisible());
Drawable.ConstantState a_state = a.getConstantState();
Drawable.ConstantState b_state = b.getConstantState();
Class classInsetState = TestUtil.resolveClass(InsetDrawable.class.getName() + "$InsetState");
assertEquals((Integer) TestUtil.getField(a_state, classInsetState, "mInsetLeft"), (Integer) TestUtil.getField(b_state, classInsetState, "mInsetLeft"));
assertEquals((Integer) TestUtil.getField(a_state, classInsetState, "mInsetTop"), (Integer) TestUtil.getField(b_state, classInsetState, "mInsetTop"));
assertEquals((Integer) TestUtil.getField(a_state, classInsetState, "mInsetRight"), (Integer) TestUtil.getField(b_state, classInsetState, "mInsetRight"));
assertEquals((Integer) TestUtil.getField(a_state, classInsetState, "mInsetBottom"), (Integer) TestUtil.getField(b_state, classInsetState, "mInsetBottom"));
// android:drawable
if (Build.VERSION.SDK_INT < TestUtil.MARSHMALLOW) // < 23 (en level 23 mDrawable está en la clase base)
{
assertEquals((Drawable) TestUtil.getField(a_state, classInsetState, "mDrawable"), (Drawable) TestUtil.getField(b_state, classInsetState, "mDrawable"));
}
}
示例15: getRectWithCustomSize
import android.graphics.drawable.InsetDrawable; //导入依赖的package包/类
public Drawable getRectWithCustomSize(Context context, String leftText, String rightText, boolean selected) {
TextDrawable.IBuilder builder = TextDrawable.builder()
.beginConfig()
.width(toPx(context, 29))
.withBorder(toPx(context, 2))
.textColor(selected ? getTextColorSelected() : getTextColorUnselected())
.endConfig()
.rect();
TextDrawable left = builder
.build(leftText, mGenerator.getColor(leftText));
TextDrawable right = builder
.build(rightText, mGenerator.getColor(rightText));
Drawable[] layerList = {
new InsetDrawable(left, 0, 0, toPx(context, 31), 0),
new InsetDrawable(right, toPx(context, 31), 0, 0, 0)
};
return new LayerDrawable(layerList);
}