List of usage examples for android.os SystemClock uptimeMillis
@CriticalNative native public static long uptimeMillis();
From source file:android.melbournehistorymap.MapsActivity.java
@Override public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: lastTouched = SystemClock.uptimeMillis(); break;// w w w.j ava 2s.co m case MotionEvent.ACTION_UP: final long now = SystemClock.uptimeMillis(); if (now - lastTouched > delay) { //check if place details is open, if not then update the map if (expandedTile.getVisibility() == View.GONE) { // Update the map updateMap(); } } break; } return super.dispatchTouchEvent(ev); }
From source file:com.usertaxi.TaxiOntheWay_Activity.java
private void animateMarker(final Marker marker, final LatLng toPosition, final boolean hideMarker) { final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); Projection proj = map.getProjection(); Point startPoint = proj.toScreenLocation(marker.getPosition()); final LatLng startLatLng = proj.fromScreenLocation(startPoint);//marker1.getPosition(); final long duration = 600; final Interpolator interpolator = new LinearInterpolator(); handler.post(new Runnable() { @Override// w w w.j a v a 2 s. co m public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = interpolator.getInterpolation((float) elapsed / duration); double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude; double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude; marker.setPosition(new LatLng(lat, lng)); if (t < 1.0) { // Post again 16ms later. handler.postDelayed(this, 16); } else { if (hideMarker) { marker.setVisible(false); } else { marker.setVisible(true); } } // map.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(lat, lng))); } }); AppPreferences.setPreviouslat(getApplicationContext(), AppPreferences.getCurrentlat(getApplicationContext())); AppPreferences.setPreviouslong(getApplicationContext(), AppPreferences.getCurrentlong(getApplicationContext())); }
From source file:com.trackdroid.activities.ShowInMapActivity.java
@Override public boolean onMarkerClick(final Marker marker) { if (marker.equals(mPerth)) { // This causes the marker at Perth to bounce into position when it // is clicked. final Handler handler = new Handler(); final long start = SystemClock.uptimeMillis(); final long duration = 1500; final Interpolator interpolator = new BounceInterpolator(); handler.post(new Runnable() { @Override/* w w w. j a v a2 s . c o m*/ public void run() { long elapsed = SystemClock.uptimeMillis() - start; float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0); marker.setAnchor(0.5f, 1.0f + 2 * t); if (t > 0.0) { // Post again 16ms later. handler.postDelayed(this, 16); } } }); } else if (marker.equals(mAdelaide)) { // This causes the marker at Adelaide to change color and alpha. marker.setIcon(BitmapDescriptorFactory.defaultMarker(mRandom.nextFloat() * 360)); marker.setAlpha(mRandom.nextFloat()); } // We return false to indicate that we have not consumed the event and // that we wish // for the default behavior to occur (which is for the camera to move // such that the // marker is centered and for the marker's info window to open, if it // has one). return false; }
From source file:org.chromium.chrome.browser.tabmodel.TabPersistentStore.java
private void restoreTab(TabRestoreDetails tabToRestore, boolean setAsActive) { // As we do this in startup, and restoring the active tab's state is critical, we permit // this read in the event that the prefetch task is not available. Either: // 1. The user just upgraded, has not yet set the new active tab id pref yet. Or // 2. restoreTab is used to preempt async queue and restore immediately on the UI thread. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try {/*ww w . ja v a 2s .co m*/ long time = SystemClock.uptimeMillis(); TabState state; int restoredTabId = mPreferences.getInt(PREF_ACTIVE_TAB_ID, Tab.INVALID_TAB_ID); if (restoredTabId == tabToRestore.id && mPrefetchActiveTabTask != null) { long timeWaitingForPrefetch = SystemClock.uptimeMillis(); state = mPrefetchActiveTabTask.get(); logExecutionTime("RestoreTabPrefetchTime", timeWaitingForPrefetch); } else { // Necessary to do on the UI thread as a last resort. state = TabState.restoreTabState(getStateDirectory(), tabToRestore.id); } logExecutionTime("RestoreTabTime", time); restoreTab(tabToRestore, state, setAsActive); } catch (Exception e) { // Catch generic exception to prevent a corrupted state from crashing the app // at startup. Log.d(TAG, "loadTabs exception: " + e.toString(), e); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
From source file:com.android.yijiang.kzx.widget.betterpickers.radialtimepicker.RadialPickerLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { final float eventX = event.getX(); final float eventY = event.getY(); int degrees;/* w w w . j a v a 2 s.c o m*/ int value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; long millis = SystemClock.uptimeMillis(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = -1; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mHideAmPm) { mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); } else { mIsTouchingAmOrPm = -1; } if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { // If the touch is on AM or PM, set it as "touched" after the tapTimeout // in case the user moves their finger quickly. tryVibrate(); mDownDegrees = -1; mHandler.postDelayed(new Runnable() { @Override public void run() { mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm); mAmPmCirclesView.invalidate(); } }, tapTimeout); } else { // If we're in accessibility mode, force the touch to be legal. Otherwise, // it will only register within the given touch target zone. boolean forceLegal = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); if (mDownDegrees != -1) { // If it's a legal touch, set that number as "selected" after the // tapTimeout in case the user moves their finger quickly. tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } }, tapTimeout); } } return true; case MotionEvent.ACTION_MOVE: if (!mInputEnabled) { // We shouldn't be in this state, because input is disabled. Log.e(TAG, "Input was disabled, but received ACTION_MOVE."); return true; } float dY = Math.abs(eventY - mDownY); float dX = Math.abs(eventX - mDownX); if (!mDoingMove && dX <= touchSlop && dY <= touchSlop) { // Hasn't registered down yet, just slight, accidental movement of finger. break; } // If we're in the middle of touching down on AM or PM, check if we still are. // If so, no-op. If not, remove its pressed state. Either way, no need to check // for touches on the other circle. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { mHandler.removeCallbacksAndMessages(null); int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); if (isTouchingAmOrPm != mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); mIsTouchingAmOrPm = -1; } break; } if (mDownDegrees == -1) { // Original down was illegal, so no movement will register. break; } // We're doing a move along the circle, so move the selection as appropriate. mDoingMove = true; mHandler.removeCallbacksAndMessages(null); degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], false, true); if (value != mLastValueSelected) { tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } } return true; case MotionEvent.ACTION_UP: if (!mInputEnabled) { // If our touch input was disabled, tell the listener to re-enable us. Log.d(TAG, "Input was disabled, but received ACTION_UP."); mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false); return true; } mHandler.removeCallbacksAndMessages(null); mDoingTouch = false; // If we're touching AM or PM, set it as selected, and tell the listener. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); if (isTouchingAmOrPm == mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm); if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) { mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false); setValueForItem(AMPM_INDEX, isTouchingAmOrPm); } } mIsTouchingAmOrPm = -1; break; } // If we have a legal degrees selected, set the value and tell the listener. if (mDownDegrees != -1) { degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false); if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) { int amOrPm = getIsCurrentlyAmOrPm(); if (amOrPm == AM && value == 12) { value = 0; } else if (amOrPm == PM && value != 12) { value += 12; } } setValueForItem(getCurrentItemShowing(), value); mListener.onValueSelected(getCurrentItemShowing(), value, true); } } mDoingMove = false; return true; default: break; } return false; }
From source file:com.fastbootmobile.encore.app.MainActivity.java
@Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { long delay = (hourOfDay * 3600L + minute * 60L) * 1000L; PlaybackProxy.setSleepTimer(SystemClock.uptimeMillis() + delay); Toast.makeText(this, getString(R.string.sleep_timer_confirm_toast, hourOfDay, minute), Toast.LENGTH_LONG) .show();/*from w ww .j a v a 2 s. c o m*/ }
From source file:com.lesikapk.opengelplus.Folder.java
public void onDragOver(DragObject d) { final DragView dragView = d.dragView; final int scrollOffset = mScrollView.getScrollY(); final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null); r[0] -= getPaddingLeft();// w w w.j a v a 2 s . com r[1] -= getPaddingTop(); final long downTime = SystemClock.uptimeMillis(); final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0); /*if (!mAutoScrollHelper.isEnabled()) { mAutoScrollHelper.setEnabled(true); } final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv); translatedEv.recycle(); if (handled) { mReorderAlarm.cancelAlarm(); } else {*/ mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell); if (isLayoutRtl()) { mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1; } if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { mReorderAlarm.cancelAlarm(); mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); mReorderAlarm.setAlarm(REORDER_DELAY); mPreviousTargetCell[0] = mTargetCell[0]; mPreviousTargetCell[1] = mTargetCell[1]; mDragMode = DRAG_MODE_REORDER; } else { mDragMode = DRAG_MODE_NONE; } // } }
From source file:com.sleepbot.datetimepicker.time.RadialPickerLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { final float eventX = event.getX(); final float eventY = event.getY(); int degrees;//from w w w . jav a 2s. c o m int value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; long millis = SystemClock.uptimeMillis(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = -1; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mHideAmPm) { mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); } else { mIsTouchingAmOrPm = -1; } if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT // in case the user moves their finger quickly. tryVibrate(); mDownDegrees = -1; mHandler.postDelayed(new Runnable() { @Override public void run() { mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm); mAmPmCirclesView.invalidate(); } }, TAP_TIMEOUT); } else { // If we're in accessibility mode, force the touch to be legal. Otherwise, // it will only register within the given touch target zone. boolean forceLegal = false; // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); if (mDownDegrees != -1) { // If it's a legal touch, set that number as "selected" after the // TAP_TIMEOUT in case the user moves their finger quickly. tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } }, TAP_TIMEOUT); } } return true; case MotionEvent.ACTION_MOVE: if (!mInputEnabled) { // We shouldn't be in this state, because input is disabled. Log.e(TAG, "Input was disabled, but received ACTION_MOVE."); return true; } float dY = Math.abs(eventY - mDownY); float dX = Math.abs(eventX - mDownX); if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) { // Hasn't registered down yet, just slight, accidental movement of finger. break; } // If we're in the middle of touching down on AM or PM, check if we still are. // If so, no-op. If not, remove its pressed state. Either way, no need to check // for touches on the other circle. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { mHandler.removeCallbacksAndMessages(null); int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); if (isTouchingAmOrPm != mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); mIsTouchingAmOrPm = -1; } break; } if (mDownDegrees == -1) { // Original down was illegal, so no movement will register. break; } // We're doing a move along the circle, so move the selection as appropriate. mDoingMove = true; mHandler.removeCallbacksAndMessages(null); degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], false, true); if (value != mLastValueSelected) { tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } } return true; case MotionEvent.ACTION_UP: if (!mInputEnabled) { // If our touch input was disabled, tell the listener to re-enable us. Log.d(TAG, "Input was disabled, but received ACTION_UP."); mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false); return true; } mHandler.removeCallbacksAndMessages(null); mDoingTouch = false; // If we're touching AM or PM, set it as selected, and tell the listener. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); if (isTouchingAmOrPm == mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm); if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) { mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false); setValueForItem(AMPM_INDEX, isTouchingAmOrPm); } } mIsTouchingAmOrPm = -1; break; } // If we have a legal degrees selected, set the value and tell the listener. if (mDownDegrees != -1) { degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false); if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) { int amOrPm = getIsCurrentlyAmOrPm(); if (amOrPm == AM && value == 12) { value = 0; } else if (amOrPm == PM && value != 12) { value += 12; } } setValueForItem(getCurrentItemShowing(), value); mListener.onValueSelected(getCurrentItemShowing(), value, true); } } mDoingMove = false; return true; default: break; } return false; }
From source file:saphion.fragments.alarm.AlarmFragment.java
private void showLabelDialog(final Alarm alarm) { /*/* w ww.ja v a2 s .com*/ * final FragmentTransaction ft = * getFragmentManager().beginTransaction(); final Fragment prev = * getFragmentManager().findFragmentByTag( "label_dialog"); if (prev != * null) { ft.remove(prev); } ft.addToBackStack(null); * * // Create and show the dialog. final LabelDialogFragment newFragment * = LabelDialogFragment .newInstance(alarm, alarm.label, getTag()); * newFragment.show(ft, "label_dialog"); */ AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext()); builder.setTitle("Enter Label"); View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.label_picker, null); final EditText picker = (EditText) view.findViewById(R.id.labelPicker); picker.setText(alarm.label); picker.selectAll(); (new Handler()).postDelayed(new Runnable() { @SuppressLint("Recycle") public void run() { picker.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 0, 0, 0)); picker.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 0, 0, 0)); picker.selectAll(); } }, 200); builder.setView(view); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setLabel(alarm, picker.getText().toString()); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); }
From source file:cc.flydev.launcher.Folder.java
public void onDragOver(DragObject d) { final DragView dragView = d.dragView; final int scrollOffset = mScrollView.getScrollY(); final float[] r = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, dragView, null); r[0] -= getPaddingLeft();// w w w. ja v a 2s. c om r[1] -= getPaddingTop(); final long downTime = SystemClock.uptimeMillis(); final MotionEvent translatedEv = MotionEvent.obtain(downTime, downTime, MotionEvent.ACTION_MOVE, d.x, d.y, 0); if (!mAutoScrollHelper.isEnabled()) { mAutoScrollHelper.setEnabled(true); } final boolean handled = mAutoScrollHelper.onTouch(this, translatedEv); translatedEv.recycle(); if (handled) { mReorderAlarm.cancelAlarm(); } else { mTargetCell = mContent.findNearestArea((int) r[0], (int) r[1] + scrollOffset, 1, 1, mTargetCell); if (isLayoutRtl()) { mTargetCell[0] = mContent.getCountX() - mTargetCell[0] - 1; } if (mTargetCell[0] != mPreviousTargetCell[0] || mTargetCell[1] != mPreviousTargetCell[1]) { mReorderAlarm.cancelAlarm(); mReorderAlarm.setOnAlarmListener(mReorderAlarmListener); mReorderAlarm.setAlarm(REORDER_DELAY); mPreviousTargetCell[0] = mTargetCell[0]; mPreviousTargetCell[1] = mTargetCell[1]; mDragMode = DRAG_MODE_REORDER; } else { mDragMode = DRAG_MODE_NONE; } } }