List of usage examples for android.graphics Color alpha
@IntRange(from = 0, to = 255) public static int alpha(int color)
From source file:de.mrapp.android.util.BitmapUtil.java
/** * Clips the long edge of a bitmap, if its width and height are not equal, in order to transform * it into a square. Additionally, the bitmap is resized to a specific size and a border will be * added./*from w w w . ja v a 2 s .c om*/ * * @param bitmap * The bitmap, which should be clipped, as an instance of the class {@link Bitmap}. The * bitmap may not be null * @param size * The size, the bitmap should be resized to, as an {@link Integer} value in pixels. The * size must be at least 1 * @param borderWidth * The width of the border as an {@link Integer} value in pixels. The width must be at * least 0 * @param borderColor * The color of the border as an {@link Integer} value * @return The clipped bitmap as an instance of the class {@link Bitmap} */ public static Bitmap clipSquare(@NonNull final Bitmap bitmap, final int size, final int borderWidth, @ColorInt final int borderColor) { ensureAtLeast(borderWidth, 0, "The border width must be at least 0"); Bitmap clippedBitmap = clipSquare(bitmap, size); Bitmap result = Bitmap.createBitmap(clippedBitmap.getWidth(), clippedBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(result); float offset = borderWidth / 2.0f; Rect src = new Rect(0, 0, clippedBitmap.getWidth(), clippedBitmap.getHeight()); RectF dst = new RectF(offset, offset, result.getWidth() - offset, result.getHeight() - offset); canvas.drawBitmap(clippedBitmap, src, dst, null); if (borderWidth > 0 && Color.alpha(borderColor) != 0) { Paint paint = new Paint(); paint.setFilterBitmap(false); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(borderWidth); paint.setColor(borderColor); offset = borderWidth / 2.0f; RectF bounds = new RectF(offset, offset, result.getWidth() - offset, result.getWidth() - offset); canvas.drawRect(bounds, paint); } return result; }
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.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.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:lollipop.iconics.IconicsDrawable.java
/** * Set contour color for the.//from w w w . j a v a 2s. c om * * @param contourColor * @return The current IconExtDrawable for chaining. */ public IconicsDrawable contourColor(@ColorInt int contourColor) { int red = Color.red(contourColor); int green = Color.green(contourColor); int blue = Color.blue(contourColor); mContourPaint.setColor(Color.rgb(red, green, blue)); mContourPaint.setAlpha(Color.alpha(contourColor)); invalidateSelf(); return this; }
From source file:com.bilibili.magicasakura.utils.GradientDrawableInflateImpl.java
int getAlphaColor(int baseColor, float alpha) { return alpha != 1.0f ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alpha)) : baseColor;// w ww . j ava 2s . co m }
From source file:com.next.PagerSlidingTabStrip.java
private void updateTextViewColor(View tabView, int color) { Color.argb(Color.alpha(color), Color.red(color), Color.green(color), Color.blue(color)); // http://stackoverflow.com/questions/4602902/how-to-set-the-text-color-of-textview-in-code float alpha = 1.0f; int alphaInteger = 255; if (color == tabTextColorNormal) { alpha = 0.5f;//from w w w.ja va2s . c o m alphaInteger *= alpha; } if (tabView instanceof TextView) { ((TextView) tabView).setTextColor(color); // ((TextView) tabView).setAlpha(alpha); } else if (tabView instanceof FrameLayout && ((FrameLayout) tabView).getChildAt(0) instanceof TextView) { ((TextView) ((FrameLayout) tabView).getChildAt(0)).setTextColor(color); // ((TextView) ((FrameLayout) tabView).getChildAt(0)).setAlpha(alpha); } }
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.android.apps.muzei.settings.SettingsChooseSourceFragment.java
public void updateSources() { mSelectedSource = null;//from w ww . j av a 2 s .c om 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:android.support.graphics.drawable.VectorDrawableCompat.java
private static int applyAlpha(int color, float alpha) { int alphaBytes = Color.alpha(color); color &= 0x00FFFFFF;/*from w ww . j av a 2s . c o m*/ color |= ((int) (alphaBytes * alpha)) << 24; return color; }