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/.
10 package org
.libreoffice
;
12 import android
.annotation
.SuppressLint
;
13 import android
.app
.AlertDialog
;
14 import android
.app
.Dialog
;
15 import android
.content
.ComponentName
;
16 import android
.content
.DialogInterface
;
17 import android
.content
.Intent
;
18 import android
.content
.pm
.PackageManager
;
19 import android
.net
.Uri
;
20 import android
.os
.Bundle
;
21 import androidx
.annotation
.NonNull
;
22 import androidx
.fragment
.app
.DialogFragment
;
23 import android
.text
.Html
;
24 import android
.text
.Spanned
;
25 import android
.text
.method
.LinkMovementMethod
;
26 import android
.view
.View
;
27 import android
.widget
.TextView
;
29 public class AboutDialogFragment
extends DialogFragment
{
32 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
34 @SuppressLint("InflateParams") //suppressed because the view will be placed in a dialog
35 View messageView
= getActivity().getLayoutInflater().inflate(R
.layout
.about
, null, false);
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
);
43 // Take care of placeholders and set text in version and vendor text views.
46 String versionName
= getActivity().getPackageManager()
47 .getPackageInfo(getActivity().getPackageName(), 0).versionName
;
48 String version
= String
.format(getString(R
.string
.app_version
), versionName
, BuildConfig
.BUILD_ID_SHORT
);
49 @SuppressWarnings("deprecation") // since 24 with additional option parameter
50 Spanned versionString
= Html
.fromHtml(version
);
51 TextView versionView
= messageView
.findViewById(R
.id
.about_version
);
52 versionView
.setText(versionString
);
53 versionView
.setMovementMethod(LinkMovementMethod
.getInstance());
54 TextView vendorView
= messageView
.findViewById(R
.id
.about_vendor
);
55 String vendor
= getString(R
.string
.app_vendor
).replace("$VENDOR", BuildConfig
.VENDOR
);
56 vendorView
.setText(vendor
);
58 catch (PackageManager
.NameNotFoundException e
)
62 AlertDialog
.Builder builder
= new AlertDialog
.Builder(getActivity());
63 builder
.setIcon(R
.mipmap
.ic_launcher
)
64 .setTitle(R
.string
.app_name
)
66 .setNegativeButton(R
.string
.about_license
, new DialogInterface
.OnClickListener() {
68 public void onClick(DialogInterface dialog
, int id
) {
69 loadFromAbout(R
.raw
.license
);
73 .setPositiveButton(R
.string
.about_notice
, new DialogInterface
.OnClickListener() {
75 public void onClick(DialogInterface dialog
, int id
) {
76 loadFromAbout(R
.raw
.notice
);
81 // when privacy policy URL is set (via '--with-privacy-policy-url=<url>' autogen option),
82 // add button to open that URL
83 final String privacyUrl
= BuildConfig
.PRIVACY_POLICY_URL
;
84 if (!privacyUrl
.isEmpty() && !privacyUrl
.equals("undefined")) {
85 builder
.setNeutralButton(R
.string
.about_privacy_policy
, (DialogInterface dialog
, int id
) -> {
86 Intent openPrivacyUrlIntent
= new Intent(Intent
.ACTION_VIEW
, Uri
.parse(privacyUrl
));
87 startActivity(openPrivacyUrlIntent
);
92 return builder
.create();
95 private void loadFromAbout(int resourceId
) {
96 Intent i
= new Intent(Intent
.ACTION_VIEW
, Uri
.parse("android.resource://" + BuildConfig
.APPLICATION_ID
+ "/" + resourceId
));
97 String packageName
= getActivity().getApplicationContext().getPackageName();
98 ComponentName componentName
= new ComponentName(packageName
, LibreOfficeMainActivity
.class.getName());
99 i
.setComponent(componentName
);
100 getActivity().startActivity(i
);