use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by ResurrectionRemix.
the class BatteryMeterDrawable method checkBatteryMeterDrawableValid.
private void checkBatteryMeterDrawableValid(Resources res, int style) {
final int resId = getBatteryDrawableResourceForStyle(style);
final Drawable batteryDrawable;
try {
batteryDrawable = res.getDrawable(resId, null);
} catch (Resources.NotFoundException e) {
throw new BatteryMeterDrawableException(res.getResourceName(resId) + " is an " + "invalid drawable", e);
}
// Check that the drawable is a LayerDrawable
if (!(batteryDrawable instanceof LayerDrawable)) {
throw new BatteryMeterDrawableException("Expected a LayerDrawable but received a " + batteryDrawable.getClass().getSimpleName());
}
final LayerDrawable layerDrawable = (LayerDrawable) batteryDrawable;
final Drawable frame = layerDrawable.findDrawableByLayerId(R.id.battery_frame);
final Drawable level = layerDrawable.findDrawableByLayerId(R.id.battery_fill);
// Now, check that the required layers exist and are of the correct type
if (frame == null) {
throw new BatteryMeterDrawableException("Missing battery_frame drawble");
}
if (level != null) {
// Check that the level drawable is an AnimatedVectorDrawable
if (!(level instanceof AnimatedVectorDrawable)) {
throw new BatteryMeterDrawableException("Expected a AnimatedVectorDrawable " + "but received a " + level.getClass().getSimpleName());
}
// Make sure we can stop-motion animate the level drawable
try {
StopMotionVectorDrawable smvd = new StopMotionVectorDrawable(level);
smvd.setCurrentFraction(0.5f);
} catch (Exception e) {
throw new BatteryMeterDrawableException("Unable to perform stop motion on " + "battery_fill drawable", e);
}
} else {
throw new BatteryMeterDrawableException("Missing battery_fill drawable");
}
}
use of android.graphics.drawable.LayerDrawable in project android_frameworks_base by ResurrectionRemix.
the class ProgressBar method getTintTarget.
/**
* Returns the drawable to which a tint or tint mode should be applied.
*
* @param layerId id of the layer to modify
* @param shouldFallback whether the base drawable should be returned
* if the id does not exist
* @return the drawable to modify
*/
@Nullable
private Drawable getTintTarget(int layerId, boolean shouldFallback) {
Drawable layer = null;
final Drawable d = mProgressDrawable;
if (d != null) {
mProgressDrawable = d.mutate();
if (d instanceof LayerDrawable) {
layer = ((LayerDrawable) d).findDrawableByLayerId(layerId);
}
if (shouldFallback && layer == null) {
layer = d;
}
}
return layer;
}
use of android.graphics.drawable.LayerDrawable in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class VibratorIntensity method onBindDialogView.
@Override
protected void onBindDialogView(final View view) {
super.onBindDialogView(view);
mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
mValueText = (TextView) view.findViewById(R.id.value);
mWarningText = (TextView) view.findViewById(R.id.warning_text);
// Read the current value in case user wants to dismiss his changes
final CMHardwareManager hardware = CMHardwareManager.getInstance(getContext());
mOriginalValue = hardware.getVibratorIntensity();
mWarningValue = hardware.getVibratorWarningIntensity();
mMinValue = hardware.getVibratorMinIntensity();
mMaxValue = hardware.getVibratorMaxIntensity();
mDefaultValue = hardware.getVibratorDefaultIntensity();
final String message = getContext().getResources().getString(R.string.vibrator_intensity_dialog_warning, intensityToPercent(mMinValue, mMaxValue, mWarningValue));
mWarningText.setText(message);
if (mWarningValue <= 0) {
mWarningText.setVisibility(View.GONE);
}
final Drawable progressDrawable = mSeekBar.getProgressDrawable();
if (progressDrawable instanceof LayerDrawable) {
LayerDrawable ld = (LayerDrawable) progressDrawable;
mProgressDrawable = ld.findDrawableByLayerId(android.R.id.progress);
}
mProgressThumb = mSeekBar.getThumb();
mRedFilter = new LightingColorFilter(Color.BLACK, getContext().getResources().getColor(android.R.color.holo_red_light));
mSeekBar.setOnSeekBarChangeListener(this);
mSeekBar.setMax(mMaxValue - mMinValue);
mSeekBar.setProgress(mOriginalValue - mMinValue);
}
use of android.graphics.drawable.LayerDrawable in project MaterialProgressBar by DreaminginCodeZH.
the class MaterialProgressBar method getTintTargetFromProgressDrawable.
private Drawable getTintTargetFromProgressDrawable(int layerId, boolean shouldFallback) {
Drawable progressDrawable = getProgressDrawable();
if (progressDrawable == null) {
return null;
}
progressDrawable.mutate();
Drawable layerDrawable = null;
if (progressDrawable instanceof LayerDrawable) {
layerDrawable = ((LayerDrawable) progressDrawable).findDrawableByLayerId(layerId);
}
if (layerDrawable == null && shouldFallback) {
layerDrawable = progressDrawable;
}
return layerDrawable;
}
use of android.graphics.drawable.LayerDrawable in project Android-Bootstrap by Bearded-Hen.
the class BootstrapDrawableFactory method setupStateDrawable.
private static StateListDrawable setupStateDrawable(ViewGroupPosition position, int strokeWidth, GradientDrawable defaultGd, GradientDrawable activeGd, GradientDrawable disabledGd) {
StateListDrawable stateListDrawable = new StateListDrawable();
LayerDrawable defaultLayer = new LayerDrawable(new Drawable[] { defaultGd });
LayerDrawable activeLayer = new LayerDrawable(new Drawable[] { activeGd });
LayerDrawable disabledLayer = new LayerDrawable(new Drawable[] { disabledGd });
LayerDrawable[] ldAry = new LayerDrawable[] { defaultLayer, activeLayer, disabledLayer };
int n = strokeWidth * -1;
// use LayerDrawable to hide strokes on one side of the drawable (if needed), using negative insets
if (position != null) {
switch(position) {
case MIDDLE_HORI:
setInsetOnLayers(ldAry, n, 0, 0, 0);
break;
case END:
setInsetOnLayers(ldAry, n, 0, 0, 0);
break;
case MIDDLE_VERT:
setInsetOnLayers(ldAry, 0, n, 0, 0);
break;
case BOTTOM:
setInsetOnLayers(ldAry, 0, n, 0, 0);
}
}
if (Build.VERSION.SDK_INT >= 14) {
stateListDrawable.addState(new int[] { android.R.attr.state_hovered }, activeLayer);
}
stateListDrawable.addState(new int[] { android.R.attr.state_activated }, activeLayer);
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, activeLayer);
stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, activeLayer);
stateListDrawable.addState(new int[] { android.R.attr.state_selected }, activeLayer);
stateListDrawable.addState(new int[] { -android.R.attr.state_enabled }, disabledLayer);
stateListDrawable.addState(new int[] {}, defaultLayer);
return stateListDrawable;
}
Aggregations