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 View mProgressHeader; 48 private View mProgressAnimation; 49 private RecentAppStatsMixin mRecentAppStatsMixin; 50 private RecentAppsPreferenceController mRecentAppsPreferenceController; 51 private AllAppsInfoPreferenceController mAllAppsInfoPreferenceController; 52 53 @Override getMetricsCategory()54 public int getMetricsCategory() { 55 return SettingsEnums.SETTINGS_APP_NOTIF_CATEGORY; 56 } 57 58 @Override getLogTag()59 protected String getLogTag() { 60 return TAG; 61 } 62 63 @Override getHelpResource()64 public int getHelpResource() { 65 return R.string.help_url_apps_and_notifications; 66 } 67 68 @Override getPreferenceScreenResId()69 protected int getPreferenceScreenResId() { 70 return R.xml.app_and_notification; 71 } 72 73 @Override onAttach(Context context)74 public void onAttach(Context context) { 75 super.onAttach(context); 76 77 use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle()); 78 79 mRecentAppStatsMixin = new RecentAppStatsMixin(context, 80 AppEntitiesHeaderController.MAXIMUM_APPS); 81 getSettingsLifecycle().addObserver(mRecentAppStatsMixin); 82 mRecentAppStatsMixin.addListener(this); 83 84 mRecentAppsPreferenceController = use(RecentAppsPreferenceController.class); 85 mRecentAppsPreferenceController.setFragment(this /* fragment */); 86 mRecentAppStatsMixin.addListener(mRecentAppsPreferenceController); 87 88 mAllAppsInfoPreferenceController = use(AllAppsInfoPreferenceController.class); 89 mRecentAppStatsMixin.addListener(mAllAppsInfoPreferenceController); 90 } 91 92 @Override onViewCreated(View view, Bundle savedInstanceState)93 public void onViewCreated(View view, Bundle savedInstanceState) { 94 super.onViewCreated(view, savedInstanceState); 95 mProgressHeader = setPinnedHeaderView(R.layout.progress_header); 96 mProgressAnimation = mProgressHeader.findViewById(R.id.progress_bar_animation); 97 setLoadingEnabled(false); 98 } 99 100 @Override onStart()101 public void onStart() { 102 super.onStart(); 103 setLoadingEnabled(true); 104 } 105 106 @Override onReloadDataCompleted(@onNull List<UsageStats> recentApps)107 public void onReloadDataCompleted(@NonNull List<UsageStats> recentApps) { 108 setLoadingEnabled(false); 109 if (!recentApps.isEmpty()) { 110 Utils.setActionBarShadowAnimation(getActivity(), getSettingsLifecycle(), 111 getListView()); 112 } 113 } 114 115 @Override createPreferenceControllers(Context context)116 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 117 return buildPreferenceControllers(context); 118 } 119 setLoadingEnabled(boolean enabled)120 private void setLoadingEnabled(boolean enabled) { 121 if (mProgressHeader != null && mProgressAnimation != null) { 122 mProgressHeader.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 123 mProgressAnimation.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 124 } 125 } 126 buildPreferenceControllers(Context context)127 private static List<AbstractPreferenceController> buildPreferenceControllers(Context context) { 128 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 129 controllers.add(new EmergencyBroadcastPreferenceController(context, 130 "app_and_notif_cell_broadcast_settings")); 131 return controllers; 132 } 133 134 public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 135 new BaseSearchIndexProvider() { 136 @Override 137 public List<SearchIndexableResource> getXmlResourcesToIndex( 138 Context context, boolean enabled) { 139 final SearchIndexableResource sir = new SearchIndexableResource(context); 140 sir.xmlResId = R.xml.app_and_notification; 141 return Arrays.asList(sir); 142 } 143 144 @Override 145 public List<AbstractPreferenceController> createPreferenceControllers( 146 Context context) { 147 return buildPreferenceControllers(context); 148 } 149 }; 150 } 151