1 /* 2 * Copyright (C) 2017 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.applications.assist; 18 19 import android.app.settings.SettingsEnums; 20 import android.content.Context; 21 import android.provider.SearchIndexableResource; 22 23 import com.android.settings.R; 24 import com.android.settings.dashboard.DashboardFragment; 25 import com.android.settings.gestures.AssistGestureSettingsPreferenceController; 26 import com.android.settings.search.BaseSearchIndexProvider; 27 import com.android.settings.search.Indexable; 28 import com.android.settingslib.core.AbstractPreferenceController; 29 import com.android.settingslib.core.lifecycle.Lifecycle; 30 import com.android.settingslib.search.SearchIndexable; 31 32 import java.util.ArrayList; 33 import java.util.Arrays; 34 import java.util.List; 35 36 /** 37 * Settings screen to manage everything about assist. 38 */ 39 @SearchIndexable 40 public class ManageAssist extends DashboardFragment { 41 42 private static final String TAG = "ManageAssist"; 43 private static final String KEY_ASSIST = "gesture_assist_application"; 44 45 @Override getLogTag()46 protected String getLogTag() { 47 return TAG; 48 } 49 50 @Override getPreferenceScreenResId()51 protected int getPreferenceScreenResId() { 52 return R.xml.manage_assist; 53 } 54 55 @Override createPreferenceControllers(Context context)56 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 57 return buildPreferenceControllers(context, getSettingsLifecycle()); 58 } 59 60 @Override getMetricsCategory()61 public int getMetricsCategory() { 62 return SettingsEnums.APPLICATIONS_MANAGE_ASSIST; 63 } 64 65 @Override onAttach(Context context)66 public void onAttach(Context context) { 67 super.onAttach(context); 68 use(AssistGestureSettingsPreferenceController.class).setAssistOnly(true); 69 } 70 71 @Override onResume()72 public void onResume() { 73 super.onResume(); 74 75 mFooterPreferenceMixin.createFooterPreference() 76 .setTitle(R.string.assist_footer); 77 } 78 buildPreferenceControllers(Context context, Lifecycle lifecycle)79 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context, 80 Lifecycle lifecycle) { 81 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 82 controllers.add(new DefaultAssistPreferenceController(context, "default_assist", 83 true /* showSetting */)); 84 controllers.add(new AssistContextPreferenceController(context, lifecycle)); 85 controllers.add(new AssistScreenshotPreferenceController(context, lifecycle)); 86 controllers.add(new AssistFlashScreenPreferenceController(context, lifecycle)); 87 controllers.add(new DefaultVoiceInputPreferenceController(context, lifecycle)); 88 return controllers; 89 } 90 91 public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 92 new BaseSearchIndexProvider() { 93 @Override 94 public List<SearchIndexableResource> getXmlResourcesToIndex(Context context, 95 boolean enabled) { 96 final SearchIndexableResource sir = new SearchIndexableResource(context); 97 sir.xmlResId = R.xml.manage_assist; 98 return Arrays.asList(sir); 99 } 100 101 @Override 102 public List<AbstractPreferenceController> createPreferenceControllers( 103 Context context) { 104 return buildPreferenceControllers(context, null /* lifecycle */); 105 } 106 107 @Override 108 public List<String> getNonIndexableKeys(Context context) { 109 List<String> keys = super.getNonIndexableKeys(context); 110 keys.add(KEY_ASSIST); 111 return keys; 112 } 113 }; 114 } 115