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;
23 import java.util.List;
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;
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;
49 public class AppInfoActivity extends ActionBarActivity implements OnAppRemoveListener {
50 public static final String APP_PACKAGE_NAME = "APP_PACKAGE_NAME";
52 private AppDetails mAppDetails;
53 private String mPackageName = null;
54 private ThreatsArrayAdapter mAdapter;
57 protected void onCreate(Bundle savedInstanceState) {
58 super.onCreate(savedInstanceState);
59 setContentView(R.layout.activity_app_info);
60 Intent intent = getIntent();
63 .getStringExtra(AppInfoActivity.APP_PACKAGE_NAME);
65 mAppDetails = AppListLoader.getAppDetails(mPackageName);
66 if(mAppDetails == null){
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());
74 grayoutText(textView);
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);
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);
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);
96 moreInfoButton.setVisibility(View.GONE);
97 systemAppTextView.setVisibility(View.GONE);
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);
104 uninstallButton.setOnClickListener(new OnClickListener() {
107 public void onClick(View v) {
108 Utils.showInstalledAppDetails(getApplicationContext(), mPackageName);
111 moreInfoButton.setOnClickListener(new OnClickListener() {
114 public void onClick(View v) {
115 Utils.startBrowser(getApplicationContext(), getResources().getString(R.string.app_info_more_info));
118 AppListLoader.setOnChangeListener(this);
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));
129 systemAppIcon.setImageDrawable(Utils
130 .getmSystemIconDisable(this));
133 systemAppIcon.setVisibility(View.INVISIBLE);
139 protected void onDestroy() {
140 AppListLoader.setOnChangeListener(null);
144 class ThreatsArrayAdapter extends ArrayAdapter<Subcategory> {
146 public ThreatsArrayAdapter(Context context, List<Subcategory> resources) {
147 super(context, R.layout.threats_list_item, resources);
151 public TextView textView;
152 public ImageView imageView;
156 public boolean isEnabled(int position) {
161 public View getView(int position, View convertView, ViewGroup parent) {
163 if (convertView == null) {
164 convertView = getLayoutInflater().inflate(R.layout.threats_list_item,
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);
173 holder = (ViewHolder) convertView.getTag();
175 Subcategory subgroupContainer = getItem(position);
176 if (subgroupContainer != null) {
178 .setImageDrawable(subgroupContainer.getDarkIcon());
179 holder.textView.setText(subgroupContainer.getDescription());
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));
193 textView.setTextColor(getResources().getColor(
194 R.color.disabled_app_name));
199 public boolean onCreateOptionsMenu(Menu menu) {
204 public void onPackageRemoved(String packageName) {
205 if (mPackageName.equals(packageName)) {