-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsActivity.java
79 lines (71 loc) · 3 KB
/
SettingsActivity.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 learning.com.applock;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
public class SettingsActivity extends AppCompatActivity {
SharedPreferences pref;
MyService.ServiceBinder mServiceBinder;
ServiceConnection mServiceConnection=new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
mServiceBinder= (MyService.ServiceBinder) iBinder;
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
mServiceBinder=null;
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
pref = getSharedPreferences("AppLock", MODE_PRIVATE);
Intent intent=new Intent(this,MyService.class);
bindService(intent,mServiceConnection,BIND_AUTO_CREATE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) {
if (resultCode == RESULT_OK) {
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean("Enrolled", true);
editor.apply();
finish();
}
}
}
public void chooseLockType(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setTitle("Set Lock Type")
.setSingleChoiceItems(R.array.lock_type, 0, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
Intent intent = new Intent(SettingsActivity.this, PatternActivity.class);
startActivityForResult(intent, 100);
} else if (i == 1) {
Intent intent = new Intent(SettingsActivity.this, PinLock.class);
startActivityForResult(intent, 100);
}
dialogInterface.dismiss();
}
}
);
builder.create().show();
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(mServiceConnection);
}
}