You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.3 KiB
69 lines
2.3 KiB
package com.example.myapplication;
|
|
|
|
import android.content.ComponentName;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.widget.Button;
|
|
import android.widget.EditText;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
Button loginB, newUser;
|
|
EditText usernameET, passwordET;
|
|
SqliteDbManager instance;
|
|
|
|
private static final String correctName = "admin";
|
|
private static final String correctPassword = "rootadmin";
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
setContentView(R.layout.activity_main);
|
|
initView();
|
|
loginB.setOnClickListener(v -> {
|
|
if (submit()) {
|
|
Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_LONG).show();
|
|
Intent intent = new Intent();
|
|
ComponentName componentName = new ComponentName(MainActivity.this, InfoActivity.class);
|
|
intent.setComponent(componentName);
|
|
intent.putExtra("username", usernameET.getText());
|
|
startActivity(intent);
|
|
} else {
|
|
Toast.makeText(MainActivity.this, "账号或密码输入错误", Toast.LENGTH_LONG).show();
|
|
}
|
|
});
|
|
newUser.setOnClickListener(v -> {
|
|
Intent intent = new Intent();
|
|
ComponentName componentName = new ComponentName(MainActivity.this, MainActivity2.class);
|
|
intent.setComponent(componentName);
|
|
startActivity(intent);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* 初始化视图绑定
|
|
*/
|
|
void initView() {
|
|
loginB = findViewById(R.id.login);
|
|
usernameET = findViewById(R.id.username);
|
|
passwordET = findViewById(R.id.password);
|
|
newUser = findViewById(R.id.newUser);
|
|
instance = SqliteDbManager.getInstance();
|
|
}
|
|
|
|
boolean submit() {
|
|
instance.setSqliteDbOpen(this);
|
|
return instance.queryTb("person", getUsername(), getPassword());
|
|
// return getUsername().equals(correctName) && getPassword().equals(correctPassword);
|
|
}
|
|
|
|
String getUsername() {
|
|
return usernameET.getText().toString();
|
|
}
|
|
|
|
String getPassword() {
|
|
return passwordET.getText().toString();
|
|
}
|
|
} |