List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:com.my.infiniteviewpager.view.InfiniteViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()/*from w ww . jav a 2 s. c o m*/ * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } if (mAdapter == null) { return; } mLastMotionX += xOffset; float oldScrollX = getScrollX(); float scrollX = oldScrollX - xOffset; final int width = getClientWidth(); float leftBound = width * mFirstOffset; float rightBound = width * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); leftBound = firstItem.offset * width; rightBound = lastItem.offset * width; if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); pageScrolled((int) scrollX); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.isapp.android.circularviewpager.CircularViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()//from www.ja v a2 s.c o m * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float oldScrollX = getScrollX(); float scrollX = oldScrollX - xOffset; final int width = getClientWidth(); float leftBound = width * mFirstOffset; float rightBound = width * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { leftBound = firstItem.offset * width; } if (lastItem.position != mAdapter.getCount() - 1) { rightBound = lastItem.offset * width; } if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); pageScrolled((int) scrollX); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.anysoftkeyboard.keyboards.views.AnyKeyboardBaseView.java
/** * Called when a key is long pressed. By default this will open any popup * keyboard associated with this key through the attributes popupLayout and * popupCharacters.// w ww. j av a2 s . c o m * * @param popupKey the key that was long pressed * @return true if the long press is handled, false otherwise. Subclasses * should call the method on the base class if the subclass doesn't * wish to handle the call. */ protected boolean onLongPress(Context packageContext, Key popupKey, boolean isSticky, boolean requireSlideInto) { if (popupKey.popupResId == 0) return false; if (mMiniKeyboard == null) { createMiniKeyboard(); } AnyPopupKeyboard popupKeyboard = setupMiniKeyboardContainer(packageContext, popupKey, isSticky); mMiniKeyboardVisible = true; if (mWindowOffset == null) { mWindowOffset = new int[2]; getLocationInWindow(mWindowOffset); } int popupX = popupKey.x + mWindowOffset[0]; popupX -= mMiniKeyboard.getPaddingLeft(); int popupY = popupKey.y + mWindowOffset[1]; popupY += getPaddingTop(); popupY -= mMiniKeyboard.getMeasuredHeight(); popupY -= mMiniKeyboard.getPaddingBottom(); final int x = popupX; final int y = mShowPreview && mOldPreviewKeyIndex != NOT_A_KEY && isOneRowKeys(mMiniKeyboard.getKeyboard().getKeys()) ? mPopupPreviewDisplayedY : popupY; int adjustedX = x; boolean shouldMirrorKeys = false; //now we need to see the the popup is positioned correctly: //1) if the right edge is off the screen, then we'll try to put the right edge over the popup key if (adjustedX > (getMeasuredWidth() - mMiniKeyboard.getMeasuredWidth())) { adjustedX = popupKey.x + mWindowOffset[0] - mMiniKeyboard.getMeasuredWidth(); //adding the width of the key - now the right most popup key is above the finger adjustedX += popupKey.width; adjustedX += mMiniKeyboard.getPaddingRight(); shouldMirrorKeys = true; } //2) if it is still negative, then let's put it at the beginning (shouldn't happen) if (adjustedX < 0) { adjustedX = 0; shouldMirrorKeys = false; } if (shouldMirrorKeys) popupKeyboard.mirrorKeys(); mMiniKeyboardOriginX = adjustedX + mMiniKeyboard.getPaddingLeft() - mWindowOffset[0]; mMiniKeyboardOriginY = y + mMiniKeyboard.getPaddingTop() - mWindowOffset[1]; //I'm not sure I need to do this, but in any case - this is to sync the popup window //to align to the mini-keyboard position mMiniKeyboard.setPopupOffset(adjustedX, y); // NOTE:I'm checking the main keyboard shift state directly! // Not anything else. mMiniKeyboard.setShifted(mKeyboard != null && mKeyboard.isShifted()); // Mini keyboard needs no pop-up key preview displayed. mMiniKeyboard.setPreviewEnabled(false); // animation switching required? mMiniKeyboardPopup.setContentView(mMiniKeyboard); mMiniKeyboardPopup.setWidth(mMiniKeyboard.getMeasuredWidth()); mMiniKeyboardPopup.setHeight(mMiniKeyboard.getMeasuredHeight()); mMiniKeyboardPopup.showAtLocation(this, Gravity.NO_GRAVITY, adjustedX, y); if (requireSlideInto) { // Inject down event on the key to mini keyboard. long eventTime = SystemClock.uptimeMillis(); mMiniKeyboardPopupTime = eventTime; MotionEvent downEvent = generateMiniKeyboardMotionEvent(MotionEvent.ACTION_DOWN, popupKey.x + popupKey.width / 2, popupKey.y + popupKey.height / 2, eventTime); mMiniKeyboard.onTouchEvent(downEvent); downEvent.recycle(); } invalidateAllKeys(); return true; }
From source file:au.com.glassechidna.velocityviewpager.VelocityViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()/* w w w . j a va 2 s . co m*/ * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += xOffset; float oldScrollX = getScrollX(); float scrollX = oldScrollX - xOffset; final int width = getClientWidth(); float leftBound = width * mFirstOffset; float rightBound = width * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { leftBound = firstItem.offset * width; } if (lastItem.position != mAdapter.getCount() - 1) { rightBound = lastItem.offset * width; } if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); pageScrolled((int) scrollX); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:android.webkit.cts.WebViewTest.java
/** * Waits at least MIN_SCROLL_WAIT_MS for scrolling to start. Once started, * scrolling is checked every SCROLL_WAIT_INTERVAL_MS for changes. Once * changes have stopped, the function exits. If no scrolling has happened * then the function exits after MIN_SCROLL_WAIT milliseconds. * @param previousScrollY The Y scroll position prior to waiting. *///from www. j av a 2s. c om private void waitForScrollingComplete(int previousScrollY) throws InterruptedException { int scrollY = previousScrollY; // wait at least MIN_SCROLL_WAIT for something to happen. long noChangeMinWait = SystemClock.uptimeMillis() + MIN_SCROLL_WAIT_MS; boolean scrollChanging = false; boolean scrollChanged = false; boolean minWaitExpired = false; while (scrollChanging || (!scrollChanged && !minWaitExpired)) { Thread.sleep(SCROLL_WAIT_INTERVAL_MS); int oldScrollY = scrollY; scrollY = mOnUiThread.getScrollY(); scrollChanging = (scrollY != oldScrollY); scrollChanged = (scrollY != previousScrollY); minWaitExpired = (SystemClock.uptimeMillis() > noChangeMinWait); } }
From source file:com.ifnoif.androidtestdemo.customview.VViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()//from w w w .j av a2 s. co m * @see #endFakeDrag() */ public void fakeDragBy(float yOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } if (mAdapter == null) { return; } mLastMotionY += yOffset; float oldScrollY = getScrollY(); float scrollY = oldScrollY - yOffset; final int height = getClientHeight(); float topBound = height * mFirstOffset; float bottomBound = height * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { topBound = firstItem.offset * height; } if (lastItem.position != mAdapter.getCount() - 1) { bottomBound = lastItem.offset * height; } if (scrollY < topBound) { scrollY = topBound; } else if (scrollY > bottomBound) { scrollY = bottomBound; } // Don't lose the rounded component mLastMotionY += scrollY - (int) scrollY; scrollTo(getScrollX(), (int) scrollY); pageScrolled((int) scrollY); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, 0, mLastMotionY, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.tjych.swip.vertical.DirectionalViewPager.java
/** * Start a fake drag of the pager./*from w w w.j a v a2 s .c om*/ * * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager * with the touch scrolling of another view, while still letting the ViewPager * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.) * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call * {@link #endFakeDrag()} to complete the fake drag and fling as necessary. * * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag * is already in progress, this method will return false. * * @return true if the fake drag began successfully, false if it could not be started. * * @see #fakeDragBy(float) * @see #endFakeDrag() */ public boolean beginFakeDrag() { if (mIsBeingDragged) { return false; } mFakeDragging = true; setScrollState(SCROLL_STATE_DRAGGING); mInitialMotionX = mLastMotionX = 0; mInitialMotionY = mLastMotionY = 0; if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } else { mVelocityTracker.clear(); } final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); mFakeDragBeginTime = time; return true; }
From source file:com.telerik.examples.primitives.ExampleViewPagerBase.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param offset Offset in pixels to drag by. * @see #beginFakeDrag()//www .ja v a 2 s . c o m * @see #endFakeDrag() */ public void fakeDragBy(float offset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } mLastMotionX += offset; float oldScroll = getScroll(this); float scroll = oldScroll - offset; final int clientLength = getClientLength(); float leftBound = clientLength * mFirstOffset; float rightBound = clientLength * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { leftBound = firstItem.offset * clientLength; } if (lastItem.position != mAdapter.getCount() - 1) { rightBound = lastItem.offset * clientLength; } if (scroll < leftBound) { scroll = leftBound; } else if (scroll > rightBound) { scroll = rightBound; } // Don't lose the rounded component mLastMotionX = mLastMotionX + (scroll - (int) scroll); if (this.orientation == LinearLayout.HORIZONTAL) { scrollTo((int) scroll, getInvertedScroll(this)); } else { scrollTo(getInvertedScroll(this), (int) scroll); } pageScrolled((int) scroll); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:com.av.remusic.widget.RoundViewPager.java
/** * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first. * * @param xOffset Offset in pixels to drag by. * @see #beginFakeDrag()/*from w ww. j a v a2 s . co m*/ * @see #endFakeDrag() */ public void fakeDragBy(float xOffset) { if (!mFakeDragging) { throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first."); } if (mAdapter == null) { return; } mLastMotionX += xOffset; float oldScrollX = getScrollX(); float scrollX = oldScrollX - xOffset; final int width = getClientWidth(); float leftBound = width * mFirstOffset; float rightBound = width * mLastOffset; final ItemInfo firstItem = mItems.get(0); final ItemInfo lastItem = mItems.get(mItems.size() - 1); if (firstItem.position != 0) { leftBound = firstItem.offset * width; } if (lastItem.position != mAdapter.getCount() - 1) { rightBound = lastItem.offset * width; } if (scrollX < leftBound) { scrollX = leftBound; } else if (scrollX > rightBound) { scrollX = rightBound; } // Don't lose the rounded component mLastMotionX += scrollX - (int) scrollX; scrollTo((int) scrollX, getScrollY()); pageScrolled((int) scrollX); // Synthesize an event for the VelocityTracker. final long time = SystemClock.uptimeMillis(); final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE, mLastMotionX, 0, 0); mVelocityTracker.addMovement(ev); ev.recycle(); }
From source file:org.mozilla.gecko.GeckoApp.java
private void loadRequest(String url, AwesomeBar.Type type, String searchEngine, boolean userEntered) { mBrowserToolbar.setTitle(url);/*from w ww. jav a 2s .c om*/ Log.d(LOGTAG, type.name()); JSONObject args = new JSONObject(); try { args.put("url", url); args.put("engine", searchEngine); args.put("userEntered", userEntered); } catch (Exception e) { Log.e(LOGTAG, "error building JSON arguments"); } if (type == AwesomeBar.Type.ADD) { Log.i(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add"); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString())); } else { GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Load", args.toString())); } }