List of usage examples for android.support.v4.graphics ColorUtils setAlphaComponent
@ColorInt public static int setAlphaComponent(@ColorInt int color, @IntRange(from = 0x0, to = 0xFF) int alpha)
From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.CircularBorderDrawable.java
/** * Creates a vertical {@link LinearGradient} * @return/* www . jav a2s . co m*/ */ private Shader createGradientShader() { final Rect rect = mRect; copyBounds(rect); final float borderRatio = mBorderWidth / rect.height(); final int[] colors = new int[6]; colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mTintColor); colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mTintColor); colors[2] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mTintColor); colors[3] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0), mTintColor); colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mTintColor); colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mTintColor); final float[] positions = new float[6]; positions[0] = 0f; positions[1] = borderRatio; positions[2] = 0.5f; positions[3] = 0.5f; positions[4] = 1f - borderRatio; positions[5] = 1f; return new LinearGradient(0, rect.top, 0, rect.bottom, colors, positions, Shader.TileMode.CLAMP); }
From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java
void customTheme(int drawableResId, int colorPrimary, int textColor, int tintColor) { Resources res = mContext.getResources(); mSunImage = res.getDrawable(drawableResId); DrawableCompat.setTintColorCompat(mSunImage, tintColor); mArcFillPaint.setColor(colorPrimary); mArcFillPaint.setColor(ColorUtils.setAlphaComponent(colorPrimary, 128)); mLinePaint.setColor(textColor);/* www.jav a 2s .c o m*/ mDotPaint.setColor(tintColor); float density = res.getDisplayMetrics().density; int sunBounds = (int) (density * 16); mSunImage.setBounds(0, 0, sunBounds, sunBounds); Callback callback = getCallback(); if (callback != null) { callback.invalidateDrawable(this); } }
From source file:com.bilibili.magicasakura.utils.ThemeUtils.java
static int getThemeAttrColor(Context context, @AttrRes int attr, float alpha) { final int color = getThemeAttrColor(context, attr); final int originalAlpha = Color.alpha(color); return ColorUtils.setAlphaComponent(color, Math.round(originalAlpha * alpha)); }
From source file:com.farmerbb.taskbar.adapter.StartMenuAdapter.java
@Override public @NonNull View getView(int position, View convertView, final @NonNull ViewGroup parent) { // Check if an existing view is being reused, otherwise inflate the view if (convertView == null) convertView = LayoutInflater.from(getContext()).inflate(isGrid ? R.layout.row_alt : R.layout.row, parent, false);//from w ww. j a v a 2 s. c om final AppEntry entry = getItem(position); assert entry != null; final SharedPreferences pref = U.getSharedPreferences(getContext()); TextView textView = (TextView) convertView.findViewById(R.id.name); textView.setText(entry.getLabel()); Intent intent = new Intent(); intent.setComponent(ComponentName.unflattenFromString(entry.getComponentName())); ActivityInfo activityInfo = intent.resolveActivityInfo(getContext().getPackageManager(), 0); if (activityInfo != null) textView.setTypeface(null, isTopApp(activityInfo) ? Typeface.BOLD : Typeface.NORMAL); switch (pref.getString("theme", "light")) { case "light": textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color)); break; case "dark": textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_dark)); break; } ImageView imageView = (ImageView) convertView.findViewById(R.id.icon); imageView.setImageDrawable(entry.getIcon(getContext())); LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.entry); layout.setOnClickListener(view -> { LocalBroadcastManager.getInstance(getContext()) .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU")); U.launchApp(getContext(), entry.getPackageName(), entry.getComponentName(), entry.getUserId(getContext()), null, false, false); }); layout.setOnLongClickListener(view -> { int[] location = new int[2]; view.getLocationOnScreen(location); openContextMenu(entry, location); return true; }); layout.setOnGenericMotionListener((view, motionEvent) -> { int action = motionEvent.getAction(); if (action == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) { int[] location = new int[2]; view.getLocationOnScreen(location); openContextMenu(entry, location); } if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true)) view.setBackgroundColor(0); return false; }); if (pref.getBoolean("visual_feedback", true)) { layout.setOnHoverListener((v, event) -> { if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) { int backgroundTint = pref.getBoolean("transparent_start_menu", false) ? U.getAccentColor(getContext()) : U.getBackgroundTint(getContext()); //noinspection ResourceAsColor backgroundTint = ColorUtils.setAlphaComponent(backgroundTint, Color.alpha(backgroundTint) / 2); v.setBackgroundColor(backgroundTint); } if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT) v.setBackgroundColor(0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) v.setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT)); return false; }); layout.setOnTouchListener((v, event) -> { v.setAlpha( event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE ? 0.5f : 1); return false; }); } return convertView; }
From source file:android.support.v7.content.res.AppCompatColorStateListInflater.java
private static int modulateColorAlpha(int color, float alphaMod) { return ColorUtils.setAlphaComponent(color, Math.round(Color.alpha(color) * alphaMod)); }
From source file:com.android.launcher3.dynamicui.ExtractedColors.java
/** * The hotseat's color is defined as follows: * - 12% black for super light wallpaper * - 18% white for super dark/* w w w . ja v a 2 s . c o m*/ * - 25% white otherwise */ public void updateHotseatPalette(Palette hotseatPalette) { int hotseatColor; if (hotseatPalette != null && ExtractionUtils.isSuperLight(hotseatPalette)) { hotseatColor = ColorUtils.setAlphaComponent(Color.BLACK, (int) (0.12f * 255)); } else if (hotseatPalette != null && ExtractionUtils.isSuperDark(hotseatPalette)) { hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.18f * 255)); } else { hotseatColor = ColorUtils.setAlphaComponent(Color.WHITE, (int) (0.25f * 255)); } setColorAtIndex(HOTSEAT_INDEX, hotseatColor); }
From source file:org.tanrabad.survey.presenter.maps.BuildingMapMarkerFragment.java
private void addPlaceCircle() { LatLng placePosition = LocationUtils.convertLocationToLatLng(place.getLocation()); int placeColor = ResourceUtils.from(getActivity()).getColor(R.color.water_blue); CircleOptions circleOptions = new CircleOptions(); circleOptions.center(placePosition); circleOptions.radius(DISTANCE_LIMIT_IN_METER); circleOptions.fillColor(ColorUtils.setAlphaComponent(placeColor, 40)); circleOptions.strokeColor(placeColor); circleOptions.strokeWidth(1);/*from ww w .j av a 2 s.c om*/ googleMap.addCircle(circleOptions); }
From source file:android.support.design.widget.CircularBorderDrawable.java
/** * Creates a vertical {@link LinearGradient} * @return/*from w w w.j ava 2 s. co m*/ */ private Shader createGradientShader() { final Rect rect = mRect; copyBounds(rect); final float borderRatio = mBorderWidth / rect.height(); final int[] colors = new int[6]; colors[0] = ColorUtils.compositeColors(mTopOuterStrokeColor, mCurrentBorderTintColor); colors[1] = ColorUtils.compositeColors(mTopInnerStrokeColor, mCurrentBorderTintColor); colors[2] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mTopInnerStrokeColor, 0), mCurrentBorderTintColor); colors[3] = ColorUtils.compositeColors(ColorUtils.setAlphaComponent(mBottomInnerStrokeColor, 0), mCurrentBorderTintColor); colors[4] = ColorUtils.compositeColors(mBottomInnerStrokeColor, mCurrentBorderTintColor); colors[5] = ColorUtils.compositeColors(mBottomOuterStrokeColor, mCurrentBorderTintColor); final float[] positions = new float[6]; positions[0] = 0f; positions[1] = borderRatio; positions[2] = 0.5f; positions[3] = 0.5f; positions[4] = 1f - borderRatio; positions[5] = 1f; return new LinearGradient(0, rect.top, 0, rect.bottom, colors, positions, Shader.TileMode.CLAMP); }
From source file:io.imoji.sdk.grid.ui.ResultView.java
private Drawable getPlaceholder(int placeholderRandomizer, int position) { int[] colorArray = context.getResources().getIntArray(R.array.search_widget_placeholder_colors); int color = colorArray[(placeholderRandomizer + position) % colorArray.length]; GradientDrawable placeholder = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { ColorUtils.setAlphaComponent(Color.WHITE, GRADIENT_START_ALPHA), ColorUtils.setAlphaComponent(Color.WHITE, GRADIENT_END_ALPHA) }); placeholder.setColor(color);// w ww . j a v a 2s . com placeholder.setShape(GradientDrawable.OVAL); return placeholder; }
From source file:me.henrytao.mdcore.core.MdCompat.java
public static int modulateColorAlpha(int baseColor, float alphaMod) { if (alphaMod == 1.0f) { return baseColor; }/*www . j a v a2 s .c om*/ int alpha = (int) (Color.alpha(baseColor) * alphaMod + 0.5f); alpha = Math.min(Math.max(alpha, 0), 255); return ColorUtils.setAlphaComponent(baseColor, alpha); }