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.richtodd.android.quiltdesign.block.PaperPiecedBlockPiece.java

private Paint createShadowPaint(int left, int top, int width, int height, int shadowStrokeWidth) {
    List<PointF> points = getPoints(width, height);
    PointF fromPoint = new PointF(left + points.get(0).x, top + points.get(0).y);
    PointF toPoint = new PointF(left + points.get(1).x, top + points.get(1).y);

    PointF midpoint = new PointF((fromPoint.x + toPoint.x) * 0.5f, (fromPoint.y + toPoint.y) * 0.5f);

    PointF vector = new PointF(fromPoint.x - midpoint.x, fromPoint.y - midpoint.y);

    PointF rotatedVector = new PointF(vector.y, -vector.x);

    float vectorLength = (float) Math.sqrt((vector.x * vector.x) + (vector.y * vector.y));

    PointF shadowVector = new PointF(rotatedVector.x * (shadowStrokeWidth * 0.5f) / vectorLength,
            rotatedVector.y * (shadowStrokeWidth * 0.5f) / vectorLength);

    LinearGradient gradient = new LinearGradient(midpoint.x, midpoint.y, midpoint.x + shadowVector.x,
            midpoint.y + shadowVector.y, Color.argb(100, 0, 0, 0), Color.argb(0, 0, 0, 0), TileMode.MIRROR);

    Paint paint = new Paint();
    paint.setStyle(Style.STROKE);
    paint.setShader(gradient);//  w w  w.  j  a  v a2 s .c om
    paint.setStrokeWidth(shadowStrokeWidth);
    paint.setStrokeCap(Cap.SQUARE);

    return paint;
}

From source file:com.google.android.apps.muzei.settings.SettingsChooseSourceFragment.java

public void updateSources() {
    mSelectedSource = null;/*from ww  w  . jav a2  s .  c  o  m*/
    Intent queryIntent = new Intent(ACTION_MUZEI_ART_SOURCE);
    PackageManager pm = getActivity().getPackageManager();
    mSources.clear();
    List<ResolveInfo> resolveInfos = pm.queryIntentServices(queryIntent, PackageManager.GET_META_DATA);

    for (ResolveInfo ri : resolveInfos) {
        Source source = new Source();
        source.label = ri.loadLabel(pm).toString();
        source.icon = new BitmapDrawable(getResources(), generateSourceImage(ri.loadIcon(pm)));
        source.componentName = new ComponentName(ri.serviceInfo.packageName, ri.serviceInfo.name);
        if (ri.serviceInfo.descriptionRes != 0) {
            try {
                Context packageContext = getActivity()
                        .createPackageContext(source.componentName.getPackageName(), 0);
                Resources packageRes = packageContext.getResources();
                source.description = packageRes.getString(ri.serviceInfo.descriptionRes);
            } catch (PackageManager.NameNotFoundException e) {
                Log.e(TAG, "Can't read package resources for source " + source.componentName);
            }
        }
        Bundle metaData = ri.serviceInfo.metaData;
        source.color = Color.WHITE;
        if (metaData != null) {
            String settingsActivity = metaData.getString("settingsActivity");
            if (!TextUtils.isEmpty(settingsActivity)) {
                source.settingsActivity = ComponentName
                        .unflattenFromString(ri.serviceInfo.packageName + "/" + settingsActivity);
            }

            String setupActivity = metaData.getString("setupActivity");
            if (!TextUtils.isEmpty(setupActivity)) {
                source.setupActivity = ComponentName
                        .unflattenFromString(ri.serviceInfo.packageName + "/" + setupActivity);
            }

            source.color = metaData.getInt("color", source.color);

            try {
                float[] hsv = new float[3];
                Color.colorToHSV(source.color, hsv);
                boolean adjust = false;
                if (hsv[2] < 0.8f) {
                    hsv[2] = 0.8f;
                    adjust = true;
                }
                if (hsv[1] > 0.4f) {
                    hsv[1] = 0.4f;
                    adjust = true;
                }
                if (adjust) {
                    source.color = Color.HSVToColor(hsv);
                }
                if (Color.alpha(source.color) != 255) {
                    source.color = Color.argb(255, Color.red(source.color), Color.green(source.color),
                            Color.blue(source.color));
                }
            } catch (IllegalArgumentException ignored) {
            }
        }

        mSources.add(source);
    }

    final String appPackage = getActivity().getPackageName();
    Collections.sort(mSources, new Comparator<Source>() {
        @Override
        public int compare(Source s1, Source s2) {
            String pn1 = s1.componentName.getPackageName();
            String pn2 = s2.componentName.getPackageName();
            if (!pn1.equals(pn2)) {
                if (appPackage.equals(pn1)) {
                    return -1;
                } else if (appPackage.equals(pn2)) {
                    return 1;
                }
            }
            return s1.label.compareTo(s2.label);
        }
    });

    redrawSources();
}

From source file:net.margaritov.preference.colorpicker.ColorPickerDialog.java

private int blendColors(int from, int to, float ratio) {
    final float inverseRatio = 1f - ratio;

    final float a = Color.alpha(to) * ratio + Color.alpha(from) * inverseRatio;
    final float r = Color.red(to) * ratio + Color.red(from) * inverseRatio;
    final float g = Color.green(to) * ratio + Color.green(from) * inverseRatio;
    final float b = Color.blue(to) * ratio + Color.blue(from) * inverseRatio;

    return Color.argb((int) a, (int) r, (int) g, (int) b);
}

From source file:com.google.blockly.android.ToolboxFragment.java

protected void updateCategoryColors(ToolboxCategory curCategory) {
    Integer maybeColor = curCategory.getColor();
    int bgColor = DEFAULT_BLOCKS_BACKGROUND_COLOR;
    if (maybeColor != null) {
        bgColor = getBackgroundColor(maybeColor);
    }/*from  ww w  .  jav  a 2  s . c o  m*/
    int alphaBgColor = Color.argb(mCloseable ? DEFAULT_BLOCKS_BACKGROUND_ALPHA : ColorUtils.ALPHA_OPAQUE,
            Color.red(bgColor), Color.green(bgColor), Color.blue(bgColor));
    mBlockListView.setBackgroundColor(alphaBgColor);
}

From source file:com.jaredrummler.android.colorpicker.ColorPickerDialog.java

private int parseColorString(String colorString) throws NumberFormatException {
    int a, r, g, b = 0;
    if (colorString.startsWith("#")) {
        colorString = colorString.substring(1);
    }//from w  ww.  j  av a2  s.  co  m
    if (colorString.length() == 0) {
        r = 0;
        a = 255;
        g = 0;
    } else if (colorString.length() <= 2) {
        a = 255;
        r = 0;
        b = Integer.parseInt(colorString, 16);
        g = 0;
    } else if (colorString.length() == 3) {
        a = 255;
        r = Integer.parseInt(colorString.substring(0, 1), 16);
        g = Integer.parseInt(colorString.substring(1, 2), 16);
        b = Integer.parseInt(colorString.substring(2, 3), 16);
    } else if (colorString.length() == 4) {
        a = 255;
        r = Integer.parseInt(colorString.substring(0, 2), 16);
        g = r;
        r = 0;
        b = Integer.parseInt(colorString.substring(2, 4), 16);
    } else if (colorString.length() == 5) {
        a = 255;
        r = Integer.parseInt(colorString.substring(0, 1), 16);
        g = Integer.parseInt(colorString.substring(1, 3), 16);
        b = Integer.parseInt(colorString.substring(3, 5), 16);
    } else if (colorString.length() == 6) {
        a = 255;
        r = Integer.parseInt(colorString.substring(0, 2), 16);
        g = Integer.parseInt(colorString.substring(2, 4), 16);
        b = Integer.parseInt(colorString.substring(4, 6), 16);
    } else if (colorString.length() == 7) {
        a = Integer.parseInt(colorString.substring(0, 1), 16);
        r = Integer.parseInt(colorString.substring(1, 3), 16);
        g = Integer.parseInt(colorString.substring(3, 5), 16);
        b = Integer.parseInt(colorString.substring(5, 7), 16);
    } else if (colorString.length() == 8) {
        a = Integer.parseInt(colorString.substring(0, 2), 16);
        r = Integer.parseInt(colorString.substring(2, 4), 16);
        g = Integer.parseInt(colorString.substring(4, 6), 16);
        b = Integer.parseInt(colorString.substring(6, 8), 16);
    } else {
        b = -1;
        g = -1;
        r = -1;
        a = -1;
    }
    return Color.argb(a, r, g, b);
}

From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java

private int getPressedColor(int color) {
    float dark = 0.6f;
    return Color.argb(Color.alpha(color), (int) (Color.red(color) * dark), (int) (Color.green(color) * dark),
            (int) (Color.blue(color) * dark));
}

From source file:es.rczone.tutoriales.gmaps.MainActivity.java

private void drawPathKML(List<LatLng> list) {
    PolygonOptions opciones = new PolygonOptions().fillColor(Color.argb(100, 0, 0, 255)).strokeWidth(5f)
            .strokeColor(Color.BLUE).geodesic(true);

    for (int z = 0; z < list.size() - 1; z++) {
        LatLng src = list.get(z);/*from ww w  .j  a  va 2 s.co  m*/
        LatLng dest = list.get(z + 1);
        opciones = opciones.add(new LatLng(src.latitude, src.longitude),
                new LatLng(dest.latitude, dest.longitude));
    }

    Polygon pol = map.addPolygon(opciones);

}

From source file:me.ccrama.redditslide.Views.SubsamplingScaleImageView.java

public SubsamplingScaleImageView(Context context, AttributeSet attr) {
    super(context, attr);
    setMinimumDpi(160);/*from   w ww.j  a  v  a 2s. c o m*/
    setDoubleTapZoomDpi(160);
    setGestureDetector(context);
    this.handler = new Handler(new Handler.Callback() {
        public boolean handleMessage(Message message) {
            if (message.what == MESSAGE_LONG_CLICK && onLongClickListener != null) {
                maxTouchCount = 0;
                SubsamplingScaleImageView.super.setOnLongClickListener(onLongClickListener);
                performLongClick();
                SubsamplingScaleImageView.super.setOnLongClickListener(null);
            }
            return true;
        }
    });
    // Handle XML attributes
    if (attr != null) {
        TypedArray typedAttr = getContext().obtainStyledAttributes(attr, styleable.SubsamplingScaleImageView);
        if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_assetName)) {
            String assetName = typedAttr.getString(styleable.SubsamplingScaleImageView_assetName);
            if (assetName != null && assetName.length() > 0) {
                setImage(ImageSource.asset(assetName).tilingEnabled());
            }
        }
        if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_src)) {
            int resId = typedAttr.getResourceId(styleable.SubsamplingScaleImageView_src, 0);
            if (resId > 0) {
                setImage(ImageSource.resource(resId).tilingEnabled());
            }
        }
        if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_panEnabled)) {
            setPanEnabled(typedAttr.getBoolean(styleable.SubsamplingScaleImageView_panEnabled, true));
        }
        if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_zoomEnabled)) {
            setZoomEnabled(typedAttr.getBoolean(styleable.SubsamplingScaleImageView_zoomEnabled, true));
        }
        if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_quickScaleEnabled)) {
            setQuickScaleEnabled(
                    typedAttr.getBoolean(styleable.SubsamplingScaleImageView_quickScaleEnabled, true));
        }
        if (typedAttr.hasValue(styleable.SubsamplingScaleImageView_tileBackgroundColor)) {
            setTileBackgroundColor(typedAttr.getColor(styleable.SubsamplingScaleImageView_tileBackgroundColor,
                    Color.argb(0, 0, 0, 0)));
        }
        typedAttr.recycle();
    }

    quickScaleThreshold = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20,
            context.getResources().getDisplayMetrics());
}

From source file:com.astuetz.PagerSlidingTabStripPlus.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
        return;// w w w. j  a v a  2s  .c  om
    }

    final int height = getHeight();

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

        View nextTab = tabsContainer.getChildAt(currentPosition + 1);
        final float nextTabLeft = nextTab.getLeft();
        final float nextTabRight = nextTab.getRight();

        lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
        lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // draw indicator line
    rectPaint.setColor(Color.argb(indicatorAlpha, Color.red(indicatorColor), Color.green(indicatorColor),
            Color.blue(indicatorColor)));
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);

    // draw divider
    if (hasDivider) {
        dividerPaint.setColor(dividerColor);
        for (int i = 0; i < tabCount - 1; i++) {
            View tab = tabsContainer.getChildAt(i);
            canvas.drawLine(tab.getRight(), dividerPadding, tab.getRight(), height - dividerPadding,
                    dividerPaint);
        }
    }
}

From source file:org.jraf.android.piclabel.app.form.FormActivity.java

private void drawText(Canvas canvas) {
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.FILL);
    paint.setAntiAlias(true);// www .j a  va2 s .  c o  m
    paint.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/" + getSelectedFontName()));

    int textSize = canvas.getHeight() / 35;
    paint.setTextSize(textSize);
    int margin = textSize / 5;

    // Measure date/time
    String dateTime = mEdtDateTime.getText().toString();
    Rect boundsDateTime = new Rect();
    paint.getTextBounds(dateTime, 0, dateTime.length(), boundsDateTime);

    // Measure location
    String location = mEdtLocation.getText().toString();
    Rect boundsLocation = new Rect();
    paint.getTextBounds(location, 0, location.length(), boundsLocation);

    int totalWidth = boundsDateTime.width() + textSize * 2 + boundsLocation.width();
    if (totalWidth > canvas.getWidth()) {
        // Draw on 2 lines

        // Draw a rectangle
        paint.setColor(Color.argb(180, 0, 0, 0));
        canvas.drawRect(0, 0, canvas.getWidth(), -boundsDateTime.top + boundsDateTime.bottom
                + -boundsLocation.top + boundsLocation.bottom + margin * 3, paint);

        // Draw date/time
        paint.setColor(Color.WHITE);
        canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint);

        // Draw location
        canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin,
                margin + -boundsDateTime.top + boundsDateTime.bottom + margin + -boundsLocation.top, paint);

    } else {
        // Draw on 1 line

        // Draw a rectangle
        paint.setColor(Color.argb(180, 0, 0, 0));
        canvas.drawRect(0, 0, canvas.getWidth(),
                margin + Math.max(boundsDateTime.height(), boundsLocation.height()) + margin, paint);

        // Draw date/time
        paint.setColor(Color.WHITE);
        canvas.drawText(dateTime, margin, margin + -boundsDateTime.top, paint);

        // Draw location
        canvas.drawText(location, canvas.getWidth() - boundsLocation.right - boundsLocation.left - margin,
                margin + -boundsLocation.top, paint);
    }
}