Allow changing back gesture height [2/2]
Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
@@ -248,4 +248,10 @@
|
|||||||
<string name="increasing_ring_volume_option_title">Increasing ring volume</string>
|
<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_min_volume_title">Start volume</string>
|
||||||
<string name="increasing_ring_ramp_up_time_title">Ramp-up time</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>
|
</resources>
|
||||||
|
|||||||
@@ -29,6 +29,15 @@
|
|||||||
android:summary="@string/show_navbar_hint_summary"
|
android:summary="@string/show_navbar_hint_summary"
|
||||||
android:defaultValue="true" />
|
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
|
<PreferenceCategory
|
||||||
android:persistent="false">
|
android:persistent="false">
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package com.android.settings.gestures;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
|
import android.graphics.Point;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -37,6 +38,7 @@ public class BackGestureIndicatorView extends LinearLayout {
|
|||||||
private ImageView mRightIndicator;
|
private ImageView mRightIndicator;
|
||||||
private BackGestureIndicatorDrawable mLeftDrawable;
|
private BackGestureIndicatorDrawable mLeftDrawable;
|
||||||
private BackGestureIndicatorDrawable mRightDrawable;
|
private BackGestureIndicatorDrawable mRightDrawable;
|
||||||
|
private int mHeightScale;
|
||||||
|
|
||||||
public BackGestureIndicatorView(Context context) {
|
public BackGestureIndicatorView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -87,6 +89,10 @@ public class BackGestureIndicatorView extends LinearLayout {
|
|||||||
indicator.setWidth(width);
|
indicator.setWidth(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIndicatorHeightScale(int heightScale) {
|
||||||
|
mHeightScale = heightScale;
|
||||||
|
}
|
||||||
|
|
||||||
public WindowManager.LayoutParams getLayoutParams(
|
public WindowManager.LayoutParams getLayoutParams(
|
||||||
WindowManager.LayoutParams parentWindowAttributes) {
|
WindowManager.LayoutParams parentWindowAttributes) {
|
||||||
int copiedFlags = (parentWindowAttributes.flags
|
int copiedFlags = (parentWindowAttributes.flags
|
||||||
@@ -99,8 +105,33 @@ public class BackGestureIndicatorView extends LinearLayout {
|
|||||||
| copiedFlags,
|
| copiedFlags,
|
||||||
PixelFormat.TRANSLUCENT);
|
PixelFormat.TRANSLUCENT);
|
||||||
|
|
||||||
|
setCurrentGestureHeight(lp);
|
||||||
lp.setTitle("BackGestureIndicatorView");
|
lp.setTitle("BackGestureIndicatorView");
|
||||||
lp.token = getContext().getActivityToken();
|
lp.token = getContext().getActivityToken();
|
||||||
return lp;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.gestures;
|
package com.android.settings.gestures;
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
@@ -52,12 +53,18 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
|
|||||||
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
.putExtra("use_tutorial_menu", true);
|
.putExtra("use_tutorial_menu", true);
|
||||||
|
|
||||||
|
private static final String GESTURE_BACK_HEIGHT_KEY = "gesture_back_height";
|
||||||
|
|
||||||
private WindowManager mWindowManager;
|
private WindowManager mWindowManager;
|
||||||
private BackGestureIndicatorView mIndicatorView;
|
private BackGestureIndicatorView mIndicatorView;
|
||||||
|
|
||||||
private float[] mBackGestureInsetScales;
|
private float[] mBackGestureInsetScales;
|
||||||
private float mDefaultBackGestureInset;
|
private float mDefaultBackGestureInset;
|
||||||
|
|
||||||
|
private float[] mBackGestureHeightScales = { 0f, 1f, 2f, 3f };
|
||||||
|
private int mCurrentRightWidth;
|
||||||
|
private int mCurrentLefttWidth;
|
||||||
|
|
||||||
public GestureNavigationSettingsFragment() {
|
public GestureNavigationSettingsFragment() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -82,6 +89,7 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
|
|||||||
|
|
||||||
initSeekBarPreference(LEFT_EDGE_SEEKBAR_KEY);
|
initSeekBarPreference(LEFT_EDGE_SEEKBAR_KEY);
|
||||||
initSeekBarPreference(RIGHT_EDGE_SEEKBAR_KEY);
|
initSeekBarPreference(RIGHT_EDGE_SEEKBAR_KEY);
|
||||||
|
initSeekBarPreference(GESTURE_BACK_HEIGHT_KEY);
|
||||||
initTutorialButton();
|
initTutorialButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,11 +154,42 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
|
|||||||
pref.setContinuousUpdates(true);
|
pref.setContinuousUpdates(true);
|
||||||
pref.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_TICKS);
|
pref.setHapticFeedbackMode(SeekBarPreference.HAPTIC_FEEDBACK_MODE_ON_TICKS);
|
||||||
|
|
||||||
final String settingsKey = key == LEFT_EDGE_SEEKBAR_KEY
|
String settingsKey;
|
||||||
? Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT
|
float initScale = 0;
|
||||||
: Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT;
|
|
||||||
final float initScale = Settings.Secure.getFloat(
|
switch(key) {
|
||||||
getContext().getContentResolver(), settingsKey, 1.0f);
|
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
|
// Find the closest value to initScale
|
||||||
float minDistance = Float.MAX_VALUE;
|
float minDistance = Float.MAX_VALUE;
|
||||||
@@ -165,15 +204,38 @@ public class GestureNavigationSettingsFragment extends DashboardFragment {
|
|||||||
pref.setProgress(minDistanceIndex);
|
pref.setProgress(minDistanceIndex);
|
||||||
|
|
||||||
pref.setOnPreferenceChangeListener((p, v) -> {
|
pref.setOnPreferenceChangeListener((p, v) -> {
|
||||||
final int width = (int) (mDefaultBackGestureInset * mBackGestureInsetScales[(int) v]);
|
if (key != GESTURE_BACK_HEIGHT_KEY) {
|
||||||
mIndicatorView.setIndicatorWidth(width, key == LEFT_EDGE_SEEKBAR_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;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
pref.setOnPreferenceChangeStopListener((p, v) -> {
|
pref.setOnPreferenceChangeStopListener((p, v) -> {
|
||||||
mIndicatorView.setIndicatorWidth(0, key == LEFT_EDGE_SEEKBAR_KEY);
|
|
||||||
final float scale = mBackGestureInsetScales[(int) v];
|
final float scale = mBackGestureInsetScales[(int) v];
|
||||||
Settings.Secure.putFloat(getContext().getContentResolver(), settingsKey, scale);
|
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;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user