Java Code Examples for android.os.Message#obtain()

The following examples show how to use android.os.Message#obtain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CaptureActivityHandler.java    From ZXingProject with MIT License 6 votes vote down vote up
public void quitSynchronously() {
	state = State.DONE;
	cameraManager.stopPreview();
	Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
	quit.sendToTarget();
	try {
		// Wait at most half a second; should be enough time, and onPause()
		// will timeout quickly
		decodeThread.join(500L);
	} catch (InterruptedException e) {
		// continue
	}

	// Be absolutely sure we don't send any queued up messages
	removeMessages(R.id.decode_succeeded);
	removeMessages(R.id.decode_failed);
}
 
Example 2
Source File: CarlifeUtil.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
public static void sendStatisticsInfo(int connect_time) {
    CarlifeCmdMessage command = new CarlifeCmdMessage(true);
    command.setServiceType(CommonParams.MSG_CMD_STATISTIC_INFO);
    CarlifeStatisticsInfo.Builder builder = CarlifeStatisticsInfo.newBuilder();
    builder.setCuid(CarlifeUtil.getInstance().getCuid());
    builder.setVersionName(CarlifeUtil.getInstance().getVersionName());
    builder.setVersionCode(CarlifeUtil.getInstance().getVersionCode());
    builder.setChannel(CarlifeUtil.getInstance().getChannel());
    builder.setConnectCount(PreferenceUtil.getInstance().getInt(CommonParams.CARLIFE_CONNECT_COUNT, 1));
    builder.setConnectSuccessCount(1);
    builder.setConnectTime(connect_time);
    String crashLog = CrashHandler.getInstance().readCrashInfoFromDir();
    if (crashLog != null) {
        LogUtil.d(TAG, crashLog);
        builder.setCrashLog(crashLog);
    }
    CarlifeStatisticsInfo statisInfo = builder.build();
    command.setData(statisInfo.toByteArray());
    command.setLength(statisInfo.getSerializedSize());
    Message msgTmp =
            Message.obtain(null, command.getServiceType(), CommonParams.MSG_CMD_PROTOCOL_VERSION, 0, command);
    ConnectClient.getInstance().sendMsgToService(msgTmp);
    PreferenceUtil.getInstance().putInt(CommonParams.CARLIFE_CONNECT_COUNT, 0);
}
 
Example 3
Source File: MLAlertController.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
public void onClick(View v) {
    Message m = null;
    if (v == mButtonPositive && mButtonPositiveMessage != null) {
        m = Message.obtain(mButtonPositiveMessage);
    } else if (v == mButtonNegative && mButtonNegativeMessage != null) {
        m = Message.obtain(mButtonNegativeMessage);
    } else if (v == mButtonNeutral && mButtonNeutralMessage != null) {
        m = Message.obtain(mButtonNeutralMessage);
    }
    if (m != null) {
        m.sendToTarget();
    }

    if (mAutoDismiss) {
        // Post a message so we dismiss after the above handlers are
        // executed
        mHandler.obtainMessage(ButtonHandler.MSG_DISMISS_DIALOG, mDialogInterface)
                .sendToTarget();
    }
}
 
Example 4
Source File: NumberPickerView.java    From SmartChart with Apache License 2.0 5 votes vote down vote up
private Message getMsg(int what, int arg1, int arg2, Object obj){
    Message msg = Message.obtain();
    msg.what = what;
    msg.arg1 = arg1;
    msg.arg2 = arg2;
    msg.obj = obj;
    return msg;
}
 
Example 5
Source File: AMapLocationClient.java    From letv with Apache License 2.0 5 votes vote down vote up
public void startLocation() {
    try {
        Message obtain = Message.obtain();
        obtain.arg1 = 3;
        this.a.sendMessage(obtain);
    } catch (Throwable th) {
        th.printStackTrace();
    }
}
 
Example 6
Source File: MarshallingTransformationListener.java    From LiTr with BSD 2-Clause "Simplified" License 5 votes vote down vote up
void onCompleted(@NonNull String jobId,
                 @NonNull final List<TrackTransformationInfo> trackTransformationInfos) {
    futureMap.remove(jobId);

    if (handler == null) {
        listener.onCompleted(jobId, trackTransformationInfos);
    } else {
        Message msg = Message.obtain(handler, EVENT_COMPLETED);
        msg.obj = trackTransformationInfos;
        data.putString(KEY_JOB_ID, jobId);
        msg.setData(data);
        msg.sendToTarget();
    }
}
 
Example 7
Source File: SdlRouterService.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings("unused")
private void pingClients(){
	Message message = Message.obtain();
	Log.d(TAG, "Pinging "+ registeredApps.size()+ " clients");
	int result;
	synchronized(REGISTERED_APPS_LOCK){
		Collection<RegisteredApp> apps = registeredApps.values();
		Iterator<RegisteredApp> it = apps.iterator();
		while(it.hasNext()){
			RegisteredApp app = it.next();
			result = app.sendMessage(message);
			if(result == RegisteredApp.SEND_MESSAGE_ERROR_MESSENGER_DEAD_OBJECT){
				app.close();
				Vector<Long> sessions = app.getSessionIds();
				for(Long session:sessions){
					if(session !=null && session != -1){
						List<TransportType> transportTypes = app.getTransportsForSession(session.intValue());
						if(transportTypes != null && transportTypes.size() > 0){
							attemptToCleanUpModule(session.intValue(), cachedModuleVersion, transportTypes.get(0) );
						}
					}
				}
				it.remove();
			}
		}
	}
}
 
Example 8
Source File: ChatDialogUtils.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onMessage(WebSocket webSocket, String text) {
    Log.i("KCV", text);
    ChatMsgObject chatMsgObject = gson.fromJson(text, ChatMsgObject.class);
    if(chatMsgObject != null) {
        Message message = Message.obtain();
        message.obj = chatMsgObject;
        mWebSocketHandler.sendMessage(message);
    }
}
 
Example 9
Source File: ClementineService.java    From Android-Remote with GNU General Public License v3.0 5 votes vote down vote up
private void sendConnectMessageIfPossible(Intent intent) {
    if (intent.hasExtra(EXTRA_STRING_IP)) {
        final String ip = intent.getStringExtra(EXTRA_STRING_IP);
        final int port = intent.getIntExtra(EXTRA_INT_PORT, 0);
        final int auth = intent.getIntExtra(EXTRA_INT_AUTH, 0);

        Message msg = Message.obtain();
        msg.obj = ClementineMessageFactory
                .buildConnectMessage(ip, port, auth, true, false);
        App.ClementineConnection.mHandler.sendMessage(msg);
    }
}
 
Example 10
Source File: SynchronizationService.java    From AsteroidOSSync with GNU General Public License v3.0 5 votes vote down vote up
void handleSetDevice(String macAddress) {
    SharedPreferences.Editor editor = mPrefs.edit();
    editor.putString(MainActivity.PREFS_DEFAULT_MAC_ADDR, macAddress);

    if(macAddress.isEmpty()) {
        if(mState != STATUS_DISCONNECTED) {
            mScreenshotService.unsync();
            mWeatherService.unsync();
            mNotificationService.unsync();
            mMediaService.unsync();
            mTimeService.unsync();
            mDevice.disconnect();
            mDevice.unbond();
        }
        mDevice = null;
        editor.putString(MainActivity.PREFS_DEFAULT_LOC_NAME, "");
    } else {
        mDevice = mBleMngr.getDevice(macAddress);

        String name = mDevice.getName_normalized();
        try {
            Message answer = Message.obtain(null, MSG_SET_LOCAL_NAME);
            answer.obj = name;
            replyTo.send(answer);

            replyTo.send(Message.obtain(null, MSG_SET_STATUS, mState, 0));
        } catch (RemoteException | NullPointerException ignored) {}

        editor.putString(MainActivity.PREFS_DEFAULT_LOC_NAME, name);
    }
    editor.apply();
}
 
Example 11
Source File: CaptureActivityHandler.java    From QrModule with Apache License 2.0 5 votes vote down vote up
public void quitSynchronously() {
    state = State.DONE;
    CameraManager.get().stopPreview();
    Message quit = Message.obtain(decodeThread.getHandler(), Cons.ID_QUIT);
    quit.sendToTarget();
    try {
        decodeThread.join();
    } catch (InterruptedException e) {
        // continue
    }

    // Be absolutely sure we don't send any queued up messages
    removeMessages(Cons.ID_DECODE_SUCCEED);
    removeMessages(Cons.ID_DECODE_FAILED);
}
 
Example 12
Source File: ServiceAgent.java    From nfcspy with GNU General Public License v3.0 5 votes vote down vote up
private void sendBinary2Activity(int type, int arg, byte[] raw) {
	try {
		Message msg = Message.obtain(null, type, raw.length, arg);
		ServiceFactory.setDataToMessage(msg, raw);
		outbox.send(msg);
	} catch (Exception e) {
	}
}
 
Example 13
Source File: MediaBrowserCompat.java    From letv with Apache License 2.0 5 votes vote down vote up
private void sendRequest(int what, Bundle data, Messenger cbMessenger) throws RemoteException {
    Message msg = Message.obtain();
    msg.what = what;
    msg.arg1 = 1;
    msg.setData(data);
    msg.replyTo = cbMessenger;
    this.mMessenger.send(msg);
}
 
Example 14
Source File: MessageFactory.java    From JIMU with Apache License 2.0 5 votes vote down vote up
public static <T extends RemoteEventBean> Message obtainEventMsg(@NonNull T event) {
    Message message = Message.obtain();// new Message();
    message.what = WHAT_SEND_CROSS_PROCESS_EVENT;
    Bundle bundle = new Bundle();
    bundle.putString(BUNDLE_STR_EVENT_CLZ, event.getClass().getName());
    bundle.putParcelable(BUNDLE_PARCEL_EVENT, event);
    message.setData(bundle);
    return message;
}
 
Example 15
Source File: CBIActivityTerminal.java    From CarBusInterface with MIT License 5 votes vote down vote up
public void onServiceConnected(final ComponentName className, final IBinder service) {
    if (D) Log.d(TAG, "mServiceMainConnection : onServiceConnected()");

    mServiceMainMessenger = new Messenger(service);

    try {
        Message message = Message.obtain(null, CBIServiceMain.BOUND_MSG_REGISTER_CLIENT);
        message.replyTo = mServiceMainIncomingMessenger;
        mServiceMainMessenger.send(message);
    } catch (RemoteException e) {
        serviceMainLostBinding();
    }
}
 
Example 16
Source File: CaptureActivityHandler.java    From KSYMediaPlayer_Android with Apache License 2.0 5 votes vote down vote up
public void quitSynchronously() {
	state = State.DONE;
	CameraManager.get().stopPreview();
	Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
	quit.sendToTarget();
	try {
		decodeThread.join();
	} catch (InterruptedException e) {
		// continue
	}

	// Be absolutely sure we don't send any queued up messages
	removeMessages(R.id.decode_succeeded);
	removeMessages(R.id.decode_failed);
}
 
Example 17
Source File: VClientImpl.java    From container with GNU General Public License v3.0 4 votes vote down vote up
private void sendMessage(int what, Object obj) {
    Message msg = Message.obtain();
    msg.what = what;
    msg.obj = obj;
    mH.sendMessage(msg);
}
 
Example 18
Source File: MainActivity.java    From Android-Remote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        int currentVolume = App.Clementine.getVolume();
        // Control the volume of clementine if enabled in the options
        if (mSharedPref.getBoolean(SharedPreferencesKeys.SP_KEY_USE_VOLUMEKEYS, true)) {
            int volumeInc = Integer.parseInt(
                    mSharedPref.getString(SharedPreferencesKeys.SP_VOLUME_INC,
                            Clementine.DefaultVolumeInc));
            switch (keyCode) {
                case KeyEvent.KEYCODE_VOLUME_DOWN:
                    Message msgDown = Message.obtain();
                    msgDown.obj = ClementineMessageFactory
                            .buildVolumeMessage(App.Clementine.getVolume() - volumeInc);
                    App.ClementineConnection.mHandler.sendMessage(msgDown);
                    if (currentVolume >= volumeInc) {
                        currentVolume -= volumeInc;
                    } else {
                        currentVolume = 0;
                    }
                    makeToast(getString(R.string.playler_volume) + " " + currentVolume + "%",
                            Toast.LENGTH_SHORT);
                    return true;
                case KeyEvent.KEYCODE_VOLUME_UP:
                    Message msgUp = Message.obtain();
                    msgUp.obj = ClementineMessageFactory
                            .buildVolumeMessage(App.Clementine.getVolume() + volumeInc);
                    App.ClementineConnection.mHandler.sendMessage(msgUp);
                    if ((currentVolume + volumeInc) >= 100) {
                        currentVolume = 100;
                    } else {
                        currentVolume += volumeInc;
                    }
                    makeToast(getString(R.string.playler_volume) + " " + currentVolume + "%",
                            Toast.LENGTH_SHORT);
                    return true;
                default:
                    break;
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}
 
Example 19
Source File: AnalyticsMessages.java    From sa-sdk-android with Apache License 2.0 4 votes vote down vote up
void deleteAll() {
    final Message m = Message.obtain();
    m.what = DELETE_ALL;

    mWorker.runMessage(m);
}
 
Example 20
Source File: LastfmClient.java    From scroball with MIT License 4 votes vote down vote up
@Override
protected void onPostExecute(AuthResult authResult) {
  Message message = Message.obtain();
  message.obj = authResult;
  callback.handleMessage(message);
}