remotes/checkIfPRContentChanged-1684754070987251875/develop
向金成 2 years ago
parent 87a0cc3ea9
commit 3fbca3c73a

@ -0,0 +1,135 @@
package net.micode.notes.ui;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.tool.CheckUtils;
import java.io.IOException;
import java.util.Timer;
import java.util.zip.Inflater;
public class LoginActivity extends Activity {
String account;
String password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.login);
//保存输入信息
EditText inputAccount = (EditText)findViewById(R.id.login_aacount);
EditText inputPassword = (EditText) findViewById(R.id.login_password);
inputAccount.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) {
}
@Override
public void afterTextChanged(Editable s) {
account = s.toString();
}
});
inputPassword.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) {
}
@Override
public void afterTextChanged(Editable s) {
password = s.toString();
}
});
//登录按钮
Button loginButton = (Button) findViewById(R.id.login_accept);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckUtils checkUtils = null;
try {
checkUtils = new CheckUtils(LoginActivity.this);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
if(checkUtils.check(account,password)){
Intent intent = new Intent(LoginActivity.this,NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
}
else{
Toast checkErrorToast = Toast.makeText(LoginActivity.this,R.string.check_error,Toast.LENGTH_SHORT);
checkErrorToast.show();
}
}
});
//注册按钮
Button registerButton = (Button) findViewById(R.id.login_register);
registerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//输入非空
if(account != null && password != null) {
CheckUtils checkUtils = null;
try {
checkUtils = new CheckUtils(LoginActivity.this);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
try {
checkUtils.loginData.write(account,password,LoginActivity.this);
} catch (IOException e) {
throw new RuntimeException(e);
}
Toast registerOKToast = Toast.makeText(LoginActivity.this, R.string.register_ok, Toast.LENGTH_SHORT);
registerOKToast.show();
Intent intent = new Intent(LoginActivity.this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
}
else {
account = null;
password = null;
Toast toast = Toast.makeText(LoginActivity.this,R.string.input_error,Toast.LENGTH_SHORT);
toast.show();
}
}
});
}
}
Loading…
Cancel
Save