List of usage examples for android.os Message sendToTarget
public void 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();/*from ww w . j a v a2 s . c om*/ 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( "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 onGyroscopeUpdate(MotionSensor sensor, MotionReading reading) { Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_GYROSCOPE_READING); Bundle b = m.getData();//from w w w. j a v a 2 s . com 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( "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 onAccelerometerUpdate(MotionSensor sensor, MotionReading reading) { DateFormat formatter = new SimpleDateFormat("MM-dd-yyyy hh:mm.ss"); // Log.d(TAG, "TimeStamp Source: " + reading.getTimeStampSource()); // Log.d(TAG," Time:" + formatter.format(reading.getTimeStamp())); Message m = mHandler.obtainMessage(MessageConstants.MESSAGE_ACCELEROMETER_READING); Bundle b = m.getData();//from w ww . j av a2 s.com b.putFloat(MessageConstants.X_VALUE_KEY, (reading.getX() + 16) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Y_VALUE_KEY, (reading.getY() + 16) * DECIMAL_PRECISION); b.putFloat(MessageConstants.Z_VALUE_KEY, (reading.getZ() + 16) * 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 = "accelerometer;" + serialnum + ";" + scanX + "," + scanY + "," + scanZ; // POST to variable dashboard Ion.getDefault(thiscontext).getConscryptMiddleware().enable(false); Ion.with(thiscontext).load( "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.dish.browser.activity.BrowserActivity.java
@Override /**/* www . j av a 2s . c om*/ * handles javascript requests to create a new window in the browser */ public void onCreateWindow(boolean isUserGesture, Message resultMsg) { if (resultMsg == null) { return; } if (newTab("", true)) { WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; transport.setWebView(mCurrentView.getWebView()); resultMsg.sendToTarget(); } }
From source file:com.android.mms.ui.MessageUtils.java
public static void viewSimpleSlideshow(Context context, SlideshowModel slideshow) { if (!slideshow.isSimple()) { throw new IllegalArgumentException("viewSimpleSlideshow() called on a non-simple slideshow"); }/*from ww w . jav a 2 s .c o m*/ SlideModel slide = slideshow.get(0); MediaModel mm = null; if (slide.hasImage()) { mm = slide.getImage(); } else if (slide.hasVideo()) { mm = slide.getVideo(); } else if (slide.hasAudio()) { mm = slide.getAudio(); } Intent intent = new Intent(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra("SingleItemOnly", true); // So we don't see "surrounding" images in Gallery /// M: CanShare: false, Hide the videopalye's share option menu. /// M: CanShare: ture, Show the share option menu. /// M: Code analyze 010, For fix bug ALPS00244046, The "JE" pops up // after you tap the "messaging" icon. @{ intent.putExtra("CanShare", false); /// @} /// M: for showing notification when view mms with video player in full screen model @{ intent.putExtra(EXTRA_FULLSCREEN_NOTIFICATION, true); /// @} String contentType = ""; if (mm != null) { contentType = mm.getContentType(); MmsLog.e(TAG, "viewSimpleSildeshow. Uri:" + mm.getUri()); MmsLog.e(TAG, "viewSimpleSildeshow. contentType:" + contentType); intent.setDataAndType(getPreviewFileUri(context, mm), contentType); } /// M: Code analyze 013, For fix bug ALPS00250939, Exception/Java(JE)-->com.android.mms. try { // M: change feature ALPS01751464 if (mm != null && mm.hasDrmContent()) { DrmUtilsEx.showDrmAlertDialog(context); return; } context.startActivity(intent); } catch (ActivityNotFoundException e) { Message msg = Message.obtain(MmsApp.getToastHandler()); msg.what = MmsApp.MSG_MMS_CAN_NOT_OPEN; msg.obj = contentType; msg.sendToTarget(); /// M: after user click view, and the error toast is shown, /// we must make it can press again. tricky code if (context instanceof ComposeMessageActivity) { ((ComposeMessageActivity) context).mClickCanResponse = true; } } /// @} }
From source file:com.android.gallery3d.app.PhotoPage.java
@Override public void onFullScreenChanged(boolean full) { Message m = mHandler.obtainMessage(MSG_ON_FULL_SCREEN_CHANGED, full ? 1 : 0, 0); m.sendToTarget(); }
From source file:android.webkit.cts.WebViewTest.java
public void testJavascriptInterfaceForClientPopup() throws Exception { if (!NullWebViewUtils.isWebViewAvailable()) { return;//from w w w .j ava 2 s . co m } mOnUiThread.getSettings().setJavaScriptEnabled(true); mOnUiThread.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); mOnUiThread.getSettings().setSupportMultipleWindows(true); class DummyJavaScriptInterface { @JavascriptInterface public int test() { return 42; } } final DummyJavaScriptInterface obj = new DummyJavaScriptInterface(); final WebView childWebView = mOnUiThread.createWebView(); WebViewOnUiThread childOnUiThread = new WebViewOnUiThread(this, childWebView); childOnUiThread.getSettings().setJavaScriptEnabled(true); childOnUiThread.addJavascriptInterface(obj, "dummy"); final boolean[] hadOnCreateWindow = new boolean[1]; hadOnCreateWindow[0] = false; mOnUiThread.setWebChromeClient(new WebViewOnUiThread.WaitForProgressClient(mOnUiThread) { @Override public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { getActivity().addContentView(childWebView, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj; transport.setWebView(childWebView); resultMsg.sendToTarget(); hadOnCreateWindow[0] = true; return true; } }); startWebServer(false); mOnUiThread.loadUrlAndWaitForCompletion(mWebServer.getAssetUrl(TestHtmlConstants.POPUP_URL)); new PollingCheck(TEST_TIMEOUT) { @Override protected boolean check() { return hadOnCreateWindow[0]; } }.run(); childOnUiThread.loadUrlAndWaitForCompletion("about:blank"); EvaluateJsResultPollingCheck jsResult; jsResult = new EvaluateJsResultPollingCheck("true"); childOnUiThread.evaluateJavascript("'dummy' in window", jsResult); jsResult.run(); // Verify that the injected object is functional. jsResult = new EvaluateJsResultPollingCheck("42"); childOnUiThread.evaluateJavascript("dummy.test()", jsResult); jsResult.run(); }
From source file:com.nextgis.ngm_clink_monitoring.fragments.CreateObjectFragment.java
protected void createObject() { String fieldName = null;/*from w w w . j av a 2s . c om*/ switch (mFoclStructLayerType) { case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT: if (null == mLayingMethod.getValue()) { fieldName = getActivity().getString(R.string.laying_method); } break; case FoclConstants.LAYERTYPE_FOCL_REAL_FOSC: // if (null == mFoscType.getValue()) { // fieldName = getActivity().getString(R.string.fosc_type); // break; // } if (null == mFoscPlacement.getValue()) { fieldName = getActivity().getString(R.string.fosc_placement); } break; case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CROSS: // if (null == mOpticalCrossType.getValue()) { // fieldName = getActivity().getString(R.string.optical_cross_type); // } break; case FoclConstants.LAYERTYPE_FOCL_REAL_ACCESS_POINT: break; case FoclConstants.LAYERTYPE_FOCL_REAL_SPECIAL_TRANSITION_POINT: if (null == mSpecialLayingMethod.getValue()) { fieldName = getActivity().getString(R.string.special_laying_method); break; } if (null == mMarkType.getValue()) { fieldName = getActivity().getString(R.string.mark_type); } break; } if (null != fieldName) { YesNoDialog dialog = new YesNoDialog(); dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning) .setMessage(String.format(getString(R.string.empty_field_warning), fieldName)) .setPositiveText(R.string.ok) .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() { @Override public void onPositiveClicked() { // cancel } }).show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "FieldsNotNull"); return; // we do not need logcat here } if (!mNewStartPoint && 0 < mObjectCount && FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT == mFoclStructLayerType && null != mDistance && FoclConstants.MAX_DISTANCE_FROM_PREV_POINT < mDistance) { showDistanceExceededDialog(); return; // we do not need logcat here } if (null == mObjectPhotoFileAdapter || mObjectPhotoFileAdapter.getItemCount() == 0) { YesNoDialog dialog = new YesNoDialog(); dialog.setKeepInstance(true).setIcon(R.drawable.ic_action_warning).setTitle(R.string.warning) .setMessage(getString(R.string.take_photos_to_confirm)).setPositiveText(R.string.ok) .setOnPositiveClickedListener(new YesNoDialog.OnPositiveClickedListener() { @Override public void onPositiveClicked() { // cancel } }).show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "TakePhotos"); return; // we do not need logcat here } LayoutInflater inflater = LayoutInflater.from(getActivity()); View view = inflater.inflate(R.layout.dialog_waiting, null); final YesNoDialog waitProgressDialog = new YesNoDialog(); waitProgressDialog.setKeepInstance(true).setIcon(R.drawable.ic_action_data_usage).setTitle(R.string.waiting) .setView(view, true); waitProgressDialog.setCancelable(false); waitProgressDialog.show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_YES_NO_DIALOG + "WaitProgress"); final Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case CREATE_OBJECT_DONE: waitProgressDialog.dismiss(); break; case CREATE_OBJECT_OK: getActivity().getSupportFragmentManager().popBackStack(); break; case CREATE_OBJECT_FAILED: Toast.makeText(getActivity(), (String) msg.obj, Toast.LENGTH_LONG).show(); waitProgressDialog.dismiss(); break; } } }; RunnableFuture<Void> future = new FutureTask<Void>(new Callable<Void>() { @Override public Void call() throws Exception { createObjectTask(); return null; } }) { @Override protected void done() { super.done(); handler.sendEmptyMessage(CREATE_OBJECT_DONE); } @Override protected void set(Void aVoid) { super.set(aVoid); handler.sendEmptyMessage(CREATE_OBJECT_OK); } @Override protected void setException(Throwable t) { super.setException(t); Message msg = handler.obtainMessage(CREATE_OBJECT_FAILED, t.getLocalizedMessage()); msg.sendToTarget(); } }; new Thread(future).start(); }
From source file:com.koma.music.service.MusicService.java
private void handleHeadsetHookClick(long timestamp) { if (mHeadsetHookWakeLock == null) { PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); mHeadsetHookWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "KomaMusic headset button"); mHeadsetHookWakeLock.setReferenceCounted(false); }/*www .ja va2 s . co m*/ // Make sure we don't indefinitely hold the wake lock under any circumstances mHeadsetHookWakeLock.acquire(10000); Message msg = mPlayerHandler.obtainMessage(MusicServiceConstants.HEADSET_HOOK_EVENT, Long.valueOf(timestamp)); msg.sendToTarget(); }