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() 

Source Link

Document

Return a new Message instance from the global pool.

Usage

From source file:org.lol.reddit.reddit.CommentListingRequest.java

private void notifyListener(Event eventType, Object object) {
    final Message message = Message.obtain();
    message.what = eventType.ordinal();/*w w w.  j  a  va  2 s.  c o m*/
    message.obj = object;
    mEventHandler.sendMessage(message);
}

From source file:de.qspool.clementineremote.ui.fragments.PlaylistFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.download_playlist:
        DownloadManager.getInstance().addJob(
                ClementineMessageFactory.buildDownloadSongsMessage(DownloadItem.APlaylist, getPlaylistId()));
        return true;
    case R.id.clear_playlist:
        new MaterialDialog.Builder(getActivity()).title(R.string.playlist_clear)
                .content(R.string.playlist_clear_content).positiveText(R.string.playlist_clear_confirm)
                .negativeText(R.string.dialog_cancel).onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override//  w ww .  j a va 2  s .co m
                    public void onClick(MaterialDialog dialog, DialogAction which) {
                        mPlaylistManager.clearPlaylist(getPlaylistId());
                        updateSongList();
                    }
                }).show();
        return true;
    case R.id.close_playlist:
        Message msg = Message.obtain();
        msg.obj = ClementineMessageFactory.buildClosePlaylist(getPlaylistId());
        App.ClementineConnection.mHandler.sendMessage(msg);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.blue.leaves.util.task.SugarTask.java

private Runnable buildRunnable(@NonNull final Integer id) {
    return new Runnable() {
        @Override//from  w  w  w .jav a 2 s .  c  o  m
        public void run() {
            Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);

            /*
             * TODO:
             *
             * Thread safety problem.
             *
             * 
             */
            if (taskMap.containsKey(id)) {
                Message message = Message.obtain();

                try {
                    message.what = MESSAGE_FINISH;
                    message.obj = new Holder(id, taskMap.get(id).onBackground());
                } catch (Exception e) {
                    message.what = MESSAGE_BROKEN;
                    message.obj = new Holder(id, e);
                }

                post(message);
            }
        }
    };
}

From source file:bucci.dev.freestyle.TimerActivity.java

private void sendMessageToService(int messageType) {
    if (DEBUG)//from   ww  w .  jav  a 2  s  . co m
        Log.d(TAG, "sendMessageToService(" + messageType + ")");
    Message msg = Message.obtain();
    msg.what = messageType;
    switch (messageType) {
    case MSG_START_TIMER:
        if (isTimerResumed())
            msg.obj = timeLeft;
        else
            msg.obj = startTime;
        break;
    case MSG_STOP_TIMER:
        if (DEBUG)
            Log.i(TAG, "startTime: " + startTime);
        msg.obj = startTime;
        break;
    }

    try {
        service.send(msg);
    } catch (RemoteException e) {
        if (DEBUG)
            Log.e(TAG, "sendMessage RemoteException, e: " + e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.wellsandwhistles.android.redditsp.views.RedditPostView.java

public void betterThumbnailAvailable(final Bitmap thumbnail, final int callbackUsageId) {
    final Message msg = Message.obtain();
    msg.obj = thumbnail;/*from  w w w .  ja  va 2s  .  co  m*/
    msg.what = callbackUsageId;
    thumbnailHandler.sendMessage(msg);
}

From source file:com.jwork.dhammapada.ChapterFragment.java

private void search(CharSequence query) {
    Message message = Message.obtain();
    message.what = Constant.WHAT_SEARCH_VERSE;
    message.obj = query;
    controller.executeMessage(message);
}

From source file:de.qspool.clementineremote.ui.MainActivity.java

/**
 * Request a disconnect from clementine// w ww  . j  av  a2  s  . c  om
 */
private void requestDisconnect() {
    // Move the request to the message
    Message msg = Message.obtain();
    msg.obj = ClementineMessage.getMessage(MsgType.DISCONNECT);

    // Send the request to the thread
    App.mClementineConnection.mHandler.sendMessage(msg);
}

From source file:cn.edu.zzu.wemall.http.AsyncHttpResponseHandler.java

protected Message obtainMessage(int responseMessage, Object response) {
    Message msg;//  w  w  w.  ja  v  a 2  s  .c o  m
    if (handler != null) {
        msg = handler.obtainMessage(responseMessage, response);
    } else {
        msg = Message.obtain();
        if (msg != null) {
            msg.what = responseMessage;
            msg.obj = response;
        }
    }
    return msg;
}

From source file:com.android.mms.ui.MailBoxMessageContent.java

private void lockUnlockMessage() {
    int lockValue;
    // 1, lock; 0, unlock
    mLock = isLockMessage();/*  w w  w  .ja v  a2s . c o m*/
    final Uri lockUri = mMessageUri;
    lockValue = mLock ? 0 : 1;
    final ContentValues values = new ContentValues(1);
    values.put("locked", lockValue);

    new Thread(new Runnable() {
        public void run() {
            Message msg = Message.obtain();
            msg.what = SHOW_TOAST;
            if (getContentResolver().update(lockUri, values, null, null) > 0) {
                msg.obj = getString(R.string.operate_success);
            } else {
                msg.obj = getString(R.string.operate_failure);
            }
            mUiHandler.sendMessage(msg);
        }
    }).start();
}

From source file:com.taobao.weex.ui.animation.WXAnimationModule.java

@JSMethod
public void transition(@Nullable String ref, @Nullable String animation, @Nullable String callBack) {
    if (!TextUtils.isEmpty(ref) && !TextUtils.isEmpty(animation)) {
        Message msg = Message.obtain();
        WXDomTask task = new WXDomTask();
        task.instanceId = mWXSDKInstance.getInstanceId();
        task.args = new ArrayList<>();
        task.args.add(ref);//from w  ww  .  j  av  a2  s. c  o m
        task.args.add(animation);
        task.args.add(callBack);
        msg.what = WXDomHandler.MsgType.WX_ANIMATION;
        msg.obj = task;
        //Due to animation module rely on the result of the css-layout and the batch mechanism of
        //css-layout, the animation.transition must be delayed the batch time.
        WXSDKManager.getInstance().getWXDomManager().sendMessageDelayed(msg, WXDomHandler.DELAY_TIME);
    }
}