ChangelogDialog.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * Copyright (C) 2015 ownCloud Inc.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2,
  8. * as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. package com.owncloud.android.ui.dialog;
  20. import android.support.v7.app.AlertDialog;
  21. import android.app.Dialog;
  22. import android.content.DialogInterface;
  23. import android.os.Bundle;
  24. import android.support.v4.app.DialogFragment;
  25. import android.webkit.WebView;
  26. import com.owncloud.android.R;
  27. /**
  28. * Dialog to show the contents of res/raw/CHANGELOG.txt
  29. */
  30. public class ChangelogDialog extends DialogFragment {
  31. private static final String ARG_CANCELABLE = ChangelogDialog.class.getCanonicalName() +
  32. ".ARG_CANCELABLE";
  33. /**
  34. * Public factory method to get dialog instances.
  35. *
  36. * @param cancelable If 'true', the dialog can be cancelled by the user input
  37. * (BACK button, touch outside...)
  38. * @return New dialog instance, ready to show.
  39. */
  40. public static ChangelogDialog newInstance(boolean cancelable) {
  41. ChangelogDialog fragment = new ChangelogDialog();
  42. Bundle args = new Bundle();
  43. args.putBoolean(ARG_CANCELABLE, cancelable);
  44. fragment.setArguments(args);
  45. return fragment;
  46. }
  47. /**
  48. * {@inheritDoc}
  49. */
  50. @Override
  51. public Dialog onCreateDialog(Bundle savedInstanceState) {
  52. /// load the custom view to insert in the dialog, between title and
  53. WebView webview = new WebView(getActivity());
  54. webview.loadUrl("file:///android_res/raw/" +
  55. getResources().getResourceEntryName(R.raw.changelog) + ".html");
  56. /// build the dialog
  57. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  58. Dialog dialog = builder.setView(webview)
  59. .setIcon(R.mipmap.ic_launcher)
  60. //.setTitle(R.string.whats_new)
  61. .setPositiveButton(R.string.common_ok,
  62. new DialogInterface.OnClickListener() {
  63. @Override
  64. public void onClick(DialogInterface dialog, int which) {
  65. dialog.dismiss();
  66. }
  67. }).create();
  68. dialog.setCancelable(getArguments().getBoolean(ARG_CANCELABLE));
  69. return dialog;
  70. }
  71. /**
  72. * {@inheritDoc}
  73. *-/
  74. @Override
  75. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  76. Bundle savedInstanceState) {
  77. /// load the custom layout
  78. View view = inflater.inflate(R.layout.fragment_changelog, container);
  79. mEditText = (EditText) view.findViewById(R.id.txt_your_name);
  80. getDialog().setTitle(R.string.whats_new);
  81. /// read full contents of the change log file (don't make it too big)
  82. InputStream changeLogStream = getResources().openRawResource(R.raw.changelog);
  83. Scanner scanner = new java.util.Scanner(changeLogStream).useDelimiter("\\A");
  84. String text = scanner.hasNext() ? scanner.next() : "";
  85. /// make clickable the links in the change log file
  86. SpannableString sText = new SpannableString(text);
  87. Linkify.addLinks(sText, Linkify.ALL);
  88. return view;
  89. }
  90. */
  91. }