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