List of usage examples for android.os Message Message
public Message()
From source file:com.oneguy.recognize.engine.GoogleStreamingEngine.java
byte[] getHttpData(String url) { String TAG = "getHttpData"; HttpGet httpGet = new HttpGet(url); byte[] result = null; try {//from ww w. j a va 2 s.c o m HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT); client.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT); Log.d(TAG, "HTTP GET:" + httpGet.getURI() + " method:" + httpGet.getMethod()); HttpResponse httpResponse = client.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() == 200) { result = EntityUtils.toByteArray(httpResponse.getEntity()); Log.d(TAG, new String(result)); StreamResponse response = new StreamResponse(null, Status.SUCCESS); response.setResponse(result); response.setResponseCode(httpResponse.getStatusLine().getStatusCode()); Message msg = new Message(); msg.what = EVENT_RESPONSE; msg.obj = response; mHandler.sendMessage(msg); } } catch (ClientProtocolException e) { onError(e); e.printStackTrace(); } catch (IOException e) { onError(e); e.printStackTrace(); } return result; }
From source file:com.cssweb.android.base.BaseActivity.java
private void downloadImage() { // ???//from w ww . ja v a 2 s . c o m if (!downloadingFlag) { downloadingFlag = true; mHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 1: setAdapter(localListView, true); break; default: break; } }; }; if (images == null) { initMenu(); } new Thread(new Runnable() { public void run() { try { boolean flag = NetUtils.download(BaseActivity.this, images); if (flag) { Message msg = new Message(); msg.what = 1; mHandler.sendMessage(msg); } } catch (Exception e) { } } }).start(); } }
From source file:com.photon.phresco.nativeapp.eshop.activity.PhrescoActivity.java
/** * Call the error dialog handler method to open the normal error dialog box * with OK button// w w w.j a va 2 s .com */ public void showNormalErrorDialog() { try { PhrescoLogger.info(TAG + " processOnComplete - readAppConfigJSON - showErrorDialogHandler :"); Message msg = new Message(); Bundle errorMessageBundle = new Bundle(); errorMessageBundle.putString(errMessage, getString(R.string.http_connect_error_message)); msg.setData(errorMessageBundle); msg.what = ERROR_DIALOG_FLAG; showErrorDialogHandler.sendMessage(msg); } catch (Exception ex) { PhrescoLogger.info(TAG + " - showNormalErrorDialog - Exception : " + ex.toString()); PhrescoLogger.warning(ex); } }
From source file:com.cettco.buycar.activity.BargainActivity.java
private void submit() { String cookieStr = null;/* w ww . j a v a 2 s . c o m*/ String cookieName = null; PersistentCookieStore myCookieStore = new PersistentCookieStore(BargainActivity.this); if (myCookieStore == null) { return; } List<Cookie> cookies = myCookieStore.getCookies(); for (Cookie cookie : cookies) { String name = cookie.getName(); cookieName = name; //System.out.println(name); if (name.equals("_JustBidIt_session")) { cookieStr = cookie.getValue(); //System.out.println("value:" + cookieStr); break; } } if (cookieStr == null || cookieStr.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "", Toast.LENGTH_SHORT); toast.show(); Intent intent = new Intent(); intent.setClass(BargainActivity.this, SignInActivity.class); startActivity(intent); return; } String tenderUrl = GlobalData.getBaseUrl() + "/tenders.json?"; // String price = priceEditText.getText().toString(); // String userName = userNameEditText.getText().toString(); String price = orderItemEntity.getPrice(); String userName = orderItemEntity.getName(); if (price == null || price.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "", Toast.LENGTH_SHORT); toast.show(); return; } if (colors == null || colors.size() == 0) { Toast toast = Toast.makeText(BargainActivity.this, "?", Toast.LENGTH_SHORT); toast.show(); return; } if (dealers == null || dealers.size() == 0) { Toast toast = Toast.makeText(BargainActivity.this, "4s", Toast.LENGTH_SHORT); toast.show(); return; } if (userName == null || userName.equals("")) { Toast toast = Toast.makeText(BargainActivity.this, "??", Toast.LENGTH_SHORT); toast.show(); return; } Tender tender = new Tender(); StringBuffer buffer = new StringBuffer(); for (int i = 0; i < colors.size(); i++) { buffer.append(colors.get(i) + ","); } if (buffer != null && buffer.length() > 0) { buffer.deleteCharAt(buffer.length() - 1); } tender.setColors_id(buffer.toString()); tender.setGot_licence(String.valueOf(plateSelection)); tender.setLoan_option(String.valueOf(loanSelection + 1)); tender.setTrim_id(trim_id); tender.setPickup_time(String.valueOf(getcarTimeSelection)); tender.setUser_name(userName); String locationString = locationList.get(locationSelection); tender.setLicense_location(locationString); tender.setPrice(price); String description = descriptionEditText.getText().toString(); // tender.setde tender.setDescription(description); Map<String, String> shops = new HashMap<String, String>(); for (int i = 0; i < dealers.size(); i++) { shops.put(dealers.get(i), "1"); } tender.setShops(shops); TenderEntity tenderEntity = new TenderEntity(); tenderEntity.setTender(tender); Gson gson = new Gson(); //System.out.println(gson.toJson(tenderEntity).toString()); StringEntity entity = null; try { // System.out.println(gson.toJson(bargainEntity).toString()); entity = new StringEntity(gson.toJson(tenderEntity).toString(), "utf-8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } progressLayout.setVisibility(View.VISIBLE); HttpConnection.getClient().addHeader("Cookie", cookieName + "=" + cookieStr); HttpConnection.post(BargainActivity.this, tenderUrl, null, entity, "application/json;charset=utf-8", new JsonHttpResponseHandler() { @Override public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) { // TODO Auto-generated method stub super.onFailure(statusCode, headers, throwable, errorResponse); progressLayout.setVisibility(View.GONE); //System.out.println("error"); //System.out.println("statusCode:" + statusCode); //System.out.println("headers:" + headers); if (statusCode == 401) { Message msg = new Message(); msg.what = RESULT_UNAUTHORIZED; handler.sendMessage(msg); } else if (statusCode == 422) { Message msg = new Message(); msg.what = RESULT_UNPROCESSABLE; handler.sendMessage(msg); } else { Toast toast = Toast.makeText(BargainActivity.this, "??,???", Toast.LENGTH_SHORT); toast.show(); } } @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { // TODO Auto-generated method stub super.onSuccess(statusCode, headers, response); progressLayout.setVisibility(View.GONE); //System.out.println("success"); //System.out.println("statusCode:" + statusCode); // for(int i=0;i<headers.length;i++){ // System.out.println(headers[0]); // } //System.out.println("response:" + response); String tender_id = ""; if (statusCode == 201) { try { //System.out.println("id:" //+ response.getString("id")); tender_id = response.getString("id"); orderItemEntity.setId(response.getString("id")); orderItemEntity.setState(response.getString("state")); DatabaseHelperOrder orderHelper = DatabaseHelperOrder .getHelper(BargainActivity.this); orderHelper.getDao().update(orderItemEntity); } catch (JSONException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast toast = Toast.makeText(BargainActivity.this, "???", Toast.LENGTH_SHORT); toast.show(); Intent intent = new Intent(); // intent.putExtra("tenderId", id); intent.setClass(BargainActivity.this, AliPayActivity.class); intent.putExtra("tender_id", tender_id); startActivity(intent); // Intent intent = new Intent(); // // intent.putExtra("tenderId", id); // intent.setClass(BargainActivity.this, // MainActivity.class); // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // startActivity(intent); } } }); }
From source file:com.example.sleepintrain.CheckDistance.java
public void listenGps() { //gpsService.setVibrateSignalTrue(); new Thread(new Runnable() { @Override/*w w w . ja va2s.c om*/ public void run() { while (!mDestinationReached && mUpdatesRequested) { try { /* Log.i(TAG, "thread running"); Log.i(TAG, "CheckDistancelatitude 1 ::" + gpsService.getLatitude()); double latitude = gpsService.getLatitude(); Log.i(TAG, "CheckDistancelatitude ::" + latitude); double longitude = gpsService.getLongitude(); currentLocation.setLatitude(latitude); Log.i(TAG, "CheckDistancelatitude 3 ::" + currentLocation.getLatitude()); */ /* currentLocation.setLongitude(gpsService.getLongitude()); double distance = destination.distanceTo(currentLocation); String distanceString = Double.toString(distance); Log.i(TAG, "CheckDistancelatitude ::" + gpsService.getLatitude()); Log.i(TAG, "distance ::" + distanceString); */ //Log.i("info", gpsService); if (gpsService != null) { Message msg = new Message(); msg.obj = gpsService.getDistance(); handler.sendMessage(msg); } } catch (Exception e) { } try { //if(gpsService != null) { Thread.sleep(1000); //} else { //Thread.sleep(5000); //} } catch (InterruptedException e) { } } } }).start(); }
From source file:org.openbmap.activities.HostActivity.java
/** * Starts broadcasting GPS position./*from w ww .j a va 2 s .c o m*/ * @param provider * @return false on error, otherwise true */ public final boolean requestPositionUpdates(final State provider) { // TODO check whether services have already been connected (i.e. received MSG_SERVICE_READY signal) Log.d(TAG, "Requesting position updates"); try { if (mPositionServiceManager == null) { Log.w(TAG, "gpsPositionServiceManager is null. No message will be sent"); return false; } final int session = mDataHelper.getActiveSessionId(); if (session == RadioBeacon.SESSION_NOT_TRACKING) { Log.e(TAG, "Couldn't start tracking, no active session"); return false; } final Bundle aProviderBundle = new Bundle(); aProviderBundle.putString("provider", provider.toString()); final Message msgGpsUp = new Message(); msgGpsUp.what = RadioBeacon.MSG_START_TRACKING; msgGpsUp.setData(aProviderBundle); mPositionServiceManager.sendAsync(msgGpsUp); // update recording indicator //((StatusBar) findViewById(R.id.gpsStatus)).manageRecordingIndicator(true); updateUI(); mSelectedProvider = provider; return true; } catch (final RemoteException e) { // service communication failed e.printStackTrace(); return false; } catch (final NumberFormatException e) { e.printStackTrace(); return false; } catch (final Exception e) { e.printStackTrace(); return false; } }
From source file:com.zzisoo.toylibrary.fragment.ToyListViewFragment.java
public void dataLoad(String strData) { Gson gson = new Gson(); Toy[] arrToy = gson.fromJson(strData, Toy[].class); Message msg = new Message(); msg.arg1 = MSG_OBJ;//from w w w . j a v a 2 s .c o m msg.obj = arrToy; mActivityHandler.dispatchMessage(msg); }
From source file:com.mk4droid.IMC_Activities.Fragment_NewIssueB.java
/** * OnMarker drag end set Position/* w w w . j a va 2 s .c o m*/ */ @Override public void onMarkerDragEnd(Marker arg0) { progressLoc = ProgressDialog.show(ctx, "", "", true); progressLoc.setContentView(R.layout.dialog_transparent_progress); ((TextView) progressLoc.findViewById(R.id.tv_prog)).setText(""); Message msg = new Message(); msg.arg1 = 1; handlerAddresUPD.sendMessage(msg); }
From source file:net.evecom.android.log.DailyLogLookActivity.java
/** * //from w ww . j av a2s. c o m */ private void formSubmit() { new Thread(new Runnable() { @Override public void run() { try { Message msg_listData = new Message(); String a = HttpUtil.BASE_URL + "teventAndroid/updateIndfoDailyLogAndroid"; String b = "sysid=" + sysid + "&personLoggin.ATTA1=" + btEditText.getText().toString().trim() + "&personLoggin.LOGTYPE=" + sourceway + "&personLoggin.LOGDATE=" + gzsjButton.getText().toString().trim() + "&personLoggin.LOGWORK=" + rznrEditText.getText().toString().trim() + "&personLoggin.NOTES=" + bzEditText.getText().toString().trim(); // +"&areaName=" // +"&eventId=" // +"&social.EVENTNM="+ // ztEditText.getText().toString().trim() // +"&social.LATITUDE="+ShareUtil.getString(getApplicationContext(),"GPS", // "GPS_longitude", "0.0") // +"&social.LONGITUDE="+ShareUtil.getString(getApplicationContext(),"GPS", // "GPS_latitude", "0.0") // +"&social.OCCURADDR="+fsddEditText.getText().toString().trim() // +"&social.SOURCEWAY="+sourceway // +"&social.OCCURTIME="+lysj // +"&social.SOURCEPEOPLE="+lyrEditText.getText().toString().trim() // +"&social.PHONE="+lxdhEditText.getText().toString().trim() // +"&social.NEWS="+xxnrEditText.getText().toString().trim() // +"&uploadFile="; // +"&attachId_="; // System.out.println(furl); try { sss = connServerForResultPost(a, b); } catch (Exception e) { msg_listData.what = MESSAGETYPE_02; } if (sss == null || "".equals(sss) || sss.contains("failure")) { msg_listData.what = MESSAGETYPE_02; } else { msg_listData.what = MESSAGETYPE_01; } handler4.sendMessage(msg_listData); } catch (Exception e) { if (null != e) { e.printStackTrace(); } } } }).start(); }
From source file:cm.aptoide.pt.RemoteInTab.java
private void downloadList(String srv) { String url = srv + REMOTE_FILE; try {/*w w w. ja va2s. co m*/ FileOutputStream saveit = new FileOutputStream(XML_PATH); HttpParams httpParameters = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(httpParameters, 5000); HttpConnectionParams.setSoTimeout(httpParameters, 5000); DefaultHttpClient mHttpClient = new DefaultHttpClient(httpParameters); HttpGet mHttpGet = new HttpGet(url); String[] logins = null; logins = db.getLogin(srv); if (logins != null) { URL mUrl = new URL(url); mHttpClient.getCredentialsProvider().setCredentials(new AuthScope(mUrl.getHost(), mUrl.getPort()), new UsernamePasswordCredentials(logins[0], logins[1])); } HttpResponse mHttpResponse = mHttpClient.execute(mHttpGet); if (mHttpResponse.getStatusLine().getStatusCode() == 401) { Message msg = new Message(); msg.obj = new String(srv); secure_error_handler.sendMessage(msg); } else { byte[] buffer = EntityUtils.toByteArray(mHttpResponse.getEntity()); saveit.write(buffer); } } catch (UnknownHostException e) { Message msg = new Message(); msg.obj = new String(srv); error_handler.sendMessage(msg); } catch (ClientProtocolException e) { } catch (IOException e) { } }