• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.car.settings.applications;
18 
19 import android.app.usage.UsageStats;
20 import android.car.drivingstate.CarUxRestrictions;
21 import android.content.Context;
22 
23 import androidx.preference.Preference;
24 
25 import com.android.car.settings.R;
26 import com.android.car.settings.common.FragmentController;
27 import com.android.car.settings.common.PreferenceController;
28 
29 import java.util.List;
30 
31 /**
32  * Controller that shows when there is no recently used apps.
33  * Sets availability based on if there are recent apps and sets summary depending on number of
34  * non-system apps.
35  */
36 public class AllAppsPreferenceController extends PreferenceController<Preference> implements
37         RecentAppsItemManager.RecentAppStatsListener,
38         InstalledAppCountItemManager.InstalledAppCountListener {
39 
40     // In most cases, device has recently opened apps. So, assume true by default.
41     private boolean mAreThereRecentlyUsedApps = true;
42 
AllAppsPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)43     public AllAppsPreferenceController(Context context, String preferenceKey,
44             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
45         super(context, preferenceKey, fragmentController, uxRestrictions);
46     }
47 
48     @Override
getPreferenceType()49     protected Class<Preference> getPreferenceType() {
50         return Preference.class;
51     }
52 
53     @Override
getAvailabilityStatus()54     public int getAvailabilityStatus() {
55         return mAreThereRecentlyUsedApps ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
56     }
57 
58     @Override
onRecentAppStatsLoaded(List<UsageStats> recentAppStats)59     public void onRecentAppStatsLoaded(List<UsageStats> recentAppStats) {
60         mAreThereRecentlyUsedApps = !recentAppStats.isEmpty();
61         refreshUi();
62     }
63 
64     @Override
onInstalledAppCountLoaded(int appCount)65     public void onInstalledAppCountLoaded(int appCount) {
66         getPreference().setSummary(getContext().getResources().getString(
67                 R.string.apps_view_all_apps_title, appCount));
68     }
69 }
70