mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
#226: Added cancel option to ProgressDialogFragments. Create Key is now cancelable.
This commit is contained in:
parent
0c60eea628
commit
1baae3775e
@ -21,6 +21,8 @@ import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.DialogInterface.OnCancelListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
@ -55,9 +57,14 @@ public class KeychainIntentServiceHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public KeychainIntentServiceHandler(Activity activity, int progressDialogMessageId, int progressDialogStyle) {
|
public KeychainIntentServiceHandler(Activity activity, int progressDialogMessageId, int progressDialogStyle) {
|
||||||
|
this(activity, progressDialogMessageId, progressDialogStyle, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public KeychainIntentServiceHandler(Activity activity, int progressDialogMessageId,
|
||||||
|
int progressDialogStyle, boolean cancelable) {
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
this.mProgressDialogFragment = ProgressDialogFragment.newInstance(progressDialogMessageId,
|
this.mProgressDialogFragment = ProgressDialogFragment.newInstance(progressDialogMessageId,
|
||||||
progressDialogStyle);
|
progressDialogStyle, cancelable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showProgressDialog(FragmentActivity activity) {
|
public void showProgressDialog(FragmentActivity activity) {
|
||||||
|
@ -185,7 +185,9 @@ public class EditKeyActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
// Message is received after generating is done in ApgService
|
// Message is received after generating is done in ApgService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
||||||
this, R.string.progress_generating, ProgressDialog.STYLE_SPINNER) {
|
this, R.string.progress_generating, ProgressDialog.STYLE_SPINNER, true) {
|
||||||
|
|
||||||
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard ApgHandler first
|
// handle messages by standard ApgHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -83,7 +83,7 @@ public class DeleteFileDialogFragment extends DialogFragment {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
ProgressDialogFragment deletingDialog = ProgressDialogFragment.newInstance(
|
ProgressDialogFragment deletingDialog = ProgressDialogFragment.newInstance(
|
||||||
R.string.progress_deleting_securely, ProgressDialog.STYLE_HORIZONTAL);
|
R.string.progress_deleting_securely, ProgressDialog.STYLE_HORIZONTAL, false);
|
||||||
|
|
||||||
// Message is received after deleting is done in ApgService
|
// Message is received after deleting is done in ApgService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(activity, deletingDialog) {
|
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(activity, deletingDialog) {
|
||||||
|
@ -26,21 +26,28 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
|
||||||
public class ProgressDialogFragment extends DialogFragment {
|
public class ProgressDialogFragment extends DialogFragment {
|
||||||
private static final String ARG_MESSAGE_ID = "message_id";
|
private static final String ARG_MESSAGE_ID = "message_id";
|
||||||
private static final String ARG_STYLE = "style";
|
private static final String ARG_STYLE = "style";
|
||||||
|
private static final String ARG_CANCELABLE = "cancelable";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new instance of this fragment
|
* Creates new instance of this fragment
|
||||||
*
|
*
|
||||||
* @param id
|
* @param messageId
|
||||||
|
* @param style
|
||||||
|
* @param cancelable
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static ProgressDialogFragment newInstance(int messageId, int style) {
|
public static ProgressDialogFragment newInstance(int messageId, int style,
|
||||||
|
boolean cancelable) {
|
||||||
ProgressDialogFragment frag = new ProgressDialogFragment();
|
ProgressDialogFragment frag = new ProgressDialogFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt(ARG_MESSAGE_ID, messageId);
|
args.putInt(ARG_MESSAGE_ID, messageId);
|
||||||
args.putInt(ARG_STYLE, style);
|
args.putInt(ARG_STYLE, style);
|
||||||
|
args.putBoolean(ARG_CANCELABLE, cancelable);
|
||||||
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
return frag;
|
return frag;
|
||||||
@ -60,7 +67,6 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
/**
|
/**
|
||||||
* Updates progress of dialog
|
* Updates progress of dialog
|
||||||
*
|
*
|
||||||
* @param messageId
|
|
||||||
* @param progress
|
* @param progress
|
||||||
* @param max
|
* @param max
|
||||||
*/
|
*/
|
||||||
@ -74,7 +80,7 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
/**
|
/**
|
||||||
* Updates progress of dialog
|
* Updates progress of dialog
|
||||||
*
|
*
|
||||||
* @param messageId
|
* @param message
|
||||||
* @param progress
|
* @param progress
|
||||||
* @param max
|
* @param max
|
||||||
*/
|
*/
|
||||||
@ -91,7 +97,7 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
Activity activity = getActivity();
|
final Activity activity = getActivity();
|
||||||
|
|
||||||
ProgressDialog dialog = new ProgressDialog(activity);
|
ProgressDialog dialog = new ProgressDialog(activity);
|
||||||
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
@ -100,10 +106,24 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
int messageId = getArguments().getInt(ARG_MESSAGE_ID);
|
int messageId = getArguments().getInt(ARG_MESSAGE_ID);
|
||||||
int style = getArguments().getInt(ARG_STYLE);
|
int style = getArguments().getInt(ARG_STYLE);
|
||||||
|
boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE);
|
||||||
|
|
||||||
dialog.setMessage(getString(messageId));
|
dialog.setMessage(getString(messageId));
|
||||||
dialog.setProgressStyle(style);
|
dialog.setProgressStyle(style);
|
||||||
|
|
||||||
|
if (cancelable) {
|
||||||
|
dialog.setButton(DialogInterface.BUTTON_NEGATIVE,
|
||||||
|
activity.getString(R.string.progress_cancel),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.cancel();
|
||||||
|
activity.setResult(Activity.RESULT_CANCELED);
|
||||||
|
activity.finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Disable the back button
|
// Disable the back button
|
||||||
OnKeyListener keyListener = new OnKeyListener() {
|
OnKeyListener keyListener = new OnKeyListener() {
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
|
|||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
mGeneratingDialog = ProgressDialogFragment.newInstance(R.string.progress_generating,
|
mGeneratingDialog = ProgressDialogFragment.newInstance(R.string.progress_generating,
|
||||||
ProgressDialog.STYLE_SPINNER);
|
ProgressDialog.STYLE_SPINNER, true);
|
||||||
|
|
||||||
// Message is received after generating is done in ApgService
|
// Message is received after generating is done in ApgService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(mActivity,
|
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(mActivity,
|
||||||
|
@ -296,6 +296,7 @@
|
|||||||
|
|
||||||
<!-- progress dialogs, usually ending in '…' -->
|
<!-- progress dialogs, usually ending in '…' -->
|
||||||
<string name="progress_done">done.</string>
|
<string name="progress_done">done.</string>
|
||||||
|
<string name="progress_cancel">cancel</string>
|
||||||
<string name="progress_saving">saving…</string>
|
<string name="progress_saving">saving…</string>
|
||||||
<string name="progress_importing">importing…</string>
|
<string name="progress_importing">importing…</string>
|
||||||
<string name="progress_exporting">exporting…</string>
|
<string name="progress_exporting">exporting…</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user