Merge "Expose calls to get the inset sensitivity for the calling user" into tm-qpr-dev

This commit is contained in:
Winson Chung
2023-02-17 19:44:51 +00:00
committed by Android (Google) Code Review

View File

@@ -56,6 +56,9 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
}
};
/**
* Registers the observer for all users.
*/
public void register() {
ContentResolver r = mContext.getContentResolver();
r.registerContentObserver(
@@ -73,7 +76,10 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
mOnPropertiesChangedListener);
}
public void registerForCurrentUser() {
/**
* Registers the observer for the calling user.
*/
public void registerForCallingUser() {
ContentResolver r = mContext.getContentResolver();
r.registerContentObserver(
Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT),
@@ -103,12 +109,46 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
}
}
/**
* Returns the left sensitivity for the current user. To be used in code that runs primarily
* in one user's process.
*/
public int getLeftSensitivity(Resources userRes) {
return getSensitivity(userRes, Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT);
final float scale = Settings.Secure.getFloatForUser(mContext.getContentResolver(),
Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT, 1.0f, UserHandle.USER_CURRENT);
return (int) (getUnscaledInset(userRes) * scale);
}
/**
* Returns the left sensitivity for the calling user. To be used in code that runs in a
* per-user process.
*/
@SuppressWarnings("NonUserGetterCalled")
public int getLeftSensitivityForCallingUser(Resources userRes) {
final float scale = Settings.Secure.getFloat(mContext.getContentResolver(),
Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT, 1.0f);
return (int) (getUnscaledInset(userRes) * scale);
}
/**
* Returns the right sensitivity for the current user. To be used in code that runs primarily
* in one user's process.
*/
public int getRightSensitivity(Resources userRes) {
return getSensitivity(userRes, Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT);
final float scale = Settings.Secure.getFloatForUser(mContext.getContentResolver(),
Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT, 1.0f, UserHandle.USER_CURRENT);
return (int) (getUnscaledInset(userRes) * scale);
}
/**
* Returns the right sensitivity for the calling user. To be used in code that runs in a
* per-user process.
*/
@SuppressWarnings("NonUserGetterCalled")
public int getRightSensitivityForCallingUser(Resources userRes) {
final float scale = Settings.Secure.getFloat(mContext.getContentResolver(),
Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT, 1.0f);
return (int) (getUnscaledInset(userRes) * scale);
}
public boolean areNavigationButtonForcedVisible() {
@@ -116,7 +156,7 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
Settings.Secure.USER_SETUP_COMPLETE, 0, UserHandle.USER_CURRENT) == 0;
}
private int getSensitivity(Resources userRes, String side) {
private float getUnscaledInset(Resources userRes) {
final DisplayMetrics dm = userRes.getDisplayMetrics();
final float defaultInset = userRes.getDimension(
com.android.internal.R.dimen.config_backGestureInset) / dm.density;
@@ -127,8 +167,6 @@ public class GestureNavigationSettingsObserver extends ContentObserver {
: defaultInset;
final float inset = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, backGestureInset,
dm);
final float scale = Settings.Secure.getFloatForUser(
mContext.getContentResolver(), side, 1.0f, UserHandle.USER_CURRENT);
return (int) (inset * scale);
return inset;
}
}