Merge branch 'material_buttons' of https://github.com/owncloud/android into material_fab
[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.support.v7.app.AppCompatActivity;
29 import android.text.method.ScrollingMovementMethod;
30 import android.view.View;
31 import android.view.ViewGroup;
32 import android.widget.ArrayAdapter;
33 import android.widget.ListAdapter;
34 import android.widget.ListView;
35 import android.widget.TextView;
36
37 import com.owncloud.android.R;
38 import com.owncloud.android.utils.DisplayUtils;
39
40
41 /**
42 * Activity showing a text message and, optionally, a couple list of single or paired text strings.
43 *
44 * Added to show explanations for notifications when the user clicks on them, and there no place
45 * better to show them.
46 */
47 public class GenericExplanationActivity extends AppCompatActivity {
48
49 public static final String EXTRA_LIST = GenericExplanationActivity.class.getCanonicalName() +
50 ".EXTRA_LIST";
51 public static final String EXTRA_LIST_2 = GenericExplanationActivity.class.getCanonicalName() +
52 ".EXTRA_LIST_2";
53 public static final String MESSAGE = GenericExplanationActivity.class.getCanonicalName() +
54 ".MESSAGE";
55
56
57 @Override
58 protected void onCreate(Bundle savedInstanceState) {
59 super.onCreate(savedInstanceState);
60
61 Intent intent = getIntent();
62 String message = intent.getStringExtra(MESSAGE);
63 ArrayList<String> list = intent.getStringArrayListExtra(EXTRA_LIST);
64 ArrayList<String> list2 = intent.getStringArrayListExtra(EXTRA_LIST_2);
65
66 setContentView(R.layout.generic_explanation);
67
68 if (message != null) {
69 TextView textView = (TextView) findViewById(R.id.message);
70 textView.setText(message);
71 textView.setMovementMethod(new ScrollingMovementMethod());
72 }
73
74 ListView listView = (ListView) findViewById(R.id.list);
75 if (list != null && list.size() > 0) {
76 //ListAdapter adapter = new ArrayAdapter<String>(this,
77 // android.R.layout.simple_list_item_1, list);
78 ListAdapter adapter = new ExplanationListAdapterView(this, list, list2);
79 listView.setAdapter(adapter);
80 } else {
81 listView.setVisibility(View.GONE);
82 }
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,
91 ArrayList<String> list2) {
92 super(context, android.R.layout.two_line_list_item, android.R.id.text1, list);
93 mList = list;
94 mList2 = list2;
95 }
96
97 @Override
98 public boolean isEnabled(int position) {
99 return false;
100 }
101
102 /**
103 * {@inheritDoc}
104 */
105 @Override
106 public View getView (int position, View convertView, ViewGroup parent) {
107 View view = super.getView(position, convertView, parent);
108 if (view != null) {
109 if (mList2 != null && mList2.size() > 0 && position >= 0 &&
110 position < mList2.size()) {
111 TextView text2 = (TextView) view.findViewById(android.R.id.text2);
112 if (text2 != null) {
113 text2.setText(mList2.get(position));
114 }
115 }
116 }
117 return view;
118 }
119 }
120
121 }