Merge remote-tracking branch 'upstream/develop' into
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / GenericExplanationActivity.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.ui.activity;
19
20 import java.util.ArrayList;
21
22 import android.content.Context;
23 import android.content.Intent;
24 import android.os.Bundle;
25 import android.text.method.ScrollingMovementMethod;
26 import android.view.View;
27 import android.view.ViewGroup;
28 import android.widget.ArrayAdapter;
29 import android.widget.ListAdapter;
30 import android.widget.ListView;
31 import android.widget.TextView;
32
33 import com.actionbarsherlock.app.ActionBar;
34 import com.actionbarsherlock.app.SherlockFragmentActivity;
35 import com.owncloud.android.R;
36 import com.owncloud.android.utils.DisplayUtils;
37
38
39 /**
40 * Activity showing a text message and, optionally, a couple list of single or paired text strings.
41 *
42 * Added to show explanations for notifications when the user clicks on them, and there no place
43 * better to show them.
44 *
45 * @author David A. Velasco
46 */
47 public class GenericExplanationActivity extends SherlockFragmentActivity {
48
49 public static final String EXTRA_LIST = GenericExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST";
50 public static final String EXTRA_LIST_2 = GenericExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST_2";
51 public static final String MESSAGE = GenericExplanationActivity.class.getCanonicalName() + ".MESSAGE";
52
53
54 @Override
55 protected void onCreate(Bundle savedInstanceState) {
56 super.onCreate(savedInstanceState);
57
58 Intent intent = getIntent();
59 String message = intent.getStringExtra(MESSAGE);
60 ArrayList<String> list = intent.getStringArrayListExtra(EXTRA_LIST);
61 ArrayList<String> list2 = intent.getStringArrayListExtra(EXTRA_LIST_2);
62
63 setContentView(R.layout.generic_explanation);
64
65 if (message != null) {
66 TextView textView = (TextView) findViewById(R.id.message);
67 textView.setText(message);
68 textView.setMovementMethod(new ScrollingMovementMethod());
69 }
70
71 ListView listView = (ListView) findViewById(R.id.list);
72 if (list != null && list.size() > 0) {
73 //ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
74 ListAdapter adapter = new ExplanationListAdapterView(this, list, list2);
75 listView.setAdapter(adapter);
76 } else {
77 listView.setVisibility(View.GONE);
78 }
79
80 ActionBar actionBar = getSupportActionBar();
81 actionBar.setIcon(DisplayUtils.getSeasonalIconId());
82 }
83
84 public class ExplanationListAdapterView extends ArrayAdapter<String> {
85
86 ArrayList<String> mList;
87 ArrayList<String> mList2;
88
89 ExplanationListAdapterView(Context context, ArrayList<String> list, ArrayList<String> list2) {
90 super(context, android.R.layout.two_line_list_item, android.R.id.text1, list);
91 mList = list;
92 mList2 = list2;
93 }
94
95 @Override
96 public boolean isEnabled(int position) {
97 return false;
98 }
99
100 /**
101 * {@inheritDoc}
102 */
103 @Override
104 public View getView (int position, View convertView, ViewGroup parent) {
105 View view = super.getView(position, convertView, parent);
106 if (view != null) {
107 if (mList2 != null && mList2.size() > 0 && position >= 0 && position < mList2.size()) {
108 TextView text2 = (TextView) view.findViewById(android.R.id.text2);
109 if (text2 != null) {
110 text2.setText(mList2.get(position));
111 }
112 }
113 }
114 return view;
115 }
116 }
117
118 }