ChangelogDialog.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.dialog;
  18. import android.app.AlertDialog;
  19. import android.app.Dialog;
  20. import android.content.DialogInterface;
  21. import android.os.Bundle;
  22. import android.webkit.WebView;
  23. import com.actionbarsherlock.app.SherlockDialogFragment;
  24. import com.owncloud.android.R;
  25. import com.owncloud.android.utils.DisplayUtils;
  26. /**
  27. * Dialog to show the contents of res/raw/CHANGELOG.txt
  28. */
  29. public class ChangelogDialog extends SherlockDialogFragment {
  30. private static final String ARG_CANCELABLE = ChangelogDialog.class.getCanonicalName() + ".ARG_CANCELABLE";
  31. /**
  32. * Public factory method to get dialog instances.
  33. *
  34. * @param cancelable If 'true', the dialog can be cancelled by the user input (BACK button, touch outside...)
  35. * @return New dialog instance, ready to show.
  36. */
  37. public static ChangelogDialog newInstance(boolean cancelable) {
  38. ChangelogDialog fragment = new ChangelogDialog();
  39. Bundle args = new Bundle();
  40. args.putBoolean(ARG_CANCELABLE, cancelable);
  41. fragment.setArguments(args);
  42. return fragment;
  43. }
  44. /**
  45. * {@inheritDoc}
  46. */
  47. @Override
  48. public Dialog onCreateDialog(Bundle savedInstanceState) {
  49. /// load the custom view to insert in the dialog, between title and
  50. WebView webview = new WebView(getActivity());
  51. webview.loadUrl("file:///android_res/raw/" + getResources().getResourceEntryName(R.raw.changelog) + ".html");
  52. /// build the dialog
  53. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
  54. Dialog dialog = builder.setView(webview)
  55. .setIcon(DisplayUtils.getSeasonalIconId())
  56. //.setTitle(R.string.whats_new)
  57. .setPositiveButton(R.string.common_ok,
  58. new DialogInterface.OnClickListener() {
  59. @Override
  60. public void onClick(DialogInterface dialog, int which) {
  61. dialog.dismiss();
  62. }
  63. }).create();
  64. dialog.setCancelable(getArguments().getBoolean(ARG_CANCELABLE));
  65. return dialog;
  66. }
  67. /**
  68. * {@inheritDoc}
  69. *-/
  70. @Override
  71. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  72. /// load the custom layout
  73. View view = inflater.inflate(R.layout.fragment_changelog, container);
  74. mEditText = (EditText) view.findViewById(R.id.txt_your_name);
  75. getDialog().setTitle(R.string.whats_new);
  76. /// read full contents of the change log file (don't make it too big)
  77. InputStream changeLogStream = getResources().openRawResource(R.raw.changelog);
  78. Scanner scanner = new java.util.Scanner(changeLogStream).useDelimiter("\\A");
  79. String text = scanner.hasNext() ? scanner.next() : "";
  80. /// make clickable the links in the change log file
  81. SpannableString sText = new SpannableString(text);
  82. Linkify.addLinks(sText, Linkify.ALL);
  83. return view;
  84. }
  85. */
  86. }