本文整理匯總了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;
}