GenericExplanationActivity.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. package com.owncloud.android.ui.activity;
  21. import android.content.Context;
  22. import android.content.Intent;
  23. import android.os.Bundle;
  24. import android.support.annotation.NonNull;
  25. import android.support.v7.app.AppCompatActivity;
  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. import com.owncloud.android.R;
  34. import java.util.ArrayList;
  35. /**
  36. * Activity showing a text message and, optionally, a couple list of single or paired text strings.
  37. *
  38. * Added to show explanations for notifications when the user clicks on them, and there no place
  39. * better to show them.
  40. */
  41. public class GenericExplanationActivity extends AppCompatActivity {
  42. public static final String EXTRA_LIST = GenericExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST";
  43. public static final String EXTRA_LIST_2 = GenericExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST_2";
  44. public static final String MESSAGE = GenericExplanationActivity.class.getCanonicalName() + ".MESSAGE";
  45. @Override
  46. protected void onCreate(Bundle savedInstanceState) {
  47. super.onCreate(savedInstanceState);
  48. Intent intent = getIntent();
  49. String message = intent.getStringExtra(MESSAGE);
  50. ArrayList<String> list = intent.getStringArrayListExtra(EXTRA_LIST);
  51. ArrayList<String> list2 = intent.getStringArrayListExtra(EXTRA_LIST_2);
  52. setContentView(R.layout.generic_explanation);
  53. if (message != null) {
  54. TextView textView = (TextView) findViewById(R.id.message);
  55. textView.setText(message);
  56. textView.setMovementMethod(new ScrollingMovementMethod());
  57. }
  58. ListView listView = (ListView) findViewById(R.id.list);
  59. if (list != null && list.size() > 0) {
  60. //ListAdapter adapter = new ArrayAdapter<String>(this,
  61. // android.R.layout.simple_list_item_1, list);
  62. ListAdapter adapter = new ExplanationListAdapterView(this, list, list2);
  63. listView.setAdapter(adapter);
  64. } else {
  65. listView.setVisibility(View.GONE);
  66. }
  67. }
  68. public class ExplanationListAdapterView extends ArrayAdapter<String> {
  69. ArrayList<String> mList;
  70. ArrayList<String> mList2;
  71. ExplanationListAdapterView(Context context, ArrayList<String> list,
  72. ArrayList<String> list2) {
  73. super(context, android.R.layout.two_line_list_item, android.R.id.text1, list);
  74. mList = list;
  75. mList2 = list2;
  76. }
  77. @Override
  78. public boolean isEnabled(int position) {
  79. return false;
  80. }
  81. /**
  82. * {@inheritDoc}
  83. */
  84. @NonNull
  85. @Override
  86. public View getView (int position, View convertView, @NonNull ViewGroup parent) {
  87. View view = super.getView(position, convertView, parent);
  88. if (mList2 != null && mList2.size() > 0 && position >= 0 &&
  89. position < mList2.size()) {
  90. TextView text2 = (TextView) view.findViewById(android.R.id.text2);
  91. if (text2 != null) {
  92. text2.setText(mList2.get(position));
  93. }
  94. }
  95. return view;
  96. }
  97. }
  98. }