yoyocx

Code Plus Plus

Jan 25th, 2016
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package id.delta.utils;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.SharedPreferences;
  7. import android.os.Handler;
  8. import android.os.SystemClock;
  9. import android.preference.PreferenceManager;
  10.  
  11. import java.util.Calendar;
  12.  
  13. import id.trangga.lock.LockActivity;
  14.  
  15. /**
  16. * Created by HOKA on 1/22/16.
  17. */
  18. public class PrayTimeUtils {
  19.  
  20. private static Handler handler;
  21. private static Runnable runnable;
  22.  
  23. public static void setPrayStatus(Context context, Activity activity){
  24. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
  25. if (sharedPreferences.getBoolean(PreferenceKeys.KEY_PRAY, true)){
  26. setPrayActivity(activity);
  27. }
  28. }
  29.  
  30.  
  31. public static void setPrayActivity (final Activity activity){
  32.  
  33. handler=new Handler();
  34.  
  35. runnable = new Runnable(){
  36. public void run (){
  37. Calendar c = Calendar.getInstance();
  38.  
  39. int hour = c.get(Calendar.HOUR_OF_DAY);
  40. int menit = c.get(Calendar.MINUTE);
  41. int detik = c.get(Calendar.SECOND);
  42.  
  43. if (hour == 18 && detik == 00) {
  44. activity.startActivity(new Intent(activity, LockActivity.class));
  45. }
  46.  
  47. long now = SystemClock.uptimeMillis();
  48. long next = now + (1000 - now % 1000);
  49. handler.postAtTime(runnable, next);
  50. }
  51. };
  52. runnable.run();
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment