Search in sources :

Example 61 with ColorFilter

use of android.graphics.ColorFilter in project android_packages_apps_Dialer by MoKee.

the class PseudoEmergencyAnimator method start.

public void start() {
    if (mPseudoEmergencyColorAnimator == null) {
        Integer colorFrom = Color.BLUE;
        Integer colorTo = Color.RED;
        mPseudoEmergencyColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
        mPseudoEmergencyColorAnimator.addUpdateListener(new AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                try {
                    int color = (int) animator.getAnimatedValue();
                    ColorFilter colorFilter = new LightingColorFilter(Color.BLACK, color);
                    View floatingActionButtonContainer = getView().findViewById(R.id.dialpad_floating_action_button_container);
                    if (floatingActionButtonContainer != null) {
                        floatingActionButtonContainer.getBackground().setColorFilter(colorFilter);
                    }
                } catch (Exception e) {
                    animator.cancel();
                }
            }
        });
        mPseudoEmergencyColorAnimator.addListener(new AnimatorListener() {

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                try {
                    vibrate(VIBRATE_LENGTH_MILLIS);
                } catch (Exception e) {
                    animation.cancel();
                }
            }

            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                try {
                    View floatingActionButtonContainer = getView().findViewById(R.id.dialpad_floating_action_button_container);
                    if (floatingActionButtonContainer != null) {
                        floatingActionButtonContainer.getBackground().clearColorFilter();
                    }
                    new Handler().postDelayed(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                vibrate(VIBRATE_LENGTH_MILLIS);
                            } catch (Exception e) {
                            // ignored
                            }
                        }
                    }, ITERATION_LENGTH_MILLIS);
                } catch (Exception e) {
                    animation.cancel();
                }
            }
        });
        mPseudoEmergencyColorAnimator.setDuration(VIBRATE_LENGTH_MILLIS);
        mPseudoEmergencyColorAnimator.setRepeatMode(ValueAnimator.REVERSE);
        mPseudoEmergencyColorAnimator.setRepeatCount(ANIMATION_ITERATION_COUNT);
    }
    if (!mPseudoEmergencyColorAnimator.isStarted()) {
        mPseudoEmergencyColorAnimator.start();
    }
}
Also used : ArgbEvaluator(android.animation.ArgbEvaluator) Handler(android.os.Handler) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) View(android.view.View) AnimatorListener(android.animation.Animator.AnimatorListener) ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) LightingColorFilter(android.graphics.LightingColorFilter)

Example 62 with ColorFilter

use of android.graphics.ColorFilter in project xDrip-plus by jamorham.

the class Home method setupCharts.

private void setupCharts() {
    bgGraphBuilder = new BgGraphBuilder(this);
    updateStuff = false;
    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();
    // ????????? what about tomato here ?????
    if (sensor != null && sensor.latest_battery_level != 0 && !DexCollectionService.getBestLimitterHardwareName().equalsIgnoreCase("BlueReader") && sensor.latest_battery_level <= Dex_Constants.TRANSMITTER_BATTERY_LOW && !Pref.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 <= Dex_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() {
                // TODO Which pixel format should this be?
                return 0;
            }
        };
        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()));
    previewChart.setViewportCalculationEnabled(true);
    previewChart.setViewportChangeListener(new ViewportListener());
    chart.setViewportCalculationEnabled(true);
    chart.setViewportChangeListener(new ChartViewPortListener());
    updateStuff = true;
    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 {
        if (homeShelf.get("time_buttons")) {
            final long which_hour = PersistentStore.getLong("home-locked-hours");
            if (which_hour > 0) {
                hours = which_hour;
                setHoursViewPort();
            } else {
                hours = DEFAULT_CHART_HOURS;
            }
        } else {
            hours = DEFAULT_CHART_HOURS;
        }
        previewChart.setVisibility(homeShelf.get("chart_preview") ? View.VISIBLE : View.GONE);
    }
    if (insulinset || glucoseset || carbsset || timeset) {
        if (chart != null) {
            chart.setAlpha((float) 0.10);
        // TODO also set buttons alpha
        }
    }
}
Also used : ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Viewport(lecho.lib.hellocharts.model.Viewport) Paint(android.graphics.Paint) DisplayMetrics(android.util.DisplayMetrics) Paint(android.graphics.Paint) Point(android.graphics.Point) BgGraphBuilder(com.eveningoutpost.dexdrip.UtilityModels.BgGraphBuilder) ColorFilter(android.graphics.ColorFilter) Sensor(com.eveningoutpost.dexdrip.Models.Sensor)

Example 63 with ColorFilter

use of android.graphics.ColorFilter in project robolectric by robolectric.

the class ShadowCanvas method describeBitmap.

private void describeBitmap(Bitmap bitmap, Paint paint) {
    separateLines();
    ShadowBitmap shadowBitmap = Shadow.extract(bitmap);
    appendDescription(shadowBitmap.getDescription());
    if (paint != null) {
        ColorFilter colorFilter = paint.getColorFilter();
        if (colorFilter != null) {
            if (colorFilter instanceof ColorMatrixColorFilter) {
                ColorMatrixColorFilter colorMatrixColorFilter = (ColorMatrixColorFilter) colorFilter;
                ShadowColorMatrixColorFilter shadowColorMatrixColorFilter = Shadow.extract(colorMatrixColorFilter);
                ColorMatrix colorMatrix = shadowColorMatrixColorFilter.getMatrix();
                appendDescription(" with ColorMatrixColorFilter<" + formatColorMatric(colorMatrix) + ">");
            } else {
                appendDescription(" with " + colorFilter);
            }
        }
    }
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorFilter(android.graphics.ColorFilter) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) ColorMatrix(android.graphics.ColorMatrix)

Example 64 with ColorFilter

use of android.graphics.ColorFilter in project glide by bumptech.

the class GifDrawableTest method testSetColorFilterSetsColorFilterOnPaint.

@Test
public void testSetColorFilterSetsColorFilterOnPaint() {
    ColorFilter colorFilter = new PorterDuffColorFilter(Color.RED, Mode.ADD);
    drawable.setColorFilter(colorFilter);
    // Use ArgumentCaptor instead of eq() due to b/73121412 where ShadowPorterDuffColorFilter.equals
    // uses a method that can't be found (PorterDuffColorFilter.getColor).
    ArgumentCaptor<ColorFilter> captor = ArgumentCaptor.forClass(ColorFilter.class);
    verify(paint).setColorFilter(captor.capture());
    assertThat(captor.getValue()).isSameAs(colorFilter);
}
Also used : PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) ColorFilter(android.graphics.ColorFilter) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Test(org.junit.Test)

Example 65 with ColorFilter

use of android.graphics.ColorFilter in project fresco by facebook.

the class ForwardingDrawableTest method testSettersAndGetters.

@Test
public void testSettersAndGetters() {
    ColorFilter colorFilterMock = mock(ColorFilter.class);
    Rect rectMock = mock(Rect.class);
    int alpha = 77;
    boolean dither = true;
    boolean filterBitmap = false;
    boolean visible = false;
    boolean restart = false;
    // when(mInnerDrawable.setVisible(visible, restart)).thenReturn(true);
    when(mInnerDrawable.getOpacity()).thenReturn(11);
    Assert.assertEquals(11, mDrawable.getOpacity());
    mDrawable.getPadding(rectMock);
    mDrawable.setAlpha(alpha);
    mDrawable.setDither(dither);
    mDrawable.setFilterBitmap(filterBitmap);
    mDrawable.setColorFilter(colorFilterMock);
    mDrawable.onBoundsChange(rectMock);
    mDrawable.setVisible(visible, restart);
    verify(mInnerDrawable).getPadding(rectMock);
    verify(mInnerDrawable).setAlpha(alpha);
    verify(mInnerDrawable).setDither(dither);
    verify(mInnerDrawable).setFilterBitmap(filterBitmap);
    verify(mInnerDrawable).setColorFilter(colorFilterMock);
    verify(mInnerDrawable).setBounds(rectMock);
    verify(mInnerDrawable).setVisible(visible, restart);
}
Also used : Rect(android.graphics.Rect) ColorFilter(android.graphics.ColorFilter) Test(org.junit.Test)

Aggregations

ColorFilter (android.graphics.ColorFilter)75 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)26 LightingColorFilter (android.graphics.LightingColorFilter)25 Paint (android.graphics.Paint)25 Drawable (android.graphics.drawable.Drawable)23 Canvas (android.graphics.Canvas)14 FilterableStateListDrawable (com.simplecity.amp_library.ui.views.FilterableStateListDrawable)14 LayerDrawable (android.graphics.drawable.LayerDrawable)12 Bitmap (android.graphics.Bitmap)11 View (android.view.View)7 Test (org.junit.Test)7 Path (android.graphics.Path)5 Rect (android.graphics.Rect)5 RectF (android.graphics.RectF)5 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Animator (android.animation.Animator)3 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3