List of usage examples for android.os Message setData
public void setData(Bundle data)
From source file:org.thialfihar.android.apg.ui.dialog.DeleteKeyDialogFragment.java
/** * Send message back to handler which is initialized in a activity * * @param what Message integer you want to send */// w w w .j av a2 s. c om private void sendMessageToHandler(Integer what, Bundle data) { Message msg = Message.obtain(); msg.what = what; if (data != null) { msg.setData(data); } try { mMessenger.send(msg); } catch (RemoteException e) { Log.w(Constants.TAG, "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w(Constants.TAG, "Messenger is null!", e); } }
From source file:com.nextgis.firereporter.HttpGetter.java
@Override protected Void doInBackground(String... urls) { if (IsNetworkAvailible(mContext)) { try {//from w ww.j ava 2s . com String sURL = urls[0]; httpget = new HttpGet(sURL); Log.d("MainActivity", "HTTPGet URL " + sURL); if (urls.length > 1) { httpget.setHeader("Cookie", urls[1]); } //TODO: move timeouts to parameters HttpParams httpParameters = new BasicHttpParams(); int timeoutConnection = 1500; HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. int timeoutSocket = 3000; HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); HttpClient Client = new DefaultHttpClient(httpParameters); HttpResponse response = Client.execute(httpget); //ResponseHandler<String> responseHandler = new BasicResponseHandler(); //mContent = Client.execute(httpget, responseHandler); HttpEntity entity = response.getEntity(); Bundle bundle = new Bundle(); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { bundle.putBoolean(GetFiresService.ERROR, false); mContent = EntityUtils.toString(entity); bundle.putString(GetFiresService.JSON, mContent); } else { bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase()); } bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } catch (ClientProtocolException e) { mError = e.getMessage(); cancel(true); } catch (IOException e) { mError = e.getMessage(); cancel(true); } } else { Bundle bundle = new Bundle(); bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, mContext.getString(R.string.noNetwork)); bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } return null; }
From source file:com.softminds.matrixcalculator.OperationFragments.DeterminantFragment.java
public void RunToGetDeterminant(final int pos, final ProgressDialog px) { Runnable runnable = new Runnable() { @Override// ww w . j a v a 2 s . com public void run() { double var = SquareList.get(pos).getDeterminant(px); Message message = new Message(); Bundle bundle = new Bundle(); bundle.putDouble("RESULTANT", var); message.setData(bundle); px.dismiss(); myhandler.sendMessage(message); } }; Thread thread = new Thread(runnable); thread.start(); }
From source file:com.jerrellmardis.amphitheatre.task.DownloadTaskHelper.java
public static void traverseSmbFiles(SmbFile root, NtlmPasswordAuthentication auth) throws SmbException, MalformedURLException { int fileCount = 0; boolean video_folder = false; final Video v = new Video(); Handler h = new Handler(Looper.getMainLooper()) { @Override//from w w w . java2 s. c om public void handleMessage(Message msg) { // super.handleMessage(msg); Video vid = (Video) msg.getData().getSerializable("VIDEO"); Log.d(TAG, "Handle " + msg.getData().getInt("WHEN") + " " + vid.getName()); updateSingleVideo(vid, null); } }; for (SmbFile f : root.listFiles()) { if (f.getParent().contains("Entertainment Media")) { // Log.d(TAG, "Discovered "+f.getPath()+" "+f.isDirectory()); } if (f.isDirectory()) { try { //TODO Port VOB folder support to USB and internal storage SmbFile[] directoryContents = f.listFiles(); // Log.d(TAG, "Going into directory "+f.getPath()); //If this works, then we can explore //Let's do some quick name checking to for time savings if (f.getName().contains("Entertainment Media")) { // Log.d(TAG, Arrays.asList(f.listFiles()).toString()); } if (!f.getName().contains("iTunes") && !f.getName().contains("Digi Pix") && !f.getName().contains("AppData") && !f.getName().startsWith(".") && !f.getName().contains("Avid") && !f.getName().contains("Spotify") && !f.getName().contains("audacity_temp") && !f.getName().contains("Media_previews") && !f.getName().contains("GFX_previews") && !f.getName().contains("Samsung Install Files") && !f.getName().contains("AE Renders") && !f.getName().contains("LocalData") && !f.getName().contains("$RECYCLE") && !f.getName().contains("Encore DVD") && !f.getName().contains("16 GB Photo card") && !f.getName().contains("Ignore") && !f.getName().contains("Documents") //TEMP && !f.getName().contains("Downloads") //TEMP && !f.getName().contains("TypeGEMs") //TEMP && !f.getName().contains("KofC7032Web") //TEMP && !f.getName().contains("hype mobile docs") //TEMP && !f.getName().contains("Thrive Music Video") //TEMP /*&& f.getPath().contains("Entertainment") //TEMP*/ && !f.getName().contains("Preview Files")) { Log.d(TAG, "Check " + f.getPath()); traverseSmbFiles(f, auth); } else { // Log.d(TAG, "Don't check " + f.getPath()); } } catch (Exception e) { //This folder isn't accessible Log.d(TAG, "Inaccessible: " + f.getName() + " " + e.getMessage()); //This will save us time in the traversal } } else/* if(f.getPath().contains("Films"))*/ { //TEMP //Is this something we want to add? // Log.d(TAG, "Non-directory "+f.getPath()); if (VideoUtils.isVideoFile(f.getPath())) { Log.d(TAG, f.getName() + " is a video"); //Perhaps. Let's do some checking. /* VOB check If the files are in a structure like: { Movie Name } -> VIDEO_TS -> VTS_nn_n.vob Then use the movie name as the source, and each vob url will be added in a comma-separated list to the video url string */ if (f.getPath().contains("VIDEO_TS")) { Log.d(TAG, "Special case for " + f.getPath()); //We have a special case! String grandparentPath = f.getPath().substring(0, f.getPath().indexOf("VIDEO_TS")); SmbFile grandparent = new SmbFile(grandparentPath, auth); //Let's delete this video and all like it from our video database //TODO Makes more sense to not delete and replace a video, just to update in place // Log.d(TAG, "Purge where video_url like "+"%" + grandparent.getPath().replace("'", "\'") + "%"); List<Video> videos = Select.from(Video.class).where(Condition.prop("video_url") .like("%" + grandparent.getPath().replace("'", "\'") + "%")).list(); // Log.d(TAG, "Purging "+videos.size()+" item(s)"); for (Video vx : videos) { // Log.d(TAG, "Deleting "+vx.getVideoUrl()); vx.delete(); } v.setName(grandparent.getName().replace("/", "").replace("_", " ") + ".avi"); //FIXME VOB currently not supported v.setSource(FileSource.SMB); v.setIsMatched(true); //Kind of a lie, but we know it's a thing! //Get all the video files ArrayList<String> urls = new ArrayList<>(); for (SmbFile f2 : grandparent.listFiles()) { for (SmbFile f3 : f2.listFiles()) { if (VideoUtils.isVideoFile(f3.getPath())) { //Presumably in order urls.add(f3.getPath()); } } } // Log.d(TAG, urls.toString()); //This works well v.setVideoUrl(urls); video_folder = true; } else { //Add the video like normal //Let's delete this video and all like it from our video database List<Video> videos = Select.from(Video.class) .where(Condition.prop("video_url").like("%" + f.getPath().replace("'", "''") + "%")) .list(); // Log.d(TAG, "Purging "+videos.size()+" item(s)"); for (Video vx : videos) { // Log.d(TAG, "Deleting "+vx.getVideoUrl()); vx.delete(); } v.setName(f.getName()); v.setSource(FileSource.SMB); v.setVideoUrl(f.getPath()); fileCount++; //Send a request to update metadata every second, to prevent as many 429 errors and memory exceptions Message m = new Message(); Bundle mBundle = new Bundle(); mBundle.putSerializable("VIDEO", v.clone()); mBundle.putInt("WHEN", (int) (1000 * fileCount + Math.round(Math.random() * 100))); m.setData(mBundle); // h.sendEmptyMessageDelayed(1000 * fileCount, 1000 * fileCount); h.sendMessageDelayed(m, 1000 * fileCount); Log.d(TAG, "Queued " + mBundle.getInt("WHEN") + " - " + v.getName()); v.save(); //Need to save here, otherwise purging won't work as expected } // Log.d(TAG, v.toString()); // return; } //Ignore otherwise } } //Let's do VOB video if (video_folder) { // Log.d(TAG, "Done rooting through "+root.getPath()); Log.d(TAG, "Created info for VOB " + v.toString()); fileCount++; //Send a request to update metadata every second, to prevent as many 429 errors and memory exceptions Message m = new Message(); Bundle mBundle = new Bundle(); mBundle.putSerializable("VIDEO", v.clone()); m.setData(mBundle); // h.sendEmptyMessageDelayed(1000 * fileCount, 1000 * fileCount); h.sendMessageDelayed(m, 1000 * fileCount); Log.d(TAG, "Queued " + 1000 * fileCount + " - " + v.getName()); v.save(); //Need to save here, otherwise purging won't work as expected } }
From source file:ibp.plugin.nsd.NSDHelper.java
public void sendNotification(String type, String msg) { Bundle messageBundle = new Bundle(); messageBundle.putString("type", type); messageBundle.putString("msg", msg); Message message = new Message(); message.setData(messageBundle); mHandler.sendMessage(message);//www . ja v a 2s . c o m }
From source file:com.kevelbreh.steamchat.activity.AuthenticationActivity.java
/** * Authenticate the user. Perform actions depending on the required form state and result code * of the Steam API.// ww w .j a v a 2 s. com */ @OnClick(R.id.authenticate) public void authenticate() { if (isValid()) try { Bundle data = new Bundle(); data.putString("username", getUsername()); data.putString("password", getPassword()); data.putString("guard", getGuard()); data.putString("machine", getMachine()); Message message = Message.obtain(null, SteamService.EVENT_STEAM_USER_LOGIN); message.setData(data); mService.send(message); } catch (RemoteException e) { SteamChat.debug(this, e.getMessage(), e); } }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.webview.GBWebClient.java
private WebResourceResponse mimicReply(Uri requestedUri) { if (requestedUri.getHost() != null && (org.apache.commons.lang3.StringUtils .indexOfAny(requestedUri.getHost(), AllowedDomains) != -1)) { if (internetHelperBound) { LOG.debug("WEBVIEW forwarding request to the internet helper"); Bundle bundle = new Bundle(); bundle.putString("URL", requestedUri.toString()); Message webRequest = Message.obtain(); webRequest.replyTo = internetHelperListener; webRequest.setData(bundle); try { latch = new CountDownLatch(1); //the messenger should run on a single thread, hence we don't need to be worried about concurrency. This approach however is certainly not ideal. internetHelper.send(webRequest); latch.await();/* w w w .ja v a 2s.com*/ return internetResponse; } catch (RemoteException | InterruptedException e) { LOG.warn("Error downloading data from " + requestedUri, e); } } else { LOG.debug("WEBVIEW request to openweathermap.org detected of type: " + requestedUri.getPath() + " params: " + requestedUri.getQuery()); return mimicOpenWeatherMapResponse(requestedUri.getPath(), requestedUri.getQueryParameter("units")); } } else { LOG.debug("WEBVIEW request:" + requestedUri.toString() + " not intercepted"); } return null; }
From source file:andlabs.lounge.service.LoungeServiceImpl.java
public void setMessageHandler(MessageHandler pMessageHandler) { mMessageHandler = pMessageHandler;/*from www.j av a 2 s . c o m*/ Message message = Message.obtain(); message.what = 42; message.setData(Bundle.EMPTY); mMessageHandler.send(message); }
From source file:org.zywx.wbpalmstar.plugin.inputtextfieldview.EUExInputTextFieldView.java
private void sendMessageWithType(int msgType, String[] params) { if (mHandler == null) { return;/* w w w. ja va 2 s.c o m*/ } Message msg = new Message(); msg.what = msgType; msg.obj = this; Bundle b = new Bundle(); b.putStringArray(INPUTTEXTFIELDVIEW_FUN_PARAMS_KEY, params); msg.setData(b); mHandler.sendMessage(msg); }
From source file:andlabs.lounge.service.LoungeServiceImpl.java
@Override public void reconnect() { Ln.v("reconnect():"); try {//from w w w. java 2 s .com Message message = Message.obtain(); message.what = 1; message.setData(Bundle.EMPTY); mMessageHandler.send(message); } catch (NullPointerException npe) { Ln.e(npe, "reconnect(): caught exception while sending message"); } }