diff --git a/数据库/voice/.idea/codeStyles/Project.xml b/数据库/voice/.idea/codeStyles/Project.xml index 30aa626..d5ec3da 100644 --- a/数据库/voice/.idea/codeStyles/Project.xml +++ b/数据库/voice/.idea/codeStyles/Project.xml @@ -1,5 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/数据库/voice/.idea/dbnavigator.xml b/数据库/voice/.idea/dbnavigator.xml new file mode 100644 index 0000000..5d9e5e9 --- /dev/null +++ b/数据库/voice/.idea/dbnavigator.xml @@ -0,0 +1,453 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/数据库/voice/app/build.gradle b/数据库/voice/app/build.gradle index fce28db..418c015 100644 --- a/数据库/voice/app/build.gradle +++ b/数据库/voice/app/build.gradle @@ -27,4 +27,5 @@ dependencies { androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' + implementation 'com.android.support:recyclerview-v7:27.1.1' } diff --git a/数据库/voice/app/libs/MobCommons-2018.1128.1916.jar b/数据库/voice/app/libs/MobCommons-2018.1128.1916.jar new file mode 100644 index 0000000..def8c9a Binary files /dev/null and b/数据库/voice/app/libs/MobCommons-2018.1128.1916.jar differ diff --git a/数据库/voice/app/libs/MobTools-2018.1128.1916.jar b/数据库/voice/app/libs/MobTools-2018.1128.1916.jar new file mode 100644 index 0000000..5a03eef Binary files /dev/null and b/数据库/voice/app/libs/MobTools-2018.1128.1916.jar differ diff --git a/数据库/voice/app/libs/SDKWrapper-2018.0801.1824.jar b/数据库/voice/app/libs/SDKWrapper-2018.0801.1824.jar new file mode 100644 index 0000000..121c4b8 Binary files /dev/null and b/数据库/voice/app/libs/SDKWrapper-2018.0801.1824.jar differ diff --git a/数据库/voice/app/libs/SMSSDK-3.3.0.jar b/数据库/voice/app/libs/SMSSDK-3.3.0.jar new file mode 100644 index 0000000..8d028e0 Binary files /dev/null and b/数据库/voice/app/libs/SMSSDK-3.3.0.jar differ diff --git a/数据库/voice/app/src/main/AndroidManifest.xml b/数据库/voice/app/src/main/AndroidManifest.xml index b71db8c..65a7c84 100644 --- a/数据库/voice/app/src/main/AndroidManifest.xml +++ b/数据库/voice/app/src/main/AndroidManifest.xml @@ -2,7 +2,18 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/数据库/voice/app/src/main/java/com/example/cici/dao/DBOpenHelper.java b/数据库/voice/app/src/main/java/com/example/cici/dao/DBOpenHelper.java index 6e2f89a..26f4f78 100644 --- a/数据库/voice/app/src/main/java/com/example/cici/dao/DBOpenHelper.java +++ b/数据库/voice/app/src/main/java/com/example/cici/dao/DBOpenHelper.java @@ -5,22 +5,25 @@ 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 { - public DBOpenHelper(Context context,String name, CursorFactory factory, - int version) { - super(context, name, factory, version); + 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 not null," + - "birthday text not null," + - "sex text not null," + - "phonenum text not null," + - "headpic 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,"+ @@ -34,8 +37,13 @@ public class DBOpenHelper extends SQLiteOpenHelper { } @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<> } diff --git a/数据库/voice/app/src/main/java/com/example/cici/util/TimeCountUtil.java b/数据库/voice/app/src/main/java/com/example/cici/util/TimeCountUtil.java new file mode 100644 index 0000000..32d411e --- /dev/null +++ b/数据库/voice/app/src/main/java/com/example/cici/util/TimeCountUtil.java @@ -0,0 +1,29 @@ +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("重新获取验证码"); + } +} \ No newline at end of file diff --git a/数据库/voice/app/src/main/java/com/example/cici/voice/LoginActivity.java b/数据库/voice/app/src/main/java/com/example/cici/voice/LoginActivity.java index 18a3d14..d331a9b 100644 --- a/数据库/voice/app/src/main/java/com/example/cici/voice/LoginActivity.java +++ b/数据库/voice/app/src/main/java/com/example/cici/voice/LoginActivity.java @@ -36,16 +36,16 @@ public class LoginActivity extends AppCompatActivity { } //call DBOpenHelper - DBOpenHelper helper = new DBOpenHelper(this,"voice.db",null,1); + 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()){ + /* while(c.moveToNext()){ for(String ColumnName:cols){ Log.i("info",ColumnName+":"+c.getString(c.getColumnIndex(ColumnName))); } - } + }*/ c.close(); db.close(); diff --git a/数据库/voice/app/src/main/java/com/example/cici/voice/RegistActivity.java b/数据库/voice/app/src/main/java/com/example/cici/voice/RegistActivity.java index d1f4b6e..6e58c93 100644 --- a/数据库/voice/app/src/main/java/com/example/cici/voice/RegistActivity.java +++ b/数据库/voice/app/src/main/java/com/example/cici/voice/RegistActivity.java @@ -1,72 +1,271 @@ 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.Bundle; +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.pubFun; +import com.example.cici.util.TimeCountUtil; +import cn.smssdk.EventHandler; +import cn.smssdk.SMSSDK; -public class RegistActivity extends AppCompatActivity { - private EditText editPhone; +public class RegistActivity extends AppCompatActivity implements View.OnClickListener { + + private EditText edit_phone; + private EditText edit_cord; private EditText editPwd; - private Button btnRegist; - protected void onCreate(Bundle savedInstanceState){ + 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); - editPhone = (EditText) findViewById(R.id.editPhone); - editPwd = (EditText) findViewById(R.id.editPwd); - btnRegist = (Button) findViewById(R.id.btnRegist); + 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); } /** - * register event - * @param v + * 使用Handler来分发Message对象到主线程中,处理事件 */ - public void OnMyRegistClick(View v) + Handler handler=new Handler() { - boolean isTrue = true; - if(pubFun.isPhoneNumberValid(editPhone.getText().toString()) == false){ - isTrue = false; - Toast.makeText(this, "手机号格式不正确!", Toast.LENGTH_SHORT).show(); - return; + @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(); + } + } + } - if(pubFun.isEmpty(editPwd.getText().toString())){ - isTrue = false; - Toast.makeText(this, "密码不能为空!", Toast.LENGTH_SHORT).show(); - return; + + }; + + /** + * 获取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; } + } - if(isTrue = true){ - //call DBOpenHelper - DBOpenHelper helper = new DBOpenHelper(this,".db",null,1); - 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){ - Toast.makeText(this, "该用户已存在", Toast.LENGTH_SHORT).show(); - c.close(); - } - else{ - //insert data - ContentValues values= new ContentValues(); - values.put("userID",editPhone.getText().toString()); - values.put("pwd",editPwd.getText().toString()); - long rowid = db.insert("user_tb",null,values); - - Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show(); - this.finish(); + 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; } - db.close(); - }else{ - return; } } -} + + 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; + } + + } + + +} \ No newline at end of file diff --git a/数据库/voice/app/src/main/java/com/example/cici/voice/ResPwdActivity.java b/数据库/voice/app/src/main/java/com/example/cici/voice/ResPwdActivity.java index e67a0f4..9343ed7 100644 --- a/数据库/voice/app/src/main/java/com/example/cici/voice/ResPwdActivity.java +++ b/数据库/voice/app/src/main/java/com/example/cici/voice/ResPwdActivity.java @@ -53,7 +53,7 @@ public class ResPwdActivity extends AppCompatActivity { } //调用DBOpenHelper - DBOpenHelper helper = new DBOpenHelper(this,"voice.db",null,1); + 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){ diff --git a/数据库/voice/app/src/main/res/layout/regist.xml b/数据库/voice/app/src/main/res/layout/regist.xml index 24db992..1d684e8 100644 --- a/数据库/voice/app/src/main/res/layout/regist.xml +++ b/数据库/voice/app/src/main/res/layout/regist.xml @@ -1,69 +1,165 @@ - - - - - - - - -