Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / android / source / src / java / org / libreoffice / LOAbout.java
blob111ad109669dc647c472e3bdd3c25e059c8d1bd7
1 package org.libreoffice;
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.content.ComponentName;
6 import android.content.DialogInterface;
7 import android.content.Intent;
8 import android.content.pm.PackageManager.NameNotFoundException;
9 import android.net.Uri;
10 import android.view.View;
11 import android.widget.TextView;
13 import java.io.File;
15 /**
16 * The about dialog.
18 public class LOAbout {
20 private static final String DEFAULT_DOC_PATH = "/assets/example.odt";
21 private final Activity mActivity;
23 private boolean mNewActivity;
25 public LOAbout(Activity activity, boolean newActivity) {
26 mActivity = activity;
27 mNewActivity = newActivity;
30 private void loadFromAbout(String input) {
31 if (mNewActivity) {
32 Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(new File(input)));
33 String packageName = mActivity.getApplicationContext().getPackageName();
34 ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName());
35 i.setComponent(componentName);
36 mActivity.startActivity(i);
37 } else {
38 LOKitShell.sendCloseEvent();
39 LOKitShell.sendLoadEvent(input);
43 public void showAbout() {
44 // Inflate the about message contents
45 View messageView = mActivity.getLayoutInflater().inflate(R.layout.about, null, false);
47 // When linking text, force to always use default color. This works
48 // around a pressed color state bug.
49 TextView textView = (TextView) messageView.findViewById(R.id.about_credits);
50 int defaultColor = textView.getTextColors().getDefaultColor();
51 textView.setTextColor(defaultColor);
53 // Take care of placeholders in the version and vendor text views.
54 TextView versionView = (TextView)messageView.findViewById(R.id.about_version);
55 TextView vendorView = (TextView)messageView.findViewById(R.id.about_vendor);
56 try
58 String versionName = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0).versionName;
59 String[] tokens = versionName.split("/");
60 if (tokens.length == 3)
62 String version = versionView.getText().toString();
63 String vendor = vendorView.getText().toString();
64 version = version.replace("$VERSION", tokens[0]);
65 version = version.replace("$BUILDID", tokens[1]);
66 vendor = vendor.replace("$VENDOR", tokens[2]);
67 versionView.setText(version);
68 vendorView.setText(vendor);
70 else
71 throw new NameNotFoundException();
73 catch (NameNotFoundException e)
75 versionView.setText("");
76 vendorView.setText("");
79 AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
80 builder.setIcon(R.drawable.lo_icon);
81 builder.setTitle(R.string.app_name);
82 builder.setView(messageView);
84 builder.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
85 @Override
86 public void onClick(DialogInterface dialog, int id) {
87 loadFromAbout("/assets/license.txt");
88 dialog.dismiss();
90 });
92 builder.setPositiveButton(R.string.about_notice, new DialogInterface.OnClickListener() {
93 @Override
94 public void onClick(DialogInterface dialog, int id) {
95 loadFromAbout("/assets/notice.txt");
96 dialog.dismiss();
98 });
100 builder.setNeutralButton(R.string.about_moreinfo, new DialogInterface.OnClickListener() {
101 @Override
102 public void onClick(DialogInterface dialog, int id) {
103 loadFromAbout(DEFAULT_DOC_PATH);
104 dialog.dismiss();
108 AlertDialog dialog = builder.create();
109 dialog.show();
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */