List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:com.zainsoft.ramzantimetable.QiblaActivity.java
private TimerTask getTimerTask() { TimerTask timerTask = new TimerTask() { @Override/*from w ww. j a va2s . c o m*/ public void run() { if (angleSignaled && !ConcurrencyUtil.isAnyAnimationOnRun()) { // numAnimationOnRun += 2; Map<String, Double> newAnglesMap = qiblaManager.fetchDeltaAngles(); Double newNorthAngle = newAnglesMap.get(QiblaCompassManager.NORTH_CHANGED_MAP_KEY); Double newQiblaAngle = newAnglesMap.get(QiblaCompassManager.QIBLA_CHANGED_MAP_KEY); Message message = mHandler.obtainMessage(); message.what = ROTATE_IMAGES_MESSAGE; Bundle b = new Bundle(); if (newNorthAngle == null) { b.putBoolean(IS_COMPASS_CHANGED, false); } else { ConcurrencyUtil.incrementAnimation(); b.putBoolean(IS_COMPASS_CHANGED, true); b.putDouble(COMPASS_BUNDLE_DELTA_KEY, newNorthAngle); } if (newQiblaAngle == null) { b.putBoolean(IS_QIBLA_CHANGED, false); } else { ConcurrencyUtil.incrementAnimation(); b.putBoolean(IS_QIBLA_CHANGED, true); b.putDouble(QIBLA_BUNDLE_DELTA_KEY, newQiblaAngle); } message.setData(b); mHandler.sendMessage(message); } else if (ConcurrencyUtil.getNumAimationsOnRun() < 0) { Log.d(NAMAZ_LOG_TAG, " Number of animations are negetive numOfAnimation: " + ConcurrencyUtil.getNumAimationsOnRun()); } } }; return timerTask; }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventsListFragment.java
public void acknowledgeSingleEvent(final int position) { //Log.e("acknowledgeSingleEvent","Am in acknowledgeSingleEvent with position " + Integer.toString(position)); setInProgress(position);//from w ww. ja va 2 s . co m new Thread() { public void run() { Message msg = new Message(); Bundle bndle = new Bundle(); msg.what = ACKEVENTHANDLER_FAILURE; bndle.putInt("position", position); msg.setData(bndle); try { if (null != mService && mBound) { try { if (null == mService.API) { //Log.e("acknowledgeSingleEvent","mService.API was null"); mService.PrepAPI(true, true); } //Log.e("acknowledgeSingleEvent","Logging in..."); ZenossCredentials credentials = new ZenossCredentials(getActivity()); mService.API.Login(credentials); //Log.e("acknowledgeSingleEvent","Acknowledging event"); mService.API.AcknowledgeEvent(listOfZenossEvents.get(position).getEVID()); } catch (Exception e) { e.printStackTrace(); BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "AckAllThread", e); msg.what = ACKEVENTHANDLER_FAILURE; } } else { //AckSingleEventHandler.sendEmptyMessage(ACKEVENTHANDLER_FAILURE); msg.what = ACKEVENTHANDLER_FAILURE; } //TODO Check it actually succeeded //AckSingleEventHandler.sendEmptyMessage(ACKEVENTHANDLER_SUCCESS); msg.what = ACKEVENTHANDLER_SUCCESS; } catch (Exception e) { e.printStackTrace(); //AckSingleEventHandler.sendEmptyMessage(ACKEVENTHANDLER_FAILURE); msg.what = ACKEVENTHANDLER_FAILURE; BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "AckAllThread outer catch", e); } //Log.e("acknowledgeSingleEvent","Sending Handler message"); if (null != AckSingleEventHandler) AckSingleEventHandler.sendMessage(msg); } }.start(); }
From source file:com.xmobileapp.rockplayer.LastFmAlbumArtImporter.java
/********************************* * //from w w w .j av a2s . co m * Get AlbumArt * @throws SAXException * @throws ParserConfigurationException * *********************************/ public void getAlbumArt() throws SAXException, ParserConfigurationException { /* * Initialize Album Cursor */ albumCursor = ((RockPlayer) context).contentResolver.query(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, ((RockPlayer) context).ALBUM_COLS, // we should minimize the number of columns null, // all albums null, // parameters to the previous parameter - which is null also null // sort order, SQLite-like ); /* * Declare & Initialize some vars */ String artistName = null; String albumName = null; SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); SAXParser saxParser = saxParserFactory.newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); XMLAlbumArtHandler xmlHandler = new XMLAlbumArtHandler(); // XMLGoogleAlbumArtHandler xmlGoogleHandler = new XMLGoogleAlbumArtHandler(); /* * Give feedback to the user */ Bundle data = new Bundle(); Message msg = new Message(); data.putString("info", "Looking for missing art..."); msg.setData(data); ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg); /* * Loop through the albums */ albumCursor.moveToFirst(); for (int i = 0; i < albumCursor.getCount(); i++) { System.gc(); /* * Get Album Details */ artistName = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Audio.Albums.ARTIST)); albumName = albumCursor.getString(albumCursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM)); /* * If no Art is available fetch it */ if (getAlbumArtPath(artistName, albumName) == null) { Log.i("LastFM", "Album with no Art " + albumName); try { if ((artistName.equals("<unknown>") && albumName.equals("<unknown>"))) { Log.i("ALBUMART", "Unknown album"); albumCursor.moveToNext(); continue; } } catch (Exception e) { Log.i("ALBUMART", "Null album or artist"); albumCursor.moveToNext(); continue; } /* * Give feedback to the user */ data = new Bundle(); msg = new Message(); data.putString("info", albumName); msg.setData(data); ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg); String albumArtURL = null; try { /* * Get album URL from Last.FM */ String artistNameFiltered = filterString(artistName); String albumNameFiltered = filterString(albumName); if (USE_GOOGLE_IMAGES) { // xmlReader.setContentHandler(xmlGoogleHandler); URL googleImagesRequest = new URL( this.GOOGLE_IMAGES_SEARCH_URL + URLEncoder.encode(artistNameFiltered) + "+" + URLEncoder.encode(albumNameFiltered)); // Log.i("GOOGLEIMAGES", googleImagesRequest.toString()); // DefaultHttpClientConnection httpCon = createGoogleImageConnection( // googleImagesRequest.toString()); /* * retreive URL */ BasicHttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 10000); DefaultHttpClient httpClient = new DefaultHttpClient(); // Get cookies from the login page (not the address same of the form post) HttpGet httpGet = new HttpGet(googleImagesRequest.toString()); HttpResponse response; try { /* * Get the page */ response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent())); /* * Parse 1st existing image on the result page */ String line; int idxStart = 0; int idxStop; do { line = in.readLine(); if (line != null) { // Log.i("GIMAGES", line); if (line.startsWith("<table")) { boolean found = false; int tries = 0; while (!found) { tries++; if (tries > 12) break; idxStart = line.indexOf("<a href=", idxStart); if (idxStart == -1) { line = in.readLine(); if (line == null) break; continue; } idxStart = line.indexOf("http://", idxStart); idxStop = line.indexOf("&imgrefurl=", idxStart); albumArtURL = line.substring(idxStart, idxStop); Log.i("GIMAGE", line.substring(idxStart, idxStop)); try { //URL albumArt = new URL(URLEncoder.encode(albumArtURL)); // URL albumArt = new URL(albumArtURL); // InputStream albumArtURLStream = albumArt.openStream(); // albumArtURLStream.close(); if (albumArtURL != null) { if (createAlbumArt(artistName, albumName, albumArtURL) == null) { albumArtURL = null; found = false; Log.i("GIMAGES", "createAlbumArt FAIL"); } else { found = true; Log.i("GIMAGES", "createAlbumArt WIN"); } } else { albumArtURL = null; found = false; Log.i("GIMAGES", "albumArt URL FAIL!"); } } catch (Exception e) { e.printStackTrace(); albumArtURL = null; found = false; } } break; } } } while (line != null); // xmlReader.parse(new InputSource(in)); entity.consumeContent(); // for(int j = 0; j < xmlGoogleHandler.MAX_IMAGES; j++){ // if(xmlGoogleHandler.albumArtUrl[j] != null){ // albumArtURL = xmlGoogleHandler.albumArtUrl[j]; // break; // } // } /* * No luck with the duck */ // if(albumArtURL == null){ // Log.i("GOOGLEIMAGES", "Absolutely no luck"); // // mark this as a problematic album... // // so we dont refetch it all the time // createSmallAlbumArt(artistName, albumName, false); // albumCursor.moveToNext(); // continue; // } else { // Log.i("GOOGLEIMAGES", albumArtURL); // } /* * Clear up the Handler */ // xmlGoogleHandler.clear(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } // // /* // * No Album Art available // * 1. try going by the album name // * 2. get some artist pic and thats it // */ // if(albumArtURL == null){ // Log.i("LASTFM", "Could not get album art immediately"); // Log.i("LASTFM", "Trying sole album search"); // // albumArtURL = getAlbumArtByAlbumName(albumName, artistName); // if(albumArtURL == null){ // Log.i("LASTFM", "Trying to get artist Art"); // albumArtURL = getArtistArt(artistName); // } // /* // * No luck with the duck // */ // if(albumArtURL == null){ // Log.i("LASTFM", "Absolutely no luck"); // // mark this as a problematic album... // // so we dont refetch it all the time // createSmallAlbumArt(artistName, albumName, false); // albumCursor.moveToNext(); // continue; // } // } } /* * If google images failed try last.fm */ if (albumArtURL == null) { xmlReader.setContentHandler(xmlHandler); URL lastFmApiRequest = new URL( this.LAST_FM_ALBUM_GETINFO_URL + "&artist=" + URLEncoder.encode(artistNameFiltered) + "&album=" + URLEncoder.encode(albumNameFiltered)); try { BufferedReader in = new BufferedReader( new InputStreamReader(lastFmApiRequest.openStream())); xmlReader.parse(new InputSource(in)); if (xmlHandler.xlargeAlbumArt != null) { albumArtURL = xmlHandler.xlargeAlbumArt; } else if (xmlHandler.largeAlbumArt != null) { albumArtURL = xmlHandler.largeAlbumArt; } else if (xmlHandler.mediumAlbumArt != null) { albumArtURL = xmlHandler.mediumAlbumArt; } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } /* * No Album Art available * 1. try going by the album name * 2. get some artist pic and thats it */ if (albumArtURL == null) { Log.i("LASTFM", "Could not get album art immediately"); Log.i("LASTFM", "Trying sole album search"); albumArtURL = getAlbumArtByAlbumName(albumName, artistName); if (albumArtURL == null) { Log.i("LASTFM", "Trying to get artist Art"); albumArtURL = getArtistArt(artistName); } /* * No luck with the duck */ if (albumArtURL == null) { Log.i("LASTFM", "Absolutely no luck"); // mark this as a problematic album... // so we dont refetch it all the time createSmallAlbumArt(artistName, albumName, false); albumCursor.moveToNext(); continue; } } /* only reaches here if not FAIL */ createAlbumArt(artistName, albumName, albumArtURL); } /* * reset xml handler */ xmlHandler.smallAlbumArt = null; xmlHandler.mediumAlbumArt = null; xmlHandler.largeAlbumArt = null; xmlHandler.xlargeAlbumArt = null; } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } } /* * Create small album art */ createSmallAlbumArt(artistName, albumName, true); /* * Give feedback to the user */ //Bundle data = new Bundle(); //Message msg = new Message(); //data.putString("info", "Creating Thumbnail"); //msg.setData(data); //((Filex) context).getAlbumArtHandler.sendMessage(msg); albumCursor.moveToNext(); } /* * Give feedback to the user */ data = new Bundle(); msg = new Message(); data.putString("info", "Done!"); msg.setData(data); ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg); /* * Set the last import date on preferences */ // SharedPreferences settings = ((Filex) this.context).getSharedPreferences(((Filex) this.context).PREFS_NAME, 0); // Editor editor = settings.edit(); // editor.putLong("artImportDate", System.currentTimeMillis()); // editor.commit(); RockOnPreferenceManager settings = new RockOnPreferenceManager( ((RockPlayer) context).FILEX_PREFERENCES_PATH); settings.putLong("artImportDate", System.currentTimeMillis()); //settings. // long lastAlbumArtImportDate = settings.getLong("artImportDate", 0); }
From source file:com.nbplus.iotapp.service.IoTService.java
/** * ?? Request? .//from w ww. j ava2 s . c o m * ? Async ? ? ? ? ? ? ? ?? . * * @param clientMessenger * @param msgId * @param command * @param result */ private void sendResultToApplication(Messenger clientMessenger, String msgId, String deviceId, int command, IoTResultCodes result) { if (clientMessenger != null) { Message response = new Message(); response.what = IoTServiceCommand.COMMAND_RESPONSE; // ?? Bundle ? request command (int) result code (serializable) ?. Bundle b = new Bundle(); b.putString(IoTServiceCommand.KEY_MSGID, msgId); b.putInt(IoTServiceCommand.KEY_CMD, command); b.putString(IoTServiceCommand.KEY_DEVICE_UUID, deviceId); b.putSerializable(IoTServiceCommand.KEY_RESULT, result); response.setData(b); try { clientMessenger.send(response); } catch (RemoteException e) { e.printStackTrace(); } } }
From source file:com.norman0406.slimgress.API.Game.GameState.java
public synchronized void intHandshake(final Handler handler) { mInterface.handshake(new Handshake.Callback() { @Override/* ww w . jav a2s .c om*/ public void handle(Handshake handshake) { mHandshake = handshake; mKnobs = mHandshake.getKnobs(); Message msg = new Message(); Bundle bundle = new Bundle(); bundle.putBoolean("Successful", mHandshake.isValid()); if (!mHandshake.isValid()) { String errString; if (mHandshake.getPregameStatus() == Handshake.PregameStatus.ClientMustUpgrade) errString = "Client must upgrade"; else if (mHandshake.getAgent() == null) errString = "Invalid agent data"; else errString = "Unknown error"; bundle.putString("Error", errString); } msg.setData(bundle); handler.sendMessage(msg); } }); }
From source file:com.apptentive.android.sdk.module.messagecenter.view.MessageCenterActivityContent.java
@Override public void onFinishComposing() { messageCenterListAdapter.setForceShowKeyboard(false); Util.hideSoftKeyboard(viewActivity, viewActivity.findViewById(android.R.id.content)); if (contextualMessage != null) { unsendMessagesCount++;/* w w w . j av a 2s.com*/ MessageManager.sendMessage(viewActivity.getApplicationContext(), contextualMessage); contextualMessage = null; } Editable content = getPendingComposingContent(); final String messageText = (content != null) ? content.toString().trim() : ""; final ArrayList<ImageItem> messageAttachments = new ArrayList<ImageItem>(); messageAttachments.addAll(imageAttachmentstList); // Close all composing UI clearComposingUi(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { messages.remove(actionBarItem); messages.remove(composingItem); actionBarItem = null; composingItem = null; messageEditText = null; messageCenterListAdapter.clearComposing(); messageCenterListAdapter.notifyDataSetChanged(); clearPendingComposingMessage(); // Send out the new message. The delay is added to ensure the CardView showing animation // is visible after the keyboard is hidden if (!messageText.isEmpty() || imageAttachmentstList.size() != 0) { Bundle b = new Bundle(); b.putString(COMPOSING_EDITTEXT_STATE, messageText); b.putParcelableArrayList(COMPOSING_ATTACHMENTS, messageAttachments); Message msg = messageCenterViewHandler.obtainMessage(MSG_START_SENDING, messageText); msg.setData(b); messageCenterViewHandler.sendMessageDelayed(msg, DEFAULT_DELAYMILLIS); } imageAttachmentstList.clear(); showFab(); showProfileButton(); } @Override public void onAnimationCancel(Animator animation) { } }, null, DEFAULT_DELAYMILLIS); }
From source file:org.navitproject.navit.Navit.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case Navit.NavitDownloaderSelectMap_id: if (resultCode == Activity.RESULT_OK) { Message msg = dialogs.obtainMessage(NavitDialogs.MSG_START_MAP_DOWNLOAD, data.getIntExtra("map_index", -1), 0); msg.sendToTarget();/*from w w w . j av a2s . c om*/ } break; case NavitAddressSearch_id: if (resultCode == Activity.RESULT_OK) { Bundle destination = data.getExtras(); Toast.makeText(getApplicationContext(), getString(R.string.address_search_set_destination) + "\n" + destination.getString(("q")), Toast.LENGTH_LONG).show(); //TRANS Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal()); msg.setData(destination); msg.sendToTarget(); } break; case NavitSelectStorage_id: if (resultCode == RESULT_OK) { String newDir = data.getStringExtra(FileBrowserActivity.returnDirectoryParameter); Log.d(TAG, "selected path= " + newDir); if (!newDir.contains("/navit")) newDir = newDir + "/navit/"; else newDir = newDir + "/"; SharedPreferences prefs = this.getSharedPreferences(NAVIT_PREFS, MODE_PRIVATE); SharedPreferences.Editor prefs_editor = prefs.edit(); prefs_editor.putString("filenamePath", newDir); prefs_editor.commit(); Toast.makeText(this, String .format(Navit._("New location set to %s\nRestart Navit to apply the changes."), newDir), Toast.LENGTH_LONG).show(); } else Log.w(TAG, "select path failed"); break; default: //Log.e("Navit", "onActivityResult " + requestCode + " " + resultCode); ActivityResults[requestCode].onActivityResult(requestCode, resultCode, data); break; } }
From source file:com.lewa.crazychapter11.MainActivity.java
private void cal() { Message msg = new Message(); msg.what = 0x1234;//from ww w. j a va 2 s . co m Bundle bundle = new Bundle(); bundle.putInt(UPPER_NUM, Integer.parseInt(etNum.getText().toString())); msg.setData(bundle); calThread.mHandler.sendMessage(msg); }
From source file:com.nbplus.iotapp.service.IoTService.java
/** * ?? ? ? ./*from www . j av a 2 s .c om*/ */ private void sendServiceStatusNotification() { if (PackageUtils.isActivePackage(this, getApplicationContext().getPackageName() + ":remote")) { Log.d(TAG, "Remote process(RealtimeBroadcast..) is running..."); return; } Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); if (clientMessenger != null) { Message response = new Message(); response.what = IoTServiceCommand.SERVICE_STATUS_NOTIFICATION; // ?? Bundle ? request command (int) result code (serializable) ?. Bundle b = new Bundle(); b.putString(IoTServiceCommand.KEY_MSGID, /*this.getApplicationContext().*/getPackageName() + "_" + System.currentTimeMillis()); b.putSerializable(IoTServiceCommand.KEY_SERVICE_STATUS, mServiceStatus); b.putSerializable(IoTServiceCommand.KEY_SERVICE_STATUS_CODE, mErrorCodes); response.setData(b); try { clientMessenger.send(response); } catch (RemoteException e) { e.printStackTrace(); } } }
From source file:org.spontaneous.trackservice.RemoteService.java
/** * Consult broadcast options and execute broadcast if necessary * * @param location//from w ww. ja v a2 s . c o m */ public void broadcastLocation(Location location) { final long nowTime = location.getTime(); if (this.mLastTimeBroadcast == 0) { this.mLastTimeBroadcast = nowTime; } long passedTime = (nowTime - this.mLastTimeBroadcast); Message msg = this.mHandler.obtainMessage(REPORT_MSG); Bundle data = new Bundle(); data.putLong(TrackingServiceConstants.TRACK_ID, this.mTrackId); data.putLong(TrackingServiceConstants.SEGMENT_ID, this.mSegmentId); data.putLong(TrackingServiceConstants.WAYPOINT_ID, this.mWaypointId); data.putLong(TrackingServiceConstants.EXTRA_TIME, passedTime); data.putParcelable(TrackingServiceConstants.EXTRA_LOCATION, location); data.putFloat(TrackingServiceConstants.EXTRA_DISTANCE, this.mDistance); data.putFloat(TrackingServiceConstants.TOTAL_DISTANCE, this.mTotalDistance); data.putFloat(TrackingServiceConstants.EXTRA_SPEED, location.getSpeed()); msg.setData(data); this.mHandler.sendMessage(msg); }