LibreOffice Module android (master) 1
AboutDialogFragment.java
Go to the documentation of this file.
1/*
2 *
3 * * This file is part of the LibreOffice project.
4 * * This Source Code Form is subject to the terms of the Mozilla Public
5 * * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 */
9
10package org.libreoffice;
11
12import android.annotation.SuppressLint;
13import android.app.AlertDialog;
14import android.app.Dialog;
15import android.content.ComponentName;
16import android.content.DialogInterface;
17import android.content.Intent;
18import android.content.pm.PackageManager;
19import android.net.Uri;
20import android.os.Bundle;
21import androidx.annotation.NonNull;
22import androidx.fragment.app.DialogFragment;
23import android.text.Html;
24import android.text.Spanned;
25import android.text.method.LinkMovementMethod;
26import android.view.View;
27import android.widget.TextView;
28
29public class AboutDialogFragment extends DialogFragment {
30
31 @NonNull @Override
32 public Dialog onCreateDialog(Bundle savedInstanceState) {
33
34 @SuppressLint("InflateParams") //suppressed because the view will be placed in a dialog
35 View messageView = getActivity().getLayoutInflater().inflate(R.layout.about, null, false);
36
37 // When linking text, force to always use default color. This works
38 // around a pressed color state bug.
39 TextView textView = messageView.findViewById(R.id.about_credits);
40 int defaultColor = textView.getTextColors().getDefaultColor();
41 textView.setTextColor(defaultColor);
42
43 // Take care of placeholders in the version and vendor text views.
44 TextView versionView = messageView.findViewById(R.id.about_version);
45 TextView vendorView = messageView.findViewById(R.id.about_vendor);
46 try
47 {
48 String versionName = getActivity().getPackageManager()
49 .getPackageInfo(getActivity().getPackageName(), 0).versionName;
50 String[] tokens = versionName.split("/");
51 if (tokens.length == 3)
52 {
53 String version = String.format(versionView.getText().toString().replace("\n", "<br/>"),
54 tokens[0], "<a href=\"https://hub.libreoffice.org/git-core/" + tokens[1] + "\">" + tokens[1] + "</a>");
55 @SuppressWarnings("deprecation") // since 24 with additional option parameter
56 Spanned versionString = Html.fromHtml(version);
57 versionView.setText(versionString);
58 versionView.setMovementMethod(LinkMovementMethod.getInstance());
59 String vendor = vendorView.getText().toString();
60 vendor = vendor.replace("$VENDOR", tokens[2]);
61 vendorView.setText(vendor);
62 }
63 else
64 throw new PackageManager.NameNotFoundException();
65 }
66 catch (PackageManager.NameNotFoundException e)
67 {
68 versionView.setText("");
69 vendorView.setText("");
70 }
71
72 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
73 builder .setIcon(R.drawable.lo_icon)
74 .setTitle(R.string.app_name)
75 .setView(messageView)
76 .setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
77 @Override
78 public void onClick(DialogInterface dialog, int id) {
79 loadFromAbout(R.raw.license);
80 dialog.dismiss();
81 }
82 })
83 .setPositiveButton(R.string.about_notice, new DialogInterface.OnClickListener() {
84 @Override
85 public void onClick(DialogInterface dialog, int id) {
86 loadFromAbout(R.raw.notice);
87 dialog.dismiss();
88 }
89 })
90 .setNeutralButton(R.string.about_moreinfo, new DialogInterface.OnClickListener() {
91 @Override
92 public void onClick(DialogInterface dialog, int id) {
93 loadFromAbout(R.raw.example);
94 dialog.dismiss();
95 }
96 });
97
98 return builder.create();
99 }
100
101 private void loadFromAbout(int resourceId) {
102 Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("android.resource://" + BuildConfig.APPLICATION_ID + "/" + resourceId));
103 String packageName = getActivity().getApplicationContext().getPackageName();
104 ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName());
105 i.setComponent(componentName);
106 getActivity().startActivity(i);
107 }
108}
Dialog onCreateDialog(Bundle savedInstanceState)
Main activity of the LibreOffice App.
int i
dictionary tokens
const sal_uInt8 R