parent
c33b1fa277
commit
f96aa55128
@ -0,0 +1,79 @@
|
||||
package com.example.musicwork;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
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 com.example.musicwork.chuangguan.GameActivity;
|
||||
|
||||
public class SignIn extends AppCompatActivity {
|
||||
public static String author_name;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
Button signin = (Button) findViewById(R.id.signin);
|
||||
final Data data = (Data)getApplication();
|
||||
signin.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final String name = ((EditText) findViewById(R.id.etname)).getText().toString();
|
||||
String password = ((EditText) findViewById(R.id.etpassword)).getText().toString();
|
||||
|
||||
if (com.example.musicwork.chuangguan.UserService.signIn(name, password))
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
data.setUsername(name);
|
||||
author_name=name;
|
||||
Toast.makeText(SignIn.this, "登录成功", Toast.LENGTH_SHORT).show();
|
||||
Intent intent = new Intent(SignIn.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
|
||||
}
|
||||
});
|
||||
else {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Toast.makeText(SignIn.this, "登录失败,请检查用户名和密码是否正确。未注册账户请注册后登录", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Button signup = (Button) findViewById(R.id.signup);
|
||||
signup.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String name = ((EditText) findViewById(R.id.etname)).getText().toString();
|
||||
String password = ((EditText) findViewById(R.id.etpassword)).getText().toString();
|
||||
if (com.example.musicwork.chuangguan.UserService.signUp(name, password))
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(SignIn.this, "注册成功,请重新登录", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
else {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(SignIn.this, "注册失败", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in new issue