blob: ebfea450af88472671ea27f9c9906e35e4a8960e [file] [log] [blame]
Mehdi Alizadehf2b28e92019-12-05 20:13:49 -08001/*
2 * Copyright (C) 2020 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
17package com.android.internal.policy;
18
19import android.content.ContentResolver;
20import android.content.Context;
21import android.content.res.Resources;
22import android.database.ContentObserver;
23import android.os.Handler;
24import android.os.UserHandle;
25import android.provider.Settings;
26
27/**
28 * @hide
29 */
30public class GestureNavigationSettingsObserver extends ContentObserver {
31 private Context mContext;
32 private Runnable mOnChangeRunnable;
33
34 public GestureNavigationSettingsObserver(Handler handler, Context context,
35 Runnable onChangeRunnable) {
36 super(handler);
37 mContext = context;
38 mOnChangeRunnable = onChangeRunnable;
39 }
40
41 public void register() {
42 ContentResolver r = mContext.getContentResolver();
43 r.registerContentObserver(
44 Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT),
45 false, this, UserHandle.USER_ALL);
46 r.registerContentObserver(
47 Settings.Secure.getUriFor(Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT),
48 false, this, UserHandle.USER_ALL);
49 }
50
51 public void unregister() {
52 mContext.getContentResolver().unregisterContentObserver(this);
53 }
54
55 @Override
56 public void onChange(boolean selfChange) {
57 super.onChange(selfChange);
58 if (mOnChangeRunnable != null) {
59 mOnChangeRunnable.run();
60 }
61 }
62
63 public int getLeftSensitivity(Resources userRes) {
64 return getSensitivity(userRes, Settings.Secure.BACK_GESTURE_INSET_SCALE_LEFT);
65 }
66
67 public int getRightSensitivity(Resources userRes) {
68 return getSensitivity(userRes, Settings.Secure.BACK_GESTURE_INSET_SCALE_RIGHT);
69 }
70
71 private int getSensitivity(Resources userRes, String side) {
72 final int inset = userRes.getDimensionPixelSize(
73 com.android.internal.R.dimen.config_backGestureInset);
74 final float scale = Settings.Secure.getFloatForUser(
75 mContext.getContentResolver(), side, 1.0f, UserHandle.USER_CURRENT);
76 return (int) (inset * scale);
77 }
78}