android.support.v4.math.MathUtils Java Examples

The following examples show how to use android.support.v4.math.MathUtils. 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: JoystickLeft.java    From android-port with GNU General Public License v3.0 6 votes vote down vote up
@Override protected void updateStick() {
    if (down) {
        // GamepadEmulator takes values on a scale [-1; 1] so convert our values
        float w = getWidth() / 3;
        float diffX = currentX - initialX;
        float diffY = currentY - initialY;

        float bias = 0.3f;

        if (Math.abs(diffX) > Math.abs(diffY)) {
            diffY = Math.signum(diffY) * (Math.max(0, Math.abs(diffY) - bias * Math.abs(diffX)));
        } else {
            diffX = Math.signum(diffX) * (Math.max(0, Math.abs(diffX) - bias * Math.abs(diffY)));
        }

        float dx = MathUtils.clamp(diffX / w + 0.2f * Math.signum(diffX), -1, 1);
        float dy = MathUtils.clamp(diffY / w + 0.2f * Math.signum(diffY), -1, 1);
        GamepadEmulator.updateStick(stickId, dx, dy);
    } else {
        GamepadEmulator.updateStick(stickId, 0, 0);
    }
}
 
Example #2
Source File: MyBottomBehavior.java    From OpenWeatherPlus-Android with Apache License 2.0 4 votes vote down vote up
public int clampViewPositionVertical(@NonNull View child, int top, int dy) {
    return MathUtils.clamp(top, MyBottomBehavior.this.getExpandedOffset(), MyBottomBehavior.this.hideable ? MyBottomBehavior.this.parentHeight : MyBottomBehavior.this.collapsedOffset);
}
 
Example #3
Source File: HeaderScrollingViewBehavior.java    From BehaviorDemo with Apache License 2.0 4 votes vote down vote up
final int getOverlapPixelsForOffset(final View header) {
    return mOverlayTop == 0 ? 0 : MathUtils.clamp(
            (int) (getOverlapRatioForOffset(header) * mOverlayTop), 0, mOverlayTop);
}
 
Example #4
Source File: AnchorSheetBehavior.java    From AnchorSheetBehavior with Apache License 2.0 4 votes vote down vote up
@Override
public int clampViewPositionVertical(View child, int top, int dy) {
    return MathUtils.clamp(top, mMinOffset, mHideable ? mParentHeight : mMaxOffset);
}
 
Example #5
Source File: ViewPagerBottomSheetBehavior.java    From ViewPagerBottomSheet with Apache License 2.0 4 votes vote down vote up
@Override
public int clampViewPositionVertical(View child, int top, int dy) {
    return MathUtils.clamp(top, mMinOffset, mHideable ? mParentHeight : mMaxOffset);
}