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.loader;
24 import java.util.Comparator;
26 import android.content.pm.ApplicationInfo;
27 import android.content.pm.PackageInfo;
28 import android.content.pm.PackageManager.NameNotFoundException;
29 import android.graphics.ColorMatrix;
30 import android.graphics.ColorMatrixColorFilter;
31 import android.graphics.drawable.Drawable;
32 import android.os.Build;
35 * Helper class containing details about given permission
37 * This Class contains : String mPermissionName; String
38 * mPermissionLabel; String mPermissionDetails;
40 public class AppDetails {
41 public static final String TAG = "AppDetails";
42 private static final ColorMatrixColorFilter mGrayscaleFilter;
44 private String mAppName;
45 private String mPackageName;
46 private Drawable mAppIcon;
47 private boolean mSystemApp;
49 private int mSubCategoriesMask;
51 private static AppListLoader mLoader;
52 private boolean mEnabled;
53 private boolean mMounted;
54 private final File mApkFile;
57 ColorMatrix matrix = new ColorMatrix();
58 matrix.setSaturation(0);
59 mGrayscaleFilter = new ColorMatrixColorFilter(matrix);
62 public AppDetails(AppListLoader loader, PackageInfo packageinfo) {
64 mPackageName = packageinfo.applicationInfo.packageName;
65 mEnabled = packageinfo.applicationInfo.enabled;
66 mApkFile = new File(packageinfo.applicationInfo.sourceDir);
67 if (!mApkFile.exists()) {
69 mAppName = packageinfo.applicationInfo.packageName;
72 CharSequence label = packageinfo.applicationInfo.loadLabel(mLoader.getPm());
73 mAppName = label != null ? label.toString()
74 : packageinfo.applicationInfo.packageName;
76 mSystemApp = (packageinfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) > 0;
80 * @return the mAppName
82 public String getAppName() {
87 * @return the mAppPackageName
89 public String getAppPackageName() {
94 * @return the mAppIcon
96 public Drawable getAppIcon() {
97 if (mAppIcon == null || !mMounted) {
98 if (mApkFile.exists()) {
100 mAppIcon = mLoader.getPm().getApplicationIcon(mPackageName);
101 } catch (NameNotFoundException e) {
102 mAppIcon = mLoader.getContext().getResources()
103 .getDrawable(android.R.drawable.sym_def_app_icon);
106 return updateAppIconColor(mAppIcon);
109 return updateAppIconColor(mLoader.getContext().getResources()
110 .getDrawable(android.R.drawable.sym_def_app_icon));
116 public int getSubcategoriesMask() {
117 return mSubCategoriesMask;
120 public boolean isInSubcategory(int subcategoryId) {
121 return (mSubCategoriesMask & subcategoryId) > 0;
124 public boolean isInAllSubcategories(int subcategoryIds) {
125 return (mSubCategoriesMask & subcategoryIds) == subcategoryIds;
128 public boolean isEnabled() {
132 public void setEnabled(boolean state) {
134 updateAppIconColor(mAppIcon);
137 private Drawable updateAppIconColor(Drawable icon) {
138 // disabling and enabling apps in system application manager is
139 // available since API 4.0
141 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
143 icon.setColorFilter(null);
145 icon.setColorFilter(mGrayscaleFilter);
152 * @return the mSystemApp
154 public boolean isSystemApp() {
158 public void addSubcategory(int id) {
159 mSubCategoriesMask |= id;
163 * @return the mAppPackageName
166 public String toString() {
171 public boolean equals(Object o) {
172 if (o instanceof AppDetails) {
173 AppDetails appDetails = (AppDetails) o;
174 if (appDetails.getAppPackageName().equals(mPackageName)) {
182 * Perform inteligent comparison of application entry objects.
184 public static final Comparator<AppDetails> SMART_COMPARATOR = new Comparator<AppDetails>() {
186 public int compare(AppDetails object1, AppDetails object2) {
187 if (object1.mSystemApp) {
188 if (object2.mSystemApp)
189 return object1.mAppName.compareTo(object2.mAppName);
192 if (object2.mSystemApp)
194 return object1.mAppName.compareTo(object2.mAppName);