• 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.PreferenceGroup;
24 
25 import com.android.car.settings.common.FragmentController;
26 import com.android.car.settings.common.PreferenceController;
27 
28 import java.util.List;
29 
30 /**
31  * Class that controls visibility based on whether there have been recently used apps.
32  * Hidden if there have are no recently used apps.
33  */
34 public class RecentAppsGroupPreferenceController extends PreferenceController<PreferenceGroup>
35         implements RecentAppsItemManager.RecentAppStatsListener {
36 
37     // In most cases, device has recently opened apps. So, assume true by default.
38     private boolean mAreThereRecentlyUsedApps = true;
39 
RecentAppsGroupPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)40     public RecentAppsGroupPreferenceController(Context context, String preferenceKey,
41             FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
42         super(context, preferenceKey, fragmentController, uxRestrictions);
43     }
44 
45     @Override
getPreferenceType()46     protected Class<PreferenceGroup> getPreferenceType() {
47         return PreferenceGroup.class;
48     }
49 
50     @Override
getAvailabilityStatus()51     public int getAvailabilityStatus() {
52         return mAreThereRecentlyUsedApps ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
53     }
54 
55     @Override
onRecentAppStatsLoaded(List<UsageStats> recentAppStats)56     public void onRecentAppStatsLoaded(List<UsageStats> recentAppStats) {
57         mAreThereRecentlyUsedApps = !recentAppStats.isEmpty();
58         refreshUi();
59     }
60 }
61