• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.annotation.NonNull;
20 import android.content.Context;
21 import android.content.pm.PackageManager;
22 import android.content.pm.ResolveInfo;
23 import android.graphics.PorterDuff;
24 import android.widget.ImageView;
25 
26 import com.android.car.settings.common.BaseFragment;
27 import com.android.car.settings.common.IconTextLineItem;
28 
29 /**
30  * Represents an application in application settings page.
31  */
32 public class ApplicationLineItem extends IconTextLineItem {
33     private final ResolveInfo mResolveInfo;
34     private final Context mContext;
35     private final PackageManager mPm;
36     private final boolean mClickable;
37     private final BaseFragment.FragmentController mFragmentController;
38 
ApplicationLineItem( @onNull Context context, PackageManager pm, ResolveInfo resolveInfo, BaseFragment.FragmentController fragmentController)39     public ApplicationLineItem(
40             @NonNull Context context,
41             PackageManager pm,
42             ResolveInfo resolveInfo,
43             BaseFragment.FragmentController fragmentController) {
44         this(context, pm, resolveInfo, fragmentController, true);
45     }
46 
ApplicationLineItem( @onNull Context context, PackageManager pm, ResolveInfo resolveInfo, BaseFragment.FragmentController fragmentController, boolean clickable)47     public ApplicationLineItem(
48             @NonNull Context context,
49             PackageManager pm,
50             ResolveInfo resolveInfo,
51             BaseFragment.FragmentController fragmentController,
52             boolean clickable) {
53         super(resolveInfo.loadLabel(pm));
54         mContext = context;
55         mPm = pm;
56         mResolveInfo = resolveInfo;
57         mFragmentController = fragmentController;
58         mClickable = clickable;
59     }
60 
61     @Override
onClick()62     public void onClick() {
63         if (mClickable) {
64             mFragmentController.launchFragment(ApplicationDetailFragment.getInstance(mResolveInfo));
65         }
66     }
67 
68     @Override
isEnabled()69     public boolean isEnabled() {
70         return true;
71     }
72 
73     @Override
isExpandable()74     public boolean isExpandable() {
75         return mClickable;
76     }
77 
78     @Override
getDesc()79     public CharSequence getDesc() {
80         return null;
81     }
82 
83     @Override
setIcon(ImageView iconView)84     public void setIcon(ImageView iconView) {
85         iconView.setImageDrawable(mResolveInfo.loadIcon(mPm));
86         iconView.setImageTintMode(PorterDuff.Mode.DST);
87     }
88 }
89