first commit

master
unknown 6 years ago
parent 1b9865e7a9
commit f7256cc286

@ -1,40 +0,0 @@
package com.example.cici.dao;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
public class DBOpenHelper extends SQLiteOpenHelper {
public DBOpenHelper(Context context,String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists user_tb(_id integer primary key autoincrement," +
"userID text not null," +
"pwd text not null," +
"name text not null," +
"birthday text not null," +
"sex text not null," +
"phonenum text not null," +
"headpic text not null)");
db.execSQL("create table if not exists voice_tb(_id integer primary key autoincrement," +
"voiceID text not null," +
"voicecontent text not null,"
"sharemoment integer," +
"diary integer," +
"memorandum integer," +
"report integer)");
db.execSQL("create table if not exists publish_tb(_id integer primary key autoincrement," +
"voiceID text not null," +
"userID text not null)");
}
@Override
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){
}
}

@ -1,49 +0,0 @@
package com.example.cici.dao;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.Cursor;
import java.util.ArrayList;
public class DBOpenHelper extends SQLiteOpenHelper {
private SQLiteDatabase db;
public DBOpenHelper(Context context) {
super(context, "voice", null, 1);
db=getReadableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists user_tb(_id integer primary key autoincrement," +
"userID text not null," +
"pwd text not null," +
"name text ," +
"birthday text ," +
"sex text ," +
"headpic text )");
db.execSQL("create table if not exists voice_tb(_id integer primary key autoincrement," +
"voiceID text not null," +
"voicecontent text not null,"+
"sharemoment integer," +
"diary integer," +
"memorandum integer," +
"report integer)");
db.execSQL("create table if not exists publish_tb(_id integer primary key autoincrement," +
"voiceID text not null," +
"userID text not null)");
}
@Override
public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){
db.execSQL("DROP TABLE IF EXISTS user_tb");
db.execSQL("DROP TABLE IF EXISTS voice_tb");
db.execSQL("DROP TABLE IF EXISTS publish_tb");
onCreate(db);
}
// public ArrayList<>
}

@ -98,10 +98,10 @@ public class LoginActivity extends AppCompatActivity {
* Jump to reset password interface
* @param v
*/
public void OnMyResPwdClick(View v){
/* public void OnMyResPwdClick(View v){
Intent intent=new Intent(LoginActivity.this,ResPwdActivity.class);
LoginActivity.this.startActivity(intent);
}
}*/
private boolean isHaveUser(String user){

@ -132,6 +132,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClick
if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {
Toast.makeText(getApplicationContext(), "验证码输入正确",
Toast.LENGTH_LONG).show();
changeHead();
}
}
else
@ -186,7 +187,6 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClick
if(judCord())
{
SMSSDK.submitVerificationCode("86", phone_number, cord_number);
changeHead();
}
flag=false;
break;

@ -1,29 +0,0 @@
package com.example.cici.util;
import android.os.CountDownTimer;
import android.widget.Button;
public class TimeCountUtil extends CountDownTimer {
private Button mButton;
public TimeCountUtil(Button button, long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
this.mButton = button;
}
@Override
public void onTick(long millisUntilFinished) {
// 按钮不可用
mButton.setEnabled(false);
String showText = millisUntilFinished / 1000 + "秒后可重新发送";
mButton.setText(showText);
}
@Override
public void onFinish() {
// 按钮设置可用
mButton.setEnabled(true);
mButton.setText("重新获取验证码");
}
}

@ -1,37 +0,0 @@
package com.example.cici.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class pubFun{
public static boolean isEmpty(String input)
{
if(input==null ||"".equals(input))
return true;
for(int i=0;i<input.length();i++)
{
char c=input.charAt(i);
if(c!=' '&&c!='\t'&&c!='\r'&&c!='\n')
{
return false;
}
}
return true;
}
public static boolean isPhoneNumberValid(String phoneNumber){
boolean isValid=false;
String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{5})$";
String expression2 = "^\\(?(\\d{3})\\)?[- ]?(\\d{4})[- ]?(\\d{4})$";
CharSequence inputStr = phoneNumber;
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(inputStr);
Pattern pattern2 = Pattern.compile(expression2);
Matcher matcher2 = pattern2.matcher(inputStr);
if(matcher.matches() || matcher2.matches()) {
isValid = true;
}
return isValid;
}
}

@ -1,84 +0,0 @@
package com.example.cici.voice;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.cici.dao.DBOpenHelper;
import com.example.cici.util.pubFun;
public class LoginActivity extends AppCompatActivity {
private EditText editPhone;
private EditText editPwd;
private Button btnLogin;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
editPhone = (EditText) findViewById(R.id.editPhone);
editPwd = (EditText) findViewById(R.id.editPwd);
btnLogin = (Button) findViewById(R.id.btnLogin);
}
public void OnMyLoginClick(View v) {
if(pubFun.isEmpty(editPhone.getText().toString()) || pubFun.isEmpty(editPwd.getText().toString())){
Toast.makeText(this, "手机号或密码不能为空!", Toast.LENGTH_SHORT).show();
return;
}
//call DBOpenHelper
DBOpenHelper helper = new DBOpenHelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
Cursor c = db.query("user_tb",null,"userID=? and pwd=?",new String[]{editPhone.getText().toString(),editPwd.getText().toString()},null,null,null);
if(c!=null && c.getCount() >= 1){
String[] cols = c.getColumnNames();
/* while(c.moveToNext()){
for(String ColumnName:cols){
Log.i("info",ColumnName+":"+c.getString(c.getColumnIndex(ColumnName)));
}
}*/
c.close();
db.close();
//将登陆用户信息存储到SharedPreferences中
SharedPreferences mySharedPreferences= getSharedPreferences("setting",Activity.MODE_PRIVATE); //实例化SharedPreferences对象
SharedPreferences.Editor editor = mySharedPreferences.edit();//实例化SharedPreferences.Editor对象
editor.putString("userID", editPhone.getText().toString()); //用putString的方法保存数据
editor.commit(); //提交当前数据
this.finish();
}
else{
Toast.makeText(this, "手机号或密码输入错误!", Toast.LENGTH_SHORT).show();
}
}
/**
* Jump to the registration interface
* @param v
*/
public void OnMyRegistClick(View v) {
Intent intent=new Intent(LoginActivity.this,RegistActivity.class);
//intent.putExtra("info", "No66778899");
LoginActivity.this.startActivity(intent);
}
/**
* Jump to reset password interface
* @param v
*/
public void OnMyResPwdClick(View v){
Intent intent=new Intent(LoginActivity.this,ResPwdActivity.class);
LoginActivity.this.startActivity(intent);
}
}

@ -1,13 +0,0 @@
package com.example.cici.voice;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

@ -1,271 +0,0 @@
package com.example.cici.voice;
import java.util.Calendar;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;
import android.util.Log;
import android.widget.DatePicker;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import com.example.cici.dao.DBOpenHelper;
import com.example.cici.util.TimeCountUtil;
import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
public class RegistActivity extends AppCompatActivity implements View.OnClickListener {
private EditText edit_phone;
private EditText edit_cord;
private EditText editPwd;
private EditText editName;
private TextView now;
private Button btn_getCord;
private Button btn_register;
private RadioButton mMaleRb;
private RadioButton mFamaleRb;
private String phone_number;
private String cord_number;
EventHandler eventHandler;
private TimeCountUtil mTimeCountUtil;
private int time=60;
private boolean flag=true;
private TextView tvShowDialog;
private Calendar cal;
private int year,month,day;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.regist);
getDate();
getId();
mTimeCountUtil = new TimeCountUtil(btn_getCord, 10000, 1000);
eventHandler = new EventHandler() {
public void afterEvent(int event, int result, Object data) {
Message msg=new Message();
msg.arg1=event;
msg.arg2=result;
msg.obj=data;
handler.sendMessage(msg);
}
};
SMSSDK.registerEventHandler(eventHandler);
}
private void getDate() {
cal=Calendar.getInstance();
year=cal.get(Calendar.YEAR); //获取年月日时分秒
Log.i("wxy","year"+year);
month=cal.get(Calendar.MONTH); //获取到的月份是从0开始计数
day=cal.get(Calendar.DAY_OF_MONTH);
}
@Override
protected void onDestroy() {
super.onDestroy();
SMSSDK.unregisterEventHandler(eventHandler);
}
/**
* 使HandlerMessage线
*/
Handler handler=new Handler()
{
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
int event=msg.arg1;
int result=msg.arg2;
Object data=msg.obj;
if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE) {
if(result == SMSSDK.RESULT_COMPLETE) {
boolean smart = (Boolean)data;
if(smart) {
Toast.makeText(getApplicationContext(),"该手机号已经注册过,请重新输入",
Toast.LENGTH_LONG).show();
edit_phone.requestFocus();
return;
}
}
}
if(result==SMSSDK.RESULT_COMPLETE)
{
if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {
Toast.makeText(getApplicationContext(), "验证码输入正确",
Toast.LENGTH_LONG).show();
}
}
else
{
if(flag)
{
btn_getCord.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(),"验证码获取失败请重新获取", Toast.LENGTH_LONG).show();
edit_phone.requestFocus();
}
else
{
Toast.makeText(getApplicationContext(),"验证码输入错误", Toast.LENGTH_LONG).show();
}
}
}
};
/**
* id
*/
private void getId()
{
edit_phone=findViewById(R.id.editPhone);
edit_cord=findViewById(R.id.editCode);
btn_getCord=findViewById(R.id.btnGetcord);
btn_register=findViewById(R.id.btnRegist);
editPwd = (EditText) findViewById(R.id.editPwd);
editName=findViewById(R.id.editName);
mMaleRb = (RadioButton)findViewById(R.id.male);
mFamaleRb = (RadioButton)findViewById(R.id.famle);
tvShowDialog=(TextView) findViewById(R.id.tvShowDialog);
tvShowDialog.setOnClickListener(this);
btn_getCord.setOnClickListener(this);
btn_register.setOnClickListener(this);
}
/**
*
*/
public void onClick(View v)
{
switch (v.getId())
{
case R.id.btnGetcord:
if(judPhone())//去掉左右空格获取字符串
{
mTimeCountUtil.start();
SMSSDK.getVerificationCode("86",phone_number);
edit_cord.requestFocus();
}
break;
case R.id.btnRegist:
if(judCord())
SMSSDK.submitVerificationCode("86",phone_number,cord_number);
DBOpenHelper helper = new DBOpenHelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
Cursor c = db.query("user_tb",null,"userID=?",new String[]{edit_phone.getText().toString()},null,null,null);
if(c!=null && c.getCount() >= 1){
Toast.makeText(this, "该用户已存在", Toast.LENGTH_SHORT).show();
c.close();
}
else{
//insert data
ContentValues values= new ContentValues();
values.put("userID",edit_phone.getText().toString());
values.put("pwd",editPwd.getText().toString());
values.put("name",editName.getText().toString());
values.put("birthday",tvShowDialog.getText().toString());
if(mMaleRb.isChecked()){
values.put("sex",mMaleRb.getText().toString());
}
else values.put("sex",mFamaleRb.getText().toString());
long rowid = db.insert("user_tb",null,values);
Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
this.finish();
}
db.close();
flag=false;
break;
case R.id.tvShowDialog:
OnDateSetListener listener=new OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int year, int month, int day) {
tvShowDialog.setText(year+"-"+(++month)+"-"+day); //将选择的日期显示到TextView中,因为之前获取month直接使用所以不需要+1这个地方需要显示所以+1
}
};
DatePickerDialog dialog=new DatePickerDialog(RegistActivity.this, 0,listener,year,month,day);//后边三个参数为显示dialog时默认的日期月份从0开始0-11对应1-12个月
dialog.show();
break;
default:
break;
}
}
private boolean judPhone()
{
if(TextUtils.isEmpty(edit_phone.getText().toString().trim()))
{
Toast.makeText(RegistActivity.this,"请输入您的电话号码",Toast.LENGTH_LONG).show();
edit_phone.requestFocus();
return false;
}
else if(edit_phone.getText().toString().trim().length()!=11)
{
Toast.makeText(RegistActivity.this,"您的电话号码位数不正确",Toast.LENGTH_LONG).show();
edit_phone.requestFocus();
return false;
}
else
{
phone_number=edit_phone.getText().toString().trim();
String num="[1][358]\\d{9}";
if(phone_number.matches(num))
return true;
else
{
Toast.makeText(RegistActivity.this,"请输入正确的手机号码",Toast.LENGTH_LONG).show();
return false;
}
}
}
private boolean judCord()
{
judPhone();
if(TextUtils.isEmpty(edit_cord.getText().toString().trim()))
{
Toast.makeText(RegistActivity.this,"请输入您的验证码",Toast.LENGTH_LONG).show();
edit_cord.requestFocus();
return false;
}
else if(edit_cord.getText().toString().trim().length()!=4)
{
Toast.makeText(RegistActivity.this,"您的验证码位数不正确",Toast.LENGTH_LONG).show();
edit_cord.requestFocus();
return false;
}
else
{
cord_number=edit_cord.getText().toString().trim();
return true;
}
}
}

@ -1,88 +0,0 @@
package com.example.cici.voice;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.cici.dao.DBOpenHelper;
import com.example.cici.util.pubFun;
public class ResPwdActivity extends AppCompatActivity {
private EditText editPhone;
private EditText editPwd;
private EditText editResPwd;
private Button btnConfirm;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.res_password);
editPhone = (EditText) findViewById(R.id.editPhone);
editPwd = (EditText) findViewById(R.id.editPwd);
editResPwd = (EditText) findViewById(R.id.editResPwd);
btnConfirm = (Button) findViewById(R.id.btnConfirm);
}
/**
* confirm event
* @param v
*/
public void OnMyConfirmClick(View v) {
confirmInfo();
}
/**
* confirm event
*/
private void confirmInfo() {
if(pubFun.isEmpty(editPhone.getText().toString()) || pubFun.isEmpty(editPwd.getText().toString()) || pubFun.isEmpty(editResPwd.getText().toString())){
Toast.makeText(this, "手机号或密码不能为空!", Toast.LENGTH_SHORT).show();
return;
}
if(!editPwd.getText().toString().equals(editResPwd.getText().toString())){
Toast.makeText(this, "输入密码不正确!", Toast.LENGTH_SHORT).show();
return;
}
//调用DBOpenHelper
DBOpenHelper helper = new DBOpenHelper(this);
SQLiteDatabase db = helper.getWritableDatabase();
Cursor c = db.query("user_tb",null,"userID=?",new String[]{editPhone.getText().toString()},null,null,null);
if(c!=null && c.getCount() >= 1){
ContentValues cv = new ContentValues();
cv.put("pwd", editPwd.getText().toString());
String[] args = {String.valueOf(editPhone.getText().toString())};
long rowid = db.update("user_tb", cv, "userID=?",args);
c.close();
db.close();
Toast.makeText(this, "密码重置成功!", Toast.LENGTH_SHORT).show();
this.finish();
}
else{
new AlertDialog.Builder(this)
.setTitle("提示")
.setMessage("该用户不存在,请到注册界面进行注册!")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
setResult(RESULT_OK);
Intent intent=new Intent(ResPwdActivity.this,RegistActivity.class);
ResPwdActivity.this.startActivity(intent);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
return;
}
})
.show();
}
}
}

@ -50,18 +50,7 @@
app:layout_constraintTop_toBottomOf="@+id/et_pwd"
app:layout_constraintVertical_bias="0.793" />
<TextView
android:id="@+id/txtForgetPwd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="80dp"
android:clickable="true"
android:onClick="OnMyResPwdClick"
android:text="忘记密码"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints" />
<TextView
android:id="@+id/txtStartRegist"

Loading…
Cancel
Save