Example usage for android.graphics Color argb

List of usage examples for android.graphics Color argb

Introduction

In this page you can find the example usage for android.graphics Color argb.

Prototype

@ColorInt
public static int argb(float alpha, float red, float green, float blue) 

Source Link

Document

Return a color-int from alpha, red, green, blue float components in the range \([0..1]\).

Usage

From source file:com.next.PagerSlidingTabStrip.java

private void updateTextViewColor(View tabView, float currentPositionOffset) {

    int currentAlpha = (int) (155 + currentPositionOffset * 100);

    //      http://stackoverflow.com/questions/4602902/how-to-set-the-text-color-of-textview-in-code
    if (tabView instanceof TextView) {
        ((TextView) tabView).setTextColor(Color.argb(currentAlpha, Color.red(tabTextColor),
                Color.green(tabTextColor), Color.blue(tabTextColor)));
        //            ((TextView) tabView).setAlpha(alpha);
    } else if (tabView instanceof FrameLayout && ((FrameLayout) tabView).getChildAt(0) instanceof TextView) {
        ((TextView) ((FrameLayout) tabView).getChildAt(0)).setTextColor(Color.argb(currentAlpha,
                Color.red(tabTextColor), Color.green(tabTextColor), Color.blue(tabTextColor)));
        //            ((TextView) ((FrameLayout) tabView).getChildAt(0)).setAlpha(alpha);
    }//from w w w  .ja va2 s. c  o  m
}

From source file:org.rm3l.ddwrt.tiles.status.bandwidth.BandwidthWANMonitoringTile.java

@Override
public void onLoadFinished(Loader<None> loader, None data) {
    Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data);

    layout.findViewById(R.id.tile_status_bandwidth_monitoring_graph_loading_view).setVisibility(View.GONE);
    layout.findViewById(R.id.tile_status_bandwidth_monitoring_graph_placeholder).setVisibility(View.VISIBLE);

    //noinspection ConstantConditions
    if (data == null || bandwidthMonitoringIfaceData.getData().isEmpty()) {
        data = (None) new None().setException(new DDWRTNoDataException("No Data!"));
    }/*from  www. j a  v a2 s. c  om*/

    @NotNull
    final TextView errorPlaceHolderView = (TextView) this.layout
            .findViewById(R.id.tile_status_bandwidth_monitoring_error);

    @Nullable
    final Exception exception = data.getException();

    if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {

        if (exception == null) {
            errorPlaceHolderView.setVisibility(View.GONE);
        }

        ((TextView) this.layout.findViewById(R.id.tile_status_bandwidth_monitoring_title))
                .setText(this.mParentFragmentActivity.getResources().getString(R.string.bandwidth_usage_mb)
                        + (!Strings.isNullOrEmpty(wanIface) ? (": " + wanIface) : ""));

        @NotNull
        final LinearLayout graphPlaceHolder = (LinearLayout) this.layout
                .findViewById(R.id.tile_status_bandwidth_monitoring_graph_placeholder);
        final Map<String, EvictingQueue<BandwidthMonitoringTile.DataPoint>> dataCircularBuffer = bandwidthMonitoringIfaceData
                .getData();

        long maxX = System.currentTimeMillis() + 5000;
        long minX = System.currentTimeMillis() - 5000;
        double maxY = 10;
        double minY = 1.;

        final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        final XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();

        for (final Map.Entry<String, EvictingQueue<BandwidthMonitoringTile.DataPoint>> entry : dataCircularBuffer
                .entrySet()) {
            final String iface = entry.getKey();
            final EvictingQueue<BandwidthMonitoringTile.DataPoint> dataPoints = entry.getValue();
            final XYSeries series = new XYSeries(iface);
            for (final BandwidthMonitoringTile.DataPoint point : dataPoints) {
                final long x = point.getTimestamp();
                final double y = point.getValue();
                series.add(x, y);
                maxX = Math.max(maxX, x);
                minX = Math.min(minX, x);
                maxY = Math.max(maxY, y);
                minY = Math.min(minY, y);
            }
            // Now we add our series
            dataset.addSeries(series);

            // Now we create the renderer
            final XYSeriesRenderer renderer = new XYSeriesRenderer();
            renderer.setLineWidth(2);

            Integer ifaceColor = colorsCache.get(iface);
            if (ifaceColor == null) {
                //Generate a Random Color, excluding 'white' (because graph background is already white)
                ifaceColor = Color.argb(255, randomColorGen.nextInt(255), randomColorGen.nextInt(255),
                        randomColorGen.nextInt(255));
                colorsCache.put(iface, ifaceColor);
            }
            renderer.setColor(ifaceColor);
            // Include low and max value
            renderer.setDisplayBoundingPoints(true);
            // we add point markers
            renderer.setPointStyle(PointStyle.POINT);
            renderer.setPointStrokeWidth(1);

            mRenderer.addSeriesRenderer(renderer);
        }

        // We want to avoid black border
        mRenderer.setMarginsColor(Color.argb(0x00, 0xff, 0x00, 0x00)); // transparent margins
        // Disable Pan on two axis
        mRenderer.setPanEnabled(false, false);
        mRenderer.setYAxisMax(maxY + 10);
        mRenderer.setYAxisMin(minY);
        mRenderer.setXAxisMin(minX);
        mRenderer.setXAxisMax(maxX + 10);
        mRenderer.setShowGrid(false);
        mRenderer.setClickEnabled(false);
        mRenderer.setZoomEnabled(true);
        mRenderer.setPanEnabled(false);
        mRenderer.setZoomRate(6.0f);
        mRenderer.setShowLabels(true);
        mRenderer.setFitLegend(true);
        mRenderer.setInScroll(true);

        final GraphicalView chartView = ChartFactory.getTimeChartView(graphPlaceHolder.getContext(), dataset,
                mRenderer, null);
        chartView.repaint();

        graphPlaceHolder.addView(chartView, 0);
    }

    if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final Throwable rootCause = Throwables.getRootCause(exception);
        errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null"));
        final Context parentContext = this.mParentFragmentActivity;
        errorPlaceHolderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                //noinspection ThrowableResultOfMethodCallIgnored
                if (rootCause != null) {
                    Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
        errorPlaceHolderView.setVisibility(View.VISIBLE);
    } else {
        if (bandwidthMonitoringIfaceData.getData().isEmpty()) {
            errorPlaceHolderView.setText("Error: No Data!");
            errorPlaceHolderView.setVisibility(View.VISIBLE);
        }
    }

    doneWithLoaderInstance(this, loader, R.id.tile_status_bandwidth_monitoring_togglebutton_title,
            R.id.tile_status_bandwidth_monitoring_togglebutton_separator);

    Log.d(LOG_TAG, "onLoadFinished(): done loading!");
}

From source file:me.lizheng.deckview.views.DeckChildView.java

/**
 * Returns the current dim.//from   ww  w  .  ja  v  a2  s  . c  om
 */
public void setDim(int dim) {
    mDimAlpha = dim;
    if (mConfig.useHardwareLayers) {
        // Defer setting hardware layers if we have not yet measured, or there is no dim to draw
        if (getMeasuredWidth() > 0 && getMeasuredHeight() > 0) {
            mDimColorFilter = new PorterDuffColorFilter(Color.argb(mDimAlpha, 0, 0, 0),
                    PorterDuff.Mode.SRC_ATOP);
            mDimLayerPaint.setColorFilter(mDimColorFilter);
            mContent.setLayerType(LAYER_TYPE_HARDWARE, mDimLayerPaint);
        }
    } else {
        float dimAlpha = mDimAlpha / 255.0f;
        if (mThumbnailView != null) {
            mThumbnailView.setDimAlpha(dimAlpha);
        }
    }
}

From source file:com.grarak.kerneladiutor.fragments.RecyclerViewFragment.java

private void setAppBarLayoutAlpha(int alpha) {
    if (isForeground())
        return;//  ww w.ja va  2 s . c o  m
    Activity activity;
    if ((activity = getActivity()) != null && mAppBarLayout != null && mToolBar != null) {
        int colorPrimary = ViewUtils.getColorPrimaryColor(activity);
        mAppBarLayout.setBackgroundDrawable(new ColorDrawable(Color.argb(alpha, Color.red(colorPrimary),
                Color.green(colorPrimary), Color.blue(colorPrimary))));
        mToolBar.setTitleTextColor(Color.argb(alpha, 255, 255, 255));
    }
}

From source file:com.apptentive.android.sdk.util.Util.java

public static int brighter(int color, float factor) {
    int red = (int) ((Color.red(color) * (1 - factor) / 255 + factor) * 255);
    int green = (int) ((Color.green(color) * (1 - factor) / 255 + factor) * 255);
    int blue = (int) ((Color.blue(color) * (1 - factor) / 255 + factor) * 255);
    return Color.argb(Color.alpha(color), red, green, blue);
}

From source file:com.chess.genesis.view.SwipeTabs.java

private static int interpolateColor(final int color1, final int color2, final float fraction) {
    final float alpha1 = Color.alpha(color1) / 255.0f;
    final float red1 = Color.red(color1) / 255.0f;
    final float green1 = Color.green(color1) / 255.0f;
    final float blue1 = Color.blue(color1) / 255.0f;

    final float alpha2 = Color.alpha(color2) / 255.0f;
    final float red2 = Color.red(color2) / 255.0f;
    final float green2 = Color.green(color2) / 255.0f;
    final float blue2 = Color.blue(color2) / 255.0f;

    final float deltaAlpha = alpha2 - alpha1;
    final float deltaRed = red2 - red1;
    final float deltaGreen = green2 - green1;
    final float deltaBlue = blue2 - blue1;

    float alpha = alpha1 + (deltaAlpha * fraction);
    float red = red1 + (deltaRed * fraction);
    float green = green1 + (deltaGreen * fraction);
    float blue = blue1 + (deltaBlue * fraction);

    alpha = 255.0f * Math.max(Math.min(alpha, 1f), 0f);
    red = 255.0f * Math.max(Math.min(red, 1f), 0f);
    green = 255.0f * Math.max(Math.min(green, 1f), 0f);
    blue = 255.0f * Math.max(Math.min(blue, 1f), 0f);

    return Color.argb((int) alpha, (int) red, (int) green, (int) blue);
}

From source file:com.apptentive.android.sdk.util.Util.java

public static int dimmer(int color, float factor) {
    int alpha = (int) (Color.alpha(color) * factor);
    return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
}

From source file:com.guipenedo.pokeradar.activities.MapsActivity.java

public void setScanning(boolean scanning) {
    if (scanRange != null)
        scanRange.remove();/*from   w w w .j  a  v a  2 s .c  o m*/
    if (scanning) {
        scanRange = mMap.addCircle(new CircleOptions().center(location)
                .strokeColor(Color.argb(50, 29, 132, 181)).fillColor(Color.argb(30, 29, 132, 181)).radius(50));
        scanButton.setVisibility(View.INVISIBLE);
        scanProgressBar.setVisibility(View.VISIBLE);
        cancelScanButton.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.VISIBLE);
        progressBar.setProgress(0);
    } else {
        scanButton.setVisibility(View.VISIBLE);
        scanProgressBar.setVisibility(View.INVISIBLE);
        cancelScanButton.setVisibility(View.INVISIBLE);
        progressBar.setVisibility(View.INVISIBLE);
        scanRange = null;
        if (rangeCenter != null)
            rangeCenter.remove();
        rangeCenter = null;
    }
}

From source file:com.lamcreations.scaffold.common.utils.CollapsingTextHelper.java

private static int blendColors(int color1, int color2, float ratio) {
    float inverseRatio = 1.0F - ratio;
    float a = (float) Color.alpha(color1) * inverseRatio + (float) Color.alpha(color2) * ratio;
    float r = (float) Color.red(color1) * inverseRatio + (float) Color.red(color2) * ratio;
    float g = (float) Color.green(color1) * inverseRatio + (float) Color.green(color2) * ratio;
    float b = (float) Color.blue(color1) * inverseRatio + (float) Color.blue(color2) * ratio;
    return Color.argb((int) a, (int) r, (int) g, (int) b);
}

From source file:com.arcgis.android.samples.geometrysample.SpatialRelationshipsFragment.java

void singleTapAct(float x, float y) throws Exception {
    countTap++;/*from  ww  w . j  a  va 2s.  c  o  m*/
    Point point = mapView.toMapPoint(x, y);
    Log.d("sigle tap on screen:", "[" + x + "," + y + "]");
    Log.d("sigle tap on map:", "[" + point.getX() + "," + point.getY() + "]");
    if (geomNumWorkon == 1) {
        if (firstGeometry == null) {
            if (firstGeoType == GEOMETRY_TYPE.point) {
                firstGeometry = point;

            } else if (firstGeoType == GEOMETRY_TYPE.multi_points) {
                firstGeometry = new MultiPoint();
                ((MultiPoint) firstGeometry).add(point);
            } else if (firstGeoType == GEOMETRY_TYPE.polygon) {
                firstGeometry = new Polygon();
                ((MultiPath) firstGeometry).startPath(point);
                isStartPointSet1 = true;
                Log.d("geometry step " + countTap,
                        GeometryEngine.geometryToJson(mapView.getSpatialReference(), firstGeometry));

            } else if (firstGeoType == GEOMETRY_TYPE.polyline) {
                isStartPointSet1 = true;
                firstGeometry = new Polyline();
                ((MultiPath) firstGeometry).startPath(point);
            }

        }

    } else if (geomNumWorkon == 2) {
        if (secondGeometry == null) {
            if (secondGeoType == GEOMETRY_TYPE.point) {
                secondGeometry = point;

            } else if (secondGeoType == GEOMETRY_TYPE.multi_points) {
                secondGeometry = new MultiPoint();
                ((MultiPoint) secondGeometry).add(point);
            } else if (secondGeoType == GEOMETRY_TYPE.polygon) {
                secondGeometry = new Polygon();
                ((MultiPath) secondGeometry).startPath(point);
                isStartPointSet2 = true;

            } else if (secondGeoType == GEOMETRY_TYPE.polyline) {
                isStartPointSet2 = true;
                secondGeometry = new Polyline();
                ((MultiPath) secondGeometry).startPath(point);
            }

        }

    }

    if (geomNumWorkon == 1) {
        if (firstGeoType == null)
            return;
        // int blue = Color.BLUE;
        int color1 = Color.BLUE;
        drawGeomOnGraphicLyr(firstGeometry, firstGeomLayer, point, firstGeoType, color1, isStartPointSet1);
        Log.d("geometry step " + countTap,
                GeometryEngine.geometryToJson(mapView.getSpatialReference(), firstGeometry));

    } else if (geomNumWorkon == 2) {
        if (secondGeoType == null)
            return;
        int green = Color.GREEN;
        int color2 = Color.argb(100, Color.red(green), Color.green(green), Color.blue(green));
        drawGeomOnGraphicLyr(secondGeometry, secondGeomLayer, point, secondGeoType, color2, isStartPointSet2);
    }

}