Browse Source

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

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

26
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) { if (intentStartContext.get() != null)
activity.startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI));
} }
}).setNegativeButton(android.R.string.no, null).create(); }).setNegativeButton(android.R.string.no, null).show();
}
}.show(activity.getFragmentManager(), "installscanner");
} }
} }

31
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) { .setMessage(activity.getString(R.string.search_filemanagernotfound))
return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton(android.R.string.yes, new OnClickListener() {
.setMessage(activity.getString(R.string.search_filemanagernotfound)) @Override
.setPositiveButton(android.R.string.yes, new OnClickListener() { public void onClick(DialogInterface dialog, int which) {
@Override if (intentStartContext.get() != null)
public void onClick(DialogInterface dialog, int which) { intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI));
if (activity != null) }
activity.startActivity(new Intent(Intent.ACTION_VIEW, }).setNegativeButton(android.R.string.no, null).show();
FILEMANAGER_MARKET_URI));
}
}).setNegativeButton(android.R.string.no, null).create();
};
}.show(activity.getFragmentManager(), "installfilemanager");
} }
} }
} }

Loading…
Cancel
Save