Java Code Examples for androidx.annotation.FloatRange

The following examples show how to use androidx.annotation.FloatRange. These examples are extracted from open source projects. 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 Project: monero-wallet-android-app   Author: WooKeyWallet   File: DrawableHelper.java    License: MIT License 6 votes vote down vote up
/**
 * 创建一张渐变图片,支持韵脚。
 *
 * @param startColor 渐变开始色
 * @param endColor   渐变结束色
 * @param radius     圆角大小
 * @param centerX    渐变中心点 X 轴坐标
 * @param centerY    渐变中心点 Y 轴坐标
 * @return 返回所创建的渐变图片。
 */
@TargetApi(16)
public static GradientDrawable getCircleGradientDrawable(@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;
}
 
Example #2
Source Project: ARVI   Author: arthur3486   File: ExoPlayerUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Calculates the amount of the visibility of the {@link com.google.android.exoplayer2.ui.PlayerView}
 * on the screen.
 * Used to determine the visibility area ratio (a value between 0.0 and 1.0), so that further
 * playback management related actions can be taken by the host {@link com.arthurivanets.arvi.widget.PlayableItemsContainer}.
 *
 * @param playable the playable
 * @return the visibility are offset (a value between 0.0 and 1.0)
 */
@FloatRange(from = 0.0, to = 1.0)
public static float getVisibleAreaOffset(@NonNull Playable playable) {
    Preconditions.nonNull(playable);

    if(playable.getParent() == null) {
        return 0f;
    }

    final View playerView = playable.getPlayerView();

    final Rect drawRect = new Rect();
    final Rect playerRect = new Rect();

    playerView.getDrawingRect(drawRect);

    final int drawArea = (drawRect.width() * drawRect.height());
    final boolean isVisible = playerView.getGlobalVisibleRect(playerRect, new Point());

    if(isVisible && (drawArea > 0)) {
        final int visibleArea = (playerRect.height() * playerRect.width());
        return (visibleArea / (float) drawArea);
    }

    return 0f;
}
 
Example #3
Source Project: Android-BLE-Common-Library   Author: NordicSemiconductor   File: CGMSpecificOpsControlPointData.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static Data setCalibrationValue(@FloatRange(from = 0) final float glucoseConcentrationOfCalibration,
									   @GlucoseSampleType final int sampleType,
									   @GlucoseSampleLocation final int sampleLocation,
									   @IntRange(from = 0, to = 65535) final int calibrationTime,
									   @IntRange(from = 0, to = 65535) final int nextCalibrationTime,
									   final boolean secure) {
	final MutableData data = new MutableData(new byte[11 + (secure ? 2 : 0)]);
	data.setByte(OP_CODE_SET_CALIBRATION_VALUE, 0);
	data.setValue(glucoseConcentrationOfCalibration, Data.FORMAT_SFLOAT, 1);
	data.setValue(calibrationTime, Data.FORMAT_UINT16, 3);
	final int typeAndSampleLocation = ((sampleLocation & 0xF) << 8) | (sampleType & 0xF);
	data.setValue(typeAndSampleLocation, Data.FORMAT_UINT8, 5);
	data.setValue(nextCalibrationTime, Data.FORMAT_UINT16, 6);
	data.setValue(0, Data.FORMAT_UINT16, 8); // ignored: calibration data record number
	data.setValue(0, Data.FORMAT_UINT8, 10); // ignored: calibration status
	return appendCrc(data, secure);
}
 
Example #4
Source Project: weather   Author: bkhezry   File: AppUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the alpha component of {@code color} to be {@code alpha}.
 */
public static @CheckResult
@ColorInt
int modifyAlpha(@ColorInt int color,
                @FloatRange(from = 0f, to = 1f) float alpha) {
  return modifyAlpha(color, (int) (255f * alpha));
}
 
Example #5
Source Project: DiscreteSlider   Author: hearsilent   File: DiscreteSlider.java    License: MIT License 5 votes vote down vote up
public void setTrackWidth(@FloatRange(from = Float.MIN_VALUE) float trackWidth) {
	if (trackWidth <= 0) {
		throw new IllegalArgumentException("Track width must be a positive number.");
	}
	mTrackWidth = trackWidth;
	generateInactiveTrackPath();
	invalidate();
}
 
Example #6
Source Project: DiscreteSlider   Author: hearsilent   File: DiscreteSlider.java    License: MIT License 5 votes vote down vote up
public void setThumbRadius(@FloatRange(from = Float.MIN_VALUE) float radius) {
	if (radius <= 0) {
		throw new IllegalArgumentException("Thumb radius must be a positive number.");
	}
	mRadius = radius;
	generateInactiveTrackPath();
	invalidate();
}
 
Example #7
Source Project: WanAndroid   Author: rain9155   File: StatusBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * 设置状态栏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);
        }
//        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 #8
Source Project: LiTr   Author: linkedin   File: TransformationEvent.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public TransformationEvent(@NonNull String id,
                           @EventType int type,
                           @FloatRange(from = 0, to = 1) float progress,
                           @Nullable Throwable cause) {
    this.id = id;
    this.type = type;
    this.progress = progress;
    this.cause = cause;
}
 
Example #9
Source Project: bcm-android   Author: bcmapp   File: StateButton.java    License: GNU General Public License v3.0 5 votes vote down vote up
/********************   radius  *******************************/

    public void setRadius(@FloatRange(from = 0) float radius) {
        this.mRadius = radius;
        mNormalBackground.setCornerRadius(mRadius);
        mPressedBackground.setCornerRadius(mRadius);
        mUnableBackground.setCornerRadius(mRadius);
    }
 
Example #10
Source Project: a   Author: 804463258   File: ColorUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ColorInt
public static int shiftColor(@ColorInt int color, @FloatRange(from = 0.0f, to = 2.0f) float by) {
    if (by == 1f) return color;
    int alpha = Color.alpha(color);
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= by; // value component
    return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
}
 
Example #11
Source Project: a   Author: 804463258   File: ColorUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ColorInt
public static int adjustAlpha(@ColorInt int color, @FloatRange(from = 0.0, to = 1.0) float factor) {
    int alpha = Math.round(Color.alpha(color) * factor);
    int red = Color.red(color);
    int green = Color.green(color);
    int blue = Color.blue(color);
    return Color.argb(alpha, red, green, blue);
}
 
Example #12
Source Project: a   Author: 804463258   File: ImmersionBar.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 导航栏颜色
 *
 * @param navigationBarColor the navigation bar color 导航栏颜色
 * @param navigationAlpha    the navigation alpha 透明度
 * @return the immersion bar
 */
public ImmersionBar navigationBarColorInt(@ColorInt int navigationBarColor,
                                          @FloatRange(from = 0f, to = 1f) float navigationAlpha) {
    mBarParams.navigationBarColor = navigationBarColor;
    mBarParams.navigationBarAlpha = navigationAlpha;
    mBarParams.navigationBarColorTemp = mBarParams.navigationBarColor;
    return this;
}
 
Example #13
Source Project: persistentsearchview   Author: mars885   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adjusts the alpha channel of the specified color.
 *
 * @param color The color to adjust alpha of
 * @param alpha The alpha value
 *
 * @return The color with the adjusted alpha channel
 */
public static int adjustColorAlpha(int color, @FloatRange(from = 0.0, to = 1.0) float alpha) {
    final int alphaChannel = (int) (255 * alpha);
    final int redChannel = Color.red(color);
    final int greenChannel = Color.green(color);
    final int blueChannel = Color.blue(color);

    return Color.argb(alphaChannel, redChannel, greenChannel, blueChannel);
}
 
Example #14
Source Project: a   Author: 804463258   File: ImmersionBar.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 状态栏和导航栏颜色
 *
 * @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.navigationBarColorTemp = mBarParams.navigationBarColor;
    mBarParams.statusBarAlpha = barAlpha;
    mBarParams.navigationBarAlpha = barAlpha;
    return this;
}
 
Example #15
Source Project: MyBookshelf   Author: gedoor   File: ImmersionBar.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 解决布局与状态栏重叠问题,支持侧滑返回
 * Fits system windows immersion bar.
 *
 * @param fits                               the fits
 * @param statusBarColorContentView          the status bar color content view 状态栏颜色
 * @param statusBarColorContentViewTransform the status bar color content view transform  状态栏变色后的颜色
 * @param statusBarContentViewAlpha          the status bar content view alpha  透明度
 * @return the immersion bar
 */
public ImmersionBar fitsSystemWindows(boolean fits, @ColorRes int statusBarColorContentView
        , @ColorRes int statusBarColorContentViewTransform, @FloatRange(from = 0f, to = 1f) float statusBarContentViewAlpha) {
    mBarParams.fits = fits;
    mBarParams.statusBarColorContentView = ContextCompat.getColor(mActivity, statusBarColorContentView);
    mBarParams.statusBarColorContentViewTransform = ContextCompat.getColor(mActivity, statusBarColorContentViewTransform);
    mBarParams.statusBarContentViewAlpha = statusBarContentViewAlpha;
    mBarParams.statusBarColorContentView = ContextCompat.getColor(mActivity, statusBarColorContentView);
    mContentView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColorContentView,
            mBarParams.statusBarColorContentViewTransform, mBarParams.statusBarContentViewAlpha));
    return this;
}
 
Example #16
Source Project: a   Author: 804463258   File: ImmersionBar.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 导航栏字体深色或亮色,判断设备支不支持状态栏变色来设置状态栏透明度
 * Status bar dark font immersion bar.
 *
 * @param isDarkFont  the is dark font
 * @param statusAlpha the status alpha 如果不支持状态栏字体变色可以使用statusAlpha来指定状态栏透明度,比如白色状态栏的时候可以用到
 * @return the immersion bar
 */
public ImmersionBar navigationBarDarkFont(boolean isDarkFont, @FloatRange(from = 0f, to = 1f) float statusAlpha) {
    mBarParams.navigationBarDarkFont = isDarkFont;
    if (canNavigationBarDarkFont()) {
        mBarParams.navigationBarAlpha = 0;
    } else {
        mBarParams.navigationBarAlpha = statusAlpha;
    }
    return this;
}
 
Example #17
Source Project: PercentageChartView   Author: RamiJ3mli   File: PercentageChartView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets a new progress value. Passing true in animate will cause an animated progress update.
 *
 * @param progress New progress float value to set.
 * @param animate  Animation boolean value to set whether to animate progress change or not.
 * @throws IllegalArgumentException if the given progress is negative, or, less or equal to 100.
 */
public void setProgress(@FloatRange(from = 0f, to = 100f) float progress, boolean animate) {
    if (progress < 0 || progress > 100) {
        throw new IllegalArgumentException("Progress value must be positive and less or equal to 100.");
    }

    renderer.setProgress(progress, animate);
}
 
Example #18
Source Project: PercentageChartView   Author: RamiJ3mli   File: PercentageChartView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the background bar thickness in pixels. Works only if chart mode is set to ring.
 *
 * @param thickness non-negative thickness value in pixels.
 * @throws IllegalArgumentException if the given value is negative, or, background bar thickness is not supported by the current used chart mode.
 */
public PercentageChartView backgroundBarThickness(@FloatRange(from = 0) float thickness) {
    if (thickness < 0) {
        throw new IllegalArgumentException("Background bar thickness must be a positive value.");
    }

    try {
        ((RingModeRenderer) renderer).setBackgroundBarThickness(thickness);
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Background bar thickness is not support by the used percentage chart mode.");
    }
    return this;
}
 
Example #19
Source Project: PercentageChartView   Author: RamiJ3mli   File: PercentageChartView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Sets the progress bar thickness in pixels. Works only if chart mode is set to ring.
 *
 * @param thickness non-negative thickness value in pixels.
 * @throws IllegalArgumentException if the given value is negative, or, progress bar thickness is not supported by the current used chart mode.
 */
public PercentageChartView progressBarThickness(@FloatRange(from = 0) float thickness) {
    if (thickness < 0) {
        throw new IllegalArgumentException("Progress bar thickness must be a positive value.");
    }

    try {
        ((RingModeRenderer) renderer).setProgressBarThickness(thickness);
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Progress bar thickness is not support by the used percentage chart mode.");
    }
    return this;
}
 
Example #20
Source Project: DevUtils   Author: afkT   File: ViewUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置 View 透明度
 * @param view  View
 * @param alpha 透明度
 * @return {@link View}
 */
public static View setAlpha(final View view, @FloatRange(from = 0.0, to = 1.0) final float alpha) {
    if (view != null) {
        view.setAlpha(alpha);
    }
    return view;
}
 
Example #21
Source Project: WanAndroid   Author: rain9155   File: StatusBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 为活动中的Fragment的设置沉浸式状态栏
 */
public static void immersiveInFragments(Activity activity, 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) {
        activity.getWindow().setStatusBarColor(color);
        activity.getWindow().getDecorView()
                .setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    } else{
        activity.getWindow()
                .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        setTranslucentView((ViewGroup)activity.getWindow().getDecorView(), color, alpha);
    }
}
 
Example #22
Source Project: LottieBottomNav   Author: wwdablu   File: MenuItemBuilder.java    License: MIT License 5 votes vote down vote up
public MenuItemBuilder pausedProgress(@FloatRange(from = 0, to = 1) float progress) {

        if (progress <= 0) progress = 0;
        else if (progress >= 1) progress = 1;

        menuItem.lottieProgress = progress;
        return this;
    }
 
Example #23
Source Project: ARVI   Author: arthur3486   File: AdapsterPlayableItemViewHolder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <br>
 *      Sets the audio volume to be used during the playback of the video associated with this {@link AdapsterPlayableItemViewHolder}.
 * <br>
 *      If the playback is the active state, then the volume will be adjusted directly on the corresponding {@link Player} instance.
 *
 * @param audioVolume the exact audio volume (a value between <strong>0.0</strong> and <strong>1.0</strong>).
 */
protected final void setVolume(@FloatRange(from = 0.0, to = 1.0) float audioVolume) {
    // creating/updating the corresponding Playback Info
    final PlaybackInfo playbackInfo = getPlaybackInfo();
    playbackInfo.getVolumeInfo().setVolume(audioVolume);

    setPlaybackInfo(playbackInfo);

    // updating the Player-related state (if necessary)
    final Player player = getPlayer();

    if(player != null) {
        player.getVolumeController().setVolume(audioVolume);
    }
}
 
Example #24
Source Project: ARVI   Author: arthur3486   File: AdapsterPlayableItemViewHolder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the audio volume that's associated with the current instance of the {@link AdapsterPlayableItemViewHolder}.
 *
 * @return an audio volume ratio (a value between <strong>0.0</strong> and <strong>1.0</strong>).
 */
@FloatRange(from = 0.0, to = 1.0)
protected final float getVolume() {
    final PlaybackInfo playbackInfo = getPlaybackInfo();
    final Player player = getPlayer();

    return ((player != null) ? player.getVolumeController().getVolume() : playbackInfo.getVolumeInfo().getVolume());
}
 
Example #25
Source Project: MyBookshelf   Author: gedoor   File: ImmersionBar.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 导航栏颜色
 *
 * @param navigationBarColor          the navigation bar color 导航栏颜色
 * @param navigationBarColorTransform the navigation bar color transform  导航栏变色后的颜色
 * @param navigationAlpha             the navigation alpha  透明度
 * @return the immersion bar
 */
public ImmersionBar navigationBarColorInt(@ColorInt int navigationBarColor,
                                          @ColorInt int navigationBarColorTransform,
                                          @FloatRange(from = 0f, to = 1f) float navigationAlpha) {
    mBarParams.navigationBarColor = navigationBarColor;
    mBarParams.navigationBarColorTransform = navigationBarColorTransform;
    mBarParams.navigationBarAlpha = navigationAlpha;
    mBarParams.navigationBarColorTemp = mBarParams.navigationBarColor;
    return this;
}
 
Example #26
Source Project: ARVI   Author: arthur3486   File: PlayableItemViewHolder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <br>
 *      Sets the audio volume to be used during the playback of the video associated with this {@link PlayableItemViewHolder}.
 * <br>
 *      If the playback is the active state, then the volume will be adjusted directly on the corresponding {@link Player} instance.
 *
 * @param audioVolume the exact audio volume (a value between <strong>0.0</strong> and <strong>1.0</strong>).
 */
protected final void setVolume(@FloatRange(from = 0.0, to = 1.0) float audioVolume) {
    // creating/updating the corresponding Playback Info
    final PlaybackInfo playbackInfo = getPlaybackInfo();
    playbackInfo.getVolumeInfo().setVolume(audioVolume);

    setPlaybackInfo(playbackInfo);

    // updating the Player-related state (if necessary)
    final Player player = getPlayer();

    if(player != null) {
        player.getVolumeController().setVolume(audioVolume);
    }
}
 
Example #27
Source Project: WanAndroid   Author: rain9155   File: StatusBarUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置沉浸式状态栏
 */
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 #28
Source Project: AndroidProject   Author: getActivity   File: BasePopupWindow.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置背景遮盖层的透明度
 */
public void setBackgroundDimAmount(@FloatRange(from = 0, to = 1) float dimAmount) {
    float alpha = 1 - dimAmount;
    if (isShowing()) {
        setActivityAlpha(alpha);
    }
    if (mPopupBackground == null && alpha != 1) {
        mPopupBackground = new PopupBackground();
        addOnShowListener(mPopupBackground);
        addOnDismissListener(mPopupBackground);
    }
    if (mPopupBackground != null) {
        mPopupBackground.setAlpha(alpha);
    }
}
 
Example #29
Source Project: AndroidProject   Author: getActivity   File: BasePopupWindow.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置背景遮盖层的透明度
 */
public B setBackgroundDimAmount(@FloatRange(from = 0, to = 1) float dimAmount) {
    mBackgroundDimAmount = dimAmount;
    if (isShowing()) {
        mPopupWindow.setBackgroundDimAmount(dimAmount);
    }
    return (B) this;
}
 
Example #30
Source Project: AndroidProject   Author: getActivity   File: BaseDialog.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 设置背景遮盖层的透明度(前提条件是背景遮盖层开关必须是为开启状态)
 */
public void setBackgroundDimAmount(@FloatRange(from = 0, to = 1) float dimAmount) {
    Window window = getWindow();
    if (window != null) {
        window.setDimAmount(dimAmount);
    }
}