Browse Source

Two more DialogFrament-related crash fixes as found in #466.

pull/471/head
Eric Kok 6 years ago
parent
commit
a39969e075
  1. 16
      app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java
  2. 21
      app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java

16
app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java

@ -19,7 +19,7 @@ package org.transdroid.core.gui.search;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.DialogFragment; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
@ -27,6 +27,8 @@ import android.net.Uri;
import org.transdroid.R; import org.transdroid.R;
import java.lang.ref.WeakReference;
public class BarcodeHelper { public class BarcodeHelper {
// A 'random' ID to identify QR-encoded settings scan intents // A 'random' ID to identify QR-encoded settings scan intents
@ -69,18 +71,16 @@ public class BarcodeHelper {
activity.startActivityForResult(intent, requestCode); activity.startActivityForResult(intent, requestCode);
} catch (Exception e) { } catch (Exception e) {
// Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present // Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present
new DialogFragment() { final WeakReference<Context> intentStartContext = new WeakReference<Context>(activity);
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_barcodescannernotfound)) .setMessage(activity.getString(R.string.search_barcodescannernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() { .setPositiveButton(android.R.string.yes, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
activity.startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); if (intentStartContext.get() != null)
} intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI));
}).setNegativeButton(android.R.string.no, null).create();
} }
}.show(activity.getFragmentManager(), "installscanner"); }).setNegativeButton(android.R.string.no, null).show();
} }
} }

21
app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java

@ -21,12 +21,14 @@ import org.transdroid.R;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.DialogFragment; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import java.lang.ref.WeakReference;
public class FilePickerHelper { public class FilePickerHelper {
public static final int ACTIVITY_FILEPICKER = 0x0000c0df; // A 'random' ID to identify file picker intents public static final int ACTIVITY_FILEPICKER = 0x0000c0df; // A 'random' ID to identify file picker intents
@ -49,22 +51,17 @@ public class FilePickerHelper {
// Start a file manager that can handle the PICK_FILE intent (specifically IO File Manager) // Start a file manager that can handle the PICK_FILE intent (specifically IO File Manager)
activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER); activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER);
} catch (Exception e2) { } catch (Exception e2) {
// Can't start the file manager, for example with a SecurityException or when IO File Manager is not // Can't start the file manager, for example with a SecurityException or when IO File Manager is not present
// present final WeakReference<Context> intentStartContext = new WeakReference<Context>(activity);
new DialogFragment() { new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) {
return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_filemanagernotfound)) .setMessage(activity.getString(R.string.search_filemanagernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() { .setPositiveButton(android.R.string.yes, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (activity != null) if (intentStartContext.get() != null)
activity.startActivity(new Intent(Intent.ACTION_VIEW, intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI));
FILEMANAGER_MARKET_URI));
} }
}).setNegativeButton(android.R.string.no, null).create(); }).setNegativeButton(android.R.string.no, null).show();
};
}.show(activity.getFragmentManager(), "installfilemanager");
} }
} }
} }

Loading…
Cancel
Save