Example usage for android.os Message Message

List of usage examples for android.os Message Message

Introduction

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

Prototype

public Message() 

Source Link

Document

Constructor (but the preferred way to get a Message is to call #obtain() Message.obtain() ).

Usage

From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java

/**
 * //from  www.j  a  v  a2 s  .  c  om
 */
private void startRecording() {
    mFileName = newFileName();
    //
    try {
        mRecorder = new MediaRecorder();
        //?
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        //???
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
        mRecorder.setAudioSamplingRate(8000);
        mRecorder.setAudioEncodingBitRate(16);
        //??
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        mRecorder.setOutputFile(mFileName);
        mRecorder.prepare();
        mRecorder.start();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (IllegalStateException e2) {
        e2.printStackTrace();
    }

    mTimer = new Timer();
    TimerTask timerTask = new TimerTask() {
        @Override
        public void run() {
            // TODO Auto-generated method stub
            mMaxTime--;
            Message msg = new Message();
            msg.what = mMaxTime;
            handler.sendMessage(msg);
        }
    };
    mTimer.schedule(timerTask, 1000, 1000);
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void addShoppingCart(final String goodsid, final String goodsnum, final String shopid,
        final String proid) {
    new Thread() {
        Message msg = new Message();

        @Override/*from www  .  ja  v  a2s  .  c o m*/
        public void run() {
            String data = "&userid=" + user.getUserId() + "&goodsid=" + goodsid + "&goodsnum=" + goodsnum
                    + "&shopid=" + shopid + "&proid=" + proid;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.ADD_SHOPPING_CART, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.ADD_SHOPPING_CART;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void GetShoppingCart() {
    new Thread() {
        Message msg = new Message();

        @Override// w  ww .j  a v  a  2s  . c  o m
        public void run() {
            String data = "&userid=" + user.getUserId();
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.GET_SHOPPPING_CART, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.GET_SHOPPING_CART;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:com.filterdevice.ProfileScanningFragment.java

public void sendMessage(int what) {
    Message message = new Message();
    message.what = what;
    handler.sendMessage(message);
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void EditShoppingCart(final String goodsid, final String goodsnum) {
    new Thread() {
        Message msg = new Message();

        @Override//from   w  ww.j  av a 2 s. c o  m
        public void run() {
            String data = "&userid=" + user.getUserId() + "&goodsid=" + goodsid + "&goodsnum=" + goodsnum;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.Edit_Shopping_Cart, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.EDIT_SHOPPING_CART;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void DeleteShoppingCart(final String goodsid) {
    new Thread() {
        Message msg = new Message();

        @Override//from ww w  . j a va2s  . co m
        public void run() {
            String data = "&userid=" + user.getUserId() + "&goodsid=" + goodsid;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.Delete_Shopping_Cart, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.DELETE_SHOPPING_CART;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}

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

private void handleResponse(Bundle b) {
    int cmd = b.getInt(IoTServiceCommand.KEY_CMD, -1);
    switch (cmd) {
    case IoTServiceCommand.DEVICE_DISCONNECT_ALL: {
        Log.d(TAG, "DEVICE_DISCONNECT_ALL received.. Start retrieve... ");

        if (mIsEmergencyDataCollecting) {
            sendConnectToEmergencyDevice();
        } else {/*from www.  jav  a2 s.com*/
            mCurrentRetrieveIndex = 0;

            if (mServiceStatus == IoTServiceStatus.RUNNING) {
                sendConnectToDeviceMessage(mCurrentRetrieveIndex);
            } else {
                Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED);
                LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent);
            }
        }
        break;
    }
    case IoTServiceCommand.REGISTER_SERVICE: {
        b.setClassLoader(IoTResultCodes.class.getClassLoader());
        IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT);
        if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) {
            // success
            Log.d(TAG, ">> IoT Register service success...");
            if (mBondedWithServerList.size() > 0
                    && (mBondedEmergencyDeviceNumbers > 0 || mBondedKeepaliveDeviceNumbers > 0)) {
                Bundle extras = new Bundle();
                extras.putBoolean(IoTServiceCommand.KEY_DATA, true);
                sendMessageToService(IoTServiceCommand.SCANNING_START, extras);
            } else {
                Bundle extras = new Bundle();
                extras.putBoolean(IoTServiceCommand.KEY_DATA, false);
                sendMessageToService(IoTServiceCommand.SCANNING_STOP, extras);
            }
        } else {
            Log.w(TAG, ">> IoT Register service failed code = " + resultCode);
            mErrorCodes = resultCode;
        }
        break;
    }
    case IoTServiceCommand.UNREGISTER_SERVICE: {
        b.setClassLoader(IoTResultCodes.class.getClassLoader());
        IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT);
        if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) {
            // success
            Log.d(TAG, ">> IoT Register service success...");
        } else {
            Log.w(TAG, ">> IoT Register service failed code = " + resultCode);
        }
        break;
    }

    case IoTServiceCommand.DEVICE_CONNECT: {
        b.setClassLoader(IoTResultCodes.class.getClassLoader());
        IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT);
        if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) {
            // success
            Log.d(TAG, ">> IoT DEVICE_CONNECT success...");
        } else {
            Log.w(TAG, ">> IoT DEVICE_CONNECT failed code = " + resultCode);
            String deviceId = b.getString(IoTServiceCommand.KEY_DEVICE_UUID);
            if (deviceId != null && mKeepAliveDeviceList.containsKey(deviceId)) {
                Log.d(TAG, "Keep alive device connection failed.");
                mKeepAliveDeviceList.remove(deviceId);
                return;
            }

            if (IoTResultCodes.DEVICE_CONNECTION_NOT_RESPOND.equals(resultCode)
                    && mConnectionRetryCount < MAX_CONNECTION_RETRY) {
                if (mServiceStatus != IoTServiceStatus.RUNNING) {
                    mCurrentRetrieveIndex = -1;
                    mCurrentRetrieveDevice = null;

                    if (mIsEmergencyDataCollecting) {
                        mEmergencyDeviceList.clear();
                        mIsEmergencyDataCollecting = false;

                        if (mIsWaitingForceDataSync) {
                            mIsWaitingForceDataSync = false;
                            Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED);
                            LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent);
                        }
                    } else {
                        Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED);
                        LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent);
                    }
                    break;
                }
                Log.d(TAG, "mConnectionRetryCount = " + mConnectionRetryCount);
                mConnectionRetryCount++;
                Bundle extras = new Bundle();
                IoTHandleData data = new IoTHandleData();
                data.setDeviceId(mCurrentRetrieveDevice.getDeviceId());
                data.setDeviceTypeId(mCurrentRetrieveDevice.getDeviceTypeId());

                extras.putParcelable(IoTServiceCommand.KEY_DATA, data);
                sendMessageToService(IoTServiceCommand.DEVICE_CONNECT, extras);
                break;
            }
            if (mIsEmergencyDataCollecting) {
                sendConnectToEmergencyDevice();
            } else {
                if (mCurrentRetrieveIndex + 1 < mBondedWithServerList.size()) {
                    mCurrentRetrieveIndex++;
                    sendConnectToDeviceMessage(mCurrentRetrieveIndex);
                } else {
                    Log.d(TAG, "Retrieving all devices.. completed");
                    mCurrentRetrieveIndex = -1;
                    mCurrentRetrieveDevice = null;

                    mHandler.removeMessages(HANDLER_RETRIEVE_IOT_DEVICES);
                    mHandler.sendEmptyMessageDelayed(HANDLER_RETRIEVE_IOT_DEVICES,
                            RETRIEVE_IOT_DEVICE_DATA_PERIOD);
                    sendCollectedDataToServer();
                }
            }
        }
        break;
    }

    case IoTServiceCommand.DEVICE_DISCONNECT: {
        b.setClassLoader(IoTResultCodes.class.getClassLoader());
        IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT);
        if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) {
            // success
            Log.d(TAG, ">> IoT DEVICE_DISCONNECT success...");
        } else {
            Log.w(TAG, ">> IoT DEVICE_DISCONNECT failed code = " + resultCode);
            if (mIsEmergencyDataCollecting) {
                sendConnectToEmergencyDevice();
            } else {
                if (mCurrentRetrieveIndex + 1 < mBondedWithServerList.size()) {
                    mCurrentRetrieveIndex++;
                    sendConnectToDeviceMessage(mCurrentRetrieveIndex);
                } else {
                    mCurrentRetrieveIndex = -1;
                    mCurrentRetrieveDevice = null;

                    mHandler.removeMessages(HANDLER_RETRIEVE_IOT_DEVICES);
                    mHandler.sendEmptyMessageDelayed(HANDLER_RETRIEVE_IOT_DEVICES,
                            RETRIEVE_IOT_DEVICE_DATA_PERIOD);
                    sendCollectedDataToServer();
                }
            }
        }
        break;
    }

    case IoTServiceCommand.DEVICE_READ_DATA:
    case IoTServiceCommand.DEVICE_WRITE_DATA:
    case IoTServiceCommand.DEVICE_SET_NOTIFICATION: {
        b.setClassLoader(IoTResultCodes.class.getClassLoader());
        IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT);
        if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) {
            // success
            Log.d(TAG, ">> IoT READ_WRITE_SET_NOTIFICATION success...");
        } else {
            Log.e(TAG, ">> IoT READ_WRITE_SET_NOTIFICATION failed code = " + resultCode);
            mHandler.removeMessages(HANDLER_WAIT_FOR_NOTIFY_DATA);
            Message disconnMsg = new Message();
            disconnMsg.what = HANDLER_WAIT_FOR_NOTIFY_DATA;
            disconnMsg.arg1 = 1;
            mHandler.sendMessage(disconnMsg);
        }
        break;
    }
    default:
        Log.d(TAG, "unknown command..");
        break;
    }
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void getSellerOrderList(final String shopId, final String state) {

    new Thread() {
        Message msg = new Message();

        @Override/*from  w ww  .  ja v  a  2  s . c o  m*/
        public void run() {
            String data = "&shopid=" + shopId + state;
            String result_data = NetUtil.getResponse(WebAddress.GET_SELLER_ORDER_LIST, data);
            Log.e("result_data=", result_data);
            Log.e(".shopis is", shopId);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.GET_SELLER_ORDER_LIST;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }

        }
    }.start();
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossEventsListFragment.java

public void DBGetThread() {
    //Log.e("DBGetThread", "Doing a DB lookup");

    if ((PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("URL", "").equals("")
            || PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("userName", "").equals("")
            || PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("passWord", "")
                    .equals(""))) {
        //Log.e("DBGetThread", "Well we can't do this because we don't have any credentials ");
        return;/*  w w w.j ava 2  s . c  o m*/
    }

    if (null != refreshStatus) {
        refreshStatus.setActionView(abprogress);
    } else {
        //Log.e("DBGetThread", "refreshStatus was null!");
    }

    listOfZenossEvents.clear();
    new Thread() {
        public void run() {
            Message msg = new Message();
            Bundle bndle = new Bundle();

            List<ZenossEvent> tempZenossEvents = null;

            try {
                RhybuddDataSource datasource = new RhybuddDataSource(getActivity());
                datasource.open();
                tempZenossEvents = datasource.GetRhybuddEvents();
                datasource.close();
            } catch (Exception e) {
                BugSenseHandler.sendExceptionMessage("ViewZenossEventsListFragment", "DBGetThread", e);
                e.printStackTrace();
                if (tempZenossEvents != null)
                    tempZenossEvents.clear();
            }

            if (tempZenossEvents != null && tempZenossEvents.size() > 0) {
                try {
                    listOfZenossEvents = tempZenossEvents;

                    eventsListHandler.sendEmptyMessage(EVENTSLISTHANDLER_SUCCESS);
                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("RhybuddHome", "DBGetThread", e);
                    bndle.putString("exception", e.getMessage());
                    msg.setData(bndle);
                    msg.what = EVENTSLISTHANDLER_ERROR;
                    eventsListHandler.sendMessage(msg);
                }
            } else {
                //Log.i("EventList","No DB data found, querying API directly");
                try {
                    eventsListHandler.sendEmptyMessage(EVENTSLISTHANDLER_DB_EMPTY);

                    if (tempZenossEvents != null)
                        tempZenossEvents.clear();

                    //Can we get away with just calling refresh now?

                    getActivity().runOnUiThread(new Runnable() {
                        public void run() {
                            //TODO This needs to be sent as a runnable or something
                            Refresh();
                        }
                    });

                } catch (Exception e) {
                    BugSenseHandler.sendExceptionMessage("RhybuddHome", "DBGetThread", e);
                    bndle.putString("exception", e.getMessage());
                    msg.setData(bndle);
                    msg.what = EVENTSLISTHANDLER_ERROR;
                    eventsListHandler.sendMessage(msg);
                }
            }
        }
    }.start();
}

From source file:cn.xiaocool.android_etong.net.constant.request.MainRequest.java

public void SearchShops(final String shop) {
    new Thread() {
        Message msg = new Message();

        @Override//  www .j  a v a  2  s.  c  om
        public void run() {
            String data = "&shop=" + shop;
            Log.e("data=", data);
            String result_data = NetUtil.getResponse(WebAddress.SearchShops, data);
            Log.e("result_data=", result_data);
            try {
                JSONObject jsonObject = new JSONObject(result_data);
                msg.what = CommunalInterfaces.SEARCH_SHOPS;
                msg.obj = jsonObject;
            } catch (JSONException e) {
                e.printStackTrace();
            } finally {
                handler.sendMessage(msg);
            }
        }
    }.start();
}