GenericExplanationActivity.java 4.4 KB

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