1 /* 2 * Copyright (C) 2016 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; 18 19 import android.app.settings.SettingsEnums; 20 import android.app.usage.UsageStats; 21 import android.content.Context; 22 import android.os.Bundle; 23 import android.provider.SearchIndexableResource; 24 import android.view.View; 25 26 import androidx.annotation.NonNull; 27 28 import com.android.settings.R; 29 import com.android.settings.Utils; 30 import com.android.settings.dashboard.DashboardFragment; 31 import com.android.settings.notification.EmergencyBroadcastPreferenceController; 32 import com.android.settings.search.BaseSearchIndexProvider; 33 import com.android.settingslib.core.AbstractPreferenceController; 34 import com.android.settingslib.search.SearchIndexable; 35 import com.android.settingslib.widget.AppEntitiesHeaderController; 36 37 import java.util.ArrayList; 38 import java.util.Arrays; 39 import java.util.List; 40 41 @SearchIndexable 42 public class AppAndNotificationDashboardFragment extends DashboardFragment 43 implements RecentAppStatsMixin.RecentAppStatsListener { 44 45 private static final String TAG = "AppAndNotifDashboard"; 46 47 private RecentAppStatsMixin mRecentAppStatsMixin; 48 private RecentAppsPreferenceController mRecentAppsPreferenceController; 49 private AllAppsInfoPreferenceController mAllAppsInfoPreferenceController; 50 51 @Override getMetricsCategory()52 public int getMetricsCategory() { 53 return SettingsEnums.SETTINGS_APP_NOTIF_CATEGORY; 54 } 55 56 @Override getLogTag()57 protected String getLogTag() { 58 return TAG; 59 } 60 61 @Override getHelpResource()62 public int getHelpResource() { 63 return R.string.help_url_apps_and_notifications; 64 } 65 66 @Override getPreferenceScreenResId()67 protected int getPreferenceScreenResId() { 68 return R.xml.app_and_notification; 69 } 70 71 @Override onAttach(Context context)72 public void onAttach(Context context) { 73 super.onAttach(context); 74 75 use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle()); 76 77 mRecentAppStatsMixin = new RecentAppStatsMixin(context, 78 AppEntitiesHeaderController.MAXIMUM_APPS); 79 getSettingsLifecycle().addObserver(mRecentAppStatsMixin); 80 mRecentAppStatsMixin.addListener(this); 81 82 mRecentAppsPreferenceController = use(RecentAppsPreferenceController.class); 83 mRecentAppsPreferenceController.setFragment(this /* fragment */); 84 mRecentAppStatsMixin.addListener(mRecentAppsPreferenceController); 85 86 mAllAppsInfoPreferenceController = use(AllAppsInfoPreferenceController.class); 87 mRecentAppStatsMixin.addListener(mAllAppsInfoPreferenceController); 88 } 89 90 @Override onViewCreated(View view, Bundle savedInstanceState)91 public void onViewCreated(View view, Bundle savedInstanceState) { 92 super.onViewCreated(view, savedInstanceState); 93 setPinnedHeaderView(R.layout.progress_header); 94 showPinnedHeader(false); 95 } 96 97 @Override onStart()98 public void onStart() { 99 super.onStart(); 100 showPinnedHeader(true); 101 } 102 103 @Override onReloadDataCompleted(@onNull List<UsageStats> recentApps)104 public void onReloadDataCompleted(@NonNull List<UsageStats> recentApps) { 105 showPinnedHeader(false); 106 if (!recentApps.isEmpty()) { 107 Utils.setActionBarShadowAnimation(getActivity(), getSettingsLifecycle(), 108 getListView()); 109 } 110 } 111 112 @Override createPreferenceControllers(Context context)113 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 114 return buildPreferenceControllers(context); 115 } 116 buildPreferenceControllers(Context context)117 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) { 118 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 119 controllers.add(new EmergencyBroadcastPreferenceController(context, 120 "app_and_notif_cell_broadcast_settings")); 121 return controllers; 122 } 123 124 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 125 new BaseSearchIndexProvider() { 126 @Override 127 public List<SearchIndexableResource> getXmlResourcesToIndex( 128 Context context, boolean enabled) { 129 final SearchIndexableResource sir = new SearchIndexableResource(context); 130 sir.xmlResId = R.xml.app_and_notification; 131 return Arrays.asList(sir); 132 } 133 134 @Override 135 public List<AbstractPreferenceController> createPreferenceControllers( 136 Context context) { 137 return buildPreferenceControllers(context); 138 } 139 }; 140 } 141