1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.settings.gestures; 18 19 import android.app.AlertDialog; 20 import android.app.Dialog; 21 import android.app.settings.SettingsEnums; 22 import android.content.Context; 23 import android.content.om.IOverlayManager; 24 import android.os.Bundle; 25 import android.os.ServiceManager; 26 import android.view.View; 27 import android.widget.SeekBar; 28 29 import com.android.settings.R; 30 import com.android.settings.core.instrumentation.InstrumentedDialogFragment; 31 32 /** 33 * Dialog to set the back gesture's sensitivity in Gesture navigation mode. 34 */ 35 public class GestureNavigationBackSensitivityDialog extends InstrumentedDialogFragment { 36 private static final String TAG = "GestureNavigationBackSensitivityDialog"; 37 private static final String KEY_BACK_SENSITIVITY = "back_sensitivity"; 38 show(SystemNavigationGestureSettings parent, int sensitivity)39 public static void show(SystemNavigationGestureSettings parent, int sensitivity) { 40 if (!parent.isAdded()) { 41 return; 42 } 43 44 final GestureNavigationBackSensitivityDialog dialog = 45 new GestureNavigationBackSensitivityDialog(); 46 final Bundle bundle = new Bundle(); 47 bundle.putInt(KEY_BACK_SENSITIVITY, sensitivity); 48 dialog.setArguments(bundle); 49 dialog.setTargetFragment(parent, 0); 50 dialog.show(parent.getFragmentManager(), TAG); 51 } 52 53 @Override getMetricsCategory()54 public int getMetricsCategory() { 55 return SettingsEnums.SETTINGS_GESTURE_NAV_BACK_SENSITIVITY_DLG; 56 } 57 58 @Override onCreateDialog(Bundle savedInstanceState)59 public Dialog onCreateDialog(Bundle savedInstanceState) { 60 final View view = getActivity().getLayoutInflater().inflate( 61 R.layout.dialog_back_gesture_sensitivity, null); 62 final SeekBar seekBar = view.findViewById(R.id.back_sensitivity_seekbar); 63 seekBar.setProgress(getArguments().getInt(KEY_BACK_SENSITIVITY)); 64 return new AlertDialog.Builder(getContext()) 65 .setTitle(R.string.back_sensitivity_dialog_title) 66 .setMessage(R.string.back_sensitivity_dialog_message) 67 .setView(view) 68 .setPositiveButton(R.string.okay, (dialog, which) -> { 69 int sensitivity = seekBar.getProgress(); 70 getArguments().putInt(KEY_BACK_SENSITIVITY, sensitivity); 71 SystemNavigationGestureSettings.setBackSensitivity(getActivity(), 72 getOverlayManager(), sensitivity); 73 }) 74 .create(); 75 } 76 getOverlayManager()77 private IOverlayManager getOverlayManager() { 78 return IOverlayManager.Stub.asInterface(ServiceManager.getService(Context.OVERLAY_SERVICE)); 79 } 80 }