GenericExplanationActivity.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* ownCloud Android client application
  2. * Copyright (C) 2012-2013 ownCloud Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. package com.owncloud.android.ui.activity;
  18. import java.util.ArrayList;
  19. import android.content.Context;
  20. import android.content.Intent;
  21. import android.os.Bundle;
  22. import android.text.method.ScrollingMovementMethod;
  23. import android.view.View;
  24. import android.view.ViewGroup;
  25. import android.widget.ArrayAdapter;
  26. import android.widget.ListAdapter;
  27. import android.widget.ListView;
  28. import android.widget.TextView;
  29. import com.actionbarsherlock.app.SherlockFragmentActivity;
  30. import com.owncloud.android.R;
  31. /**
  32. * Activity showing a text message and, optionally, a couple list of single or paired text strings.
  33. *
  34. * Added to show explanations for notifications when the user clicks on them, and there no place
  35. * better to show them.
  36. *
  37. * @author David A. Velasco
  38. */
  39. public class GenericExplanationActivity extends SherlockFragmentActivity {
  40. public static final String EXTRA_LIST = GenericExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST";
  41. public static final String EXTRA_LIST_2 = GenericExplanationActivity.class.getCanonicalName() + ".EXTRA_LIST_2";
  42. public static final String MESSAGE = GenericExplanationActivity.class.getCanonicalName() + ".MESSAGE";
  43. @Override
  44. protected void onCreate(Bundle savedInstanceState) {
  45. super.onCreate(savedInstanceState);
  46. Intent intent = getIntent();
  47. String message = intent.getStringExtra(MESSAGE);
  48. ArrayList<String> list = intent.getStringArrayListExtra(EXTRA_LIST);
  49. ArrayList<String> list2 = intent.getStringArrayListExtra(EXTRA_LIST_2);
  50. setContentView(R.layout.generic_explanation);
  51. if (message != null) {
  52. TextView textView = (TextView) findViewById(R.id.message);
  53. textView.setText(message);
  54. textView.setMovementMethod(new ScrollingMovementMethod());
  55. }
  56. ListView listView = (ListView) findViewById(R.id.list);
  57. if (list != null && list.size() > 0) {
  58. //ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
  59. ListAdapter adapter = new ExplanationListAdapterView(this, list, list2);
  60. listView.setAdapter(adapter);
  61. } else {
  62. listView.setVisibility(View.GONE);
  63. }
  64. }
  65. public class ExplanationListAdapterView extends ArrayAdapter<String> {
  66. ArrayList<String> mList;
  67. ArrayList<String> mList2;
  68. ExplanationListAdapterView(Context context, ArrayList<String> list, ArrayList<String> list2) {
  69. super(context, android.R.layout.two_line_list_item, android.R.id.text1, list);
  70. mList = list;
  71. mList2 = list2;
  72. }
  73. @Override
  74. public boolean isEnabled(int position) {
  75. return false;
  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. }