本文整理汇总了Java中android.support.annotation.FloatRange类的典型用法代码示例。如果您正苦于以下问题:Java FloatRange类的具体用法?Java FloatRange怎么用?Java FloatRange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FloatRange类属于android.support.annotation包,在下文中一共展示了FloatRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: immersiveStatusBar
import android.support.annotation.FloatRange; //导入依赖的package包/类
public static void immersiveStatusBar(Window window, @FloatRange(from = 0.0d, to = 1.0d)
float alpha) {
if (VERSION.SDK_INT >= 19) {
if (VERSION.SDK_INT >= 21) {
window.clearFlags(67108864);
window.addFlags(Integer.MIN_VALUE);
window.setStatusBarColor(0);
window.getDecorView().setSystemUiVisibility((window.getDecorView()
.getSystemUiVisibility() | 1024) | 256);
} else {
window.addFlags(67108864);
}
ViewGroup decorView = (ViewGroup) window.getDecorView();
View rootView = ((ViewGroup) window.getDecorView().findViewById(16908290)).getChildAt
(0);
int statusBarHeight = getStatusBarHeight(window.getContext());
if (rootView != null) {
LayoutParams lp = (LayoutParams) rootView.getLayoutParams();
ViewCompat.setFitsSystemWindows(rootView, true);
lp.topMargin = -statusBarHeight;
rootView.setLayoutParams(lp);
}
setTranslucentView(decorView, alpha);
}
}
示例2: LABToXYZ
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* Converts a color from CIE Lab to CIE XYZ representation.
*
* <p>The resulting XYZ representation will use the D65 illuminant and the CIE
* 2° Standard Observer (1931).</p>
*
* <ul>
* <li>outXyz[0] is X [0 ...95.047)</li>
* <li>outXyz[1] is Y [0...100)</li>
* <li>outXyz[2] is Z [0...108.883)</li>
* </ul>
*
* @param l L component value [0...100)
* @param a A component value [-128...127)
* @param b B component value [-128...127)
* @param outXyz 3-element array which holds the resulting XYZ components
*/
public static void LABToXYZ(@FloatRange(from = 0f, to = 100) final double l,
@FloatRange(from = -128, to = 127) final double a,
@FloatRange(from = -128, to = 127) final double b,
@NonNull double[] outXyz) {
final double fy = (l + 16) / 116;
final double fx = a / 500 + fy;
final double fz = fy - b / 200;
double tmp = Math.pow(fx, 3);
final double xr = tmp > XYZ_EPSILON ? tmp : (116 * fx - 16) / XYZ_KAPPA;
final double yr = l > XYZ_KAPPA * XYZ_EPSILON ? Math.pow(fy, 3) : l / XYZ_KAPPA;
tmp = Math.pow(fz, 3);
final double zr = tmp > XYZ_EPSILON ? tmp : (116 * fz - 16) / XYZ_KAPPA;
outXyz[0] = xr * XYZ_WHITE_REFERENCE_X;
outXyz[1] = yr * XYZ_WHITE_REFERENCE_Y;
outXyz[2] = zr * XYZ_WHITE_REFERENCE_Z;
}
示例3: scrimify
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* 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] = constrain(0f, 1f, hsl[2] * lightnessMultiplier);
return android.support.v4.graphics.ColorUtils.HSLToColor(hsl);
}
示例4: createCircleGradientDrawable
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* 创建一张渐变图片,支持圆角
*
* @param startColor 渐变开始色
* @param endColor 渐变结束色
* @param radius 圆角大小
* @param centerX 渐变中心点 X 轴坐标
* @param centerY 渐变中心点 Y 轴坐标
* @return
*/
@TargetApi(16)
public static GradientDrawable createCircleGradientDrawable(@ColorInt int startColor,
@ColorInt int endColor, int radius,
@FloatRange(from = 0f, to = 1f) float centerX,
@FloatRange(from = 0f, to = 1f) float centerY) {
GradientDrawable gradientDrawable = new GradientDrawable();
gradientDrawable.setColors(new int[]{
startColor,
endColor
});
gradientDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
gradientDrawable.setGradientRadius(radius);
gradientDrawable.setGradientCenter(centerX, centerY);
return gradientDrawable;
}
示例5: tintStatusBar
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* 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);
}
示例6: tintStatusBarForDrawer
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* Android4.4以上的状态栏着色(针对于DrawerLayout)
* 注:
* 1.如果出现界面展示不正确,删除布局中所有fitsSystemWindows属性,尤其是DrawerLayout的fitsSystemWindows属性
* 2.可以版本判断在5.0以上不调用该方法,使用系统自带
*
* @param activity Activity对象
* @param drawerLayout DrawerLayout对象
* @param statusBarColor 状态栏颜色
* @param alpha 透明栏透明度[0.0-1.0]
*/
public static void tintStatusBarForDrawer(Activity activity, DrawerLayout drawerLayout,
@ColorInt int statusBarColor,
@FloatRange(from = 0.0, to = 1.0) float alpha) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return;
}
Window window = activity.getWindow();
ViewGroup decorView = (ViewGroup) window.getDecorView();
ViewGroup drawContent = (ViewGroup) drawerLayout.getChildAt(0);
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);
drawerLayout.setStatusBarBackgroundColor(statusBarColor);
int systemUiVisibility = window.getDecorView().getSystemUiVisibility();
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
systemUiVisibility |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
window.getDecorView().setSystemUiVisibility(systemUiVisibility);
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
setStatusBar(decorView, statusBarColor, true, true);
setTranslucentView(decorView, alpha);
drawerLayout.setFitsSystemWindows(false);
drawContent.setFitsSystemWindows(true);
ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
drawer.setFitsSystemWindows(false);
}
示例7: getDarkerColor
import android.support.annotation.FloatRange; //导入依赖的package包/类
@ColorInt
public static int getDarkerColor(@ColorInt int color, @FloatRange(from = 0.0D, to = 1.0D) float transparency) {
float[] hsv = new float[3];
Color.colorToHSV(color, hsv);
hsv[2] *= transparency;
return Color.HSVToColor(hsv);
}
示例8: fastBlur
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* 快速模糊图片
* <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
*
* @param src 源图片
* @param scale 缩放比例(0...1)
* @param radius 模糊半径(0...25)
* @param recycle 是否回收
* @return 模糊后的图片
*/
public static Bitmap fastBlur(Bitmap src, @FloatRange(from = 0, to = 1, fromInclusive = false) float scale, @FloatRange(from = 0, to = 25, fromInclusive = false) float radius, boolean recycle) {
if (isEmptyBitmap(src)) {
return null;
}
int width = src.getWidth();
int height = src.getHeight();
int scaleWidth = (int) (width * scale + 0.5f);
int scaleHeight = (int) (height * scale + 0.5f);
if (scaleWidth == 0 || scaleHeight == 0) {
return null;
}
Bitmap scaleBitmap = Bitmap
.createScaledBitmap(src, scaleWidth, scaleHeight, true);
Paint paint = new Paint(
Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
Canvas canvas = new Canvas();
PorterDuffColorFilter filter = new PorterDuffColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
paint.setColorFilter(filter);
canvas.scale(scale, scale);
canvas.drawBitmap(scaleBitmap, 0, 0, paint);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
scaleBitmap = renderScriptBlur(ContextUtils
.getContext(), scaleBitmap, radius);
} else {
scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
}
if (scale == 1) {
return scaleBitmap;
}
Bitmap ret = Bitmap
.createScaledBitmap(scaleBitmap, width, height, true);
if (scaleBitmap != null && !scaleBitmap.isRecycled()) {
scaleBitmap.recycle();
}
if (recycle && !src.isRecycled()) {
src.recycle();
}
return ret;
}
示例9: BlurTransformation
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
*
* @param context Context
* @param radius The blur's radius.
* @param color The color filter for blurring.
*/
public BlurTransformation(Context context, @FloatRange(from = 0.0f) float radius, int color) {
super(context);
mContext = context;
if (radius > MAX_RADIUS) {
mSampling = radius / 25.0f;
mRadius = MAX_RADIUS;
} else {
mRadius = radius;
}
mColor = color;
}
示例10: setLineDistance
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void setLineDistance(@FloatRange(from = 0) final float lineDistance) {
if (lineDistance < 0) {
throw new IllegalArgumentException("line distance must not be negative");
}
if (Float.compare(lineDistance, Float.NaN) == 0) {
throw new IllegalArgumentException("line distance must be a valid float");
}
mLineDistance = lineDistance;
}
示例11: setColorAlpha
import android.support.annotation.FloatRange; //导入依赖的package包/类
@ColorInt
public static int setColorAlpha(@ColorInt int color, @FloatRange(from = 0.0D, to = 1.0D) float alpha) {
int alpha2 = Math.round((float) Color.alpha(color) * alpha);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha2, red, green, blue);
}
示例12: createRipple
import android.support.annotation.FloatRange; //导入依赖的package包/类
public static RippleDrawable createRipple(@NonNull Palette palette,
@FloatRange(from = 0f, to = 1f) float darkAlpha,
@FloatRange(from = 0f, to = 1f) float lightAlpha,
@ColorInt int fallbackColor,
boolean bounded) {
int rippleColor = fallbackColor;
if (palette != null) {
// try the named swatches in preference order
if (palette.getVibrantSwatch() != null) {
rippleColor =
ColorUtils.modifyAlpha(palette.getVibrantSwatch().getRgb(), darkAlpha);
} else if (palette.getLightVibrantSwatch() != null) {
rippleColor = ColorUtils.modifyAlpha(palette.getLightVibrantSwatch().getRgb(),
lightAlpha);
} else if (palette.getDarkVibrantSwatch() != null) {
rippleColor = ColorUtils.modifyAlpha(palette.getDarkVibrantSwatch().getRgb(),
darkAlpha);
} else if (palette.getMutedSwatch() != null) {
rippleColor = ColorUtils.modifyAlpha(palette.getMutedSwatch().getRgb(), darkAlpha);
} else if (palette.getLightMutedSwatch() != null) {
rippleColor = ColorUtils.modifyAlpha(palette.getLightMutedSwatch().getRgb(),
lightAlpha);
} else if (palette.getDarkMutedSwatch() != null) {
rippleColor =
ColorUtils.modifyAlpha(palette.getDarkMutedSwatch().getRgb(), darkAlpha);
}
}
return new RippleDrawable(ColorStateList.valueOf(rippleColor), null,
bounded ? new ColorDrawable(Color.WHITE) : null);
}
示例13: LABToXYZ
import android.support.annotation.FloatRange; //导入依赖的package包/类
public static void LABToXYZ(@FloatRange(from = 0.0d, to = 100.0d) double l, @FloatRange(from = -128.0d, to = 127.0d) double a, @FloatRange(from = -128.0d, to = 127.0d) double b, @NonNull double[] outXyz) {
double fy = (16.0d + l) / 116.0d;
double fx = (a / 500.0d) + fy;
double fz = fy - (b / 200.0d);
double tmp = Math.pow(fx, 3.0d);
double xr = tmp > XYZ_EPSILON ? tmp : ((116.0d * fx) - 16.0d) / XYZ_KAPPA;
double yr = l > 7.9996247999999985d ? Math.pow(fy, 3.0d) : l / XYZ_KAPPA;
tmp = Math.pow(fz, 3.0d);
double zr = tmp > XYZ_EPSILON ? tmp : ((116.0d * fz) - 16.0d) / XYZ_KAPPA;
outXyz[0] = XYZ_WHITE_REFERENCE_X * xr;
outXyz[1] = XYZ_WHITE_REFERENCE_Y * yr;
outXyz[2] = XYZ_WHITE_REFERENCE_Z * zr;
}
示例14: setShadow
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* 设置阴影
*
* @param radius 阴影半径
* @param dx x轴偏移量
* @param dy y轴偏移量
* @param shadowColor 阴影颜色
* @return {@link SpanUtils}
*/
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;
}
示例15: setWeightWidth
import android.support.annotation.FloatRange; //导入依赖的package包/类
/**
* 设置view的权重,总权重数为1 ,weightWidth范围(0.0f-1.0f)
* */
public void setWeightWidth(@FloatRange(from = 0, to = 1)float weightWidth) {
if(weightWidth<0){
weightWidth = 0;
}
if(!TextUtils.isEmpty(label)){
if(weightWidth>=1){
weightWidth = 0.5f;
}
}
this.weightWidth = weightWidth;
}