コード例 #1
0
 public void run() {
   int timedCount = 0;
   while (!Thread.interrupted()) {
     try {
       Thread.sleep(SEC_POLL_DELAY);
     } catch (InterruptedException e) {
       break;
     }
     // 5400 seconds = 90 min
     if (timedCount == 5400) {
       timedCount = 0;
       Intent dialogIntent = new Intent(getBaseContext(), BlockerActivity.class);
       dialogIntent.addFlags(
           Intent.FLAG_ACTIVITY_CLEAR_TOP
               | Intent.FLAG_ACTIVITY_NEW_TASK
               | Intent.FLAG_ACTIVITY_CLEAR_TASK);
       dialogIntent.putExtra(
           "AlertInfo", "You've used your phone for 90 minutes NON-STOP. Please take a break!");
       getApplication().startActivity(dialogIntent);
     }
     timedCount++;
     synchronized (mPauseLock) {
       while (mPaused) {
         try {
           mPauseLock.wait();
         } catch (InterruptedException e) {
           e.printStackTrace();
         }
       }
     }
   }
 }
コード例 #2
0
 private void startRemoteLogging() {
   remoteLoggingThread =
       new Thread(
           new Runnable() {
             @Override
             public void run() {
               while (!Thread.interrupted()) {
                 try {
                   Thread.sleep(POLL_DELAY_MS);
                 } catch (InterruptedException e) {
                   break;
                 }
                 // checking the last update time
                 String lastTimeStamp = "0";
                 HttpClient httpClient = new DefaultHttpClient();
                 HttpGet request = new HttpGet();
                 try {
                   // set up session header, don't use rest api call whose callback is run on main
                   // thread, will not be called properly
                   request.setHeader("Authorization", "HL " + prefs.getSession());
                   request.setURI(new URI(BuildConfig.ENDPOINT_URL + "/stat/lastUpdate"));
                   HttpResponse response = httpClient.execute(request);
                   BufferedReader in =
                       new BufferedReader(
                           new InputStreamReader(response.getEntity().getContent()));
                   lastTimeStamp = in.readLine();
                   Intent broadcast = new Intent();
                   broadcast.setAction(getString(R.string.remote_logging));
                   broadcast.putExtra("lastTimestamp", lastTimeStamp);
                   // need last update timestamp
                   localBroadcastManager.sendBroadcast(broadcast);
                 } catch (URISyntaxException e) {
                   e.printStackTrace();
                 } catch (ClientProtocolException e) {
                   e.printStackTrace();
                 } catch (IOException e) {
                   e.printStackTrace();
                 }
               }
             }
           });
   remoteLoggingThread.start();
 }
コード例 #3
0
  private void startTimeCount() {

    timedRunnable = new TimedRunnable();
    timeCountThread = new Thread(timedRunnable);
    timeCountThread.start();
  }