Example usage for android.os Messenger Messenger

List of usage examples for android.os Messenger Messenger

Introduction

In this page you can find the example usage for android.os Messenger Messenger.

Prototype

public Messenger(IBinder target) 

Source Link

Document

Create a Messenger from a raw IBinder, which had previously been retrieved with #getBinder .

Usage

From source file:com.money.manager.ex.MainActivity.java

public void startServiceSyncDropbox() {
    if (mDropboxHelper != null && mDropboxHelper.isLinked()) {
        Intent service = new Intent(getApplicationContext(), DropboxServiceIntent.class);
        service.setAction(DropboxServiceIntent.INTENT_ACTION_SYNC);
        service.putExtra(DropboxServiceIntent.INTENT_EXTRA_LOCAL_FILE,
                MoneyManagerApplication.getDatabasePath(this.getApplicationContext()));
        service.putExtra(DropboxServiceIntent.INTENT_EXTRA_REMOTE_FILE, mDropboxHelper.getLinkedRemoteFile());
        //progress dialog
        final ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false);
        progressDialog.setMessage(getString(R.string.dropbox_syncProgress));
        progressDialog.setIndeterminate(true);
        progressDialog.show();/*from  ww  w  .ja v a  2s .  co m*/
        //create a messenger
        Messenger messenger = new Messenger(new Handler() {
            @Override
            public void handleMessage(Message msg) {
                if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_NOT_CHANGE) {
                    // close dialog
                    if (progressDialog != null && progressDialog.isShowing())
                        progressDialog.hide();

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.dropbox_database_is_synchronized,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_START_DOWNLOAD) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.dropbox_download_is_starting,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_DOWNLOAD) {
                    // close dialog
                    if (progressDialog != null && progressDialog.isShowing())
                        progressDialog.hide();
                    // reload fragment
                    reloadAllFragment();
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_START_UPLOAD) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.dropbox_upload_is_starting,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                } else if (msg.what == DropboxServiceIntent.INTENT_EXTRA_MESSENGER_UPLOAD) {
                    // close dialog
                    if (progressDialog != null && progressDialog.isShowing())
                        progressDialog.hide();

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(MainActivity.this, R.string.upload_file_to_dropbox_complete,
                                    Toast.LENGTH_LONG).show();
                        }
                    });
                }
            }
        });
        service.putExtra(DropboxServiceIntent.INTENT_EXTRA_MESSENGER, messenger);

        this.startService(service);
    }
}

From source file:org.thialfihar.android.apg.ui.KeyListFragment.java

/**
 * Show dialog to delete key/*  w w  w. j a v a 2 s  . c  om*/
 *
 * @param keyRingRowIds
 */
@TargetApi(11)
// TODO: this method needs an overhaul to handle both public and secret keys gracefully!
public void showDeleteKeyDialog(final ActionMode mode, long[] keyRingRowIds) {
    // Message is received after key is deleted
    Handler returnHandler = new Handler() {
        @Override
        public void handleMessage(Message message) {
            if (message.what == DeleteKeyDialogFragment.MESSAGE_OKAY) {
                mode.finish();
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(returnHandler);

    DeleteKeyDialogFragment deleteKeyDialog = DeleteKeyDialogFragment.newInstance(messenger, keyRingRowIds);

    deleteKeyDialog.show(getActivity().getSupportFragmentManager(), "deleteKeyDialog");
}

From source file:org.thialfihar.android.apg.ui.CertifyKeyActivity.java

private void uploadKey() {
    // Send all information needed to service to upload key in other thread
    Intent intent = new Intent(this, ApgIntentService.class);

    intent.setAction(ApgIntentService.ACTION_UPLOAD_KEYRING);

    // set data uri as path to keyring
    intent.setData(mDataUri);//w w w .  j a  v a  2  s.c  o  m

    // fill values for this action
    Bundle data = new Bundle();

    Spinner keyServer = (Spinner) findViewById(R.id.sign_key_keyserver);
    String server = (String) keyServer.getSelectedItem();
    data.putString(ApgIntentService.UPLOAD_KEY_SERVER, server);

    intent.putExtra(ApgIntentService.EXTRA_DATA, data);

    // Message is received after uploading is done in ApgService
    ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this,
            getString(R.string.progress_exporting), ProgressDialog.STYLE_HORIZONTAL) {
        public void handleMessage(Message message) {
            // handle messages by standard ApgHandler first
            super.handleMessage(message);

            if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
                Toast.makeText(CertifyKeyActivity.this, R.string.key_send_success, Toast.LENGTH_SHORT).show();

                setResult(RESULT_OK);
                finish();
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    saveHandler.showProgressDialog(this);

    // start service with intent
    startService(intent);
}

From source file:org.sufficientlysecure.keychain.ui.ImportKeysActivity.java

/**
 * Import keys with mImportData//  www . j av a  2 s.c o  m
 */
public void importKeys() {
    if (mImportData != null || mImportFilename != null) {
        Log.d(Constants.TAG, "importKeys started");

        // Send all information needed to service to import key in other thread
        Intent intent = new Intent(this, KeychainIntentService.class);

        intent.putExtra(KeychainIntentService.EXTRA_ACTION, KeychainIntentService.ACTION_IMPORT_KEYRING);

        // fill values for this action
        Bundle data = new Bundle();

        // TODO: check for key type?
        // data.putInt(ApgIntentService.IMPORT_KEY_TYPE, Id.type.secret_key);

        if (mImportData != null) {
            data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
            data.putByteArray(KeychainIntentService.IMPORT_BYTES, mImportData);
        } else {
            data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE);
            data.putString(KeychainIntentService.IMPORT_FILENAME, mImportFilename);
        }

        intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

        // Message is received after importing is done in ApgService
        KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
                R.string.progress_importing, ProgressDialog.STYLE_HORIZONTAL) {
            public void handleMessage(Message message) {
                // handle messages by standard ApgHandler first
                super.handleMessage(message);

                if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                    // get returned data bundle
                    Bundle returnData = message.getData();

                    int added = returnData.getInt(KeychainIntentService.RESULT_IMPORT_ADDED);
                    int updated = returnData.getInt(KeychainIntentService.RESULT_IMPORT_UPDATED);
                    int bad = returnData.getInt(KeychainIntentService.RESULT_IMPORT_BAD);
                    String toastMessage;
                    if (added > 0 && updated > 0) {
                        toastMessage = getString(R.string.keysAddedAndUpdated, added, updated);
                    } else if (added > 0) {
                        toastMessage = getString(R.string.keysAdded, added);
                    } else if (updated > 0) {
                        toastMessage = getString(R.string.keysUpdated, updated);
                    } else {
                        toastMessage = getString(R.string.noKeysAddedOrUpdated);
                    }
                    Toast.makeText(ImportKeysActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
                    if (bad > 0) {
                        AlertDialog.Builder alert = new AlertDialog.Builder(ImportKeysActivity.this);

                        alert.setIcon(android.R.drawable.ic_dialog_alert);
                        alert.setTitle(R.string.warning);
                        alert.setMessage(ImportKeysActivity.this.getString(R.string.badKeysEncountered, bad));

                        alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                        alert.setCancelable(true);
                        alert.create().show();
                    } else if (mDeleteAfterImport) {
                        // everything went well, so now delete, if that was turned on
                        DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                                .newInstance(mImportFilename);
                        deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
                    }
                }
            };
        };

        // Create a new Messenger for the communication back
        Messenger messenger = new Messenger(saveHandler);
        intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

        // show progress dialog
        saveHandler.showProgressDialog(this);

        // start service with intent
        startService(intent);
    } else {
        Toast.makeText(this, R.string.error_nothingImport, Toast.LENGTH_LONG).show();
    }
}

From source file:org.sufficientlysecure.keychain.ui.CertifyKeyActivity.java

/**
 * kicks off the actual signing process on a background thread
 *//*from w w  w  . j  a  v  a 2s.  com*/
private void startRevokation() {

    // Bail out if there is not at least one user id selected
    ArrayList<String> userIds = mUserIdsAdapter.getSelectedUserIds();
    if (userIds.isEmpty()) {
        AppMsg.makeText(CertifyKeyActivity.this, "No User IDs to sign selected!", AppMsg.STYLE_ALERT).show();
        return;
    }

    // Send all information needed to service to sign key in other thread
    Intent intent = new Intent(this, KeychainIntentService.class);

    intent.setAction(KeychainIntentService.ACTION_REVOKE_KEYRING);

    // fill values for this action
    Bundle data = new Bundle();

    data.putLong(KeychainIntentService.CERTIFY_KEY_MASTER_KEY_ID, mMasterKeyId);
    data.putLong(KeychainIntentService.CERTIFY_KEY_PUB_KEY_ID, mPubKeyId);
    data.putStringArrayList(KeychainIntentService.CERTIFY_KEY_UIDS, userIds);

    intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

    // Message is received after signing is done in KeychainIntentService
    KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
            getString(R.string.progress_signing), ProgressDialog.STYLE_SPINNER) {
        public void handleMessage(Message message) {
            // handle messages by standard KeychainIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {

                AppMsg.makeText(CertifyKeyActivity.this, R.string.key_revokation_success, AppMsg.STYLE_INFO)
                        .show();

                // check if we need to send the key to the server or not
                if (mUploadKeyCheckbox.isChecked()) {
                    // upload the newly signed key to the keyserver
                    uploadKey();
                } else {
                    setResult(RESULT_OK);
                    finish();
                }
            }
        }
    };

    // Create a new Messenger for the communication back
    Messenger messenger = new Messenger(saveHandler);
    intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

    // show progress dialog
    saveHandler.showProgressDialog(this);

    // start service with intent
    startService(intent);
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.java

private void editSubkey(final int position) {
    final long keyId = mSubkeysAdapter.getKeyId(position);

    Handler returnHandler = new Handler() {
        @Override/*from www. j  a  v  a 2 s  .  co m*/
        public void handleMessage(Message message) {
            switch (message.what) {
            case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
                editSubkeyExpiry(position);
                break;
            case EditSubkeyDialogFragment.MESSAGE_REVOKE:
                // toggle
                if (mEditModeSaveKeyringParcel.mRevokeSubKeys.contains(keyId)) {
                    mEditModeSaveKeyringParcel.mRevokeSubKeys.remove(keyId);
                } else {
                    mEditModeSaveKeyringParcel.mRevokeSubKeys.add(keyId);
                }
                break;
            case EditSubkeyDialogFragment.MESSAGE_STRIP: {
                SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position);
                if (secretKeyType == SecretKeyType.GNU_DUMMY) {
                    // Key is already stripped; this is a no-op.
                    break;
                }

                SubkeyChange change = mEditModeSaveKeyringParcel.getSubkeyChange(keyId);
                if (change == null) {
                    mEditModeSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, true, false));
                    break;
                }
                // toggle
                change.mDummyStrip = !change.mDummyStrip;
                if (change.mDummyStrip && change.mMoveKeyToSecurityToken) {
                    // User had chosen to divert key, but now wants to strip it instead.
                    change.mMoveKeyToSecurityToken = false;
                }
                break;
            }
            case EditSubkeyDialogFragment.MESSAGE_MOVE_KEY_TO_SECURITY_TOKEN: {
                SecretKeyType secretKeyType = mSubkeysAdapter.getSecretKeyType(position);
                if (secretKeyType == SecretKeyType.DIVERT_TO_CARD || secretKeyType == SecretKeyType.GNU_DUMMY) {
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_stripped,
                            Notify.Style.ERROR).show();
                    break;
                }

                switch (mSubkeysAdapter.getAlgorithm(position)) {
                case PublicKeyAlgorithmTags.RSA_GENERAL:
                case PublicKeyAlgorithmTags.RSA_ENCRYPT:
                case PublicKeyAlgorithmTags.RSA_SIGN:
                    if (mSubkeysAdapter.getKeySize(position) < 2048) {
                        Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_size,
                                Notify.Style.ERROR).show();
                    }
                    break;

                case PublicKeyAlgorithmTags.ECDH:
                case PublicKeyAlgorithmTags.ECDSA:
                    final ASN1ObjectIdentifier curve = NISTNamedCurves
                            .getOID(mSubkeysAdapter.getCurveOid(position));
                    if (!curve.equals(NISTNamedCurves.getOID("P-256"))
                            && !curve.equals(NISTNamedCurves.getOID("P-384"))
                            && !curve.equals(NISTNamedCurves.getOID("P-521"))) {
                        Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_curve,
                                Notify.Style.ERROR).show();
                    }
                    break;

                default:
                    Notify.create(getActivity(), R.string.edit_key_error_bad_security_token_algo,
                            Notify.Style.ERROR).show();
                    break;
                }

                SubkeyChange change;
                change = mEditModeSaveKeyringParcel.getSubkeyChange(keyId);
                if (change == null) {
                    mEditModeSaveKeyringParcel.mChangeSubKeys.add(new SubkeyChange(keyId, false, true));
                    break;
                }
                // toggle
                change.mMoveKeyToSecurityToken = !change.mMoveKeyToSecurityToken;
                if (change.mMoveKeyToSecurityToken && change.mDummyStrip) {
                    // User had chosen to strip key, but now wants to divert it.
                    change.mDummyStrip = false;
                }
                break;
            }
            }
            getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad();
        }
    };

    // Create a new Messenger for the communication back
    final Messenger messenger = new Messenger(returnHandler);

    DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
        public void run() {
            EditSubkeyDialogFragment dialogFragment = EditSubkeyDialogFragment.newInstance(messenger);

            dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyDialog");
        }
    });
}

From source file:org.sufficientlysecure.privacybox.VaultProvider.java

@Override
public ParcelFileDescriptor openDocument(String documentId, String mode, final CancellationSignal signal)
        throws FileNotFoundException {
    final long docId = Long.parseLong(documentId);
    try {//from   w ww.j  av a  2  s.c  om
        final EncryptedDocument doc = getDocument(docId);

        if ("r".equals(mode)) {
            /*
             * READ MODE
             */

            JSONObject meta = doc.readMetadata();
            String filename = "no filename";
            try {
                filename = meta.getString(Document.COLUMN_DISPLAY_NAME);
            } catch (JSONException e) {
                Log.e(TAG, "JSONException getting filename", e);
            }

            openResult = -1;
            Handler handler = new Handler(Looper.getMainLooper(), new Handler.Callback() {
                @Override
                public boolean handleMessage(Message msg) {
                    synchronized (mUILock) {
                        openResult = msg.what;
                        mUILock.notify();
                    }
                    return true;
                }
            });

            // start dialog activity and wait here for it finishing...
            Intent dialog = new Intent(getContext(), OpenDialogActivity.class);
            dialog.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            dialog.putExtra(OpenDialogActivity.EXTRA_MESSENGER, new Messenger(handler));
            dialog.putExtra(OpenDialogActivity.EXTRA_FILENAME, filename);

            getContext().startActivity(dialog);

            Log.d(TAG, "mUILock.wait");
            synchronized (mUILock) {
                try {
                    mUILock.wait();
                } catch (InterruptedException e) {
                    Log.e(TAG, "interrupt", e);
                }
            }
            Log.d(TAG, "after mUILock.wait");

            Log.d(TAG, "openResult:" + openResult);
            switch (openResult) {
            case OpenDialogActivity.MSG_DECRYPT_OPEN:
                Log.d(TAG, "MSG_DECRYPT_OPEN");

                // TODO
                return startRead(doc);
            case OpenDialogActivity.MSG_GET_ENCRYPTED:
                Log.d(TAG, "MSG_GET_ENCRYPTED");

                // TODO
                return startRead(doc);
            case OpenDialogActivity.MSG_CANCEL:
                Log.d(TAG, "MSG_CANCEL");
                return null;
            default:
                Log.e(TAG, "should not happen");
                return null;
            }

        } else if ("w".equals(mode) || "wt".equals(mode)) {
            /*
             * WRITE MODE
             */

            return startWrite(doc);
        } else {
            throw new IllegalArgumentException("Unsupported mode: " + mode);
        }
    } catch (IOException e) {
        throw new IllegalStateException(e);
    } catch (GeneralSecurityException e) {
        throw new IllegalStateException(e);
    }
}

From source file:id.nci.stm_9.ImportKeysActivity.java

/**
 * Import keys with mImportData// w  w  w  . j  a  v a2s .  c o  m
 */
public void importKeys() {
    if (mListFragment.getKeyBytes() != null || mListFragment.getImportFilename() != null) {
        Log.d("stm-9", "importKeys started");

        // Send all information needed to service to import key in other thread
        Intent intent = new Intent(this, KeychainIntentService.class);

        intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);

        // fill values for this action
        Bundle data = new Bundle();

        // get selected key ids
        List<ImportKeysListEntry> listEntries = mListFragment.getData();
        ArrayList<Long> selectedKeyIds = new ArrayList<Long>();
        for (ImportKeysListEntry entry : listEntries) {
            if (entry.isSelected()) {
                selectedKeyIds.add(entry.keyId);
            }
        }

        data.putSerializable(KeychainIntentService.IMPORT_KEY_LIST, selectedKeyIds);

        if (mListFragment.getKeyBytes() != null) {
            data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
            data.putByteArray(KeychainIntentService.IMPORT_BYTES, mListFragment.getKeyBytes());
        } else {
            data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_FILE);
            data.putString(KeychainIntentService.IMPORT_FILENAME, mListFragment.getImportFilename());
        }

        intent.putExtra(KeychainIntentService.EXTRA_DATA, data);

        // Message is received after importing is done in ApgService
        KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
                R.string.progress_importing, ProgressDialog.STYLE_HORIZONTAL) {
            public void handleMessage(Message message) {
                // handle messages by standard ApgHandler first
                super.handleMessage(message);

                if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
                    // get returned data bundle
                    Bundle returnData = message.getData();

                    int added = returnData.getInt(KeychainIntentService.RESULT_IMPORT_ADDED);
                    int updated = returnData.getInt(KeychainIntentService.RESULT_IMPORT_UPDATED);
                    //                        int bad = returnData.getInt(KeychainIntentService.RESULT_IMPORT_BAD);
                    String toastMessage;
                    if (added > 0 && updated > 0) {
                        toastMessage = getString(R.string.keys_added_and_updated, added, updated);
                    } else if (added > 0) {
                        toastMessage = getString(R.string.keys_added, added);
                    } else if (updated > 0) {
                        toastMessage = getString(R.string.keys_updated, updated);
                    } else {
                        toastMessage = getString(R.string.no_keys_added_or_updated);
                    }
                    Toast.makeText(ImportKeysActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
                    //                        if (bad > 0) {
                    //                            AlertDialog.Builder alert = new AlertDialog.Builder(
                    //                                    ImportKeysActivity.this);
                    //
                    //                            alert.setIcon(android.R.drawable.ic_dialog_alert);
                    //                            alert.setTitle(R.string.warning);
                    //                            alert.setMessage(ImportKeysActivity.this.getString(
                    //                                    R.string.bad_keys_encountered, bad));
                    //
                    //                            alert.setPositiveButton(android.R.string.ok,
                    //                                    new DialogInterface.OnClickListener() {
                    //                                        public void onClick(DialogInterface dialog, int id) {
                    //                                            dialog.cancel();
                    //                                        }
                    //                                    });
                    //                            alert.setCancelable(true);
                    //                            alert.create().show();
                    //                        } else if (mDeleteAfterImport) {
                    //                            // everything went well, so now delete, if that was turned on
                    //                            DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment
                    //                                    .newInstance(mListFragment.getImportFilename());
                    //                            deleteFileDialog.show(getSupportFragmentManager(), "deleteDialog");
                    //                        }
                }
            };
        };

        // Create a new Messenger for the communication back
        Messenger messenger = new Messenger(saveHandler);
        intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);

        // show progress dialog
        saveHandler.showProgressDialog(this);

        // start service with intent
        startService(intent);
    } else {
        Toast.makeText(this, R.string.error_nothing_import, Toast.LENGTH_LONG).show();
    }
}

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvSubkeysFragment.java

private void editSubkeyExpiry(final int position) {
    final long keyId = mSubkeysAdapter.getKeyId(position);
    final Long creationDate = mSubkeysAdapter.getCreationDate(position);
    final Long expiryDate = mSubkeysAdapter.getExpiryDate(position);

    Handler returnHandler = new Handler() {
        @Override//w  w w . j a  va2 s  .c  o m
        public void handleMessage(Message message) {
            switch (message.what) {
            case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY:
                mEditModeSaveKeyringParcel.getOrCreateSubkeyChange(keyId).mExpiry = (Long) message.getData()
                        .getSerializable(EditSubkeyExpiryDialogFragment.MESSAGE_DATA_EXPIRY);
                break;
            }
            getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad();
        }
    };

    // Create a new Messenger for the communication back
    final Messenger messenger = new Messenger(returnHandler);

    DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
        public void run() {
            EditSubkeyExpiryDialogFragment dialogFragment = EditSubkeyExpiryDialogFragment
                    .newInstance(messenger, creationDate, expiryDate);

            dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyExpiryDialog");
        }
    });
}

From source file:org.thialfihar.android.apg.ui.ImportKeysActivity.java

/**
 * Import keys with mImportData/*  w w  w  .  java2s.c o m*/
 */
public void importKeys() {
    // Message is received after importing is done in ApgService
    ApgIntentServiceHandler mSaveHandler = new ApgIntentServiceHandler(this,
            getString(R.string.progress_importing), ProgressDialog.STYLE_HORIZONTAL) {
        public void handleMessage(Message message) {
            // handle messages by standard ApgIntentServiceHandler first
            super.handleMessage(message);

            if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) {
                // get returned data bundle
                Bundle returnData = message.getData();

                int added = returnData.getInt(ApgIntentService.RESULT_IMPORT_ADDED);
                int updated = returnData.getInt(ApgIntentService.RESULT_IMPORT_UPDATED);
                int bad = returnData.getInt(ApgIntentService.RESULT_IMPORT_BAD);
                String toastMessage;
                if (added > 0 && updated > 0) {
                    String addedStr = getResources().getQuantityString(R.plurals.keys_added_and_updated_1,
                            added, added);
                    String updatedStr = getResources().getQuantityString(R.plurals.keys_added_and_updated_2,
                            updated, updated);
                    toastMessage = addedStr + updatedStr;
                } else if (added > 0) {
                    toastMessage = getResources().getQuantityString(R.plurals.keys_added, added, added);
                } else if (updated > 0) {
                    toastMessage = getResources().getQuantityString(R.plurals.keys_updated, updated, updated);
                } else {
                    toastMessage = getString(R.string.no_keys_added_or_updated);
                }
                AppMsg.makeText(ImportKeysActivity.this, toastMessage, AppMsg.STYLE_INFO).show();
                if (bad > 0) {
                    BadImportKeyDialogFragment badImportKeyDialogFragment = BadImportKeyDialogFragment
                            .newInstance(bad);
                    badImportKeyDialogFragment.show(getSupportFragmentManager(), "badKeyDialog");
                }
            }
        }
    };

    if (mListFragment.getKeyBytes() != null || mListFragment.getDataUri() != null) {
        Log.d(Constants.TAG, "importKeys started");

        // Send all information needed to service to import key in other thread
        Intent intent = new Intent(this, ApgIntentService.class);

        intent.setAction(ApgIntentService.ACTION_IMPORT_KEYRING);

        // fill values for this action
        Bundle data = new Bundle();

        // get selected key entries
        ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedData();
        data.putParcelableArrayList(ApgIntentService.IMPORT_KEY_LIST, selectedEntries);

        intent.putExtra(ApgIntentService.EXTRA_DATA, data);

        // Create a new Messenger for the communication back
        Messenger messenger = new Messenger(mSaveHandler);
        intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);

        // show progress dialog
        mSaveHandler.showProgressDialog(this);

        // start service with intent
        startService(intent);
    } else if (mListFragment.getServerQuery() != null) {
        // Send all information needed to service to query keys in other thread
        Intent intent = new Intent(this, ApgIntentService.class);

        intent.setAction(ApgIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS);

        // fill values for this action
        Bundle data = new Bundle();

        data.putString(ApgIntentService.DOWNLOAD_KEY_SERVER, mListFragment.getKeyServer());

        // get selected key entries
        ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedData();
        data.putParcelableArrayList(ApgIntentService.DOWNLOAD_KEY_LIST, selectedEntries);

        intent.putExtra(ApgIntentService.EXTRA_DATA, data);

        // Create a new Messenger for the communication back
        Messenger messenger = new Messenger(mSaveHandler);
        intent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger);

        // show progress dialog
        mSaveHandler.showProgressDialog(this);

        // start service with intent
        startService(intent);
    } else {
        AppMsg.makeText(this, R.string.error_nothing_import, AppMsg.STYLE_ALERT).show();
    }
}