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