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.google.android.DemoKit.DemoKitActivity.java

public void onClickSetSettings(View v) {
    Toast.makeText(this, "Click received from Set Settings", Toast.LENGTH_SHORT).show();
    try {//from w w w .java 2  s. c  o  m
        mAccessoryController.send(Message.obtain(null, UsbMessages.SET_SETTINGS, 0, 0));
    } catch (RemoteException e) {
    }
    ;
}

From source file:com.google.android.gcm.demo.app.BluetoothHDPActivity.java

private void sendMessage(int what, int value) {
    if (mHealthService == null) {
        Log.d(TAG, "Health Service not connected.");
        return;//from ww w. j av a2 s .c o  m
    }

    try {
        mHealthService.send(Message.obtain(null, what, value, 0));
    } catch (RemoteException e) {
        Log.w(TAG, "Unable to reach service.");
        e.printStackTrace();
    }
}

From source file:com.xdandroid.lunboviewpager.CirclePageIndicator.java

@Override
public void onPageSelected(int position) {
    if (mSnap || mScrollState == ViewPager.SCROLL_STATE_IDLE) {
        mCurrentPage = position % (mViewPager.getAdapter().getCount() / 1000);
        mSnapPage = position % (mViewPager.getAdapter().getCount() / 1000);
        invalidate();/*from  ww  w.j  av  a2 s .c  o m*/
    }

    handler.sendMessage(Message.obtain(handler, PagerHandler.MSG_PAGE_CHANGED, position, 0));
}

From source file:com.samsung.smcl.example.helloworldprovider.backend.HelloWorldProviderService.java

private boolean sendToHelloWorldService(String data) {

    if (mHelloWorldMessenger == null || mBound == false) {
        Utility.logError(TAG, "mHelloWorldMessenger is null or mBound is false, return false");
        return false;
    }// ww  w .ja v  a  2s . c o m
    Bundle providerData = new Bundle(1);
    providerData.putString(BUNDLE_DATA, data);
    Message providerMsg = Message.obtain(null, MSG_TO_HELLOWORLDSERVICE, 0, 0);
    providerMsg.setData(providerData);

    try {
        mHelloWorldMessenger.send(providerMsg);
        Utility.logDebug(TAG, "MSG_TO_HELLOWORLDSERVICE");
    } catch (RemoteException e) {
        Utility.logError(TAG, "", e);
        return false;
    }
    return true;
}

From source file:fr.mixit.android.ui.fragments.SessionDetailsFragment.java

public void refreshSessionData() {
    if (mIsBound && mServiceReady) {
        setRefreshMode(true);//from   w  ww . j a v a  2  s . c  o  m

        final Message msg = Message.obtain(null,
                MixItContract.Sessions.FORMAT_LIGHTNING_TALK.equalsIgnoreCase(mSessionFormat)
                        ? MixItService.MSG_LIGHTNING_TALK
                        : MixItService.MSG_TALK,
                0, 0);
        msg.replyTo = mMessenger;
        final Bundle b = new Bundle();
        b.putInt(MixItService.EXTRA_ID, mSessionId);
        msg.setData(b);
        try {
            mService.send(msg);
        } catch (final RemoteException e) {
            e.printStackTrace();
        }

        mIsFirstLoad = false;
    }
}

From source file:fr.mixit.android.ui.fragments.MemberDetailsFragment.java

protected void refreshMemberData() {
    if (mIsBound && mServiceReady) {
        setRefreshMode(true);//from  ww  w.j a  va2s.  com

        final Message msg = Message.obtain(null, MixItService.MSG_MEMBER, 0, 0);
        msg.replyTo = mMessenger;
        final Bundle b = new Bundle();
        b.putInt(MixItService.EXTRA_ID, mMemberId);
        msg.setData(b);
        try {
            mService.send(msg);
        } catch (final RemoteException e) {
            e.printStackTrace();
        }

        mIsFirstLoad = false;
    }
}

From source file:com.freerdp.freerdpcore.presentation.SessionActivity.java

private void sendDelayedMoveEvent(int x, int y) {
    if (uiHandler.hasMessages(UIHandler.SEND_MOVE_EVENT)) {
        uiHandler.removeMessages(UIHandler.SEND_MOVE_EVENT);
        discardedMoveEvents++;//from w  w w.j ava  2s . c om
    } else
        discardedMoveEvents = 0;

    if (discardedMoveEvents > MAX_DISCARDED_MOVE_EVENTS)
        LibFreeRDP.sendCursorEvent(session.getInstance(), x, y, Mouse.getMoveEvent());
    else
        uiHandler.sendMessageDelayed(Message.obtain(null, UIHandler.SEND_MOVE_EVENT, x, y),
                SEND_MOVE_EVENT_TIMEOUT);
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void setupAnimators() {
    // A zoom-in/zoom-out animator
    mZoomAnimator = ValueAnimator.ofFloat(1.f);
    mZoomAnimator.setDuration(350L);//from w  w w .  jav  a 2  s. c  o m
    mZoomAnimator.setInterpolator(new DecelerateInterpolator());
    mZoomAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mCurrentZoom = (Float) animation.getAnimatedValue();
            ViewCompat.postInvalidateOnAnimation(TimelineChartView.this);
        }
    });
    mZoomAnimator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mInZoomOut) {
                // Swap temporary refs
                swapRefs();

                // Update the view, notify and end the animation
                Message.obtain(mUiHandler, MSG_UPDATE_COMPUTED_DATA, 1, 0).sendToTarget();
            } else {
                mState = STATE_IDLE;
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mState = STATE_IDLE;
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void reloadCursorData(boolean animate) {
    int arg1 = mAnimateCursorTransition && animate ? 1 : 0;
    Message.obtain(mBackgroundHandler, MSG_COMPUTE_DATA, arg1, 1).sendToTarget();
}

From source file:com.ruesga.timelinechart.TimelineChartView.java

private void performComputeData(boolean animate, boolean notify) {
    // Process the data
    processData();//from ww w  .  java  2 s . c  o m

    if (animate) {
        // Run in an animation
        if (mZoomAnimator.isRunning()) {
            mZoomAnimator.cancel();
        }
        mInZoomOut = true;
        mZoomAnimator.setFloatValues(MIN_ZOOM_OUT, MAX_ZOOM_OUT);
        mScroller.forceFinished(true);
        mState = STATE_ZOOMING;
        mZoomAnimator.start();

    } else if (notify) {
        // Swap temporary refs
        mScroller.forceFinished(true);
        mState = STATE_IDLE;
        swapRefs();

        // Update the view and notify
        Message.obtain(mUiHandler, MSG_UPDATE_COMPUTED_DATA, 0, 0).sendToTarget();
    }

    // Update the graph view
    ViewCompat.postInvalidateOnAnimation(TimelineChartView.this);
}