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.display;
18 
19 import static com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice.PREF;
20 import static com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice.PREF_KEY_INTERACTED;
21 
22 import android.app.settings.SettingsEnums;
23 import android.content.Context;
24 import android.os.Bundle;
25 
26 import androidx.preference.Preference;
27 
28 import com.android.settings.R;
29 import com.android.settings.dashboard.DashboardFragment;
30 import com.android.settings.search.BaseSearchIndexProvider;
31 import com.android.settingslib.search.SearchIndexable;
32 
33 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
34 public class AdaptiveSleepSettings extends DashboardFragment {
35 
36     private static final String TAG = "AdaptiveSleepSettings";
37     private Context mContext;
38 
39     @Override
onCreate(Bundle icicle)40     public void onCreate(Bundle icicle) {
41         super.onCreate(icicle);
42         mContext = getContext();
43         Preference permissionPreference = findPreference(
44                 AdaptiveSleepPermissionPreferenceController.PREF_NAME);
45         if (permissionPreference != null) {
46             permissionPreference.setVisible(false);
47         }
48 
49         mContext.getSharedPreferences(PREF, Context.MODE_PRIVATE)
50                 .edit()
51                 .putBoolean(PREF_KEY_INTERACTED, true)
52                 .apply();
53     }
54 
55     @Override
getPreferenceScreenResId()56     protected int getPreferenceScreenResId() {
57         return R.xml.adaptive_sleep_detail;
58     }
59 
60     @Override
getLogTag()61     protected String getLogTag() {
62         return TAG;
63     }
64 
65     @Override
getMetricsCategory()66     public int getMetricsCategory() {
67         return SettingsEnums.SETTINGS_ADAPTIVE_SLEEP;
68     }
69 
70     @Override
getHelpResource()71     public int getHelpResource() {
72         return R.string.help_url_adaptive_sleep;
73     }
74 
75     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
76             new BaseSearchIndexProvider(R.xml.adaptive_sleep_detail);
77 }
78