From af18e75a6bd108bfe0818b081469b7d2b2ab5f1e Mon Sep 17 00:00:00 2001 From: unknown <654649447@qq.com> Date: Fri, 4 Jan 2019 19:34:41 +0800 Subject: [PATCH] first commit --- 前端/前端设计.txt | 0 数据库/voice/.idea/gradle.xml | 6 ++ 数据库/voice/.idea/misc.xml | 31 ++++++- 数据库/voice/app/build.gradle | 12 +-- .../example/cici/voice/LoginActivityTest.java | 7 ++ .../voice/app/src/main/AndroidManifest.xml | 4 +- .../com/example/cici/dao/DBOpenHelper.java | 41 +++++++++ .../java/com/example/cici/util/pubFun.java | 37 ++++++++ .../com/example/cici/voice/LoginActivity.java | 84 +++++++++++++++++ .../example/cici/voice/RegistActivity.java | 72 +++++++++++++++ .../example/cici/voice/ResPwdActivity.java | 88 ++++++++++++++++++ .../voice/app/src/main/res/layout/login.xml | 90 +++++++++++++++++++ .../voice/app/src/main/res/layout/regist.xml | 69 ++++++++++++++ .../app/src/main/res/layout/res_password.xml | 75 ++++++++++++++++ .../voice/app/src/main/res/values/strings.xml | 7 ++ .../voice/app/src/main/res/values/styles.xml | 9 +- 数据库/voice/build.gradle | 2 + 最终项目/最终项目交付.txt | 0 设计/图标设计.txt | 0 19 files changed, 626 insertions(+), 8 deletions(-) delete mode 100644 前端/前端设计.txt create mode 100644 数据库/voice/app/src/androidTest/java/com/example/cici/voice/LoginActivityTest.java create mode 100644 数据库/voice/app/src/main/java/com/example/cici/dao/DBOpenHelper.java create mode 100644 数据库/voice/app/src/main/java/com/example/cici/util/pubFun.java create mode 100644 数据库/voice/app/src/main/java/com/example/cici/voice/LoginActivity.java create mode 100644 数据库/voice/app/src/main/java/com/example/cici/voice/RegistActivity.java create mode 100644 数据库/voice/app/src/main/java/com/example/cici/voice/ResPwdActivity.java create mode 100644 数据库/voice/app/src/main/res/layout/login.xml create mode 100644 数据库/voice/app/src/main/res/layout/regist.xml create mode 100644 数据库/voice/app/src/main/res/layout/res_password.xml delete mode 100644 最终项目/最终项目交付.txt delete mode 100644 设计/图标设计.txt diff --git a/前端/前端设计.txt b/前端/前端设计.txt deleted file mode 100644 index e69de29..0000000 diff --git a/数据库/voice/.idea/gradle.xml b/数据库/voice/.idea/gradle.xml index 76a4349..7ac24c7 100644 --- a/数据库/voice/.idea/gradle.xml +++ b/数据库/voice/.idea/gradle.xml @@ -5,6 +5,12 @@ diff --git a/数据库/voice/.idea/misc.xml b/数据库/voice/.idea/misc.xml index aed02e1..e0d5b93 100644 --- a/数据库/voice/.idea/misc.xml +++ b/数据库/voice/.idea/misc.xml @@ -1,6 +1,35 @@ - + + + + + diff --git a/数据库/voice/app/build.gradle b/数据库/voice/app/build.gradle index 20ab839..fce28db 100644 --- a/数据库/voice/app/build.gradle +++ b/数据库/voice/app/build.gradle @@ -1,11 +1,11 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 28 + compileSdkVersion 27 defaultConfig { applicationId "com.example.cici.voice" - minSdkVersion 15 - targetSdkVersion 28 + minSdkVersion 18 + targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -20,9 +20,11 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' 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' } diff --git a/数据库/voice/app/src/androidTest/java/com/example/cici/voice/LoginActivityTest.java b/数据库/voice/app/src/androidTest/java/com/example/cici/voice/LoginActivityTest.java new file mode 100644 index 0000000..c612023 --- /dev/null +++ b/数据库/voice/app/src/androidTest/java/com/example/cici/voice/LoginActivityTest.java @@ -0,0 +1,7 @@ +package com.example.cici.voice; + +import static org.junit.Assert.*; + +public class LoginActivityTest { + +} \ No newline at end of file diff --git a/数据库/voice/app/src/main/AndroidManifest.xml b/数据库/voice/app/src/main/AndroidManifest.xml index d0c7270..b71db8c 100644 --- a/数据库/voice/app/src/main/AndroidManifest.xml +++ b/数据库/voice/app/src/main/AndroidManifest.xml @@ -9,13 +9,15 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" > - + + + \ 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 new file mode 100644 index 0000000..6e2f89a --- /dev/null +++ b/数据库/voice/app/src/main/java/com/example/cici/dao/DBOpenHelper.java @@ -0,0 +1,41 @@ + +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){ + + } + +} + diff --git a/数据库/voice/app/src/main/java/com/example/cici/util/pubFun.java b/数据库/voice/app/src/main/java/com/example/cici/util/pubFun.java new file mode 100644 index 0000000..f989549 --- /dev/null +++ b/数据库/voice/app/src/main/java/com/example/cici/util/pubFun.java @@ -0,0 +1,37 @@ +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= 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); + } + } + 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 new file mode 100644 index 0000000..d1f4b6e --- /dev/null +++ b/数据库/voice/app/src/main/java/com/example/cici/voice/RegistActivity.java @@ -0,0 +1,72 @@ +package com.example.cici.voice; + + +import android.content.ContentValues; +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 RegistActivity extends AppCompatActivity { + private EditText editPhone; + private EditText editPwd; + private Button btnRegist; + 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); + } + + /** + * register event + * @param v + */ + public void OnMyRegistClick(View v) + { + boolean isTrue = true; + if(pubFun.isPhoneNumberValid(editPhone.getText().toString()) == false){ + isTrue = false; + Toast.makeText(this, "手机号格式不正确!", Toast.LENGTH_SHORT).show(); + return; + } + if(pubFun.isEmpty(editPwd.getText().toString())){ + isTrue = false; + Toast.makeText(this, "密码不能为空!", Toast.LENGTH_SHORT).show(); + return; + } + + 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(); + } + db.close(); + }else{ + return; + } + } +} 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 new file mode 100644 index 0000000..e67a0f4 --- /dev/null +++ b/数据库/voice/app/src/main/java/com/example/cici/voice/ResPwdActivity.java @@ -0,0 +1,88 @@ +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,"voice.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){ + 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(); + } + } +} diff --git a/数据库/voice/app/src/main/res/layout/login.xml b/数据库/voice/app/src/main/res/layout/login.xml new file mode 100644 index 0000000..08ee87d --- /dev/null +++ b/数据库/voice/app/src/main/res/layout/login.xml @@ -0,0 +1,90 @@ + + + + + + + + + +