-
Notifications
You must be signed in to change notification settings - Fork 0
/
BroadcasterTwo.java
79 lines (59 loc) · 2.49 KB
/
BroadcasterTwo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.wallpapernote.plutopix.wallpaperorganizer;
import android.app.KeyguardManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.util.Log;
import java.util.Calendar;
public class BroadcasterTwo extends BroadcastReceiver {
private SharedPreferences mSharedPreferences;
@Override
public void onReceive(final Context context, Intent intent) {
final Intent service2 = new Intent(context, Servicetwo.class);
final Intent servicethree = new Intent(context, Servicethree.class);
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean toOrNot = mSharedPreferences.getBoolean(Settings.TOBROADCAST, false);
switch (intent.getAction()){
case Intent.ACTION_SCREEN_OFF:
rebootYear();
context.stopService(service2);
if(toOrNot){
context.startService(servicethree);
}
break;
case Intent.ACTION_SCREEN_ON:
KeyguardManager mKeyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
boolean isLocked = mKeyguardManager.isKeyguardLocked();
if(!isLocked){
context.stopService(servicethree);
context.startService(service2);
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
context.stopService(servicethree);
context.startService(service2);
}
},3000);
break;
case Intent.ACTION_USER_PRESENT:
context.stopService(servicethree);
context.startService(service2);
break;
}
}
public void rebootYear(){
Calendar mCalendar = Calendar.getInstance();
int year = mCalendar.get(Calendar.YEAR);
int month = mCalendar.get(Calendar.MONTH);
int day = mCalendar.get(Calendar.DAY_OF_MONTH);
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(MainActivity.NOWYEAR,year);
editor.putInt(MainActivity.NOWMONTH,month);
editor.putInt(MainActivity.NOWDAY,day);
editor.commit();
}
}