1 /*
2  * Copyright (C) 2015 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.settings.applications;
18 
19 import android.util.Log;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.ImageView;
24 import android.widget.TextView;
25 
26 import com.android.settings.R;
27 import com.android.settingslib.applications.ApplicationsState;
28 
29 // View Holder used when displaying views
30 public class AppViewHolder {
31     public ApplicationsState.AppEntry entry;
32     public View rootView;
33     public TextView appName;
34     public ImageView appIcon;
35     public TextView summary;
36     public TextView disabled;
37 
createOrRecycle(LayoutInflater inflater, View convertView)38     static public AppViewHolder createOrRecycle(LayoutInflater inflater, View convertView) {
39         if (convertView == null) {
40             convertView = inflater.inflate(R.layout.preference_app, null);
41             inflater.inflate(R.layout.widget_text_views,
42                     (ViewGroup) convertView.findViewById(android.R.id.widget_frame));
43 
44             // Creates a ViewHolder and store references to the two children views
45             // we want to bind data to.
46             AppViewHolder holder = new AppViewHolder();
47             holder.rootView = convertView;
48             holder.appName = (TextView) convertView.findViewById(android.R.id.title);
49             holder.appIcon = (ImageView) convertView.findViewById(android.R.id.icon);
50             holder.summary = (TextView) convertView.findViewById(R.id.widget_text1);
51             holder.disabled = (TextView) convertView.findViewById(R.id.widget_text2);
52             convertView.setTag(holder);
53             return holder;
54         } else {
55             // Get the ViewHolder back to get fast access to the TextView
56             // and the ImageView.
57             return (AppViewHolder)convertView.getTag();
58         }
59     }
60 
updateSizeText(CharSequence invalidSizeStr, int whichSize)61     void updateSizeText(CharSequence invalidSizeStr, int whichSize) {
62         if (ManageApplications.DEBUG) Log.i(ManageApplications.TAG, "updateSizeText of "
63                 + entry.label + " " + entry + ": " + entry.sizeStr);
64         if (entry.sizeStr != null) {
65             switch (whichSize) {
66                 case ManageApplications.SIZE_INTERNAL:
67                     summary.setText(entry.internalSizeStr);
68                     break;
69                 case ManageApplications.SIZE_EXTERNAL:
70                     summary.setText(entry.externalSizeStr);
71                     break;
72                 default:
73                     summary.setText(entry.sizeStr);
74                     break;
75             }
76         } else if (entry.size == ApplicationsState.SIZE_INVALID) {
77             summary.setText(invalidSizeStr);
78         }
79     }
80 }