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