Kaydet (Commit) 8802ebd5 authored tarafından aleksandar-stefanovic's avatar aleksandar-stefanovic Kaydeden (comit) Aleksandar Stefanović

Moved About dialog to DialogFragment

This makes the dialog more modular, and it takes no parameters
instead of two. This is in the preparation of making
the classes more independent on each-other's states, which is very
important. Also, this follows the Android way of workflow better,
since there is no "wrapper" class around the dialog, but instead
the dialog is called directly.

Change-Id: I7571480a040efaf202fae3929cfe76d65c19653e
Reviewed-on: https://gerrit.libreoffice.org/33086Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarAleksandar Stefanović <theonewithideas@gmail.com>
üst 690ab77f
/*
*
* * 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.app.Activity;
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.NameNotFoundException;
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;
/**
* The about dialog.
*/
public class LOAbout {
public class AboutDialogFragment extends DialogFragment {
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;
}
@NonNull @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
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);
@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.
......@@ -55,7 +47,8 @@ public class LOAbout {
TextView vendorView = (TextView)messageView.findViewById(R.id.about_vendor);
try
{
String versionName = mActivity.getPackageManager().getPackageInfo(mActivity.getPackageName(), 0).versionName;
String versionName = getActivity().getPackageManager()
.getPackageInfo(getActivity().getPackageName(), 0).versionName;
String[] tokens = versionName.split("/");
if (tokens.length == 3)
{
......@@ -68,46 +61,48 @@ public class LOAbout {
vendorView.setText(vendor);
}
else
throw new NameNotFoundException();
throw new PackageManager.NameNotFoundException();
}
catch (NameNotFoundException e)
catch (PackageManager.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.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();
}
AlertDialog dialog = builder.create();
dialog.show();
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);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -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() {
......
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment