diff --git a/res/values/evolution_strings.xml b/res/values/evolution_strings.xml index 2784d3228ca..e3cd0e3f944 100644 --- a/res/values/evolution_strings.xml +++ b/res/values/evolution_strings.xml @@ -248,4 +248,10 @@ Increasing ring volume Start volume Ramp-up time + + + Full + Bottom + Back gesture height + Screen height valid for back gesture diff --git a/res/xml/gesture_navigation_settings.xml b/res/xml/gesture_navigation_settings.xml index 040a31b613d..a692822c24d 100644 --- a/res/xml/gesture_navigation_settings.xml +++ b/res/xml/gesture_navigation_settings.xml @@ -29,6 +29,15 @@ android:summary="@string/show_navbar_hint_summary" android:defaultValue="true" /> + + diff --git a/src/com/android/settings/gestures/BackGestureIndicatorView.java b/src/com/android/settings/gestures/BackGestureIndicatorView.java index c60afd003d3..3bf40ec7c96 100644 --- a/src/com/android/settings/gestures/BackGestureIndicatorView.java +++ b/src/com/android/settings/gestures/BackGestureIndicatorView.java @@ -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; + } + } } diff --git a/src/com/android/settings/gestures/GestureNavigationSettingsFragment.java b/src/com/android/settings/gestures/GestureNavigationSettingsFragment.java index 9a6b653fc45..692e440d668 100644 --- a/src/com/android/settings/gestures/GestureNavigationSettingsFragment.java +++ b/src/com/android/settings/gestures/GestureNavigationSettingsFragment.java @@ -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( - getContext().getContentResolver(), settingsKey, 1.0f); + 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) -> { - final int width = (int) (mDefaultBackGestureInset * mBackGestureInsetScales[(int) v]); - mIndicatorView.setIndicatorWidth(width, key == LEFT_EDGE_SEEKBAR_KEY); + 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]; - 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; }); }