• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.notification;
18 
19 import android.content.Context;
20 import android.provider.Settings;
21 
22 import com.android.settings.R;
23 import com.android.settings.core.BasePreferenceController;
24 
25 import androidx.preference.ListPreference;
26 import androidx.preference.Preference;
27 
28 public class SwipeDirectionPreferenceController extends BasePreferenceController
29         implements Preference.OnPreferenceChangeListener {
30 
SwipeDirectionPreferenceController(Context context, String key)31     public SwipeDirectionPreferenceController(Context context, String key) {
32         super(context, key);
33     }
34 
35     @Override
getAvailabilityStatus()36     public int getAvailabilityStatus() {
37         return AVAILABLE;
38     }
39 
40     @Override
updateState(Preference pref)41     public void updateState(Preference pref) {
42         ((ListPreference) pref).setValue(String.valueOf(Settings.Secure.getInt(
43                 mContext.getContentResolver(),
44                 Settings.Secure.NOTIFICATION_DISMISS_RTL,
45                 1)));
46         super.updateState(pref);
47     }
48 
49     @Override
onPreferenceChange(Preference preference, Object newValue)50     public boolean onPreferenceChange(Preference preference, Object newValue) {
51         Settings.Secure.putInt(mContext.getContentResolver(),
52                 Settings.Secure.NOTIFICATION_DISMISS_RTL,
53                 Integer.valueOf((String) newValue));
54         refreshSummary(preference);
55         return true;
56     }
57 
58     @Override
getSummary()59     public CharSequence getSummary() {
60         int value = Settings.Secure.getInt(mContext.getContentResolver(),
61                 Settings.Secure.NOTIFICATION_DISMISS_RTL, 1);
62         String[] values = mContext.getResources().getStringArray(R.array.swipe_direction_values);
63         String[] titles = mContext.getResources().getStringArray(R.array.swipe_direction_titles);
64         if (values == null) {
65             return null;
66         }
67         for (int i = 0; i < values.length; i++) {
68             int valueAt = Integer.parseInt(values[i]);
69             if (value == valueAt) {
70                 return titles[i];
71             }
72         }
73         return null;
74     }
75 }
76