-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMainActivity.java
More file actions
151 lines (84 loc) · 4 KB
/
MainActivity.java
File metadata and controls
151 lines (84 loc) · 4 KB
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
package com.rakesh.arfirstaid;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
EditText userText,passText,mobileText;
TextView textView;
Button button;
SharedPreferences sharedPreferences;
public void onClick(View view) {
if (view.getId() == R.id.loginText) {
String loginText = textView.getText().toString();
userText.setText("");
passText.setText("");
mobileText.setText("");
if (loginText.matches("OR, LOGIN")) {
button.setText("login");
userText.setText(sharedPreferences.getString("username",""));
passText.setText(sharedPreferences.getString("password",""));
mobileText.setVisibility(View.GONE);
textView.setText("OR, SIGNUP");
} else {
button.setText("signup");
textView.setText("OR, LOGIN");
mobileText.setVisibility(View.VISIBLE);
}
}
}
public void loginfun(View view) {
if (button.getText().toString().matches("signup")) {
String username = userText.getText().toString();
String mobile = mobileText.getText().toString();
String password = passText.getText().toString();
if (!(username.matches("") || mobile.matches("") || password.matches(""))) {
sharedPreferences.edit().putString("username", username).apply();
sharedPreferences.edit().putString("mobile", mobile).apply();
sharedPreferences.edit().putString("password", password).apply();
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
startActivity(intent);
} else {
Toast.makeText(this, "All values are required!!!", Toast.LENGTH_SHORT).show();
}
} else {
String username = userText.getText().toString();
String password = passText.getText().toString();
String saveName = sharedPreferences.getString("username","");
String savePass = sharedPreferences.getString("password","");
if(!(username.matches("") || password.matches(""))) {
if(username.equals(saveName) && !(saveName.equals(""))) {
//Toast.makeText(this, "Hi", Toast.LENGTH_SHORT).show();
if (password.equals(savePass)) {
Intent intent = new Intent(getApplicationContext(), Main2Activity.class);
startActivity(intent);
} else {
Toast.makeText(this, "Wrong Password : " + sharedPreferences.getString("password",""), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Check Username : " + sharedPreferences.getString("username",""), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "Username & Password Required", Toast.LENGTH_SHORT).show();
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
userText = findViewById(R.id.usernameText);
passText = findViewById(R.id.passwordText);
mobileText = findViewById(R.id.phoneNumberText);
textView = findViewById(R.id.loginText);
button = findViewById(R.id.signupButton);
textView.setOnClickListener(this);
sharedPreferences = getApplicationContext().getSharedPreferences("com.rakesh.afirstaid", MODE_PRIVATE);
}
}