List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:net.networksaremadeofstring.rhybudd.DeviceList.java
public void Refresh() { if (dialog != null) { dialog.setTitle("Contacting Zenoss..."); dialog.setMessage("Please wait:\nLoading Infrastructure...."); dialog.setCancelable(false);/*w w w . ja v a 2 s . com*/ if (!dialog.isShowing()) { dialog.show(); } } else { dialog = new ProgressDialog(this); dialog.setTitle("Contacting Zenoss..."); dialog.setMessage("Please wait:\nLoading Infrastructure...."); dialog.setCancelable(false); dialog.show(); } if (listOfZenossDevices != null) listOfZenossDevices.clear(); ((Thread) new Thread() { public void run() { String MessageExtra = ""; try { Message msg = new Message(); Bundle bundle = new Bundle(); ZenossAPI API = null; try { if (PreferenceManager.getDefaultSharedPreferences(DeviceList.this) .getBoolean(ZenossAPI.PREFERENCE_IS_ZAAS, false)) { API = new ZenossAPIZaas(); } else { API = new ZenossAPICore(); } ZenossCredentials credentials = new ZenossCredentials(DeviceList.this); API.Login(credentials); } catch (ConnectTimeoutException cte) { if (cte.getMessage() != null) { bundle.putString("exception", "The connection timed out;\r\n" + cte.getMessage().toString()); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "The connection timed out;\r\n" + cte.getMessage().toString(), Toast.LENGTH_LONG).show(); } else { bundle.putString("exception", "A time out error was encountered but the exception thrown contains no further information."); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "A time out error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); } } catch (Exception e) { if (e.getMessage() != null) { bundle.putString("exception", "An error was encountered;\r\n" + e.getMessage().toString()); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "An error was encountered;\r\n" + e.getMessage().toString(), Toast.LENGTH_LONG).show(); } else { bundle.putString("exception", "An error was encountered but the exception thrown contains no further information."); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); //Toast.makeText(DeviceList.this, "An error was encountered but the exception thrown contains no further information.", Toast.LENGTH_LONG).show(); } } try { if (API != null) { listOfZenossDevices = API.GetRhybuddDevices(); } else { listOfZenossDevices = null; } } catch (Exception e) { if (e.getMessage() != null) MessageExtra = e.getMessage(); listOfZenossDevices = null; } if (listOfZenossDevices != null && listOfZenossDevices.size() > 0) { DeviceCount = listOfZenossDevices.size(); Message.obtain(); handler.sendEmptyMessage(1); RhybuddDataSource datasource = new RhybuddDataSource(DeviceList.this); datasource.open(); datasource.UpdateRhybuddDevices(listOfZenossDevices); datasource.close(); } else { //Message msg = new Message(); //Bundle bundle = new Bundle(); bundle.putString("exception", "A query to both the local DB and Zenoss API returned no devices. " + MessageExtra); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); } } catch (Exception e) { //BugSenseHandler.log("DeviceList", e); Message msg = new Message(); Bundle bundle = new Bundle(); bundle.putString("exception", e.getMessage()); msg.setData(bundle); msg.what = 0; handler.sendMessage(msg); } } }).start(); }
From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java
@SuppressFBWarnings("ANDROID_BROADCAST") private void sendBroadcastMessageToAllLocalClients(BroadcastMessage msg) { for (int i = mClients.size() - 1; i >= 0; i--) { try {//www . ja v a 2 s .co m // local directly connected activities (i.e., ours) Messenger client = mClients.get(i); Message message = Message.obtain(null, MSG_BROADCAST); message.replyTo = mMessenger; Bundle bundle = new Bundle(1); bundle.putSerializable(PluginIntent.KEY_BROADCAST_MESSAGE, msg); message.setData(bundle); client.send(message); // local unconnected activities (i.e., plugins) Log.d(TAG, "Sending broadcast message to all local clients with package " + mConnectionOptions.mPluginPackage + " - type: " + msg.getType() + ", message: " + msg.getMessage()); Intent broadcastIntent = new Intent(PluginIntent.ACTION_MESSAGE_RECEIVED); broadcastIntent.setClassName(mConnectionOptions.mPluginPackage, PluginIntent.MESSAGE_RECEIVER); // TODO: source is only necessary for internal plugins - remove later? broadcastIntent.putExtra(PluginIntent.EXTRA_SOURCE, HotspotManagerService.this.getPackageName()); broadcastIntent.putExtra(PluginIntent.KEY_BROADCAST_MESSAGE, msg); sendBroadcast(broadcastIntent); } catch (RemoteException e) { e.printStackTrace(); mClients.remove(i); // client is dead - ok to remove here as we're reversing through the list } } }
From source file:ac.robinson.bettertogether.hotspot.HotspotManagerService.java
private void sendSystemMessageToAllLocalClients(int type, String data) { for (int i = mClients.size() - 1; i >= 0; i--) { try {// w w w . java 2s. com Messenger client = mClients.get(i); Message message = Message.obtain(null, type); message.replyTo = mMessenger; if (data != null) { Bundle bundle = new Bundle(1); bundle.putString(PluginIntent.KEY_SERVICE_MESSAGE, data); message.setData(bundle); } client.send(message); } catch (RemoteException e) { e.printStackTrace(); mClients.remove(i); // client is dead - ok to remove here as we're reversing through the list } } }
From source file:ch.bfh.evoting.alljoyn.BusHandler.java
/** * Initialize AllJoyn//from w w w. j ava2 s . co m */ private void doInit() { PeerGroupListener pgListener = new PeerGroupListener() { @Override public void foundAdvertisedName(String groupName, short transport) { Intent i = new Intent("advertisedGroupChange"); LocalBroadcastManager.getInstance(context).sendBroadcast(i); } @Override public void lostAdvertisedName(String groupName, short transport) { Intent i = new Intent("advertisedGroupChange"); LocalBroadcastManager.getInstance(context).sendBroadcast(i); } @Override public void groupLost(String groupName) { if (mGroupManager.listHostedGroups().contains(groupName) && mGroupManager.getNumPeers(groupName) == 1) { //signal was send because admin stays alone in the group //not necessary to manage this case for us Log.d(TAG, "Group destroyed event ignored"); return; } Log.d(TAG, "Group " + groupName + " was destroyed."); Intent i = new Intent("groupDestroyed"); i.putExtra("groupName", groupName); LocalBroadcastManager.getInstance(context).sendBroadcast(i); } @Override public void peerAdded(String busId, String groupName, int numParticipants) { Log.d(TAG, "peer added"); if (amIAdmin) { Log.d(TAG, "Sending salt " + Base64.encodeToString(messageEncrypter.getSalt(), Base64.DEFAULT)); Message msg = obtainMessage(BusHandler.PING); Bundle data = new Bundle(); data.putString("groupName", lastJoinedNetwork); data.putString("pingString", Base64.encodeToString(messageEncrypter.getSalt(), Base64.DEFAULT)); data.putBoolean("encrypted", false); data.putSerializable("type", Type.SALT); msg.setData(data); sendMessage(msg); } //update UI LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("participantStateUpdate")); } @Override public void peerRemoved(String peerId, String groupName, int numPeers) { //update UI Log.d(TAG, "peer left"); Intent intent = new Intent("participantStateUpdate"); intent.putExtra("action", "left"); intent.putExtra("id", peerId); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); super.peerRemoved(peerId, groupName, numPeers); } }; ArrayList<BusObjectData> busObjects = new ArrayList<BusObjectData>(); Handler mainHandler = new Handler(context.getMainLooper()); Runnable myRunnable = new Runnable() { @Override public void run() { org.alljoyn.bus.alljoyn.DaemonInit.PrepareDaemon(context); } }; mainHandler.post(myRunnable); busObjects.add(new BusObjectData(mSimpleService, "/SimpleService")); mGroupManager = new PeerGroupManager(SERVICE_NAME, pgListener, busObjects); mGroupManager.registerSignalHandlers(this); }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * Initializes the SSL related UI widget properties and event handlers to deal with user * interactions.// w ww . j av a 2s . c o m */ private void initSSLState() { // Get UI Widget references... final ToggleButton sslToggleButton = (ToggleButton) findViewById(R.id.ssl_toggle); final EditText sslPortEditField = (EditText) findViewById(R.id.ssl_port); final TextView pin = (TextView) findViewById(R.id.ssl_clientcert_pin); // Configure UI to current settings state... boolean sslEnabled = AppSettingsModel.isSSLEnabled(this); sslToggleButton.setChecked(sslEnabled); sslPortEditField.setText("" + AppSettingsModel.getSSLPort(this)); // If SSL is off, disable the port edit field by default... if (!sslEnabled) { sslPortEditField.setEnabled(false); sslPortEditField.setFocusable(false); sslPortEditField.setFocusableInTouchMode(false); } // Manage state changes to SSL toggle... sslToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isEnabled) { // If SSL is being disabled, and the user had soft keyboard open, close it... if (!isEnabled) { InputMethodManager input = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); input.hideSoftInputFromWindow(sslPortEditField.getWindowToken(), 0); } // Set SSL state in config model accordingly... AppSettingsModel.enableSSL(AppSettingsActivity.this, isEnabled); // Enable/Disable SSL Port text field according to SSL toggle on/off state... sslPortEditField.setEnabled(isEnabled); sslPortEditField.setFocusable(isEnabled); sslPortEditField.setFocusableInTouchMode(isEnabled); } }); pin.setText("..."); final Handler pinHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); pin.setText(msg.getData().getString("pin")); } }; new Thread() { public void run() { String pin = ORKeyPair.getInstance().getPIN(getApplicationContext()); Bundle bundle = new Bundle(); bundle.putString("pin", pin); Message msg = pinHandler.obtainMessage(); msg.setData(bundle); msg.sendToTarget(); } }.start(); sslPortEditField.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { //TODO not very user friendly if (keyCode == KeyEvent.KEYCODE_ENTER) { String sslPortStr = ((EditText) v).getText().toString(); try { int sslPort = Integer.parseInt(sslPortStr.trim()); AppSettingsModel.setSSLPort(AppSettingsActivity.this, sslPort); } catch (NumberFormatException ex) { Toast toast = Toast.makeText(getApplicationContext(), "SSL port format is not correct.", 1); toast.show(); return false; } catch (IllegalArgumentException e) { Toast toast = Toast.makeText(getApplicationContext(), e.getMessage(), 2); toast.show(); sslPortEditField.setText("" + AppSettingsModel.getSSLPort(AppSettingsActivity.this)); return false; } } return false; } }); }
From source file:com.BeatYourRecord.SubmitActivity.java
public void asyncUpload(final Uri uri, final Handler handler) { new Thread(new Runnable() { @Override/*from w w w.j ava 2s .c o m*/ public void run() { Message msg = new Message(); Bundle bundle = new Bundle(); msg.setData(bundle); String videoId = null; int submitCount = 0; try { while (submitCount <= MAX_RETRIES && videoId == null) { try { submitCount++; videoId = startUpload(uri); //log.v("please",videoId); assert videoId != null; } catch (Internal500ResumeException e500) { // TODO - this should not really happen if (submitCount < MAX_RETRIES) { Log.w(LOG_TAG, e500.getMessage()); Log.d(LOG_TAG, String.format("Upload retry :%d.", submitCount)); } else { Log.d(LOG_TAG, "Giving up"); Log.e(LOG_TAG, e500.getMessage()); throw new IOException(e500.getMessage()); } } } } catch (IOException e) { e.printStackTrace(); bundle.putString("error", e.getMessage()); handler.sendMessage(msg); return; } catch (YouTubeAccountException e) { e.printStackTrace(); bundle.putString("error", e.getMessage()); handler.sendMessage(msg); return; } catch (SAXException e) { e.printStackTrace(); bundle.putString("error", e.getMessage()); handler.sendMessage(msg); } catch (ParserConfigurationException e) { e.printStackTrace(); bundle.putString("error", e.getMessage()); handler.sendMessage(msg); } bundle.putString("videoId", videoId); handler.sendMessage(msg); } }).start(); }
From source file:ro.ciubex.keepscreenlock.MainApplication.java
/** * Send a message to service.//from w ww . j a va2s. c o m */ public void sendToKeepScreenLockService(String messageKey, String messageValue) { if (mBound) { Message msg = Message.obtain(); Bundle bundle = new Bundle(); bundle.putString(messageKey, messageValue); msg.setData(bundle); try { mService.send(msg); } catch (RemoteException e) { logE(TAG, "sendMessageToService(" + messageKey + "," + messageValue + "): " + e.getMessage(), e); } } }
From source file:com.app.jdy.ui.CashAdvanceActivity.java
public void getData() { new Thread(new Runnable() { @Override// www . j ava2s . co m public void run() { SharedPreferences userPreferences = getSharedPreferences("umeng_general_config", Context.MODE_PRIVATE); memberId = userPreferences.getString("ID", "").trim(); canWithdCash = HttpUtils.request(null, URLs.CanWithdCash_URL + "/" + memberId); String bankCard = HttpUtils.request(null, URLs.BANKCARD_URL + "/" + memberId); Message msg = new Message(); msg.what = 1; Bundle bundle = new Bundle(); try { JSONObject jsonObject = new JSONObject(bankCard); String tmpJson = jsonObject.getString("data"); JSONArray jsonArray = new JSONArray(tmpJson); for (int i = 0; i < jsonArray.length(); i++) { JSONObject tmpObj = (JSONObject) jsonArray.get(i); String bankName = tmpObj.getString("bankName"); String bankCode = tmpObj.getString("bankCode"); String bankCode1 = tmpObj.getString("bankCode1"); bundle.putString("bankName", bankName); bundle.putString("bankCode", bankCode); bundle.putString("bankCode1", bankCode1); } } catch (JSONException e) { e.printStackTrace(); } bundle.putString("canWithdCash", canWithdCash); msg.setData(bundle); handler.sendMessage(msg); } }).start(); }
From source file:com.zoffcc.applications.zanavi.ZANaviMainIntroActivityStatic.java
protected void onActivityResult(int requestCode, int resultCode, Intent data) { System.out.println("ZANaviMainIntroActivity:" + "onActivityResult"); switch (requestCode) { case Navit.NavitDeleteSecSelectMap_id: try {//from w w w . j a v a2s . co m if (resultCode == AppCompatActivity.RESULT_OK) { System.out.println("Global_Location_update_not_allowed = 1"); Navit.Global_Location_update_not_allowed = 1; // dont allow location updates now! // remove all sdcard maps Message msg = new Message(); Bundle b = new Bundle(); b.putInt("Callback", 19); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); try { Thread.sleep(100); } catch (InterruptedException e) { } Log.d("Navit", "delete map id=" + Integer.parseInt(data.getStringExtra("selected_id"))); String map_full_line = NavitMapDownloader.OSM_MAP_NAME_ondisk_ORIG_LIST[Integer .parseInt(data.getStringExtra("selected_id"))]; Log.d("Navit", "delete map full line=" + map_full_line); String del_map_name = Navit.MAP_FILENAME_PATH + map_full_line.split(":", 2)[0]; System.out.println("del map file :" + del_map_name); // remove from cat file NavitMapDownloader.remove_from_cat_file(map_full_line); // remove from disk File del_map_name_file = new File(del_map_name); del_map_name_file.delete(); for (int jkl = 1; jkl < 51; jkl++) { File del_map_name_fileSplit = new File(del_map_name + "." + String.valueOf(jkl)); del_map_name_fileSplit.delete(); } // also remove index file File del_map_name_file_idx = new File(del_map_name + ".idx"); del_map_name_file_idx.delete(); // remove also any MD5 files for this map that may be on disk try { String tmp = map_full_line.split(":", 2)[1]; if (!tmp.equals(NavitMapDownloader.MAP_URL_NAME_UNKNOWN)) { tmp = tmp.replace("*", ""); tmp = tmp.replace("/", ""); tmp = tmp.replace("\\", ""); tmp = tmp.replace(" ", ""); tmp = tmp.replace(">", ""); tmp = tmp.replace("<", ""); System.out.println("removing md5 file:" + Navit.MAPMD5_FILENAME_PATH + tmp + ".md5"); File md5_final_filename = new File(Navit.MAPMD5_FILENAME_PATH + tmp + ".md5"); md5_final_filename.delete(); } } catch (Exception e) { e.printStackTrace(); } try { Thread.sleep(100); } catch (InterruptedException e) { } // add all sdcard maps msg = new Message(); b = new Bundle(); b.putInt("Callback", 20); msg.setData(b); NavitGraphics.callback_handler.sendMessage(msg); System.out.println("Global_Location_update_not_allowed = 0"); Navit.Global_Location_update_not_allowed = 0; // DO allow location updates now! // ----------------- Navit.intro_flag_indexmissing = false; try { // go to next slide btnNext.callOnClick(); // ----------------- } catch (java.lang.NoSuchMethodError e2) { System.out.println("ZANaviMainIntroActivity:" + "callOnClick:Ex01"); } } } catch (Exception e) { Log.d("Navit", "error on onActivityResult 3"); e.printStackTrace(); } break; } }
From source file:com.trailbehind.android.iburn.map.MapActivity.java
/** * Move map./* ww w . j a va 2s . com*/ * * @param point * the point */ private void moveMap(WgsPoint point) { final double lat1 = point.getLat(); final double lon1 = point.getLon(); final WgsPoint middlePoint = mMapComponent.getMiddlePoint(); final double lat0 = middlePoint.getLat(); final double lon0 = middlePoint.getLon(); final double latDiff = (lat1 - lat0) / 20; final double lonDiff = (lon1 - lon0) / 20; for (int i = 1; i < 21; i++) { final Bundle bundle = new Bundle(); if (i != 20) { bundle.putDouble(KEY_LAT, (lat0 + (latDiff * i))); bundle.putDouble(KEY_LON, (lon0 + (lonDiff * i))); } else { bundle.putDouble(KEY_LAT, lat1); bundle.putDouble(KEY_LON, lon1); } final Message msg = mActivityHandler.obtainMessage(ActivityHandler.MESSAGE_MOVE_MAP); msg.setData(bundle); mActivityHandler.sendMessageDelayed(msg, i * 30); } }