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 import android.provider.SearchIndexableResource; 26 27 import androidx.preference.Preference; 28 29 import com.android.settings.R; 30 import com.android.settings.dashboard.DashboardFragment; 31 import com.android.settings.search.BaseSearchIndexProvider; 32 import com.android.settingslib.search.SearchIndexable; 33 import com.android.settingslib.widget.FooterPreference; 34 35 import java.util.Arrays; 36 import java.util.List; 37 38 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 39 public class AdaptiveSleepSettings extends DashboardFragment { 40 41 private static final String TAG = "AdaptiveSleepSettings"; 42 private Context mContext; 43 44 @Override onCreate(Bundle icicle)45 public void onCreate(Bundle icicle) { 46 super.onCreate(icicle); 47 final FooterPreference footerPreference = 48 mFooterPreferenceMixin.createFooterPreference(); 49 mContext = getContext(); 50 51 footerPreference.setIcon(R.drawable.ic_privacy_shield_24dp); 52 footerPreference.setTitle(R.string.adaptive_sleep_privacy); 53 54 Preference permissionPreference = findPreference( 55 AdaptiveSleepPermissionPreferenceController.PREF_NAME); 56 if (permissionPreference != null) { 57 permissionPreference.setVisible(false); 58 } 59 60 mContext.getSharedPreferences(PREF, Context.MODE_PRIVATE) 61 .edit() 62 .putBoolean(PREF_KEY_INTERACTED, true) 63 .apply(); 64 } 65 66 @Override getPreferenceScreenResId()67 protected int getPreferenceScreenResId() { 68 return R.xml.adaptive_sleep_detail; 69 } 70 71 @Override getLogTag()72 protected String getLogTag() { 73 return TAG; 74 } 75 76 @Override getMetricsCategory()77 public int getMetricsCategory() { 78 return SettingsEnums.SETTINGS_ADAPTIVE_SLEEP; 79 } 80 81 @Override getHelpResource()82 public int getHelpResource() { 83 return R.string.help_url_adaptive_sleep; 84 } 85 86 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 87 new BaseSearchIndexProvider() { 88 @Override 89 public List<SearchIndexableResource> getXmlResourcesToIndex( 90 Context context, boolean enabled) { 91 final SearchIndexableResource sir = new SearchIndexableResource(context); 92 sir.xmlResId = R.xml.adaptive_sleep_detail; 93 return Arrays.asList(sir); 94 } 95 }; 96 } 97