Example usage for android.os Message obtain

List of usage examples for android.os Message obtain

Introduction

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

Prototype

public static Message obtain(Handler h, int what, int arg1, int arg2) 

Source Link

Document

Same as #obtain() , but sets the values of the target, what, arg1, and arg2 members.

Usage

From source file:com.kakao.http.KakaoAsyncHandler.java

public Void onCompleted(final Response response) throws Exception {
    final URI requestUri = response.getUri();
    try {//from ww  w.  j a  va2  s  .co m
        if (!response.hasResponseStatus()) {
            sendError(response, "the response didn't have a response status");
            return null;
        }

        final int httpStatusCode = response.getStatusCode();
        if (httpStatusCode != HttpStatus.SC_OK) {
            return handleFailureHttpStatus(response, requestUri, httpStatusCode);
        } else {
            if (returnType.equals(Void.class)) {
                httpResponseHandler
                        .sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0));
            } else {
                Object result = null;
                if (checkResponseBody(response))
                    return null;
                if (APIErrorResult.class.equals(returnType)) {
                    JSONObject json = new JSONObject(response.getResponseBody());
                    result = new APIErrorResult(json.getInt("code"), json.getString("msg"));
                } else if (User.class.equals(returnType)) {
                    JSONObject json = new JSONObject(response.getResponseBody());
                    result = new User(json.getLong("id"));
                } else if (KakaoTalkProfile.class.equals(returnType)) {
                    JSONObject json = new JSONObject(response.getResponseBody());
                    result = new KakaoTalkProfile(json.getString("nickName"), json.getString("profileImageURL"),
                            json.getString("thumbnailURL"), json.getString("countryISO"));
                } else if (KakaoStoryUpload.class.equals(returnType)) {
                    JSONObject json = new JSONObject(response.getResponseBody());
                    result = new KakaoStoryUpload(json.getString("url"));
                } else if (KakaoStoryProfile.class.equals(returnType)) {
                    JSONObject json = new JSONObject(response.getResponseBody());

                    result = new KakaoStoryProfile(json.getString("nickName"),
                            json.getString("profileImageURL"), json.getString("thumbnailURL"),
                            json.getString("bgImageURL"), json.getString("birthday"),
                            "+".equals(json.getString("birthdayType")) ? KakaoStoryProfile.BirthdayType.SOLAR
                                    : KakaoStoryProfile.BirthdayType.LUNAR);
                } else if (Map.class.equals(returnType)) {
                    JSONObject json = new JSONObject(response.getResponseBody());
                    result = JsonHelper.MapFromJson(json);
                } else if (List.class.equals(returnType)) {
                    JSONArray json = new JSONArray(response.getResponseBody());
                    result = JsonHelper.ListFromJson(json);
                } else {
                    throw new IllegalStateException("unknown result type " + returnType);
                }
                httpResponseHandler.sendMessage(
                        Message.obtain(httpResponseHandler, HttpRequestTask.SUCCESS, 0, 0, result));
            }
            return null;
        }
    } catch (Exception e) {
        sendError(response, e.toString());
        return null;
    }
}

From source file:org.peercast.core.PeerCastServiceController.java

/** ????????
 * /*from w  w  w .  j  a v a 2s  .c  o m*/
 * <ul>
 *  <li>
 * MSG_CMD_CHANNEL_BUMP = 0x10;<br>
  * bump????  <br><br>
 *  <li>
 *  MSG_CMD_CHANNEL_DISCONNECT = 0x11;<br>
 * ??? <br><br>
 *  <li>
  * MSG_CMD_CHANNEL_KEEP_YES = 0x12;<br>
  * ???<br><br>
  *  <li>
  * MSG_CMD_CHANNEL_KEEP_NO = 0x13;<br>
  * ????<br><br>
  * 
 * @param cmdType MSG_CMD_CHANNEL_ ??
 * @param channel_id ?channel_id
 */
public void sendChannelCommand(int cmdType, int channel_id) {
    if (serverMessenger == null)
        new IllegalStateException("service not connected.");
    Message msg = Message.obtain(null, cmdType, channel_id, 0);
    try {
        serverMessenger.send(msg);
    } catch (RemoteException e) {
        Log.e(TAG, "what=" + cmdType, e);
    }
}

From source file:com.google.android.DemoKit.DemoKitActivity.java

/** Called when the activity is first created. */
@Override/*from   w w w .  j av  a  2  s .  com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = getApplicationContext();

    //      Toast.makeText(this, "inside onCreate of DemoKitActivity", Toast.LENGTH_SHORT).show();

    IntentFilter connFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    mConnReceiver = new ConnBroadcastReceiver();

    registerReceiver(mConnReceiver, connFilter);

    setContentView(R.layout.main);

    enableControls(true);

    mNocServiceRequestor = new PeriodicScheduler(new Runnable() {
        @Override
        public void run() {
            if (mNocAccessServiceMessenger != null) {
                toastHandler("Trying to upload Sensor Data");
                //               if(mConnReceiver.isConnected) {
                Message msg = Message.obtain(null, NocMessages.URL_MSG, 0, 0);
                Bundle msgBundle = new Bundle();
                msgBundle.putString("url",
                        "http://98.26.23.101/update.php?req=UI:WLDCTLAB1;FV:1.36;E1:0;EC1:0;E2:0;EC2:0;FL:2937;FC:0;BA:1218;TO:2181;TC:2181;FL20:0;FE:0;BL:0;HTO:0;HTC:0;BP1:0;BP2:0;GF:0;UF:1;IN:0;DT:0;TCF:0;TOF:0");
                msg.setData(msgBundle);
                try {
                    mNocAccessServiceMessenger.send(msg);
                } catch (RemoteException e) {

                }

            } else {
                toastHandler("mNocAccessServiceMessenger is null!");
            }

        }
    }, 5000);

    mBTMsgHandler = new Messenger(new BluetoothMsgHandler());
    mAccessoryMsgHandler = new Messenger(new ServiceMsgHandler());
    mNocMsgHandler = new Messenger(new ServiceMsgHandler());
}

From source file:ch.nexuscomputing.android.osciprimeics.OsciPrimeService.java

private void status() {
    try {//from   w ww . j  ava 2s  . c om
        mActivityMessenger.send(Message.obtain(null, OsciPrimeICSActivity.STATUS, mState, -1));
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}

From source file:com.kakao.rest.APIHttpRequestTask.java

protected void preRequest() {
    HttpResponseHandler.sendMessage(Message.obtain(HttpResponseHandler, -1, 0, 0));
}

From source file:org.interactiverobotics.headset_launcher.BluetoothHeadsetMonitorService.java

/**
 * @see BluetoothHeadsetMonitor.BluetoothHeadsetMonitorDelegate#onBluetoothStarted()
 *
 *///from w ww  . j  a  v a  2  s .  co  m
@Override
public void onBluetoothStarted() {

    if (mCallbackMessengers.isEmpty()) {

        //  

        final NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.headset_launcher_notification)
                .setContentTitle(getString(R.string.text_bluetooth_started)).setAutoCancel(true);

        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);

        notificationManager.notify(1, builder.build());

        // ?  ?  ?

        mTimer.start();

    } else {

        //  

        for (Messenger x : mCallbackMessengers) {

            try {

                x.send(Message.obtain(null, 1, 0, 0));

            } catch (RemoteException e) {

                Log.e(TAG, "Callback error!");
            }
        }
    }
}

From source file:com.tweetlanes.android.service.BackgroundService.java

private void sendMessageToUI(int intvaluetosend) {
    for (int i = mClients.size() - 1; i >= 0; i--) {
        try {/*from   w  w  w.j a  v  a  2 s.  c  o m*/
            // Send data as an Integer
            mClients.get(i).send(Message.obtain(null, MSG_SET_INT_VALUE, intvaluetosend, 0));

            //Send data as a String
            Bundle b = new Bundle();
            b.putString("str1", "ab" + intvaluetosend + "cd");
            Message msg = Message.obtain(null, MSG_SET_STRING_VALUE);
            msg.setData(b);
            mClients.get(i).send(msg);

        } catch (RemoteException e) {
            // The client is dead. Remove it from the list; we are going through the list from back to front so this is safe to do inside the loop.
            mClients.remove(i);
        }
    }
}

From source file:com.shafiq.mytwittle.service.BackgroundService.java

private void sendMessageToUI(int intvaluetosend) {
    for (int i = mClients.size() - 1; i >= 0; i--) {
        try {/* w w w  .  ja v a  2s. co  m*/
            // Send data as an Integer
            mClients.get(i).send(Message.obtain(null, MSG_SET_INT_VALUE, intvaluetosend, 0));

            // Send data as a String
            Bundle b = new Bundle();
            b.putString("str1", "ab" + intvaluetosend + "cd");
            Message msg = Message.obtain(null, MSG_SET_STRING_VALUE);
            msg.setData(b);
            mClients.get(i).send(msg);

        } catch (RemoteException e) {
            // The client is dead. Remove it from the list; we are going
            // through the list from back to front so this is safe to do
            // inside the loop.
            mClients.remove(i);
        }
    }
}

From source file:com.bangz.shotrecorder.RecordActivity.java

private void OnMessageLaps(Message msg) {
    if (msg.arg1 == RecordService.EVENT_ARRIVED) {
        if (mService != null) {
            try {
                Message msgreturn = Message.obtain(null, RecordService.MSG_LAPS, mSplitManager.getNumbers(), 0);
                msgreturn.replyTo = mMessenger;
                mService.send(msgreturn);
            } catch (RemoteException e) {

            }// w w  w .  j  a v  a2 s  .co m
        }
    } else {
        long[] events = (long[]) msg.obj;
        for (long e : events) {
            mSplitManager.append(e);
            mSplitAdapter.notifyDataSetChanged();
            FragmentManager fm = getSupportFragmentManager();
            SplitListFragment splitfragment = (SplitListFragment) fm.findFragmentById(R.id.splitlist);
            splitfragment.getListView().smoothScrollToPosition(mSplitManager.getNumbers() - 1);

            mbModified = true;
        }

        mCurrentSplitIndex = mSplitManager.getNumbers() - 1;
        UpdateCurrentSplitView(mCurrentSplitIndex);

        SetShareIntent();
    }
}