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, Object obj) 

Source Link

Document

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

Usage

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

@Override
public boolean OnAuthenticate(StringBuilder username, StringBuilder domain, StringBuilder password) {
    // this is where the return code of our dialog will be stored
    callbackDialogResult = false;//  w w w  .  j  ava  2 s.c o m

    // set text fields
    ((EditText) userCredView.findViewById(R.id.editTextUsername)).setText(username);
    ((EditText) userCredView.findViewById(R.id.editTextDomain)).setText(domain);
    ((EditText) userCredView.findViewById(R.id.editTextPassword)).setText(password);

    // start dialog in UI thread      
    uiHandler.sendMessage(Message.obtain(null, UIHandler.SHOW_DIALOG, dlgUserCredentials));

    // wait for result
    try {
        synchronized (dlgUserCredentials) {
            dlgUserCredentials.wait();
        }
    } catch (InterruptedException e) {
    }

    // clear buffers
    username.setLength(0);
    domain.setLength(0);
    password.setLength(0);

    // read back user credentials
    username.append(((EditText) userCredView.findViewById(R.id.editTextUsername)).getText().toString());
    domain.append(((EditText) userCredView.findViewById(R.id.editTextDomain)).getText().toString());
    password.append(((EditText) userCredView.findViewById(R.id.editTextPassword)).getText().toString());

    return callbackDialogResult;
}

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

@Override
public boolean OnVerifiyCertificate(String subject, String issuer, String fingerprint) {

    // see if global settings says accept all
    if (GlobalSettings.getAcceptAllCertificates())
        return true;

    // this is where the return code of our dialog will be stored
    callbackDialogResult = false;/*from  w w w  . java  2  s .  c  o  m*/

    // set message
    String msg = getResources().getString(R.string.dlg_msg_verify_certificate);
    msg = msg + "\n\nSubject: " + subject + "\nIssuer: " + issuer + "\nFingerprint: " + fingerprint;
    dlgVerifyCertificate.setMessage(msg);

    // start dialog in UI thread      
    uiHandler.sendMessage(Message.obtain(null, UIHandler.SHOW_DIALOG, dlgVerifyCertificate));

    // wait for result
    try {
        synchronized (dlgVerifyCertificate) {
            dlgVerifyCertificate.wait();
        }
    } catch (InterruptedException e) {
    }

    return callbackDialogResult;
}

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

/** {@inheritDoc} */
@Override/*from w  w w . ja  v  a  2 s  .c om*/
public boolean onTouchEvent(final MotionEvent event) {
    // Ignore events while performing scrolling animation
    if (mState == STATE_ZOOMING) {
        return true;
    }

    final int action = event.getActionMasked();
    final int index = event.getActionIndex();
    final int pointerId = event.getPointerId(index);
    final long now = System.currentTimeMillis();
    mLastX = event.getX();
    mLastY = event.getY();

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        // Initialize velocity tracker
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
        } else {
            mVelocityTracker.clear();
        }
        mVelocityTracker.addMovement(event);
        mScroller.forceFinished(true);
        releaseEdgeEffects();
        mState = STATE_INITIALIZE;

        mLongPressDetector.mLongPressTriggered = false;
        mUiHandler.postDelayed(mLongPressDetector, mLongPressTimeout);

        mInitialTouchOffset = mCurrentOffset;
        mInitialTouchX = event.getX();
        mInitialTouchY = event.getY();
        mLastPressTimestamp = now;
        return true;

    case MotionEvent.ACTION_MOVE:
        // If a long press was detected then we end with the movement
        if (mLongPressDetector.mLongPressTriggered) {
            return true;
        }

        mVelocityTracker.addMovement(event);
        float diffX = event.getX() - mInitialTouchX;
        float diffY = event.getY() - mInitialTouchY;
        if (Math.abs(diffX) > mTouchSlop || mState >= STATE_MOVING) {
            mUiHandler.removeCallbacks(mLongPressDetector);

            mCurrentOffset = mInitialTouchOffset + diffX;
            if (mCurrentOffset < 0) {
                onOverScroll();
                mCurrentOffset = 0;
            } else if (mCurrentOffset > mMaxOffset) {
                onOverScroll();
                mCurrentOffset = mMaxOffset;
            }
            mVelocityTracker.computeCurrentVelocity(1000, mMaxFlingVelocity);
            mState = STATE_MOVING;
            ViewCompat.postInvalidateOnAnimation(this);
        } else if (Math.abs(diffY) > mTouchSlop && mState < STATE_MOVING) {
            mUiHandler.removeCallbacks(mLongPressDetector);
            return false;
        }
        return true;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mUiHandler.removeCallbacks(mLongPressDetector);
        // If a long press was detected then we end with the movement
        if (mLongPressDetector.mLongPressTriggered) {
            return true;
        }

        if (mState >= STATE_MOVING) {
            final int velocity = (int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, pointerId);
            mScroller.forceFinished(true);
            mState = STATE_FLINGING;
            releaseEdgeEffects();
            mScroller.fling((int) mCurrentOffset, 0, velocity, 0, 0, (int) mMaxOffset, 0, 0);
            ViewCompat.postInvalidateOnAnimation(this);
        } else {
            // Reset scrolling state
            mState = STATE_IDLE;

            if (action == MotionEvent.ACTION_UP) {
                // we are in a tap or long press action
                final long timeDiff = (now - mLastPressTimestamp);
                // If diff < 0, that means that time have change. ignore this event
                if (timeDiff >= 0) {
                    if (timeDiff > TAP_TIMEOUT && timeDiff < mLongPressTimeout) {
                        // A tap event happens. Long click are detected outside
                        Message.obtain(mUiHandler, MSG_ON_CLICK_ITEM, computeItemEvent()).sendToTarget();
                    }
                }
            }
        }

        mLastPressTimestamp = -1;
        return true;
    }
    return false;
}

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

/** {@inheritDoc} */
@Override//  w  ww.j a  v  a 2s.c  o  m
public void computeScroll() {
    super.computeScroll();

    // Ignore any scroll while performing scrolling animation
    if (mState == STATE_ZOOMING) {
        return;
    }

    // Determine whether we still scrolling and needs a viewport refresh
    final boolean scrolling = mScroller.computeScrollOffset();
    if (scrolling) {
        float x = mScroller.getCurrX();
        if (x > mMaxOffset || x < 0) {
            return;
        }
        mCurrentOffset = x;
        ViewCompat.postInvalidateOnAnimation(this);
    } else if (mState > STATE_MOVING) {
        boolean needsInvalidate = false;
        final boolean needOverScroll;
        synchronized (mLock) {
            needOverScroll = mData.size() >= Math.floor(mMaxBarItemsInScreen / 2);
        }
        final int overScrollMode = ViewCompat.getOverScrollMode(this);
        if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS
                || (needOverScroll && overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS)) {
            float x = mScroller.getCurrX();
            if (x >= mMaxOffset && mEdgeEffectLeft.isFinished() && !mEdgeEffectLeftActive) {
                mEdgeEffectLeft.onAbsorb((int) mScroller.getCurrVelocity());
                mEdgeEffectLeftActive = true;
                needsInvalidate = true;
            }
            if (x <= 0 && mEdgeEffectRight.isFinished() && !mEdgeEffectRightActive) {
                mEdgeEffectRight.onAbsorb((int) mScroller.getCurrVelocity());
                mEdgeEffectRightActive = true;
                needsInvalidate = true;
            }
        }
        if (!needsInvalidate) {
            // Reset state
            mState = STATE_IDLE;
            mLastTimestamp = -1;
        } else {
            ViewCompat.postInvalidateOnAnimation(this);
        }
    }

    long timestamp = computeTimestampFromOffset(mCurrentOffset);

    // If we are not centered in a item, perform an scroll
    if (mAlwaysEnsureSelection && mState == STATE_IDLE) {
        timestamp = computeNearestTimestampFromOffset(mCurrentOffset);
        smoothScrollTo(timestamp);
    }

    if (mCurrentTimestamp != timestamp) {
        // Don't perform selection operations while we are just scrolling
        if (mState != STATE_SCROLLING) {
            boolean fromUser = mCurrentTimestamp != -2;
            mCurrentTimestamp = timestamp;
            if (fromUser) {
                performSelectionSoundEffect();
            }

            // Notify any valid item, but only notify invalid items if
            // we are not panning/scrolling
            if (mCurrentTimestamp >= 0 || !scrolling) {
                Message.obtain(mUiHandler, MSG_ON_SELECTION_ITEM_CHANGED, fromUser).sendToTarget();
            }
        }
    }
}

From source file:eu.davidea.flexibleadapter.FlexibleAdapter.java

/**
 * Start Undo timer with custom timeout//ww  w. ja  va 2  s.co m
 *
 * @param timeout  custom timeout
 * @param listener the listener that will be called after timeout to commit the change
 * @since 3.0.0
 */
public void startUndoTimer(long timeout, OnDeleteCompleteListener listener) {
    //Make longer the timer for new coming deleted items
    stopUndoTimer();
    mHandler.sendMessageDelayed(Message.obtain(mHandler, CONFIRM_DELETE, listener),
            timeout > 0 ? timeout : UNDO_TIMEOUT);
}

From source file:eu.davidea.flexibleadapter.FlexibleAdapter.java

/**
 * <b>WATCH OUT! PASS ALWAYS A <u>COPY</u> OF THE ORIGINAL LIST</b>: due to internal mechanism,
 * items are removed and/or added in order to animate items in the final list.
 * <p>Same as {@link #filterItems(List)}, but with a delay in the execution, useful to grab
 * more characters from user before starting the search.</p>
 *
 * @param unfilteredItems the list to filter
 * @param delay           any non-negative delay
 * @see #filterObject(IFlexible, String)
 * @see #setAnimateToLimit(int)//from  ww w .  j  a v  a 2s . com
 * @since 5.0.0-b1
 * <br/>5.0.0-b8 Synchronization animations limit + AsyncFilter
 */
public void filterItems(@NonNull List<T> unfilteredItems, @IntRange(from = 0) long delay) {
    //Make longer the timer for new coming deleted items
    mHandler.removeMessages(FILTER);
    mHandler.sendMessageDelayed(Message.obtain(mHandler, FILTER, unfilteredItems), delay > 0 ? delay : 0);
}

From source file:eu.davidea.flexibleadapter.FlexibleAdapter.java

/**
 * <b>WATCH OUT! PASS ALWAYS A <u>COPY</u> OF THE ORIGINAL LIST</b>: due to internal
 * mechanism, items are removed and/or added in order to animate items in the final list.
 * <p>This method filters the provided list with the search text previously set with
 * {@link #setSearchText(String)}.</p>
 * <b>Important notes:</b>/*  w w w . j  a  v a 2 s . c o  m*/
 * <ol>
 * <li>This method calls {@link #filterObject(IFlexible, String)}.</li>
 * <li>If search text is empty or null, the provided list is the current list.</li>
 * <li>Any pending deleted items are always filtered out, but if restored, they will be
 * displayed according to the current filter and at the right positions.</li>
 * <li><b>NEW!</b> Expandable items are picked up and displayed if at least a child is
 * collected by the current filter.</li>
 * <li><b>NEW!</b> Items are animated thanks to {@link #animateTo(List)} BUT a limit of
 * {@value mAnimateToLimit} (default) items is set. <b>NOTE:</b> you can change this limit
 * by calling {@link #setAnimateToLimit(int)}. Above this limit {@link #notifyDataSetChanged()}
 * will be called to improve performance.</li>
 * </ol>
 *
 * @param unfilteredItems the list to filter
 * @see #filterObject(IFlexible, String)
 * @see #setAnimateToLimit(int)
 * @since 4.1.0 Created
 * <br/>5.0.0-b1 Expandable + Child filtering
 * <br/>5.0.0-b8 Synchronization animations limit + AsyncFilter
 */
public void filterItems(@NonNull List<T> unfilteredItems) {
    mHandler.removeMessages(FILTER);
    mHandler.sendMessage(Message.obtain(mHandler, FILTER, unfilteredItems));
}