Allow changing back gesture height [2/2]

Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
maxwen
2020-11-11 16:04:30 +01:00
committed by Joey
parent ee39140069
commit 86d9f8c549
4 changed files with 117 additions and 9 deletions

View File

@@ -248,4 +248,10 @@
<string name="increasing_ring_volume_option_title">Increasing ring volume</string>
<string name="increasing_ring_min_volume_title">Start volume</string>
<string name="increasing_ring_ramp_up_time_title">Ramp-up time</string>
<!-- Back gesture height -->
<string name="back_height_low_label">Full</string>
<string name="back_height_high_label">Bottom</string>
<string name="back_height_title">Back gesture height</string>
<string name="back_height_summary">Screen height valid for back gesture</string>
</resources>

View File

@@ -29,6 +29,15 @@
android:summary="@string/show_navbar_hint_summary"
android:defaultValue="true" />
<com.android.settings.widget.LabeledSeekBarPreference
android:key="gesture_back_height"
android:title="@string/back_height_title"
android:summary="@string/back_height_summary"
android:max="3"
android:selectable="true"
settings:textStart="@string/back_height_low_label"
settings:textEnd="@string/back_height_high_label"/>
<PreferenceCategory
android:persistent="false">

View File

@@ -19,6 +19,7 @@ package com.android.settings.gestures;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PixelFormat;
import android.graphics.Point;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -37,6 +38,7 @@ public class BackGestureIndicatorView extends LinearLayout {
private ImageView mRightIndicator;
private BackGestureIndicatorDrawable mLeftDrawable;
private BackGestureIndicatorDrawable mRightDrawable;
private int mHeightScale;
public BackGestureIndicatorView(Context context) {
super(context);
@@ -87,6 +89,10 @@ public class BackGestureIndicatorView extends LinearLayout {
indicator.setWidth(width);
}
public void setIndicatorHeightScale(int heightScale) {
mHeightScale = heightScale;
}
public WindowManager.LayoutParams getLayoutParams(
WindowManager.LayoutParams parentWindowAttributes) {
int copiedFlags = (parentWindowAttributes.flags
@@ -99,8 +105,33 @@ public class BackGestureIndicatorView extends LinearLayout {
| copiedFlags,
PixelFormat.TRANSLUCENT);
setCurrentGestureHeight(lp);
lp.setTitle("BackGestureIndicatorView");
lp.token = getContext().getActivityToken();
return lp;
}
private void setCurrentGestureHeight(WindowManager.LayoutParams lp) {
Point displaySize = new Point();
getContext().getDisplay().getRealSize(displaySize);
// mHeightScale cant be range 0 - 3
// 0 means full height
// 1 measns half of the screen
// 2 means lower third of the screen
// 3 means lower sicth of the screen
if (mHeightScale == 0) {
lp.height = displaySize.y;
lp.y = 0;
} else if (mHeightScale == 1) {
lp.height = displaySize.y / 2;
lp.y = displaySize.y - lp.height;
} else if (mHeightScale == 2) {
lp.height = displaySize.y / 3;
lp.y = displaySize.y - lp.height;
} else {
lp.height = displaySize.y / 6;
lp.y = displaySize.y - lp.height;
}
}
}

View File

@@ -17,6 +17,7 @@
package com.android.settings.gestures;
import android.app.settings.SettingsEnums;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -52,12 +53,18 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.putExtra("use_tutorial_menu", true);
private static final String GESTURE_BACK_HEIGHT_KEY = "gesture_back_height";
private WindowManager mWindowManager;
private BackGestureIndicatorView mIndicatorView;
private float[] mBackGestureInsetScales;
private float mDefaultBackGestureInset;
private float[] mBackGestureHeightScales = { 0f, 1f, 2f, 3f };
private int mCurrentRightWidth;
private int mCurrentLefttWidth;
public GestureNavigationSettingsFragment() {
super();
}
@@ -82,6 +89,7 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
initSeekBarPreference(LEFT_EDGE_SEEKBAR_KEY);
initSeekBarPreference(RIGHT_EDGE_SEEKBAR_KEY);
initSeekBarPreference(GESTURE_BACK_HEIGHT_KEY);
initTutorialButton();
}
@@ -146,11 +154,42 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
pref.setContinuousUpdates(true);
pref.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_TICKS);
final String settingsKey = key == LEFT_EDGE_SEEKBAR_KEY
? Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT
: Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT;
final float initScale = Settings.Secure.getFloat(
String settingsKey;
float initScale = 0;
switch(key) {
case LEFT_EDGE_SEEKBAR_KEY:
settingsKey = Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT;
break;
case RIGHT_EDGE_SEEKBAR_KEY:
settingsKey = Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT;
break;
case GESTURE_BACK_HEIGHT_KEY:
settingsKey = Settings.System.BACK_GESTURE_HEIGHT;
break;
default:
settingsKey = "";
break;
}
if (settingsKey != "") {
initScale = Settings.Secure.getFloat(
getContext().getContentResolver(), settingsKey, 1.0f);
}
// needed if we just change the height
float currentWidthScale = Settings.Secure.getFloat(
getContext().getContentResolver(), Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT, 1.0f);
mCurrentRightWidth = (int) (mDefaultBackGestureInset * currentWidthScale);
currentWidthScale = Settings.Secure.getFloat(
getContext().getContentResolver(), Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT, 1.0f);
mCurrentLefttWidth = (int) (mDefaultBackGestureInset * currentWidthScale);
if (key == GESTURE_BACK_HEIGHT_KEY) {
mBackGestureInsetScales = mBackGestureHeightScales;
initScale = Settings.System.getInt(
getContext().getContentResolver(), settingsKey, 0);
}
// Find the closest value to initScale
float minDistance = Float.MAX_VALUE;
@@ -165,15 +204,38 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
pref.setProgress(minDistanceIndex);
pref.setOnPreferenceChangeListener((p, v) -> {
if (key != GESTURE_BACK_HEIGHT_KEY) {
final int width = (int) (mDefaultBackGestureInset * mBackGestureInsetScales[(int) v]);
mIndicatorView.setIndicatorWidth(width, key == LEFT_EDGE_SEEKBAR_KEY);
if (key == LEFT_EDGE_SEEKBAR_KEY) {
mCurrentLefttWidth = width;
} else {
mCurrentRightWidth = width;
}
} else {
final int heightScale = (int) (mBackGestureInsetScales[(int) v]);
mIndicatorView.setIndicatorHeightScale(heightScale);
// dont use updateViewLayout else it will animate
mWindowManager.removeView(mIndicatorView);
mWindowManager.addView(mIndicatorView, mIndicatorView.getLayoutParams(
getActivity().getWindow().getAttributes()));
// peek the indicators
mIndicatorView.setIndicatorWidth(mCurrentRightWidth, false);
mIndicatorView.setIndicatorWidth(mCurrentLefttWidth, true);
}
return true;
});
pref.setOnPreferenceChangeStopListener((p, v) -> {
mIndicatorView.setIndicatorWidth(0, key == LEFT_EDGE_SEEKBAR_KEY);
final float scale = mBackGestureInsetScales[(int) v];
if (key == GESTURE_BACK_HEIGHT_KEY) {
mIndicatorView.setIndicatorWidth(0, false);
mIndicatorView.setIndicatorWidth(0, true);
Settings.System.putInt(getContext().getContentResolver(), settingsKey, (int) scale);
} else {
mIndicatorView.setIndicatorWidth(0, key == LEFT_EDGE_SEEKBAR_KEY);
Settings.Secure.putFloat(getContext().getContentResolver(), settingsKey, scale);
}
return true;
});
}