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