-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppLockActivity.java
83 lines (73 loc) · 2.37 KB
/
AppLockActivity.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
80
81
82
83
package learning.com.applock;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.util.Set;
public class AppLockActivity extends AppCompatActivity {
MyService.ServiceBinder mServiceBinder;
static boolean isLaunchByUser = false;
SharedPreferences mPreferences;
ServiceConnection mServiceConnection=new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mServiceBinder= (MyService.ServiceBinder) iBinder;
if(mServiceBinder.getLockType()>0){
if(mServiceBinder.getLockType()==1){
startActivity(new Intent(AppLockActivity.this,
PatternActivity.class));
finish();
}
else if(mServiceBinder.getLockType()==2){
startActivity(new Intent(AppLockActivity.this,PinLock.class));
finish();
}
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
mServiceBinder=null;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i=getIntent();
if(i!=null){
String action=i.getAction();
if(action!=null && action.equalsIgnoreCase(Intent.ACTION_MAIN)){
isLaunchByUser=true;
}
}
else{
isLaunchByUser=false;
}
mPreferences=getSharedPreferences("AppLock",MODE_PRIVATE);
setContentView(R.layout.activity_app_lock);
Intent intent=new Intent(this,MyService.class);
bindService(intent,mServiceConnection,BIND_AUTO_CREATE);
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(mServiceConnection);
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
protected void onStart() {
super.onStart();
if(!isLockEnrolled()){
startActivity(new Intent(this,MainActivity.class));
finish();
}
}
private boolean isLockEnrolled(){
return mPreferences.getBoolean("Enrolled",false);
}
}