android.support.annotation.FloatRange Java Examples
The following examples show how to use
android.support.annotation.FloatRange.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SystemBarHelper.java From FlycoSystemBar with MIT License | 6 votes |
/** * Android4.4以上的状态栏着色 * * @param window 一般都是用于Activity的window,也可以是其他的例如Dialog,DialogFragment * @param statusBarColor 状态栏颜色 * @param alpha 透明栏透明度[0.0-1.0] */ public static void tintStatusBar(Window window, @ColorInt int statusBarColor, @FloatRange(from = 0.0, to = 1.0) float alpha) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(Color.TRANSPARENT); } else { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); } ViewGroup decorView = (ViewGroup) window.getDecorView(); ViewGroup contentView = (ViewGroup) window.getDecorView().findViewById(Window.ID_ANDROID_CONTENT); View rootView = contentView.getChildAt(0); if (rootView != null) { ViewCompat.setFitsSystemWindows(rootView, true); } setStatusBar(decorView, statusBarColor, true); setTranslucentView(decorView, alpha); }
Example #2
Source File: SnakeCircleBuilder.java From AndroidWallet with GNU General Public License v3.0 | 6 votes |
@Override protected void computeUpdateValue(ValueAnimator animation, @FloatRange(from = 0.0, to = 1.0) float animatedValue) { mRotateAngle = 360 * animatedValue; mAntiRotateAngle = 360 * (1 - animatedValue); switch (mCurrAnimatorState) { case 0: resetDrawPath(); mPathMeasure.setPath(mPath, false); float stop = mPathMeasure.getLength() * animatedValue; float start = 0; mPathMeasure.getSegment(start, stop, mDrawPath, true); break; case 1: resetDrawPath(); mPathMeasure.setPath(mPath, false); stop = mPathMeasure.getLength(); start = mPathMeasure.getLength() * animatedValue; mPathMeasure.getSegment(start, stop, mDrawPath, true); break; default: break; } }
Example #3
Source File: AppStoreStyleProgressProvider.java From UILibrary with MIT License | 6 votes |
@Override protected void drawProgress(Canvas canvas, @FloatRange(from=0.0F, to=1.0F) float progress){ path.reset(); //add outer rect path.addRect(mOuterBound, Path.Direction.CCW); //punch a hole path.addCircle(mCenterX, mCenterY, mRadius, Path.Direction.CW); canvas.drawPath(path, mPaint); if(progress >= 0){ float angle = (1.0F - progress) * 360; float startAngle = -90 + (360 - angle); canvas.drawArc(mOval, startAngle, angle, true, mPaint); } }
Example #4
Source File: ColorUtils.java From Protein with Apache License 2.0 | 6 votes |
/** * Calculate a variant of the color to make it more suitable for overlaying information. Light * colors will be lightened and dark colors will be darkened * * @param color the color to adjust * @param isDark whether {@code color} is light or dark * @param lightnessMultiplier the amount to modify the color e.g. 0.1f will alter it by 10% * @return the adjusted color */ public static @ColorInt int scrimify(@ColorInt int color, boolean isDark, @FloatRange(from = 0f, to = 1f) float lightnessMultiplier) { float[] hsl = new float[3]; android.support.v4.graphics.ColorUtils.colorToHSL(color, hsl); if (!isDark) { lightnessMultiplier += 1f; } else { lightnessMultiplier = 1f - lightnessMultiplier; } hsl[2] = MathUtils.constrain(0f, 1f, hsl[2] * lightnessMultiplier); return android.support.v4.graphics.ColorUtils.HSLToColor(hsl); }
Example #5
Source File: ColorUtils.java From Android-utils with Apache License 2.0 | 6 votes |
/** * 根据比例,在两个 color 值之间计算出一个 color 值 * <b>注意该方法是 ARGB 通道分开计算比例的</b> * * @param fromColor 开始的 color 值 * @param toColor 最终的 color 值 * @param fraction 比例,取值为 [0,1],为 0 时返回 fromColor, 为 1 时返回 toColor * @return 计算出的 color 值 */ public static int computeColor(@ColorInt int fromColor, @ColorInt int toColor, @FloatRange(from = 0, to = 1) float fraction) { fraction = Math.max(Math.min(fraction, 1), 0); int minColorA = Color.alpha(fromColor); int maxColorA = Color.alpha(toColor); int resultA = (int) ((maxColorA - minColorA) * fraction) + minColorA; int minColorR = Color.red(fromColor); int maxColorR = Color.red(toColor); int resultR = (int) ((maxColorR - minColorR) * fraction) + minColorR; int minColorG = Color.green(fromColor); int maxColorG = Color.green(toColor); int resultG = (int) ((maxColorG - minColorG) * fraction) + minColorG; int minColorB = Color.blue(fromColor); int maxColorB = Color.blue(toColor); int resultB = (int) ((maxColorB - minColorB) * fraction) + minColorB; return Color.argb(resultA, resultR, resultG, resultB); }
Example #6
Source File: StatusBarUtil.java From Awesome-WanAndroid with Apache License 2.0 | 6 votes |
public static void immersive(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { if (Build.VERSION.SDK_INT >= 21) { window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(mixtureColor(color, alpha)); window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); } else if (Build.VERSION.SDK_INT >= 19) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); setTranslucentView((ViewGroup) window.getDecorView(), color, alpha); } else if (Build.VERSION.SDK_INT >= MIN_API && Build.VERSION.SDK_INT > 16) { int systemUiVisibility = window.getDecorView().getSystemUiVisibility(); systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE; window.getDecorView().setSystemUiVisibility(systemUiVisibility); } }
Example #7
Source File: ColorUtils.java From materialup with Apache License 2.0 | 6 votes |
/** * Calculate a variant of the color to make it more suitable for overlaying information. Light * colors will be lightened and dark colors will be darkened * * @param color the color to adjust * @param isDark whether {@code color} is light or dark * @param lightnessMultiplier the amount to modify the color e.g. 0.1f will alter it by 10% * @return the adjusted color */ public static @ColorInt int scrimify(@ColorInt int color, boolean isDark, @FloatRange(from = 0f, to = 1f) float lightnessMultiplier) { float[] hsl = new float[3]; android.support.v4.graphics.ColorUtils.colorToHSL(color, hsl); if (!isDark) { lightnessMultiplier += 1f; } else { lightnessMultiplier = 1f - lightnessMultiplier; } hsl[2] = MathUtils.constrain(0f, 1f, hsl[2] * lightnessMultiplier); return android.support.v4.graphics.ColorUtils.HSLToColor(hsl); }
Example #8
Source File: Bubble.java From FireworkyPullToRefresh with MIT License | 6 votes |
@FloatRange(from = 0, to = 1) float getPercent() { if (mAlpha <= 0f && mDAlpha <= 0f) { return 1.f; } if (mRadius <= 0f && mDRadius <= 0f) { return 1.f; } float percent; if (mDAlpha >= 0f) { percent = mAlpha / 255.f; } else { percent = 1.f - mAlpha / mInitialState.mAlpha; } //noinspection StatementWithEmptyBody if (mDRadius >= 0f) { //incalculable, do nothing } else { percent = Math.max(1.f - mRadius / mInitialState.mRadius, percent); } return percent; }
Example #9
Source File: StatusBarUtil.java From Yuan-WanAndroid with Apache License 2.0 | 6 votes |
/** * 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */ public static void darkMode(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { if (isFlyme4Later()) { darkModeForFlyme4(window, true); immersive(window,color,alpha); } else if (isMIUI6Later()) { darkModeForMIUI6(window, true); immersive(window,color,alpha); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { darkModeForM(window, true); immersive(window, color, alpha); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); setTranslucentView((ViewGroup) window.getDecorView(), color, alpha); } else { immersive(window, color, alpha); } }
Example #10
Source File: StatusBarUtil.java From UGank with GNU General Public License v3.0 | 6 votes |
/** 设置状态栏darkMode,字体颜色及icon变黑(目前支持MIUI6以上,Flyme4以上,Android M以上) */ public static void darkMode(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { if (isFlyme4Later()) { immersive(window,color,alpha); darkModeForFlyme4(window, true); } else if (isMIUI6Later()) { immersive(window,color,alpha); darkModeForMIUI6(window, true); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { immersive(window, color, alpha); darkModeForM(window, true); } else if (Build.VERSION.SDK_INT >= 19) { window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); setTranslucentView((ViewGroup) window.getDecorView(), color, alpha); } // if (Build.VERSION.SDK_INT >= 21) { // window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // window.setStatusBarColor(Color.TRANSPARENT); // } else if (Build.VERSION.SDK_INT >= 19) { // window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // } // setTranslucentView((ViewGroup) window.getDecorView(), color, alpha); }
Example #11
Source File: AnimatorDurationScaler.java From AnimatorDurationTile with Apache License 2.0 | 5 votes |
static boolean setAnimatorScale( @NonNull Context context, @FloatRange(from = 0.0, to = 10.0) float scale) { try { Settings.Global.putFloat( context.getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE, scale); return true; } catch (SecurityException se) { String message = context.getString(R.string.permission_required_toast); Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_LONG).show(); Log.d(TAG, message); return false; } }
Example #12
Source File: ParallaxRatioImageView.java From Melophile with Apache License 2.0 | 5 votes |
public void setScrimAlpha(@FloatRange(from = 0f, to = 1f) float alpha) { if (scrimAlpha != alpha) { scrimAlpha = alpha; scrimPaint.setColor(PresentationUtils.modifyAlpha(scrimColor, scrimAlpha)); postInvalidateOnAnimation(); } }
Example #13
Source File: StatusBarUtil.java From Yuan-WanAndroid with Apache License 2.0 | 5 votes |
/** * 设置沉浸式状态栏 */ public static void immersive(Window window, int color, @FloatRange(from = 0.0, to = 1.0) float alpha) { if(Build.VERSION.SDK_INT < MIN_API) return; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setStatusColor(window, color, alpha); }else{ window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); setTranslucentView((ViewGroup)window.getDecorView(), color, alpha); } }
Example #14
Source File: ParallaxLinearLayout.java From material-intro-screen with MIT License | 5 votes |
@Override public void setOffset(@FloatRange(from = -1.0, to = 1.0) float offset) { for (int i = getChildCount() - 1; i >= 0; i--) { View child = getChildAt(i); ParallaxLinearLayout.LayoutParams p = (LayoutParams) child.getLayoutParams(); if (p.parallaxFactor == 0) continue; child.setTranslationX(getWidth() * -offset * p.parallaxFactor); } }
Example #15
Source File: Spans.java From spanner with Apache License 2.0 | 5 votes |
/** * @see android.text.style.ScaleXSpan#ScaleXSpan(float) */ public static Span scaleXSize(@FloatRange(from = 0.0) final float proportion) { return new Span(new SpanBuilder() { @Override public Object build() { return new ScaleXSpan(proportion); } }); }
Example #16
Source File: ColorUtils.java From letv with Apache License 2.0 | 5 votes |
public static void XYZToLAB(@FloatRange(from = 0.0d, to = 95.047d) double x, @FloatRange(from = 0.0d, to = 100.0d) double y, @FloatRange(from = 0.0d, to = 108.883d) double z, @NonNull double[] outLab) { if (outLab.length != 3) { throw new IllegalArgumentException("outLab must have a length of 3."); } x = pivotXyzComponent(x / XYZ_WHITE_REFERENCE_X); y = pivotXyzComponent(y / XYZ_WHITE_REFERENCE_Y); z = pivotXyzComponent(z / XYZ_WHITE_REFERENCE_Z); outLab[0] = Math.max(0.0d, (116.0d * y) - 16.0d); outLab[1] = 500.0d * (x - y); outLab[2] = 200.0d * (y - z); }
Example #17
Source File: ImmersionBar.java From MNImageBrowser with GNU General Public License v3.0 | 5 votes |
/** * 状态栏和导航栏颜色 * * @param barColor the bar color * @param barAlpha the bar alpha * @return the immersion bar */ public ImmersionBar barColorInt(@ColorInt int barColor, @FloatRange(from = 0f, to = 1f) float barAlpha) { mBarParams.statusBarColor = barColor; mBarParams.navigationBarColor = barColor; mBarParams.statusBarAlpha = barAlpha; mBarParams.navigationBarAlpha = barAlpha; return this; }
Example #18
Source File: ImmersionBar.java From PocketEOS-Android with GNU Lesser General Public License v3.0 | 5 votes |
/** * 状态栏和导航栏颜色 * * @param barColor the bar color * @param barColorTransform the bar color transform * @param barAlpha the bar alpha * @return the immersion bar */ public ImmersionBar barColorInt(@ColorInt int barColor, @ColorInt int barColorTransform, @FloatRange(from = 0f, to = 1f) float barAlpha) { mBarParams.statusBarColor = barColor; mBarParams.navigationBarColor = barColor; mBarParams.navigationBarColorTemp = mBarParams.navigationBarColor; mBarParams.statusBarColorTransform = barColorTransform; mBarParams.navigationBarColorTransform = barColorTransform; mBarParams.statusBarAlpha = barAlpha; mBarParams.navigationBarAlpha = barAlpha; return this; }
Example #19
Source File: SeparatorDecoration.java From fritz-examples with MIT License | 5 votes |
/** * Create a decoration that draws a line in the given color and width between the items in the view. * * @param context a context to access the resources. * @param color the color of the separator to draw. * @param heightDp the height of the separator in dp. */ public SeparatorDecoration(@NonNull Context context, @ColorInt int color, @FloatRange(from = 0, fromInclusive = false) float heightDp) { mPaint = new Paint(); mPaint.setColor(color); final float thickness = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, heightDp, context.getResources().getDisplayMetrics()); mPaint.setStrokeWidth(thickness); }
Example #20
Source File: OneDrawable.java From OneDrawable with Apache License 2.0 | 5 votes |
/** * 使用一个 Drawable 资源生成一个具有按下效果的 StateListDrawable * * @param context context * @param res drawable resource * @param mode mode for press * @param alpha value * @return a stateListDrawable */ private static Drawable createBgDrawable(@NonNull Context context, @DrawableRes int res, @PressedMode.Mode int mode, @FloatRange(from = 0.0f, to = 1.0f) float alpha) { Drawable normal = context.getResources().getDrawable(res); Drawable pressed = context.getResources().getDrawable(res); Drawable unable = context.getResources().getDrawable(res); pressed.mutate(); unable.mutate(); pressed = getPressedStateDrawable(context, mode, alpha, pressed); unable = getUnableStateDrawable(context, unable); return createStateListDrawable(normal, pressed, unable); }
Example #21
Source File: ColorUtils.java From letv with Apache License 2.0 | 5 votes |
public static void blendLAB(@NonNull double[] lab1, @NonNull double[] lab2, @FloatRange(from = 0.0d, to = 1.0d) double ratio, @NonNull double[] outResult) { if (outResult.length != 3) { throw new IllegalArgumentException("outResult must have a length of 3."); } double inverseRatio = 1.0d - ratio; outResult[0] = (lab1[0] * inverseRatio) + (lab2[0] * ratio); outResult[1] = (lab1[1] * inverseRatio) + (lab2[1] * ratio); outResult[2] = (lab1[2] * inverseRatio) + (lab2[2] * ratio); }
Example #22
Source File: TrackerSettings.java From android-location-tracker with MIT License | 5 votes |
/** * Set the distance between updates of the location * * @param metersBetweenUpdates the distance between the updates * @return the instance of TrackerSettings */ public TrackerSettings setMetersBetweenUpdates(@FloatRange(from = 1) float metersBetweenUpdates) { if (metersBetweenUpdates > 0) { mMetersBetweenUpdates = metersBetweenUpdates; } return this; }
Example #23
Source File: ViewUtils.java From android-proguards with Apache License 2.0 | 5 votes |
public static RippleDrawable createRipple(@ColorInt int color, @FloatRange(from = 0f, to = 1f) float alpha, boolean bounded) { color = ColorUtils.modifyAlpha(color, alpha); return new RippleDrawable(ColorStateList.valueOf(color), null, bounded ? new ColorDrawable(Color.WHITE) : null); }
Example #24
Source File: ImageUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
/** * Return the blur bitmap using render script. * * @param src The source of bitmap. * @param radius The radius(0...25). * @return the blur bitmap */ @RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public static Bitmap renderScriptBlur(final Bitmap src, @FloatRange( from = 0, to = 25, fromInclusive = false ) final float radius) { return renderScriptBlur(src, radius, false); }
Example #25
Source File: XStateButton.java From XFrame with Apache License 2.0 | 5 votes |
/******************** radius *******************************/ public void setRadius(@FloatRange(from = 0) float radius) { this.mRadius = radius; mNormalBackground.setCornerRadius(mRadius); mPressedBackground.setCornerRadius(mRadius); mUnableBackground.setCornerRadius(mRadius); }
Example #26
Source File: BaseLayer.java From atlas with Apache License 2.0 | 5 votes |
void setProgress(@FloatRange(from = 0f, to = 1f) float progress) { if (matteLayer != null) { matteLayer.setProgress(progress); } for (int i = 0; i < animations.size(); i++) { animations.get(i).setProgress(progress); } }
Example #27
Source File: ParallaxRelativeLayout.java From youqu_master with Apache License 2.0 | 5 votes |
@Override public void setOffset(@FloatRange(from = -1.0, to = 1.0) float offset) { for (int i = getChildCount() - 1; i >= 0; i--) { View child = getChildAt(i); ParallaxRelativeLayout.LayoutParams p = (LayoutParams) child.getLayoutParams(); if (p.parallaxFactor == 0) continue; child.setTranslationX(getWidth() * -offset * p.parallaxFactor); } }
Example #28
Source File: ExoVideoView.java From v9porn with MIT License | 5 votes |
private void updateVolume(@FloatRange(from = 0.0, to = 1.0) float volume) { Log.d("AAAAAAAAA", "::" + String.valueOf(volume)); if (stepVolume > 1) { stepVolume = 1; } else if (stepVolume < 0) { stepVolume = 0; } setVolume(stepVolume); if (videoControls != null) { videoControls.showVolumeLightView(stepVolume, ExoVideoControls.VOLUME_MODEL); } }
Example #29
Source File: SpanUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
/** * Set the span of shadow. * * @param radius The radius of shadow. * @param dx X-axis offset, in pixel. * @param dy Y-axis offset, in pixel. * @param shadowColor The color of shadow. * @return the single {@link SpanUtils} instance */ public SpanUtils setShadow(@FloatRange(from = 0, fromInclusive = false) final float radius, final float dx, final float dy, final int shadowColor) { this.shadowRadius = radius; this.shadowDx = dx; this.shadowDy = dy; this.shadowColor = shadowColor; return this; }
Example #30
Source File: Result.java From tenor-android-core with Apache License 2.0 | 4 votes |
/** * @return aspect ratio of this {@link Result} or the default 1080p aspect ratio, 1.7778f */ @FloatRange(from = 0.01f, to = 5.01f) public float getAspectRatio() { float ratio = FloatString.parse(aspectRatio, 1.7778f); return ratio >= 0.01f && ratio <= 5.01f ? ratio : 1.7778f; }