commit fd2db2f8f7ed5b38de853c48817cc1e5b9d6f065 Author: 陈宇欣 <3641588853@qq.com> Date: Sat Apr 4 22:18:09 2026 +0800 提交Android待办项目核心代码 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..43d88b6 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +AAA \ No newline at end of file diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61a9130 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml new file mode 100644 index 0000000..6b50131 --- /dev/null +++ b/.idea/dbnavigator.xml @@ -0,0 +1,461 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..b268ef3 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..639c779 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..722a63c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..66c073f --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,39 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 32 + + defaultConfig { + applicationId "com.example.aaa" + minSdk 25 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.3.0' + + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/aaa/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/aaa/ExampleInstrumentedTest.java new file mode 100644 index 0000000..cbe0e70 --- /dev/null +++ b/app/src/androidTest/java/com/example/aaa/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.aaa; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.aaa", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..4356414 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/aaa/AddActivity.java b/app/src/main/java/com/example/aaa/AddActivity.java new file mode 100644 index 0000000..e84f09a --- /dev/null +++ b/app/src/main/java/com/example/aaa/AddActivity.java @@ -0,0 +1,307 @@ +package com.example.aaa; + + +import android.app.AlarmManager; +import android.app.DatePickerDialog; +import android.app.PendingIntent; +import android.app.TimePickerDialog; +import android.content.Intent; +import android.content.SharedPreferences; +import android.icu.util.Calendar; +import android.icu.util.TimeZone; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.TimePicker; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + + +public class AddActivity extends AppCompatActivity implements View.OnClickListener { + private Button back; //返回按钮 + private CheckBox notif; //返回按钮 + private EditText title; //标题 + private EditText content; //内容 + private ImageView BGTime;//开始时间 + private ImageView FNTime;//结束时间 + private TextView BG_Time_content; + private TextView FN_Time_content; + private Spinner sp_dropdown; + private String strBGTime; + private String strBGDate; + private String strBG; + private String strFNTime; + private String strFNDate; + private String strFN; + private int statu; + private int Hour; + private int Minute; + + private String[] learingSiteArrar = {"学习", "工作", "日常", "生活", "社交", "购物"}; + + private int TongzhiId = 1; + + private Button finish; //完成按钮 + private String get_title; + private String get_content; + private String get_createTime; + private String get_finishTime; + private String get_statu; + private AdapterView.OnItemSelectedListener onItemSelectedListener = new AdapterView.OnItemSelectedListener() { + + @Override + public void onItemSelected(AdapterView adapterView, View view, int postion, long I) { + switch (adapterView.getId()) { + case R.id.sp_dropdown: + //记住点击的选项 + statu = postion; + break; + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add); + + back = (Button) findViewById(R.id.back_add); + notif = (CheckBox) findViewById(R.id.notif); + title = (EditText) findViewById(R.id.title_add); + content = (EditText) findViewById(R.id.context_add); + finish = (Button) findViewById(R.id.finish); + BGTime = (ImageView) findViewById(R.id.BG_Time_Right_jv); + FNTime = (ImageView) findViewById(R.id.FN_Time_Right_jv); + BG_Time_content = (TextView) findViewById(R.id.BG_Time_content); + FN_Time_content = (TextView) findViewById(R.id.FN_Time_content); + sp_dropdown = (Spinner) findViewById(R.id.sp_dropdown); + + finish.setOnClickListener(this); + back.setOnClickListener(this); + BGTime.setOnClickListener(this); + FNTime.setOnClickListener(this); + + + intiDropdownSpinner(); + } + + private void intiDropdownSpinner() { + //初始化AdapterView + Spinner sp_dropdown = (Spinner) findViewById(R.id.sp_dropdown); + sp_dropdown.setPrompt("请选择待办类型"); + ArrayAdapter learningSiteAdapter = new ArrayAdapter(this, + R.layout.item_select, learingSiteArrar); + sp_dropdown.setAdapter(learningSiteAdapter); + sp_dropdown.setSelection(0); + sp_dropdown.setOnItemSelectedListener(onItemSelectedListener); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.finish: { + NoteOperator noteOperator = new NoteOperator(AddActivity.this); + get_title = title.getText().toString().trim(); + get_content = content.getText().toString().trim(); + get_createTime = BG_Time_content.getText().toString(); + get_finishTime = FN_Time_content.getText().toString(); + get_statu = statu + ""; + //判断输入是否有空项 + if (TextUtils.isEmpty(get_title) || TextUtils.isEmpty(get_content) || TextUtils.isEmpty(strBG) + || TextUtils.isEmpty(strFN) || TextUtils.isEmpty(get_statu)) { + Toast.makeText(AddActivity.this, "不能有空项", Toast.LENGTH_SHORT).show(); + } else { + Note note = new Note(); + note.title = get_title; + note.context = get_content; + note.createTime = get_createTime; + note.finishTime = get_finishTime; + note.statu = statu + ""; + + boolean add = noteOperator.insert(note); + //如果添加数据成功,跳到待办事项界面,并通过传值,让目标界面进行刷新 + if (add) { + //Toast.makeText(AddActivity.this,"添加成功",Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(); + intent.setClass(AddActivity.this, MainActivity.class); + intent.putExtra("Insert", 1); + Toast.makeText(AddActivity.this, "添加成功", Toast.LENGTH_SHORT).show(); + startActivity(intent); + //将设置的标题和内容存入文件,待会通知会去取值 + SharedPreferences sp = getSharedPreferences("notif", MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putString("Title", get_title); + editor.putString("Content", get_content); + editor.commit(); + + finish(); + } else { + Toast.makeText(AddActivity.this, "添加失败", Toast.LENGTH_SHORT).show(); + } + } + + //通过判断是否选择来发送通知 + if (notif.isChecked()) { + Intent intent = new Intent(AddActivity.this, AlarmReceiver.class); + AlarmReceiver.title = get_title; + AlarmReceiver.content = get_content; + startRemind(); + } + + + } + break; + + case R.id.BG_Time_Right_jv: { + + strBGDate = null; + strBGTime = null; + strBG = ""; + Calendar cal = Calendar.getInstance(); + //得到小时 + int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); + //得到分钟 + int minute = cal.get(Calendar.MINUTE); + new TimePickerDialog(AddActivity.this, new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + Hour = hourOfDay; + Minute = minute; + strBGTime = " " + hourOfDay + ":" + minute; + if (strBGDate != null && strBGTime != null) { + strBG = strBGDate + strBGTime; + + } else { + strBG = ""; + } + //将选择的时间设置到TextView + BG_Time_content.setText(strBG); + } + }, hourOfDay, minute, true).show(); + + //得到年月日 + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH); + int day = cal.get(Calendar.DAY_OF_MONTH); + new DatePickerDialog(AddActivity.this, new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker datePicker, int year, int month, int day) { + strBGDate = year + "/" + (month + 1) + "/" + day + ""; + + } + }, year, month, day).show(); + + + } + break; + + case R.id.FN_Time_Right_jv: { + + strFNDate = null; + strFNTime = null; + strFN = null; + + Calendar cal = Calendar.getInstance(); + int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); //得到小时 + int minute = cal.get(Calendar.MINUTE); //得到分钟 + new TimePickerDialog(AddActivity.this, new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + strFNTime = " " + hourOfDay + ":" + minute; + if (strFNDate != null && strFNTime != null) { + strFN = strFNDate + strFNTime; + + } else { + strFN = ""; + } + FN_Time_content.setText(strFN); + } + }, hourOfDay, minute, true).show(); + + //得到年月日 + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH); + int day = cal.get(Calendar.DAY_OF_MONTH); + new DatePickerDialog(AddActivity.this, new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker datePicker, int year, int month, int day) { + strFNDate = year + "/" + (month + 1) + "/" + day + ""; + + } + }, year, month, day).show(); + + + } + break; + + case R.id.back_add: { + //返回按钮,返回主页面 + Intent intent = new Intent(AddActivity.this, MainActivity.class); + startActivity(intent); + finish(); + } + break; + + default: + break; + + + } + + } + + //启动定时通知方法 + public void startRemind() { + Calendar mCalendar = Calendar.getInstance(); + mCalendar.setTimeInMillis(System.currentTimeMillis()); + //获取当前毫秒值 + long systemTime = System.currentTimeMillis(); + //是设置日历的时间,主要是让日历的年月日和当前同步 + mCalendar.setTimeInMillis(System.currentTimeMillis()); + // 这里时区需要设置一下,不然可能个别手机会有8个小时的时间差 + mCalendar.setTimeZone(TimeZone.getTimeZone("GMT+8")); + //设置在几点提醒 设置的为选定的Hour + mCalendar.set(Calendar.HOUR_OF_DAY, Hour); + //设置在几分提醒 设置的为选定的Minute分 + mCalendar.set(Calendar.MINUTE, Minute); + mCalendar.set(Calendar.SECOND, 0); + mCalendar.set(Calendar.MILLISECOND, 0); + //上面设置的就是小时和分钟的时间点 + //获取上面设置的时间 + long selectTime = mCalendar.getTimeInMillis(); + + // 如果当前时间大于设置的时间,那么就从第二天的设定时间开始 + if (systemTime > selectTime) { + mCalendar.add(Calendar.DAY_OF_MONTH, 1); + } + //AlarmReceiver.class为广播接受者 + Intent intent = new Intent(AddActivity.this, AlarmReceiver.class); + PendingIntent pi = PendingIntent.getBroadcast(AddActivity.this, 0, intent, 0); + //得到AlarmManager实例 + AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); + /** + * 单次提醒 + * mCalendar.getTimeInMillis() 上面设置的时间点毫秒值 + */ + am.set(AlarmManager.RTC_WAKEUP, mCalendar.getTimeInMillis(), pi); + + } +} + + + + diff --git a/app/src/main/java/com/example/aaa/AlarmReceiver.java b/app/src/main/java/com/example/aaa/AlarmReceiver.java new file mode 100644 index 0000000..05ace10 --- /dev/null +++ b/app/src/main/java/com/example/aaa/AlarmReceiver.java @@ -0,0 +1,52 @@ +package com.example.aaa; + + +import static android.content.Context.NOTIFICATION_SERVICE; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.BitmapFactory; + + +public class AlarmReceiver extends BroadcastReceiver { + + + //定义通知标题和内容,避免魔法字符串 + public static String title = "ToDo"; + public static String content = "content"; + public static String news = "您设置的ToDo开始时间到啦"; + + @Override + public void onReceive(Context context, Intent intent) { + //将设置好的标题的内容取出来 + SharedPreferences sp = context.getSharedPreferences("notif", context.MODE_PRIVATE); + title = (sp.getString("Title", title)); + content = (sp.getString("Content", content)); + + //初始调用 + NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); + Notification.Builder builder = new Notification.Builder(context); + builder.setSmallIcon(R.drawable.notif); + builder.setContentTitle(title); + builder.setContentText(content); + builder.setTicker(news); + builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.logo)); + builder.setContentInfo("附加消息"); + //全部效果展示(震动,铃声,呼吸灯) + builder.setDefaults(Notification.DEFAULT_ALL); + //点击页面跳转 + intent = new Intent(context, MainActivity.class); + PendingIntent activity = PendingIntent.getActivity(context, 100, intent, PendingIntent.FLAG_ONE_SHOT); + builder.setContentIntent(activity); + //悬浮显示 + builder.setFullScreenIntent(activity, true); + manager.notify(1, builder.build()); + } + //传递通知 + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/aaa/DBOpenHelper.java b/app/src/main/java/com/example/aaa/DBOpenHelper.java new file mode 100644 index 0000000..dd367dd --- /dev/null +++ b/app/src/main/java/com/example/aaa/DBOpenHelper.java @@ -0,0 +1,32 @@ +package com.example.aaa; + +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; + +import androidx.annotation.Nullable; + +public class DBOpenHelper extends SQLiteOpenHelper { + public DBOpenHelper(@Nullable Context context) { + super(context, "todo.db", null, 4); + } + //创建数据库的方法,只有项目第一次运行时,会被调用 + + @Override + public void onCreate(SQLiteDatabase db) { + //创建USER表 + String sql1 = "Create table user(account text primary key,password text,id text,phone text)"; + String sql2 = "Create table todo(id integer primary key autoincrement, title text,context text,createTime text,finishTime text,statu text)"; + db.execSQL(sql1); + db.execSQL(sql2); + } + + + // 数据库版本在更新时发生改变,会调用此方法 + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + db.execSQL("drop table if exists user"); + db.execSQL("drop table if exists todo"); + onCreate(db); + } +} diff --git a/app/src/main/java/com/example/aaa/DetailActivity.java b/app/src/main/java/com/example/aaa/DetailActivity.java new file mode 100644 index 0000000..3248c4d --- /dev/null +++ b/app/src/main/java/com/example/aaa/DetailActivity.java @@ -0,0 +1,233 @@ +package com.example.aaa; + +import android.app.DatePickerDialog; +import android.app.TimePickerDialog; +import android.content.Intent; +import android.icu.util.Calendar; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.TimePicker; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +public class DetailActivity extends AppCompatActivity implements View.OnClickListener { + private Button back; + private Button save; + private EditText title; + private EditText context; + private TextView BG_content; + private TextView FN_content; + private int note_id = 0; + private String get_title;//获取标题字符串 + private String get_context;//获取内容字符串 + private Spinner sp_dropdown; + private String strBGDate; + private String strFNDate; + private String strFNTime; + private String strBGTime; + private String strBG; + private String strFN; + private String statu; + private String[] learingSiteArrar = {"学习", "工作", "日常", "生活", "社交", "购物"}; + private int Hour; + private int Minute; + private String get_statu; + private ImageView BGTime;//开始时间 + private ImageView FNTime;//结束时间 + private String get_BG_Time; + private String get_FN_Time; + private AdapterView.OnItemSelectedListener onItemSelectedListener = new AdapterView.OnItemSelectedListener() { + + @Override + public void onItemSelected(AdapterView adapterView, View view, int postion, long I) { + switch (adapterView.getId()) { + case R.id.sp_dropdown_2: + statu = postion + ""; + break; + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_detail); + + title = (EditText) findViewById(R.id.title_detail); + context = (EditText) findViewById(R.id.context_detail); + BG_content = (TextView) findViewById(R.id.BG_Time_content); + FN_content = (TextView) findViewById(R.id.FN_Time_content); + back = (Button) findViewById(R.id.back_detail); + save = (Button) findViewById(R.id.save_detail); + BGTime = (ImageView) findViewById(R.id.BG_Time_Right_jv); + FNTime = (ImageView) findViewById(R.id.FN_Time_Right_jv); + sp_dropdown = (Spinner) findViewById(R.id.sp_dropdown_2); + + back.setOnClickListener(this); + save.setOnClickListener(this); + BGTime.setOnClickListener(this); + FNTime.setOnClickListener(this); + + //接收listView中点击item传来的note_id, + Intent intent = getIntent(); + note_id = intent.getIntExtra("note_id", 0); + NoteOperator noteOperator = new NoteOperator(this); + Note note = noteOperator.getNoteById(note_id); + + title.setText(String.valueOf(note.title)); + context.setText(String.valueOf(note.context)); + BG_content.setText(String.valueOf(note.createTime)); + FN_content.setText(String.valueOf(note.finishTime)); + sp_dropdown.setSelection(Integer.parseInt(note.statu));//此处存疑 + + + intiDropdownSpinner(Integer.parseInt(note.statu)); + + } + + private void intiDropdownSpinner(int statu) { + Spinner sp_dropdown = (Spinner) findViewById(R.id.sp_dropdown_2); + + + ArrayAdapter learningSiteAdapter = new ArrayAdapter(this, + R.layout.item_select, learingSiteArrar); + + sp_dropdown.setAdapter(learningSiteAdapter); + sp_dropdown.setSelection(statu); + sp_dropdown.setOnItemSelectedListener(onItemSelectedListener); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.back_detail: { + Intent intent = new Intent(DetailActivity.this, MainActivity.class); + startActivity(intent); + finish(); + } + break; + case R.id.save_detail: { + get_title = title.getText().toString().trim(); + get_context = context.getText().toString().trim(); + get_statu = statu; + if (TextUtils.isEmpty(get_title) || TextUtils.isEmpty(get_context)) { + Toast.makeText(this, "修改内容不能为空", Toast.LENGTH_SHORT).show(); + } else { + Note note = new Note(); + note.note_id = note_id; + note.title = get_title; + note.context = get_context; + note.createTime = BG_content.toString(); + note.finishTime = FN_content.toString(); + note.statu = statu; + NoteOperator noteOperator = new NoteOperator(DetailActivity.this); + noteOperator.update(note); + + Toast.makeText(this, "修改成功", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(); + intent.setClass(DetailActivity.this, MainActivity.class); + startActivity(intent); + finish(); + } + + } + break; + + case R.id.BG_Time_Right_jv: { + + strBGDate = null; + strBGTime = null; + strBG = ""; + Calendar cal = Calendar.getInstance(); + int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); //得到小时 + int minute = cal.get(Calendar.MINUTE); //得到分钟 + new TimePickerDialog(DetailActivity.this, new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + Hour = hourOfDay; + Minute = minute; + strBGTime = " " + hourOfDay + ":" + minute; + if (strBGDate != null && strBGTime != null) { + strBG = strBGDate + strBGTime; + + } else { + strBG = ""; + } + BG_content.setText(strBG); + } + }, hourOfDay, minute, true).show(); + + + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH); + int day = cal.get(Calendar.DAY_OF_MONTH); + new DatePickerDialog(DetailActivity.this, new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker datePicker, int year, int month, int day) { + strBGDate = year + "/" + (month + 1) + "/" + day + ""; + + } + }, year, month, day).show(); + + + } + break; + + case R.id.FN_Time_Right_jv: { + + strFNDate = null; + strFNTime = null; + strFN = null; + + Calendar cal = Calendar.getInstance(); + int hourOfDay = cal.get(Calendar.HOUR_OF_DAY); //得到小时 + int minute = cal.get(Calendar.MINUTE); //得到分钟 + new TimePickerDialog(DetailActivity.this, new TimePickerDialog.OnTimeSetListener() { + @Override + public void onTimeSet(TimePicker view, int hourOfDay, int minute) { + strFNTime = " " + hourOfDay + ":" + minute; + if (strFNDate != null && strFNTime != null) { + strFN = strFNDate + strFNTime; + + } else { + strFN = ""; + } + FN_content.setText(strFN); + } + }, hourOfDay, minute, true).show(); + + + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH); + int day = cal.get(Calendar.DAY_OF_MONTH); + new DatePickerDialog(DetailActivity.this, new DatePickerDialog.OnDateSetListener() { + @Override + public void onDateSet(DatePicker datePicker, int year, int month, int day) { + strFNDate = year + "/" + (month + 1) + "/" + day + ""; + + } + }, year, month, day).show(); + + + } + break; + + + } + + } +} diff --git a/app/src/main/java/com/example/aaa/LoginActivity.java b/app/src/main/java/com/example/aaa/LoginActivity.java new file mode 100644 index 0000000..3e040f3 --- /dev/null +++ b/app/src/main/java/com/example/aaa/LoginActivity.java @@ -0,0 +1,122 @@ +package com.example.aaa; + + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.content.SharedPreferences; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.RadioButton; +import android.widget.RadioGroup; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +public class LoginActivity extends AppCompatActivity implements View.OnClickListener { + EditText ed_name; + EditText ed_password; + Button btn_login; + Button btn_reg; + String userName; + String IdInput; + String PhoneInput; + String Password; + RadioGroup radioGroup; + RadioButton rb_phone; + RadioButton rb_id; + SQLiteDatabase db; + DBOpenHelper helper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + helper = new DBOpenHelper(this); + //控件获取 + ed_name = findViewById(R.id.ed_Name); + ed_password = findViewById(R.id.ed_Password); + btn_login = findViewById(R.id.btn_login); + btn_reg = findViewById(R.id.btn_reg); + radioGroup = findViewById(R.id.radioGroup); + rb_phone = findViewById(R.id.rb_phone); + rb_id = findViewById(R.id.rb_id); + btn_login.setOnClickListener(this); + btn_reg.setOnClickListener(this); + } + + //记住登录信息 + @Override + protected void onResume() { + super.onResume(); + SharedPreferences sp = getSharedPreferences("loginInfo", MODE_PRIVATE); + ed_name.setText(sp.getString("account", "")); + ed_password.setText(sp.getString("password", "")); + } + + @SuppressLint("Range") + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.btn_login: + String name = ed_name.getText().toString(); + String password = ed_password.getText().toString(); + if (name.isEmpty()) { + Toast.makeText(LoginActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show(); + return; + } + if (password.isEmpty()) { + Toast.makeText(LoginActivity.this, "请输入密码", Toast.LENGTH_SHORT).show(); + return; + } + //从数据库中获取信息 + db = helper.getReadableDatabase(); + //通过判断是学号登陆还是手机号登录来获取不同的信息比对 + if (rb_phone.isChecked()) { + Cursor cursor = db.query("user", null, "phone=?", new String[]{name}, null, null, null); + if (cursor.getCount() > 0) { + cursor.moveToNext();//结果集中的指针指向下一个位置 + PhoneInput = cursor.getString(cursor.getColumnIndex("phone")); + Password = cursor.getString(cursor.getColumnIndex("password")); + } + userName = PhoneInput; + } + if (rb_id.isChecked()) { + Cursor cursor = db.query("user", null, "id=?", new String[]{name}, null, null, null); + if (cursor.getCount() > 0) { + cursor.moveToNext();//结果集中的指针指向下一个位置 + IdInput = cursor.getString(cursor.getColumnIndex("id")); + Password = cursor.getString(cursor.getColumnIndex("password")); + } + userName = IdInput; + } + db.close(); + //如果密码和账号都正确的话可以登录,并且记住密码 + if (name.equals(userName) && password.equals(Password)) { + Toast.makeText(LoginActivity.this, "登陆成功", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(LoginActivity.this, MainActivity.class); + startActivity(intent); + SharedPreferences sp = getSharedPreferences("loginInfo", MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putString("account", name); + editor.putString("password", password); + editor.commit(); + finish(); + + } else { + Toast.makeText(LoginActivity.this, "账号或密码错误", Toast.LENGTH_SHORT).show(); + } + break; + //跳转到注册界面 + case R.id.btn_reg: + Intent intent = new Intent(LoginActivity.this, RegistActivity.class); + startActivity(intent); + finish(); + break; + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/aaa/MainActivity.java b/app/src/main/java/com/example/aaa/MainActivity.java new file mode 100644 index 0000000..1b220f0 --- /dev/null +++ b/app/src/main/java/com/example/aaa/MainActivity.java @@ -0,0 +1,166 @@ +package com.example.aaa; + +import android.app.AlarmManager; +import android.app.AlertDialog; +import android.app.PendingIntent; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.icu.util.Calendar; +import android.icu.util.TimeZone; +import android.os.Build; +import android.os.Bundle; +import android.view.View; +import android.widget.AdapterView; +import android.widget.Button; +import android.widget.ListAdapter; +import android.widget.ListView; +import android.widget.SimpleAdapter; +import android.widget.Toast; + +import androidx.annotation.RequiresApi; +import androidx.appcompat.app.AppCompatActivity; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener { + ListView listView; + Button add;//添加按钮 + Button btnok;//完成按钮 + ArrayList> list; + private List data; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + listView = (ListView) findViewById(R.id.listView); + add = (Button) findViewById(R.id.add); + btnok = (Button) findViewById(R.id.btnok); + + add.setOnClickListener(this); + + + + + + //通过list获取数据库表中的所有id和title,通过ListAdapter给listView赋值 + final NoteOperator noteOperator = new NoteOperator(MainActivity.this); + + + + + + list = noteOperator.getNoteList(); + final ListAdapter listAdapter = new SimpleAdapter(MainActivity.this, list, R.layout.item, + new String[]{"id", "title"}, new int[]{R.id.note_id, R.id.note_title}); + listView.setAdapter(listAdapter); + + + data = new ArrayList<>(); + data=noteOperator.getTitleList(); + MyAdapter myAdapter=new MyAdapter(data); + listView.setAdapter(myAdapter); + + + + + //通过添加界面传来的值判断是否要刷新listView + Intent intent = getIntent(); + int flag = intent.getIntExtra("Insert", 0); + if (flag == 1) { + list = noteOperator.getNoteList(); + listView.setAdapter(listAdapter); + } + + if (list.size() != 0) { + //点击listView的任何一项跳到详情页面 + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int position, long i) { + + String id = list.get(position).get("id"); + Intent intent = new Intent(); + intent.setClass(MainActivity.this, DetailActivity.class); + intent.putExtra("note_id", Integer.parseInt(id)); + startActivity(intent); + finish(); + } + }); + + //长按实现对列表的删除 + listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(final AdapterView adapterView, View view, final int position, long l) { + AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); + builder.setMessage("确定删除?"); + builder.setTitle("提示"); + + //添加AlterDialog.Builder对象的setPositiveButton()方法 + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int which) { + String id = list.get(position).get("id"); + noteOperator.delete(Integer.parseInt(id)); + list.remove(position); + //listAdapter.notify(); + listView.setAdapter(listAdapter); + Toast.makeText(MainActivity.this, "已删除待办", Toast.LENGTH_SHORT).show(); + } + }); + + //添加AlterDialog.Builder对象的setNegativeButton()方法 + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + + } + }); + builder.create().show(); + return true; + } + }); + + } + + + } + + @RequiresApi(api = Build.VERSION_CODES.O) + @Override + public void onClick(View view) { + switch (view.getId()) { + + case R.id.add: { + //添加待办按钮事件,跳转到添加页面 + Intent intent = new Intent(); + intent.setClass(MainActivity.this, AddActivity.class); + startActivity(intent); + finish(); + break; + } + + + } + + + } + + // + public void refresh() { + //通过list获取数据库表中的所有id和title,通过ListAdapter给listView赋值 + final NoteOperator noteOperator = new NoteOperator(MainActivity.this); + list = noteOperator.getNoteList(); + final ListAdapter listAdapter = new SimpleAdapter(MainActivity.this, list, R.layout.item, + new String[]{"id", "title"}, new int[]{R.id.note_id, R.id.note_title}); + listView.setAdapter(listAdapter); + + } + +} + + + diff --git a/app/src/main/java/com/example/aaa/MyAdapter.java b/app/src/main/java/com/example/aaa/MyAdapter.java new file mode 100644 index 0000000..194718c --- /dev/null +++ b/app/src/main/java/com/example/aaa/MyAdapter.java @@ -0,0 +1,110 @@ +package com.example.aaa; + +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.database.sqlite.SQLiteDatabase; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.BaseAdapter; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import java.util.List; + +public class MyAdapter extends BaseAdapter implements View.OnClickListener { + private Context context; + private List data; + private int position; + final NoteOperator noteOperator = new NoteOperator(context); + private DBOpenHelper DBOpenHelper=new DBOpenHelper(context); + + public void NoteOperator(Context context) { + DBOpenHelper = new DBOpenHelper(context); + } + + + public MyAdapter(List data){ + this.data = data; + } + @Override + public int getCount() { + return data == null ? 0 : data.size(); + } + @Override + public Object getItem(int i) { + return data.get(i); + } + + @Override + public long getItemId(int i) { + return i; + } + + @Override + public View getView(int i, View view, ViewGroup viewGroup) { + ViewHolder viewHolder = null; + if(context == null) + context = viewGroup.getContext(); + if(view == null){ + view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item,null); + viewHolder = new ViewHolder(); + viewHolder.mTv = (TextView)view.findViewById(R.id.note_title); + viewHolder.mBtn = (Button)view.findViewById(R.id.btnok); + view.setTag(viewHolder); + } + viewHolder = (ViewHolder)view.getTag(); + //设置tag标记 + viewHolder.mBtn.setTag(R.id.btnok,i);//添加此代码 +// viewHolder.mBtn.setText("点我点我"+ i); + viewHolder.mBtn.setOnClickListener(this); + viewHolder.mTv.setText(data.get(i)); + //设置tag标记 + viewHolder.mTv.setTag(R.id.note_title,i);//添加此代码 + + return view; + } + @Override + public void onClick(View view) { + switch (view.getId()){ + case R.id.btnok: + ViewHolder viewHolder = null; + int b = (int) view.getTag(R.id.btnok); +// Toast.makeText(context,"我是按钮 " + b,Toast.LENGTH_SHORT).show(); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setMessage("确定完成并删除该待办吗?"); + builder.setTitle("提示"); + + //添加AlterDialog.Builder对象的setPositiveButton()方法 + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int which) { + NoteOperator noteOperator = new NoteOperator(context); + noteOperator.btn_delete(data.get(b)); + + Intent intent = new Intent(context, MainActivity.class); + context.startActivity(intent); + + } + }); + + //添加AlterDialog.Builder对象的setNegativeButton()方法 + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + + } + }); + builder.create().show(); + break; + } + } + static class ViewHolder{ + TextView mTv; + Button mBtn; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/aaa/Note.java b/app/src/main/java/com/example/aaa/Note.java new file mode 100644 index 0000000..9379b3b --- /dev/null +++ b/app/src/main/java/com/example/aaa/Note.java @@ -0,0 +1,22 @@ +package com.example.aaa; + +public class Note { + //表名 + public static final String TABLE = "todo"; + //列名 + public static final String KEY_id = "id"; + public static final String KEY_title = "title"; + public static final String KEY_context = "context"; + public static final String KEY_createTime = "createTime"; + public static final String KEY_finishTime = "finishTime"; + public static final String KEY_statu = "statu"; + + public int note_id; + public String title; + public String context; + public String createTime; + public String finishTime; + public String statu; + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/aaa/NoteOperator.java b/app/src/main/java/com/example/aaa/NoteOperator.java new file mode 100644 index 0000000..a6f20c0 --- /dev/null +++ b/app/src/main/java/com/example/aaa/NoteOperator.java @@ -0,0 +1,143 @@ +package com.example.aaa; + + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; + +import java.util.ArrayList; +import java.util.HashMap; + + +public class NoteOperator { + + private DBOpenHelper DBOpenHelper; + + public NoteOperator(Context context) { + DBOpenHelper = new DBOpenHelper(context); + } + + public boolean insert(Note note) { + + //与数据库建立连接 + SQLiteDatabase db = DBOpenHelper.getWritableDatabase(); + ContentValues contentValues = new ContentValues(); + contentValues.put(Note.KEY_title, note.title); + contentValues.put(Note.KEY_context, note.context); + contentValues.put(Note.KEY_createTime, note.createTime); + contentValues.put(Note.KEY_finishTime, note.finishTime); + contentValues.put(Note.KEY_statu, note.statu); + //插入每一行数据 + long note_id = db.insert(Note.TABLE, null, contentValues); + db.close(); + if (note_id != -1) + return true; + else + return false; + } + + /** + * 删除数据 + * + * @param note_id + */ + public void delete(int note_id) { + //与数据库建立连接 + SQLiteDatabase db = DBOpenHelper.getWritableDatabase(); + db.delete(Note.TABLE, Note.KEY_id + "=?", new String[]{String.valueOf(note_id)}); + db.close(); + } + public void btn_delete(String title) { + //与数据库建立连接 + SQLiteDatabase db = DBOpenHelper.getWritableDatabase(); + db.delete(Note.TABLE, Note.KEY_title + "=?", new String[]{String.valueOf(title)}); + db.close(); + } + + /** + * 从数据库中查找 id,title,context,createTime,finishTime,status + * + * @return ArrayList + */ + public ArrayList> getNoteList() { + //与数据库建立连接 + SQLiteDatabase db = DBOpenHelper.getReadableDatabase(); + String sql = "select " + Note.KEY_id + "," + Note.KEY_title + "," + Note.KEY_context + "," + + Note.KEY_createTime + "," + Note.KEY_finishTime + "," + Note.KEY_statu + " from " + Note.TABLE; + //通过游标将每一条数据放进ArrayList中 + ArrayList> noteList = new ArrayList>(); + Cursor cursor = db.rawQuery(sql, null); + while (cursor.moveToNext()) { + HashMap note = new HashMap(); + note.put("id", cursor.getString(cursor.getColumnIndex(Note.KEY_id))); + note.put("title", cursor.getString(cursor.getColumnIndex(Note.KEY_title))); + + + noteList.add(note); + } + cursor.close(); + db.close(); + return noteList; + } + + /** + * 从数据库中查找 id,title,context,createTime,finishTime,status + * + * @return ArrayList + */ + public ArrayList getTitleList() { + //与数据库建立连接 + SQLiteDatabase db = DBOpenHelper.getReadableDatabase(); + String sql = "select " + Note.KEY_id + "," + Note.KEY_title + "," + Note.KEY_context + "," + + Note.KEY_createTime + "," + Note.KEY_finishTime + "," + Note.KEY_statu + " from " + Note.TABLE; + //通过游标将每一条数据放进ArrayList中 + ArrayList noteList = new ArrayList(); + Cursor cursor = db.rawQuery(sql, null); + while (cursor.moveToNext()) { + noteList.add(cursor.getString(cursor.getColumnIndex(Note.KEY_title))); + } + cursor.close(); + db.close(); + return noteList; + } + + /** + * 通过id查找,返回一个Note对象 + * + * @param id + * @return note对象 + */ + public Note getNoteById(int id) { + //与数据库建立连接 + SQLiteDatabase db = DBOpenHelper.getReadableDatabase(); + String sql = "select " + Note.KEY_title + "," + Note.KEY_context + + "," + Note.KEY_createTime + "," + Note.KEY_finishTime + "," + Note.KEY_statu + " from " + Note.TABLE + " where " + Note.KEY_id + "=?"; + Note note = new Note(); + Cursor cursor = db.rawQuery(sql, new String[]{String.valueOf(id)}); + while (cursor.moveToNext()) { + note.title = cursor.getString(cursor.getColumnIndex(Note.KEY_title)); + note.context = cursor.getString(cursor.getColumnIndex(Note.KEY_context)); + note.createTime = cursor.getString(cursor.getColumnIndex(Note.KEY_createTime)); + note.finishTime = cursor.getString(cursor.getColumnIndex(Note.KEY_finishTime)); + note.statu = cursor.getString(cursor.getColumnIndex(Note.KEY_statu)); + } + cursor.close(); + db.close(); + return note; + } + + /** + * 更新数据 + * + * @param note + */ + public void update(Note note) { + SQLiteDatabase db = DBOpenHelper.getWritableDatabase(); + ContentValues contentValues = new ContentValues(); + contentValues.put(Note.KEY_title, note.title); + contentValues.put(Note.KEY_context, note.context); + db.update(Note.TABLE, contentValues, Note.KEY_id + "=?", new String[]{String.valueOf(note.note_id)}); + db.close(); + } +} diff --git a/app/src/main/java/com/example/aaa/RegistActivity.java b/app/src/main/java/com/example/aaa/RegistActivity.java new file mode 100644 index 0000000..0d18541 --- /dev/null +++ b/app/src/main/java/com/example/aaa/RegistActivity.java @@ -0,0 +1,113 @@ +package com.example.aaa; + +import android.content.ContentValues; +import android.content.Intent; +import android.content.SharedPreferences; +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.Toast; + +import androidx.appcompat.app.AppCompatActivity; + +public class RegistActivity extends AppCompatActivity implements View.OnClickListener { + EditText ed_username, ed_userpwd, ed_userpwdr, ed_id, ed_phone; + Button btn_submit, btn_back; + SQLiteDatabase db; + DBOpenHelper helper; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_regist); + initView(); + helper = new DBOpenHelper(this); + } + + private void initView() { + ed_username = findViewById(R.id.UserNameEdit); + ed_userpwd = findViewById(R.id.PassWordEdit); + ed_userpwdr = findViewById(R.id.PassWordAgainEdit); + ed_id = findViewById(R.id.IdEdit); + ed_phone = findViewById(R.id.PhoneEdit); + btn_submit = findViewById(R.id.SignUpButton); + btn_back = findViewById(R.id.BackLoginButton); + btn_back.setOnClickListener(this); + btn_submit.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + String userName = ed_username.getText().toString(); + String userPsd = ed_userpwd.getText().toString(); + String confirPsd = ed_userpwdr.getText().toString(); + String userId = ed_id.getText().toString(); + String userPhone = ed_phone.getText().toString(); + + switch (view.getId()) { + //通过判断哪一项为空来提示输入 + case R.id.SignUpButton: + String name = ed_username.getText().toString(); + String pwd = ed_userpwd.getText().toString(); + String id = ed_id.getText().toString(); + String phone = ed_phone.getText().toString(); + if (name.isEmpty()) { + Toast.makeText(RegistActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show(); + return; + } + if (pwd.isEmpty()) { + Toast.makeText(RegistActivity.this, "请输入密码", Toast.LENGTH_SHORT).show(); + return; + } + if (id.isEmpty()) { + Toast.makeText(RegistActivity.this, "请输入学号", Toast.LENGTH_SHORT).show(); + return; + } + if (phone.isEmpty()) { + Toast.makeText(RegistActivity.this, "请输入手机号", Toast.LENGTH_SHORT).show(); + return; + } + //判断两次密码是否一致 + if (!userPsd.equals(confirPsd)) { + Toast.makeText(RegistActivity.this, "两次输入的密码不一致,注册失败", Toast.LENGTH_SHORT).show(); + } else { + //密码一致注册成功并且存入数据库 + SharedPreferences sp = getSharedPreferences("regInfo", MODE_PRIVATE); + SharedPreferences.Editor editor = sp.edit(); + editor.putString("account", userName); + editor.putString("password", userPsd); + editor.putString("id", userId); + editor.putString("phone", userPhone); + editor.commit(); + //获取创建的数据库对象 + db = helper.getWritableDatabase(); + ContentValues values = new ContentValues(); + values.put("account", userName); + values.put("password", userPsd); + values.put("id", userId); + values.put("phone", userPhone); + db.insert("user", null, values); + db.close(); + + //获取创建的数据库对象 + Toast.makeText(RegistActivity.this, "注册成功", Toast.LENGTH_SHORT).show(); + //注册成功后跳转到登陆界面 + Intent intent = new Intent(RegistActivity.this, LoginActivity.class); + startActivity(intent); + finish(); + + } + + break; + case R.id.BackLoginButton: + //返回到登陆界面 + Intent intent = new Intent(RegistActivity.this, LoginActivity.class); + startActivity(intent); + finish(); + break; + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_launcher_icon.png b/app/src/main/res/drawable-v24/ic_launcher_icon.png new file mode 100644 index 0000000..d4975e6 Binary files /dev/null and b/app/src/main/res/drawable-v24/ic_launcher_icon.png differ diff --git a/app/src/main/res/drawable-v24/rightiv.png b/app/src/main/res/drawable-v24/rightiv.png new file mode 100644 index 0000000..e3340d0 Binary files /dev/null and b/app/src/main/res/drawable-v24/rightiv.png differ diff --git a/app/src/main/res/drawable/btn_circle.xml b/app/src/main/res/drawable/btn_circle.xml new file mode 100644 index 0000000..655b829 --- /dev/null +++ b/app/src/main/res/drawable/btn_circle.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/edit_background.xml b/app/src/main/res/drawable/edit_background.xml new file mode 100644 index 0000000..cacb4f9 --- /dev/null +++ b/app/src/main/res/drawable/edit_background.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_icon.png b/app/src/main/res/drawable/ic_launcher_icon.png new file mode 100644 index 0000000..b0054a8 Binary files /dev/null and b/app/src/main/res/drawable/ic_launcher_icon.png differ diff --git a/app/src/main/res/drawable/logo.jpg b/app/src/main/res/drawable/logo.jpg new file mode 100644 index 0000000..b0054a8 Binary files /dev/null and b/app/src/main/res/drawable/logo.jpg differ diff --git a/app/src/main/res/drawable/notif.jpg b/app/src/main/res/drawable/notif.jpg new file mode 100644 index 0000000..511ee34 Binary files /dev/null and b/app/src/main/res/drawable/notif.jpg differ diff --git a/app/src/main/res/layout/activity_add.xml b/app/src/main/res/layout/activity_add.xml new file mode 100644 index 0000000..02dc410 --- /dev/null +++ b/app/src/main/res/layout/activity_add.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml new file mode 100644 index 0000000..e8252fc --- /dev/null +++ b/app/src/main/res/layout/activity_detail.xml @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml new file mode 100644 index 0000000..7203d98 --- /dev/null +++ b/app/src/main/res/layout/activity_login.xml @@ -0,0 +1,169 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_regist.xml b/app/src/main/res/layout/activity_regist.xml new file mode 100644 index 0000000..7ba58c5 --- /dev/null +++ b/app/src/main/res/layout/activity_regist.xml @@ -0,0 +1,210 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +