diff --git a/app/src/main/java/cc/liuyx/note/activity/BaseActivity.java b/app/src/main/java/cc/liuyx/note/activity/BaseActivity.java index 4ff049c..a211642 100644 --- a/app/src/main/java/cc/liuyx/note/activity/BaseActivity.java +++ b/app/src/main/java/cc/liuyx/note/activity/BaseActivity.java @@ -1,5 +1,6 @@ package cc.liuyx.note.activity; +import android.annotation.SuppressLint; import android.app.Activity; import android.content.BroadcastReceiver; import android.content.Context; @@ -21,6 +22,7 @@ import com.githang.statusbar.StatusBarCompat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Objects; public abstract class BaseActivity extends AppCompatActivity { @@ -59,7 +61,6 @@ public abstract class BaseActivity extends AppCompatActivity { public void setNightMode(){ if(isNightMode()) this.setTheme(R.style.NightTheme); else setTheme(R.style.DayTheme); - } protected abstract void needRefresh(); @@ -71,8 +72,7 @@ public abstract class BaseActivity extends AppCompatActivity { } public long calStrToSec(String date) throws ParseException {//decode calender date to second - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - long secTime = format.parse(date).getTime(); - return secTime; + @SuppressLint("SimpleDateFormat") SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + return Objects.requireNonNull(format.parse(date)).getTime(); } } diff --git a/app/src/main/java/cc/liuyx/note/activity/EditActivity.java b/app/src/main/java/cc/liuyx/note/activity/EditActivity.java index 60f7cb0..827cb42 100644 --- a/app/src/main/java/cc/liuyx/note/activity/EditActivity.java +++ b/app/src/main/java/cc/liuyx/note/activity/EditActivity.java @@ -24,6 +24,7 @@ import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.List; +import java.util.Objects; import cc.liuyx.note.db.NoteDatabase; @@ -47,7 +48,7 @@ public class EditActivity extends BaseActivity { Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); setSupportActionBar(myToolbar); - getSupportActionBar().setHomeButtonEnabled(true); + Objects.requireNonNull(getSupportActionBar()).setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/cc/liuyx/note/activity/MainActivity.java b/app/src/main/java/cc/liuyx/note/activity/MainActivity.java index 4fc7889..069577e 100644 --- a/app/src/main/java/cc/liuyx/note/activity/MainActivity.java +++ b/app/src/main/java/cc/liuyx/note/activity/MainActivity.java @@ -171,40 +171,40 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O add_tag = customView.findViewById(R.id.add_tag); add_tag.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (sharedPreferences.getString("tagListString", "").split("_").length < 8) { - final EditText et = new EditText(context); - new AlertDialog.Builder(MainActivity.this) - .setMessage("输入标签名") - .setView(et) - .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - List tagList = Arrays.asList(sharedPreferences.getString("tagListString", null).split("_")); //获取tags - - String name = et.getText().toString(); - if (!tagList.contains(name)) { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - String oldTagListString = sharedPreferences.getString("tagListString", null); - String newTagListString = oldTagListString + "_" + name; - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString("tagListString", newTagListString); - editor.apply(); - refreshTagList(); - } else - Toast.makeText(context, "Repeated tag!", Toast.LENGTH_SHORT).show(); - } - }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }).create().show(); - } else { - Toast.makeText(context, "自定义的标签够多了!", Toast.LENGTH_SHORT).show(); - } + @Override + public void onClick(View v) { + if (sharedPreferences.getString("tagListString", "").split("_").length < 8) { + final EditText et = new EditText(context); + new AlertDialog.Builder(MainActivity.this) + .setMessage("输入标签名") + .setView(et) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + List tagList = Arrays.asList(sharedPreferences.getString("tagListString", null).split("_")); //获取tags + + String name = et.getText().toString(); + if (!tagList.contains(name)) { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + String oldTagListString = sharedPreferences.getString("tagListString", null); + String newTagListString = oldTagListString + "_" + name; + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString("tagListString", newTagListString); + editor.apply(); + refreshTagList(); + } else + Toast.makeText(context, "Repeated tag!", Toast.LENGTH_SHORT).show(); + } + }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }).create().show(); + } else { + Toast.makeText(context, "自定义的标签够多了!", Toast.LENGTH_SHORT).show(); } + } }); //final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); @@ -481,8 +481,8 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O else myToolbar.setTitle("所有笔记"); } + @SuppressLint("InflateParams") public void initPopupView() { - //instantiate the popup.xml layout file layoutInflater = (LayoutInflater) MainActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); customView = (ViewGroup) layoutInflater.inflate(R.layout.setting_layout, null); coverView = (ViewGroup) layoutInflater.inflate(R.layout.setting_cover, null); @@ -496,8 +496,6 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, O } private void initPrefs() { - //initialize all useful SharedPreferences for the first time the app runs - sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); SharedPreferences.Editor editor = sharedPreferences.edit(); if (!sharedPreferences.contains("nightMode")) { diff --git a/app/src/main/java/cc/liuyx/note/alarm/AlarmReceiver.java b/app/src/main/java/cc/liuyx/note/alarm/AlarmReceiver.java index ef6c740..0c2ae83 100644 --- a/app/src/main/java/cc/liuyx/note/alarm/AlarmReceiver.java +++ b/app/src/main/java/cc/liuyx/note/alarm/AlarmReceiver.java @@ -35,15 +35,12 @@ public class AlarmReceiver extends BroadcastReceiver { manager.createNotificationChannel(mChannel); } - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, channelId) .setContentTitle(title).setContentText(content).setSmallIcon(R.drawable.red_alarm_24dp) .setContentIntent(pendingIntent).setAutoCancel(true).setFullScreenIntent(pendingIntent, true); Notification notification = builder.build(); - manager.notify(1, notification); - } }