d6849ffafefa5196393366737bbc901c6ed24c3e
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / ExplanationActivity.java
1 package com.owncloud.android.ui.activity;
2
3 import java.util.ArrayList;
4
5 import android.content.Context;
6 import android.content.Intent;
7 import android.os.Bundle;
8 import android.view.View;
9 import android.view.ViewGroup;
10 import android.widget.ArrayAdapter;
11 import android.widget.ListAdapter;
12 import android.widget.ListView;
13 import android.widget.TextView;
14
15 import com.actionbarsherlock.app.SherlockFragmentActivity;
16 import com.owncloud.android.R;
17
18 /**
19 * Activity showing a text message and, optionally, a couple of scrollable lists of texts.
20 *
21 * Added to show explanations for notifications when the user clicks on them, and there no place
22 * better to show them.
23 *
24 * @author David A. Velasco
25 */
26 public class ExplanationActivity extends SherlockFragmentActivity {
27
28 public static final String EXTRA_LIST = ExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST";
29 public static final String EXTRA_LIST_2 = ExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST_2";
30 public static final String MESSAGE = ExplanationActivity.class.getCanonicalName() + ".MESSAGE";
31
32
33 @Override
34 protected void onCreate(Bundle savedInstanceState) {
35 super.onCreate(savedInstanceState);
36
37 Intent intent = getIntent();
38 String message = intent.getStringExtra(MESSAGE);
39 ArrayList<String> list = intent.getStringArrayListExtra(EXTRA_LIST);
40 ArrayList<String> list2 = intent.getStringArrayListExtra(EXTRA_LIST_2);
41
42 setContentView(R.layout.explanation);
43
44 if (message != null) {
45 TextView textView = (TextView) findViewById(R.id.message);
46 textView.setText(message);
47 }
48
49 ListView listView = (ListView) findViewById(R.id.list);
50 if (list != null && list.size() > 0) {
51 //ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
52 ListAdapter adapter = new ExplanationListAdapterView(this, list, list2);
53 listView.setAdapter(adapter);
54 } else {
55 listView.setVisibility(View.GONE);
56 }
57 }
58
59 public class ExplanationListAdapterView extends ArrayAdapter<String> {
60
61 ArrayList<String> mList;
62 ArrayList<String> mList2;
63
64 ExplanationListAdapterView(Context context, ArrayList<String> list, ArrayList<String> list2) {
65 //super(context, android.R.layout.two_line_list_item, android.R.id.text1, list);
66 super(context, android.R.layout.two_line_list_item, android.R.id.text1, list);
67 mList = list;
68 mList2 = list2;
69 }
70
71 @Override
72 public boolean isEnabled(int position) {
73 return false;
74 }
75
76 /**
77 * {@inheritDoc}
78 */
79 @Override
80 public View getView (int position, View convertView, ViewGroup parent) {
81 View view = super.getView(position, convertView, parent);
82 if (view != null) {
83 if (mList2 != null && mList2.size() > 0 && position >= 0 && position < mList2.size()) {
84 TextView text2 = (TextView) view.findViewById(android.R.id.text2);
85 if (text2 != null) {
86 text2.setText(mList2.get(position));
87 }
88 }
89 }
90 return view;
91 }
92 }
93
94 }