Compare commits

..

No commits in common. 'be0f1dbf04211ac8d26e9117aa06d830d4a41fb5' and 'd8199843b24e93cfee41a060a791f2a1b72102a3' have entirely different histories.

@ -13,7 +13,7 @@
tools:targetApi="31"> tools:targetApi="31">
<activity <activity
android:name=".UserInfoActivity" android:name=".LoginActivity"
android:exported="true"> android:exported="true">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -26,7 +26,7 @@
android:exported="false" /> android:exported="false" />
<activity <activity
android:name=".LoginActivity" android:name=".UserInfoActivity"
android:exported="false" /> android:exported="false" />
</application> </application>

@ -1,28 +1,20 @@
package cc.liuyx.app; package cc.liuyx.app;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener { public class LoginActivity extends AppCompatActivity {
private EditText usernameEdit, passwdEdit;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login); setContentView(R.layout.activity_login);
usernameEdit = findViewById(R.id.login_username);
passwdEdit = findViewById(R.id.login_passwd);
findViewById(R.id.btn_login).setOnClickListener(this);
TextView textView = findViewById(R.id.click_register); TextView textView = findViewById(R.id.click_register);
textView.setOnClickListener(new View.OnClickListener() { textView.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -30,42 +22,13 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
startActivity(new Intent(LoginActivity.this, RegisterActivity.class)); startActivity(new Intent(LoginActivity.this, RegisterActivity.class));
} }
}); });
}
Button btnLogin = findViewById(R.id.btn_login);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View view) {
switch (v.getId()) { startActivity(new Intent(LoginActivity.this, UserInfoActivity.class));
case R.id.btn_login:
login();
break;
}
}
private void login() {
String username = usernameEdit.getText().toString();
String passwd = passwdEdit.getText().toString();
if (!username.equals("") && !passwd.equals("")) {
SharedPreferences sp = getSharedPreferences("loginStatus", MODE_PRIVATE);
String localName = sp.getString("username", null);
String localPasswd = sp.getString("passwd", null);
if (!username.equals(localName) || !passwd.equals(localPasswd)) {
Toast.makeText(LoginActivity.this, "用户名或密码错误>_<", Toast.LENGTH_SHORT).show();
return;
}
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean("isLoggedIn", true);
editor.putString("username", username);
editor.apply();
Intent intent = new Intent(LoginActivity.this, UserInfoActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
Toast.makeText(LoginActivity.this, "请填入用户名与密码哦~", Toast.LENGTH_SHORT).show();
} }
});
} }
} }

@ -1,40 +1,18 @@
package cc.liuyx.app; package cc.liuyx.app;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener { public class RegisterActivity extends AppCompatActivity {
private String username = "";
private String passwd = "";
private String passwdAgain = "";
private String phone = "";
private String email = "";
private EditText usernameEdit, passwdEdit, passwdAgainEdit, phoneEdit, emailEdit;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register); setContentView(R.layout.activity_register);
// 初始化每个组件
usernameEdit = findViewById(R.id.username);
passwdEdit = findViewById(R.id.passwd);
passwdAgainEdit = findViewById(R.id.passwd2);
phoneEdit = findViewById(R.id.phone);
emailEdit = findViewById(R.id.email);
findViewById(R.id.btn_register).setOnClickListener(this);
ImageView back = findViewById(R.id.register_back); ImageView back = findViewById(R.id.register_back);
back.setOnClickListener(new View.OnClickListener() { back.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -44,43 +22,4 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
} }
}); });
} }
@Override
public void onClick(View v) {
if (v.getId() == R.id.btn_register) {
validateRegister();
}
}
private void validateRegister() {
Intent intent = new Intent(RegisterActivity.this, UserInfoActivity.class);
username = usernameEdit.getText().toString();
passwd = passwdEdit.getText().toString();
passwdAgain = passwdAgainEdit.getText().toString();
email = emailEdit.getText().toString();
phone = phoneEdit.getText().toString();
// 判断两次密码是否相等
if (passwd.equals(passwdAgain)) {
if (!username.equals("") && !passwd.equals("")) {
// 设置登录状态
SharedPreferences sharedPreferences = getSharedPreferences("loginStatus", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isLoggedIn", true);
editor.putString("username", username);
editor.putString("email", email);
editor.putString("phone", phone);
editor.putString("passwd", passwd);
editor.apply();
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} else {
Toast.makeText(RegisterActivity.this, "请填入用户名与密码哦~", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(RegisterActivity.this, "两次密码输入不一致!", Toast.LENGTH_SHORT).show();
}
}
} }

@ -1,65 +1,14 @@
package cc.liuyx.app; package cc.liuyx.app;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
public class UserInfoActivity extends AppCompatActivity implements View.OnClickListener { public class UserInfoActivity extends AppCompatActivity {
private String username = "";
private String phone = "";
private String email = "";
@SuppressLint("SetTextI18n")
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_info); setContentView(R.layout.activity_user_info);
// 判断用户是否已经登录
// 如果未登录,则跳转至登录页面
SharedPreferences preferences = getSharedPreferences("loginStatus", MODE_PRIVATE);
boolean isLogin = preferences.getBoolean("isLoggedIn", false);
System.out.println(isLogin);
if (!isLogin) {
// 跳转到 LoginActivity
Intent intent = new Intent(UserInfoActivity.this, LoginActivity.class);
startActivity(intent);
finish();
return;
}
username = preferences.getString("username", null);
email = preferences.getString("email", null);
phone = preferences.getString("phone", null);
TextView userName = findViewById(R.id.user_username);
TextView userPhone = findViewById(R.id.user_phone);
TextView userEmail = findViewById(R.id.user_email);
userName.setText(userName.getText() + username);
userPhone.setText(userPhone.getText() + phone);
userEmail.setText(userEmail.getText() + email);
Button btnLogout = findViewById(R.id.logout);
btnLogout.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.logout) {
SharedPreferences preferences = getSharedPreferences("loginStatus", MODE_PRIVATE);
SharedPreferences.Editor edit = preferences.edit();
edit.remove("isLoggedIn");
edit.apply();
finish();
startActivity(new Intent(this, LoginActivity.class));
}
} }
} }

@ -23,7 +23,7 @@
android:textSize="18sp" /> android:textSize="18sp" />
<EditText <EditText
android:id="@+id/login_username" android:id="@+id/editTextTextPersonName"
android:layout_width="357dp" android:layout_width="357dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_margin="10dp"
@ -35,7 +35,7 @@
android:textSize="15sp" /> android:textSize="15sp" />
<EditText <EditText
android:id="@+id/login_passwd" android:id="@+id/editTextTextPassword"
android:layout_width="357dp" android:layout_width="357dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_margin="10dp"

@ -41,7 +41,7 @@
android:hint="来将可留姓名?" android:hint="来将可留姓名?"
android:inputType="textPersonName" android:inputType="textPersonName"
android:lines="1" android:lines="1"
android:textSize="@dimen/normal_font_size" /> android:textSize="15sp" />
<EditText <EditText
android:id="@+id/passwd" android:id="@+id/passwd"
@ -54,7 +54,7 @@
android:hint="对对暗号" android:hint="对对暗号"
android:inputType="textPassword" android:inputType="textPassword"
android:lines="1" android:lines="1"
android:textSize="@dimen/normal_font_size" /> android:textSize="15sp" />
<EditText <EditText
android:id="@+id/passwd2" android:id="@+id/passwd2"
@ -67,7 +67,7 @@
android:hint="重复暗号" android:hint="重复暗号"
android:inputType="textPassword" android:inputType="textPassword"
android:lines="1" android:lines="1"
android:textSize="@dimen/normal_font_size" /> android:textSize="15sp" />
<EditText <EditText
android:id="@+id/phone" android:id="@+id/phone"
@ -80,7 +80,7 @@
android:inputType="phone" android:inputType="phone"
android:lines="1" android:lines="1"
android:textAllCaps="false" android:textAllCaps="false"
android:textSize="@dimen/normal_font_size" /> android:textSize="15sp" />
<EditText <EditText
android:id="@+id/email" android:id="@+id/email"
@ -92,7 +92,7 @@
android:hint="邮箱也留个噻" android:hint="邮箱也留个噻"
android:inputType="textEmailAddress" android:inputType="textEmailAddress"
android:lines="1" android:lines="1"
android:textSize="@dimen/normal_font_size" /> android:textSize="15sp" />
<Button <Button
android:id="@+id/btn_register" android:id="@+id/btn_register"

@ -11,8 +11,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="45dp" android:layout_marginTop="55dp"
android:layout_marginBottom="30dp" android:layout_marginBottom="35dp"
android:gravity="center"> android:gravity="center">
<ImageView <ImageView
@ -22,64 +22,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:id="@+id/user_edit"
android:layout_height="wrap_content"
android:background="@drawable/shape_infoitem"
android:gravity="center">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_user" />
<TextView
android:id="@+id/user_username"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text=" 用户名:"
android:textSize="@dimen/normal_font_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:src="@drawable/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_infoitem"
android:gravity="center">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_phone" />
<TextView
android:id="@+id/user_phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"
android:text=" 手机号:"
android:textSize="@dimen/normal_font_size" />
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:src="@drawable/ic_arrow_right" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="15dp" android:layout_marginBottom="15dp"
@ -90,15 +33,14 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:src="@drawable/ic_email" /> android:src="@drawable/ic_edit" />
<TextView <TextView
android:id="@+id/user_email"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="8" android:layout_weight="8"
android:text=" 邮箱:" android:text=" 修改信息"
android:textSize="@dimen/normal_font_size" /> android:textSize="16sp" />
<ImageView <ImageView
android:layout_width="0dp" android:layout_width="0dp"
@ -128,7 +70,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="8" android:layout_weight="8"
android:text=" 设置" android:text=" 设置"
android:textSize="@dimen/normal_font_size" /> android:textSize="16sp" />
<ImageView <ImageView
android:layout_width="0dp" android:layout_width="0dp"
@ -157,7 +99,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="8" android:layout_weight="8"
android:text=" 更多" android:text=" 更多"
android:textSize="@dimen/normal_font_size" /> android:textSize="16sp" />
<ImageView <ImageView
android:layout_width="0dp" android:layout_width="0dp"
@ -168,35 +110,16 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center">
</LinearLayout>
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<Button
android:id="@+id/logout"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_above="@+id/footnote"
android:layout_centerHorizontal="true"
android:layout_marginBottom="30dp"
android:text="退出登录" />
<TextView <TextView
android:id="@+id/footnote"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp" android:layout_marginBottom="10dp"
android:text="@string/footnote" android:text="联系我liuyxcc@gmail.com"
android:textAlignment="center" /> android:textAlignment="center" />
</RelativeLayout> </RelativeLayout>

@ -3,5 +3,4 @@
<dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen> <dimen name="fab_margin">16dp</dimen>
<dimen name="normal_font_size">16sp</dimen>
</resources> </resources>

@ -10,6 +10,4 @@
<string name="hello_first_fragment">Hello first fragment</string> <string name="hello_first_fragment">Hello first fragment</string>
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string> <string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
<string name="title_activity_register">RegisterActivity</string> <string name="title_activity_register">RegisterActivity</string>
<string name="footnote">联系我liuyxcc@gmail.com</string>
</resources> </resources>
Loading…
Cancel
Save