List of usage examples for android.os SystemClock currentThreadTimeMillis
@CriticalNative public static native long currentThreadTimeMillis();
From source file:Main.java
public static String encryptPassword(String s) { int i = 10 + (new Random(SystemClock.currentThreadTimeMillis())).nextInt(90); return (new StringBuilder()).append(md5((new StringBuilder()).append(i).append(s).toString())).append(":") .append(i).toString();/*from w ww . j a v a 2 s .com*/ }
From source file:Main.java
public static boolean insertMediaStore(Context context, File file, String imageName) { if (context == null || file == null || !file.exists()) { return false; }//from w w w . ja va 2s.c o m if (TextUtils.isEmpty(imageName)) { imageName = SystemClock.currentThreadTimeMillis() + PNG; } try { MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), imageName, null); // String imagePath = // MediaStore.Images.Media.insertImage(getContentResolver(), // bitmap, "", ""); context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file))); } catch (FileNotFoundException e) { e.printStackTrace(); return false; } return true; }
From source file:com.weidian.blockcanary.LogPrinter.java
@Override public void println(String x) { switch (isStart(x)) { case START:/*from ww w.ja va 2s. co m*/ mStartTimeMillis = System.currentTimeMillis(); mStartThreadTimeMillis = SystemClock.currentThreadTimeMillis(); mStartedPrinting = true; break; case FINISH: final long endTime = System.currentTimeMillis(); mStartedPrinting = false; if (isBlock(endTime)) { notifyBlockEvent(endTime, mStartTimeMillis); } break; default: } }
From source file:android.net.http.ConnectionThread.java
/** * Loop until app shutdown. Runs connections in priority * order./*from w w w . j a va2s . c o m*/ */ public void run() { android.os.Process.setThreadPriority( android.os.Process.THREAD_PRIORITY_DEFAULT + android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE); // these are used to get performance data. When it is not in the timing, // mCurrentThreadTime is 0. When it starts timing, mCurrentThreadTime is // first set to -1, it will be set to the current thread time when the // next request starts. mCurrentThreadTime = 0; mTotalThreadTime = 0; while (mRunning) { if (mCurrentThreadTime == -1) { mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); } Request request; /* Get a request to process */ request = mRequestFeeder.getRequest(); /* wait for work */ if (request == null) { synchronized (mRequestFeeder) { if (HttpLog.LOGV) HttpLog.v("ConnectionThread: Waiting for work"); mWaiting = true; try { mRequestFeeder.wait(); } catch (InterruptedException e) { } mWaiting = false; if (mCurrentThreadTime != 0) { mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); } } } else { if (HttpLog.LOGV) HttpLog.v("ConnectionThread: new request " + request.mHost + " " + request); mConnection = mConnectionManager.getConnection(mContext, request.mHost); mConnection.processRequests(request); if (mConnection.getCanPersist()) { if (!mConnectionManager.recycleConnection(mConnection)) { mConnection.closeConnection(); } } else { mConnection.closeConnection(); } mConnection = null; if (mCurrentThreadTime > 0) { long start = mCurrentThreadTime; mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); mTotalThreadTime += mCurrentThreadTime - start; } } } }
From source file:org.mycard.net.network.ConnectionThread.java
/*** * Loop until app shutdown. Runs connections in priority * order.//from ww w.jav a 2 s . c o m */ @SuppressWarnings("unused") public void run() { android.os.Process.setThreadPriority( android.os.Process.THREAD_PRIORITY_DEFAULT + android.os.Process.THREAD_PRIORITY_LESS_FAVORABLE); // these are used to get performance data. When it is not in the timing, // mCurrentThreadTime is 0. When it starts timing, mCurrentThreadTime is // first set to -1, it will be set to the current thread time when the // next request starts. mCurrentThreadTime = 0; mTotalThreadTime = 0; while (mRunning) { if (mCurrentThreadTime == -1) { mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); } Request request; /** Get a request to process */ request = mRequestFeeder.getRequest(); /** wait for work */ if (request == null) { synchronized (mRequestFeeder) { //if (HttpLog.LOGV) HttpLog.v("ConnectionThread: Waiting for work"); mWaiting = true; try { mRequestFeeder.wait(); } catch (InterruptedException e) { } mWaiting = false; if (mCurrentThreadTime != 0) { mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); } } } else { //if (HttpLog.LOGV) HttpLog.v("ConnectionThread: new request " + // request.mHost + " " + request ); HttpHost proxy = mConnectionManager.getProxyHost(); HttpHost host; if (false) { // Allow https proxy host = proxy == null ? request.mHost : proxy; } else { // Disallow https proxy -- tmob proxy server // serves a request loop for https reqs host = (proxy == null || request.mHost.getSchemeName().equals("https")) ? request.mHost : proxy; } mConnection = mConnectionManager.getConnection(mContext, host); mConnection.processRequests(request); if (mConnection.getCanPersist()) { if (!mConnectionManager.recycleConnection(mConnection)) { mConnection.closeConnection(); } } else { mConnection.closeConnection(); } mConnection = null; if (mCurrentThreadTime > 0) { long start = mCurrentThreadTime; mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); mTotalThreadTime += mCurrentThreadTime - start; } } } }
From source file:com.android.callstat.common.net.ConnectionThread.java
/** * Loop until app shutdown./*from w w w . j ava2s . c o m*/ */ public void run() { Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); // these are used to get performance data. When it is not in the timing, // mCurrentThreadTime is 0. When it starts timing, mCurrentThreadTime is // first set to -1, it will be set to the current thread time when the // next request starts. mCurrentThreadTime = 0; mTotalThreadTime = 0; MyHttpClient client = null; client = createHttpClient(mContext); while (mRunning) { if (mCurrentThreadTime == -1) { mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); } Request request; // mCancaled = false; /* Get a request to process */ request = mRequestFeeder.getRequest(); /* wait for work */ if (request == null) { synchronized (mRequestFeeder) { if (DebugFlags.CONNECTION_THREAD) HttpLog.v("ConnectionThread: Waiting for work"); try { mRequestFeeder.wait(); } catch (InterruptedException e) { } if (mCurrentThreadTime != 0) { mCurrentThreadTime = SystemClock.currentThreadTimeMillis(); } } } else { if (DebugFlags.CONNECTION_THREAD) { // HttpLog.v("ConnectionThread: new request " + // request.mHost + " " + request ); } try { httpConnection(mContext, false, client, null, 0, request); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } if (client != null) { client.close(); } }
From source file:com.diedrico.diedricoapp.ProjectionFragment.java
public void threadTime() { new Thread(new Runnable() { public void run() { if (pressed == false) { currentTime = SystemClock.currentThreadTimeMillis(); while (pressed == false) { if ((SystemClock.currentThreadTimeMillis() - currentTime) > 3000) { renderer.setNotPressed(true); break; }/* w w w . ja v a 2 s. c om*/ } } } }).start(); }
From source file:com.google.android.gcm.demo.ui.NetworkSchedulerFragment.java
private void addPeriodic(long periodSecs, long flexSecs, int connectivity, boolean charging, boolean persistence) { if (flexSecs > periodSecs) { Toast.makeText(getActivity(), getString(R.string.scheduler_error_flex), Toast.LENGTH_SHORT).show(); return;//from w ww . ja v a 2 s .c o m } String tag = Long.toString(SystemClock.currentThreadTimeMillis()); final TaskTracker taskTracker = TaskTracker.createPeriodic(tag, periodSecs, flexSecs); PeriodicTask periodic = new PeriodicTask.Builder().setService(TaskSchedulerService.class) .setPeriod(periodSecs).setFlex(flexSecs).setTag(tag).setRequiredNetwork(connectivity) .setRequiresCharging(charging).setPersisted(persistence).build(); mScheduler.schedule(periodic); mTasks.updateTask(taskTracker); }
From source file:com.google.android.gcm.demo.ui.NetworkSchedulerFragment.java
private void addOneOff(long winStartSecs, long winEndSecs, int connectivity, boolean charging) { if (winStartSecs > winEndSecs) { Toast.makeText(getActivity(), getString(R.string.scheduler_error_window), Toast.LENGTH_SHORT).show(); return;/*ww w .ja v a 2s . c o m*/ } String tag = Long.toString(SystemClock.currentThreadTimeMillis()); final long elapsedNowSeconds = SystemClock.elapsedRealtime() / 1000; final TaskTracker taskTracker = TaskTracker.createOneoff(tag, elapsedNowSeconds + winStartSecs, elapsedNowSeconds + winEndSecs); OneoffTask oneOff = new OneoffTask.Builder().setService(TaskSchedulerService.class).setTag(tag) .setExecutionWindow(winStartSecs, winEndSecs).setRequiredNetwork(connectivity) // Persistence not yet support for Oneoffs. .setRequiresCharging(charging).build(); mScheduler.schedule(oneOff); mTasks.updateTask(taskTracker); }
From source file:com.frostwire.android.gui.adapters.SearchResultListAdapter.java
public FilteredSearchResults filter() { long now = SystemClock.currentThreadTimeMillis(); long timeSinceLastFilterCall = now - lastFilterCallTimestamp.get(); if (cachedFilteredSearchResults != null && timeSinceLastFilterCall < 250) { return cachedFilteredSearchResults; }/*from w w w .j a v a2s . co m*/ lastFilterCallTimestamp.set(now); cachedFilteredSearchResults = filter(list); this.visualList = cachedFilteredSearchResults.filtered; notifyDataSetChanged(); notifyDataSetInvalidated(); return cachedFilteredSearchResults; }