List of usage examples for android.os Message Message
public Message()
From source file:com.example.zf_android.trade.ApplyDetailActivity.java
@Override protected void onActivityResult(final int requestCode, int resultCode, final Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode != RESULT_OK) return;/*from ww w . j a v a2s.com*/ switch (requestCode) { case REQUEST_CHOOSE_MERCHANT: { mAgentId = mMerchantId = data.getIntExtra(AGENT_ID, 0); mAgentName = data.getStringExtra(AGENT_NAME); setItemValue(mMerchantKeys[0], mAgentName); getAgentInfo(); break; } case REQUEST_CHOOSE_BANK: { mBankName = data.getStringExtra("bank_name"); mBankNo = data.getStringExtra("bank_no"); setItemValue(customTag, mBankName); setItemValue(mBankKeys[0], mBankName); //FIXME no // setItemValue(mBankKeys[1], mBankNo); break; } case REQUEST_CHOOSE_CITY: { mMerchantProvince = (Province) data.getSerializableExtra(SELECTED_PROVINCE); mMerchantCity = (City) data.getSerializableExtra(SELECTED_CITY); mCityId = mMerchantCity.getId(); setItemValue(mMerchantKeys[8], mMerchantCity.getName()); break; } case REQUEST_CHOOSE_CHANNEL: { mChannelId = data.getIntExtra("channelId", 0); mBillingId = data.getIntExtra("billId", 0); String channelName = data.getStringExtra("channelName"); String billName = data.getStringExtra("billName"); setItemValue(getString(R.string.apply_detail_channel), channelName + " " + billName); break; } case REQUEST_UPLOAD_IMAGE: case REQUEST_TAKE_PHOTO: { final Handler handler = new Handler() { @Override public void handleMessage(Message msg) { if (msg.what == 1) { // CommonUtil.toastShort(ApplyDetailActivity.this, (String) msg.obj); if (null != uploadingTextView) { final String url = (String) msg.obj; LinearLayout item = (LinearLayout) uploadingTextView.getParent().getParent(); updateCustomerDetails(item.getTag(), url); uploadingTextView.setVisibility(View.GONE); ImageView iv_view = (ImageView) item.findViewById(R.id.apply_detail_view); iv_view.setVisibility(View.VISIBLE); iv_view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(ApplyDetailActivity.this, ImageViewer.class); i.putExtra("url", url); i.putExtra("justviewer", true); startActivity(i); } }); } } else { CommonUtil.toastShort(ApplyDetailActivity.this, getString(R.string.toast_upload_failed)); if (null != uploadingTextView) { uploadingTextView.setText(getString(R.string.apply_upload_again)); uploadingTextView.setClickable(true); } } } }; if (null != uploadingTextView) { uploadingTextView.setText(getString(R.string.apply_uploading)); uploadingTextView.setClickable(false); } new Thread() { @Override public void run() { String realPath = ""; if (requestCode == REQUEST_TAKE_PHOTO) { realPath = photoPath; } else { Uri uri = data.getData(); if (uri != null) { realPath = getRealPathFromURI(uri); } } if (TextUtils.isEmpty(realPath)) { handler.sendEmptyMessage(0); return; } CommonUtil.uploadFile(realPath, "img", new CommonUtil.OnUploadListener() { @Override public void onSuccess(String result) { try { JSONObject jo = new JSONObject(result); String url = jo.getString("result"); Message msg = new Message(); msg.what = 1; msg.obj = url; handler.sendMessage(msg); } catch (JSONException e) { handler.sendEmptyMessage(0); } } @Override public void onFailed(String message) { handler.sendEmptyMessage(0); } }); } }.start(); break; } } }
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void changeGoodPics(final String goodId, final String picList) { new Thread() { Message msg = new Message(); @Override/*from w w w . j a v a 2 s . c o m*/ public void run() { String data = "&id=" + goodId + "&picture=" + picList; Log.e("data=", data); String result_data = NetUtil.getResponse(WebAddress.CHANGE_GOOD_PICS, data); Log.e("successful", result_data); try { JSONObject obj = new JSONObject(result_data); msg.what = CommunalInterfaces.CHANGE_GOOD_PICS; msg.obj = obj; Log.e("return is", result_data); } catch (JSONException e) { e.printStackTrace(); } finally { handler.sendMessage(msg); } } }.start(); }
From source file:com.jinfukeji.jinyihuiup.indexBannerClick.ZhiboActivity.java
@Override public void onReconnecting() { Message message = new Message(); message.what = HANDlER.RECONNECTING; mHandler.sendMessage(message); }
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void changeGoodDetailsPics(final String goodId, final String picList) { new Thread() { Message msg = new Message(); @Override/* w w w . j av a2 s . com*/ public void run() { String data = "&id=" + goodId + "&cpiclist=" + picList; Log.e("data=", data); String result_data = NetUtil.getResponse(WebAddress.CHANGE_GOOD_PIC_DETAILS, data); Log.e("successful", result_data); try { JSONObject obj = new JSONObject(result_data); msg.what = CommunalInterfaces.CHANGE_GOOD_PIC_DETAILS; msg.obj = obj; Log.e("return is", result_data); } catch (JSONException e) { e.printStackTrace(); } finally { handler.sendMessage(msg); } } }.start(); }
From source file:com.nbplus.push.PushService.java
private void getFromServer(final String url) { if (mRequestBody == null) { String prefName = mContext.getApplicationContext().getPackageName() + "_preferences"; SharedPreferences prefs = mContext.getSharedPreferences(prefName, Context.MODE_PRIVATE); // load from preferences.. String deviceId = prefs.getString(PushConstants.KEY_DEVICE_ID, ""); if (StringUtils.isEmptyString(deviceId)) { deviceId = DeviceUtils.getDeviceIdByMacAddress(mContext); prefs.edit().putString(PushConstants.KEY_DEVICE_ID, deviceId).apply(); }/*from ww w . j a v a 2 s . c o m*/ GetPushInterfaceRequestBody reqBodyObj = new GetPushInterfaceRequestBody(); reqBodyObj.deviceId = deviceId; reqBodyObj.os = Build.VERSION.RELEASE; reqBodyObj.pushVersion = Integer.toString(BuildConfig.VERSION_CODE); reqBodyObj.vendor = Build.MANUFACTURER; reqBodyObj.model = DeviceUtils.getDeviceName(); reqBodyObj.os = Build.ID + " " + Build.VERSION.RELEASE; reqBodyObj.deviceType = "android"; Gson gson = new GsonBuilder().create(); mRequestBody = gson.toJson(reqBodyObj, new TypeToken<GetPushInterfaceRequestBody>() { }.getType()); } // RequestQueue requestQueue = Volley.newRequestQueue(mContext, new HurlStack() { // @Override // protected HttpURLConnection createConnection(URL url) throws IOException { // HttpURLConnection connection = super.createConnection(url); // // Fix for bug in Android runtime(!!!): // // https://code.google.com/p/android/issues/detail?id=24672 // connection.setRequestProperty("Accept-Encoding", ""); // // return connection; // } // }); final GsonRequest gsonRequest = new GsonRequest(Request.Method.POST, url, mRequestBody, PushInterfaceData.class, new Response.Listener<PushInterfaceData>() { @Override public void onResponse(PushInterfaceData response) { Log.d(TAG, ">>> get PushInterfaceData success !!!"); mApiRetryCount = 0; Message message = new Message(); message.what = PushConstants.HANDLER_MESSAGE_GET_PUSH_GATEWAY_DATA; message.obj = response; mHandler.sendMessage(message); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { /** * 2015.10.05 * 1? ? ?? . */ Log.d(TAG, ">>> get PushInterfaceData error... retry connection after 1 minutes..."); if (mPushRunnable.getState() != PushRunnable.State.Stopped) { mPushRunnable.releasePushClientSocket(false); } mHandler.removeMessages(PushConstants.HANDLER_MESSAGE_RETRY_MESSAGE); mHandler.sendEmptyMessageDelayed(PushConstants.HANDLER_MESSAGE_RETRY_MESSAGE, PushService.MILLISECONDS * PushService.mNextRetryPeriodTerm); } }); if (mRequestQueue == null) { mRequestQueue = Volley.newRequestQueue(mContext, new HurlStack() { @Override protected HttpURLConnection createConnection(URL url) throws IOException { HttpURLConnection connection = super.createConnection(url); // Fix for bug in Android runtime(!!!): // https://code.google.com/p/android/issues/detail?id=24672 connection.setRequestProperty("Accept-Encoding", ""); return connection; } }); } gsonRequest.setRetryPolicy(new DefaultRetryPolicy(20 * 1000, 3, 1.0f)); mRequestQueue.add(gsonRequest); }
From source file:com.jinfukeji.jinyihuiup.indexBannerClick.ZhiboActivity.java
@Override public void onCaching(boolean b) { Message msg = new Message(); msg.what = b ? HANDlER.CACHING : HANDlER.CACHING_END; mHandler.sendMessage(msg);//from w w w .ja v a 2s . co m }
From source file:com.xdyou.sanguo.GameSanGuo.java
public static void callFBCreateSession() { Message createSession = new Message(); createSession.what = FB_CREATE_SESSION; handler.sendMessage(createSession);/*from ww w. j av a 2s . co m*/ }
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void getshopgoodlist(final String shopid) { new Thread() { Message msg = new Message(); @Override//w w w .jav a 2s .c o m public void run() { String data = "&userid=" + user.getUserId() + "&shopid=" + shopid + "&xiajia=0"; Log.e("data=", data); String result_data = NetUtil.getResponse(WebAddress.GETSHOPGOODLIST, data); Log.e("successful", result_data); try { JSONObject obj = new JSONObject(result_data); msg.what = CommunalInterfaces.GETSHOPGOODLIST; msg.obj = obj; } catch (JSONException e) { e.printStackTrace(); } finally { handler.sendMessage(msg); } } }.start(); }
From source file:com.oasis.sdk.activity.GooglePlayBillingActivity.java
private void queryInventory() { if (isPageClose()) { isPageCloseHandler();/*from ww w . j a v a 2s . c o m*/ return; } List<String> moreSkus = new ArrayList<String>(); moreSkus.add(productID); mHelper.queryInventoryAsync(true, moreSkus, new QueryInventoryFinishedListener() { @Override public void onQueryInventoryFinished(IabResult result, Inventory inv) { if (isPageClose()) { isPageCloseHandler(); return; } // Is it a failure? if (result.isFailure() || inv == null) { BaseUtils.logError(TAG, "Failed to query inventory: " + IabHelper.getResponseDesc(result.getResponse())); Message msg = new Message(); msg.what = 0; msg.obj = getResources() .getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_google_notice_2")); myHandler.sendMessage(msg); return; } SkuDetails sku = inv.getSkuDetails(productID); if (sku == null || TextUtils.isEmpty(sku.getPrice())) { BaseUtils.logError(TAG, "Don't find SkuDetails by " + productID); Message msg = new Message(); msg.what = 0; msg.obj = getResources() .getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_google_notice_2")); myHandler.sendMessage(msg); return; } final Purchase p = inv.getPurchase(productID); if (p == null || (p != null && p.getPurchaseState() != IabHelper.BILLING_RESPONSE_RESULT_OK && p.getPurchaseState() != IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED)) { if (p != null && p.getPurchaseState() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED) { inv.erasePurchase(productID); } BaseUtils.logDebug(TAG, "Old purchase is null. Start purchase."); startPurchase(); return; } //???? Message msg = new Message(); msg.what = -2; msg.obj = getResources() .getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_order_notice_old")); myHandler.sendMessage(msg); new Thread(new Runnable() { @Override public void run() { BaseUtils.logDebug(TAG, "Old purchase info:" + p.toString()); int res = -1; try { res = HttpService.instance().checkPurchaseForGoogle(p, GoogleBillingUtils.SEPARATE); } catch (OasisSdkException e) { } finally { try { String[] info = p.getDeveloperPayload().split(GoogleBillingUtils.SEPARATE); // ?Mdata??? List<String> parameters = new ArrayList<String>(); parameters.add("\"uid\":\"" + info[0] + "\""); parameters.add("\"roleid\":\"" + info[2] + "\""); parameters.add("\"serverid\":\"" + info[1] + "\""); if (info.length >= 6 && ("android".equalsIgnoreCase(info[5]) || "all".equalsIgnoreCase(info[5]) || "test".equalsIgnoreCase(info[5]))) parameters.add("\"servertype\":\"" + info[5] + "\""); else parameters.add("\"servertype\":\"\""); parameters.add("\"product_id\":\"" + p.getSku() + "\""); parameters.add("\"payment_channal\":\"mob_google\""); String re = info[4]; if (re != null && !TextUtils.isEmpty(re)) { String[] rev = re.split("_"); parameters.add("\"cost\":\"" + (rev.length > 0 ? rev[0] : "") + "\""); parameters.add("\"currency\":\"" + (rev.length > 1 ? rev[1] : "") + "\""); } else { parameters.add("\"cost\":\"\""); parameters.add("\"currency\":\"\""); } parameters.add("\"value\":\"\""); if (info.length >= 7) parameters.add("\"oas_order_id\":\"" + info[6] + "\""); else parameters.add("\"oas_order_id\":\"\""); parameters.add("\"third_party_orderid\":\"" + p.getOrderId() + "\""); parameters.add("\"result_code\":\"" + res + "\""); parameters.add("\"isreport\":\"" + (PhoneInfo.instance().isTrackAble() ? "Y" : "N") + "\""); List<String> status = new ArrayList<String>(); status.add("\"event_type\":\"order\""); ReportUtils.add(ReportUtils.DEFAULTEVENT_ORDER_REPORT_OLD_GOOGLE, parameters, status); } catch (Exception e) { BaseUtils.logError(TAG, "Google play billing send mdata fail."); } BaseUtils.logDebug(TAG, "Old purchase handle.purchase.orderID=" + p.getOrderId() + ", Code=" + res); if (isPageClose()) { isPageCloseHandler(); return; } Message msg = new Message(); if (res == 1000000 || res == 1000002 || res == 1000006) { msg.what = 100; msg.obj = p; msg.arg1 = -1; myHandler.sendMessage(msg); } else { BaseUtils.logError(TAG, "???GoogleOrderid=" + p.getOrderId() + ", Result Code=" + res + ""); //???? msg.what = 0; msg.obj = getResources().getString( BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_error_fail")); myHandler.sendMessage(msg); } } } }).start(); } }); }
From source file:com.cettco.buycar.dealer.activity.OrderDetailActivity.java
private void accept(String url) { System.out.println("url:" + url); String cookieStr = null;//from w w w.ja v a2 s .com String cookieName = null; PersistentCookieStore myCookieStore = new PersistentCookieStore(this); if (myCookieStore == null) { System.out.println("cookie store 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("")) { System.out.println("cookie null"); return; } JSONObject bidJson = new JSONObject(); JSONObject json = new JSONObject(); try { bidJson.put("bargain_id", bargain_id); json.put("bid", bidJson); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Gson gson = new Gson(); StringEntity entity = null; try { entity = new StringEntity(json.toString()); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } HttpConnection.getClient().removeHeader("x-http-method-override"); HttpConnection.getClient().addHeader("Cookie", cookieName + "=" + cookieStr); // HttpConnection.setCookie(getApplicationContext()); progressLayout.setVisibility(View.VISIBLE); HttpConnection.post(OrderDetailActivity.this, url, null, entity, "application/json;charset=utf-8", new AsyncHttpResponseHandler() { @Override public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) { // TODO Auto-generated method stub System.out.println("header :" + arg0); progressLayout.setVisibility(View.GONE); System.out.println("fail"); Message message = new Message(); message.what = 3; mHandler.sendMessage(message); } @Override public void onSuccess(int arg0, Header[] arg1, byte[] arg2) { // TODO Auto-generated method stub progressLayout.setVisibility(View.GONE); System.out.println("header :" + arg0); try { String result = new String(arg2, "UTF-8"); System.out.println("order detail submit:" + result); // Type listType = new // TypeToken<ArrayList<OrderItemEntity>>() { // }.getType(); // list = new Gson().fromJson(result, listType); // //System.out.println("size:"+dealerList.size()); Message message = new Message(); message.what = 4; mHandler.sendMessage(message); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); }