Example usage for android.graphics.drawable Drawable Drawable

List of usage examples for android.graphics.drawable Drawable Drawable

Introduction

In this page you can find the example usage for android.graphics.drawable Drawable Drawable.

Prototype

Drawable

Source Link

Usage

From source file:Main.java

public static Drawable solidColorDrawable(int color) {
    return new Drawable() {
        @Override/*w  ww.  j a  v a 2  s. c  o  m*/
        public void setColorFilter(ColorFilter cf) {
        }

        @Override
        public void setAlpha(int alpha) {
        }

        @Override
        public int getOpacity() {
            return 0;
        }

        @Override
        public void draw(Canvas canvas) {
            canvas.drawColor(0xFF000000);
        }
    };
}

From source file:Main.java

public static void setSpanBetweenTokens(SpannableString ss, String text, String token, CharacterStyle... cs) {
    // Start and end refer to the points where the span will apply
    int tokenLen = token.length();
    int base = 0;

    while (true) {
        int start = text.indexOf(token, base);
        int end = text.indexOf(token, start + tokenLen);

        if (start < 0 || end < 0) {
            break;
        }//from ww w . j  ava2s .c  o m

        base = end + tokenLen;

        for (CharacterStyle c : cs) {
            ss.setSpan(CharacterStyle.wrap(c), start + tokenLen, end, 0);
        }

        Drawable blankDrawable = new Drawable() {

            @Override
            public void setColorFilter(ColorFilter cf) {
            }

            @Override
            public void setAlpha(int alpha) {
            }

            @Override
            public int getOpacity() {
                return 0;
            }

            @Override
            public void draw(Canvas canvas) {
            }
        };

        // because AbsoluteSizeSpan(0) doesn't work on older versions
        ss.setSpan(new ImageSpan(blankDrawable), start, start + tokenLen, 0);
        ss.setSpan(new ImageSpan(blankDrawable), end, end + tokenLen, 0);
    }
}

From source file:org.telegram.ui.Cells.ArchivedStickerSetCell.java

public void setStickersSet(TLRPC.StickerSetCovered set, boolean divider, boolean unread) {
    needDivider = divider;/*w  w w  .jav a 2  s. com*/
    stickersSet = set;
    setWillNotDraw(!needDivider);

    textView.setText(stickersSet.set.title);
    if (unread) {
        Drawable drawable = new Drawable() {

            Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

            @Override
            public void draw(Canvas canvas) {
                paint.setColor(0xff44a8ea);
                canvas.drawCircle(AndroidUtilities.dp(4), AndroidUtilities.dp(5), AndroidUtilities.dp(3),
                        paint);
            }

            @Override
            public void setAlpha(int alpha) {

            }

            @Override
            public void setColorFilter(ColorFilter colorFilter) {

            }

            @Override
            public int getOpacity() {
                return 0;
            }

            @Override
            public int getIntrinsicWidth() {
                return AndroidUtilities.dp(12);
            }

            @Override
            public int getIntrinsicHeight() {
                return AndroidUtilities.dp(8);
            }
        };
        textView.setCompoundDrawablesWithIntrinsicBounds(LocaleController.isRTL ? null : drawable, null,
                LocaleController.isRTL ? drawable : null, null);
    } else {
        textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    }

    valueTextView.setText(LocaleController.formatPluralString("Stickers", set.set.count));
    if (set.cover != null && set.cover.thumb != null && set.cover.thumb.location != null) {
        imageView.setImage(set.cover.thumb.location, null, "webp", null);
    } else if (!set.covers.isEmpty()) {
        imageView.setImage(set.covers.get(0).thumb.location, null, "webp", null);
    }
}

From source file:org.telegram.ui.Cells.FeaturedStickerSetCell.java

public void setStickersSet(TLRPC.StickerSetCovered set, boolean divider, boolean unread) {
    boolean sameSet = set == stickersSet && wasLayout;
    needDivider = divider;// w  ww .  jav  a  2 s .c  om
    stickersSet = set;
    lastUpdateTime = System.currentTimeMillis();
    setWillNotDraw(!needDivider);
    if (currentAnimation != null) {
        currentAnimation.cancel();
        currentAnimation = null;
    }

    textView.setText(stickersSet.set.title);
    if (unread) {
        Drawable drawable = new Drawable() {

            Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

            @Override
            public void draw(Canvas canvas) {
                paint.setColor(0xff44a8ea);
                canvas.drawCircle(AndroidUtilities.dp(4), AndroidUtilities.dp(5), AndroidUtilities.dp(3),
                        paint);
            }

            @Override
            public void setAlpha(int alpha) {

            }

            @Override
            public void setColorFilter(ColorFilter colorFilter) {

            }

            @Override
            public int getOpacity() {
                return 0;
            }

            @Override
            public int getIntrinsicWidth() {
                return AndroidUtilities.dp(12);
            }

            @Override
            public int getIntrinsicHeight() {
                return AndroidUtilities.dp(8);
            }
        };
        textView.setCompoundDrawablesWithIntrinsicBounds(LocaleController.isRTL ? null : drawable, null,
                LocaleController.isRTL ? drawable : null, null);
    } else {
        textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    }

    valueTextView.setText(LocaleController.formatPluralString("Stickers", set.set.count));
    if (set.cover != null && set.cover.thumb != null && set.cover.thumb.location != null) {
        imageView.setImage(set.cover.thumb.location, null, "webp", null);
    } else if (!set.covers.isEmpty()) {
        imageView.setImage(set.covers.get(0).thumb.location, null, "webp", null);
    }

    if (sameSet) {
        boolean wasInstalled = isInstalled;
        if (isInstalled = StickersQuery.isStickerPackInstalled(set.set.id)) {
            if (!wasInstalled) {
                checkImage.setVisibility(VISIBLE);
                addButton.setClickable(false);
                currentAnimation = new AnimatorSet();
                currentAnimation.setDuration(200);
                currentAnimation.playTogether(ObjectAnimator.ofFloat(addButton, "alpha", 1.0f, 0.0f),
                        ObjectAnimator.ofFloat(addButton, "scaleX", 1.0f, 0.01f),
                        ObjectAnimator.ofFloat(addButton, "scaleY", 1.0f, 0.01f),
                        ObjectAnimator.ofFloat(checkImage, "alpha", 0.0f, 1.0f),
                        ObjectAnimator.ofFloat(checkImage, "scaleX", 0.01f, 1.0f),
                        ObjectAnimator.ofFloat(checkImage, "scaleY", 0.01f, 1.0f));
                currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationEnd(Animator animator) {
                        if (currentAnimation != null && currentAnimation.equals(animator)) {
                            addButton.setVisibility(INVISIBLE);
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animator) {
                        if (currentAnimation != null && currentAnimation.equals(animator)) {
                            currentAnimation = null;
                        }
                    }
                });
                currentAnimation.start();
            }
        } else {
            if (wasInstalled) {
                addButton.setVisibility(VISIBLE);
                addButton.setClickable(true);
                currentAnimation = new AnimatorSet();
                currentAnimation.setDuration(200);
                currentAnimation.playTogether(ObjectAnimator.ofFloat(checkImage, "alpha", 1.0f, 0.0f),
                        ObjectAnimator.ofFloat(checkImage, "scaleX", 1.0f, 0.01f),
                        ObjectAnimator.ofFloat(checkImage, "scaleY", 1.0f, 0.01f),
                        ObjectAnimator.ofFloat(addButton, "alpha", 0.0f, 1.0f),
                        ObjectAnimator.ofFloat(addButton, "scaleX", 0.01f, 1.0f),
                        ObjectAnimator.ofFloat(addButton, "scaleY", 0.01f, 1.0f));
                currentAnimation.addListener(new AnimatorListenerAdapterProxy() {
                    @Override
                    public void onAnimationEnd(Animator animator) {
                        if (currentAnimation != null && currentAnimation.equals(animator)) {
                            checkImage.setVisibility(INVISIBLE);
                        }
                    }

                    @Override
                    public void onAnimationCancel(Animator animator) {
                        if (currentAnimation != null && currentAnimation.equals(animator)) {
                            currentAnimation = null;
                        }
                    }
                });
                currentAnimation.start();
            }
        }
    } else {
        if (isInstalled = StickersQuery.isStickerPackInstalled(set.set.id)) {
            addButton.setVisibility(INVISIBLE);
            addButton.setClickable(false);
            checkImage.setVisibility(VISIBLE);
            checkImage.setScaleX(1.0f);
            checkImage.setScaleY(1.0f);
            checkImage.setAlpha(1.0f);
        } else {
            addButton.setVisibility(VISIBLE);
            addButton.setClickable(true);
            checkImage.setVisibility(INVISIBLE);
            addButton.setScaleX(1.0f);
            addButton.setScaleY(1.0f);
            addButton.setAlpha(1.0f);
        }
    }
}

From source file:org.telegram.ui.ActionBar.Theme.java

public static Drawable createBarSelectorDrawable(int color, boolean masked) {
    Drawable drawable;//from w  ww.j  a va 2  s  . c om
    if (Build.VERSION.SDK_INT >= 21) {
        Drawable maskDrawable = null;
        if (masked) {
            maskPaint.setColor(0xffffffff);
            maskDrawable = new Drawable() {
                @Override
                public void draw(Canvas canvas) {
                    android.graphics.Rect bounds = getBounds();
                    canvas.drawCircle(bounds.centerX(), bounds.centerY(), AndroidUtilities.dp(18), maskPaint);
                }

                @Override
                public void setAlpha(int alpha) {

                }

                @Override
                public void setColorFilter(ColorFilter colorFilter) {

                }

                @Override
                public int getOpacity() {
                    return PixelFormat.UNKNOWN;
                }
            };
        }
        ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] {} }, new int[] { color });
        return new RippleDrawable(colorStateList, null, maskDrawable);
    } else {
        StateListDrawable stateListDrawable = new StateListDrawable();
        stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(color));
        stateListDrawable.addState(new int[] { android.R.attr.state_focused }, new ColorDrawable(color));
        stateListDrawable.addState(new int[] { android.R.attr.state_selected }, new ColorDrawable(color));
        stateListDrawable.addState(new int[] { android.R.attr.state_activated }, new ColorDrawable(color));
        stateListDrawable.addState(new int[] {}, new ColorDrawable(0x00000000));
        return stateListDrawable;
    }
}

From source file:com.eveningoutpost.dexdrip.Home.java

private void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;//from w w  w  .j a  v a  2s .  c om
    chart = (LineChartView) findViewById(R.id.chart);

    if (BgGraphBuilder.isXLargeTablet(getApplicationContext())) {
        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) chart.getLayoutParams();
        params.topMargin = 130;
        chart.setLayoutParams(params);
    }
    chart.setBackgroundColor(getCol(X.color_home_chart_background));
    chart.setZoomType(ZoomType.HORIZONTAL);

    //Transmitter Battery Level
    final Sensor sensor = Sensor.currentSensor();
    if (sensor != null && sensor.latest_battery_level != 0
            && sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_LOW
            && !prefs.getBoolean("disable_battery_warning", false)) {
        Drawable background = new Drawable() {

            @Override
            public void draw(Canvas canvas) {

                DisplayMetrics metrics = getApplicationContext().getResources().getDisplayMetrics();
                int px = (int) (30 * (metrics.densityDpi / 160f));
                Paint paint = new Paint();
                paint.setTextSize(px);
                paint.setAntiAlias(true);
                paint.setColor(Color.parseColor("#FFFFAA"));
                paint.setStyle(Paint.Style.STROKE);
                paint.setAlpha(100);
                canvas.drawText(getString(R.string.transmitter_battery), 10,
                        chart.getHeight() / 3 - (int) (1.2 * px), paint);
                if (sensor.latest_battery_level <= Constants.TRANSMITTER_BATTERY_EMPTY) {
                    paint.setTextSize((int) (px * 1.5));
                    canvas.drawText(getString(R.string.very_low), 10, chart.getHeight() / 3, paint);
                } else {
                    canvas.drawText(getString(R.string.low), 10, chart.getHeight() / 3, paint);
                }
            }

            @Override
            public void setAlpha(int alpha) {
            }

            @Override
            public void setColorFilter(ColorFilter cf) {
            }

            @Override
            public int getOpacity() {
                return 0; // TODO Which pixel format should this be?
            }
        };
        chart.setBackground(background);
    }
    previewChart = (PreviewLineChartView) findViewById(R.id.chart_preview);

    chart.setLineChartData(bgGraphBuilder.lineData());
    chart.setOnValueTouchListener(bgGraphBuilder.getOnValueSelectTooltipListener(mActivity));

    previewChart.setBackgroundColor(getCol(X.color_home_chart_background));
    previewChart.setZoomType(ZoomType.HORIZONTAL);

    previewChart.setLineChartData(bgGraphBuilder.previewLineData(chart.getLineChartData()));
    updateStuff = true;

    previewChart.setViewportCalculationEnabled(true);
    chart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportChangeListener(new ChartViewPortListener());
    setViewport();

    if (small_height) {
        previewChart.setVisibility(View.GONE);

        // quick test
        Viewport moveViewPort = new Viewport(chart.getMaximumViewport());
        float tempwidth = (float) moveViewPort.width() / 4;
        holdViewport.left = moveViewPort.right - tempwidth;
        holdViewport.right = moveViewPort.right + (moveViewPort.width() / 24);
        holdViewport.top = moveViewPort.top;
        holdViewport.bottom = moveViewPort.bottom;
        chart.setCurrentViewport(holdViewport);
        previewChart.setCurrentViewport(holdViewport);
    } else {
        previewChart.setVisibility(View.VISIBLE);
    }

    if (insulinset || glucoseset || carbsset || timeset) {
        if (chart != null) {
            chart.setAlpha((float) 0.10);
            // TODO also set buttons alpha
        }
    }

}