2 * ownCloud Android client application
4 * Copyright (C) 2015 ownCloud Inc.
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.
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.
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/>.
20 package com
.owncloud
.android
.ui
.dialog
;
22 import android
.app
.AlertDialog
;
23 import android
.app
.Dialog
;
24 import android
.content
.DialogInterface
;
25 import android
.os
.Bundle
;
26 import android
.support
.v4
.app
.DialogFragment
;
27 import android
.webkit
.WebView
;
29 import com
.owncloud
.android
.R
;
30 import com
.owncloud
.android
.utils
.DisplayUtils
;
34 * Dialog to show the contents of res/raw/CHANGELOG.txt
36 public class ChangelogDialog
extends DialogFragment
{
38 private static final String ARG_CANCELABLE
= ChangelogDialog
.class.getCanonicalName() +
43 * Public factory method to get dialog instances.
45 * @param cancelable If 'true', the dialog can be cancelled by the user input
46 * (BACK button, touch outside...)
47 * @return New dialog instance, ready to show.
49 public static ChangelogDialog
newInstance(boolean cancelable
) {
50 ChangelogDialog fragment
= new ChangelogDialog();
51 Bundle args
= new Bundle();
52 args
.putBoolean(ARG_CANCELABLE
, cancelable
);
53 fragment
.setArguments(args
);
62 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
63 /// load the custom view to insert in the dialog, between title and
64 WebView webview
= new WebView(getActivity());
65 webview
.loadUrl("file:///android_res/raw/" +
66 getResources().getResourceEntryName(R
.raw
.changelog
) + ".html");
69 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity());
71 Dialog dialog
= builder
.setView(webview
)
72 .setIcon(DisplayUtils
.getSeasonalIconId())
73 //.setTitle(R.string.whats_new)
74 .setPositiveButton(R
.string
.common_ok
,
75 new DialogInterface
.OnClickListener() {
77 public void onClick(DialogInterface dialog
, int which
) {
82 dialog
.setCancelable(getArguments().getBoolean(ARG_CANCELABLE
));
90 public View onCreateView(LayoutInflater inflater, ViewGroup container,
91 Bundle savedInstanceState) {
92 /// load the custom layout
93 View view = inflater.inflate(R.layout.fragment_changelog, container);
94 mEditText = (EditText) view.findViewById(R.id.txt_your_name);
95 getDialog().setTitle(R.string.whats_new);
97 /// read full contents of the change log file (don't make it too big)
98 InputStream changeLogStream = getResources().openRawResource(R.raw.changelog);
99 Scanner scanner = new java.util.Scanner(changeLogStream).useDelimiter("\\A");
100 String text = scanner.hasNext() ? scanner.next() : "";
102 /// make clickable the links in the change log file
103 SpannableString sText = new SpannableString(text);
104 Linkify.addLinks(sText, Linkify.ALL);