List of usage examples for android.os Message getData
public Bundle getData()
From source file:com.sharpcart.android.wizardpager.SharpCartLoginActivity.java
public void checkIfRegistered(final String email, final String password) { final Handler handler = new Handler() { @Override// w ww .j av a2s . c o m public void handleMessage(final Message msg) { final Bundle bundle = msg.getData(); isRegistered = bundle.getBoolean("isRegistered"); //if the user is already registered, go back to first screen and let the user know if (isRegistered) { mPager.setCurrentItem(0); Toast.makeText(mContext, "You already have an account", Toast.LENGTH_SHORT).show(); } } }; final Runnable runnable = new Runnable() { @Override public void run() { final Message msg = handler.obtainMessage(); boolean isRegistered = false; try { //before we perform a login we check that there is an Internet connection if (SharpCartUtilities.getInstance() .hasActiveInternetConnection(SharpCartApplication.getAppContext())) { final String response = LoginServiceImpl.sendCredentials(email, password); if (response.equalsIgnoreCase(SharpCartConstants.SUCCESS) || response.equalsIgnoreCase(SharpCartConstants.USER_EXISTS_IN_DB_CODE)) isRegistered = true; else isRegistered = false; } } catch (final SharpCartException e) { } final Bundle bundle = new Bundle(); bundle.putBoolean("isRegistered", isRegistered); msg.setData(bundle); handler.sendMessage(msg); } }; final Thread mythread = new Thread(runnable); mythread.start(); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyFragment.java
private void changePassphrase() { // Intent passIntent = new Intent(getActivity(), PassphraseWizardActivity.class); // passIntent.setAction(PassphraseWizardActivity.CREATE_METHOD); // startActivityForResult(passIntent, 12); // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override/*from ww w.j av a2s .c om*/ public void handleMessage(Message message) { if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) { Bundle data = message.getData(); // cache new returned passphrase! mSaveKeyringParcel.setNewUnlock(new ChangeUnlockParcel( (Passphrase) data.getParcelable(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE))); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(messenger, R.string.title_change_passphrase); setPassphraseDialog.show(getActivity().getSupportFragmentManager(), "setPassphraseDialog"); }
From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java
/** * Retrieve the children from the specified node. * //from w w w . j ava 2 s. c o m * @param position * n-th child position */ public void getChildren(int position) { final NodeRef ref = getItem(position); // For folders display the contents for the specified URI if (ref.isFolder()) { mStack.push(mCurrentState); String uuid = ref.getContent(); mCurrentState = new Pair<String, NodeRef[]>(uuid, null); getChildren(uuid); } // For non-folders try a download (if there is an external storage card) else { String storageState = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(storageState)) { downloadContent(ref, new Handler() { public void handleMessage(Message msg) { boolean done = msg.getData().getBoolean("done"); if (done) { dismissProgressDlg(); File file = (File) mDlThread.getResult(); if (file != null) { viewContent(file, ref); } } else { int value = msg.getData().getInt("progress"); if (value > 0) { mProgressDlg.setProgress(value); } } } }); } } }
From source file:com.zia.freshdocs.widget.adapter.CMISAdapter.java
/** * Saves the content node to the favorites area of the sdcard * /*from w ww .j a va2 s .c om*/ * @param position */ public void toggleFavorite(int position) { final Context context = getContext(); final CMISPreferencesManager prefsMgr = CMISPreferencesManager.getInstance(); final NodeRef ref = getItem(position); final Set<NodeRef> favorites = prefsMgr.getFavorites(context); if (favorites.contains(ref)) { favorites.remove(ref); prefsMgr.storeFavorites(context, favorites); if (mFavoritesView) { remove(ref); notifyDataSetChanged(); } } else { try { downloadContent(ref, new Handler() { public void handleMessage(Message msg) { boolean done = msg.getData().getBoolean("done"); if (done) { dismissProgressDlg(); File file = null; try { file = (File) mDlThread.getResult(); } catch (ClassCastException e) { e.printStackTrace(); } if (file != null) { favorites.add(ref); prefsMgr.storeFavorites(context, favorites); } } else { int value = msg.getData().getInt("progress"); if (value > 0) { mProgressDlg.setProgress(value); } } } }); } catch (Exception e) { e.printStackTrace(); } } }
From source file:id.nci.stm_9.ImportKeysActivity.java
/** * Import keys with mImportData/*from www. ja v a 2s . c om*/ */ 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:com.zia.freshdocs.widget.adapter.CMISAdapter.java
/** * Send the content using a built-in Android activity which can handle the * content type.//from w ww .ja va 2s .c o m * * @param position */ public void shareContent(int position) { final NodeRef ref = getItem(position); downloadContent(ref, new Handler() { public void handleMessage(Message msg) { Context context = getContext(); boolean done = msg.getData().getBoolean("done"); if (done) { dismissProgressDlg(); File file = (File) mDlThread.getResult(); if (file != null) { Resources res = context.getResources(); Uri uri = Uri.fromFile(file); Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_STREAM, uri); emailIntent.putExtra(Intent.EXTRA_SUBJECT, ref.getName()); emailIntent.putExtra(Intent.EXTRA_TEXT, res.getString(R.string.email_text)); emailIntent.setType(ref.getContentType()); try { context.startActivity( Intent.createChooser(emailIntent, res.getString(R.string.email_title))); } catch (ActivityNotFoundException e) { String text = "No suitable applications registered to send " + ref.getContentType(); int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } } } else { int value = msg.getData().getInt("progress"); if (value > 0) { mProgressDlg.setProgress(value); } } } }); }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossDeviceListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); handler = new Handler() { public void handleMessage(Message msg) { try { if (msg.what == 0) { Toast.makeText(getActivity(), "An error was encountered;\r\n" + msg.getData().getString("exception"), Toast.LENGTH_LONG).show(); try { dialog.dismiss(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment", "dialog.dismiss()", e);//w ww . j av a 2 s. c o m } } else if (msg.what == 1) { dialog.setMessage("Refresh Complete!"); this.sendEmptyMessageDelayed(2, 1000); } else if (msg.what == 2) { try { dialog.dismiss(); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment", "dialog.dismiss()", e); } try { adapter = new ZenossDeviceAdaptor(getActivity(), listOfDevices); //((TextView) findViewById(R.id.ServerCountLabel)).setText("Monitoring " + DeviceCount + " servers"); setListAdapter(adapter); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment", "setListAdapter", e); } } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment", "HandleMessage", e); } } }; try { listOfDevices = (List<ZenossDevice>) getActivity().getLastNonConfigurationInstance(); } catch (Exception e) { listOfDevices = null; BugSenseHandler.sendExceptionMessage("ViewZenossDeviceListFragment", "getLastNonConfigurationInstance", e); //BugSenseHandler.log("DeviceList", e); } /*if(listOfDevices == null || listOfDevices.size() < 1) { listOfDevices = new ArrayList<ZenossDevice>(); //DBGetThread(); } else { adapter = new ZenossDeviceAdaptor(getActivity(), listOfDevices); setListAdapter(adapter); }*/ if (null != listOfDevices) { adapter = new ZenossDeviceAdaptor(getActivity(), listOfDevices); setListAdapter(adapter); } }
From source file:com.nextgis.maplibui.service.LayerFillService.java
@Override public void onCreate() { mNotifyManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Bitmap largeIcon = NotificationHelper.getLargeIcon(R.drawable.ic_notification_download, getResources()); mProgressIntent = new Intent(ACTION_UPDATE); Intent intent = new Intent(this, LayerFillService.class); intent.setAction(ACTION_STOP);//w w w .j a v a 2 s . co m PendingIntent stopService = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); intent.setAction(ACTION_SHOW); PendingIntent showProgressDialog = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder = new NotificationCompat.Builder(this); mBuilder.setSmallIcon(R.drawable.ic_notification_download).setLargeIcon(largeIcon).setAutoCancel(false) .setOngoing(true).setContentIntent(showProgressDialog) .addAction(R.drawable.ic_action_cancel_dark, getString(R.string.tracks_stop), stopService); mIsCanceled = false; mQueue = new LinkedList<>(); mIsRunning = false; mHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { super.handleMessage(msg); Bundle resultData = msg.getData(); Toast.makeText(LayerFillService.this, resultData.getString(BUNDLE_MSG_KEY), Toast.LENGTH_LONG) .show(); } }; }
From source file:org.sufficientlysecure.keychain.ui.ImportKeysActivity.java
/** * Import keys with mImportData//w ww. ja va2s. 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.EditKeyFragment.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 va 2 s .co m public void handleMessage(Message message) { switch (message.what) { case EditSubkeyExpiryDialogFragment.MESSAGE_NEW_EXPIRY: mSaveKeyringParcel.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"); } }); }