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