2 Copyright (C) 2014 Samsung Electronics Polska Sp. z o.o.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU AFFERO General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8 You may obtain a copy of the License at
10 http://www.gnu.org/licenses/agpl-3.0.txt
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 package com.samsung.srpol.ui.tabpager;
23 import java.util.ArrayList;
25 import com.samsung.srpol.R;
26 import com.samsung.srpol.data.Category;
27 import com.samsung.srpol.data.Subcategory;
28 import com.samsung.srpol.loader.AppDetails;
29 import com.samsung.srpol.loader.AppListLoader;
30 import com.samsung.srpol.utils.Utils;
32 import android.annotation.TargetApi;
33 import android.content.Context;
34 import android.content.SharedPreferences;
35 import android.graphics.drawable.Drawable;
36 import android.os.Build;
37 import android.preference.PreferenceManager;
38 import android.view.LayoutInflater;
39 import android.view.View;
40 import android.view.ViewGroup;
41 import android.widget.ArrayAdapter;
42 import android.widget.ImageView;
43 import android.widget.LinearLayout;
44 import android.widget.TextView;
46 public class AppListArrayAdapter extends ArrayAdapter<AppDetails> {
48 private static SharedPreferences mSp;
50 private final Context mContext;
51 private final Category mCategory;
52 private ArrayList<AppDetails> mDisplayedList;
54 private static class ViewHolder {
55 public TextView appName;
56 public TextView appPackageName;
57 public ImageView appIcon;
58 public ImageView systemAppIcon;
59 public LinearLayout groupIcons;
60 public ImageView[] groupIconsView;
63 public AppListArrayAdapter(Context context, Category category) {
64 super(context, R.layout.app_list_item_view);
67 mDisplayedList = new ArrayList<AppDetails>();
69 mSp = PreferenceManager.getDefaultSharedPreferences(mContext);
73 private void refreshVisibleList() {
74 boolean includeSystemApps = mSp.getBoolean(
75 AppListLoader.PREF_INCLUDE_SYSTEM_APPS, true);
77 mDisplayedList.clear();
78 for (AppDetails app : mCategory.getRelatedApps()) {
79 if (isVisible(app, includeSystemApps))
80 mDisplayedList.add(app);
82 mCategory.updateVisibleCount(mDisplayedList.size());
86 public void notifyDataSetChanged() {
88 super.notifyDataSetChanged();
92 public AppDetails getItem(int position) {
93 return mDisplayedList.get(position);
97 public int getCount() {
98 return mDisplayedList.size();
101 private boolean isVisible(AppDetails item, boolean includeSystemApps) {
103 return !item.isSystemApp()
104 || (includeSystemApps && item.isSystemApp());
107 @SuppressWarnings("deprecation")
108 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
110 public View getView(int position, View convertView, ViewGroup parent) {
112 if (convertView == null) {
113 LayoutInflater inflater = (LayoutInflater) mContext
114 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
115 convertView = inflater.inflate(R.layout.app_list_item_view, parent,
117 holder = new ViewHolder();
118 holder.appName = (TextView) convertView
119 .findViewById(R.id.list_app_name);
120 holder.appPackageName = (TextView) convertView
121 .findViewById(R.id.list_app_package);
122 holder.appIcon = (ImageView) convertView
123 .findViewById(R.id.list_app_icon);
124 holder.systemAppIcon = (ImageView) convertView
125 .findViewById(R.id.list_system_app_icon);
126 holder.groupIcons = (LinearLayout) convertView
127 .findViewById(R.id.app_list_group_icons);
130 holder.groupIconsView = new ImageView[mCategory.getSubCategories().size()];
131 for (Subcategory category : mCategory.getSubCategories()){
132 ImageView icon = new ImageView(mContext);
133 icon.setImageDrawable(category.getDarkIcon());
134 holder.groupIconsView[i++] = icon;
135 holder.groupIcons.addView(icon);
137 convertView.setTag(holder);
139 holder = (ViewHolder) convertView.getTag();
141 AppDetails details = getItem(position);
142 holder.appName.setText(details.getAppName());
143 holder.appPackageName.setText(details.getAppPackageName());
144 holder.appIcon.setImageDrawable(details.getAppIcon());
146 // disabling and enabling apps in system application manager is available since API 4.0
147 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
148 if (details.isEnabled()) {
149 holder.appName.setTextColor(mContext.getResources().getColor(android.R.color.black));
151 holder.appName.setTextColor(mContext.getResources().getColor(R.color.disabled_app_name));
154 if(details.isSystemApp()){
155 holder.systemAppIcon.setVisibility(View.VISIBLE);
156 if(details.isEnabled()){
157 holder.systemAppIcon.setImageDrawable(Utils.getmSystemIcon(mContext));
159 holder.systemAppIcon.setImageDrawable(Utils.getmSystemIconDisable(mContext));
162 holder.systemAppIcon.setVisibility(View.INVISIBLE);
165 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
166 convertView.setBackgroundDrawable(mContext
169 details.isSystemApp() ? R.color.grayout_list_item_bg
170 : android.R.color.white));
172 convertView.setBackground(mContext
175 details.isSystemApp() ? R.color.grayout_list_item_bg
176 : android.R.color.white));
178 for (int i = 0; i < mCategory.getSubCategories().size(); ++i) {
179 if (details.isInSubcategory(mCategory.getSubCategories().get(i).getId())) {
180 // disabling and enabling apps in system application manager is available since API 4.0
181 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
182 if (details.isEnabled())
183 holder.groupIconsView[i].setImageDrawable(mCategory.getSubCategories().get(i).getDarkIcon());
185 holder.groupIconsView[i].setImageDrawable(mCategory.getSubCategories().get(i).getDisabledIcon());
187 holder.groupIconsView[i].setVisibility(View.VISIBLE);
189 holder.groupIconsView[i].setVisibility(View.GONE);