From 3fbca3c73a9a23033fbc2a297d7f415be399c85d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E9=87=91=E6=88=90?= <2693239786@qq.com> Date: Mon, 22 May 2023 19:14:00 +0800 Subject: [PATCH] 8 --- .../net/micode/notes/ui/LoginActivity.java | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/Notes-master1/app/src/main/java/net/micode/notes/ui/LoginActivity.java diff --git a/src/Notes-master1/app/src/main/java/net/micode/notes/ui/LoginActivity.java b/src/Notes-master1/app/src/main/java/net/micode/notes/ui/LoginActivity.java new file mode 100644 index 00000000..117f859a --- /dev/null +++ b/src/Notes-master1/app/src/main/java/net/micode/notes/ui/LoginActivity.java @@ -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(); + } + } + }); + } + +}