Example usage for android.os Message setData

List of usage examples for android.os Message setData

Introduction

In this page you can find the example usage for android.os Message setData.

Prototype

public void setData(Bundle data) 

Source Link

Document

Sets a Bundle of arbitrary data values.

Usage

From source file:com.max2idea.android.limbo.main.LimboActivity.java

public static void sendHandlerMessage(Handler handler, int message_type, String[] message_var,
        String[] message_value) {
    Message msg1 = handler.obtainMessage();
    Bundle b = new Bundle();
    b.putInt("message_type", message_type);
    for (int i = 0; i < message_var.length; i++) {
        b.putString(message_var[i], message_value[i]);
    }//w  ww  .j a  v a 2 s.  com
    msg1.setData(b);
    handler.sendMessage(msg1);
}

From source file:com.nbplus.iotlib.IoTInterface.java

private void sendMessageToService(int what, Bundle b) {
    // Now that we have the service messenger, lets send our messenger
    Message msg = new Message();
    msg.what = what;/*  w  w w .  ja  v  a2 s . c  o m*/

    /*
     * In case we would want to send extra data, we could use Bundles:
     * Bundle b = new Bundle(); b.putString("key", "hello world");
     * msg.setData(b);
     */
    if (b == null) {
        b = new Bundle();

        IoTHandleData data = new IoTHandleData();
        b.putParcelable(IoTServiceCommand.KEY_DATA, data);
    }
    b.putString(IoTServiceCommand.KEY_MSGID, IoTServiceCommand.generateMessageId(mCtx));
    msg.setData(b);

    try {
        mServiceMessenger.send(msg);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.nbplus.iotlib.IoTInterface.java

public void getDevicesList(DeviceTypes type, final IoTServiceStatusNotification callback, boolean forceRescan) {
    if (!mInitialized) {
        InitializeRequiredException initException = new InitializeRequiredException(
                "Init required Exception!!");

        try {/* w w  w.  j  ava 2 s. c o  m*/
            throw initException;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }

    if (mServiceStatus.equals(IoTServiceStatus.NONE) && !mErrorCodes.equals(IoTResultCodes.SUCCESS)) {
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.onResult(IoTServiceCommand.GET_DEVICE_LIST, mServiceStatus, mErrorCodes, null);
            }
        }, 100);
    } else if (mServiceStatus.equals(IoTServiceStatus.RUNNING)) {
        //  ?? 
        if (forceRescan) {
            //   ?  ..
            Message msg = new Message();

            msg.what = IoTServiceCommand.GET_DEVICE_LIST;
            Bundle b = new Bundle();
            String msgId = IoTServiceCommand.generateMessageId(mCtx);
            b.putString(IoTServiceCommand.KEY_MSGID, msgId);
            b.putSerializable(IoTServiceCommand.KEY_DEVICE_TYPE, type);

            mForceRescanCallback = new WeakReference<>(callback);
            //mRequestedCallbaks.put(msgId, new WeakReference<>(callback));

            msg.setData(b);
            try {
                mServiceMessenger.send(msg);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        } else {
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Bundle b = new Bundle();
                    ArrayList<IoTDevice> devicesList = null;
                    if (mBondedWithServerList != null && mBondedWithServerList.size() > 0) {
                        devicesList = new ArrayList<>(mBondedWithServerList.values());
                    } else {
                        devicesList = new ArrayList<>();
                    }

                    b.putParcelableArrayList(IoTServiceCommand.KEY_DATA, devicesList);
                    callback.onResult(IoTServiceCommand.GET_DEVICE_LIST, mServiceStatus, mErrorCodes, b);
                }
            }, 100);
        }
    } else if (mServiceStatus.equals(IoTServiceStatus.INITIALIZE)) {
        // bound ?
        String msgId = IoTServiceCommand.generateMessageId(mCtx);
        mForceRescanCallback = new WeakReference<>(callback);
    } else {
        // stop ?.. ?? ? ? ?.
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                callback.onResult(IoTServiceCommand.GET_DEVICE_LIST, mServiceStatus, mErrorCodes, null);
            }
        }, 100);
    }
}

From source file:com.huofu.RestaurantOS.ui.splash.activate.java

@Override
protected void dealWithmessage(Message msg) {
    switch (msg.what) {
    case ERROR://from w  ww.j  a v  a2s  .c  o  m
        Bundle bd = (Bundle) msg.getData();
        CommonUtils.sendMsg(null, HIDE_LOADING, mUiHandler);
        showDialogError(bd.getString("reason"), 0);
        break;
    case AUTH_FAILED:
        stopQrScanTimer();
        buttonSwitchInputCode.performClick();
        CommonUtils.sendMsg(null, HIDE_LOADING, mUiHandler);
        showDialogError((String) msg.obj, 0);
        break;
    case AUTH_SUCCESS:
        CommonUtils.sendMsg(getString(R.string.readyToJumpToLogin), activate.SHOW_LOADING_TEXT, mUiHandler);
        mUiHandler.removeMessages(AUTH_SUCCESS);

        finishWithNextActivity(LoginActivity.class);
        break;
    case GET_QRCODE_SUCCESS://???
        qrcodeCreateTime = System.currentTimeMillis() / 1000;

        Bundle bdQrcode = (Bundle) msg.getData();

        tokenQrcode = bdQrcode.getString("token");
        String qrcode_url = bdQrcode.getString("qrcode_url");
        imageViewQrcode.setVisibility(View.VISIBLE);
        bitmapUtils.display(imageViewQrcode, qrcode_url, bigPicDisplayConfig, callback);
        break;
    case SCAN_QRCODE_SUCCESS://???
        flagAuthSuccess = true;
        //stopQrScanTimer();
        CommonUtils.sendMsg(null, AUTH_SUCCESS, mUiHandler);
        break;
    case GET_QRCODE://???
        CommonUtils.sendMsg(getString(R.string.loadingQrcode), SHOW_LOADING_TEXT, mUiHandler);
        ApisManager.GetAuthQrcode(new ApiCallback() {
            @Override
            public void success(Object object) {
                sendUIMessage(HIDE_LOADING, "");
                try {
                    JSONObject obj = (JSONObject) object;
                    String token = (String) obj.get("token");
                    String qrcode_url = (String) obj.get("qrcode_url");

                    Message msg = new Message();
                    msg.what = activate.GET_QRCODE_SUCCESS;
                    Bundle bd = new Bundle();
                    bd.putString("token", token);
                    bd.putString("qrcode_url", qrcode_url);
                    msg.setData(bd);
                    mUiHandler.sendMessage(msg);
                } catch (Exception e) {
                }

            }

            @Override
            public void error(BaseApi.ApiResponse response) {
                sendUIMessage(HIDE_LOADING, "");
                sendUIMessage(SHOW_ERROR_MESSAGE, response.error_message + "");
                CommonUtils.LogWuwei(tag, "GetAuthQrcode failed:" + response.error_message);
            }
        });

        break;
    case SHOW_LOADING_TEXT:
        String content = (String) msg.obj;
        showLoadingDialog(content);
        break;
    case HIDE_LOADING:
        hideLoadingDialog();
        break;
    case SHOW_ERROR_MESSAGE:
        String errMsg = (String) msg.obj;
        showDialogError(errMsg, 0);
        break;
    case UPDATE_QRCODE_SCAN_STATUS:
        textviewScanStauts.setText((String) msg.obj);
        break;
    case SHOW_QRCODE_REFRSH_AGAIN:
        dealQrcodeExpired();
        break;
    case STOP_SCAN_QRCODE_TIMER:
        stopQrScanTimer();
        break;

    }
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

public void openAd(String[] params) {
    if (params == null || params.length < 4) {
        errorCallback(0, 0, "error params!");
        return;//from  w ww . j a  va2 s.c om
    }
    Message msg = new Message();
    msg.obj = this;
    msg.what = MSG_OPEN_AD;
    Bundle bd = new Bundle();
    bd.putStringArray(TAG_BUNDLE_PARAM, params);
    msg.setData(bd);
    mHandler.sendMessage(msg);
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

public void open(String[] parm) {
    if (parm.length < 7) {
        return;//from  w w w  .  j  a  v  a  2  s .c  om
    }
    Message msg = new Message();
    msg.obj = this;
    msg.what = MSG_FUNCTION_OPEN;
    Bundle bd = new Bundle();
    bd.putStringArray(TAG_BUNDLE_PARAM, parm);
    msg.setData(bd);
    mHandler.sendMessage(msg);
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

public void toast(String[] parm) {
    if (parm.length < 4) {
        return;//from  w w w .  j  ava2 s .c  o m
    }
    Message msg = new Message();
    msg.obj = this;
    msg.what = MSG_FUNCTION_TOAST;
    Bundle bd = new Bundle();
    bd.putStringArray(TAG_BUNDLE_PARAM, parm);
    msg.setData(bd);
    mHandler.sendMessage(msg);
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

public void actionSheet(String[] params) {
    if (params == null || params.length < 3) {
        errorCallback(0, 0, "error params!");
        return;//  w w  w.  j  a  v  a  2  s  .  c om
    }
    Message msg = new Message();
    msg.obj = this;
    msg.what = MSG_ACTION_SHEET;
    Bundle bd = new Bundle();
    bd.putStringArray(TAG_BUNDLE_PARAM, params);
    msg.setData(bd);
    mHandler.sendMessage(msg);
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

public void windowBack(String[] parm) {
    Message msg = new Message();
    msg.obj = this;
    msg.what = MSG_FUNCTION_WINDOWBACK;/*from w w  w.j ava2  s .c o m*/
    Bundle bd = new Bundle();
    bd.putStringArray(TAG_BUNDLE_PARAM, parm);
    msg.setData(bd);
    mHandler.sendMessage(msg);
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExWindow.java

public void showSoftKeyboard(String[] params) {
    Message msg = new Message();
    msg.obj = this;
    msg.what = MSG_SHOW_SOFT_KEYBOARD;//from   w w w  .ja va2 s.  c  o  m
    Bundle bd = new Bundle();
    bd.putStringArray(TAG_BUNDLE_PARAM, params);
    msg.setData(bd);
    mHandler.sendMessage(msg);
}