Search in sources :

Example 36 with LayerDrawable

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");
    }
}
Also used : StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) Resources(android.content.res.Resources) Paint(android.graphics.Paint) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 37 with LayerDrawable

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;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimationDrawable(android.graphics.drawable.AnimationDrawable) Drawable(android.graphics.drawable.Drawable) StateListDrawable(android.graphics.drawable.StateListDrawable) ClipDrawable(android.graphics.drawable.ClipDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Nullable(android.annotation.Nullable)

Example 38 with LayerDrawable

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);
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter) CMHardwareManager(cyanogenmod.hardware.CMHardwareManager)

Example 39 with LayerDrawable

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;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable)

Example 40 with 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;
}
Also used : LayerDrawable(android.graphics.drawable.LayerDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

LayerDrawable (android.graphics.drawable.LayerDrawable)133 Drawable (android.graphics.drawable.Drawable)91 BitmapDrawable (android.graphics.drawable.BitmapDrawable)61 StateListDrawable (android.graphics.drawable.StateListDrawable)45 AnimationDrawable (android.graphics.drawable.AnimationDrawable)42 ClipDrawable (android.graphics.drawable.ClipDrawable)42 ShapeDrawable (android.graphics.drawable.ShapeDrawable)39 Paint (android.graphics.Paint)25 SuppressLint (android.annotation.SuppressLint)21 GradientDrawable (android.graphics.drawable.GradientDrawable)19 Bitmap (android.graphics.Bitmap)14 ColorDrawable (android.graphics.drawable.ColorDrawable)14 BitmapShader (android.graphics.BitmapShader)13 AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)8 OvalShape (android.graphics.drawable.shapes.OvalShape)8 TypedArray (android.content.res.TypedArray)7 Nullable (android.annotation.Nullable)5 Resources (android.content.res.Resources)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 TransitionDrawable (android.graphics.drawable.TransitionDrawable)5