use of android.graphics.drawable.InsetDrawable in project material-components-android by material-components.
the class FloatingActionButtonLollipop method onPaddingUpdated.
@Override
void onPaddingUpdated(Rect padding) {
if (mShadowViewDelegate.isCompatPaddingEnabled()) {
mInsetDrawable = new InsetDrawable(mRippleDrawable, padding.left, padding.top, padding.right, padding.bottom);
mShadowViewDelegate.setBackgroundDrawable(mInsetDrawable);
} else {
mShadowViewDelegate.setBackgroundDrawable(mRippleDrawable);
}
}
use of android.graphics.drawable.InsetDrawable in project Shuttle by timusus.
the class SettingsFragment method onActivityCreated.
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (mPrefResId == R.xml.settings_headers) {
if (getListView() != null && getListView().getDivider() != null) {
Drawable drawable = getListView().getDivider();
InsetDrawable divider = new InsetDrawable(drawable, ResourceUtils.toPixels(72), 0, 0, 0);
getListView().setDivider(divider);
}
}
}
use of android.graphics.drawable.InsetDrawable in project FlatUI by eluleci.
the class FlatToggleButton method init.
private void init(AttributeSet attrs) {
if (attributes == null)
attributes = new Attributes(this, getResources());
if (attrs != null) {
TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.fl_FlatToggleButton);
// getting common attributes
int customTheme = a.getResourceId(R.styleable.fl_FlatToggleButton_fl_theme, Attributes.DEFAULT_THEME);
attributes.setThemeSilent(customTheme, getResources());
attributes.setRadius(a.getDimensionPixelSize(R.styleable.fl_FlatToggleButton_fl_cornerRadius, Attributes.DEFAULT_RADIUS_PX));
space = a.getDimensionPixelSize(R.styleable.fl_FlatToggleButton_fl_space, space);
padding = space / 10;
a.recycle();
}
// creating unchecked-enabled state drawable
ShapeDrawable uncheckedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
uncheckedEnabledFrontCore.getPaint().setColor(attributes.getColor(2));
InsetDrawable uncheckedEnabledFront = new InsetDrawable(uncheckedEnabledFrontCore, padding);
ShapeDrawable uncheckedEnabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
uncheckedEnabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
uncheckedEnabledBack.setIntrinsicWidth(space / 2 * 5);
uncheckedEnabledBack.setIntrinsicHeight(space);
uncheckedEnabledBack.setPadding(0, 0, space / 2 * 5, 0);
Drawable[] d1 = { uncheckedEnabledBack, uncheckedEnabledFront };
LayerDrawable uncheckedEnabled = new LayerDrawable(d1);
// creating checked-enabled state drawable
ShapeDrawable checkedEnabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
checkedEnabledFrontCore.getPaint().setColor(attributes.getColor(2));
InsetDrawable checkedEnabledFront = new InsetDrawable(checkedEnabledFrontCore, padding);
ShapeDrawable checkedEnabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
checkedEnabledBack.getPaint().setColor(attributes.getColor(3));
checkedEnabledBack.setPadding(space / 2 * 5, 0, 0, 0);
Drawable[] d2 = { checkedEnabledBack, checkedEnabledFront };
LayerDrawable checkedEnabled = new LayerDrawable(d2);
// creating unchecked-disabled state drawable
ShapeDrawable uncheckedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
uncheckedDisabledFrontCore.getPaint().setColor(Color.parseColor("#d2d2d2"));
InsetDrawable uncheckedDisabledFront = new InsetDrawable(uncheckedDisabledFrontCore, padding);
ShapeDrawable uncheckedDisabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
uncheckedDisabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
uncheckedDisabledBack.setPadding(0, 0, space / 2 * 5, 0);
Drawable[] d3 = { uncheckedDisabledBack, uncheckedDisabledFront };
LayerDrawable uncheckedDisabled = new LayerDrawable(d3);
// creating checked-disabled state drawable
ShapeDrawable checkedDisabledFrontCore = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
checkedDisabledFrontCore.getPaint().setColor(attributes.getColor(3));
InsetDrawable checkedDisabledFront = new InsetDrawable(checkedDisabledFrontCore, padding);
ShapeDrawable checkedDisabledBack = new ShapeDrawable(new RoundRectShape(attributes.getOuterRadius(), null, null));
checkedDisabledBack.getPaint().setColor(Color.parseColor("#f2f2f2"));
checkedDisabledBack.setPadding(space / 2 * 5, 0, 0, 0);
Drawable[] d4 = { checkedDisabledBack, checkedDisabledFront };
LayerDrawable checkedDisabled = new LayerDrawable(d4);
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { -android.R.attr.state_checked, android.R.attr.state_enabled }, new InsetDrawable(uncheckedEnabled, padding * 2));
states.addState(new int[] { android.R.attr.state_checked, android.R.attr.state_enabled }, new InsetDrawable(checkedEnabled, padding * 2));
states.addState(new int[] { -android.R.attr.state_checked, -android.R.attr.state_enabled }, new InsetDrawable(uncheckedDisabled, padding * 2));
states.addState(new int[] { android.R.attr.state_checked, -android.R.attr.state_enabled }, new InsetDrawable(checkedDisabled, padding * 2));
setBackgroundDrawable(states);
setText("");
setTextOff("");
setTextOn("");
setTextSize(0);
}
use of android.graphics.drawable.InsetDrawable in project PocketHub by pockethub.
the class AvatarLoader method bind.
/**
* Sets the logo on the {@link ActionBar} to the user's avatar.
*
* @param actionBar An ActionBar object on which you're placing the user's avatar.
* @param userReference An AtomicReference that points to the desired user.
* @return this helper
*/
public void bind(final ActionBar actionBar, final AtomicReference<User> userReference) {
if (userReference == null) {
return;
}
final User user = userReference.get();
if (user == null) {
return;
}
String avatarUrl = user.avatarUrl();
if (TextUtils.isEmpty(avatarUrl)) {
return;
}
// Remove the URL params as they are not needed and break cache
if (avatarUrl.contains("?") && !avatarUrl.contains("gravatar")) {
avatarUrl = avatarUrl.substring(0, avatarUrl.indexOf("?"));
}
final String url = avatarUrl;
new FetchAvatarTask(context) {
@Override
public BitmapDrawable call() throws Exception {
Bitmap image = Bitmap.createScaledBitmap(p.load(url).get(), avatarSize, avatarSize, false);
return new BitmapDrawable(context.getResources(), ImageUtils.roundCorners(image, cornerRadius));
}
@Override
protected void onSuccess(BitmapDrawable image) throws Exception {
// compute inset in pixels
int insetPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, context.getResources().getDisplayMetrics());
actionBar.setLogo(new InsetDrawable(image, 0, 0, insetPx, 0));
}
}.execute();
}
use of android.graphics.drawable.InsetDrawable in project uitableview4android by DayS.
the class UITableCellView method setBackgroundColor.
public void setBackgroundColor(int[] colorDefault, int[] colorPressed) {
// Assign the right backgroundDrawable according to the cell's position in the group
Drawable backgroundDrawable;
if (indexPath.getRowsCount() == 1) {
backgroundDrawable = new UITableCellDrawable(10.0f, 10.0f, colorDefault, colorPressed, borderColor);
} else {
if (indexPath.isFirstCellOfGroup()) {
backgroundDrawable = new UITableCellDrawable(10.0f, 0, colorDefault, colorPressed, borderColor);
} else if (indexPath.isLastCellOfGroup()) {
backgroundDrawable = new UITableCellDrawable(0, 10.0f, colorDefault, colorPressed, borderColor);
} else {
backgroundDrawable = new UITableCellDrawable(0, 0, colorDefault, colorPressed, borderColor);
}
}
// Add extra space if this cell is the last one
int bottomInset = 0;
if (indexPath.isLastCell()) {
bottomInset = INSET;
}
setBackgroundDrawable(new InsetDrawable(backgroundDrawable, INSET, 0, INSET, bottomInset));
}
Aggregations