package com.example.yzy_qq;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ListActivity; import android.app.ProgressDialog; import android.content.Intent; import android.os.Bundle; import android.os.SystemClock; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast;
import com.example.yzy_qq.user.Register; import com.example.yzy_qq.user.UserDB; import com.example.yzy_qq.user.user; import com.example.yzy_qq.utils.AllUser; import com.example.yzy_qq.utils.DataHelper;
public class Login extends AppCompatActivity implements View.OnClickListener { private UserDB userDB; private user user; private EditText accountET, pwdET; private CheckBox remember; private Button LoginButton, RegistButton; private TextView alluser; private ProgressBar progressBar; ProgressDialog prodialog;
public static final String TAG = Login.class.getName(); private ImageView iv_showCode; private EditText et_phoneCode; private EditText et_phoneNum; //产生的验证码 private String realCode; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); accountET=findViewById(R.id.accountedit); pwdET=findViewById(R.id.passwordedit); iv_showCode = (ImageView) findViewById(R.id.iv_showCode); //将验证码用图片的形式显示出来 iv_showCode.setImageBitmap(Code.getInstance().createBitmap()); realCode = Code.getInstance().getCode().toLowerCase(); iv_showCode.setOnClickListener(this); final ProgressDialog dialog = new ProgressDialog(this); et_phoneCode = (EditText) findViewById(R.id.et_phoneCodes); Button button1 = (Button) findViewById(R.id.go); button1.setOnClickListener(this); Button button2 = (Button) findViewById(R.id.add); Button button3 = (Button) findViewById(R.id.forget); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Login.this, Register.class); startActivity(intent); } }); button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Login.this, FindPwd.class); startActivity(intent); } }); } @Override public void onClick(View v) { userDB =new UserDB(); userDB.OpenUserDb(this); String account, password; account=accountET.getText().toString(); password=pwdET.getText().toString(); user = userDB.findUserByAccout(account); switch (v.getId()) { case R.id.iv_showCode: iv_showCode.setImageBitmap(Code.getInstance().createBitmap()); realCode = Code.getInstance().getCode().toLowerCase(); Log.v(TAG, "realCode" + realCode); break; case R.id.go: String phoneCode = et_phoneCode.getText().toString().toLowerCase(); if (user == null) { Toast.makeText(this, "账号不存在", Toast.LENGTH_SHORT).show(); return; } else if(!account.equals(user.getAccount()) || !password.equals(user.getPassword())){ Toast.makeText(this, "账号或密码错误", Toast.LENGTH_SHORT).show(); }else if(!phoneCode.equals(realCode)){ Toast.makeText(this, "验证码错误", Toast.LENGTH_SHORT).show(); } else if (account.equals(user.getAccount())&&password.equals(user.getPassword())&&phoneCode.equals(realCode)) { final ProgressDialog dialog = new ProgressDialog(this); dialog.setTitle("正在登录,请稍后..."); // 设置一下进度条的样式 dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // 最后一步一定要记得show 出来 dialog.show(); // 创建一个子线程 new Thread() { public void run() { // 设置进度条最大值 dialog.setMax(100); // 设置当前进度 for (int i = 0; i <= 100; i++) { dialog.setProgress(i); // 睡眠一会 SystemClock.sleep(20); } // 关闭对话框 dialog.dismiss(); Intent intent = new Intent(Login.this, User.class); intent.putExtra("account",user.getAccount()); intent.putExtra("name",user.getName()); intent.putExtra("age",user.getAge()); intent.putExtra("sex",user.getSex()); intent.putExtra("psd",user.getPassword()); startActivity(intent); }; }.start(); } else { Toast.makeText(Login.this, phoneCode + "验证码错误", Toast.LENGTH_SHORT).show(); } break; } } }