summaryrefslogtreecommitdiffstats
path: root/android/source/src/java/org/libreoffice/AboutDialogFragment.java
diff options
context:
space:
mode:
authoraleksandar-stefanovic <theonewithideas@gmail.com>2017-01-15 10:45:56 +0100
committerAleksandar Stefanović <theonewithideas@gmail.com>2017-01-26 12:22:14 +0000
commit8802ebd5172ec4bc412a59d136c82b77ab452281 (patch)
tree2e495ad0758bc757b25bdbcd679edca10953f494 /android/source/src/java/org/libreoffice/AboutDialogFragment.java
parentRemove dead code (diff)
downloadcore-8802ebd5172ec4bc412a59d136c82b77ab452281.tar.gz
core-8802ebd5172ec4bc412a59d136c82b77ab452281.zip
Moved About dialog to DialogFragment
This makes the dialog more modular, and it takes no parameters instead of two. This is in the preparation of making the classes more independent on each-other's states, which is very important. Also, this follows the Android way of workflow better, since there is no "wrapper" class around the dialog, but instead the dialog is called directly. Change-Id: I7571480a040efaf202fae3929cfe76d65c19653e Reviewed-on: https://gerrit.libreoffice.org/33086 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Aleksandar Stefanović <theonewithideas@gmail.com>
Diffstat (limited to 'android/source/src/java/org/libreoffice/AboutDialogFragment.java')
-rw-r--r--android/source/src/java/org/libreoffice/AboutDialogFragment.java108
1 files changed, 108 insertions, 0 deletions
diff --git a/android/source/src/java/org/libreoffice/AboutDialogFragment.java b/android/source/src/java/org/libreoffice/AboutDialogFragment.java
new file mode 100644
index 000000000000..1f4e7438d2ce
--- /dev/null
+++ b/android/source/src/java/org/libreoffice/AboutDialogFragment.java
@@ -0,0 +1,108 @@
+/*
+ *
+ * * This file is part of the LibreOffice project.
+ * * This Source Code Form is subject to the terms of the Mozilla Public
+ * * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+package org.libreoffice;
+
+import android.annotation.SuppressLint;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.ComponentName;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.v4.app.DialogFragment;
+import android.view.View;
+import android.widget.TextView;
+
+import java.io.File;
+
+public class AboutDialogFragment extends DialogFragment {
+
+ private static final String DEFAULT_DOC_PATH = "/assets/example.odt";
+
+
+ @NonNull @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+
+ @SuppressLint("InflateParams") //suppressed because the view will be placed in a dialog
+ View messageView = getActivity().getLayoutInflater().inflate(R.layout.about, null, false);
+
+ // When linking text, force to always use default color. This works
+ // around a pressed color state bug.
+ TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
+ int defaultColor = textView.getTextColors().getDefaultColor();
+ textView.setTextColor(defaultColor);
+
+ // Take care of placeholders in the version and vendor text views.
+ TextView versionView = (TextView)messageView.findViewById(R.id.about_version);
+ TextView vendorView = (TextView)messageView.findViewById(R.id.about_vendor);
+ try
+ {
+ String versionName = getActivity().getPackageManager()
+ .getPackageInfo(getActivity().getPackageName(), 0).versionName;
+ String[] tokens = versionName.split("/");
+ if (tokens.length == 3)
+ {
+ String version = versionView.getText().toString();
+ String vendor = vendorView.getText().toString();
+ version = version.replace("$VERSION", tokens[0]);
+ version = version.replace("$BUILDID", tokens[1]);
+ vendor = vendor.replace("$VENDOR", tokens[2]);
+ versionView.setText(version);
+ vendorView.setText(vendor);
+ }
+ else
+ throw new PackageManager.NameNotFoundException();
+ }
+ catch (PackageManager.NameNotFoundException e)
+ {
+ versionView.setText("");
+ vendorView.setText("");
+ }
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder .setIcon(R.drawable.lo_icon)
+ .setTitle(R.string.app_name)
+ .setView(messageView)
+ .setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ loadFromAbout("/assets/license.txt");
+ dialog.dismiss();
+ }
+ })
+ .setPositiveButton(R.string.about_notice, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ loadFromAbout("/assets/notice.txt");
+ dialog.dismiss();
+ }
+ })
+ .setNeutralButton(R.string.about_moreinfo, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ loadFromAbout(DEFAULT_DOC_PATH);
+ dialog.dismiss();
+ }
+ });
+
+ return builder.create();
+ }
+
+ private void loadFromAbout(String input) {
+ Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(new File(input)));
+ String packageName = getActivity().getApplicationContext().getPackageName();
+ ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName());
+ i.setComponent(componentName);
+ getActivity().startActivity(i);
+ }
+}