diff options
4 files changed, 115 insertions, 127 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); + } +} diff --git a/android/source/src/java/org/libreoffice/LOAbout.java b/android/source/src/java/org/libreoffice/LOAbout.java deleted file mode 100644 index 111ad109669d..000000000000 --- a/android/source/src/java/org/libreoffice/LOAbout.java +++ /dev/null @@ -1,113 +0,0 @@ -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: */ diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 93e041c14349..b84f78bc94e6 100755 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -64,7 +64,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity { private URI documentUri; private DrawerLayout mDrawerLayout; - private LOAbout mAbout; private ListView mDrawerList; private List<DocumentPartView> mDocumentPartView = new ArrayList<DocumentPartView>(); @@ -79,10 +78,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity { private FontController mFontController; private SearchController mSearchController; - public LibreOfficeMainActivity() { - mAbout = new LOAbout(this, false); - } - public GeckoLayerClient getLayerClient() { return mLayerClient; } @@ -599,7 +594,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity { } public void showAbout() { - mAbout.showAbout(); + AboutDialogFragment aboutDialogFragment = new AboutDialogFragment(); + aboutDialogFragment.show(getSupportFragmentManager(), "AboutDialogFragment"); } public void showSettings() { diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 67a848086353..efec500e4c57 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -48,7 +48,7 @@ import android.widget.TextView; import android.widget.Toast; import android.support.design.widget.NavigationView; -import org.libreoffice.LOAbout; +import org.libreoffice.AboutDialogFragment; import org.libreoffice.LibreOfficeMainActivity; import org.libreoffice.R; import org.libreoffice.SettingsActivity; @@ -99,13 +99,8 @@ public class LibreOfficeUIActivity extends AppCompatActivity { private ActionBarDrawerToggle drawerToggle; RecyclerView fileRecyclerView; - private final LOAbout mAbout; private boolean canQuit = false; - public LibreOfficeUIActivity() { - mAbout = new LOAbout(this, true); - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -554,8 +549,10 @@ public class LibreOfficeUIActivity extends AppCompatActivity { case R.id.menu_sort_modified: sortFiles(item); break; - case R.id.action_about: - mAbout.showAbout(); + case R.id.action_about: { + AboutDialogFragment aboutDialogFragment = new AboutDialogFragment(); + aboutDialogFragment.show(getSupportFragmentManager(), "AboutDialogFragment"); + } return true; case R.id.action_settings: startActivity(new Intent(getApplicationContext(), SettingsActivity.class)); |