List of usage examples for android.os Message Message
public Message()
From source file:net.networksaremadeofstring.cyllell.Search.java
public void PerformSearch(final Boolean Crafted) { try {/* ww w . ja v a 2 s. c om*/ threadCut = new Cuts(Search.this); dialog = new ProgressDialog(this); dialog.setTitle("Chef Search"); dialog.setMessage("Searching for: " + query + "\n\nPlease wait: Prepping Authentication protocols"); dialog.setIndeterminate(true); dialog.show(); Thread dataPreload = new Thread() { public void run() { try { JSONObject Nodes; handler.sendEmptyMessage(200); if (Crafted) { Nodes = threadCut.CraftedSearch(query, index); } else { Nodes = threadCut.Search(query, index); } handler.sendEmptyMessage(201); JSONArray rows = Nodes.getJSONArray("rows"); for (int i = 0; i < rows.length(); i++) { //Log.i("URI", ((JSONObject) rows.get(i)).getString("name")); listOfNodes.add(new Node(((JSONObject) rows.get(i)).getString("name"), "")); } handler.sendEmptyMessage(202); handler.sendEmptyMessage(0); } catch (Exception e) { Message msg = new Message(); Bundle data = new Bundle(); data.putString("exception", e.getMessage()); msg.setData(data); msg.what = 1; handler.sendMessage(msg); } return; } }; dataPreload.start(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.softminds.matrixcalculator.OperationFragments.DeterminantFragment.java
public void RunToGetDeterminant(final int pos, final ProgressDialog px) { Runnable runnable = new Runnable() { @Override/*from w w w . jav a 2 s. c om*/ public void run() { double var = SquareList.get(pos).getDeterminant(px); Message message = new Message(); Bundle bundle = new Bundle(); bundle.putDouble("RESULTANT", var); message.setData(bundle); px.dismiss(); myhandler.sendMessage(message); } }; Thread thread = new Thread(runnable); thread.start(); }
From source file:com.softminds.matrixcalculator.OperationFragments.InverseFragment.java
public void RunAndGetDeterminantWithAdjoint(final int i, final ProgressDialog progressDialog) { Runnable runnable = new Runnable() { @Override/*from ww w . ja v a 2 s .c o m*/ public void run() { Message message = new Message(); Bundle bundle = new Bundle(); float detr = (float) SquareList.get(i).getDeterminant(progressDialog); if (detr == 0.0f) { myHandler.postDelayed(new Runnable() { @Override public void run() { Toast.makeText(getContext(), R.string.NoInverse, Toast.LENGTH_SHORT).show(); } }, 0); progressDialog.dismiss(); } else { progressDialog.setProgress(0); bundle.putFloat("DETERMINANT", detr); MatrixV2 res = SquareList.get(i).getAdjoint(progressDialog); bundle.putAll(res.getDataBundled()); message.setData(bundle); myHandler.sendMessage(message); } } }; Thread thread = new Thread(runnable); thread.start(); }
From source file:com.nextgis.firereporter.HttpGetter.java
@Override protected void onPostExecute(Void unused) { super.onPostExecute(unused); DismissDowloadDialog();/* w ww. j a v a 2 s . c om*/ if (mError != null) { Bundle bundle = new Bundle(); bundle.putBoolean(GetFiresService.ERROR, true); bundle.putString(GetFiresService.ERR_MSG, mError); bundle.putInt(GetFiresService.SOURCE, mnType); Message msg = new Message(); msg.setData(bundle); if (mEventReceiver != null) { mEventReceiver.sendMessage(msg); } } else { //Toast.makeText(MainActivity.this, "Source: " + Content, Toast.LENGTH_LONG).show(); } }
From source file:com.nextgis.metroaccess.MetaDownloader.java
@Override protected void onPostExecute(Void unused) { super.onPostExecute(unused); DismissDowloadDialog();//from w w w. ja v a2 s. c o m if (msError != null) { if (moEventReceiver != null) { Bundle bundle = new Bundle(); bundle.putBoolean(BUNDLE_ERRORMARK_KEY, true); bundle.putString(BUNDLE_MSG_KEY, msError); bundle.putInt(BUNDLE_EVENTSRC_KEY, 1); Message oMsg = new Message(); oMsg.setData(bundle); moEventReceiver.sendMessage(oMsg); } } }
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitControlSet.java
public boolean activityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_TASK_RABBIT_ACTIVITY) { if (resultCode == Activity.RESULT_OK) { String result = data.getStringExtra(TaskRabbitOAuthLoginActivity.DATA_RESPONSE); if (!TextUtils.isEmpty(result)) { try { Message successMessage = new Message(); successMessage.what = 1; handler.sendMessageDelayed(successMessage, 500); return true; } catch (Exception e) { e.printStackTrace(); }//w ww . ja va 2s . c o m } } else { updateDisplay(null); } return true; } return false; }
From source file:com.firescar96.nom.GCMIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from w ww .j ava2 s. com*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) Log.i(Consts.TAG, "onHandleIntent: message error"); else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) Log.i(Consts.TAG, "onHandleIntent: message deleted"); // If it's a regular GCM message, do some work. else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // Post notification of received message. System.out.println("Received: " + extras.toString()); if (context == null) { System.out.println("null conxtext"); /*Intent needIntent = new Intent(this, MainActivity.class); needIntent.putExtra("purpose", "update"); needIntent.putExtra("mate", (String)extras.get("mate")); needIntent.putExtra("event", (String)extras.get("event")); needIntent.putExtra("chat", (String)extras.get("chat")); needIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(needIntent);*/ System.out.println(getFilesDir().getAbsolutePath()); MainActivity.initAppData(getFilesDir().getAbsolutePath()); } try { if (extras.get("mate") != null) { //context.appData.getJSONArray("mates").put(extras.get("mate")); } if (extras.get("event") != null) { JSONObject eveData = new JSONObject("{\"event\":" + extras.get("event") + "}") .getJSONObject("event"); JSONArray eve = MainActivity.appData.getJSONArray("events"); for (int i = 0; i < eve.length(); i++) { System.out.println(eveData.getString("hash")); System.out.println(eve.getJSONObject(i).getString("hash")); if (eveData.getString("hash").equals(eve.getJSONObject(i).getString("hash"))) return; } eveData.accumulate("member", false); System.out.println(eveData.getLong("date")); System.out.println(Calendar.getInstance().getTimeInMillis()); if (eveData.getLong("date") < Calendar.getInstance().getTimeInMillis()) return; eve.put(eveData); Message msg = new Message(); Bundle data = new Bundle(); data.putString("type", "event." + eveData.getString("privacy")); data.putString("host", eveData.getString("host")); data.putString("date", eveData.getString("date")); msg.setData(data); contextHandler.sendMessage(msg); } if (extras.get("chat") != null) { JSONObject chatData = new JSONObject("{\"chat\":" + extras.get("chat") + "}") .getJSONObject("chat"); JSONArray eve = MainActivity.appData.getJSONArray("events"); for (int i = 0; i < eve.length(); i++) if (chatData.getString("hash").equals(eve.getJSONObject(i).getString("hash"))) { JSONObject msgSon = new JSONObject(); msgSon.accumulate("author", chatData.getString("author")); msgSon.accumulate("message", chatData.getString("message")); eve.getJSONObject(i).getJSONArray("chat").put(msgSon); Message msg = new Message(); Bundle data = new Bundle(); data.putString("type", "chat"); data.putString("author", chatData.getString("author")); data.putString("message", chatData.getString("message")); data.putBoolean("member", eve.getJSONObject(i).getBoolean("member")); data.putString("hash", chatData.getString("hash")); msg.setData(data); contextHandler.sendMessage(msg); return; } } MainActivity.closeAppData(getFilesDir().getAbsolutePath()); } catch (JSONException e1) { e1.printStackTrace(); } } // Release the wake lock provided by the WakefulBroadcastReceiver. MainBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.example.manan.enhancedurdureader.EpubReader.BookView.java
@TargetApi(Build.VERSION_CODES.KITKAT) @Override/*from www . j a v a 2 s . c o m*/ public void onActivityCreated(Bundle saved) { super.onActivityCreated(saved); view = (WebView) getView().findViewById(R.id.Viewport); view.getSettings().setTextZoom(textSize); mScaleDetector = new ScaleGestureDetector(getActivity().getBaseContext(), new ScaleGestureDetector.OnScaleGestureListener() { @Override public void onScaleEnd(ScaleGestureDetector detector) { } @Override public boolean onScaleBegin(ScaleGestureDetector detector) { return true; } @Override public boolean onScale(ScaleGestureDetector detector) { //Log.w(LOG_KEY, "zoom ongoing, scale: " + detector.getScaleFactor()); return false; } }); // enable JavaScript for cool things to happen! view.getSettings().setJavaScriptEnabled(true); // ----- SWIPE PAGE view.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { /* if (state == ViewStateEnum.books) swipePage(v, event, 0); //int fontSize, newFont;*/ WebView view = (WebView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: x1 = event.getX(); break; case MotionEvent.ACTION_UP: if (mode != ZOOM && swipeFlag) { //if (state == ViewStateEnum.books) //swipePage(v, event, 0); } break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { mode = ZOOM; } break; case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { float scale = newDist / oldDist; if (scale > 1) { int currentTextSize = view.getSettings().getTextZoom(); textSize = currentTextSize + 15; view.getSettings().setTextZoom(textSize); mode = NONE; swipeFlag = false; } else { int currentTextSize = view.getSettings().getTextZoom(); textSize = currentTextSize - 15; view.getSettings().setTextZoom(textSize); mode = NONE; swipeFlag = false; } } } break; } return view.onTouchEvent(event); } }); // ----- NOTE & LINK view.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); String url = msg.getData().getString(getString(R.string.url)); if (url != null) navigator.setNote(url, index); } }); view.requestFocusNodeHref(msg); return false; } }); view.setWebViewClient(new WebViewClient() { public boolean shouldOverrideUrlLoading(WebView view, String url) { try { navigator.setBookPage(url, index); } catch (Exception e) { errorMessage(getString(R.string.error_LoadPage)); } return true; } }); loadPage(viewedPage); }
From source file:com.nbplus.iotapp.service.IoTService.java
public void handleMessage(Message msg) { if (msg == null) { return;/* w w w. j a v a2 s. c om*/ } Log.d(TAG, "handle message msg.what = " + msg.what); switch (msg.what) { // when using iot gateway case IoTServiceCommand.IOT_GATEWAY_CONNECTED: { Log.d(TAG, "IoTServiceCommand.IOT_GATEWAY_CONNECTED received..."); mIoTGatewayWorkerMessengerRef = new WeakReference<>(msg.replyTo); // TODO : test handler if (mIoTGatewayWorkerMessengerRef != null) { try { Messenger workerMessenger = mIoTGatewayWorkerMessengerRef.get(); if (workerMessenger != null) { Message testMsg = new Message(); msg.what = IoTServiceCommand.IOT_GATEWAY_DISCONNECTED; Log.d(TAG, "test IoTServiceCommand.IOT_GATEWAY_DISCONNECTED"); workerMessenger.send(testMsg); } } catch (Exception e) { e.printStackTrace(); } } break; } case IoTServiceCommand.SCANNING_START: { Bundle extras = msg.getData(); if (extras == null) { Log.w(TAG, "Scanning bundle data is not found !!!"); return; } boolean isPeriodic = extras.getBoolean(IoTServiceCommand.KEY_DATA); Log.d(TAG, "IoTServiceCommand.SCANNING_START called. periodic = " + isPeriodic); if (mUseIoTGateway) { } else { if (mBluetoothLeService != null && mServiceStatus == IoTServiceStatus.RUNNING) { mIsBleScanPeriodic = isPeriodic; mBluetoothLeService.scanLeDevicePeriodically(true, isPeriodic); } } break; } case IoTServiceCommand.SCANNING_STOP: { Bundle extras = msg.getData(); if (extras == null) { Log.w(TAG, "Scanning bundle data is not found !!!"); return; } //boolean isPeriodic = extras.getBoolean(IoTServiceCommand.KEY_DATA); Log.d(TAG, "IoTServiceCommand.SCANNING_STOP called."); if (mUseIoTGateway) { } else { if (mBluetoothLeService != null && mServiceStatus == IoTServiceStatus.RUNNING) { mIsBleScanPeriodic = false; mBluetoothLeService.scanLeDevicePeriodically(false, false); } } break; } case HANDLER_MESSAGE_CONNECTIVITY_CHANGED: final boolean isConnected = NetworkUtils.isConnected(this); Log.d(TAG, "HANDLER_MESSAGE_CONNECTIVITY_CHANGED received isConnected = " + isConnected); if (mLastConnectionStatus == isConnected) { Log.d(TAG, "mLastConnectionStatus == isConnected do not anything."); return; } mLastConnectionStatus = isConnected; if (mLastConnectionStatus) { Log.d(TAG, "HANDLER_MESSAGE_CONNECTIVITY_CHANGED network is connected !!!"); // TODO : re-connect if (mServiceStatus == IoTServiceStatus.STOPPED) { } } else { Log.d(TAG, "HANDLER_MESSAGE_CONNECTIVITY_CHANGED network is disconnected !!!"); } break; case HANDLER_MESSAGE_BT_STATE_CHANGED: Log.d(TAG, "HANDLER_MESSAGE_CONNECTIVITY_CHANGED received !!!"); final int state = msg.arg1; if ((mLastConnectionStatus && state == BluetoothAdapter.STATE_ON) || (!mLastConnectionStatus && state == BluetoothAdapter.STATE_OFF)) { return; } mLastConnectionStatus = (state == BluetoothAdapter.STATE_ON) ? true : false; if (mLastConnectionStatus) { Log.d(TAG, "HANDLER_MESSAGE_BT_STATE_CHANGED bluetooth is enabled !!!"); if (mServiceStatus != IoTServiceStatus.RUNNING) { final Intent gattServiceIntent = new Intent(this, BluetoothLeService.class); if (!bindService(gattServiceIntent, mBluetoothServiceConnection, BIND_AUTO_CREATE)) { Log.e(TAG, ">> bind BluetoothServiceConnection failed.... !!!"); } } } else { Log.d(TAG, "HANDLER_MESSAGE_BT_STATE_CHANGED bluetooth is disabled !!!"); mErrorCodes = IoTResultCodes.BLUETOOTH_NOT_ENABLED; unbindService(mBluetoothServiceConnection); mServiceStatus = IoTServiceStatus.STOPPED; mHandler.removeMessages(HANDLER_MESSAGE_CONNECTION_NOT_RESPOND); mConnectedDeviceList.clear(); mRequestHandleMap.clear(); sendServiceStatusNotification(); } break; case IoTServiceCommand.REGISTER_SERVICE: { Bundle b = msg.getData(); if (msg.replyTo == null || b == null) { Log.e(TAG, "Invalid register args..."); break; } String msgId = b.getString(IoTServiceCommand.KEY_MSGID, ""); if (!StringUtils.isEmptyString(msgId)) { Log.d(TAG, "msgId == " + msgId); String[] strArrays = msgId.split("_"); if (strArrays.length == 2) { mRegisteredAppMessenger = new WeakReference<>(msg.replyTo); sendResultToApplication(msg.replyTo, msgId, null, msg.what, IoTResultCodes.SUCCESS); // ?? ?? ? ? . sendServiceStatusNotification(); } else { Log.e(TAG, "Invalid register args..."); sendResultToApplication(msg.replyTo, msgId, null, msg.what, IoTResultCodes.INVALID_REQUEST_ARGUMENTS); break; } } else { Log.e(TAG, "Invalid register args..."); sendResultToApplication(msg.replyTo, "", null, msg.what, IoTResultCodes.INVALID_REQUEST_ARGUMENTS); break; } break; } case IoTServiceCommand.UNREGISTER_SERVICE: { Bundle b = msg.getData(); if (b == null) { Log.e(TAG, "Invalid register args..."); break; } String msgId = b.getString(IoTServiceCommand.KEY_MSGID, ""); if (!StringUtils.isEmptyString(msgId)) { String[] strArrays = msgId.split("_"); if (strArrays.length == 2) { Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); if (clientMessenger != null) { sendResultToApplication(clientMessenger, msgId, null, msg.what, IoTResultCodes.SUCCESS); mRegisteredAppMessenger = null; } else { //?? } } else { Log.e(TAG, "Invalid register args..."); break; } } else { Log.e(TAG, "Invalid un-register args..."); } break; } case IoTServiceCommand.GET_DEVICE_LIST: { if (mUseIoTGateway) { // TODO } else { mBluetoothLeService.scanLeDevice(false); mBluetoothLeService.scanLeDevicePeriodically(true, mIsBleScanPeriodic); } break; } case IoTServiceCommand.DEVICE_DISCONNECT_ALL: { Bundle b = msg.getData(); String msgId = b.getString(IoTServiceCommand.KEY_MSGID, ""); b.setClassLoader(IoTHandleData.class.getClassLoader()); IoTHandleData ioTHandleData = b.getParcelable(IoTServiceCommand.KEY_DATA); if (mConnectedDeviceList.size() > 0) { mIsDisconnectAllState = true; ioTHandleData.setMsgId(msgId); ioTHandleData.setRequestCommand(msg.what); String connectedDeviceId = mConnectedDeviceList.get(0); if (mUseIoTGateway) { // TODO } else { if (mBluetoothLeService != null) { mBluetoothLeService.disconnect(connectedDeviceId); } else { Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); } } } else { Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.SUCCESS); } break; } case IoTServiceCommand.DEVICE_CONNECT: { Bundle b = msg.getData(); b.setClassLoader(IoTHandleData.class.getClassLoader()); IoTHandleData ioTHandleData = b.getParcelable(IoTServiceCommand.KEY_DATA); String msgId = b.getString(IoTServiceCommand.KEY_MSGID, ""); Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); if (ioTHandleData == null) { sendResultToApplication(clientMessenger, msgId, null, msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case READ_WRITE_SETNOTI : ioTHandleData is null"); return; } if (mRequestHandleMap.get(ioTHandleData.getDeviceId()) != null) { Log.d(TAG, "Already previous command deviceid = " + ioTHandleData.getDeviceId() + ", command = " + ioTHandleData.getRequestCommand()); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); return; } if (mUseIoTGateway) { } else { if (mBluetoothLeService == null) { sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case IoTServiceCommand.DEVICE_CONNECT : mBluetoothLeService or ioTHandleData is null"); return; } if (ioTHandleData.getDeviceTypeId() != IoTDevice.DEVICE_TYPE_ID_BT) { sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case IoTServiceCommand.DEVICE_DISCONNECT : is not bt device... mUseIoTGateway == false"); return; } if (ioTHandleData.isKeepAliveDevice()) { if (mKeepAliveConnectionDeviceList.contains(ioTHandleData.getDeviceId())) { Log.d(TAG, "Keep alive device is already connected.. id = " + ioTHandleData.getDeviceId()); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.SUCCESS); // send to IoT interface module Message connectedMsg = new Message(); connectedMsg.what = IoTServiceCommand.DEVICE_CONNECTED; Bundle extras = new Bundle(); extras.putString(IoTServiceCommand.KEY_DEVICE_UUID, ioTHandleData.getDeviceId()); connectedMsg.setData(extras); sendNotificationToApplication(connectedMsg); return; } } if (mBluetoothLeService.connect(ioTHandleData.getDeviceId())) { ioTHandleData.setMsgId(msgId); ioTHandleData.setRequestCommand(msg.what); mRequestHandleMap.put(ioTHandleData.getDeviceId(), ioTHandleData); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.SUCCESS); // ?... connect ? . Message notRespondMsg = new Message(); notRespondMsg.what = HANDLER_MESSAGE_CONNECTION_NOT_RESPOND; Bundle extras = new Bundle(); extras.putParcelable(IoTServiceCommand.KEY_DATA, ioTHandleData); notRespondMsg.setData(extras); mHandler.sendMessageDelayed(notRespondMsg, CONNECTION_NOT_RESPOND_WAIT_TIME); } else { Log.w(TAG, "mBluetoothLeService.connect() return false"); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); } } break; } case HANDLER_MESSAGE_CONNECTION_NOT_RESPOND: { Log.d(TAG, "HANDLER_MESSAGE_CONNECTION_NOT_RESPOND ..."); Bundle b = msg.getData(); b.setClassLoader(IoTHandleData.class.getClassLoader()); IoTHandleData ioTHandleData = b.getParcelable(IoTServiceCommand.KEY_DATA); if (mBluetoothLeService != null) { mBluetoothLeService.disconnect(ioTHandleData.getDeviceId()); } mRequestHandleMap.remove(ioTHandleData.getDeviceId()); Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); sendResultToApplication(clientMessenger, ioTHandleData.getMsgId(), ioTHandleData.getDeviceId(), IoTServiceCommand.DEVICE_CONNECT, IoTResultCodes.DEVICE_CONNECTION_NOT_RESPOND); break; } case IoTServiceCommand.DEVICE_DISCONNECT: { Bundle b = msg.getData(); b.setClassLoader(IoTHandleData.class.getClassLoader()); IoTHandleData ioTHandleData = b.getParcelable(IoTServiceCommand.KEY_DATA); String msgId = b.getString(IoTServiceCommand.KEY_MSGID, ""); Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); if (ioTHandleData == null) { sendResultToApplication(clientMessenger, msgId, null, msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case READ_WRITE_SETNOTI : ioTHandleData is null"); return; } if (mRequestHandleMap.get(ioTHandleData.getDeviceId()) != null) { Log.d(TAG, "Already previous command deviceid = " + ioTHandleData.getDeviceId() + ", command = " + ioTHandleData.getRequestCommand()); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); return; } if (mUseIoTGateway) { } else { if (mBluetoothLeService == null) { sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case IoTServiceCommand.DEVICE_DISCONNECT : mBluetoothLeService or ioTHandleData is null"); return; } if (ioTHandleData.getDeviceTypeId() != IoTDevice.DEVICE_TYPE_ID_BT) { sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case IoTServiceCommand.DEVICE_DISCONNECT : is not bt device... mUseIoTGateway == false"); return; } if (mConnectedDeviceList.contains(ioTHandleData.getDeviceId()) || mKeepAliveConnectionDeviceList.contains(ioTHandleData.getDeviceId())) { ioTHandleData.setMsgId(msgId); ioTHandleData.setRequestCommand(msg.what); mRequestHandleMap.put(ioTHandleData.getDeviceId(), ioTHandleData); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.SUCCESS); mBluetoothLeService.disconnect(ioTHandleData.getDeviceId()); } else { Log.w(TAG, "mConnectedDeviceList.contains(ioTHandleData.getDeviceId()) is false"); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); } } break; } case IoTServiceCommand.DEVICE_READ_DATA: case IoTServiceCommand.DEVICE_WRITE_DATA: case IoTServiceCommand.DEVICE_SET_NOTIFICATION: { Bundle b = msg.getData(); b.setClassLoader(IoTHandleData.class.getClassLoader()); IoTHandleData ioTHandleData = b.getParcelable(IoTServiceCommand.KEY_DATA); String msgId = b.getString(IoTServiceCommand.KEY_MSGID, ""); Messenger clientMessenger = (mRegisteredAppMessenger == null) ? null : mRegisteredAppMessenger.get(); if (ioTHandleData == null) { sendResultToApplication(clientMessenger, msgId, null, msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case READ_WRITE_SETNOTI : ioTHandleData is null"); return; } if (mRequestHandleMap.get(ioTHandleData.getDeviceId()) != null) { Log.d(TAG, "Already previous command deviceid = " + ioTHandleData.getDeviceId() + ", command = " + ioTHandleData.getRequestCommand()); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); return; } if (mUseIoTGateway) { } else { if (mBluetoothLeService == null) { sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case READ_WRITE_SETNOTI : ioTHandleData is null"); return; } if (ioTHandleData.getDeviceTypeId() != IoTDevice.DEVICE_TYPE_ID_BT) { sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); Log.w(TAG, "case READ_WRITE_SETNOTI : is not bt device... mUseIoTGateway == false"); return; } if (mConnectedDeviceList.contains(ioTHandleData.getDeviceId()) || mKeepAliveConnectionDeviceList.contains(ioTHandleData.getDeviceId())) { ioTHandleData.setMsgId(msgId); ioTHandleData.setRequestCommand(msg.what); boolean result = true; switch (msg.what) { case IoTServiceCommand.DEVICE_READ_DATA: result = mBluetoothLeService.readCharacteristic(ioTHandleData.getDeviceId(), ioTHandleData.getServiceUuid(), ioTHandleData.getCharacteristicUuid()); break; case IoTServiceCommand.DEVICE_WRITE_DATA: result = mBluetoothLeService.writeRemoteCharacteristic(ioTHandleData.getDeviceId(), ioTHandleData.getServiceUuid(), ioTHandleData.getCharacteristicUuid(), ioTHandleData.getValue()); break; case IoTServiceCommand.DEVICE_SET_NOTIFICATION: result = mBluetoothLeService.setCharacteristicNotification(ioTHandleData.getDeviceId(), ioTHandleData.getServiceUuid(), ioTHandleData.getCharacteristicUuid(), true); break; } if (result) { mRequestHandleMap.put(ioTHandleData.getDeviceId(), ioTHandleData); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.SUCCESS); } else { sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); } } else { Log.w(TAG, "mConnectedDeviceList.contains(ioTHandleData.getDeviceId()) is false"); sendResultToApplication(clientMessenger, msgId, ioTHandleData.getDeviceId(), msg.what, IoTResultCodes.FAILED); } } break; } } }
From source file:com.studio.arm.wink.FaceTrackerActivity.java
/** * Initializes the UI and initiates the creation of a face detector. *///from w w w. jav a 2 s. c o m @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); //VK if (VKAccessToken.currentToken() == null || VKAccessToken.currentToken().accessToken == null) { VKSdk.login(this, sMyScope); } //new ProgressTask().execute(); setContentView(R.layout.main); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay); eye = (ImageView) findViewById(R.id.imageEye); eye.setBackgroundResource(R.drawable.eyeanim); mAnimationDrawable = (AnimationDrawable) eye.getBackground(); settings = (ImageButton) findViewById(R.id.imageSetting); settings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(FaceTrackerActivity.this, Setting.class); startActivity(intent); overridePendingTransition(R.animator.push_down_in, R.animator.push_down_out); } }); rotateCamera = (ImageButton) findViewById(R.id.imageRotateCamera); rotateCamera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub //mCameraSource.release(); flag = !flag; if (mCameraSource != null) mCameraSource.release(); createCameraSource(flag ? CameraSource.CAMERA_FACING_BACK : CameraSource.CAMERA_FACING_FRONT); startCameraSource(); Message msg = new Message(); msg.obj = FACE_NONE; handler.sendMessage(msg); } }); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(CameraSource.CAMERA_FACING_FRONT); startCameraSource(); } else { requestCameraPermission(); } int rmw = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (rmw != PackageManager.PERMISSION_GRANTED) { requestMemoryWritePermission(); } int rmr = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE); if (rmr != PackageManager.PERMISSION_GRANTED) { requestMemoryWritePermission(); } handler = new Handler() { @Override public void handleMessage(Message msg) { String text = (String) msg.obj; try { if (text.equals(FACE_DETECT)) { eye.setBackgroundResource(R.drawable.eyeanim); mAnimationDrawable = (AnimationDrawable) eye.getBackground(); mAnimationDrawable.start(); } if (text.equals(FACE_NONE)) { mAnimationDrawable.stop(); eye.setBackgroundResource(R.drawable.eye3); } } catch (NullPointerException e) { } } }; sharedPref = getSharedPreferences(PREF_FILE_NAME, MODE_PRIVATE); }