use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by crdroidandroid.
the class RenderDrawable method render.
public Result render() {
checkLock();
// get the drawable resource value
DrawableParams params = getParams();
HardwareConfig hardwareConfig = params.getHardwareConfig();
ResourceValue drawableResource = params.getDrawable();
// resolve it
BridgeContext context = getContext();
drawableResource = context.getRenderResources().resolveResValue(drawableResource);
if (drawableResource == null) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
ResourceType resourceType = drawableResource.getResourceType();
if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
Drawable d = ResourceHelper.getDrawable(drawableResource, context);
final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
if (allStates == Boolean.TRUE) {
final List<BufferedImage> result;
if (d instanceof StateListDrawable) {
result = new ArrayList<BufferedImage>();
final StateListDrawable stateList = (StateListDrawable) d;
for (int i = 0; i < stateList.getStateCount(); i++) {
final Drawable stateDrawable = stateList.getStateDrawable(i);
result.add(renderImage(hardwareConfig, stateDrawable, context));
}
} else {
result = Collections.singletonList(renderImage(hardwareConfig, d, context));
}
return Status.SUCCESS.createResult(result);
} else {
BufferedImage image = renderImage(hardwareConfig, d, context);
return Status.SUCCESS.createResult(image);
}
}
use of android.graphics.drawable.StateListDrawable in project android_frameworks_base by AOSPA.
the class RenderDrawable method render.
public Result render() {
checkLock();
// get the drawable resource value
DrawableParams params = getParams();
HardwareConfig hardwareConfig = params.getHardwareConfig();
ResourceValue drawableResource = params.getDrawable();
// resolve it
BridgeContext context = getContext();
drawableResource = context.getRenderResources().resolveResValue(drawableResource);
if (drawableResource == null) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
ResourceType resourceType = drawableResource.getResourceType();
if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
Drawable d = ResourceHelper.getDrawable(drawableResource, context);
final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
if (allStates == Boolean.TRUE) {
final List<BufferedImage> result;
if (d instanceof StateListDrawable) {
result = new ArrayList<BufferedImage>();
final StateListDrawable stateList = (StateListDrawable) d;
for (int i = 0; i < stateList.getStateCount(); i++) {
final Drawable stateDrawable = stateList.getStateDrawable(i);
result.add(renderImage(hardwareConfig, stateDrawable, context));
}
} else {
result = Collections.singletonList(renderImage(hardwareConfig, d, context));
}
return Status.SUCCESS.createResult(result);
} else {
BufferedImage image = renderImage(hardwareConfig, d, context);
return Status.SUCCESS.createResult(image);
}
}
use of android.graphics.drawable.StateListDrawable in project Shuttle by timusus.
the class AestheticNavigationView method invalidateColors.
private void invalidateColors(ColorIsDarkState state) {
int selectedColor = state.color();
boolean isDark = state.isDark();
int baseColor = isDark ? Color.WHITE : Color.BLACK;
int unselectedIconColor = Util.adjustAlpha(baseColor, .54f);
int unselectedTextColor = Util.adjustAlpha(baseColor, .87f);
int selectedItemBgColor = ContextCompat.getColor(getContext(), isDark ? R.color.ate_navigation_drawer_selected_dark : R.color.ate_navigation_drawer_selected_light);
final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { unselectedIconColor, selectedColor });
final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { unselectedTextColor, selectedColor });
setItemTextColor(textSl);
setItemIconTintList(iconSl);
StateListDrawable bgDrawable = new StateListDrawable();
bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedItemBgColor));
setItemBackground(bgDrawable);
}
use of android.graphics.drawable.StateListDrawable in project BottomNavigation by Ashok-Varma.
the class BottomNavigationTab method initialise.
@CallSuper
public void initialise(boolean setActiveColor) {
iconView.setSelected(false);
if (isInActiveIconSet) {
StateListDrawable states = new StateListDrawable();
states.addState(new int[] { android.R.attr.state_selected }, mCompactIcon);
states.addState(new int[] { -android.R.attr.state_selected }, mCompactInActiveIcon);
states.addState(new int[] {}, mCompactInActiveIcon);
iconView.setImageDrawable(states);
} else {
if (setActiveColor) {
DrawableCompat.setTintList(mCompactIcon, new ColorStateList(new int[][] { // 1
new int[] { android.R.attr.state_selected }, // 2
new int[] { -android.R.attr.state_selected }, new int[] {} }, new int[] { // 1
mActiveColor, // 2
mInActiveColor, // 3
mInActiveColor }));
} else {
DrawableCompat.setTintList(mCompactIcon, new ColorStateList(new int[][] { // 1
new int[] { android.R.attr.state_selected }, // 2
new int[] { -android.R.attr.state_selected }, new int[] {} }, new int[] { // 1
mBackgroundColor, // 2
mInActiveColor, // 3
mInActiveColor }));
}
iconView.setImageDrawable(mCompactIcon);
}
if (isNoTitleMode) {
labelView.setVisibility(GONE);
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) iconContainerView.getLayoutParams();
layoutParams.gravity = Gravity.CENTER;
setNoTitleIconContainerParams(layoutParams);
iconContainerView.setLayoutParams(layoutParams);
FrameLayout.LayoutParams iconLayoutParams = (FrameLayout.LayoutParams) iconView.getLayoutParams();
setNoTitleIconParams(iconLayoutParams);
iconView.setLayoutParams(iconLayoutParams);
}
}
use of android.graphics.drawable.StateListDrawable in project android_packages_apps_crDroidSettings by crdroidandroid.
the class FloatingActionButton method createFillDrawable.
private StateListDrawable createFillDrawable(float strokeWidth) {
StateListDrawable drawable = new StateListDrawable();
drawable.addState(new int[] { -android.R.attr.state_enabled }, createCircleDrawable(mColorDisabled, strokeWidth));
drawable.addState(new int[] { android.R.attr.state_pressed }, createCircleDrawable(mColorPressed, strokeWidth));
drawable.addState(new int[] {}, createCircleDrawable(mColorNormal, strokeWidth));
return drawable;
}
Aggregations