List of usage examples for android.os Message obtain
public static Message obtain()
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void sendCode(final String phoNum) { new Thread() { Message msg = Message.obtain(); public void run() { String data = "&phone=" + phoNum; String result_data = NetUtil.getResponse(WebAddress.SEND_CODE, data); Log.e("result data is", result_data); try { JSONObject obj = new JSONObject(result_data); msg.what = CommunalInterfaces.SEND_CODE; msg.obj = obj;/* w w w . jav a 2 s.c o m*/ } catch (JSONException e) { e.printStackTrace(); } finally { handler.sendMessage(msg); } } }.start(); }
From source file:my.home.lehome.service.SendMsgIntentService.java
private void preparePengindCommand(Intent intent) { Messenger messenger;//from w w w . ja v a 2 s . com if (intent.hasExtra("messenger")) messenger = (Messenger) intent.getExtras().get("messenger"); else messenger = null; Message repMsg = Message.obtain(); repMsg.what = MSG_BEGIN_SENDING; boolean isSysCmd = intent.getBooleanExtra("isSysCmd", false); if (isSysCmd) { Log.d(TAG, "sys cmd item"); return; } ChatItem item = intent.getParcelableExtra("update"); if (item == null) { item = new ChatItem(); item.setContent(intent.getStringExtra("cmd")); item.setType(ChatItemConstants.TYPE_CLIENT); item.setState(Constants.CHATITEM_STATE_ERROR); // set ERROR item.setDate(new Date()); DBStaticManager.addChatItem(getApplicationContext(), item); } item.setState(Constants.CHATITEM_STATE_PENDING); Log.d(TAG, "enqueue item: \n" + item); Bundle bundle = new Bundle(); bundle.putBoolean("update", intent.hasExtra("update")); bundle.putParcelable("item", item); if (messenger != null) { repMsg.setData(bundle); try { messenger.send(repMsg); } catch (RemoteException e) { e.printStackTrace(); } } else { Log.d(TAG, "messager is null, send broadcast instead:" + ACTION_SEND_MSG_BEGIN); Intent newIntent = new Intent(ACTION_SEND_MSG_BEGIN); newIntent.putExtras(bundle); sendBroadcast(newIntent); } intent.putExtra("pass_item", item); }
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);/* w w w . j a v a 2 s. c o m*/ 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(); 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:MyWeatherService.java
void sendWeatherToClient(String actualWeatherString) { Bundle reply = new Bundle(); reply.putString("weather", actualWeatherString); Message replyMessage = Message.obtain(); replyMessage.setData(reply);//from w w w . j a v a 2s. c o m try { messengerToClient.send(replyMessage); } catch (RemoteException e) { e.printStackTrace(); } }
From source file:com.jwork.dhammapada.controller.DhammapadaController.java
private void init() { log.v(this, "init()"); int version = Configuration.getInstance(activity).getCurrentVersion(); if (version != CrashHandler.getVersionCode(activity)) { Message msg = Message.obtain(); msg.what = Constant.WHAT_DISPLAY_CHANGELOG; viewHandler.sendMessage(msg);//from www .j a v a2 s.c o m } }
From source file:org.durka.hallmonitor.CoreService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { if (!mStateManager.getMainLaunched() && mStateManager.getPreference().getBoolean("pref_enabled", false)) { Message msg = Message.obtain(); msg.arg1 = startId;//from www. j ava 2s. c o m msg.what = CoreApp.CS_TASK_MAINLAUNCH; ServiceThread svcThread = new ServiceThread(msg); svcThread.start(); } if (intent != null && intent.hasExtra(CoreApp.CS_EXTRA_TASK)) { int requestedTaskMode = intent.getIntExtra(CoreApp.CS_EXTRA_TASK, 0); if (requestedTaskMode > 0) { int msgArg2 = 0; switch (requestedTaskMode) { case CoreApp.CS_TASK_CHANGE_TOUCHCOVER: boolean sendTouchCoverRequest = intent.getBooleanExtra(CoreApp.CS_EXTRA_STATE, false); if (sendTouchCoverRequest != lastTouchCoverRequest) { mStateManager.acquireCPUGlobal(); lastTouchCoverRequest = sendTouchCoverRequest; Message msgTCH = mTouchCoverHandler.obtainMessage(); msgTCH.arg1 = startId; if (sendTouchCoverRequest) { msgTCH.arg2 = 1; } else { msgTCH.arg2 = 0; } mTouchCoverHandler.sendMessage(msgTCH); } return START_STICKY; case CoreApp.CS_TASK_AUTO_BLACKSCREEN: if (mStateManager.getInActivity()) { Log.d(LOG_TAG + ".oSC", "Blackscreen requested canceled during activity"); return START_STICKY; } else if (mStateManager.getBlackScreenTime() > 0) { Log.d(LOG_TAG + ".oSC", "Blackscreen already requested"); return START_STICKY; } break; case CoreApp.CS_TASK_LAUNCH_ACTIVITY: mStateManager.acquireCPUGlobal(); if (intent.getBooleanExtra(CoreApp.CS_EXTRA_STATE, false)) { msgArg2 = 1; } break; case CoreApp.CS_TASK_TORCH_STATE: if (intent.getBooleanExtra(CoreApp.CS_EXTRA_STATE, false)) { msgArg2 = 1; } break; } Log.d(LOG_TAG + ".oSC", "Request starting: " + requestedTaskMode); Message msg = Message.obtain(); msg.arg1 = startId; msg.arg2 = msgArg2; msg.what = requestedTaskMode; ServiceThread svcThread = new ServiceThread(msg); svcThread.start(); } } // If we get killed, after returning from here, restart return START_STICKY; }
From source file:id.nci.stm_9.LookupUnknownKeyDialogFragment.java
/** * Send message back to handler which is initialized in a activity * /*from w ww. j av a2s.c om*/ * @param what * Message integer you want to send */ private void sendMessageToHandler(Integer what) { Message msg = Message.obtain(); msg.what = what; try { mMessenger.send(msg); } catch (RemoteException e) { Log.w("stm-9", "Exception sending message, Is handler present?", e); } catch (NullPointerException e) { Log.w("stm-9", "Messenger is null!", e); } }
From source file:com.jwork.dhammapada.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); log.v(this, "onCreate()"); if (CrashHandler.getInstance().isCrashFlag()) { log.v(this, "Crash flag detected"); showCrashDialog();/* w w w. j ava2s . c o m*/ } else { // setTheme(MainActivity.THEME); // requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); mainLayout = (FrameLayout) findViewById(R.id.mainLayout); mainLayout.getForeground().setAlpha(0); LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); aboutWindow = new PopupWindow(inflater.inflate(R.layout.activity_about, null, false), LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true); TextView text = ((TextView) aboutWindow.getContentView().findViewById(R.id.about_text)); text.setText(Html.fromHtml( getString(R.string.about_html).replaceAll("\\{0\\}", CrashHandler.getVersionName(this)) .replaceAll("\\{1\\}", "" + CrashHandler.getVersionCode(this)))); text.setMovementMethod(LinkMovementMethod.getInstance()); ImageButton button = ((ImageButton) aboutWindow.getContentView().findViewById(R.id.about_ok)); button.setOnClickListener(this); controller = new DhammapadaController(this, viewHandler); Message message = Message.obtain(); message.what = Constant.WHAT_DISPLAY_CHAPTER; controller.executeMessage(message); message = Message.obtain(); message.what = Constant.WHAT_INIT; controller.executeMessage(message); // ActionBar actionBar = getSupportActionBar(); // actionBar.hide(); // actionBar.setTitle("Dhammapada"); // actionBar.setSubtitle("Chapter"); // actionBar.setLogo(R.drawable.ic_launcher); // actionBar.show(); } }
From source file:andlabs.lounge.service.LoungeServiceImpl.java
public void setMessageHandler(MessageHandler pMessageHandler) { mMessageHandler = pMessageHandler;// w w w. j a v a 2 s. co m Message message = Message.obtain(); message.what = 42; message.setData(Bundle.EMPTY); mMessageHandler.send(message); }
From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java
public void register(final String phone, final String password, final String code) { new Thread() { Message msg = Message.obtain(); public void run() { String data = "&phone=" + phone + "&password=" + password + "&code=" + code + "&devicestate=1"; Log.e("data is ", data); String result_data = NetUtil.getResponse(WebAddress.REGISTER, data); Log.e("successful", result_data); try { JSONObject obj = new JSONObject(result_data); msg.what = CommunalInterfaces.REGISTER; msg.obj = obj;/*ww w.ja va2 s. c o m*/ } catch (JSONException e) { e.printStackTrace(); } finally { handler.sendMessage(msg); } } }.start(); }