List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:org.zywx.wbpalmstar.engine.universalex.EUExWidget.java
public void reloadWidgetByAppId(String[] params) { if (params.length < 1) { return;//from w w w . j a va2 s . c o m } Message msg = mHandler.obtainMessage(); msg.what = MSG_RELOAD_WIDGET_BY_APPID; msg.obj = this; Bundle bd = new Bundle(); bd.putStringArray(BUNDLE_DATA, params); msg.setData(bd); mHandler.sendMessage(msg); }
From source file:org.navitproject.navit.Navit.java
void setDestination(float latitude, float longitude, String address) { Toast.makeText(getApplicationContext(), getString(R.string.address_search_set_destination) + "\n" + address, Toast.LENGTH_LONG).show(); //TRANS Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_SET_DESTINATION.ordinal()); Bundle b = new Bundle(); b.putFloat("lat", latitude); b.putFloat("lon", longitude); b.putString("q", address); msg.setData(b); msg.sendToTarget();//from w w w.ja va2s . c om }
From source file:org.navitproject.navit.Navit.java
public void runOptionsItem(int id) { // Handle item selection switch (id) { case 1://from ww w . j a v a 2 s . c om // zoom in Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_IN.ordinal()) .sendToTarget(); // if we zoom, hide the bubble Log.e("Navit", "onOptionsItemSelected -> zoom in"); break; case 2: // zoom out Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_ZOOM_OUT.ordinal()) .sendToTarget(); // if we zoom, hide the bubble Log.e("Navit", "onOptionsItemSelected -> zoom out"); break; case 3: // map download menu Intent map_download_list_activity = new Intent(this, NavitDownloadSelectMapActivity.class); startActivityForResult(map_download_list_activity, Navit.NavitDownloaderSelectMap_id); break; case 5: // toggle the normal POI layers and labels (to avoid double POIs) Message msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal()); Bundle b = new Bundle(); b.putString("cmd", "toggle_layer(\"POI Symbols\");"); msg.setData(b); msg.sendToTarget(); msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal()); b = new Bundle(); b.putString("cmd", "toggle_layer(\"POI Labels\");"); msg.setData(b); msg.sendToTarget(); // toggle full POI icons on/off msg = Message.obtain(N_NavitGraphics.callback_handler, NavitGraphics.msg_type.CLB_CALL_CMD.ordinal()); b = new Bundle(); b.putString("cmd", "toggle_layer(\"Android-POI-Icons-full\");"); msg.setData(b); msg.sendToTarget(); break; case 6: // ok startup address search activity Intent search_intent = new Intent(this, NavitAddressSearchActivity.class); this.startActivityForResult(search_intent, NavitAddressSearch_id); break; case 7: /* Backup / Restore */ showDialog(NavitDialogs.DIALOG_BACKUP_RESTORE); break; case 10: setMapLocation(); break; case 99: // exit this.onStop(); this.exit(); break; } }
From source file:com.shurik.droidzebra.ZebraEngine.java
private JSONObject Callback(int msgcode, JSONObject data) { JSONObject retval = null;/*from ww w. j a v a 2s. com*/ Message msg = mHandler.obtainMessage(msgcode); Bundle b = new Bundle(); msg.setData(b); // Log.d("ZebraEngine", String.format("Callback(%d,%s)", msgcode, data.toString())); if (bInCallback) fatalError("Recursive vallback call"); try { bInCallback = true; switch (msgcode) { case MSG_ERROR: { b.putString("error", data.getString("error")); if (getEngineState() == ES_INITIAL) { // delete .bin files if initialization failed // will be recreated from resources new File(mFilesDir, PATTERNS_FILE).delete(); new File(mFilesDir, BOOK_FILE).delete(); new File(mFilesDir, BOOK_FILE_COMPRESSED).delete(); } mHandler.sendMessage(msg); } break; case MSG_DEBUG: { b.putString("message", data.getString("message")); mHandler.sendMessage(msg); } break; case MSG_BOARD: { int len; JSONObject info; JSONArray zeArray; byte[] moves; JSONArray zeboard = data.getJSONArray("board"); byte newBoard[] = new byte[BOARD_SIZE * BOARD_SIZE]; for (int i = 0; i < zeboard.length(); i++) { JSONArray row = zeboard.getJSONArray(i); for (int j = 0; j < row.length(); j++) { newBoard[i * BOARD_SIZE + j] = (byte) row.getInt(j); } } b.putByteArray("board", newBoard); b.putInt("side_to_move", data.getInt("side_to_move")); mCurrentGameState.mDisksPlayed = data.getInt("disks_played"); // black info { Bundle black = new Bundle(); info = data.getJSONObject("black"); black.putString("time", info.getString("time")); black.putFloat("eval", (float) info.getDouble("eval")); black.putInt("disc_count", info.getInt("disc_count")); black.putString("time", info.getString("time")); zeArray = info.getJSONArray("moves"); len = zeArray.length(); moves = new byte[len]; assert (2 * len <= mCurrentGameState.mMoveSequence.length); for (int i = 0; i < len; i++) { moves[i] = (byte) zeArray.getInt(i); mCurrentGameState.mMoveSequence[2 * i] = moves[i]; } black.putByteArray("moves", moves); b.putBundle("black", black); } // white info { Bundle white = new Bundle(); info = data.getJSONObject("white"); white.putString("time", info.getString("time")); white.putFloat("eval", (float) info.getDouble("eval")); white.putInt("disc_count", info.getInt("disc_count")); white.putString("time", info.getString("time")); zeArray = info.getJSONArray("moves"); len = zeArray.length(); moves = new byte[len]; assert ((2 * len + 1) <= mCurrentGameState.mMoveSequence.length); for (int i = 0; i < len; i++) { moves[i] = (byte) zeArray.getInt(i); mCurrentGameState.mMoveSequence[2 * i + 1] = moves[i]; } white.putByteArray("moves", moves); b.putBundle("white", white); } mHandler.sendMessage(msg); } break; case MSG_CANDIDATE_MOVES: { JSONArray jscmoves = data.getJSONArray("moves"); CandidateMove cmoves[] = new CandidateMove[jscmoves.length()]; mValidMoves = new int[jscmoves.length()]; for (int i = 0; i < jscmoves.length(); i++) { JSONObject jscmove = jscmoves.getJSONObject(i); mValidMoves[i] = jscmoves.getJSONObject(i).getInt("move"); cmoves[i] = new CandidateMove(new Move(jscmove.getInt("move"))); } msg.obj = cmoves; mHandler.sendMessage(msg); } break; case MSG_GET_USER_INPUT: { mMovesWithoutInput = 0; setEngineState(ES_USER_INPUT_WAIT); waitForEngineState(ES_PLAY); while (mPendingEvent == null) { setEngineState(ES_USER_INPUT_WAIT); waitForEngineState(ES_PLAY); } retval = mPendingEvent; setEngineState(ES_PLAYINPROGRESS); mValidMoves = null; mPendingEvent = null; } break; case MSG_PASS: { setEngineState(ES_USER_INPUT_WAIT); mHandler.sendMessage(msg); waitForEngineState(ES_PLAY); setEngineState(ES_PLAYINPROGRESS); } break; case MSG_OPENING_NAME: { b.putString("opening", data.getString("opening")); mHandler.sendMessage(msg); } break; case MSG_LAST_MOVE: { b.putInt("move", data.getInt("move")); mHandler.sendMessage(msg); } break; case MSG_GAME_START: { mHandler.sendMessage(msg); } break; case MSG_GAME_OVER: { mHandler.sendMessage(msg); } break; case MSG_MOVE_START: { mMoveStartTime = android.os.SystemClock.uptimeMillis(); mSideToMove = data.getInt("side_to_move"); // can change player info here if (mPlayerInfoChanged) { zeSetPlayerInfo(PLAYER_BLACK, mPlayerInfo[PLAYER_BLACK].skill, mPlayerInfo[PLAYER_BLACK].exactSolvingSkill, mPlayerInfo[PLAYER_BLACK].wldSolvingSkill, mPlayerInfo[PLAYER_BLACK].playerTime, mPlayerInfo[PLAYER_BLACK].playerTimeIncrement); zeSetPlayerInfo(PLAYER_WHITE, mPlayerInfo[PLAYER_WHITE].skill, mPlayerInfo[PLAYER_WHITE].exactSolvingSkill, mPlayerInfo[PLAYER_WHITE].wldSolvingSkill, mPlayerInfo[PLAYER_WHITE].playerTime, mPlayerInfo[PLAYER_WHITE].playerTimeIncrement); zeSetPlayerInfo(PLAYER_ZEBRA, mPlayerInfo[PLAYER_ZEBRA].skill, mPlayerInfo[PLAYER_ZEBRA].exactSolvingSkill, mPlayerInfo[PLAYER_ZEBRA].wldSolvingSkill, mPlayerInfo[PLAYER_ZEBRA].playerTime, mPlayerInfo[PLAYER_ZEBRA].playerTimeIncrement); } mHandler.sendMessage(msg); } break; case MSG_MOVE_END: { // introduce delay between moves made by the computer without user input // so we can actually to see that the game is being played :) if (mMoveDelay > 0 || (mMovesWithoutInput > 1 && mPlayerInfo[mSideToMove].skill > 0)) { long moveEnd = android.os.SystemClock.uptimeMillis(); int delay = mMoveDelay > 0 ? mMoveDelay : SELFPLAY_MOVE_DELAY; if ((moveEnd - mMoveStartTime) < delay) { android.os.SystemClock.sleep(delay - (moveEnd - mMoveStartTime)); } } // this counter is reset by user input mMovesWithoutInput += 1; mHandler.sendMessage(msg); } break; case MSG_EVAL_TEXT: { b.putString("eval", data.getString("eval")); mHandler.sendMessage(msg); } break; case MSG_PV: { JSONArray zeArray = data.getJSONArray("pv"); int len = zeArray.length(); byte[] moves = new byte[len]; for (int i = 0; i < len; i++) moves[i] = (byte) zeArray.getInt(i); b.putByteArray("pv", moves); mHandler.sendMessage(msg); } break; case MSG_CANDIDATE_EVALS: { JSONArray jscevals = data.getJSONArray("evals"); CandidateMove cmoves[] = new CandidateMove[jscevals.length()]; for (int i = 0; i < jscevals.length(); i++) { JSONObject jsceval = jscevals.getJSONObject(i); cmoves[i] = new CandidateMove(new Move(jsceval.getInt("move")), jsceval.getString("eval_s"), jsceval.getString("eval_l"), (jsceval.getInt("best") != 0)); } msg.obj = cmoves; mHandler.sendMessage(msg); } break; default: { b.putString("error", String.format("Unkown message ID %d", msgcode)); msg.setData(b); mHandler.sendMessage(msg); } break; } } catch (JSONException e) { msg.what = MSG_ERROR; b.putString("error", "JSONException:" + e.getMessage()); msg.setData(b); mHandler.sendMessage(msg); } finally { bInCallback = false; } return retval; }
From source file:ch.bfh.evoting.alljoyn.BusHandler.java
/** * Method processing the message received * @param messageObject object containing the message transmitted over the newtork *//* w w w . java 2 s .c o m*/ private void processMessage(AllJoynMessage messageObject) { /* * First we check if decrypter is ready. If not, only Salt message can go further */ //if messageEncrypter isn't ready to decrypt and message is encrypted if (!messageEncrypter.isReady() && messageObject.isEncrypted()) { //requeue the message in order to process it later Message msg = this.obtainMessage(BusHandler.REPROCESS_MESSAGE); Bundle data = new Bundle(); data.putSerializable("message", messageObject); msg.setData(data); this.sendMessage(msg); Log.d(TAG, "Requeueing message received"); return; } /* * Second, we check if the message contains the salt and extract it */ //Check if the message contains the salt if (messageObject.getType().equals(Type.SALT)) { if (messageEncrypter.getSalt() == null) { this.saltReceived(messageObject); return; } } /* * Third, we check if the message contains an identity */ //Check if message contain an identity if (messageObject.getType().equals(Type.IDENTITY)) { extractIdentity(messageObject); return; } /* * Fourth, we verify the signature, if we know the sender, otherwise we set a flag */ if (identityMap.containsKey(messageObject.getSender())) { boolean result = messageObject.verifyMessage(identityMap.get(messageObject.getSender()).getPublicKey());//messageAuthenticater.verifySignature(identityMap.get(sender).getPublicKey(), Base64.decode(signature,Base64.DEFAULT), Base64.decode(message,Base64.DEFAULT)); if (!result) { //signature verification failed //ignoring message Log.e(TAG, "Wrong signature"); return; } else { Log.d(TAG, "Signature correct"); } } else { //message not containing a salt nor an identity coming from an unknown person => ignore Log.d(TAG, "Ignoring message since sender is not known"); //try to decrypt in order to detect if it could be a password error messageObject.getMessage(); return; } /* * Fifth, we decrypt the message */ String decryptedString = messageObject.getMessage(); if (decryptedString == null || decryptedString.equals("")) { //decryption failed Log.d(TAG, "Message decryption failed"); return; } /* * Sixth, we transmit message to the application */ //Send the message to the app Intent i = new Intent("messageArrived"); i.putExtra("senderId", messageObject.getSender()); i.putExtra("senderName", identityMap.get(messageObject.getSender()).getName()); i.putExtra("message", decryptedString); LocalBroadcastManager.getInstance(context).sendBroadcast(i); }
From source file:ch.bfh.evoting.alljoyn.BusHandler.java
/** * Helper method send my identity to the other peers *///from w w w . j a v a2s . c o m private void sendMyIdentity() { Log.d(TAG, "Sending my identity"); String myName = userDetails.getString("identification", ""); //save my own identity in identityMap Identity myIdentity = new Identity(myName, messageAuthenticater.getMyPublicKey()); identityMap.put(this.getIdentification(), myIdentity); byte[] publicKeyBytes = messageAuthenticater.getMyPublicKey().getEncoded(); if (publicKeyBytes == null) { Log.e(TAG, "Key encoding not supported"); } String myKey = Base64.encodeToString(publicKeyBytes, Base64.DEFAULT); String identity = myName + MESSAGE_PARTS_SEPARATOR + myKey; Log.d(TAG, "Send my identity"); //send my identity Message msg = obtainMessage(BusHandler.PING); Bundle data = new Bundle(); data.putString("groupName", lastJoinedNetwork); data.putString("pingString", identity); data.putSerializable("type", Type.IDENTITY); msg.setData(data); sendMessage(msg); }
From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java
/** * Implementation of Runnable. This runnable thread gets the k by reverse * Geocode in the background. Results are sent to the handler. *//* w w w . j av a 2 s .c om*/ @Override public void run() { String address = null; try { /** * Reverse Geocode search. */ address = GeoHelper.findAddressFromLocation(getActivity(), mGeoLat, mGeoLng); } catch (IOException e) { e.printStackTrace(); } final Message msg = handler.obtainMessage(); final Bundle b = new Bundle(); if (address == null) { /** * Send error message to handler. */ b.putInt(Const.KEY_BUNDLE_REVERSE_GEOCODER, Const.BUNDLE_SEARCH_ADDRESS_ERROR); } else { /** * Send success message to handler with the found geocoordinates. */ b.putInt(Const.KEY_BUNDLE_REVERSE_GEOCODER, Const.BUNDLE_SEARCH_ADDRESS_SUCCESS); b.putString(Const.KEY_BUNDLE_ADDRESS_DESC, address); } msg.setData(b); handler.sendMessage(msg); }
From source file:com.xmobileapp.rockplayer.LastFmAlbumArtImporter.java
/********************************* * /*w w w . j a v a 2s.c om*/ * Constructor * @param context * *********************************/ public LastFmAlbumArtImporter(Context context) { this.context = context; try { /* * Check for Internet Connection (Through whichever interface) */ ConnectivityManager connManager = (ConnectivityManager) ((RockPlayer) context) .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connManager.getActiveNetworkInfo(); /******* EMULATOR HACK - false condition needs to be removed *****/ //if (false && (netInfo == null || !netInfo.isConnected())){ if ((netInfo == null || netInfo.isConnected() == false)) { Bundle data = new Bundle(); data.putString("info", "No Internet Connection"); Message msg = new Message(); msg.setData(data); ((RockPlayer) context).getAlbumArtHandler.sendMessage(msg); return; } /* * Import Album Art from Last FM */ //getAlbumArt(); } catch (Exception e) { e.printStackTrace(); } }
From source file:my.home.lehome.service.SendMsgIntentService.java
private void preparePengindCommand(Intent intent) { Messenger messenger;//from ww w .j a va2 s. c om if (intent.hasExtra("messenger")) messenger = (Messenger) intent.getExtras().get("messenger"); else messenger = null; Message repMsg = Message.obtain(); repMsg.what = MSG_BEGIN_SENDING; boolean isSysCmd = intent.getBooleanExtra("isSysCmd", false); if (isSysCmd) { Log.d(TAG, "sys cmd item"); return; } ChatItem item = intent.getParcelableExtra("update"); if (item == null) { item = new ChatItem(); item.setContent(intent.getStringExtra("cmd")); item.setType(ChatItemConstants.TYPE_CLIENT); item.setState(Constants.CHATITEM_STATE_ERROR); // set ERROR item.setDate(new Date()); DBStaticManager.addChatItem(getApplicationContext(), item); } item.setState(Constants.CHATITEM_STATE_PENDING); Log.d(TAG, "enqueue item: \n" + item); Bundle bundle = new Bundle(); bundle.putBoolean("update", intent.hasExtra("update")); bundle.putParcelable("item", item); if (messenger != null) { repMsg.setData(bundle); try { messenger.send(repMsg); } catch (RemoteException e) { e.printStackTrace(); } } else { Log.d(TAG, "messager is null, send broadcast instead:" + ACTION_SEND_MSG_BEGIN); Intent newIntent = new Intent(ACTION_SEND_MSG_BEGIN); newIntent.putExtras(bundle); sendBroadcast(newIntent); } intent.putExtra("pass_item", item); }
From source file:ch.bfh.evoting.alljoyn.BusHandler.java
/** * Send a message to the given group//from www.ja v a 2 s. c o m * @param groupName group to send the message to * @param message message to send * @param encrypted indicate if message must be encrypted or not * @param type type of the content in the message */ private void doPing(String groupName, String message, boolean encrypted, Type type) { //if messageEncrypter is not ready or group joining is not terminated, we enqueue the message if ((!messageEncrypter.isReady() && encrypted) || !connected) { Message msg = this.obtainMessage(BusHandler.PING); Bundle data = new Bundle(); data.putString("groupName", groupName); data.putString("pingString", message); data.putBoolean("encrypted", encrypted); data.putSerializable("type", type); msg.setData(data); this.sendMessage(msg); Log.d(TAG, "Queueing message to send " + message); return; } //Create the message object with the received parameter AllJoynMessage messageObject = new AllJoynMessage(this.messageEncrypter, this.messageAuthenticater); if (type == null) type = Type.NORMAL; messageObject.setType(type); messageObject.setSender(this.getIdentification()); boolean messageEncrypted = messageObject.setMessage(message, encrypted); if (!messageEncrypted) { Log.e(TAG, "Message encryption failed"); return; } boolean messageSigned = messageObject.signMessage(); if (!messageSigned) { Log.e(TAG, "Signature failed"); return; } //Serialize the message messageObject.setMessageAuthenticater(null); messageObject.setMessageEncrypter(null); String toSend = su.serialize(messageObject); try { Log.d(TAG, "sending message of size " + toSend.getBytes("UTF-8").length + " bytes. Maximum allowed by AllJoyn is 128Kb."); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } //Send the message SimpleInterface simpleInterface = mGroupManager.getSignalInterface(groupName, mSimpleService, SimpleInterface.class); try { if (simpleInterface != null) { simpleInterface.Ping(toSend); } } catch (BusException e) { e.printStackTrace(); } }