List of usage examples for android.os Messenger Messenger
public Messenger(IBinder target)
From source file:com.randerson.cloudantdroid.CouchSession.java
@SuppressLint("HandlerLeak") public void useSessionHandler() { // create a new handler object for the couch session HANDLER = new Handler() { @Override/*w w w . j a v a2 s. c om*/ public void handleMessage(Message msg) { super.handleMessage(msg); // verify that the handled message is returned successfully if (msg.arg1 == -1) { // receive the msg object and assign its contents to the // response object for processing String[] response = (String[]) msg.obj; // pass the response object to the parent activity getActivityInterface().returnServiceResponse(response, msg.arg2); } } }; // setup the messenger object for using the handler MESSENGER = new Messenger(HANDLER); }
From source file:org.thialfihar.android.apg.ui.EditKeyActivity.java
/** * Handle intent action to create new key * * @param intent/*from w ww . j a va 2 s.c om*/ */ private void handleActionCreateKey(Intent intent) { Bundle extras = intent.getExtras(); mCurrentPassphrase = ""; mIsBrandNewKeyring = true; if (extras != null) { // if userId is given, prefill the fields if (extras.containsKey(EXTRA_USER_IDS)) { Log.d(Constants.TAG, "UserIds are given!"); mUserIds.add(extras.getString(EXTRA_USER_IDS)); } // if no passphrase is given if (extras.containsKey(EXTRA_NO_PASSPHRASE)) { boolean noPassphrase = extras.getBoolean(EXTRA_NO_PASSPHRASE); if (noPassphrase) { // check "no passphrase" checkbox and remove button mNoPassphrase.setChecked(true); mChangePassphrase.setVisibility(View.GONE); } } // generate key if (extras.containsKey(EXTRA_GENERATE_DEFAULT_KEYS)) { boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS); if (generateDefaultKeys) { // Send all information needed to service generate keys in other thread final Intent serviceIntent = new Intent(this, ApgIntentService.class); serviceIntent.setAction(ApgIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS); // fill values for this action Bundle data = new Bundle(); data.putString(ApgIntentService.GENERATE_KEY_SYMMETRIC_PASSPHRASE, mCurrentPassphrase); serviceIntent.putExtra(ApgIntentService.EXTRA_DATA, data); // Message is received after generating is done in ApgIntentService ApgIntentServiceHandler saveHandler = new ApgIntentServiceHandler(this, getResources().getQuantityString(R.plurals.progress_generating, 1), ProgressDialog.STYLE_HORIZONTAL, true, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // Stop key generation on cancel stopService(serviceIntent); EditKeyActivity.this.setResult(Activity.RESULT_CANCELED); EditKeyActivity.this.finish(); } }) { @Override public void handleMessage(Message message) { // handle messages by standard ApgIntentServiceHandler first super.handleMessage(message); if (message.arg1 == ApgIntentServiceHandler.MESSAGE_OKAY) { // get new key from data bundle returned from service Bundle data = message.getData(); ArrayList<PGPSecretKey> newKeys = PgpConversionHelper.BytesToPGPSecretKeyList( data.getByteArray(ApgIntentService.RESULT_NEW_KEY)); ArrayList<Integer> keyUsageFlags = data .getIntegerArrayList(ApgIntentService.RESULT_KEY_USAGES); if (newKeys.size() == keyUsageFlags.size()) { for (int i = 0; i < newKeys.size(); ++i) { mKeys.add(newKeys.get(i)); mKeysUsages.add(keyUsageFlags.get(i)); } } buildLayout(true); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); serviceIntent.putExtra(ApgIntentService.EXTRA_MESSENGER, messenger); saveHandler.showProgressDialog(this); // start service with intent startService(serviceIntent); } } } else { buildLayout(false); } }
From source file:com.fanfou.app.opensource.HomePage.java
/** * ??//from www . j ava2 s . com * * @param type * ?Home/Mention/Message/Public */ private void doRetrieve(final int page, final boolean doGetMore) { if (AppContext.DEBUG) { log("doRetrieve() page=" + page + " doGetMore=" + doGetMore); } final ResultHandler handler = new ResultHandler(page, doGetMore); String sinceId = null; String maxId = null; final Cursor cursor = this.cursors[page]; switch (page) { case 0: if (doGetMore) { maxId = CommonHelper.getMaxId(cursor); } else { sinceId = CommonHelper.getSinceId(cursor); } FanfouServiceManager.doFetchHomeTimeline(this, new Messenger(handler), sinceId, maxId); break; case 1: if (doGetMore) { maxId = CommonHelper.getMaxId(cursor); } else { sinceId = CommonHelper.getSinceId(cursor); } FanfouServiceManager.doFetchMentions(this, new Messenger(handler), sinceId, maxId); break; case 2: FanfouServiceManager.doFetchDirectMessagesConversationList(this, new Messenger(handler), doGetMore); break; case 3: if (!doGetMore) { FanfouServiceManager.doFetchPublicTimeline(this, new Messenger(handler)); } break; default: break; } }
From source file:com.ratebeer.android.gui.fragments.BeerViewFragment.java
protected void onTickBarUpdated(float rating) { int newRating = (int) rating; if (rating <= 0.1) { // Force everything below 0.1 (since the user might not have the finger all the way at 0) as a tick removal newRating = -1;/*from ww w .j a v a 2 s . com*/ } if (ownTicks != null && ownTicks.size() > 0 && ownTicks.get(0).liked == rating) { // No need to update return; } // Update the user's tick status of this beer Intent i = new Intent(PosterService.ACTION_POSTTICK); i.putExtra(PosterService.EXTRA_BEERID, beerId); i.putExtra(PosterService.EXTRA_BEERNAME, beerName); i.putExtra(PosterService.EXTRA_USERID, getUser().getUserID()); i.putExtra(PosterService.EXTRA_LIKED, newRating); i.putExtra(PosterService.EXTRA_MESSENGER, new Messenger(new Handler() { @Override public void handleMessage(Message msg) { // Callback from the poster service; just refresh the tick status refreshOwnTick(); } })); getActivity().startService(i); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyActivity.java
/** * Handle intent action to create new key * * @param intent// w ww . java 2s . c o m */ private void handleActionCreateKey(Intent intent) { Bundle extras = intent.getExtras(); mCurrentPassphrase = ""; mIsBrandNewKeyring = true; if (extras != null) { // if userId is given, prefill the fields if (extras.containsKey(EXTRA_USER_IDS)) { Log.d(Constants.TAG, "UserIds are given!"); mUserIds.add(extras.getString(EXTRA_USER_IDS)); } // if no passphrase is given if (extras.containsKey(EXTRA_NO_PASSPHRASE)) { boolean noPassphrase = extras.getBoolean(EXTRA_NO_PASSPHRASE); if (noPassphrase) { // check "no passphrase" checkbox and remove button mNoPassphrase.setChecked(true); mChangePassphrase.setVisibility(View.GONE); } } // generate key if (extras.containsKey(EXTRA_GENERATE_DEFAULT_KEYS)) { boolean generateDefaultKeys = extras.getBoolean(EXTRA_GENERATE_DEFAULT_KEYS); if (generateDefaultKeys) { // Send all information needed to service generate keys in other thread final Intent serviceIntent = new Intent(this, KeychainIntentService.class); serviceIntent.setAction(KeychainIntentService.ACTION_GENERATE_DEFAULT_RSA_KEYS); // fill values for this action Bundle data = new Bundle(); data.putString(KeychainIntentService.GENERATE_KEY_SYMMETRIC_PASSPHRASE, mCurrentPassphrase); serviceIntent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after generating is done in KeychainIntentService KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this, getResources().getQuantityString(R.plurals.progress_generating, 1), ProgressDialog.STYLE_HORIZONTAL, true, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { // Stop key generation on cancel stopService(serviceIntent); EditKeyActivity.this.setResult(Activity.RESULT_CANCELED); EditKeyActivity.this.finish(); } }) { @Override public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { // get new key from data bundle returned from service Bundle data = message.getData(); ArrayList<UncachedSecretKey> newKeys = PgpConversionHelper.BytesToPGPSecretKeyList( data.getByteArray(KeychainIntentService.RESULT_NEW_KEY)); ArrayList<Integer> keyUsageFlags = data .getIntegerArrayList(KeychainIntentService.RESULT_KEY_USAGES); if (newKeys.size() == keyUsageFlags.size()) { for (int i = 0; i < newKeys.size(); ++i) { mKeys.add(newKeys.get(i)); mKeysUsages.add(keyUsageFlags.get(i)); } } buildLayout(true); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); serviceIntent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); saveHandler.showProgressDialog(this); // start service with intent startService(serviceIntent); } } } else { buildLayout(false); } }
From source file:org.sufficientlysecure.keychain.ui.EditIdentitiesFragment.java
private void editUserId(final int position) { final String userId = mUserIdsAdapter.getUserId(position); final boolean isRevoked = mUserIdsAdapter.getIsRevoked(position); final boolean isRevokedPending = mUserIdsAdapter.getIsRevokedPending(position); Handler returnHandler = new Handler() { @Override// w ww .j a v a 2 s. com public void handleMessage(Message message) { switch (message.what) { case EditUserIdDialogFragment.MESSAGE_CHANGE_PRIMARY_USER_ID: // toggle if (mSaveKeyringParcel.mChangePrimaryUserId != null && mSaveKeyringParcel.mChangePrimaryUserId.equals(userId)) { mSaveKeyringParcel.mChangePrimaryUserId = null; } else { mSaveKeyringParcel.mChangePrimaryUserId = userId; } break; case EditUserIdDialogFragment.MESSAGE_REVOKE: // toggle if (mSaveKeyringParcel.mRevokeUserIds.contains(userId)) { mSaveKeyringParcel.mRevokeUserIds.remove(userId); } else { mSaveKeyringParcel.mRevokeUserIds.add(userId); // not possible to revoke and change to primary user id if (mSaveKeyringParcel.mChangePrimaryUserId != null && mSaveKeyringParcel.mChangePrimaryUserId.equals(userId)) { mSaveKeyringParcel.mChangePrimaryUserId = null; } } break; } getLoaderManager().getLoader(LOADER_ID_USER_IDS).forceLoad(); } }; // Create a new Messenger for the communication back final Messenger messenger = new Messenger(returnHandler); DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() { public void run() { EditUserIdDialogFragment dialogFragment = EditUserIdDialogFragment.newInstance(messenger, isRevoked, isRevokedPending); dialogFragment.show(getActivity().getSupportFragmentManager(), "editUserIdDialog"); } }); }
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 2 s . c o m private void startSigning() { // 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_CERTIFY_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_certify_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.base.CryptoOperationHelper.java
public void cryptoOperation(final CryptoInputParcel cryptoInput) { FragmentActivity activity = mUseFragment ? mFragment.getActivity() : mActivity; T operationInput = mCallback.createOperationInput(); if (operationInput == null) { return;/*from ww w . ja v a2 s .c o m*/ } // Send all information needed to service to edit key in other thread Intent intent = new Intent(activity, KeychainService.class); intent.putExtra(KeychainService.EXTRA_OPERATION_INPUT, operationInput); intent.putExtra(KeychainService.EXTRA_CRYPTO_INPUT, cryptoInput); ServiceProgressHandler saveHandler = new ServiceProgressHandler(activity) { @Override public void handleMessage(Message message) { // handle messages by standard KeychainIntentServiceHandler first super.handleMessage(message); if (message.arg1 == MessageStatus.OKAY.ordinal()) { // get returned data bundle Bundle returnData = message.getData(); if (returnData == null) { return; } final OperationResult result = returnData.getParcelable(OperationResult.EXTRA_RESULT); onHandleResult(result); } } @Override protected void onSetProgress(String msg, int progress, int max) { // allow handling of progress in fragment, or delegate upwards if (!mCallback.onCryptoSetProgress(msg, progress, max)) { super.onSetProgress(msg, progress, max); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(saveHandler); intent.putExtra(KeychainService.EXTRA_MESSENGER, messenger); if (mProgressMessageResource != null) { saveHandler.showProgressDialog(activity.getString(mProgressMessageResource), ProgressDialog.STYLE_HORIZONTAL, mCancellable); } activity.startService(intent); }
From source file:org.scratch.microwebserver.MicrowebserverService.java
public void connectDispatcher() { final Intent i = new Intent("org.scratch.microwebserver"); i.setComponent(new ComponentName("org.scratch.microwebserver", "org.scratch.microwebserver.RemoteDispatcherService")); dispatchConn = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { // This is called when the connection with the service has been // established, giving us the service object we can use to // interact with the service. We are communicating with our // service through an IDL interface, so get a client-side // representation of that from the raw service object. disptachMessenger = new Messenger(service); // We want to monitor the service for as long as we are // connected to it. try { System.err.println("SEND SERVER HELLO"); Message msg = new Message(); msg.what = MessageTypes.MSG_SERVER_HELLO.ordinal(); msg.replyTo = mMessenger; disptachMessenger.send(msg); } catch (RemoteException e) { // In this case the service has crashed before we could even // do anything with it; we can count on soon being // disconnected (and then reconnected if it can be restarted) // so there is no need to do anything here. //HANDLE !!! e.printStackTrace();//from w ww . j ava 2s . co m } // As part of the sample, tell the user what happened. //Toast.makeText(Binding.this, "remote service connected",Toast.LENGTH_SHORT).show(); } public void onServiceDisconnected(ComponentName className) { // This is called when the connection with the service has been // unexpectedly disconnected -- that is, its process crashed. disptachMessenger = null; // As part of the sample, tell the user what happened. // Toast.makeText(Binding.this, R.string.remote_service_disconnected, // Toast.LENGTH_SHORT).show(); } }; bindService(i, dispatchConn, Context.BIND_AUTO_CREATE); }
From source file:org.sufficientlysecure.keychain.ui.EditIdentitiesFragment.java
private void addUserId() { Handler returnHandler = new Handler() { @Override/*from ww w.j ava 2s . com*/ public void handleMessage(Message message) { if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) { Bundle data = message.getData(); // add new user id mUserIdsAddedAdapter.add(data.getString(AddUserIdDialogFragment.MESSAGE_DATA_USER_ID)); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); // pre-fill out primary name String predefinedName = KeyRing.splitUserId(mPrimaryUserId).name; AddUserIdDialogFragment addUserIdDialog = AddUserIdDialogFragment.newInstance(messenger, predefinedName); addUserIdDialog.show(getActivity().getSupportFragmentManager(), "addUserIdDialog"); }