List of usage examples for android.os Message obtain
public static Message obtain()
From source file:com.jwork.spycamera.CameraTaskService.java
private void startAutoShot() { running = true;// w w w . jav a2 s .co m Message backMsg = Message.obtain(); backMsg.what = MainController.WHAT_START_AUTOSHOOT; try { outMessenger.send(backMsg); } catch (android.os.RemoteException e1) { log.w(this, e1); } CameraTaskService.setState(WHAT_START_AUTOSHOT); if (task != null) { task.cancel(true); } }
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void uploadavatar(final String img, final int KEY) { new Thread() { Message msg = Message.obtain(); public void run() { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("upfile", img)); String result = NetBaseUtils.getResponseForImg(WebAddress.UPLOADAVATAR, params, mContext); Log.e("?", img); // Log.e("result= ",result); msg.what = KEY;/*from w w w. j av a 2 s. c o m*/ msg.obj = result; handler.sendMessage(msg); } }.start(); }
From source file:com.adjust.sdk.ActivityHandler.java
@Override public void readOpenUrl(Uri url, long clickTime) { Message message = Message.obtain(); message.arg1 = SessionHandler.DEEP_LINK; UrlClickTime urlClickTime = new UrlClickTime(url, clickTime); message.obj = urlClickTime;/*w w w. j av a2 s .co m*/ sessionHandler.sendMessage(message); }
From source file:com.experiment.chickenjohn.materialdemo.MainActivity.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); int currentOrientation = this.getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_PORTRAIT) { portLoading();/* w w w .j av a 2s . c o m*/ Message uiRefreshMessage = Message.obtain(); uiRefreshMessage.what = 0; uiRefreshHandler.sendMessage(uiRefreshMessage); } else if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { landLoading(); } drawSurfaceView.resetSurfaceViewX(); }
From source file:com.jwork.dhammapada.VerseFragment.java
private void back() { Message message = Message.obtain(); message.what = Constant.WHAT_GOTO_BACK; message.obj = this; controller.executeMessage(message); }
From source file:com.android.providers.downloads.OmaDownload.java
/** * This method notifies the server for the status of the download operation. * It sends a status report to a Web server if installNotify attribute is specified in the download descriptor. @param component the component that contains attributes in the descriptor. @param handler the handler used to send and process messages. A message indicates whether the media object is available to the user or not (READY or DISCARD). *//*from w w w .j a va 2 s.c om*/ //protected static void installNotify (OmaDescription component, Handler handler) { protected static int installNotify(OmaDescription component, Handler handler) { int ack = -1; int release = OmaStatusHandler.DISCARD; URL url = component.getInstallNotifyUrl(); if (url != null) { DefaultHttpClient client = new DefaultHttpClient(); HttpPost postRequest = new HttpPost(url.toString()); try { HttpParams params = postRequest.getParams(); HttpProtocolParams.setUseExpectContinue(params, false); postRequest.setEntity( new StringEntity(OmaStatusHandler.statusCodeToString(component.getStatusCode()) + "\n\r")); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler() { @Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { // TODO Auto-generated method stub Log.i("@M_" + Constants.LOG_OMA_DL, "Retry the request..."); return (executionCount <= OmaStatusHandler.MAXIMUM_RETRY); } }); try { HttpResponse response = client.execute(postRequest); if (response.getStatusLine() != null) { ack = response.getStatusLine().getStatusCode(); //200-series response code if (ack == HttpStatus.SC_OK || ack == HttpStatus.SC_ACCEPTED || ack == HttpStatus.SC_CREATED || ack == HttpStatus.SC_MULTI_STATUS || ack == HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION || ack == HttpStatus.SC_NO_CONTENT || ack == HttpStatus.SC_PARTIAL_CONTENT || ack == HttpStatus.SC_RESET_CONTENT) { if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } final HttpEntity entity = response.getEntity(); if (entity != null) { InputStream inputStream = null; try { inputStream = entity.getContent(); if (inputStream != null) { BufferedReader br = new BufferedReader(new InputStreamReader(inputStream)); String s; while ((s = br.readLine()) != null) { Log.v("@M_" + Constants.LOG_OMA_DL, "Response: " + s); } } } finally { if (inputStream != null) { inputStream.close(); } entity.consumeContent(); } } } } catch (ConnectTimeoutException e) { Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); postRequest.abort(); //After time out period, the client releases the media object for use. if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } catch (NoHttpResponseException e) { Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); postRequest.abort(); //After time out period, the client releases the media object for use. if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } catch (IOException e) { Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); postRequest.abort(); } if (client != null) { client.getConnectionManager().shutdown(); } } else { if (component.getStatusCode() == OmaStatusHandler.SUCCESS) { release = OmaStatusHandler.READY; } } if (handler != null) { Message mg = Message.obtain(); mg.arg1 = release; handler.sendMessage(mg); } return release; }
From source file:org.ymkm.lib.controller.support.ControlledDialogFragment.java
@Override public void onPause() { super.onPause(); if (null != mControllerMessenger) { Message m = Message.obtain(); m.what = FragmentController.MSG_DETACH_MESSAGE; m.arg1 = getControlId();//from w w w . j a v a 2s . c om m.obj = this; Bundle b = new Bundle(); b.putString("controllableName", mControllableName); m.setData(b); try { mControllerMessenger.send(m); } catch (RemoteException e) { e.printStackTrace(); } } mControllerMessenger = null; }
From source file:com.layer8apps.CalendarHandler.java
/************ * PURPOSE: Handles the primary thread in the service * ARGUMENTS: Intent intent/*from ww w.jav a2s . co m*/ * RETURNS: VOID * AUTHOR: Devin Collins <agent14709@gmail.com> *************/ @Override protected void onHandleIntent(Intent intent) { // Get our stored data from the intent username = intent.getStringExtra("username"); password = intent.getStringExtra("password"); messenger = (Messenger) intent.getExtras().get("handler"); calID = intent.getIntExtra("calendarID", -1); String url = getApplicationContext().getResources().getString(R.string.url); // Create variables to be used through the application List<String[]> workDays = null; ConnectionManager conn = ConnectionManager.newConnection(); /************ * Once we verify that we have a valid token, we get the actual schedule *************/ updateStatus("Logging in..."); String tempToken = conn.getData(url + "/etm/login.jsp"); if (tempToken != null) { loginToken = parseToken(tempToken); } else { showError("Error connecting to MyTLC, make sure you have a valid network connection"); return; } String postResults = null; // This creates our login information List<NameValuePair> parameters = createParams(); if (loginToken != null) { // Here we send the information to the server and login postResults = conn.postData(url + "/etm/login.jsp", parameters); } else { showError("Error retrieving your login token"); return; } if (postResults != null && postResults.toLowerCase().contains("etmmenu.jsp") && !postResults.toLowerCase().contains("<font size=\"2\">")) { updateStatus("Retrieving schedule..."); postResults = conn.getData(url + "/etm/time/timesheet/etmTnsMonth.jsp"); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error logging in, please verify your username and password"); } return; } // If we successfully got the information, then parse out the schedule to read it properly String secToken = null; if (postResults != null) { updateStatus("Parsing schedule..."); workDays = parseSchedule(postResults); secToken = parseSecureToken(postResults); wbat = parseWbat(postResults); } else { showError("Could not obtain user schedule"); return; } if (secToken != null) { parameters = createSecondParams(secToken); postResults = conn.postData(url + "/etm/time/timesheet/etmTnsMonth.jsp", parameters); } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("Error retrieving your security token"); } return; } List<String[]> secondMonth = null; if (postResults != null) { secondMonth = parseSchedule(postResults); } else { showError("Could not obtain user schedule"); return; } if (secondMonth != null) { if (workDays == null) { workDays = secondMonth; } else { workDays.addAll(secondMonth); } finalDays = workDays; } else { String error = parseError(postResults); if (error != null) { showError(error); } else { showError("There was an error retrieving your schedule"); } return; } // Add our shifts to the calendar updateStatus("Adding shifts to calendar..."); int numShifts = addDays(); if (finalDays != null && numShifts > -1) { // Report back that we're successful! Message msg = Message.obtain(); Bundle b = new Bundle(); b.putString("status", "DONE"); b.putInt("count", numShifts); msg.setData(b); try { messenger.send(msg); } catch (Exception e) { // Nothing } } else { showError("Couldn't add your shifts to your calendar"); } }
From source file:de.qspool.clementineremote.ui.Player.java
/** * Request a disconnect from clementine/* w w w . ja v a 2 s .co m*/ */ void requestDisconnect() { // Create a new request RequestDisconnect r = new RequestDisconnect(); // Move the request to the message Message msg = Message.obtain(); msg.obj = r; // Send the request to the thread App.mClementineConnection.mHandler.sendMessage(msg); }
From source file:com.jwork.dhammapada.VerseFragment.java
private void shareVerse() { if (currentContentFragment == null) { currentContentFragment = mPagerAdapter.getRegisteredFragment(0); }//from www. j a va 2 s . c o m Message message = Message.obtain(); message.what = Constant.WHAT_SHARE_VERSE; message.obj = currentContentFragment.getVerseCurrent(); controller.executeMessage(message); }