c29ed306165475dbeba8861a9deada3dc8e5e8df
[mobilnebezpieczenstwo.git] / src / com / samsung / srpol / ui / AppInfoActivity.java
1 /*
2    Copyright (C) 2014  Samsung Electronics Polska Sp. z o.o.
3
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
9
10                 http://www.gnu.org/licenses/agpl-3.0.txt
11
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.
16
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/>.
19 */
20
21 package com.samsung.srpol.ui;
22
23 import java.util.List;
24
25 import com.nhaarman.listviewanimations.appearance.AnimationAdapter;
26 import com.nhaarman.listviewanimations.appearance.simple.AlphaInAnimationAdapter;
27 import com.samsung.srpol.R;
28 import com.samsung.srpol.data.Subcategory;
29 import com.samsung.srpol.loader.AppDetails;
30 import com.samsung.srpol.loader.AppListLoader;
31 import com.samsung.srpol.loader.AppListLoader.OnAppRemoveListener;
32 import com.samsung.srpol.utils.Utils;
33
34 import android.support.v7.app.ActionBarActivity;
35 import android.content.Context;
36 import android.content.Intent;
37 import android.os.Build;
38 import android.os.Bundle;
39 import android.view.Menu;
40 import android.view.View;
41 import android.view.View.OnClickListener;
42 import android.view.ViewGroup;
43 import android.widget.ArrayAdapter;
44 import android.widget.ImageButton;
45 import android.widget.ImageView;
46 import android.widget.ListView;
47 import android.widget.TextView;
48
49 public class AppInfoActivity extends ActionBarActivity implements OnAppRemoveListener {
50     public static final String APP_PACKAGE_NAME = "APP_PACKAGE_NAME";
51     
52     private AppDetails mAppDetails;
53     private String mPackageName = null;
54     private ThreatsArrayAdapter mAdapter;
55
56     @Override
57     protected void onCreate(Bundle savedInstanceState) {
58         super.onCreate(savedInstanceState);
59         setContentView(R.layout.activity_app_info);
60         Intent intent = getIntent();
61         if (intent != null) {
62             mPackageName = intent
63                     .getStringExtra(AppInfoActivity.APP_PACKAGE_NAME);
64         }
65         mAppDetails = AppListLoader.getAppDetails(mPackageName);
66         if(mAppDetails == null){
67             return;
68         }
69         ImageView imageView = (ImageView) findViewById(R.id.app_icon);
70         imageView.setImageDrawable(mAppDetails.getAppIcon());
71         TextView textView = (TextView) findViewById(R.id.app_name);
72         textView.setText(mAppDetails.getAppName());
73
74         grayoutText(textView);
75
76         ListView listView = (ListView) findViewById(R.id.threats_list);
77         mAdapter = new ThreatsArrayAdapter(getApplicationContext(),
78                 AppListLoader.getSubcategoriesOfMask(mAppDetails
79                         .getSubcategoriesMask()));
80         AnimationAdapter adapter = new AlphaInAnimationAdapter(mAdapter);
81         adapter.setAbsListView(listView);
82         listView.setAdapter(adapter);
83
84         ImageButton uninstallButton = (ImageButton) findViewById(R.id.uninstall_button);
85         ImageButton moreInfoButton = (ImageButton) findViewById(R.id.more_info_button);
86         TextView systemAppTextView = (TextView) findViewById(R.id.system_app_text);
87         View activityLayout = findViewById(R.id.container);
88         if (mAppDetails.isSystemApp()) {
89             moreInfoButton.setVisibility(View.VISIBLE);
90             systemAppTextView.setVisibility(View.VISIBLE);
91             uninstallButton
92                     .setImageResource(R.drawable.app_info_settings_button);
93             uninstallButton.setContentDescription(getResources().getText(R.string.app_detail_settings_button));
94             activityLayout.setBackgroundResource(R.color.grayout_list_item_bg);
95         } else {
96             moreInfoButton.setVisibility(View.GONE);
97             systemAppTextView.setVisibility(View.GONE);
98             uninstallButton
99                     .setImageResource(R.drawable.app_info_uninstall_button);
100             uninstallButton.setContentDescription(getResources().getText(R.string.app_detail_uninstall_button));
101             activityLayout.setBackgroundResource(R.color.app_detail_bg);
102         }
103
104         uninstallButton.setOnClickListener(new OnClickListener() {
105
106             @Override
107             public void onClick(View v) {
108                 Utils.showInstalledAppDetails(getApplicationContext(), mPackageName);
109             }
110         });
111         moreInfoButton.setOnClickListener(new OnClickListener() {
112
113             @Override
114             public void onClick(View v) {
115                 Utils.startBrowser(getApplicationContext(), getResources().getString(R.string.app_info_more_info));
116             }
117         });
118         AppListLoader.setOnChangeListener(this);
119     }
120
121     @Override
122     protected void onResume() {
123         ImageView systemAppIcon = (ImageView) findViewById(R.id.list_system_app_icon);
124         if (mAppDetails.isSystemApp()) {
125             systemAppIcon.setVisibility(View.VISIBLE);
126             if (mAppDetails.isEnabled()) {
127                 systemAppIcon.setImageDrawable(Utils.getmSystemIcon(this));
128             } else {
129                 systemAppIcon.setImageDrawable(Utils
130                         .getmSystemIconDisable(this));
131             }
132         } else {
133             systemAppIcon.setVisibility(View.INVISIBLE);
134         }
135         super.onResume();
136     }
137
138     @Override
139     protected void onDestroy() {
140         AppListLoader.setOnChangeListener(null);
141         super.onDestroy();
142     }
143
144     class ThreatsArrayAdapter extends ArrayAdapter<Subcategory> {
145
146         public ThreatsArrayAdapter(Context context, List<Subcategory> resources) {
147             super(context, R.layout.threats_list_item, resources);
148         }
149
150         class ViewHolder {
151             public TextView textView;
152             public ImageView imageView;
153         }
154
155         @Override
156         public boolean isEnabled(int position) {
157             return false;
158         }
159         
160         @Override
161         public View getView(int position, View convertView, ViewGroup parent) {
162             ViewHolder holder;
163             if (convertView == null) {
164                 convertView = getLayoutInflater().inflate(R.layout.threats_list_item,
165                         parent, false);
166                 holder = new ViewHolder();
167                 holder.imageView = (ImageView) convertView
168                         .findViewById(R.id.threat_icon);
169                 holder.textView = (TextView) convertView
170                         .findViewById(R.id.threat_text);
171                 convertView.setTag(holder);
172             } else {
173                 holder = (ViewHolder) convertView.getTag();
174             }
175             Subcategory subgroupContainer = getItem(position);
176             if (subgroupContainer != null) {
177                 holder.imageView
178                         .setImageDrawable(subgroupContainer.getDarkIcon());
179                 holder.textView.setText(subgroupContainer.getDescription());
180             }
181             return convertView;
182         }
183     }
184
185     private void grayoutText(TextView textView){
186      // disabling and enabling apps in system application manager is
187         // available since API 4.0
188         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
189             if (mAppDetails.isEnabled()) {
190                 textView.setTextColor(getResources().getColor(
191                         android.R.color.black));
192             } else {
193                 textView.setTextColor(getResources().getColor(
194                         R.color.disabled_app_name));
195             }
196         }
197     }
198     @Override
199     public boolean onCreateOptionsMenu(Menu menu) {
200         return true;
201     }
202
203     @Override
204     public void onPackageRemoved(String packageName) {
205         if (mPackageName.equals(packageName)) {
206             finish();
207         }
208     }
209
210 }