mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
switch to native DialogFragment, fix some nullpointers
This commit is contained in:
parent
204893a025
commit
403f74f558
@ -18,16 +18,14 @@
|
|||||||
package org.sufficientlysecure.keychain.service;
|
package org.sufficientlysecure.keychain.service;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.app.FragmentManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -106,7 +104,7 @@ public class ServiceProgressHandler extends Handler {
|
|||||||
|
|
||||||
// TODO: This is a hack!, see
|
// TODO: This is a hack!, see
|
||||||
// http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult
|
// http://stackoverflow.com/questions/10114324/show-dialogfragment-from-onactivityresult
|
||||||
final FragmentManager manager = activity.getSupportFragmentManager();
|
final FragmentManager manager = activity.getFragmentManager();
|
||||||
Handler handler = new Handler();
|
Handler handler = new Handler();
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -19,13 +19,14 @@ package org.sufficientlysecure.keychain.ui.dialog;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
|
import android.app.DialogFragment;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.DialogInterface.OnKeyListener;
|
import android.content.DialogInterface.OnKeyListener;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.annotation.NonNull;
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -44,7 +45,7 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
private static final String ARG_CANCELABLE = "cancelable";
|
private static final String ARG_CANCELABLE = "cancelable";
|
||||||
private static final String ARG_SERVICE_TYPE = "service_class";
|
private static final String ARG_SERVICE_TYPE = "service_class";
|
||||||
|
|
||||||
public static enum ServiceType {
|
public enum ServiceType {
|
||||||
KEYCHAIN_INTENT,
|
KEYCHAIN_INTENT,
|
||||||
CLOUD_IMPORT
|
CLOUD_IMPORT
|
||||||
}
|
}
|
||||||
@ -59,7 +60,6 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
* @param style the progress bar style, as defined in ProgressDialog (horizontal or spinner)
|
* @param style the progress bar style, as defined in ProgressDialog (horizontal or spinner)
|
||||||
* @param cancelable should we let the user cancel this operation
|
* @param cancelable should we let the user cancel this operation
|
||||||
* @param serviceType which Service this progress dialog is meant for
|
* @param serviceType which Service this progress dialog is meant for
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
public static ProgressDialogFragment newInstance(String message, int style, boolean cancelable,
|
public static ProgressDialogFragment newInstance(String message, int style, boolean cancelable,
|
||||||
ServiceType serviceType) {
|
ServiceType serviceType) {
|
||||||
@ -75,24 +75,21 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
return frag;
|
return frag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates progress of dialog */
|
|
||||||
public void setProgress(int messageId, int progress, int max) {
|
public void setProgress(int messageId, int progress, int max) {
|
||||||
setProgress(getString(messageId), progress, max);
|
setProgress(getString(messageId), progress, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates progress of dialog */
|
|
||||||
public void setProgress(int progress, int max) {
|
public void setProgress(int progress, int max) {
|
||||||
if (mIsCancelled) {
|
ProgressDialog dialog = (ProgressDialog) getDialog();
|
||||||
|
|
||||||
|
if (mIsCancelled || dialog == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressDialog dialog = (ProgressDialog) getDialog();
|
|
||||||
|
|
||||||
dialog.setProgress(progress);
|
dialog.setProgress(progress);
|
||||||
dialog.setMax(max);
|
dialog.setMax(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates progress of dialog */
|
|
||||||
public void setProgress(String message, int progress, int max) {
|
public void setProgress(String message, int progress, int max) {
|
||||||
ProgressDialog dialog = (ProgressDialog) getDialog();
|
ProgressDialog dialog = (ProgressDialog) getDialog();
|
||||||
|
|
||||||
@ -105,9 +102,7 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
dialog.setMax(max);
|
dialog.setMax(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@NonNull
|
||||||
* Creates dialog
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
final Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
@ -165,7 +160,12 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mPreventCancel = preventCancel;
|
mPreventCancel = preventCancel;
|
||||||
final Button negative = ((ProgressDialog) getDialog()).getButton(DialogInterface.BUTTON_NEGATIVE);
|
ProgressDialog dialog = (ProgressDialog) getDialog();
|
||||||
|
if (dialog == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Button negative = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
|
||||||
negative.setEnabled(mIsCancelled && !preventCancel);
|
negative.setEnabled(mIsCancelled && !preventCancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,11 +188,6 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
negative.setClickable(false);
|
negative.setClickable(false);
|
||||||
negative.setTextColor(Color.GRAY);
|
negative.setTextColor(Color.GRAY);
|
||||||
|
|
||||||
// Set the progress bar accordingly
|
|
||||||
ProgressDialog dialog = (ProgressDialog) getDialog();
|
|
||||||
dialog.setIndeterminate(true);
|
|
||||||
dialog.setMessage(getString(R.string.progress_cancelling));
|
|
||||||
|
|
||||||
// send a cancel message. note that this message will be handled by
|
// send a cancel message. note that this message will be handled by
|
||||||
// KeychainIntentService.onStartCommand, which runs in this thread,
|
// KeychainIntentService.onStartCommand, which runs in this thread,
|
||||||
// not the service one, and will not queue up a command.
|
// not the service one, and will not queue up a command.
|
||||||
@ -212,6 +207,17 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
serviceIntent.setAction(KeychainIntentService.ACTION_CANCEL);
|
serviceIntent.setAction(KeychainIntentService.ACTION_CANCEL);
|
||||||
getActivity().startService(serviceIntent);
|
getActivity().startService(serviceIntent);
|
||||||
|
|
||||||
|
// Set the progress bar accordingly
|
||||||
|
ProgressDialog dialog = (ProgressDialog) getDialog();
|
||||||
|
if (dialog == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.setIndeterminate(true);
|
||||||
|
dialog.setMessage(getString(R.string.progress_cancelling));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user