Migrate to gradle, appcompat as external dependency.
[mobilnebezpieczenstwo.git] / app / src / main / java / com / samsung / srpol / ui / PopupActivity.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.Category;
29 import com.samsung.srpol.data.Subcategory;
30 import com.samsung.srpol.loader.AppListLoader;
31
32 import android.content.Context;
33 import android.content.Intent;
34 import android.net.Uri;
35 import android.os.Bundle;
36 import android.support.v7.app.ActionBarActivity;
37 import android.view.LayoutInflater;
38 import android.view.View;
39 import android.view.ViewGroup;
40 import android.view.View.OnClickListener;
41 import android.widget.ArrayAdapter;
42 import android.widget.ImageButton;
43 import android.widget.ImageView;
44 import android.widget.ListView;
45 import android.widget.TextView;
46
47 public class PopupActivity extends ActionBarActivity {
48
49     public static final String POPUP_CATEGORY = "POPUP_CATEGORY";
50
51     private Category mCategory;
52     private ThreatsAdapter mAdapter;
53
54     @Override
55     protected void onCreate(Bundle savedInstanceState) {
56         super.onCreate(savedInstanceState);
57         setContentView(R.layout.activity_popup);
58         int categotyId = 0;
59         Intent intent = getIntent();
60         if (intent != null) {
61             categotyId = intent.getIntExtra(POPUP_CATEGORY, -1);
62         }
63
64         TextView header = (TextView) findViewById(R.id.header_text);
65         List<Category> containerList = AppListLoader.getCategories();
66         if (containerList != null && categotyId >= 0) {
67             mCategory = containerList.get(categotyId);
68             header.setText(getString(R.string.apps_that)
69                     + mCategory.getHeader());
70         }
71
72         ListView listview = (ListView) findViewById(R.id.threats_list);
73         mAdapter = new ThreatsAdapter(this);
74         for (Subcategory subCat : mCategory.getSubCategories())
75             mAdapter.add(subCat);
76         AnimationAdapter adapter = new AlphaInAnimationAdapter(mAdapter);
77         adapter.setAbsListView(listview);
78         listview.setAdapter(adapter);
79
80         ImageButton back = (ImageButton) findViewById(R.id.back_button);
81         back.setOnClickListener(new OnClickListener() {
82
83             @Override
84             public void onClick(View arg0) {
85                 finish();
86             }
87         });
88
89         ImageButton more = (ImageButton) findViewById(R.id.moreinfo_button);
90         more.setOnClickListener(new OnClickListener() {
91
92             @Override
93             public void onClick(View v) {
94                 Intent intent = new Intent(Intent.ACTION_VIEW, Uri
95                         .parse(mCategory.getLink()));
96                 startActivity(intent);
97             }
98         });
99     }
100
101     private class ThreatsAdapter extends ArrayAdapter<Subcategory> {
102
103         private class ViewHolder {
104             ImageView icon;
105             TextView description;
106         }
107
108         public ThreatsAdapter(Context context) {
109             super(context, R.layout.threats_list_item);
110         }
111
112         @Override
113         public boolean isEnabled(int position) {
114             return false;
115         }
116
117         @Override
118         public View getView(int position, View convertView, ViewGroup parent) {
119             ViewHolder holder;
120             if (convertView == null) {
121                 LayoutInflater inflater = getLayoutInflater();
122                 convertView = inflater.inflate(R.layout.threats_list_item,
123                         parent, false);
124                 holder = new ViewHolder();
125                 holder.icon = (ImageView) convertView
126                         .findViewById(R.id.threat_icon);
127                 holder.description = (TextView) convertView
128                         .findViewById(R.id.threat_text);
129                 convertView.setTag(holder);
130             } else {
131                 holder = (ViewHolder) convertView.getTag();
132             }
133
134             Subcategory item = getItem(position);
135
136             holder.icon.setImageDrawable(item.getIconDrawable());
137             holder.description.setText(item.getDescription());
138             holder.description.setTextColor(getResources().getColor(
139                     android.R.color.white));
140
141             return convertView;
142         }
143     }
144
145 }