Skip to content

Commit

Permalink
ViewConfiguration: add support for max/min fling velocity sysproperties
Browse files Browse the repository at this point in the history
Change-Id: Ia9ee8a5fdd5063691fc3cf08097f10f80306553e
Signed-off-by: Simao Gomes Viana <[email protected]>
Signed-off-by: saikiran2001 <[email protected]>
  • Loading branch information
Simao Gomes Viana authored and sagarrokade006 committed Oct 12, 2020
1 parent 9be309a commit c9a7618
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions core/java/android/view/ViewConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.os.Bundle;
import android.os.RemoteException;
import android.os.StrictMode;
import android.os.SystemProperties;
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
Expand Down Expand Up @@ -467,10 +468,49 @@ private ViewConfiguration(Context context) {

mDoubleTapTouchSlop = mTouchSlop;

mMinimumFlingVelocity = res.getDimensionPixelSize(
com.android.internal.R.dimen.config_viewMinFlingVelocity);
mMaximumFlingVelocity = res.getDimensionPixelSize(
com.android.internal.R.dimen.config_viewMaxFlingVelocity);
// Modification by xdevs23 for better responsiveness using
// system.prop
String minFlingVeloProp = "ro.min.fling_velocity", // Min fling prop
maxFlingVeloProp = "ro.max.fling_velocity"; // Max fling prop
// Get the properties
String minFlingVeloSysProp = SystemProperties.get(minFlingVeloProp),
maxFlingVeloSysProp = SystemProperties.get(maxFlingVeloProp);
boolean isMaxFlingVeloPredefined = false,
isMinFlingVeloPredefined = false;
int minFlingVeloTmp = 0,
maxFlingVeloTmp = 0;

// Check whether the property values are valid
if(minFlingVeloSysProp != null && (!minFlingVeloSysProp.isEmpty()) &&
isNumeric(minFlingVeloSysProp)) {
minFlingVeloTmp = Integer.parseInt(minFlingVeloSysProp);
isMinFlingVeloPredefined = true;
}

if(maxFlingVeloSysProp != null && (!maxFlingVeloSysProp.isEmpty()) &&
isNumeric(maxFlingVeloSysProp)) {
maxFlingVeloTmp = Integer.parseInt(maxFlingVeloSysProp);
isMaxFlingVeloPredefined = true;
}

// Use config values if no prop available or invalid
if(!isMinFlingVeloPredefined && minFlingVeloTmp == 0)
minFlingVeloTmp = res.getDimensionPixelSize(
com.android.internal.R.dimen.config_viewMinFlingVelocity);
if(!isMaxFlingVeloPredefined && maxFlingVeloTmp == 0)
maxFlingVeloTmp = res.getDimensionPixelSize(
com.android.internal.R.dimen.config_viewMaxFlingVelocity);

// Check again for availability, otherwise use default values
if(minFlingVeloTmp * maxFlingVeloTmp == 0) {
minFlingVeloTmp = MINIMUM_FLING_VELOCITY;
maxFlingVeloTmp = MAXIMUM_FLING_VELOCITY;
}

// Assign the final variables
mMinimumFlingVelocity = minFlingVeloTmp;
mMaximumFlingVelocity = maxFlingVeloTmp;

mGlobalActionsKeyTimeout = res.getInteger(
com.android.internal.R.integer.config_globalActionsKeyTimeout);

Expand All @@ -489,6 +529,18 @@ private ViewConfiguration(Context context) {
com.android.internal.R.integer.config_screenshotChordKeyTimeout);
}

/**
* @hide
*/
public static boolean isNumeric(String string) {
try {
Integer.parseInt(string);
} catch(NumberFormatException e) {
return false;
}
return true;
}

/**
* Returns a configuration for the specified visual {@link Context}. The configuration depends
* on various parameters of the {@link Context}, like the dimension of the display or the
Expand Down

0 comments on commit c9a7618

Please sign in to comment.