代码逻辑优化

master
liuyx 2 years ago
parent fec99da20f
commit 4a6219c302

@ -6,30 +6,27 @@
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<application
android:theme="@style/DayTheme"
android:allowBackup="true"
android:icon="@mipmap/ic_app"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_app_round"
android:supportsRtl="true"
>
android:theme="@style/DayTheme">
<activity android:name="cc.liuyx.note.activity.MainActivity"
<activity
android:name="cc.liuyx.note.activity.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="cc.liuyx.note.activity.EditActivity">
</activity>
<activity android:name="cc.liuyx.note.activity.EditActivity" />
<activity android:name="cc.liuyx.note.activity.FabColorActivity" />
<activity android:name="cc.liuyx.note.activity.UserSettingsActivity" />
<activity android:name="cc.liuyx.note.alarm.EditAlarmActivity" />
<activity android:name="cc.liuyx.note.activity.UserSettingsActivity$EditAlarmActivity" />
<activity android:name="cc.liuyx.note.activity.AboutActivity" />
<receiver android:name="cc.liuyx.note.alarm.AlarmReceiver" />
</application>

@ -0,0 +1,45 @@
package cc.liuyx.note.activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.LinearLayout;
import android.widget.Switch;
import com.example.atry.R;
import java.util.Objects;
public class AboutActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Intent intent = getIntent();
boolean night_change;
if (intent.getExtras() != null)
night_change = intent.getBooleanExtra("night_change", false);
else night_change = false;
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (isNightMode())
myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_more));
else myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_more));
}
@Override
protected void needRefresh() {
}
}

@ -47,13 +47,13 @@ import android.widget.TextView;
import android.widget.Toast;
import cc.liuyx.note.alarm.AlarmReceiver;
import cc.liuyx.note.alarm.EditAlarmActivity;
import cc.liuyx.note.alarm.Plan;
import cc.liuyx.note.alarm.PlanAdapter;
import cc.liuyx.note.alarm.PlanDatabase;
import cc.liuyx.note.db.PlanDatabase;
import cc.liuyx.note.entity.Plan;
import cc.liuyx.note.adapter.PlanAdapter;
import cc.liuyx.note.db.PlanCRUD;
import cc.liuyx.note.adapter.NoteAdapter;
import cc.liuyx.note.adapter.TagAdapter;
import cc.liuyx.note.db.CRUD;
import cc.liuyx.note.db.NoteCRUD;
import cc.liuyx.note.db.NoteDatabase;
import cc.liuyx.note.entity.Note;
@ -105,6 +105,8 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
private TextView setting_text;
private ImageView setting_image;
private TextView about_text;
private ImageView about_image;
private ListView lv_tag;
private TextView add_tag;
@ -161,6 +163,10 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
setting_text = customView.findViewById(R.id.setting_settings_text);
setting_image = customView.findViewById(R.id.setting_settings_image);
about_image = customView.findViewById(R.id.setting_about_image);
about_text = customView.findViewById(R.id.setting_about_text);
lv_tag = customView.findViewById(R.id.lv_tag);
add_tag = customView.findViewById(R.id.add_tag);
@ -170,7 +176,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
if (sharedPreferences.getString("tagListString", "").split("_").length < 8) {
final EditText et = new EditText(context);
new AlertDialog.Builder(MainActivity.this)
.setMessage("Enter the name of tag")
.setMessage("输入标签名")
.setView(et)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
@ -184,7 +190,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
String newTagListString = oldTagListString + "_" + name;
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("tagListString", newTagListString);
editor.commit();
editor.apply();
refreshTagList();
} else
Toast.makeText(context, "Repeated tag!", Toast.LENGTH_SHORT).show();
@ -254,7 +260,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
Note temp = noteList.get(i);
if (temp.getTag() == tag) {
temp.setTag(1);
CRUD op = new CRUD(context);
NoteCRUD op = new NoteCRUD(context);
op.open();
op.updateNote(temp);
op.close();
@ -268,7 +274,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
Note temp = noteList.get(i);
if (temp.getTag() == j) {
temp.setTag(j - 1);
CRUD op = new CRUD(context);
NoteCRUD op = new NoteCRUD(context);
op.open();
op.updateNote(temp);
op.close();
@ -278,14 +284,13 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
}
//edit the preference
List<String> newTagList = new ArrayList<>();
newTagList.addAll(tagList);
List<String> newTagList = new ArrayList<>(tagList);
newTagList.remove(position);
String newTagListString = TextUtils.join("_", newTagList);
Log.d(TAG, "onClick: " + newTagListString);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("tagListString", newTagListString);
editor.commit();
editor.apply();
refreshTagList();
}
@ -304,7 +309,6 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
}
});
setting_text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
@ -322,8 +326,24 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
}
});
about_text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, AboutActivity.class));
overridePendingTransition(R.anim.in_lefttoright, R.anim.no);
}
});
about_image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, AboutActivity.class));
overridePendingTransition(R.anim.in_lefttoright, R.anim.no);
}
});
coverView.setOnTouchListener(new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View v, MotionEvent event) {
popupWindow.dismiss();
@ -408,7 +428,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("content_switch", isChecked);
editor.commit();
editor.apply();
refreshLvVisibility();
}
});
@ -426,7 +446,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
fab_alarm.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, EditAlarmActivity.class);
Intent intent = new Intent(MainActivity.this, UserSettingsActivity.EditAlarmActivity.class);
intent.putExtra("mode", 2); // MODE of 'new plan'
startActivityForResult(intent, 1);
overridePendingTransition(R.anim.in_righttoleft, R.anim.no);
@ -441,7 +461,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
setSupportActionBar(myToolbar);
getSupportActionBar().setHomeButtonEnabled(true);
Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //设置toolbar取代actionbar
initPopupView();
}
@ -482,32 +502,32 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
SharedPreferences.Editor editor = sharedPreferences.edit();
if (!sharedPreferences.contains("nightMode")) {
editor.putBoolean("nightMode", false);
editor.commit();
editor.apply();
}
if (!sharedPreferences.contains("reverseSort")) {
editor.putBoolean("reverseSort", false);
editor.commit();
editor.apply();
}
if (!sharedPreferences.contains("fabColor")) {
editor.putInt("fabColor", -500041);
editor.commit();
editor.apply();
}
if (!sharedPreferences.contains("tagListString")) {
String s = "no tag_life_study_work_play";
editor.putString("tagListString", s);
editor.commit();
editor.apply();
}
if (!sharedPreferences.contains("content_switch")) {
editor.putBoolean("content_switch", false);
editor.commit();
editor.apply();
}
if (!sharedPreferences.contains("fabPlanColor")) {
editor.putInt("fabPlanColor", -500041);
editor.commit();
editor.apply();
}
if (!sharedPreferences.contains("noteTitle")) {
editor.putBoolean("noteTitle", true);
editor.commit();
editor.apply();
}
@ -549,9 +569,9 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Delete all " + itemName);
builder.setIcon(R.drawable.ic_error_outline_black_24dp);
builder.setItems(list_String, new DialogInterface.OnClickListener() {//列表对话框;
builder.setItems(list_String, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, final int which) {//根据这里which值即可以指定是点击哪一个Item
public void onClick(DialogInterface dialog, final int which) {
new AlertDialog.Builder(MainActivity.this)
.setMessage("Do you want to delete all " + itemName + " " + list_String[which] + "? ")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@ -563,6 +583,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
}
//根据模式与时长删除对顶的计划s/笔记s
@SuppressLint("Range")
private void removeSelectItems(int which, int mode) {
int monthNum = 0;
switch (which) {
@ -582,14 +603,14 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
Calendar rightNow = Calendar.getInstance();
rightNow.add(Calendar.MONTH, -monthNum);//日期加3个月
Date selectDate = rightNow.getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String selectDateStr = simpleDateFormat.format(selectDate);
Log.d(TAG, "removeSelectItems: " + selectDateStr);
switch (mode) {
case 1: //notes
dbHelper = new NoteDatabase(context);
SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.rawQuery("select * from notes", null);
@SuppressLint("Recycle") Cursor cursor = db.rawQuery("select * from notes", null);
while (cursor.moveToNext()) {
if (cursor.getString(cursor.getColumnIndex(NoteDatabase.TIME)).compareTo(selectDateStr) < 0) {
db.delete("notes", NoteDatabase.ID + "=?", new String[]{Long.toString(cursor.getLong(cursor.getColumnIndex(NoteDatabase.ID)))});
@ -601,7 +622,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
case 2: //plans
planDbHelper = new PlanDatabase(context);
SQLiteDatabase pdb = planDbHelper.getWritableDatabase();
Cursor pcursor = pdb.rawQuery("select * from plans", null);
@SuppressLint("Recycle") Cursor pcursor = pdb.rawQuery("select * from plans", null);
while (pcursor.moveToNext()) {
if (pcursor.getString(pcursor.getColumnIndex(PlanDatabase.TIME)).compareTo(selectDateStr) < 0) {
pdb.delete("plans", PlanDatabase.ID + "=?", new String[]{Long.toString(pcursor.getLong(pcursor.getColumnIndex(PlanDatabase.ID)))});
@ -635,6 +656,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
}
@SuppressLint("NonConstantResourceId")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -647,8 +669,8 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
public void onClick(DialogInterface dialog, int which) {
dbHelper = new NoteDatabase(context);
SQLiteDatabase db = dbHelper.getWritableDatabase();
db.delete("notes", null, null);//delete data in table NOTES
db.execSQL("update sqlite_sequence set seq=0 where name='notes'"); //reset id to 1
db.delete("notes", null, null);
db.execSQL("update sqlite_sequence set seq=0 where name='notes'");
refreshListView();
}
}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@ -665,8 +687,8 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
public void onClick(DialogInterface dialog, int which) {
planDbHelper = new PlanDatabase(context);
SQLiteDatabase db = planDbHelper.getWritableDatabase();
db.delete("plans", null, null);//delete data in table NOTES
db.execSQL("update sqlite_sequence set seq=0 where name='plans'"); //reset id to 1
db.delete("plans", null, null);
db.execSQL("update sqlite_sequence set seq=0 where name='plans'");
refreshListView();
}
}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@ -679,7 +701,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
break;
case R.id.refresh:
myToolbar.setTitle("All Notes");
myToolbar.setTitle("所有笔记");
lv.setAdapter(adapter);
break;
}
@ -694,7 +716,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
int fabPlanColor = sharedPreferences.getInt("fabPlanColor", -500041);
chooseFabPlanColor(fabPlanColor);
//initialize CRUD
CRUD op = new CRUD(context);
NoteCRUD op = new NoteCRUD(context);
op.open();
// set adapter
@ -705,7 +727,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
op.close();
adapter.notifyDataSetChanged();
cc.liuyx.note.alarm.CRUD op1 = new cc.liuyx.note.alarm.CRUD(context);
PlanCRUD op1 = new PlanCRUD(context);
op1.open();
if (planList.size() > 0) {
cancelAlarms(planList);//删除所有闹钟
@ -801,6 +823,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
}
//click item in listView
@SuppressLint("NonConstantResourceId")
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
@ -817,7 +840,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
break;
case R.id.lv_plan:
Plan curPlan = (Plan) parent.getItemAtPosition(position);
Intent intent1 = new Intent(MainActivity.this, EditAlarmActivity.class);
Intent intent1 = new Intent(MainActivity.this, UserSettingsActivity.EditAlarmActivity.class);
intent1.putExtra("title", curPlan.getTitle());
intent1.putExtra("content", curPlan.getContent());
intent1.putExtra("time", curPlan.getTime());
@ -834,6 +857,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
int returnMode;
long note_Id;
assert data != null;
returnMode = data.getExtras().getInt("mode", -1);
note_Id = data.getExtras().getLong("id", 0);
if (returnMode == 1) { //update current note
@ -843,7 +867,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
int tag = data.getExtras().getInt("tag", 1);
Note newNote = new Note(content, time, tag);
newNote.setId(note_Id);
CRUD op = new CRUD(context);
NoteCRUD op = new NoteCRUD(context);
op.open();
op.updateNote(newNote);
achievement.editNote(op.getNote(note_Id).getContent(), content);
@ -852,7 +876,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
} else if (returnMode == 2) { //delete current note
Note curNote = new Note();
curNote.setId(note_Id);
CRUD op = new CRUD(context);
NoteCRUD op = new NoteCRUD(context);
op.open();
op.removeNote(curNote);
op.close();
@ -862,7 +886,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
String time = data.getExtras().getString("time");
int tag = data.getExtras().getInt("tag", 1);
Note newNote = new Note(content, time, tag);
CRUD op = new CRUD(context);
NoteCRUD op = new NoteCRUD(context);
op.open();
op.addNote(newNote);
op.close();
@ -874,14 +898,14 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
Log.d(TAG, time);
Plan plan = new Plan(title, content, time);
plan.setId(note_Id);
cc.liuyx.note.alarm.CRUD op = new cc.liuyx.note.alarm.CRUD(context);
PlanCRUD op = new PlanCRUD(context);
op.open();
op.updatePlan(plan);
op.close();
} else if (returnMode == 12) {//delete existing plan
Plan plan = new Plan();
plan.setId(note_Id);
cc.liuyx.note.alarm.CRUD op = new cc.liuyx.note.alarm.CRUD(context);
PlanCRUD op = new PlanCRUD(context);
op.open();
op.removePlan(plan);
op.close();
@ -890,28 +914,28 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
String content = data.getExtras().getString("content", null);
String time = data.getExtras().getString("time", null);
Plan newPlan = new Plan(title, content, time);
cc.liuyx.note.alarm.CRUD op = new cc.liuyx.note.alarm.CRUD(context);
PlanCRUD op = new PlanCRUD(context);
op.open();
op.addPlan(newPlan);
Log.d(TAG, "onActivityResult: " + time);
op.close();
} else {
}
refreshListView();
}
//longclick item in listView
@SuppressLint("NonConstantResourceId")
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
switch (parent.getId()) {
case R.id.lv:
final Note note = noteList.get(position);
new AlertDialog.Builder(MainActivity.this)
.setMessage("Do you want to delete this note ?")
.setMessage("你想要删除这条笔记吗?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
CRUD op = new CRUD(context);
NoteCRUD op = new NoteCRUD(context);
op.open();
op.removeNote(note);
op.close();
@ -927,12 +951,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
case R.id.lv_plan:
final Plan plan = planList.get(position);
new AlertDialog.Builder(MainActivity.this)
.setMessage("Do you want to delete this plan ?")
.setMessage("你想要删除这条计划吗?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
cc.liuyx.note.alarm.CRUD op = new cc.liuyx.note.alarm.CRUD(context);
PlanCRUD op = new PlanCRUD(context);
op.open();
op.removePlan(plan);
op.close();
@ -1021,9 +1045,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
Calendar c = p.getPlanTime();
if (!c.before(Calendar.getInstance())) {
Intent intent = new Intent(MainActivity.this, AlarmReceiver.class);
intent.putExtra("title", p.getTitle());
intent.putExtra("content", p.getContent());
intent.putExtra("id", (int) p.getId());
Bundle data = new Bundle();
data.putString("title", p.getTitle());
data.putString("title", p.getTitle());
data.putString("content", p.getContent());
data.putInt("id", (int) p.getId());
intent.putExtras(data);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, (int) p.getId(), intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
alarmManager.setExact(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pendingIntent);
@ -1059,7 +1086,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
//achievement system
public class Achievement {
private SharedPreferences sharedPreferences;
private final SharedPreferences sharedPreferences;
private int noteNumber;
private int wordNumber;
@ -1084,27 +1111,27 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
SharedPreferences.Editor editor = sharedPreferences.edit();
if (!sharedPreferences.contains("noteLevel")) {
editor.putInt("noteLevel", 0);
editor.commit();
editor.apply();
if (!sharedPreferences.contains("wordLevel")) {
editor.putInt("wordLevel", 0);
editor.commit();
editor.apply();
addCurrent(noteList);
if (sharedPreferences.contains("maxRemainNumber")) {
editor.remove("maxRemainNumber");
editor.commit();
editor.apply();
}
if (sharedPreferences.contains("remainNumber")) {
editor.remove("remainNumber");
editor.commit();
editor.apply();
}
if (!sharedPreferences.contains("noteNumber")) {
editor.putInt("noteNumber", 0);
editor.commit();
editor.apply();
addCurrent(noteList);
if (!sharedPreferences.contains("wordNumber")) {
editor.putInt("wordNumber", 0);
editor.commit();
editor.apply();
}
}
@ -1132,7 +1159,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
else if (wordCount >= 1000) editor.putInt("noteLevel", 3);
else if (wordCount >= 500) editor.putInt("noteLevel", 2);
else if (wordCount >= 100) editor.putInt("noteLevel", 1);
editor.commit();
editor.apply();
}
//添加笔记
@ -1144,7 +1171,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
wordNumber += content.length();
editor.putInt("wordNumber", wordNumber);
editor.commit();
editor.apply();
}
//删除笔记
@ -1158,7 +1185,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
SharedPreferences.Editor editor = sharedPreferences.edit();
wordNumber += (newContent.length() - oldContent.length());
editor.putInt("wordNumber", wordNumber);
editor.commit();
editor.apply();
}
}
@ -1231,12 +1258,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
case 1:
noteLevel++;
editor.putInt("noteLevel", noteLevel);
editor.commit();
editor.apply();
break;
case 2:
wordLevel++;
editor.putInt("wordLevel", wordLevel);
editor.commit();
editor.apply();
break;
}
}
@ -1257,7 +1284,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O
editor.putInt("wordNumber", wordNumber);
editor.putInt("noteLevel", 0);
editor.putInt("wordLevel", 0);
editor.commit();
editor.apply();
}
}

@ -1,20 +1,37 @@
package cc.liuyx.note.activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import com.example.atry.R;
import java.util.Calendar;
import java.util.Objects;
import cc.liuyx.note.entity.Plan;
public class UserSettingsActivity extends BaseActivity {
private Switch nightMode;
@ -171,4 +188,305 @@ public class UserSettingsActivity extends BaseActivity {
}
public static class EditAlarmActivity extends BaseActivity implements View.OnClickListener {
private DatePickerDialog.OnDateSetListener dateSetListener;
private TimePickerDialog.OnTimeSetListener timeSetListener;
private EditText et_title;
private EditText et;
private Button set_date;
private Button set_time;
private TextView date;
private TextView time;
private Plan plan;
private int[] dateArray = new int[3];
private int[] timeArray = new int[2];
private int openMode = 0;
private String old_title = "";
private String old_content = "";
private String old_time = "";
private long id = 0;
private boolean timeChange = false;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_alarm_layout);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
init();
final Intent intent = getIntent();
openMode = intent.getExtras().getInt("mode", 0);
if(openMode == 1){
id = intent.getLongExtra("id", 0);
old_title = intent.getStringExtra("title");
old_content = intent.getStringExtra("content");
old_time = intent.getStringExtra("time");
et_title.setText(old_title);
et_title.setSelection(old_title.length());
et.setText(old_content);
et.setSelection(old_content.length());
String[] wholeTime = old_time.split(" ");
String[] temp = wholeTime[0].split("-");
String[] temp1 = wholeTime[1].split(":");
setDateTV(Integer.parseInt(temp[0]), Integer.parseInt(temp[1]), Integer.parseInt(temp[2]));
setTimeTV(Integer.parseInt(temp1[0]), Integer.parseInt(temp1[1]));
}
if(isNightMode()) myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_keyboard_arrow_left_white_24dp));
else myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_keyboard_arrow_left_black_24dp));
myToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!canBeSet()) {
Toast.makeText(EditAlarmActivity.this, "Invalid Time", Toast.LENGTH_SHORT).show();
}else if(et.getText().toString().length() + et_title.getText().toString().length() == 0 && openMode == 2){
Intent intent1 = new Intent();
intent1.putExtra("mode", -1);//nothing new happens.
setResult(RESULT_OK, intent1);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
else if (et_title.getText().toString().length() == 0) {
Toast.makeText(EditAlarmActivity.this, "Title cannot be empty", Toast.LENGTH_SHORT).show();
}
else {
isTimeChange();
Intent intent = new Intent();
if (openMode == 2) {
intent.putExtra("mode", 10); // new one plan;
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
Log.d(TAG, date.getText().toString() + time.getText().toString());
} else {
if (et.getText().toString().equals(old_content) && et_title.getText().toString().equals(old_title) && !timeChange) {
intent.putExtra("mode", -1); // edit nothing
}
else {
intent.putExtra("mode", 11); //edit the content
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
intent.putExtra("id", id);
}
}
setResult(RESULT_OK, intent);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
}
});
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if( keyCode== KeyEvent.KEYCODE_HOME){
return true;
} else if( keyCode== KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
if(!canBeSet()) {
Toast.makeText(EditAlarmActivity.this, "Invalid Time", Toast.LENGTH_SHORT).show();
}else if(et.getText().toString().length() + et_title.getText().toString().length() == 0 && openMode == 2){
Intent intent1 = new Intent();
intent1.putExtra("mode", -1);//nothing new happens.
setResult(RESULT_OK, intent1);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
else if (et_title.getText().toString().length() == 0) {
Toast.makeText(EditAlarmActivity.this, "Title cannot be empty", Toast.LENGTH_SHORT).show();
}
else {
isTimeChange();
Intent intent = new Intent();
if (openMode == 2) {
intent.putExtra("mode", 10); // new one plan;
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
Log.d(TAG, date.getText().toString() + time.getText().toString());
} else {
if (et.getText().toString().equals(old_content) && et_title.getText().toString().equals(old_title) && !timeChange) {
intent.putExtra("mode", -1); // edit nothing
}
else {
intent.putExtra("mode", 11); //edit the content
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
intent.putExtra("id", id);
}
}
setResult(RESULT_OK, intent);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.edit_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final Intent intent = new Intent();
switch (item.getItemId()){
case R.id.delete:
new AlertDialog.Builder(EditAlarmActivity.this)
.setMessage("Delete this plan ?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(openMode == 2){
intent.putExtra("mode", -1); // delete the plan
setResult(RESULT_OK, intent);
}
else {
intent.putExtra("mode", 12); // delete the plan
intent.putExtra("id", id);
setResult(RESULT_OK, intent);
}
finish();
}
}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void needRefresh() {
setNightMode();
startActivity(new Intent(this, EditAlarmActivity.class));
overridePendingTransition(R.anim.night_switch, R.anim.night_switch_over);
finish();
}
private void init(){
plan = new Plan();
dateArray[0] = plan.getYear();
dateArray[1] = plan.getMonth() + 1;
dateArray[2] = plan.getDay();
timeArray[0] = plan.getHour();
timeArray[1] = plan.getMinute();
et_title = findViewById(R.id.et_title);
et = findViewById(R.id.et);
set_date = findViewById(R.id.set_date);
set_time = findViewById(R.id.set_time);
date = findViewById(R.id.date);
time = findViewById(R.id.time);
//initialize two textviews
setDateTV(dateArray[0], dateArray[1], dateArray[2]);
setTimeTV((timeArray[1]>54? timeArray[0]+1 : timeArray[0]), (timeArray[1]+5)%60);
Log.d(TAG, "init: "+dateArray[1]);
set_date.setOnClickListener(this);
set_time.setOnClickListener(this);
dateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
setDateTV(year, month+1, dayOfMonth);
}
};
timeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
setTimeTV(hourOfDay, minute);
}
};
}
private void setDateTV(int y, int m, int d){
//update tv and dateArray
String temp = y + "-";
if(m<10) temp += "0";
temp += (m + "-");
if(d<10) temp +="0";
temp += d;
date.setText(temp);
dateArray[0] = y;
dateArray[1] = m;
dateArray[2] = d;
}
private void setTimeTV(int h, int m){
//update tv and timeArra
String temp = "";
if(h<10) temp += "0";
temp += (h + ":");
if(m<10) temp += "0";
temp += m;
time.setText(temp);
timeArray[0] = h;
timeArray[1] = m;
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.set_date: //choose day
DatePickerDialog dialog = new DatePickerDialog(EditAlarmActivity.this,
(isNightMode()?R.style.NightDialogTheme :R.style.DayDialogTheme), dateSetListener,
dateArray[0], dateArray[1] - 1, dateArray[2]);
//dialog.getWindow().setBackgroundDrawable(new ColorDrawable((isNightMode()?Color.BLACK : Color.WHITE)));
dialog.show();
break;
case R.id.set_time://choose hour and minute
TimePickerDialog dialog1 = new TimePickerDialog(EditAlarmActivity.this,
(isNightMode()?R.style.NightDialogTheme :R.style.DayDialogTheme), timeSetListener,
timeArray[0], timeArray[1], true);
//dialog1.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog1.show();
break;
}
}
private void isTimeChange(){
String newTime = date.getText().toString() + " " + time.getText().toString();
if(!newTime.equals(old_time)) timeChange = true;
}
private boolean canBeSet(){
Calendar calendar = Calendar.getInstance();
calendar.set(dateArray[0], dateArray[1] - 1, dateArray[2], timeArray[0], timeArray[1]);
Calendar cur = Calendar.getInstance();
Log.d(TAG, "canBeSet: " + cur.getTime().toString() + calendar.getTime().toString());
if(cur.before(calendar)) return true;
else {
Toast.makeText(this, "Invalid Time", Toast.LENGTH_SHORT).show();
return false;
}
}
}
}

@ -1,4 +1,4 @@
package cc.liuyx.note.alarm;
package cc.liuyx.note.adapter;
import android.content.Context;
import android.content.SharedPreferences;
@ -16,6 +16,8 @@ import com.example.atry.R;
import java.util.ArrayList;
import java.util.List;
import cc.liuyx.note.entity.Plan;
public class PlanAdapter extends BaseAdapter implements Filterable {
private Context mContext;

@ -1,63 +0,0 @@
@startuml
title __ADAPTER's Class Diagram__\n
namespace cc.liuyx.note {
namespace adapter {
class cc.liuyx.note.adapter.NoteAdapter {
- backList : List<Note>
- mContext : Context
- noteList : List<Note>
+ NoteAdapter()
+ getCount()
+ getFilter()
+ getItem()
+ getItemId()
+ getView()
}
}
}
namespace cc.liuyx.note {
namespace adapter {
class cc.liuyx.note.adapter.NoteAdapter.MyFilter {
# performFiltering()
# publishResults()
}
}
}
namespace cc.liuyx.note {
namespace adapter {
class cc.liuyx.note.adapter.TagAdapter {
- context : Context
- numList : List<Integer>
- tagList : List<String>
+ TagAdapter()
+ getCount()
+ getItem()
+ getItemId()
+ getView()
}
}
}
cc.liuyx.note.adapter.NoteAdapter .up.|> android.widget.Filterable
cc.liuyx.note.adapter.NoteAdapter -up-|> android.widget.BaseAdapter
cc.liuyx.note.adapter.NoteAdapter o-- cc.liuyx.note.adapter.NoteAdapter.MyFilter : mFilter
cc.liuyx.note.adapter.NoteAdapter +-down- cc.liuyx.note.adapter.NoteAdapter.MyFilter
cc.liuyx.note.adapter.NoteAdapter.MyFilter -up-|> android.widget.Filter
cc.liuyx.note.adapter.TagAdapter -up-|> android.widget.BaseAdapter
right footer
PlantUML diagram generated by SketchIt! (https://bitbucket.org/pmesmeur/sketch.it)
For more information about this tool, please contact philippe.mesmeur@gmail.com
endfooter
@enduml

@ -8,6 +8,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import cc.liuyx.note.activity.MainActivity;
@ -15,13 +16,14 @@ import com.example.atry.R;
public class AlarmReceiver extends BroadcastReceiver {
private String channelId = "Piggy Notes";
private String name = "ChannelName";
private String channelId = "JNote";
private String name = "Liuyx";
@Override
public void onReceive(Context context, Intent intent) {
String title = intent.getExtras().getString("title");
String content = intent.getExtras().getString("content");
int id = intent.getExtras().getInt("id");
Bundle data = intent.getExtras();
String title = data.getString("title");
String content = data.getString("content");
int id = data.getInt("id");
Intent intent1 = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, id, intent1, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);

@ -1,329 +0,0 @@
package cc.liuyx.note.alarm;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import cc.liuyx.note.activity.BaseActivity;
import com.example.atry.R;
import java.util.Calendar;
public class EditAlarmActivity extends BaseActivity implements View.OnClickListener {
private DatePickerDialog.OnDateSetListener dateSetListener;
private TimePickerDialog.OnTimeSetListener timeSetListener;
private EditText et_title;
private EditText et;
private Button set_date;
private Button set_time;
private TextView date;
private TextView time;
private Plan plan;
private int[] dateArray = new int[3];
private int[] timeArray = new int[2];
private int openMode = 0;
private String old_title = "";
private String old_content = "";
private String old_time = "";
private long id = 0;
private boolean timeChange = false;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_alarm_layout);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
init();
final Intent intent = getIntent();
openMode = intent.getExtras().getInt("mode", 0);
if(openMode == 1){
id = intent.getLongExtra("id", 0);
old_title = intent.getStringExtra("title");
old_content = intent.getStringExtra("content");
old_time = intent.getStringExtra("time");
et_title.setText(old_title);
et_title.setSelection(old_title.length());
et.setText(old_content);
et.setSelection(old_content.length());
String[] wholeTime = old_time.split(" ");
String[] temp = wholeTime[0].split("-");
String[] temp1 = wholeTime[1].split(":");
setDateTV(Integer.parseInt(temp[0]), Integer.parseInt(temp[1]), Integer.parseInt(temp[2]));
setTimeTV(Integer.parseInt(temp1[0]), Integer.parseInt(temp1[1]));
}
if(isNightMode()) myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_keyboard_arrow_left_white_24dp));
else myToolbar.setNavigationIcon(getDrawable(R.drawable.ic_keyboard_arrow_left_black_24dp));
myToolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!canBeSet()) {
Toast.makeText(EditAlarmActivity.this, "Invalid Time", Toast.LENGTH_SHORT).show();
}else if(et.getText().toString().length() + et_title.getText().toString().length() == 0 && openMode == 2){
Intent intent1 = new Intent();
intent1.putExtra("mode", -1);//nothing new happens.
setResult(RESULT_OK, intent1);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
else if (et_title.getText().toString().length() == 0) {
Toast.makeText(EditAlarmActivity.this, "Title cannot be empty", Toast.LENGTH_SHORT).show();
}
else {
isTimeChange();
Intent intent = new Intent();
if (openMode == 2) {
intent.putExtra("mode", 10); // new one plan;
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
Log.d(TAG, date.getText().toString() + time.getText().toString());
} else {
if (et.getText().toString().equals(old_content) && et_title.getText().toString().equals(old_title) && !timeChange) {
intent.putExtra("mode", -1); // edit nothing
}
else {
intent.putExtra("mode", 11); //edit the content
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
intent.putExtra("id", id);
}
}
setResult(RESULT_OK, intent);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
}
});
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if( keyCode== KeyEvent.KEYCODE_HOME){
return true;
} else if( keyCode== KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN){
if(!canBeSet()) {
Toast.makeText(EditAlarmActivity.this, "Invalid Time", Toast.LENGTH_SHORT).show();
}else if(et.getText().toString().length() + et_title.getText().toString().length() == 0 && openMode == 2){
Intent intent1 = new Intent();
intent1.putExtra("mode", -1);//nothing new happens.
setResult(RESULT_OK, intent1);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
else if (et_title.getText().toString().length() == 0) {
Toast.makeText(EditAlarmActivity.this, "Title cannot be empty", Toast.LENGTH_SHORT).show();
}
else {
isTimeChange();
Intent intent = new Intent();
if (openMode == 2) {
intent.putExtra("mode", 10); // new one plan;
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
Log.d(TAG, date.getText().toString() + time.getText().toString());
} else {
if (et.getText().toString().equals(old_content) && et_title.getText().toString().equals(old_title) && !timeChange) {
intent.putExtra("mode", -1); // edit nothing
}
else {
intent.putExtra("mode", 11); //edit the content
intent.putExtra("title", et_title.getText().toString());
intent.putExtra("content", et.getText().toString());
intent.putExtra("time", date.getText().toString() + " " + time.getText().toString());
intent.putExtra("id", id);
}
}
setResult(RESULT_OK, intent);
finish();//返回
overridePendingTransition(R.anim.in_lefttoright, R.anim.out_lefttoright);
}
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.edit_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final Intent intent = new Intent();
switch (item.getItemId()){
case R.id.delete:
new AlertDialog.Builder(EditAlarmActivity.this)
.setMessage("Delete this plan ?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(openMode == 2){
intent.putExtra("mode", -1); // delete the plan
setResult(RESULT_OK, intent);
}
else {
intent.putExtra("mode", 12); // delete the plan
intent.putExtra("id", id);
setResult(RESULT_OK, intent);
}
finish();
}
}).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).create().show();
break;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void needRefresh() {
setNightMode();
startActivity(new Intent(this, EditAlarmActivity.class));
overridePendingTransition(R.anim.night_switch, R.anim.night_switch_over);
finish();
}
private void init(){
plan = new Plan();
dateArray[0] = plan.getYear();
dateArray[1] = plan.getMonth() + 1;
dateArray[2] = plan.getDay();
timeArray[0] = plan.getHour();
timeArray[1] = plan.getMinute();
et_title = findViewById(R.id.et_title);
et = findViewById(R.id.et);
set_date = findViewById(R.id.set_date);
set_time = findViewById(R.id.set_time);
date = findViewById(R.id.date);
time = findViewById(R.id.time);
//initialize two textviews
setDateTV(dateArray[0], dateArray[1], dateArray[2]);
setTimeTV((timeArray[1]>54? timeArray[0]+1 : timeArray[0]), (timeArray[1]+5)%60);
Log.d(TAG, "init: "+dateArray[1]);
set_date.setOnClickListener(this);
set_time.setOnClickListener(this);
dateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
setDateTV(year, month+1, dayOfMonth);
}
};
timeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
setTimeTV(hourOfDay, minute);
}
};
}
private void setDateTV(int y, int m, int d){
//update tv and dateArray
String temp = y + "-";
if(m<10) temp += "0";
temp += (m + "-");
if(d<10) temp +="0";
temp += d;
date.setText(temp);
dateArray[0] = y;
dateArray[1] = m;
dateArray[2] = d;
}
private void setTimeTV(int h, int m){
//update tv and timeArra
String temp = "";
if(h<10) temp += "0";
temp += (h + ":");
if(m<10) temp += "0";
temp += m;
time.setText(temp);
timeArray[0] = h;
timeArray[1] = m;
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.set_date: //choose day
DatePickerDialog dialog = new DatePickerDialog(EditAlarmActivity.this,
(isNightMode()?R.style.NightDialogTheme :R.style.DayDialogTheme), dateSetListener,
dateArray[0], dateArray[1] - 1, dateArray[2]);
//dialog.getWindow().setBackgroundDrawable(new ColorDrawable((isNightMode()?Color.BLACK : Color.WHITE)));
dialog.show();
break;
case R.id.set_time://choose hour and minute
TimePickerDialog dialog1 = new TimePickerDialog(EditAlarmActivity.this,
(isNightMode()?R.style.NightDialogTheme :R.style.DayDialogTheme), timeSetListener,
timeArray[0], timeArray[1], true);
//dialog1.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog1.show();
break;
}
}
private void isTimeChange(){
String newTime = date.getText().toString() + " " + time.getText().toString();
if(!newTime.equals(old_time)) timeChange = true;
}
private boolean canBeSet(){
Calendar calendar = Calendar.getInstance();
calendar.set(dateArray[0], dateArray[1] - 1, dateArray[2], timeArray[0], timeArray[1]);
Calendar cur = Calendar.getInstance();
Log.d(TAG, "canBeSet: " + cur.getTime().toString() + calendar.getTime().toString());
if(cur.before(calendar)) return true;
else {
Toast.makeText(this, "Invalid Time", Toast.LENGTH_SHORT).show();
return false;
}
}
}

@ -12,7 +12,7 @@ import java.util.List;
import cc.liuyx.note.entity.Note;
public class CRUD {
public class NoteCRUD {
SQLiteOpenHelper dbHandler;
SQLiteDatabase db;
@ -23,7 +23,7 @@ public class CRUD {
NoteDatabase.MODE
};
public CRUD(Context context){
public NoteCRUD(Context context){
dbHandler = new NoteDatabase(context);
}
@ -32,7 +32,7 @@ public class CRUD {
}
public void close(){
dbHandler.close();
// dbHandler.close();
}
public void addNote(Note note){

@ -1,5 +1,6 @@
package cc.liuyx.note.alarm;
package cc.liuyx.note.db;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
@ -8,7 +9,9 @@ import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.List;
public class CRUD {
import cc.liuyx.note.entity.Plan;
public class PlanCRUD {
SQLiteOpenHelper dbHandler;
SQLiteDatabase db;
@ -19,7 +22,7 @@ public class CRUD {
PlanDatabase.TIME,
};
public CRUD(Context context){
public PlanCRUD(Context context){
dbHandler = new PlanDatabase(context);
}
@ -28,10 +31,10 @@ public class CRUD {
}
public void close(){
dbHandler.close();
// dbHandler.close();
}
public Plan addPlan(Plan plan){
public void addPlan(Plan plan){
//add a plan object to database
ContentValues contentValues = new ContentValues();
contentValues.put(PlanDatabase.TITLE, plan.getTitle());
@ -39,18 +42,18 @@ public class CRUD {
contentValues.put(PlanDatabase.TIME, plan.getTime());
long insertId = db.insert(PlanDatabase.TABLE_NAME, null, contentValues);
plan.setId(insertId);
return plan;
}
public Plan getPlan(long id){
//get a plan from database using cursor index
Cursor cursor = db.query(PlanDatabase.TABLE_NAME,columns,PlanDatabase.ID + "=?",
@SuppressLint("Recycle") Cursor cursor = db.query(PlanDatabase.TABLE_NAME,columns, PlanDatabase.ID + "=?",
new String[]{String.valueOf(id)},null,null, null, null);
if (cursor != null) cursor.moveToFirst();
Plan e = new Plan(cursor.getString(1),cursor.getString(2), cursor.getString(3));
return e;
assert cursor != null;
return new Plan(cursor.getString(1),cursor.getString(2), cursor.getString(3));
}
@SuppressLint("Range")
public List<Plan> getAllPlans(){
Cursor cursor = db.query(PlanDatabase.TABLE_NAME,columns,null,null,null, null, null);

@ -1,8 +1,13 @@
package cc.liuyx.note.alarm;
package cc.liuyx.note.db;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class PlanDatabase extends SQLiteOpenHelper {
@ -14,13 +19,13 @@ public class PlanDatabase extends SQLiteOpenHelper {
public static final String MODE = "mode";
public PlanDatabase(Context context){
public PlanDatabase(Context context) {
super(context, "plans", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE "+ TABLE_NAME
db.execSQL("CREATE TABLE " + TABLE_NAME
+ "("
+ ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ TITLE + " TEXT NOT NULL,"

@ -1,4 +1,4 @@
package cc.liuyx.note.alarm;
package cc.liuyx.note.entity;
import android.util.Log;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

@ -8,7 +8,7 @@
<corners android:radius="6dp"/>
</shape>
</item>
<item android:bottom="3dp">
<item android:bottom="5dp">
<shape android:shape="rectangle">
<solid android:color="?attr/tvBackground" />
<corners android:radius="6dp"/>
Loading…
Cancel
Save