1 /* 2 * Copyright (C) 2018 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.car.drivingstate.CarUxRestrictions; 20 import android.content.Context; 21 import android.content.Intent; 22 import android.graphics.drawable.Drawable; 23 import android.provider.Settings; 24 25 import androidx.preference.Preference; 26 import androidx.preference.PreferenceGroup; 27 28 import com.android.car.settings.common.CarSettingActivities; 29 import com.android.car.settings.common.FragmentController; 30 import com.android.car.settings.common.PreferenceController; 31 import com.android.car.ui.preference.CarUiPreference; 32 import com.android.settingslib.applications.ApplicationsState; 33 34 import java.util.ArrayList; 35 36 /** Business logic which populates the applications in this setting. */ 37 public class ApplicationsSettingsPreferenceController extends 38 PreferenceController<PreferenceGroup> implements 39 ApplicationListItemManager.AppListItemListener { 40 ApplicationsSettingsPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)41 public ApplicationsSettingsPreferenceController(Context context, String preferenceKey, 42 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 43 super(context, preferenceKey, fragmentController, uxRestrictions); 44 } 45 46 @Override getPreferenceType()47 protected Class<PreferenceGroup> getPreferenceType() { 48 return PreferenceGroup.class; 49 } 50 51 @Override onDataLoaded(ArrayList<ApplicationsState.AppEntry> apps)52 public void onDataLoaded(ArrayList<ApplicationsState.AppEntry> apps) { 53 getPreference().removeAll(); 54 for (ApplicationsState.AppEntry appEntry : apps) { 55 getPreference().addPreference( 56 createPreference(appEntry.label, appEntry.sizeStr, appEntry.icon, 57 appEntry.info.packageName)); 58 } 59 } 60 createPreference(String title, String summary, Drawable icon, String packageName)61 private Preference createPreference(String title, String summary, Drawable icon, 62 String packageName) { 63 CarUiPreference preference = new CarUiPreference(getContext()); 64 preference.setTitle(title); 65 preference.setSummary(summary); 66 preference.setIcon(icon); 67 preference.setKey(packageName); 68 preference.setOnPreferenceClickListener(p -> { 69 Intent intent = new Intent(getContext(), 70 CarSettingActivities.ApplicationsDetailsActivity.class); 71 intent.putExtra(Settings.EXTRA_APP_PACKAGE, packageName); 72 getContext().startActivity(intent); 73 return true; 74 }); 75 return preference; 76 } 77 } 78