Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package id.delta.utils;
- import android.app.Activity;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.Handler;
- import android.os.SystemClock;
- import android.preference.PreferenceManager;
- import java.util.Calendar;
- import id.trangga.lock.LockActivity;
- /**
- * Created by HOKA on 1/22/16.
- */
- public class PrayTimeUtils {
- private static Handler handler;
- private static Runnable runnable;
- public static void setPrayStatus(Context context, Activity activity){
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
- if (sharedPreferences.getBoolean(PreferenceKeys.KEY_PRAY, true)){
- setPrayActivity(activity);
- }
- }
- public static void setPrayActivity (final Activity activity){
- handler=new Handler();
- runnable = new Runnable(){
- public void run (){
- Calendar c = Calendar.getInstance();
- int hour = c.get(Calendar.HOUR_OF_DAY);
- int menit = c.get(Calendar.MINUTE);
- int detik = c.get(Calendar.SECOND);
- if (hour == 18 && detik == 00) {
- activity.startActivity(new Intent(activity, LockActivity.class));
- }
- long now = SystemClock.uptimeMillis();
- long next = now + (1000 - now % 1000);
- handler.postAtTime(runnable, next);
- }
- };
- runnable.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment