summaryrefslogtreecommitdiffstats
path: root/android/source/src/java/org/libreoffice/LOAbout.java
blob: 111ad109669dc647c472e3bdd3c25e059c8d1bd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package org.libreoffice;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.view.View;
import android.widget.TextView;

import java.io.File;

/**
 * The about dialog.
 */
public class LOAbout {

    private static final String DEFAULT_DOC_PATH = "/assets/example.odt";
    private final Activity mActivity;

    private boolean mNewActivity;

    public LOAbout(Activity activity, boolean newActivity) {
        mActivity = activity;
        mNewActivity = newActivity;
    }

    private void loadFromAbout(String input) {
        if (mNewActivity) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.fromFile(new File(input)));
            String packageName = mActivity.getApplicationContext().getPackageName();
            ComponentName componentName = new ComponentName(packageName, LibreOfficeMainActivity.class.getName());
            i.setComponent(componentName);
            mActivity.startActivity(i);
        } else {
            LOKitShell.sendCloseEvent();
            LOKitShell.sendLoadEvent(input);
        }
    }

    public void showAbout() {
        // Inflate the about message contents
        View messageView = mActivity.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 = mActivity.getPackageManager().getPackageInfo(mActivity.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 NameNotFoundException();
        }
        catch (NameNotFoundException e)
        {
            versionView.setText("");
            vendorView.setText("");
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
        builder.setIcon(R.drawable.lo_icon);
        builder.setTitle(R.string.app_name);
        builder.setView(messageView);

        builder.setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                loadFromAbout("/assets/license.txt");
                dialog.dismiss();
            }
        });

        builder.setPositiveButton(R.string.about_notice, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                loadFromAbout("/assets/notice.txt");
                dialog.dismiss();
            }
        });

        builder.setNeutralButton(R.string.about_moreinfo, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                loadFromAbout(DEFAULT_DOC_PATH);
                dialog.dismiss();
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */