parent
cab9bb682d
commit
9ad8ef00b7
@ -0,0 +1,88 @@
|
|||||||
|
package com.example.myapplication;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.ContentValues;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
|
public class RegistrationPage extends Activity implements View.OnClickListener {
|
||||||
|
public static final String TAG = RegistrationPage.class.getName();
|
||||||
|
private ImageView iv_showCode;
|
||||||
|
private EditText et_phoneCode;
|
||||||
|
private EditText ETphone_number;
|
||||||
|
private EditText ETpassword;
|
||||||
|
private SQLiteDatabase sqLiteDatabase;
|
||||||
|
private MyHelper myHelper;
|
||||||
|
private String phone_number;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
//产生的验证码
|
||||||
|
private String realCode;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.regist_layout);
|
||||||
|
ETphone_number=findViewById(R.id.phone_number);
|
||||||
|
|
||||||
|
ETpassword=findViewById(R.id.password);
|
||||||
|
|
||||||
|
myHelper=new MyHelper(this);
|
||||||
|
sqLiteDatabase=myHelper.getWritableDatabase();
|
||||||
|
et_phoneCode = findViewById(R.id.Code);
|
||||||
|
Button but_toSetCode = findViewById(R.id.btn_regist);
|
||||||
|
but_toSetCode.setOnClickListener(this);
|
||||||
|
iv_showCode = findViewById(R.id.iv_showCode);
|
||||||
|
//将验证码用图片的形式显示出来
|
||||||
|
iv_showCode.setImageBitmap(Code.getInstance().createBitmap());
|
||||||
|
realCode = Code.getInstance().getCode().toLowerCase();
|
||||||
|
iv_showCode.setOnClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
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.btn_regist:
|
||||||
|
String phoneCode = et_phoneCode.getText().toString().toLowerCase();
|
||||||
|
password = ETpassword.getText().toString();
|
||||||
|
phone_number=ETphone_number.getText().toString();
|
||||||
|
// String msg = "生成的验证码:"+realCode+"输入的验证码:"+phoneCode;
|
||||||
|
//Toast.makeText(注册页面.this,msg,Toast.LENGTH_LONG).show();
|
||||||
|
if (password.trim().equals("")) {
|
||||||
|
Toast.makeText(RegistrationPage.this, phoneCode + "密码不能为空", Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (phone_number.trim().equals("")){
|
||||||
|
Toast.makeText(RegistrationPage.this, phoneCode + "手机号不能为空", Toast.LENGTH_SHORT).show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (phoneCode.equals(realCode)) {
|
||||||
|
Toast.makeText(RegistrationPage.this, phoneCode + "验证码正确", Toast.LENGTH_SHORT).show();
|
||||||
|
ContentValues values =new ContentValues();
|
||||||
|
|
||||||
|
values.put("user_phone_number", phone_number);
|
||||||
|
values.put("user_password", password);
|
||||||
|
sqLiteDatabase.insert("USERS", null,values);
|
||||||
|
Toast.makeText(RegistrationPage.this, "注册成功", Toast.LENGTH_SHORT).show();
|
||||||
|
RegistrationPage.this.startActivity( new Intent(RegistrationPage.this, LandingPage.class));
|
||||||
|
} else {
|
||||||
|
Toast.makeText(RegistrationPage.this, "验证码错误", Toast.LENGTH_SHORT).show();
|
||||||
|
Toast.makeText(RegistrationPage.this, "注册失败", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue