Search in sources :

Example 51 with Drawable

use of android.graphics.drawable.Drawable in project Shuttle by timusus.

the class DrawableUtils method getSemiTransparentBaseDrawable.

/**
     * Takes a drawable resource and colors it according to the base color of the theme
     *
     * @param baseDrawableResId the resource id of the drawable to theme
     * @return a themed {@link android.graphics.drawable.Drawable}
     */
public static Drawable getSemiTransparentBaseDrawable(Context context, int baseDrawableResId) {
    Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId).getConstantState().newDrawable();
    ColorFilter colorFilter = new LightingColorFilter(ThemeUtils.getBaseColor(context), 0);
    baseDrawable.mutate().setColorFilter(colorFilter);
    baseDrawable.setAlpha(155);
    return baseDrawable;
}
Also used : ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter)

Example 52 with Drawable

use of android.graphics.drawable.Drawable in project Shuttle by timusus.

the class DrawableUtils method getColoredStateListDrawable.

/**
     * Returns a {@link FilterableStateListDrawable}, coloring the passed in
     * drawable according to the theme and the passed in highlight color
     *
     * @param baseDrawable the drawable to use
     * @return an {@link FilterableStateListDrawable}, coloring the passed in
     * drawable according to the theme and the passed in highlight color
     */
public static Drawable getColoredStateListDrawable(Context context, Drawable baseDrawable, boolean inverted) {
    if (baseDrawable == null) {
        return null;
    }
    Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
    int baseColor;
    if (!inverted) {
        baseColor = context.getResources().getColor(R.color.drawable_base_color_dark);
    } else {
        baseColor = context.getResources().getColor(R.color.drawable_base_color_light);
    }
    ColorFilter baseColorFilter = new LightingColorFilter(baseColor, 0);
    ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getPrimaryColor(), 0);
    FilterableStateListDrawable filterableStateListDrawable = new FilterableStateListDrawable();
    filterableStateListDrawable.addState(new int[] { android.R.attr.state_pressed }, baseDrawable, highlightColorFilter);
    filterableStateListDrawable.addState(StateSet.WILD_CARD, highlightDrawable, baseColorFilter);
    return filterableStateListDrawable;
}
Also used : FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter)

Example 53 with Drawable

use of android.graphics.drawable.Drawable in project Shuttle by timusus.

the class DrawableUtils method getColoredStateListDrawableWithThemeType.

/**
     * Returns a {@link FilterableStateListDrawable}, coloring the passed in
     * drawable according to the theme and the passed in highlight color
     *
     * @param baseDrawableResId the drawable to use
     * @return an {@link FilterableStateListDrawable}, coloring the passed in
     * drawable according to the theme and the passed in highlight color
     */
public static Drawable getColoredStateListDrawableWithThemeType(Context context, int baseDrawableResId, @ThemeUtils.ThemeType int themeType) {
    Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId);
    Drawable highlightDrawable = baseDrawable.getConstantState().newDrawable();
    int baseColor;
    if ((themeType == ThemeUtils.ThemeType.TYPE_DARK) || (themeType == ThemeUtils.ThemeType.TYPE_SOLID_DARK) || (themeType == ThemeUtils.ThemeType.TYPE_SOLID_BLACK)) {
        baseColor = context.getResources().getColor(R.color.drawable_base_color_dark);
    } else {
        baseColor = context.getResources().getColor(R.color.drawable_base_color_light);
    }
    ColorFilter baseColorFilter = new LightingColorFilter(baseColor, 0);
    ColorFilter highlightColorFilter = new LightingColorFilter(ColorUtils.getPrimaryColor(), 0);
    FilterableStateListDrawable filterableStateListDrawable = new FilterableStateListDrawable();
    filterableStateListDrawable.addState(new int[] { android.R.attr.state_pressed }, baseDrawable, highlightColorFilter);
    filterableStateListDrawable.addState(StateSet.WILD_CARD, highlightDrawable, baseColorFilter);
    return filterableStateListDrawable;
}
Also used : FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable) LightingColorFilter(android.graphics.LightingColorFilter)

Example 54 with Drawable

use of android.graphics.drawable.Drawable in project Shuttle by timusus.

the class DrawableUtils method getTintedNotificationDrawable.

/**
     * Takes a drawable resource and turns it black
     *
     * @param baseDrawableResId the resource id of the drawable to theme
     * @return a themed {@link android.graphics.drawable.Drawable}
     */
public static Bitmap getTintedNotificationDrawable(Context context, int baseDrawableResId) {
    boolean inverse = SettingsManager.getInstance().invertNotificationIcons();
    int colorResId = inverse ? R.color.notification_control_tint_inverse : R.color.notification_control_tint;
    if (ShuttleUtils.hasNougat()) {
        colorResId = inverse ? R.color.notification_control_tint_v24_inverse : R.color.notification_control_tint_v24;
    }
    int tintColor = context.getResources().getColor(colorResId);
    Drawable baseDrawable = context.getResources().getDrawable(baseDrawableResId);
    baseDrawable = DrawableCompat.wrap(baseDrawable);
    DrawableCompat.setTint(baseDrawable, tintColor);
    Bitmap bitmap = Bitmap.createBitmap(baseDrawable.getIntrinsicWidth(), baseDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    baseDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    baseDrawable.draw(canvas);
    return bitmap;
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) LayerDrawable(android.graphics.drawable.LayerDrawable) FilterableStateListDrawable(com.simplecity.amp_library.ui.views.FilterableStateListDrawable) Drawable(android.graphics.drawable.Drawable)

Example 55 with Drawable

use of android.graphics.drawable.Drawable in project AndroidPdfViewer by barteksc.

the class DefaultScrollHandle method setupLayout.

@Override
public void setupLayout(PDFView pdfView) {
    int align, width, height;
    Drawable background;
    // determine handler position, default is right (when scrolling vertically) or bottom (when scrolling horizontally)
    if (pdfView.isSwipeVertical()) {
        width = HANDLE_LONG;
        height = HANDLE_SHORT;
        if (inverted) {
            // left
            align = ALIGN_PARENT_LEFT;
            background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_left);
        } else {
            // right
            align = ALIGN_PARENT_RIGHT;
            background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_right);
        }
    } else {
        width = HANDLE_SHORT;
        height = HANDLE_LONG;
        if (inverted) {
            // top
            align = ALIGN_PARENT_TOP;
            background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_top);
        } else {
            // bottom
            align = ALIGN_PARENT_BOTTOM;
            background = ContextCompat.getDrawable(context, R.drawable.default_scroll_handle_bottom);
        }
    }
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        setBackgroundDrawable(background);
    } else {
        setBackground(background);
    }
    LayoutParams lp = new LayoutParams(Util.getDP(context, width), Util.getDP(context, height));
    lp.setMargins(0, 0, 0, 0);
    LayoutParams tvlp = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    tvlp.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    addView(textView, tvlp);
    lp.addRule(align);
    pdfView.addView(this, lp);
    this.pdfView = pdfView;
}
Also used : Drawable(android.graphics.drawable.Drawable)

Aggregations

Drawable (android.graphics.drawable.Drawable)2742 BitmapDrawable (android.graphics.drawable.BitmapDrawable)527 View (android.view.View)316 ColorDrawable (android.graphics.drawable.ColorDrawable)283 Bitmap (android.graphics.Bitmap)244 ImageView (android.widget.ImageView)232 TextView (android.widget.TextView)220 Paint (android.graphics.Paint)213 LayerDrawable (android.graphics.drawable.LayerDrawable)212 Rect (android.graphics.Rect)204 StateListDrawable (android.graphics.drawable.StateListDrawable)152 Resources (android.content.res.Resources)143 AnimationDrawable (android.graphics.drawable.AnimationDrawable)137 PackageManager (android.content.pm.PackageManager)127 Context (android.content.Context)126 TypedArray (android.content.res.TypedArray)115 ClipDrawable (android.graphics.drawable.ClipDrawable)108 ViewGroup (android.view.ViewGroup)100 Test (org.junit.Test)100 ShapeDrawable (android.graphics.drawable.ShapeDrawable)94