• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.carlauncher;
18 
19 import android.annotation.Nullable;
20 import android.content.Context;
21 import android.support.v7.widget.RecyclerView;
22 import android.view.View;
23 import android.widget.ImageView;
24 import android.widget.TextView;
25 
26 /**
27  * App item view holder that contains the app icon and name.
28  */
29 public class AppItemViewHolder extends RecyclerView.ViewHolder {
30     private final Context mContext;
31     public View mAppItem;
32     public ImageView mAppIconView;
33     public TextView mAppNameView;
34 
AppItemViewHolder(View view, Context context)35     public AppItemViewHolder(View view, Context context) {
36         super(view);
37         mContext = context;
38         mAppItem = view.findViewById(R.id.app_item);
39         mAppIconView = mAppItem.findViewById(R.id.app_icon);
40         mAppNameView = mAppItem.findViewById(R.id.app_name);
41     }
42 
43     /**
44      * Binds the grid app item view with the app meta data.
45      *
46      * @param app Pass {@code null} will empty out the view.
47      */
bind(@ullable AppMetaData app, boolean isDistractionOptimizationRequired)48     public void bind(@Nullable AppMetaData app, boolean isDistractionOptimizationRequired) {
49         // Empty out the view
50         mAppItem.setClickable(false);
51         mAppIconView.setImageDrawable(null);
52         mAppNameView.setText(null);
53 
54         if (app == null) {
55             return;
56         }
57 
58         mAppNameView.setText(app.getDisplayName());
59         if (isDistractionOptimizationRequired && !app.getIsDistractionOptimized()) {
60             mAppIconView.setImageDrawable(AppLauncherUtils.toGrayscale(app.getIcon()));
61         } else {
62             mAppIconView.setImageDrawable(app.getIcon());
63             mAppItem.setOnClickListener(v -> AppLauncherUtils.launchApp(mContext, app));
64         }
65     }
66 }
67