-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcw.java
306 lines (259 loc) · 12 KB
/
cw.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
MAINACTIVITY.JAVA
public class MainActivity extends AppCompatActivity {
FirebaseUser user;
ProgressDialog progressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Auto Login...");
if(isConnectedToInternet()){
checkPermision();
} else {
showNoInternetDialog();
}
}
public boolean isConnectedToInternet(){
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting();
}
public void checkPermision(){
Dexter.withContext(this.getApplicationContext())
.withPermission(Manifest.permission.ACCESS_FINE_LOCATION)
.withListener(new PermissionListener() {
@Override
public void onPermissionGranted(PermissionGrantedResponse permissionGrantedResponse) {
if(isConnectedToInternet()){
user = FirebaseAuth.getInstance().getCurrentUser();
if(user != null){
progressDialog.show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
MainActivity.this.progressDialog.dismiss();
Intent intent = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(intent);
}
}, 3000);
} else {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(getApplicationContext(), AccountLogin.class);
startActivity(intent);
}
}, 3000);
}
}
}
@Override
public void onPermissionDenied(PermissionDeniedResponse permissionDeniedResponse) {
Toast.makeText(getApplicationContext(), "Please allow it to continue. To get request again, clear the app's data.", Toast.LENGTH_LONG).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
MainActivity.this.finish();
System.exit(0);
}
}, 3000);
}
@Override
public void onPermissionRationaleShouldBeShown(PermissionRequest permissionRequest, PermissionToken permissionToken) {
permissionToken.continuePermissionRequest();
}
}).check();
}
private void showNoInternetDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
dialog.setTitle("Internet Required");
dialog.setCancelable(false);
dialog.setMessage("Apologies, but unfortunately you don't have an internet access. Please enable WiFi or Data Connection to continue.");
dialog.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
dialog.cancel();
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
}).show();
}
}
ACCOUNTLOGIN.JAVA
public class AccountLogin extends AppCompatActivity {
MaterialButton btnLogin, btnBack;
EditText emailAdd, pass;
TextInputLayout layout_email_address, layout_pass;
TextView signup_text;
FirebaseAuth firebaseAuth;
ProgressDialog progressDialog;
Animation slide_left, slide_right;
String SAVE_EMAIL;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.account_login);
if(!isConnectedToInternet()){
showNoInternetDialog();
}
//dito
btnLogin = findViewById(R.id.btnLogin);
btnBack = findViewById(R.id.btnBack);
signup_text = findViewById(R.id.signup_text);
emailAdd = findViewById(R.id.email_address);
pass = findViewById(R.id.password);
layout_email_address = findViewById(R.id.layout_email_address);
layout_pass = findViewById(R.id.layout_pass);
btnBack.setVisibility(View.GONE);
Bundle bundle = getIntent().getExtras();
if(bundle != null){
SAVE_EMAIL = bundle.getString("email");
emailAdd.setText(bundle.getString("email"));
btnBack.setVisibility(View.VISIBLE);
}
if(savedInstanceState != null){
String email = savedInstanceState.getString("email");
emailAdd.setText(email);
}
//animations
slide_left = AnimationUtils.loadAnimation(this, R.anim.right_to_left);
signup_text.startAnimation(slide_left);
firebaseAuth = FirebaseAuth.getInstance();
progressDialog = new ProgressDialog(this);
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(AccountLogin.this, Checkpoint.class));
CustomIntent.customType(AccountLogin.this,
"fadein-to-fadeout");
}
});
emailAdd.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.toString().isEmpty()){
layout_email_address.setError("Please don't leave fields empty!");
} else {
layout_email_address.setError(null);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
pass.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.toString().isEmpty()){
layout_pass.setError("Please don't leave fields empty!");
} else {
layout_pass.setError(null);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = emailAdd.getText().toString();
String password = pass.getText().toString();
if(!isConnectedToInternet()){
showNoInternetDialog();
} else {
if(TextUtils.isEmpty(email)){
layout_email_address.setError("Your email address is empty! It is required.");
} else if (!(Patterns.EMAIL_ADDRESS.matcher(email).matches())){
} else if (TextUtils.isEmpty(password)){
layout_pass.setError("Your password is empty! It is required.");
} else {
LoginAccount(email, password);
btnLogin.setText("Logging in...");
signup_text.animate().alpha(0f).setDuration(500).start();
btnLogin.setEnabled(false);
}
}
}
});
}
private void LoginAccount(String email, String password) {
firebaseAuth.signInWithEmailAndPassword(email, password)
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
SAVE_EMAIL = email;
Toast.makeText(AccountLogin.this, "Login success!", Toast.LENGTH_LONG).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(AccountLogin.this, HomeActivity.class);
startActivity(intent);
CustomIntent.customType(AccountLogin.this,
"fadein-to-fadeout");
}
}, 3000);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(AccountLogin.this, "Failed to login", Toast.LENGTH_LONG).show();
pass.getText().clear();
}
});
}
public void SignUp(View view) {
Intent intent = new Intent(AccountLogin.this, Checkpoint.class);
startActivity(intent);
CustomIntent.customType(AccountLogin.this,
"fadein-to-fadeout");
}
@Override
public void onBackPressed() {
super.onBackPressed();
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("email", SAVE_EMAIL);
}
@Override
protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
if(savedInstanceState != null){
emailAdd.setText(savedInstanceState.getString("email"));
}
}
public boolean isConnectedToInternet(){
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return connectivityManager.getActiveNetworkInfo() != null && connectivityManager.getActiveNetworkInfo().isConnectedOrConnecting();
}
private void showNoInternetDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(AccountLogin.this);
dialog.setTitle("Internet Required");
dialog.setCancelable(false);
dialog.setMessage("Apologies, but unfortunately you don't have an internet access. Please enable WiFi or Data Connection to continue.");
dialog.setPositiveButton("OKAY", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
dialog.cancel();
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
}).show();
}
}