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