List of usage examples for android.os Message getData
public Bundle getData()
From source file:net.evecom.androidecssp.base.BaseActivity.java
/** * /* ww w .j a v a 2 s. c o m*/ * dictValue dictKey TextViewDictName * * @author Mars zhang * @created 2015-11-25 9:50:55 * @param dictKey * @param value * @param view */ protected void setDictNameByValueToView(final String dictKey, final String dictValue, final TextView view) { final Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case MESSAGETYPE_01: view.setText(msg.getData().getString("dictname")); break; default: break; } }; }; new Thread(new Runnable() { @Override public void run() { try { HashMap<String, String> entityMap = new HashMap<String, String>(); entityMap.put("dictkey", dictKey); String result = connServerForResultPost("jfs/ecssp/mobile/pubCtr/getDictByKey", entityMap); List<BaseModel> baseModels = getObjsInfo(result); HashMap<String, String> keyValehashmap = new HashMap<String, String>(); for (int i = 0; i < baseModels.size(); i++) { keyValehashmap.put(baseModels.get(i).get("dictvalue") + "", baseModels.get(i).get("name") + ""); } String dictname = ifnull(keyValehashmap.get(dictValue), ""); Message message = new Message(); Bundle mbundle = new Bundle(); mbundle.putString("dictname", dictname); message.setData(mbundle); message.what = MESSAGETYPE_01; mHandler.sendMessage(message); } catch (ClientProtocolException e) { Log.v("mars", e.getMessage()); } catch (IOException e) { Log.v("mars", e.getMessage()); } catch (JSONException e) { Log.v("mars", e.getMessage()); } } }).start(); }
From source file:org.thialfihar.android.apg.ui.ImportKeysActivity.java
/** * Import keys with mImportData// w w w .j a v a 2s .co 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(); } }
From source file:net.evecom.androidecssp.base.BaseActivity.java
/** * /*from w w w.j a v a 2s . c o m*/ * dictValue dictKey TextViewDictName * * @author Mars zhang * @created 2015-11-25 9:50:55 * @param dictKey * @param value * @param view */ protected void setLikeDictNameByValueToView(final String url, final String dictKey, final String dictValue, final TextView view) { final Handler mHandler = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case MESSAGETYPE_01: view.setText(msg.getData().getString("dictname")); break; default: break; } }; }; new Thread(new Runnable() { @Override public void run() { try { HashMap<String, String> entityMap = new HashMap<String, String>(); entityMap.put("dictkey", dictKey); String result = connServerForResultPost(url, entityMap); List<BaseModel> baseModels = getObjsInfo(result); HashMap<String, String> keyValehashmap = new HashMap<String, String>(); for (int i = 0; i < baseModels.size(); i++) { keyValehashmap.put(baseModels.get(i).get("dictvalue") + "", baseModels.get(i).get("name") + ""); } String dictname = ifnull(keyValehashmap.get(dictValue), ""); Message message = new Message(); Bundle mbundle = new Bundle(); mbundle.putString("dictname", dictname); message.setData(mbundle); message.what = MESSAGETYPE_01; mHandler.sendMessage(message); } catch (ClientProtocolException e) { Log.v("mars", e.getMessage()); } catch (IOException e) { Log.v("mars", e.getMessage()); } catch (JSONException e) { Log.v("mars", e.getMessage()); } } }).start(); }
From source file:org.sufficientlysecure.keychain.ui.EditKeyActivity.java
/** * Shows the dialog to set a new passphrase *//*from w w w. j a v a 2s. c om*/ private void showSetPassphraseDialog() { // Message is received after passphrase is cached Handler returnHandler = new Handler() { @Override public void handleMessage(Message message) { if (message.what == SetPassphraseDialogFragment.MESSAGE_OKAY) { Bundle data = message.getData(); // set new returned passphrase! mNewPassphrase = data.getString(SetPassphraseDialogFragment.MESSAGE_NEW_PASSPHRASE); updatePassphraseButtonText(); somethingChanged(); } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); // set title based on isPassphraseSet() int title; if (isPassphraseSet()) { title = R.string.title_change_passphrase; } else { title = R.string.title_set_passphrase; } SetPassphraseDialogFragment setPassphraseDialog = SetPassphraseDialogFragment.newInstance(messenger, title); setPassphraseDialog.show(getSupportFragmentManager(), "setPassphraseDialog"); }
From source file:com.nextgis.firereporter.GetFiresService.java
protected void Prepare() { mLocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mnCurrentExec = 0;//from w ww . ja v a 2 s .c o m mmoFires = new HashMap<Long, FireItem>(); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nUserCount = 0; nNasaCount = 0; nScanexCount = 0; TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(new Intent(this, MainActivity.class)); //stackBuilder.addNextIntent(new Intent(this, ScanexNotificationsActivity.class)); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_fire_small) .setContentTitle(getString(R.string.stNewFireNotifications)); mBuilder.setContentIntent(resultPendingIntent); Intent delIntent = new Intent(this, GetFiresService.class); delIntent.putExtra(COMMAND, SERVICE_NOTIFY_DISMISSED); PendingIntent deletePendingIntent = PendingIntent.getService(this, 0, delIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setDeleteIntent(deletePendingIntent); mInboxStyle = new NotificationCompat.InboxStyle(); mInboxStyle.setBigContentTitle(getString(R.string.stNewFireNotificationDetailes)); LoadScanexData(); mSanextCookieTime = new Time(); mSanextCookieTime.setToNow(); msScanexLoginCookie = new String("not_set"); mFillDataHandler = new Handler() { public void handleMessage(Message msg) { mnCurrentExec--; Bundle resultData = msg.getData(); boolean bHaveErr = resultData.getBoolean(ERROR); if (bHaveErr) { SendError(resultData.getString(ERR_MSG)); } else { int nType = resultData.getInt(SOURCE); String sData = resultData.getString(JSON); switch (nType) { case 3: FillScanexData(nType, sData); break; case 4: msScanexLoginCookie = sData; mSanextCookieTime.setToNow(); GetScanexData(false); break; default: FillData(nType, sData); break; } } GetDataStoped(); }; }; }
From source file:ac.robinson.mediaphone.activity.NarrativeBrowserActivity.java
private void postScrollToSelectedFrame(String narrativeId, String frameId) { mScrollHandler.removeMessages(R.id.msg_scroll_to_selected_frame); Message message = mScrollHandler.obtainMessage(R.id.msg_scroll_to_selected_frame, NarrativeBrowserActivity.this); Bundle messageData = message.getData(); messageData.putString(getString(R.string.extra_parent_id), narrativeId); messageData.putString(getString(R.string.extra_internal_id), frameId); mScrollHandler.sendMessage(message); }
From source file:ac.robinson.mediaphone.activity.NarrativeBrowserActivity.java
private void postDelayedScrollToSelectedFrame(String narrativeId, String frameId) { // intentionally not removing, so non-delayed call from onActivityResult is handled first (onResume = rotation) // mScrollHandler.removeMessages(R.id.msg_scroll_to_selected_frame); Message message = mScrollHandler.obtainMessage(R.id.msg_scroll_to_selected_frame, NarrativeBrowserActivity.this); Bundle messageData = message.getData(); messageData.putString(getString(R.string.extra_parent_id), narrativeId); messageData.putString(getString(R.string.extra_internal_id), frameId); mScrollHandler.sendMessageDelayed(message, MediaPhone.ANIMATION_ICON_REFRESH_DELAY); }
From source file:com.smithdtyler.prettygoodmusicplayer.NowPlaying.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Intent originIntent = getIntent();//from ww w .jav a2s .c o m if (originIntent.getBooleanExtra("From_Notification", false)) { String artistName = originIntent.getStringExtra(ArtistList.ARTIST_NAME); String artistAbsPath = originIntent.getStringExtra(ArtistList.ARTIST_ABS_PATH_NAME); if (artistName != null && artistAbsPath != null) { Log.i(TAG, "Now Playing was launched from a notification, setting up its back stack"); // Reference: https://developer.android.com/reference/android/app/TaskStackBuilder.html TaskStackBuilder tsb = TaskStackBuilder.create(this); Intent intent = new Intent(this, ArtistList.class); tsb.addNextIntent(intent); intent = new Intent(this, AlbumList.class); intent.putExtra(ArtistList.ARTIST_NAME, artistName); intent.putExtra(ArtistList.ARTIST_ABS_PATH_NAME, artistAbsPath); tsb.addNextIntent(intent); String albumName = originIntent.getStringExtra(AlbumList.ALBUM_NAME); if (albumName != null) { intent = new Intent(this, SongList.class); intent.putExtra(AlbumList.ALBUM_NAME, albumName); intent.putExtra(ArtistList.ARTIST_NAME, artistName); intent.putExtra(ArtistList.ARTIST_ABS_PATH_NAME, artistAbsPath); tsb.addNextIntent(intent); } intent = new Intent(this, NowPlaying.class); tsb.addNextIntent(intent); tsb.startActivities(); } } SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); String theme = sharedPref.getString("pref_theme", getString(R.string.light)); String size = sharedPref.getString("pref_text_size", getString(R.string.medium)); Log.i(TAG, "got configured theme " + theme); Log.i(TAG, "got configured size " + size); // These settings were fixed in english for a while, so check for old style settings as well as language specific ones. if (theme.equalsIgnoreCase(getString(R.string.dark)) || theme.equalsIgnoreCase("dark")) { Log.i(TAG, "setting theme to " + theme); if (size.equalsIgnoreCase(getString(R.string.small)) || size.equalsIgnoreCase("small")) { setTheme(R.style.PGMPDarkSmall); } else if (size.equalsIgnoreCase(getString(R.string.medium)) || size.equalsIgnoreCase("medium")) { setTheme(R.style.PGMPDarkMedium); } else { setTheme(R.style.PGMPDarkLarge); } } else if (theme.equalsIgnoreCase(getString(R.string.light)) || theme.equalsIgnoreCase("light")) { Log.i(TAG, "setting theme to " + theme); if (size.equalsIgnoreCase(getString(R.string.small)) || size.equalsIgnoreCase("small")) { setTheme(R.style.PGMPLightSmall); } else if (size.equalsIgnoreCase(getString(R.string.medium)) || size.equalsIgnoreCase("medium")) { setTheme(R.style.PGMPLightMedium); } else { setTheme(R.style.PGMPLightLarge); } } boolean fullScreen = sharedPref.getBoolean("pref_full_screen_now_playing", false); currentFullScreen = fullScreen; if (fullScreen) { requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); } setContentView(R.layout.activity_now_playing); if (savedInstanceState == null) { doBindService(true); startPlayingRequired = true; } else { doBindService(false); startPlayingRequired = false; } // Get the message from the intent Intent intent = getIntent(); if (intent.getBooleanExtra(KICKOFF_SONG, false)) { desiredArtistName = intent.getStringExtra(ArtistList.ARTIST_NAME); desiredAlbumName = intent.getStringExtra(AlbumList.ALBUM_NAME); desiredArtistAbsPath = intent.getStringExtra(ArtistList.ARTIST_ABS_PATH_NAME); desiredSongAbsFileNames = intent.getStringArrayExtra(SongList.SONG_ABS_FILE_NAME_LIST); desiredAbsSongFileNamesPosition = intent.getIntExtra(SongList.SONG_ABS_FILE_NAME_LIST_POSITION, 0); desiredSongProgress = intent.getIntExtra(MusicPlaybackService.TRACK_POSITION, 0); Log.d(TAG, "Got song names " + desiredSongAbsFileNames + " position " + desiredAbsSongFileNamesPosition); TextView et = (TextView) findViewById(R.id.artistName); et.setText(desiredArtistName); et = (TextView) findViewById(R.id.albumName); et.setText(desiredAlbumName); } // The song name field will be set when we get our first update update from the service. final ImageButton pause = (ImageButton) findViewById(R.id.playPause); pause.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { playPause(); } }); ImageButton previous = (ImageButton) findViewById(R.id.previous); previous.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { previous(); } }); previous.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { jumpBack(); return true; } }); ImageButton next = (ImageButton) findViewById(R.id.next); next.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { next(); } }); final ImageButton shuffle = (ImageButton) findViewById(R.id.shuffle); shuffle.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { toggleShuffle(); } }); final ImageButton jumpback = (ImageButton) findViewById(R.id.jumpback); jumpback.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { jumpBack(); } }); SeekBar seekBar = (SeekBar) findViewById(R.id.songProgressBar); seekBar.setEnabled(true); seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { private int requestedProgress; @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { Log.v(TAG, "drag location updated..." + progress); this.requestedProgress = progress; updateSongProgressLabel(progress); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { NowPlaying.this.userDraggingProgress = true; } @Override public void onStopTrackingTouch(SeekBar seekBar) { Message msg = Message.obtain(null, MusicPlaybackService.MSG_SEEK_TO); msg.getData().putInt(MusicPlaybackService.TRACK_POSITION, requestedProgress); try { Log.i(TAG, "Sending a request to seek!"); mService.send(msg); } catch (RemoteException e) { e.printStackTrace(); } NowPlaying.this.userDraggingProgress = false; } }); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("com.smithdtyler.ACTION_EXIT"); exitReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "Received exit request, shutting down..."); Intent msgIntent = new Intent(getBaseContext(), MusicPlaybackService.class); msgIntent.putExtra("Message", MusicPlaybackService.MSG_STOP_SERVICE); startService(msgIntent); finish(); } }; registerReceiver(exitReceiver, intentFilter); }
From source file:com.qrcode.app.zxing.decoding.CaptureActivityHandler.java
@Override public void handleMessage(Message message) { switch (message.what) { case R.id.auto_focus: //Log.d(TAG, "Got auto-focus message"); // When one auto focus pass finishes, start another. This is the closest thing to // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do. if (state == State.PREVIEW) { CameraManager.get().requestAutoFocus(this, R.id.auto_focus); }// ww w . jav a 2 s . com break; case R.id.restart_preview: Log.d(TAG, "Got restart preview message"); restartPreviewAndDecode(); break; case R.id.decode_succeeded: Log.d(TAG, "Got decode succeeded message"); state = State.SUCCESS; Bundle bundle = message.getData(); /***********************************************************************/ Bitmap barcode = bundle == null ? null : (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//?????????? try { activity.handleDecode((Result) message.obj, barcode);//??????? /***********************************************************************/ } catch (JSONException e) { e.printStackTrace(); } break; case R.id.decode_failed: // We're decoding as fast as possible, so when one decode fails, start another. state = State.PREVIEW; CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); break; case R.id.return_scan_result: Log.d(TAG, "Got return scan result message"); activity.setResult(Activity.RESULT_OK, (Intent) message.obj); activity.finish(); break; case R.id.launch_product_query: Log.d(TAG, "Got product query message"); String url = (String) message.obj; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); activity.startActivity(intent); break; } }
From source file:com.onebus.zxing.decoding.CaptureActivityHandler.java
@Override public void handleMessage(Message message) { switch (message.what) { case R.id.auto_focus: //Log.d(TAG, "Got auto-focus message"); // When one auto focus pass finishes, start another. This is the closest thing to // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do. if (state == State.PREVIEW) { CameraManager.get().requestAutoFocus(this, R.id.auto_focus); }// w w w.j a v a 2s. c om break; case R.id.restart_preview: Log.d(TAG, "Got restart preview message"); restartPreviewAndDecode(); break; case R.id.decode_succeeded: Log.d(TAG, "Got decode succeeded message"); state = State.SUCCESS; Bundle bundle = message.getData(); /***********************************************************************/ Bitmap barcode = bundle == null ? null : (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);// try { activity.handleDecode((Result) message.obj, barcode); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } //? /***********************************************************************/ break; case R.id.decode_failed: // We're decoding as fast as possible, so when one decode fails, start another. state = State.PREVIEW; CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode); break; case R.id.return_scan_result: Log.d(TAG, "Got return scan result message"); activity.setResult(Activity.RESULT_OK, (Intent) message.obj); activity.finish(); break; case R.id.launch_product_query: Log.d(TAG, "Got product query message"); String url = (String) message.obj; Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); activity.startActivity(intent); break; } }