List of usage examples for android.os Message getData
public Bundle getData()
From source file:com.baofeng.game.sdk.net.AsyncHttpGet.java
@Override public void run() { String ret = ""; try {/*www . j a v a 2 s. c o m*/ if (parameter != null && parameter.size() > 0) { StringBuilder bulider = new StringBuilder(); for (RequestParameter p : parameter) { if (bulider.length() != 0) { bulider.append("&"); } bulider.append(Util.encode(p.getName())); bulider.append("="); bulider.append(Util.encode(p.getValue())); } // url += "?" + bulider.toString(); url += "?" + bulider.toString() + "&sign=" + MD5Util.MD5(bulider.toString() + "1234" + BFGameConfig.SERVERKEY); // System.out.println("@@@"+bulider.toString()); } LogUtil.d("AsyncHttpGet : ", url); for (int i = 0; i < BFGameConfig.CONNECTION_COUNT; i++) { try { request = new HttpGet(url); if (BFGameConfig.isGzip) { request.addHeader("Accept-Encoding", "gzip"); } else { request.addHeader("Accept-Encoding", "default"); } // httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout); // ? httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout); HttpResponse response = httpClient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { InputStream is = response.getEntity().getContent(); BufferedInputStream bis = new BufferedInputStream(is); bis.mark(2); // ?? byte[] header = new byte[2]; int result = bis.read(header); // reset?? bis.reset(); // ?GZIP? int headerData = getShort(header); // Gzip ? ? 0x1f8b if (result != -1 && headerData == 0x1f8b) { is = new GZIPInputStream(bis); } else { is = bis; } InputStreamReader reader = new InputStreamReader(is, "utf-8"); char[] data = new char[100]; int readSize; StringBuffer sb = new StringBuffer(); while ((readSize = reader.read(data)) > 0) { sb.append(data, 0, readSize); } ret = sb.toString(); bis.close(); reader.close(); } else { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, "??,??" + statusCode); ret = ErrorUtil.errorJson("-1", exception.getMessage()); LogUtil.d("connection url", "" + i); continue; } break; } catch (Exception e) { if (i == BFGameConfig.CONNECTION_COUNT - 1) { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, ""); ret = ErrorUtil.errorJson("-1", exception.getMessage()); } else { LogUtil.d("connection url", "" + i); continue; } } } } catch (java.lang.IllegalArgumentException e) { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, BFGameConfig.ERROR_MESSAGE); ret = ErrorUtil.errorJson("-2", exception.getMessage()); } finally { if (!BFGameConfig.IS_STOP_REQUEST) { Message msg = new Message(); msg.obj = ret; msg.getData().putSerializable("callback", callBack); resultHandler.sendMessage(msg); } if (customLoadingDialog != null && customLoadingDialog.isShowing()) { customLoadingDialog.dismiss(); customLoadingDialog = null; } } super.run(); }
From source file:com.changxiang.game.sdk.net.AsyncHttpPost.java
@Override public void run() { String ret = ""; try {//from w w w .j a v a2 s.c o m for (int i = 0; i < CXGameConfig.CONNECTION_COUNT; i++) { try { request = new HttpPost(url); request.addHeader("Accept-Encoding", "default"); if (parameter != null && parameter.size() > 0) { List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>(); for (RequestParameter p : parameter) { list.add(new BasicNameValuePair(Util.encode(p.getName()), Util.encode(p.getValue()))); LogUtil.d("AsyncHttpPost Param ", p.getName() + " , " + p.getValue()); } StringBuffer sb = new StringBuffer(); for (int j = 0; j < list.size(); j++) { sb.append(list.get(j)); if (!(j == list.size() - 1)) { sb.append("&"); } } BasicNameValuePair bn = new BasicNameValuePair("sign", MD5Util.MD5(sb + "1234" + CXGameConfig.SERVERKEY)); System.out.println( "POST_SIGN:" + sb + "&sign=" + MD5Util.MD5(sb + "1234" + CXGameConfig.SERVERKEY)); list.add(bn); ((HttpPost) request).setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); } System.out.println("====" + url); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout); HttpResponse response = httpClient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { // HttpManager.saveCookies(response); InputStream is = response.getEntity().getContent(); BufferedInputStream bis = new BufferedInputStream(is); bis.mark(2); // ?? byte[] header = new byte[2]; int result = bis.read(header); // reset?? bis.reset(); // ?GZIP? int headerData = getShort(header); // Gzip ? ? 0x1f8b if (result != -1 && headerData == 0x1f8b) { is = new GZIPInputStream(bis); } else { is = bis; } InputStreamReader reader = new InputStreamReader(is, "utf-8"); char[] data = new char[100]; int readSize; StringBuffer sb = new StringBuffer(); while ((readSize = reader.read(data)) > 0) { sb.append(data, 0, readSize); } ret = sb.toString(); bis.close(); reader.close(); } else { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, "??,??" + statusCode); ret = ErrorUtil.errorJson("-1", exception.getMessage()); } break; } catch (Exception e) { if (i == CXGameConfig.CONNECTION_COUNT - 1) { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, ""); ret = ErrorUtil.errorJson("-1", exception.getMessage()); } else { LogUtil.d("connection url", "" + i); continue; } } } } catch (java.lang.IllegalArgumentException e) { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, CXGameConfig.ERROR_MESSAGE); ret = ErrorUtil.errorJson("-2", exception.getMessage()); } finally { if (!CXGameConfig.IS_STOP_REQUEST) { Message msg = new Message(); msg.obj = ret; msg.getData().putSerializable("callback", callBack); resultHandler.sendMessage(msg); } if (customLoadingDialog != null && customLoadingDialog.isShowing()) { customLoadingDialog.dismiss(); customLoadingDialog = null; } } super.run(); }
From source file:com.baofeng.game.sdk.net.AsyncHttpPost.java
@Override public void run() { String ret = ""; try {//w w w . j ava 2 s .c om for (int i = 0; i < BFGameConfig.CONNECTION_COUNT; i++) { try { request = new HttpPost(url); request.addHeader("Accept-Encoding", "default"); if (parameter != null && parameter.size() > 0) { List<BasicNameValuePair> list = new ArrayList<BasicNameValuePair>(); for (RequestParameter p : parameter) { list.add(new BasicNameValuePair(Util.encode(p.getName()), Util.encode(p.getValue()))); LogUtil.d("AsyncHttpPost Param ", p.getName() + " , " + p.getValue()); } StringBuffer sb = new StringBuffer(); for (int j = 0; j < list.size(); j++) { sb.append(list.get(j)); if (!(j == list.size() - 1)) { sb.append("&"); } } BasicNameValuePair bn = new BasicNameValuePair("sign", MD5Util.MD5(sb + "1234" + BFGameConfig.SERVERKEY)); // System.out.println("@@@" + sb + "1234" // + BFGameConfig.SERVERKEY); list.add(bn); ((HttpPost) request).setEntity(new UrlEncodedFormEntity(list, HTTP.UTF_8)); } LogUtil.d("AsyncHttpPost : ", url); httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectTimeout); httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, readTimeout); HttpResponse response = httpClient.execute(request); int statusCode = response.getStatusLine().getStatusCode(); if (statusCode == HttpStatus.SC_OK) { // HttpManager.saveCookies(response); InputStream is = response.getEntity().getContent(); BufferedInputStream bis = new BufferedInputStream(is); bis.mark(2); // ?? byte[] header = new byte[2]; int result = bis.read(header); // reset?? bis.reset(); // ?GZIP? int headerData = getShort(header); // Gzip ? ? 0x1f8b if (result != -1 && headerData == 0x1f8b) { is = new GZIPInputStream(bis); } else { is = bis; } InputStreamReader reader = new InputStreamReader(is, "utf-8"); char[] data = new char[100]; int readSize; StringBuffer sb = new StringBuffer(); while ((readSize = reader.read(data)) > 0) { sb.append(data, 0, readSize); } ret = sb.toString(); bis.close(); reader.close(); } else { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, "??,??" + statusCode); ret = ErrorUtil.errorJson("-1", exception.getMessage()); } break; } catch (Exception e) { if (i == BFGameConfig.CONNECTION_COUNT - 1) { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, ""); ret = ErrorUtil.errorJson("-1", exception.getMessage()); } else { LogUtil.d("connection url", "" + i); continue; } } } } catch (java.lang.IllegalArgumentException e) { RequestException exception = new RequestException(RequestException.IO_EXCEPTION, BFGameConfig.ERROR_MESSAGE); ret = ErrorUtil.errorJson("-2", exception.getMessage()); } finally { if (!BFGameConfig.IS_STOP_REQUEST) { Message msg = new Message(); msg.obj = ret; msg.getData().putSerializable("callback", callBack); resultHandler.sendMessage(msg); } if (customLoadingDialog != null && customLoadingDialog.isShowing()) { customLoadingDialog.dismiss(); customLoadingDialog = null; } } super.run(); }
From source file:ti.modules.titanium.geolocation.TiLocation.java
public void forwardGeocode(String address, GeocodeResponseHandler responseHandler) { if (address != null) { String geocoderUrl = buildGeocoderURL(TiC.PROPERTY_FORWARD, mobileId, appGuid, sessionId, address, countryCode);//from ww w. ja v a 2 s .c o m if (geocoderUrl != null) { Message message = runtimeHandler.obtainMessage(MSG_LOOKUP); message.getData().putString(TiC.PROPERTY_DIRECTION, TiC.PROPERTY_FORWARD); message.getData().putString(TiC.PROPERTY_URL, geocoderUrl); message.obj = responseHandler; message.sendToTarget(); } } else { Log.e(TAG, "Unable to forward geocode, address is null"); } }
From source file:ti.modules.titanium.geolocation.TiLocation.java
public boolean handleMessage(Message msg) { if (msg.what == MSG_LOOKUP) { String urlValue = msg.getData().getString(TiC.PROPERTY_URL); String directionValue = msg.getData().getString(TiC.PROPERTY_DIRECTION); AsyncTask<Object, Void, Integer> task = getLookUpTask(); task.execute(urlValue, directionValue, msg.obj); return true; }//from w ww . ja v a 2 s . c o m return false; }
From source file:com.variable.demo.api.fragment.MotionFragment.java
@Override public void onGyroscopeUpdate(MotionSensor sensor, MotionReading reading) { Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_GYROSCOPE_READING); Bundle b = m.getData(); b.putFloat(MessageConstants.X_VALUE_KEY, (reading.getX() + 2000) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Y_VALUE_KEY, (reading.getY() + 2000) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Z_VALUE_KEY, (reading.getZ() + 2000) * DECIMAL_PRECISION); //For this demo we are streaming all time stamp from the node device. b.putLong(MessageConstants.TIME_STAMP, reading.getTimeStamp().getTime()); b.putInt(MessageConstants.TIME_SOURCE, reading.getTimeStampSource()); final Context thiscontext = this.getActivity(); final String serialnumOne = sensor.getSerialNumber(); final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", ""); final String scanX = Float.toString((reading.getX() + 16) * DECIMAL_PRECISION); final String scanY = Float.toString((reading.getY() + 16) * DECIMAL_PRECISION); final String scanZ = Float.toString((reading.getZ() + 16) * DECIMAL_PRECISION); String json = "gyroscope;" + serialnum + ";" + scanX + "," + scanY + "," + scanZ; // POST to variable dashboard Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false); Ion.with(thiscontext).load(/*ww w . j a va2 s. c om*/ "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]=" + json) .setLogging("MyLogs", Log.DEBUG).asString().withResponse() .setCallback(new FutureCallback<Response<String>>() { @Override public void onCompleted(Exception e, Response<String> result) { if (e == null) { Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString()); } else { Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION"); e.printStackTrace(); } } }); m.sendToTarget(); }
From source file:com.variable.demo.api.fragment.MotionFragment.java
@Override public void onMagnetometerUpdate(MotionSensor sensor, MotionReading reading) { Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_MAGNETOMETER_READING); Bundle b = m.getData(); b.putFloat(MessageConstants.X_VALUE_KEY, (reading.getX() + 6) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Y_VALUE_KEY, (reading.getY() + 6) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Z_VALUE_KEY, (reading.getZ() + 6) * DECIMAL_PRECISION); //For this demo we are streaming all time stamp from the node device. b.putLong(MessageConstants.TIME_STAMP, reading.getTimeStamp().getTime()); b.putInt(MessageConstants.TIME_SOURCE, reading.getTimeStampSource()); final Context thiscontext = this.getActivity(); final String serialnumOne = sensor.getSerialNumber(); final String serialnum = serialnumOne.replaceAll("[^\\u0000-\\uFFFF]", ""); final String scanX = Float.toString((reading.getX() + 16) * DECIMAL_PRECISION); final String scanY = Float.toString((reading.getY() + 16) * DECIMAL_PRECISION); final String scanZ = Float.toString((reading.getZ() + 16) * DECIMAL_PRECISION); String json = "magnetometer;" + serialnum + ";" + scanX + "," + scanY + "," + scanZ; // POST to variable dashboard Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false); Ion.with(thiscontext).load(/*from www .j a va 2s.com*/ "https://datadipity.com/clickslide/fleetplusdata.json?PHPSESSID=gae519f8k5humje0jqb195nob6&update&postparam[payload]=" + json) .setLogging("MyLogs", Log.DEBUG).asString().withResponse() .setCallback(new FutureCallback<Response<String>>() { @Override public void onCompleted(Exception e, Response<String> result) { if (e == null) { Log.i(TAG, "ION SENT MESSAGE WITH RESULT CODE: " + result.toString()); } else { Log.i(TAG, "ION SENT MESSAGE WITH EXCEPTION"); e.printStackTrace(); } } }); m.sendToTarget(); }
From source file:org.sufficientlysecure.keychain.ui.SettingsKeyserverFragment.java
private void startEditKeyserverDialog(AddEditKeyserverDialogFragment.DialogAction action, ParcelableHkpKeyserver keyserver, final int position) { Handler returnHandler = new Handler() { @Override//w w w.java2 s.co m public void handleMessage(Message message) { Bundle data = message.getData(); switch (message.what) { case AddEditKeyserverDialogFragment.MESSAGE_OKAY: { boolean deleted = data.getBoolean(AddEditKeyserverDialogFragment.MESSAGE_KEYSERVER_DELETED, false); if (deleted) { Notify.create(getActivity(), getActivity().getString(R.string.keyserver_preference_deleted, mKeyservers.get(position)), Notify.Style.OK).show(); deleteKeyserver(position); return; } boolean verified = data.getBoolean(AddEditKeyserverDialogFragment.MESSAGE_VERIFIED); if (verified) { Notify.create(getActivity(), R.string.add_keyserver_connection_verified, Notify.Style.OK) .show(); } else { Notify.create(getActivity(), R.string.add_keyserver_without_verification, Notify.Style.WARN) .show(); } ParcelableHkpKeyserver keyserver = data .getParcelable(AddEditKeyserverDialogFragment.MESSAGE_KEYSERVER); AddEditKeyserverDialogFragment.DialogAction dialogAction = (AddEditKeyserverDialogFragment.DialogAction) data .getSerializable(AddEditKeyserverDialogFragment.MESSAGE_DIALOG_ACTION); switch (dialogAction) { case ADD: addKeyserver(keyserver); break; case EDIT: editKeyserver(keyserver, position); break; } break; } } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); AddEditKeyserverDialogFragment dialogFragment = AddEditKeyserverDialogFragment.newInstance(messenger, action, keyserver, position); dialogFragment.show(getFragmentManager(), "addKeyserverDialog"); }
From source file:org.sufficientlysecure.keychain.ui.SettingsSmartPGPAuthorityFragment.java
private void startEditAuthorityDialog(AddEditSmartPGPAuthorityDialogFragment.Action action, final String old_alias, final Uri uri, final int position) { Handler returnHandler = new Handler() { @Override//from ww w . j a va 2 s . co m public void handleMessage(Message message) { Bundle data = message.getData(); final String new_alias = data.getString(AddEditSmartPGPAuthorityDialogFragment.OUT_ALIAS); final int position = data.getInt(AddEditSmartPGPAuthorityDialogFragment.OUT_POSITION); final String uri = data.getString(AddEditSmartPGPAuthorityDialogFragment.OUT_URI); final AddEditSmartPGPAuthorityDialogFragment.Action action = (AddEditSmartPGPAuthorityDialogFragment.Action) data .getSerializable(AddEditSmartPGPAuthorityDialogFragment.OUT_ACTION); switch (action) { case ADD: if (editAuthority(old_alias, new_alias, position, uri)) { Notify.create(getActivity(), "Authority " + new_alias + " added", Notify.LENGTH_SHORT, Notify.Style.OK).show(); } break; case EDIT: if (editAuthority(old_alias, new_alias, position, uri)) { Notify.create(getActivity(), "Authority " + old_alias + " modified", Notify.LENGTH_SHORT, Notify.Style.OK).show(); } break; case DELETE: if (deleteAuthority(position)) { Notify.create(getActivity(), "Authority " + old_alias + " deleted", Notify.LENGTH_SHORT, Notify.Style.OK).show(); } break; } } }; // Create a new Messenger for the communication back Messenger messenger = new Messenger(returnHandler); AddEditSmartPGPAuthorityDialogFragment dialogFragment = AddEditSmartPGPAuthorityDialogFragment .newInstance(messenger, action, old_alias, uri, position); dialogFragment.show(getFragmentManager(), "addSmartPGPAuthorityDialog"); }
From source file:com.spoiledmilk.ibikecph.login.HTTPAccountHandler.java
public static Message performRegister(final UserData userData, Context context) { Message message = new Message(); JsonNode result = null;/* ww w . j a v a 2s .c om*/ JSONObject jsonPOST = new JSONObject(); JSONObject jsonUser = new JSONObject(); JSONObject jsonImagePath = new JSONObject(); try { jsonImagePath.put("filename", userData.getImageName()); jsonImagePath.put("original_filename", userData.getImageName()); jsonImagePath.put("file", userData.getBase64Image()); jsonUser.put("name", userData.getName()); jsonUser.put("email", userData.getEmail()); jsonUser.put("email_confirmation", userData.getEmail()); jsonUser.put("password", userData.getPassword()); jsonUser.put("password_confirmation", userData.getPassword()); if (userData.getBase64Image() != null && !userData.getBase64Image().trim().equals("")) jsonUser.put("image_path", jsonImagePath); jsonUser.put("account_source", context.getResources().getString(R.string.account_source)); jsonPOST.put("user", jsonUser); result = HttpUtils.postToServer(Config.API_SERVER_REGISTER, jsonPOST); message = HttpUtils.JSONtoMessage(result); message.getData().putInt("type", REGISTER_USER); } catch (JSONException e) { LOG.e(e.getLocalizedMessage()); message.getData().putInt("type", ERROR); } return message; }