Java Code Examples for android.os.SystemClock
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project 2Degrees-Toolbox, under directory /ActionBarSherlock/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft,getPaddingTop() + mIndeterminateRealTop); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }
Example 2
From project 4308Cirrus, under directory /Extras/actionbarsherlock/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft,getPaddingTop() + mIndeterminateRealTop); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }
Example 3
From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft,getPaddingTop() + mIndeterminateRealTop); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }
Example 4
From project adg-android, under directory /src/com/analysedesgeeks/android/.
Source file: AbstractPodcastActivity.java

@Override public void onProgressChanged(final SeekBar bar,final int progress,final boolean fromuser){ if (!fromuser || (mService == null)) { return; } final long now=SystemClock.elapsedRealtime(); if ((now - mLastSeekEventTime) > 250) { mLastSeekEventTime=now; mPosOverride=mDuration * progress / 1000; try { mService.seek(mPosOverride); } catch ( final RemoteException ex) { } if (!mFromTouch) { refreshNow(); mPosOverride=-1; } } }
Example 5
From project Airports, under directory /src/com/nadmm/airports/views/.
Source file: ImageZoomView.java

/** * Release control and start pan fling animation * @param vx Velocity in x-dimension * @param vy Velocity in y-dimension */ public void startFling(float vx,float vy){ final float aspectQuotient=mAspectQuotient.get(); final long now=SystemClock.uptimeMillis(); mPanDynamicsX.setState(mState.getPanX(),vx / mState.getZoomX(aspectQuotient),now); mPanDynamicsY.setState(mState.getPanY(),vy / mState.getZoomY(aspectQuotient),now); mPanDynamicsX.setMinPosition(mPanMinX); mPanDynamicsX.setMaxPosition(mPanMaxX); mPanDynamicsY.setMinPosition(mPanMinY); mPanDynamicsY.setMaxPosition(mPanMaxY); mHandler.post(mUpdateRunnable); }
Example 6
From project Amantech, under directory /Android/action_bar_sherlock/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft,getPaddingTop() + mIndeterminateRealTop); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }
Example 7
From project andlytics, under directory /actionbarsherlock/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft,getPaddingTop() + mIndeterminateRealTop); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }
Example 8
From project android-async-http, under directory /src/com/loopj/android/http/.
Source file: RetryHandler.java

public boolean retryRequest(IOException exception,int executionCount,HttpContext context){ boolean retry=true; Boolean b=(Boolean)context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent=(b != null && b.booleanValue()); if (executionCount > maxRetries) { retry=false; } else if (exceptionBlacklist.contains(exception.getClass())) { retry=false; } else if (exceptionWhitelist.contains(exception.getClass())) { retry=true; } else if (!sent) { retry=true; } if (retry) { HttpUriRequest currentReq=(HttpUriRequest)context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType=currentReq.getMethod(); retry=!requestType.equals("POST"); } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
Example 9
From project Android-automation, under directory /Tmts_Java/src/com/taobao/tmts/framework/.
Source file: TmtsTestCase.java

/** * @deprecated This method does not work anyway. * @param xStart * @param yStart * @param xEnd * @param yEnd */ public void scrollScreen(float xStart,float yStart,float xEnd,float yEnd){ Log.i(LOG_TAG,"scrollScreen"); MotionEvent e=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,xStart,yStart,0); inst.sendPointerSync(e); e=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_MOVE,xStart,yStart,0); inst.sendPointerSync(e); e=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_MOVE,xStart,yStart,0); inst.sendPointerSync(e); e=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_MOVE,xEnd,yEnd,0); inst.sendPointerSync(e); e=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_MOVE,xEnd,yEnd,0); inst.sendPointerSync(e); e=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,xEnd,yEnd,0); inst.sendPointerSync(e); Log.i(LOG_TAG,"scrollScreen finish"); }
Example 10
From project android-bankdroid, under directory /src/com/liato/bankdroid/.
Source file: LockableActivity.java

@Override protected void onPause(){ super.onPause(); if (!mLockPatternUtils.isLockPatternEnabled()) return; if (mHasLoaded) { writeLockTime(); } else { writeLockTime(SystemClock.elapsedRealtime() - 10000); } }
Example 11
From project android-context, under directory /src/edu/fsu/cs/contextprovider/.
Source file: PrefsActivity.java

@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,String key){ if (key.equals(ContextConstants.PREFS_ACCURACY_POPUP_ENABLED) || key.equals(ContextConstants.PREFS_ACCURACY_POPUP_FREQ)) { if (DEBUG) { Toast.makeText(this,"ACCURACY_POPUP changed",Toast.LENGTH_SHORT).show(); } boolean accuracyPopupEnabled=prefs.getBoolean(ContextConstants.PREFS_ACCURACY_POPUP_ENABLED,true); String accuracyPopupPeriod=prefs.getString(ContextConstants.PREFS_ACCURACY_POPUP_FREQ,"45"); int period=Integer.parseInt(accuracyPopupPeriod); if (DEBUG) { Log.d(TAG,"accuracyPopupPeriod: " + accuracyPopupPeriod + " period: "+ period); } AlarmManager manager=(AlarmManager)getSystemService(Context.ALARM_SERVICE); Intent intent=new Intent(getBaseContext(),edu.fsu.cs.contextprovider.wakeup.WakeupAlarmReceiver.class); PendingIntent pi=PendingIntent.getBroadcast(getBaseContext(),0,intent,0); if (accuracyPopupEnabled) { manager.cancel(pi); manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,SystemClock.elapsedRealtime() + 10000,period * 1000,pi); } else { manager.cancel(pi); } } }
Example 12
From project android-database-sqlcipher, under directory /src/net/sqlcipher/database/.
Source file: SQLiteDatabase.java

/** * Locks the database for exclusive access. The database lock must be held when touch the native sqlite3* object since it is single threaded and uses a polling lock contention algorithm. The lock is recursive, and may be acquired multiple times by the same thread. This is a no-op if mLockingEnabled is false. * @see #unlock() */ void lock(){ if (!mLockingEnabled) return; mLock.lock(); if (SQLiteDebug.DEBUG_LOCK_TIME_TRACKING) { if (mLock.getHoldCount() == 1) { mLockAcquiredWallTime=SystemClock.elapsedRealtime(); mLockAcquiredThreadTime=Debug.threadCpuTimeNanos(); } } }
Example 13
From project Android-GifStitch, under directory /src/com/phunkosis/gifstitch/helpers/.
Source file: VariableAnimationDrawable.java

@Override public void run(){ int n=this.getNumberOfFrames(); this.currentFrame++; if (this.currentFrame >= n) this.currentFrame=0; this.selectDrawable(currentFrame); this.scheduleSelf(this,SystemClock.uptimeMillis() + this.duration); }
Example 14
From project android-gltron, under directory /GlTron/src/com/glTron/Game/.
Source file: GLTronGame.java

private void ResetTime(){ TimeLastFrame=SystemClock.uptimeMillis(); TimeCurrent=TimeLastFrame; TimeDt=0; DtHead=0; DtElements=0; }
Example 15
From project Android-MapForgeFragment, under directory /library-common/src/com/jakewharton/android/mapsforge_fragment/.
Source file: MapMover.java

/** * Handles a "move down" event. */ void moveDown(){ if (this.moveY > 0) { this.moveY=0; } else if (this.moveY == 0) { this.moveY=-MOVE_SPEED * this.mapView.getMoveSpeed(); this.timePrevious=SystemClock.uptimeMillis(); synchronized (this) { notify(); } } }
Example 16
From project android-marvin, under directory /marvin/src/main/java/de/akquinet/android/marvin/actions/.
Source file: BaseAction.java

public void click(float x,float y){ MotionEvent downEvent=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_DOWN,x,y,0); MotionEvent upEvent=MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(),MotionEvent.ACTION_UP,x,y,0); try { instrumentation.sendPointerSync(downEvent); instrumentation.sendPointerSync(upEvent); } catch ( SecurityException e) { Assert.fail("Click on (" + x + ","+ y+ ") failed."); } }
Example 17
From project android-thaiime, under directory /latinime/src/com/android/inputmethod/accessibility/.
Source file: AccessibilityUtils.java

/** * Sends the specified text to the {@link AccessibilityManager} to bespoken. * @param text the text to speak */ public void speak(CharSequence text){ if (!mAccessibilityManager.isEnabled()) { Log.e(TAG,"Attempted to speak when accessibility was disabled!"); return; } final AccessibilityEvent event=AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED); event.setPackageName(PACKAGE); event.setClassName(CLASS); event.setEventTime(SystemClock.uptimeMillis()); event.setEnabled(true); event.getText().add(text); mAccessibilityManager.sendAccessibilityEvent(event); }
Example 18
From project android-xbmcremote, under directory /src/org/xbmc/android/remote/presentation/drawable/.
Source file: CrossFadeDrawable.java

/** * Reverses the transition, picking up where the transition currently is. If the transition is not currently running, this will start the transition with the specified duration. If the transition is already running, the last known duration will be used. * @param duration The duration to use if no transition is running. */ public void reverseTransition(int duration){ final long time=SystemClock.uptimeMillis(); if (time - mStartTimeMillis > mOriginalDuration) { if (mAlpha == 0) { mFrom=0; mTo=255; mAlpha=0; mReverse=false; } else { mFrom=255; mTo=0; mAlpha=255; mReverse=true; } mDuration=mOriginalDuration=duration; mTransitionState=TRANSITION_STARTING; mHandler.post(mInvalidater); return; } mReverse=!mReverse; mFrom=mAlpha; mTo=mReverse ? 0 : 255; mDuration=(int)(mReverse ? time - mStartTimeMillis : mOriginalDuration - (time - mStartTimeMillis)); mTransitionState=TRANSITION_STARTING; }
Example 19
From project AndroidCommon, under directory /src/com/asksven/android/common/kernelutils/.
Source file: CpuStates.java

public static ArrayList<State> getTimesInStates(){ ArrayList<State> states=new ArrayList<State>(); long totalTime=0; try { InputStream is=new FileInputStream(TIME_IN_STATE_PATH); InputStreamReader ir=new InputStreamReader(is); BufferedReader br=new BufferedReader(ir); String line; while ((line=br.readLine()) != null) { String[] nums=line.split(" "); State myState=new State(Integer.parseInt(nums[0]),Long.parseLong(nums[1]) * 10); totalTime+=myState.m_duration; states.add(myState); } is.close(); } catch ( Exception e) { Log.e(TAG,e.getMessage()); return null; } long sleepTime=SystemClock.elapsedRealtime() - SystemClock.uptimeMillis(); states.add(new State(0,sleepTime)); totalTime+=sleepTime; for (int i=0; i < states.size(); i++) { states.get(i).setTotal(totalTime); } return states; }
Example 20
From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/drawable/.
Source file: CrossFadeDrawable.java

/** * Reverses the transition, picking up where the transition currently is. If the transition is not currently running, this will start the transition with the specified duration. If the transition is already running, the last known duration will be used. * @param duration The duration to use if no transition is running. */ public void reverseTransition(int duration){ final long time=SystemClock.uptimeMillis(); if (time - mStartTimeMillis > mOriginalDuration) { if (mAlpha == 0) { mFrom=0; mTo=255; mAlpha=0; mReverse=false; } else { mFrom=255; mTo=0; mAlpha=255; mReverse=true; } mDuration=mOriginalDuration=duration; mTransitionState=TRANSITION_STARTING; mHandler.post(mInvalidater); return; } mReverse=!mReverse; mFrom=mAlpha; mTo=mReverse ? 0 : 255; mDuration=(int)(mReverse ? time - mStartTimeMillis : mOriginalDuration - (time - mStartTimeMillis)); mTransitionState=TRANSITION_STARTING; }
Example 21
From project androidZenWriter, under directory /library/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft,getPaddingTop() + mIndeterminateRealTop); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }
Example 22
From project android_7, under directory /src/org/immopoly/android/widget/.
Source file: ViewPager.java

/** * Start a fake drag of the pager. <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; 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; }
Example 23
From project android_aosp_packages_apps_Settings, under directory /src/com/android/settings/applications/.
Source file: ApplicationsState.java

ArrayList<AppEntry> rebuild(AppFilter filter,Comparator<AppEntry> comparator){ synchronized (mRebuildSync) { mRebuildRequested=true; mRebuildAsync=false; mRebuildFilter=filter; mRebuildComparator=comparator; mRebuildResult=null; if (!mBackgroundHandler.hasMessages(BackgroundHandler.MSG_REBUILD_LIST)) { mBackgroundHandler.sendEmptyMessage(BackgroundHandler.MSG_REBUILD_LIST); } long waitend=SystemClock.uptimeMillis() + 250; while (mRebuildResult == null) { long now=SystemClock.uptimeMillis(); if (now >= waitend) { break; } try { mRebuildSync.wait(waitend - now); } catch ( InterruptedException e) { } } mRebuildAsync=true; return mRebuildResult; } }
Example 24
From project android_packages_apps_cmparts, under directory /src/com/cyanogenmod/cmparts/activities/.
Source file: ColorPickerDialog.java

@Override protected boolean onLevelChange(int level){ if (level < 4000 && mDelta <= 0) { mDelta=1; mAnimation.startScrolling(mTextXScale,1); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } else if (level > 6000 && mDelta >= 0) { mDelta=-1; mAnimation.startScrolling(mTextXScale,0); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } return mProgress.setLevel(level); }
Example 25
From project android_packages_apps_CMSettings, under directory /src/com/cyanogenmod/settings/activities/.
Source file: ColorPickerDialog.java

@Override protected boolean onLevelChange(int level){ if (level < 4000 && mDelta <= 0) { mDelta=1; mAnimation.startScrolling(mTextXScale,1); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } else if (level > 6000 && mDelta >= 0) { mDelta=-1; mAnimation.startScrolling(mTextXScale,0); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } return mProgress.setLevel(level); }
Example 26
From project android_packages_apps_FileManager, under directory /src/org/openintents/filemanager/.
Source file: DirectoryScanner.java

private void updateProgress(int progress,int maxProgress){ if ((progress % PROGRESS_STEPS) == 0) { long curTime=SystemClock.uptimeMillis(); if (curTime - operationStartTime < 1000L) { return; } Message msg=handler.obtainMessage(FileManagerActivity.MESSAGE_SET_PROGRESS); msg.arg1=progress; msg.arg2=maxProgress; msg.sendToTarget(); } }
Example 27
From project android_packages_apps_Gallery, under directory /src/com/android/camera/.
Source file: Camera.java

private void startPreview() throws CameraHardwareException { if (mPausing || isFinishing()) return; ensureCameraDevice(); if (mPreviewing) stopPreview(); setPreviewDisplay(mSurfaceHolder); setCameraParameters(); final long wallTimeStart=SystemClock.elapsedRealtime(); final long threadTimeStart=Debug.threadCpuTimeNanos(); mCameraDevice.setOneShotPreviewCallback(mOneShotPreviewCallback); mCameraDevice.setErrorCallback(mErrorCallback); try { Log.v(TAG,"startPreview"); mCameraDevice.startPreview(); } catch ( Throwable ex) { closeCamera(); throw new RuntimeException("startPreview failed",ex); } mPreviewing=true; mStatus=IDLE; long threadTimeEnd=Debug.threadCpuTimeNanos(); long wallTimeEnd=SystemClock.elapsedRealtime(); if ((wallTimeEnd - wallTimeStart) > 3000) { Log.w(TAG,"startPreview() to " + (wallTimeEnd - wallTimeStart) + " ms. Thread time was"+ (threadTimeEnd - threadTimeStart) / 1000000 + " ms."); } }
Example 28
From project android_packages_apps_Gallery2, under directory /src/com/android/gallery3d/app/.
Source file: EyePosition.java

private void onGyroscopeChanged(float gx,float gy,float gz){ long now=SystemClock.elapsedRealtime(); float distance=(gx > 0 ? gx : -gx) + (gy > 0 ? gy : -gy); if (distance < GYROSCOPE_THRESHOLD || distance > GYROSCOPE_LIMIT || mGyroscopeCountdown > 0) { --mGyroscopeCountdown; mStartTime=now; float limit=mUserDistance / 20f; if (mX > limit || mX < -limit || mY > limit || mY < -limit) { mX*=GYROSCOPE_RESTORE_FACTOR; mY*=GYROSCOPE_RESTORE_FACTOR; mZ=(float)-Math.sqrt(mUserDistance * mUserDistance - mX * mX - mY * mY); mListener.onEyePositionChanged(mX,mY,mZ); } return; } float t=(now - mStartTime) / 1000f * mUserDistance * (-mZ); mStartTime=now; float x=-gy, y=-gx; switch (mDisplay.getRotation()) { case Surface.ROTATION_90: x=-gx; y=gy; break; case Surface.ROTATION_180: x=gy; y=gx; break; case Surface.ROTATION_270: x=gx; y=-gy; break; } mX=Utils.clamp((float)(mX + x * t / Math.hypot(mZ,mX)),-mLimit,mLimit) * GYROSCOPE_RESTORE_FACTOR; mY=Utils.clamp((float)(mY + y * t / Math.hypot(mZ,mY)),-mLimit,mLimit) * GYROSCOPE_RESTORE_FACTOR; mZ=-FloatMath.sqrt(mUserDistance * mUserDistance - mX * mX - mY * mY); mListener.onEyePositionChanged(mX,mY,mZ); }
Example 29
From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/cache/.
Source file: CacheService.java

private static final byte[] queryThumbnail(final Context context,final long thumbId,final long origId,final boolean isVideo,final DiskCache thumbnailCache,final long timestamp){ if (!App.get(context).isPaused()) { final Thread thumbnailThread=THUMBNAIL_THREAD.getAndSet(null); if (thumbnailThread != null) { thumbnailThread.interrupt(); } } byte[] bitmap=thumbnailCache.get(thumbId,timestamp); if (bitmap == null) { final long time=SystemClock.uptimeMillis(); bitmap=buildThumbnailForId(context,thumbnailCache,thumbId,origId,isVideo,DEFAULT_THUMBNAIL_WIDTH,DEFAULT_THUMBNAIL_HEIGHT,timestamp); if (DEBUG) Log.i(TAG,"Built thumbnail and screennail for " + origId + " in "+ (SystemClock.uptimeMillis() - time)); } return bitmap; }
Example 30
From project android_packages_apps_Nfc, under directory /src/com/android/nfc/handover/.
Source file: BluetoothOppHandover.java

/** * Main entry point. This method is usually called after construction, to begin the BT sequence. Must be called on Main thread. */ public void start(){ mStartTime=SystemClock.elapsedRealtime(); IntentFilter filter=new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); mContext.registerReceiver(mReceiver,filter); if (!mHandoverPowerManager.isBluetoothEnabled()) { if (mHandoverPowerManager.enableBluetooth()) { mState=STATE_TURNING_ON; } else { Toast.makeText(mContext,mContext.getString(R.string.beam_failed),Toast.LENGTH_SHORT).show(); complete(); } } else { if (mRemoteActivating) { mHandler.sendEmptyMessageDelayed(MSG_START_SEND,REMOTE_BT_ENABLE_DELAY_MS); } else { sendIntent(); } } }
Example 31
From project android_packages_apps_phone, under directory /src/com/android/phone/.
Source file: CallTime.java

void periodicUpdateTimer(){ if (!mTimerRunning) { mTimerRunning=true; long now=SystemClock.uptimeMillis(); long nextReport=mLastReportedTime + mInterval; while (now >= nextReport) { nextReport+=mInterval; } if (DBG) log("periodicUpdateTimer() @ " + nextReport); postAtTime(mTimerCallback,nextReport); mLastReportedTime=nextReport; if (mCall != null) { Call.State state=mCall.getState(); if (state == Call.State.ACTIVE) { updateElapsedTime(mCall); } } if (PROFILE && isTraceReady()) { startTrace(); } } else { if (DBG) log("periodicUpdateTimer: timer already running, bail"); } }
Example 32
From project android_packages_apps_QuickSearchBox, under directory /src/com/android/quicksearchbox/.
Source file: SearchWidgetProvider.java

private static void rescheduleAction(Context context,boolean reschedule,String action,long period){ AlarmManager alarmManager=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); PendingIntent intent=createBroadcast(context,action); alarmManager.cancel(intent); if (reschedule) { if (DBG) Log.d(TAG,"Scheduling action " + action + " after period "+ period); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME,SystemClock.elapsedRealtime() + period,period,intent); } else { if (DBG) Log.d(TAG,"Cancelled action " + action); } }
Example 33
From project android_packages_apps_SalvageParts, under directory /src/com/salvagemod/salvageparts/activities/.
Source file: ColorPickerDialog.java

@Override protected boolean onLevelChange(int level){ if (level < 4000 && mDelta <= 0) { mDelta=1; mAnimation.startScrolling(mTextXScale,1); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } else if (level > 6000 && mDelta >= 0) { mDelta=-1; mAnimation.startScrolling(mTextXScale,0); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } return mProgress.setLevel(level); }
Example 34
From project android_packages_apps_TouchWiz30Launcher, under directory /src/com/sec/android/app/twlauncher/.
Source file: AppShortcutZone.java

public void drawBg(boolean flag,boolean flag1){ mIsDrawBg=flag; if (flag1) { mAnimationDuration=500; mAnimationStartTime=SystemClock.uptimeMillis(); if (mIsDrawBg) { mAnimationState=1; mAnimationFrom=0.0F; mAnimationTo=1.0F; mInterpolator=mOpenInterpolator; } else { mAnimationState=1; mAnimationFrom=1.0F; mAnimationTo=0.0F; mInterpolator=mCloseInterpolator; } } else { mAnimationState=3; } invalidate(); }
Example 35
From project android_packages_inputmethods_LatinIME, under directory /java/src/com/android/inputmethod/accessibility/.
Source file: AccessibilityUtils.java

/** * Sends the specified text to the {@link AccessibilityManager} to bespoken. * @param text the text to speak */ public void speak(CharSequence text){ if (!mAccessibilityManager.isEnabled()) { Log.e(TAG,"Attempted to speak when accessibility was disabled!"); return; } final AccessibilityEvent event=AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED); event.setPackageName(PACKAGE); event.setClassName(CLASS); event.setEventTime(SystemClock.uptimeMillis()); event.setEnabled(true); event.getText().add(text); mAccessibilityManager.sendAccessibilityEvent(event); }
Example 36
From project android_packages_wallpapers_MusicVisualization, under directory /src/com/android/musicvis/.
Source file: GenericWaveRS.java

@Override public void start(){ super.start(); mVisible=true; if (mAudioCapture != null) { mAudioCapture.start(); } SystemClock.sleep(200); updateWave(); }
Example 37
From project android_wallpaper_flier, under directory /src/fi/harism/wallpaper/flier/.
Source file: FlierClouds.java

/** * Called from renderer once surface has changed. * @param width Width in pixels. * @param height Height in pixels. */ public void onSurfaceChanged(int width,int height){ mAspectRatioX=(float)Math.min(width,height) / width; mAspectRatioY=(float)Math.min(width,height) / height; Matrix.frustumM(mProjM,0,-mAspectRatioX,mAspectRatioX,-mAspectRatioY,mAspectRatioY,ZNEAR,ZFAR); final float projInvM[]=new float[16]; Matrix.invertM(projInvM,0,mProjM,0); unproject(projInvM,mRectNear,-1); unproject(projInvM,mRectFar,1); mRectNear.right+=X_OFFSET_MULTIPLIER; mRectFar.right+=X_OFFSET_MULTIPLIER; for ( StructCloud cloud : mClouds) { genRandCloud(cloud); cloud.mXOffset=rand(cloud.mViewRect.left,cloud.mViewRect.right); } sortClouds(); mRenderTime=SystemClock.uptimeMillis(); }
Example 38
From project android_wallpaper_flowers, under directory /src/fi/harism/wallpaper/flowers/.
Source file: FlowerObjects.java

/** * Renders flowers into scene. * @param offset Global offset value. */ public void onDrawFrame(PointF offset){ GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA,GLES20.GL_ONE_MINUS_SRC_ALPHA); long renderTime=SystemClock.uptimeMillis(); for (int i=0; i < mFlowerElements.length; ++i) { mContainerPoint.clear(); mContainerSpline.clear(); ElementFlower flower=mFlowerElements[i]; update(flower,renderTime,offset); flower.getRenderStructs(mContainerSpline,mContainerPoint,renderTime); renderSplines(mContainerSpline,flower.mColor,offset); renderFlowers(mContainerPoint,flower.mColor,offset); } GLES20.glDisable(GLES20.GL_BLEND); }
Example 39
/** * Starts the repeating Alarm that sends the fetch Intent. */ private boolean scheduleRepeatingAlarm(){ final AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE); final PendingIntent pIntent=getRepeatingIntent(); final int frequencyMs=getFetchFrequencyS(); final long firstTime=SystemClock.elapsedRealtime() + frequencyMs; am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime,frequencyMs,pIntent); MyLog.d(TAG,"Started repeating alarm in a " + frequencyMs + "ms rhythm."); return true; }
Example 40
From project andtweet, under directory /src/com/xorcode/andtweet/.
Source file: AndTweetService.java

/** * Starts the repeating Alarm that sends the fetch Intent. */ private boolean scheduleRepeatingAlarm(){ final AlarmManager am=(AlarmManager)getSystemService(Context.ALARM_SERVICE); final PendingIntent pIntent=getRepeatingIntent(); final int frequencyMs=getFetchFrequencyS(); final long firstTime=SystemClock.elapsedRealtime() + frequencyMs; am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,firstTime,frequencyMs,pIntent); d(TAG,"Started repeating alarm in a " + frequencyMs + "ms rhythm."); return true; }
Example 41
@Override public void onPostExecute(DeckTask.TaskData result){ mFlipCard.setChecked(false); if (mPrefWhiteboard) { mWhiteboard.clear(); } if (mPrefTimer) { mCardTimer.setBase(SystemClock.elapsedRealtime()); mCardTimer.start(); } mProgressDialog.dismiss(); }
Example 42
From project AnySoftKeyboard, under directory /src/com/anysoftkeyboard/.
Source file: AnySoftKeyboard.java

public void updateShiftKeyState(EditorInfo attr){ mHandler.removeMessages(MSG_UPDATE_SHIFT_STATE); InputConnection ic=getCurrentInputConnection(); if (ic != null && attr != null && mKeyboardSwitcher.isAlphabetMode() && (mInputView != null)) { final boolean inputSaysCaps=getCursorCapsMode(ic,attr) != 0; if (inputSaysCaps) mShiftStartTime=SystemClock.elapsedRealtime(); mInputView.setShifted(mShiftKeyState.isMomentary() || mCapsLock || inputSaysCaps); } }
Example 43
From project apps-for-android, under directory /DivideAndConquer/src/com/google/android/divideandconquer/.
Source file: DivideAndConquerActivity.java

/** * Go to the next level * @param ballEngine The ball engine. */ private void levelUp(final BallEngine ballEngine){ mNumBalls++; updatePercentDisplay(0); updateLevelDisplay(mNumBalls); ballEngine.reset(SystemClock.elapsedRealtime(),mNumBalls); mBallsView.setMode(DivideAndConquerView.Mode.Bouncing); if (mNumBalls % 4 == 0) { mNumLives++; updateLivesDisplay(mNumLives); showToast("bonus life!"); } if (mNumBalls == 10) { showToast("Level 10? You ROCK!"); } else if (mNumBalls == 15) { showToast("BALLS TO THE WALL!"); } }
Example 44
From project AquaNotesTest, under directory /src/com/google/android/apps/iosched/ui/.
Source file: SessionsFragment.java

public void run(){ if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } long nextQuarterHour=(SystemClock.uptimeMillis() / 900000 + 1) * 900000 + 5000; mMessageQueueHandler.postAtTime(mRefreshSessionsRunnable,nextQuarterHour); }
Example 45
From project Barcamp-Bangalore-Android-App, under directory /slidingmenu/library/src/com/slidingmenu/lib/.
Source file: CustomViewAbove.java

/** * Start a fake drag of the pager. <p>A fake drag can be useful if you want to synchronize the motion of the CustomViewPager with the touch scrolling of another view, while still letting the CustomViewPager 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 CustomViewPager 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; 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; }
Example 46
From project BF3-Battlelog, under directory /src/com/ninetwozero/battlelog/asynctask/.
Source file: AsyncLogin.java

@Override protected Boolean doInBackground(PostData... arg0){ try { ProfileInformation profileInformation=doLogin(arg0); ProfileData profileData=new ProfileData.Builder(profileInformation.getUserId(),profileInformation.getUsername()).persona(profileInformation.getAllPersonas()).build(); mSessionKeeperPackage=new SessionKeeperPackage(profileData,profileInformation.getPlatoons()); publishProgress(1); SystemClock.sleep(2000); return (mSessionKeeperPackage != null); } catch ( WebsiteHandlerException ex) { mErrorMessage=ex.getMessage(); return false; } catch ( Exception ex) { mErrorMessage=mContext.getString(R.string.general_no_data); return false; } }
Example 47
From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.
Source file: FastScroller.java

int getAlpha(){ if (getState() != STATE_EXIT) { return ALPHA_MAX; } int alpha; long now=SystemClock.uptimeMillis(); if (now > mStartTime + mFadeDuration) { alpha=0; } else { alpha=(int)(ALPHA_MAX - ((now - mStartTime) * ALPHA_MAX) / mFadeDuration); } return alpha; }
Example 48
From project box-android-sdk, under directory /BoxAndroidLibrary/src/com/box/androidlib/FileTransfer/.
Source file: BoxFileUpload.java

@Override public void write(final byte[] buffer,final int offset,final int length) throws IOException { out.write(buffer,offset,length); bytesBransferred+=length; long currTime=SystemClock.uptimeMillis(); if (mProgresslistener != null && currTime - lastOnProgressPost > ON_PROGRESS_UPDATE_THRESHOLD) { lastOnProgressPost=currTime; mProgresslistener.onTransferred(bytesBransferred); } if (Thread.currentThread().isInterrupted()) { throw new IOException(FileUploadListener.STATUS_CANCELLED); } }
Example 49
From project btmidi, under directory /BluetoothMidiPlayer/src/com/noisepages/nettoyeur/midi/player/.
Source file: BluetoothMidiPlayerService.java

MidiRunnable(Iterator<CompoundMidiEvent> events,HandlerThread thread){ this.handler=new Handler(thread.getLooper()); this.events=events; currentEvent=events.next(); t0=SystemClock.uptimeMillis() - currentEvent.timeInMillis + 250; }
Example 50
From project Cafe, under directory /testrunner/src/com/baidu/cafe/local/.
Source file: LocalLib.java

/** * send a Multi-Touch Motion Event * @param pointerNumber the number of pointer * @param start the start position e.g. new int[]{0,0,1,2}; means two pointers start at {0,0} and {1,2} * @param end the end position e.g. new int[]{100,110,200,220}; means two pointers end at {100,110} and {200,220} * @param step the move step * @param downDelay the delay after down event was sent * @param moveDelay the delay after each move event was sent * @param upDelay the delay before sending up event */ public void sendMultiTouchMotionEvent(int pointerNumber,int[] start,int[] end,int step,int downDelay,int moveDelay,int upDelay){ double[] delta=new double[pointerNumber * 2]; int[] pointerIds=new int[pointerNumber]; PointerCoords[] pointerPositions=new PointerCoords[pointerNumber]; int temp=0; for (int i=0; i < pointerNumber; i++) { pointerPositions[i]=new PointerCoords(); pointerPositions[i].pressure=1.0f; temp=i * 2; delta[temp]=(end[temp] - start[temp]) / (double)step; pointerPositions[i].x=start[temp]; temp++; delta[temp]=(end[temp] - start[temp]) / (double)step; pointerPositions[i].y=start[temp]; pointerIds[i]=i; } long myTime=SystemClock.uptimeMillis(); mInstrumentation.sendPointerSync(MotionEvent.obtain(myTime,myTime,MotionEvent.ACTION_DOWN,pointerNumber,pointerIds,pointerPositions,0,0.1f,0.1f,0,0,0,0)); this.sleep(downDelay); for (int i=0; i < step; i++) { for (int j=0; j < pointerNumber; j++) { temp=j * 2; pointerPositions[j].x=(float)(start[temp] + delta[temp] * (i + 1)); temp++; pointerPositions[j].y=(float)(start[temp] + delta[temp] * (i + 1)); } myTime=SystemClock.uptimeMillis(); mInstrumentation.sendPointerSync(MotionEvent.obtain(myTime,myTime,MotionEvent.ACTION_MOVE,pointerNumber,pointerIds,pointerPositions,0,0.1f,0.1f,0,0,0,0)); this.sleep(moveDelay); } this.sleep(upDelay); myTime=SystemClock.uptimeMillis(); mInstrumentation.sendPointerSync(MotionEvent.obtain(myTime,myTime,MotionEvent.ACTION_UP,pointerNumber,pointerIds,pointerPositions,0,0.1f,0.1f,0,0,0,0)); }
Example 51
From project callmeter, under directory /src/de/ub0r/android/callmeter/data/.
Source file: LogRunnerReceiver.java

/** * Schedule next update. * @param context {@link Context} * @param delay delay in milliseconds * @param action {@link Intent}'s action */ public static void schedNext(final Context context,final long delay,final String action){ Log.d(TAG,"schedNext(ctx, " + delay + ","+ action+ ")"); final Intent i=new Intent(context,LogRunnerReceiver.class); if (action != null) { i.setAction(action); } final PendingIntent pi=PendingIntent.getBroadcast(context,0,i,PendingIntent.FLAG_CANCEL_CURRENT); final long t=SystemClock.elapsedRealtime() + delay; final AlarmManager mgr=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.ELAPSED_REALTIME,t,pi); }
Example 52
From project cocos2d, under directory /cocos2d-android/src/org/cocos2d/nodes/.
Source file: CCDirector.java

private void waitForFPS(){ if (animationInterval_ >= dt) { sleepInterval=animationInterval_ - dt + sleepInterval; SystemClock.sleep((long)(sleepInterval * 1000)); } else { sleepInterval=0; } }
Example 53
From project Common-Sense-Net-2, under directory /AndroidBarSherlock/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft() + mIndeterminateRealLeft,getPaddingTop() + mIndeterminateRealTop); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }
Example 54
From project conference-mobile-app, under directory /android-app/src/com/google/android/apps/iosched/ui/.
Source file: SessionsFragment.java

public void run(){ if (mAdapter != null) { mAdapter.notifyDataSetChanged(); } long nextQuarterHour=(SystemClock.uptimeMillis() / 900000 + 1) * 900000 + 5000; mMessageQueueHandler.postAtTime(mRefreshSessionsRunnable,nextQuarterHour); }
Example 55
From project cornerstone, under directory /frameworks/base/policy/src/com/android/internal/policy/impl/.
Source file: PhoneWindowManager.java

private void interceptScreenshotChord(){ if (mVolumeDownKeyTriggered && mPowerKeyTriggered && !mVolumeUpKeyTriggered) { final long now=SystemClock.uptimeMillis(); if (now <= mVolumeDownKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS && now <= mPowerKeyTime + SCREENSHOT_CHORD_DEBOUNCE_DELAY_MILLIS) { mVolumeDownKeyConsumedByScreenshotChord=true; cancelPendingPowerKeyAction(); mHandler.postDelayed(mScreenshotChordLongPress,ViewConfiguration.getGlobalActionKeyTimeout()); } } }
Example 56
From project COSsettings, under directory /src/com/cyanogenmod/cmparts/activities/.
Source file: ColorPickerDialog.java

@Override protected boolean onLevelChange(int level){ if (level < 4000 && mDelta <= 0) { mDelta=1; mAnimation.startScrolling(mTextXScale,1); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } else if (level > 6000 && mDelta >= 0) { mDelta=-1; mAnimation.startScrolling(mTextXScale,0); scheduleSelf(this,SystemClock.uptimeMillis() + DELAY); } return mProgress.setLevel(level); }
Example 57
From project cow, under directory /libs/ActionBarSherlock/library/src/com/actionbarsherlock/internal/widget/.
Source file: IcsProgressBar.java

@Override protected synchronized void onDraw(Canvas canvas){ super.onDraw(canvas); Drawable d=mCurrentDrawable; if (d != null) { canvas.save(); canvas.translate(getPaddingLeft(),getPaddingTop()); long time=getDrawingTime(); if (mAnimation != null) { mAnimation.getTransformation(time,mTransformation); float scale=mTransformation.getAlpha(); try { mInDrawing=true; d.setLevel((int)(scale * MAX_LEVEL)); } finally { mInDrawing=false; } if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) { mLastDrawTime=SystemClock.uptimeMillis(); postInvalidateDelayed(mAnimationResolution); } } d.draw(canvas); canvas.restore(); if (mShouldStartAnimationDrawable && d instanceof Animatable) { ((Animatable)d).start(); mShouldStartAnimationDrawable=false; } } }