Merge pull request 'wan' (#5) from a_branch into master

master
pkl7bfvwa 4 months ago
commit 2697485a71

@ -4,10 +4,10 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-05-29T14:05:32.256772800Z"> <DropdownSelection timestamp="2025-06-05T01:06:08.196508400Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Administrator\.android\avd\Pixel_9_Pro_XL.avd" /> <DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\Administrator\.android\avd\Medium_Phone_2.avd" />
</handle> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
@ -6,4 +7,11 @@
<component name="ProjectType"> <component name="ProjectType">
<option name="id" value="Android" /> <option name="id" value="Android" />
</component> </component>
<component name="VisualizationToolProject">
<option name="state">
<ProjectState>
<option name="scale" value="0.1132844335778321" />
</ProjectState>
</option>
</component>
</project> </project>

@ -10,7 +10,7 @@ android {
defaultConfig { defaultConfig {
applicationId = "net.micode.notes" applicationId = "net.micode.notes"
minSdk = 24 minSdk = 30
targetSdk = 35 targetSdk = 35
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"

@ -23,7 +23,7 @@ Component组件、Extra扩展信息、Flag标志位 -->
android:versionCode="1" android:versionCode="1"
android:versionName="0.1" > android:versionName="0.1" >
<uses-sdk android:minSdkVersion="24" /> <uses-sdk android:minSdkVersion="30" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /> <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />

@ -29,11 +29,15 @@ import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE; import net.micode.notes.data.NotesDatabaseHelper.TABLE;
import java.util.Objects;
public class NotesProvider extends ContentProvider { public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher; private static final UriMatcher mMatcher;
@ -73,12 +77,6 @@ public class NotesProvider extends ContentProvider {
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + "," + "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA; + "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
@Override @Override
public boolean onCreate() { public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext()); mHelper = NotesDatabaseHelper.getInstance(getContext());
@ -86,8 +84,8 @@ public class NotesProvider extends ContentProvider {
} }
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) { String sortOrder) {
Cursor c = null; Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase(); SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null; String id = null;
@ -132,6 +130,11 @@ public class NotesProvider extends ContentProvider {
try { try {
searchString = String.format("%%%s%%", searchString); searchString = String.format("%%%s%%", searchString);
String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY, c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
new String[] { searchString }); new String[] { searchString });
} catch (IllegalStateException ex) { } catch (IllegalStateException ex) {
@ -142,13 +145,13 @@ public class NotesProvider extends ContentProvider {
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException("Unknown URI " + uri);
} }
if (c != null) { if (c != null) {
c.setNotificationUri(getContext().getContentResolver(), uri); c.setNotificationUri(Objects.requireNonNull(getContext()).getContentResolver(), uri);
} }
return c; return c;
} }
@Override @Override
public Uri insert(Uri uri, ContentValues values) { public Uri insert(@NonNull Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0; long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) { switch (mMatcher.match(uri)) {
@ -168,13 +171,13 @@ public class NotesProvider extends ContentProvider {
} }
// Notify the note uri // Notify the note uri
if (noteId > 0) { if (noteId > 0) {
getContext().getContentResolver().notifyChange( Objects.requireNonNull(getContext()).getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
} }
// Notify the data uri // Notify the data uri
if (dataId > 0) { if (dataId > 0) {
getContext().getContentResolver().notifyChange( Objects.requireNonNull(getContext()).getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
} }
@ -182,7 +185,7 @@ public class NotesProvider extends ContentProvider {
} }
@Override @Override
public int delete(Uri uri, String selection, String[] selectionArgs) { public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
int count = 0; int count = 0;
String id = null; String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
@ -198,7 +201,7 @@ public class NotesProvider extends ContentProvider {
* ID that smaller than 0 is system folder which is not allowed to * ID that smaller than 0 is system folder which is not allowed to
* trash * trash
*/ */
long noteId = Long.valueOf(id); long noteId = Long.parseLong(id);
if (noteId <= 0) { if (noteId <= 0) {
break; break;
} }
@ -220,15 +223,15 @@ public class NotesProvider extends ContentProvider {
} }
if (count > 0) { if (count > 0) {
if (deleteData) { if (deleteData) {
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); Objects.requireNonNull(getContext()).getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
} }
getContext().getContentResolver().notifyChange(uri, null); Objects.requireNonNull(getContext()).getContentResolver().notifyChange(uri, null);
} }
return count; return count;
} }
@Override @Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0; int count = 0;
String id = null; String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
@ -240,7 +243,7 @@ public class NotesProvider extends ContentProvider {
break; break;
case URI_NOTE_ITEM: case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1); id = uri.getPathSegments().get(1);
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs); increaseNoteVersion(Long.parseLong(id), selection, selectionArgs);
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs); + parseSelection(selection), selectionArgs);
break; break;
@ -260,9 +263,9 @@ public class NotesProvider extends ContentProvider {
if (count > 0) { if (count > 0) {
if (updateData) { if (updateData) {
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); Objects.requireNonNull(getContext()).getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
} }
getContext().getContentResolver().notifyChange(uri, null); Objects.requireNonNull(getContext()).getContentResolver().notifyChange(uri, null);
} }
return count; return count;
} }
@ -283,7 +286,7 @@ public class NotesProvider extends ContentProvider {
sql.append(" WHERE "); sql.append(" WHERE ");
} }
if (id > 0) { if (id > 0) {
sql.append(NoteColumns.ID + "=" + String.valueOf(id)); sql.append(NoteColumns.ID + "=").append(String.valueOf(id));
} }
if (!TextUtils.isEmpty(selection)) { if (!TextUtils.isEmpty(selection)) {
String selectString = id > 0 ? parseSelection(selection) : selection; String selectString = id > 0 ? parseSelection(selection) : selection;
@ -297,7 +300,7 @@ public class NotesProvider extends ContentProvider {
} }
@Override @Override
public String getType(Uri uri) { public String getType(@NonNull Uri uri) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return null; return null;
} }

@ -35,8 +35,8 @@ import java.util.ArrayList;
public class Note { public class Note {
private ContentValues mNoteDiffValues; private final ContentValues mNoteDiffValues;
private NoteData mNoteData; private final NoteData mNoteData;
private static final String TAG = "Note"; private static final String TAG = "Note";
/** /**
* Create a new note id for adding a new note to databases * Create a new note id for adding a new note to databases
@ -54,10 +54,10 @@ public class Note {
long noteId = 0; long noteId = 0;
try { try {
noteId = Long.valueOf(uri.getPathSegments().get(1)); assert uri != null;
noteId = Long.parseLong(uri.getPathSegments().get(1));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString()); Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0;
} }
if (noteId == -1) { if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId); throw new IllegalStateException("Wrong note id:" + noteId);
@ -97,7 +97,7 @@ public class Note {
} }
public boolean isLocalModified() { public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); return !mNoteDiffValues.isEmpty() || mNoteData.isLocalModified();
} }
public boolean syncNote(Context context, long noteId) { public boolean syncNote(Context context, long noteId) {
@ -122,22 +122,18 @@ public class Note {
} }
mNoteDiffValues.clear(); mNoteDiffValues.clear();
if (mNoteData.isLocalModified() return !mNoteData.isLocalModified()
&& (mNoteData.pushIntoContentResolver(context, noteId) == null)) { || (mNoteData.pushIntoContentResolver(context, noteId) != null);
return false;
}
return true;
} }
private class NoteData { private class NoteData {
private long mTextDataId; private long mTextDataId;
private ContentValues mTextDataValues; private final ContentValues mTextDataValues;
private long mCallDataId; private long mCallDataId;
private ContentValues mCallDataValues; private final ContentValues mCallDataValues;
private static final String TAG = "NoteData"; private static final String TAG = "NoteData";
@ -189,14 +185,15 @@ public class Note {
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null; ContentProviderOperation.Builder builder = null;
if(mTextDataValues.size() > 0) { if(!mTextDataValues.isEmpty()) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId); mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) { if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues); mTextDataValues);
try { try {
setTextDataId(Long.valueOf(uri.getPathSegments().get(1))); assert uri != null;
setTextDataId(Long.parseLong(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "Insert new text data fail with noteId" + noteId); Log.e(TAG, "Insert new text data fail with noteId" + noteId);
mTextDataValues.clear(); mTextDataValues.clear();
@ -211,14 +208,15 @@ public class Note {
mTextDataValues.clear(); mTextDataValues.clear();
} }
if(mCallDataValues.size() > 0) { if(!mCallDataValues.isEmpty()) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId); mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) { if (mCallDataId == 0) {
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI, Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues); mCallDataValues);
try { try {
setCallDataId(Long.valueOf(uri.getPathSegments().get(1))); assert uri != null;
setCallDataId(Long.parseLong(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.e(TAG, "Insert new call data fail with noteId" + noteId); Log.e(TAG, "Insert new call data fail with noteId" + noteId);
mCallDataValues.clear(); mCallDataValues.clear();
@ -233,16 +231,13 @@ public class Note {
mCallDataValues.clear(); mCallDataValues.clear();
} }
if (operationList.size() > 0) { if (!operationList.isEmpty()) {
try { try {
ContentProviderResult[] results = context.getContentResolver().applyBatch( ContentProviderResult[] results = context.getContentResolver().applyBatch(
Notes.AUTHORITY, operationList); Notes.AUTHORITY, operationList);
return (results == null || results.length == 0 || results[0] == null) ? null return results.length == 0 || results[0] == null ? null
: ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId); : ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId);
} catch (RemoteException e) { } catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null; return null;
} }

@ -34,7 +34,7 @@ import net.micode.notes.tool.ResourceParser.NoteBgResources;
public class WorkingNote { public class WorkingNote {
// Note for the working note // Note for the working note
private Note mNote; private final Note mNote;
// Note Id // Note Id
private long mNoteId; private long mNoteId;
// Note content // Note content
@ -54,7 +54,7 @@ public class WorkingNote {
private long mFolderId; private long mFolderId;
private Context mContext; private final Context mContext;
private static final String TAG = "WorkingNote"; private static final String TAG = "WorkingNote";
@ -217,12 +217,8 @@ public class WorkingNote {
} }
private boolean isWorthSaving() { private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) return !mIsDeleted && (existInDatabase() || !TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) { && (!existInDatabase() || mNote.isLocalModified());
return false;
} else {
return true;
}
} }
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
@ -295,7 +291,7 @@ public class WorkingNote {
} }
public boolean hasClockAlert() { public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false); return (mAlertDate > 0);
} }
public String getContent() { public String getContent() {

@ -36,7 +36,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
public class BackupUtils { public class BackupUtils {
private static final String TAG = "BackupUtils"; private static final String TAG = "BackupUtils";
// Singleton stuff // Singleton stuff
private static BackupUtils sInstance; private static BackupUtils sInstance;
@ -63,7 +63,7 @@ public class BackupUtils {
// Backup or restore success // Backup or restore success
public static final int STATE_SUCCESS = 4; public static final int STATE_SUCCESS = 4;
private TextExport mTextExport; private final TextExport mTextExport;
private BackupUtils(Context context) { private BackupUtils(Context context) {
mTextExport = new TextExport(context); mTextExport = new TextExport(context);
@ -121,7 +121,7 @@ public class BackupUtils {
private static final int FORMAT_NOTE_DATE = 1; private static final int FORMAT_NOTE_DATE = 1;
private static final int FORMAT_NOTE_CONTENT = 2; private static final int FORMAT_NOTE_CONTENT = 2;
private Context mContext; private final Context mContext;
private String mFileName; private String mFileName;
private String mFileDirectory; private String mFileDirectory;
@ -267,9 +267,9 @@ public class BackupUtils {
if (noteCursor != null) { if (noteCursor != null) {
if (noteCursor.moveToFirst()) { if (noteCursor.moveToFirst()) {
do { do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format( ps.printf((getFormat(FORMAT_NOTE_DATE)) + "%n", DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm), mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)))); noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE)));
// Query data belong to this note // Query data belong to this note
String noteId = noteCursor.getString(NOTE_COLUMN_ID); String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps); exportNoteToText(noteId, ps);
@ -298,10 +298,7 @@ public class BackupUtils {
try { try {
FileOutputStream fos = new FileOutputStream(file); FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos); ps = new PrintStream(fos);
} catch (FileNotFoundException e) { } catch (FileNotFoundException | NullPointerException e) {
e.printStackTrace();
return null;
} catch (NullPointerException e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
@ -331,9 +328,7 @@ public class BackupUtils {
file.createNewFile(); file.createNewFile();
} }
return file; return file;
} catch (SecurityException e) { } catch (SecurityException | IOException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -42,7 +42,7 @@ public class DataUtils {
Log.d(TAG, "the ids is null"); Log.d(TAG, "the ids is null");
return true; return true;
} }
if (ids.size() == 0) { if (ids.isEmpty()) {
Log.d(TAG, "no id is in the hashset"); Log.d(TAG, "no id is in the hashset");
return true; return true;
} }
@ -59,14 +59,12 @@ public class DataUtils {
} }
try { try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) { if (results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false; return false;
} }
return true; return true;
} catch (RemoteException e) { } catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
return false; return false;
@ -98,14 +96,12 @@ public class DataUtils {
try { try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) { if (results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false; return false;
} }
return true; return true;
} catch (RemoteException e) { } catch (RemoteException | OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} }
return false; return false;
@ -232,12 +228,10 @@ public class DataUtils {
null); null);
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
try { try (cursor) {
return cursor.getString(0); return cursor.getString(0);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString()); Log.e(TAG, "Get call number fails " + e.toString());
} finally {
cursor.close();
} }
} }
return ""; return "";

@ -38,6 +38,7 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
import java.io.IOException; import java.io.IOException;
import java.util.Objects;
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
@ -64,7 +65,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
Intent intent = getIntent(); Intent intent = getIntent();
try { try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); mNoteId = Long.parseLong(Objects.requireNonNull(intent.getData()).getPathSegments().get(1));
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId); mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0, mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info) SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
@ -104,16 +105,8 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer.prepare(); mPlayer.prepare();
mPlayer.setLooping(true); mPlayer.setLooping(true);
mPlayer.start(); mPlayer.start();
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException | SecurityException | IOException |
// TODO Auto-generated catch block IllegalStateException e) {
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -131,15 +124,11 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
} }
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { if (which == DialogInterface.BUTTON_NEGATIVE) {
case DialogInterface.BUTTON_NEGATIVE: Intent intent = new Intent(this, NoteEditActivity.class);
Intent intent = new Intent(this, NoteEditActivity.class); intent.setAction(Intent.ACTION_VIEW);
intent.setAction(Intent.ACTION_VIEW); intent.putExtra(Intent.EXTRA_UID, mNoteId);
intent.putExtra(Intent.EXTRA_UID, mNoteId); startActivity(intent);
startActivity(intent);
break;
default:
break;
} }
} }

@ -16,6 +16,7 @@
package net.micode.notes.ui; package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -38,6 +39,7 @@ public class AlarmInitReceiver extends BroadcastReceiver {
private static final int COLUMN_ID = 0; private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1; private static final int COLUMN_ALERTED_DATE = 1;
@SuppressLint("UnsafeProtectedBroadcastReceiver")
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
long currentDate = System.currentTimeMillis(); long currentDate = System.currentTimeMillis();

@ -50,9 +50,9 @@ public class DateTimePicker extends FrameLayout {
private final NumberPicker mHourSpinner; private final NumberPicker mHourSpinner;
private final NumberPicker mMinuteSpinner; private final NumberPicker mMinuteSpinner;
private final NumberPicker mAmPmSpinner; private final NumberPicker mAmPmSpinner;
private Calendar mDate; private final Calendar mDate;
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK]; private final String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
private boolean mIsAm; private boolean mIsAm;
@ -64,100 +64,6 @@ public class DateTimePicker extends FrameLayout {
private OnDateTimeChangedListener mOnDateTimeChangedListener; private OnDateTimeChangedListener mOnDateTimeChangedListener;
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
updateDateControl();
onDateTimeChanged();
}
};
private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
boolean isDateChanged = false;
Calendar cal = Calendar.getInstance();
if (!mIs24HourView) {
if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, 1);
isDateChanged = true;
} else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -1);
isDateChanged = true;
}
if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY ||
oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
mIsAm = !mIsAm;
updateAmPmControl();
}
} else {
if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, 1);
isDateChanged = true;
} else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -1);
isDateChanged = true;
}
}
int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY);
mDate.set(Calendar.HOUR_OF_DAY, newHour);
onDateTimeChanged();
if (isDateChanged) {
setCurrentYear(cal.get(Calendar.YEAR));
setCurrentMonth(cal.get(Calendar.MONTH));
setCurrentDay(cal.get(Calendar.DAY_OF_MONTH));
}
}
};
private NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
int minValue = mMinuteSpinner.getMinValue();
int maxValue = mMinuteSpinner.getMaxValue();
int offset = 0;
if (oldVal == maxValue && newVal == minValue) {
offset += 1;
} else if (oldVal == minValue && newVal == maxValue) {
offset -= 1;
}
if (offset != 0) {
mDate.add(Calendar.HOUR_OF_DAY, offset);
mHourSpinner.setValue(getCurrentHour());
updateDateControl();
int newHour = getCurrentHourOfDay();
if (newHour >= HOURS_IN_HALF_DAY) {
mIsAm = false;
updateAmPmControl();
} else {
mIsAm = true;
updateAmPmControl();
}
}
mDate.set(Calendar.MINUTE, newVal);
onDateTimeChanged();
}
};
private NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mIsAm = !mIsAm;
if (mIsAm) {
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);
} else {
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);
}
updateAmPmControl();
onDateTimeChanged();
}
};
public interface OnDateTimeChangedListener { public interface OnDateTimeChangedListener {
void onDateTimeChanged(DateTimePicker view, int year, int month, void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute); int dayOfMonth, int hourOfDay, int minute);
@ -181,14 +87,91 @@ public class DateTimePicker extends FrameLayout {
mDateSpinner = (NumberPicker) findViewById(R.id.date); mDateSpinner = (NumberPicker) findViewById(R.id.date);
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL); mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL); mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);
NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
updateDateControl();
onDateTimeChanged();
}
};
mDateSpinner.setOnValueChangedListener(mOnDateChangedListener); mDateSpinner.setOnValueChangedListener(mOnDateChangedListener);
mHourSpinner = (NumberPicker) findViewById(R.id.hour); mHourSpinner = (NumberPicker) findViewById(R.id.hour);
NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
boolean isDateChanged = false;
Calendar cal = Calendar.getInstance();
if (!mIs24HourView) {
if (!mIsAm && oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, 1);
isDateChanged = true;
} else if (mIsAm && oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -1);
isDateChanged = true;
}
if (oldVal == HOURS_IN_HALF_DAY - 1 && newVal == HOURS_IN_HALF_DAY ||
oldVal == HOURS_IN_HALF_DAY && newVal == HOURS_IN_HALF_DAY - 1) {
mIsAm = !mIsAm;
updateAmPmControl();
}
} else {
if (oldVal == HOURS_IN_ALL_DAY - 1 && newVal == 0) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, 1);
isDateChanged = true;
} else if (oldVal == 0 && newVal == HOURS_IN_ALL_DAY - 1) {
cal.setTimeInMillis(mDate.getTimeInMillis());
cal.add(Calendar.DAY_OF_YEAR, -1);
isDateChanged = true;
}
}
int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY);
mDate.set(Calendar.HOUR_OF_DAY, newHour);
onDateTimeChanged();
if (isDateChanged) {
setCurrentYear(cal.get(Calendar.YEAR));
setCurrentMonth(cal.get(Calendar.MONTH));
setCurrentDay(cal.get(Calendar.DAY_OF_MONTH));
}
}
};
mHourSpinner.setOnValueChangedListener(mOnHourChangedListener); mHourSpinner.setOnValueChangedListener(mOnHourChangedListener);
mMinuteSpinner = (NumberPicker) findViewById(R.id.minute); mMinuteSpinner = (NumberPicker) findViewById(R.id.minute);
mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL); mMinuteSpinner.setMinValue(MINUT_SPINNER_MIN_VAL);
mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL); mMinuteSpinner.setMaxValue(MINUT_SPINNER_MAX_VAL);
mMinuteSpinner.setOnLongPressUpdateInterval(100); mMinuteSpinner.setOnLongPressUpdateInterval(100);
NumberPicker.OnValueChangeListener mOnMinuteChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
int minValue = mMinuteSpinner.getMinValue();
int maxValue = mMinuteSpinner.getMaxValue();
int offset = 0;
if (oldVal == maxValue && newVal == minValue) {
offset += 1;
} else if (oldVal == minValue && newVal == maxValue) {
offset -= 1;
}
if (offset != 0) {
mDate.add(Calendar.HOUR_OF_DAY, offset);
mHourSpinner.setValue(getCurrentHour());
updateDateControl();
int newHour = getCurrentHourOfDay();
if (newHour >= HOURS_IN_HALF_DAY) {
mIsAm = false;
updateAmPmControl();
} else {
mIsAm = true;
updateAmPmControl();
}
}
mDate.set(Calendar.MINUTE, newVal);
onDateTimeChanged();
}
};
mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener); mMinuteSpinner.setOnValueChangedListener(mOnMinuteChangedListener);
String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings(); String[] stringsForAmPm = new DateFormatSymbols().getAmPmStrings();
@ -196,6 +179,19 @@ public class DateTimePicker extends FrameLayout {
mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL); mAmPmSpinner.setMinValue(AMPM_SPINNER_MIN_VAL);
mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL); mAmPmSpinner.setMaxValue(AMPM_SPINNER_MAX_VAL);
mAmPmSpinner.setDisplayedValues(stringsForAmPm); mAmPmSpinner.setDisplayedValues(stringsForAmPm);
NumberPicker.OnValueChangeListener mOnAmPmChangedListener = new NumberPicker.OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
mIsAm = !mIsAm;
if (mIsAm) {
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);
} else {
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);
}
updateAmPmControl();
onDateTimeChanged();
}
};
mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener); mAmPmSpinner.setOnValueChangedListener(mOnAmPmChangedListener);
// update controls to initial state // update controls to initial state

@ -31,10 +31,9 @@ import android.text.format.DateUtils;
public class DateTimePickerDialog extends AlertDialog implements OnClickListener { public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
private Calendar mDate = Calendar.getInstance(); private final Calendar mDate = Calendar.getInstance();
private boolean mIs24HourView; private boolean mIs24HourView;
private OnDateTimeSetListener mOnDateTimeSetListener; private OnDateTimeSetListener mOnDateTimeSetListener;
private DateTimePicker mDateTimePicker;
public interface OnDateTimeSetListener { public interface OnDateTimeSetListener {
void OnDateTimeSet(AlertDialog dialog, long date); void OnDateTimeSet(AlertDialog dialog, long date);
@ -42,7 +41,7 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
public DateTimePickerDialog(Context context, long date) { public DateTimePickerDialog(Context context, long date) {
super(context); super(context);
mDateTimePicker = new DateTimePicker(context); DateTimePicker mDateTimePicker = new DateTimePicker(context);
setView(mDateTimePicker); setView(mDateTimePicker);
mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() { mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
public void onDateTimeChanged(DateTimePicker view, int year, int month, public void onDateTimeChanged(DateTimePicker view, int year, int month,
@ -77,7 +76,7 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_SHOW_YEAR |
DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_DATE |
DateUtils.FORMAT_SHOW_TIME; DateUtils.FORMAT_SHOW_TIME;
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR; flag |= DateUtils.FORMAT_24HOUR;
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag)); setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
} }

@ -28,9 +28,9 @@ import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R; import net.micode.notes.R;
public class DropdownMenu { public class DropdownMenu {
private Button mButton; private final Button mButton;
private PopupMenu mPopupMenu; private final PopupMenu mPopupMenu;
private Menu mMenu; private final Menu mMenu;
public DropdownMenu(Context context, Button button, int menuId) { public DropdownMenu(Context context, Button button, int menuId) {
mButton = button; mButton = button;

@ -63,8 +63,8 @@ public class FoldersListAdapter extends CursorAdapter {
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN); .getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
} }
private class FolderListItem extends LinearLayout { private static class FolderListItem extends LinearLayout {
private TextView mName; private final TextView mName;
public FolderListItem(Context context) { public FolderListItem(Context context) {
super(context); super(context);

@ -16,6 +16,7 @@
package net.micode.notes.ui; package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -52,6 +53,8 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.TextNote; import net.micode.notes.data.Notes.TextNote;
@ -68,13 +71,14 @@ import net.micode.notes.widget.NoteWidgetProvider_4x;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class NoteEditActivity extends Activity implements OnClickListener, public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener { NoteSettingChangedListener, OnTextViewChangeListener {
private class HeadViewHolder { private static class HeadViewHolder {
public TextView tvModified; public TextView tvModified;
public ImageView ivAlertIcon; public ImageView ivAlertIcon;
@ -147,7 +151,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private LinearLayout mEditTextList; private LinearLayout mEditTextList;
private String mUserQuery; private String mUserQuery;
private Pattern mPattern;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -166,9 +169,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* user load this activity, we should restore the former state * user load this activity, we should restore the former state
*/ */
@Override @Override
protected void onRestoreInstanceState(Bundle savedInstanceState) { protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState); super.onRestoreInstanceState(savedInstanceState);
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) { if (savedInstanceState.containsKey(Intent.EXTRA_UID)) {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID)); intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
if (!initActivityState(intent)) { if (!initActivityState(intent)) {
@ -193,7 +196,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* Starting from the searched result * Starting from the searched result
*/ */
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) { if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)); noteId = Long.parseLong(Objects.requireNonNull(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY)));
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY); mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
} }
@ -205,11 +208,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false; return false;
} else { } else {
mWorkingNote = WorkingNote.load(this, noteId); mWorkingNote = WorkingNote.load(this, noteId);
if (mWorkingNote == null) {
Log.e(TAG, "load note failed with note id" + noteId);
finish();
return false;
}
} }
getWindow().setSoftInputMode( getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
@ -235,11 +233,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(), if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
phoneNumber, callDate)) > 0) { phoneNumber, callDate)) > 0) {
mWorkingNote = WorkingNote.load(this, noteId); mWorkingNote = WorkingNote.load(this, noteId);
if (mWorkingNote == null) {
Log.e(TAG, "load call note failed with note id" + noteId);
finish();
return false;
}
} else { } else {
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
widgetType, bgResId); widgetType, bgResId);
@ -309,7 +302,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else { } else {
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE); mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE); mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
}; }
} }
@Override @Override
@ -319,7 +312,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
/** /**
* For new note without note id, we should firstly save it to * For new note without note id, we should firstly save it to
@ -354,13 +347,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
view.getLocationOnScreen(location); view.getLocationOnScreen(location);
int x = location[0]; int x = location[0];
int y = location[1]; int y = location[1];
if (ev.getX() < x return !(ev.getX() < x)
|| ev.getX() > (x + view.getWidth()) && !(ev.getX() > (x + view.getWidth()))
|| ev.getY() < y && !(ev.getY() < y)
|| ev.getY() > (y + view.getHeight())) { && !(ev.getY() > (y + view.getHeight()));
return false;
}
return true;
} }
private void initResources() { private void initResources() {
@ -383,7 +373,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
for (int id : sFontSizeBtnsMap.keySet()) { for (int id : sFontSizeBtnsMap.keySet()) {
View view = findViewById(id); View view = findViewById(id);
view.setOnClickListener(this); view.setOnClickListener(this);
}; }
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE); mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
/** /**
@ -439,7 +429,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} else if (sFontSizeBtnsMap.containsKey(id)) { } else if (sFontSizeBtnsMap.containsKey(id)) {
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE); findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.GONE);
mFontSizeId = sFontSizeBtnsMap.get(id); mFontSizeId = sFontSizeBtnsMap.get(id);
mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).commit(); mSharedPrefs.edit().putInt(PREFERENCE_FONT_SIZE, mFontSizeId).apply();
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE); findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) { if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
getWorkingText(); getWorkingText();
@ -505,6 +495,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true; return true;
} }
@SuppressLint("NonConstantResourceId")
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
@ -609,7 +600,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
private boolean isSyncMode() { private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0; return !NotesPreferenceActivity.getSyncAccountName(this).trim().isEmpty();
} }
public void onClockAlertChanged(long date, boolean set) { public void onClockAlertChanged(long date, boolean set) {
@ -711,7 +702,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private Spannable getHighlightQueryResult(String fullText, String userQuery) { private Spannable getHighlightQueryResult(String fullText, String userQuery) {
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText); SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
if (!TextUtils.isEmpty(userQuery)) { if (!TextUtils.isEmpty(userQuery)) {
mPattern = Pattern.compile(userQuery); Pattern mPattern = Pattern.compile(userQuery);
assert fullText != null;
Matcher m = mPattern.matcher(fullText); Matcher m = mPattern.matcher(fullText);
int start = 0; int start = 0;
while (m.find(start)) { while (m.find(start)) {
@ -726,7 +718,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
} }
private View getListItem(String item, int index) { private View getListItem(String item, int index) {
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null); @SuppressLint("InflateParams") View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text); final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId)); edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item)); CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
@ -743,11 +735,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (item.startsWith(TAG_CHECKED)) { if (item.startsWith(TAG_CHECKED)) {
cb.setChecked(true); cb.setChecked(true);
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
item = item.substring(TAG_CHECKED.length(), item.length()).trim(); item = item.substring(TAG_CHECKED.length()).trim();
} else if (item.startsWith(TAG_UNCHECKED)) { } else if (item.startsWith(TAG_UNCHECKED)) {
cb.setChecked(false); cb.setChecked(false);
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG); edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim(); item = item.substring(TAG_UNCHECKED.length()).trim();
} }
edit.setOnTextViewChangeListener(this); edit.setOnTextViewChangeListener(this);

@ -16,6 +16,7 @@
package net.micode.notes.ui; package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
import android.text.Layout; import android.text.Layout;
@ -32,6 +33,8 @@ import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.widget.EditText; import android.widget.EditText;
import androidx.annotation.NonNull;
import net.micode.notes.R; import net.micode.notes.R;
import java.util.HashMap; import java.util.HashMap;
@ -99,23 +102,21 @@ public class NoteEditText extends EditText {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
@SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
case MotionEvent.ACTION_DOWN: int x = (int) event.getX();
int y = (int) event.getY();
int x = (int) event.getX(); x -= getTotalPaddingLeft();
int y = (int) event.getY(); y -= getTotalPaddingTop();
x -= getTotalPaddingLeft(); x += getScrollX();
y -= getTotalPaddingTop(); y += getScrollY();
x += getScrollX();
y += getScrollY(); Layout layout = getLayout();
int line = layout.getLineForVertical(y);
Layout layout = getLayout(); int off = layout.getOffsetForHorizontal(line, x);
int line = layout.getLineForVertical(y); Selection.setSelection(getText(), off);
int off = layout.getOffsetForHorizontal(line, x);
Selection.setSelection(getText(), off);
break;
} }
return super.onTouchEvent(event); return super.onTouchEvent(event);
@ -170,18 +171,14 @@ public class NoteEditText extends EditText {
@Override @Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) { protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (mOnTextViewChangeListener != null) { if (mOnTextViewChangeListener != null) {
if (!focused && TextUtils.isEmpty(getText())) { mOnTextViewChangeListener.onTextChange(mIndex, focused || !TextUtils.isEmpty(getText()));
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
mOnTextViewChangeListener.onTextChange(mIndex, true);
}
} }
super.onFocusChanged(focused, direction, previouslyFocusedRect); super.onFocusChanged(focused, direction, previouslyFocusedRect);
} }
@Override @Override
protected void onCreateContextMenu(ContextMenu menu) { protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) { if (getText() != null) {
int selStart = getSelectionStart(); int selStart = getSelectionStart();
int selEnd = getSelectionEnd(); int selEnd = getSelectionEnd();
@ -192,7 +189,7 @@ public class NoteEditText extends EditText {
if (urls.length == 1) { if (urls.length == 1) {
int defaultResId = 0; int defaultResId = 0;
for(String schema: sSchemaActionResMap.keySet()) { for(String schema: sSchemaActionResMap.keySet()) {
if(urls[0].getURL().indexOf(schema) >= 0) { if(urls[0].getURL().contains(schema)) {
defaultResId = sSchemaActionResMap.get(schema); defaultResId = sSchemaActionResMap.get(schema);
break; break;
} }
@ -204,7 +201,7 @@ public class NoteEditText extends EditText {
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener( menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
new OnMenuItemClickListener() { new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(@NonNull MenuItem item) {
// goto a new intent // goto a new intent
urls[0].onClick(NoteEditText.this); urls[0].onClick(NoteEditText.this);
return true; return true;

@ -26,7 +26,7 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
public class NoteItemData { public class NoteItemData {
static final String [] PROJECTION = new String [] { static final String [] PROJECTION = new String [] {
NoteColumns.ID, NoteColumns.ID,
NoteColumns.ALERTED_DATE, NoteColumns.ALERTED_DATE,
@ -55,13 +55,13 @@ public class NoteItemData {
private static final int WIDGET_ID_COLUMN = 10; private static final int WIDGET_ID_COLUMN = 10;
private static final int WIDGET_TYPE_COLUMN = 11; private static final int WIDGET_TYPE_COLUMN = 11;
private long mId; private final long mId;
private long mAlertDate; private final long mAlertDate;
private int mBgColorId; private final int mBgColorId;
private long mCreatedDate; private final long mCreatedDate;
private boolean mHasAttachment; private final boolean mHasAttachment;
private long mModifiedDate; private final long mModifiedDate;
private int mNotesCount; private final int mNotesCount;
private long mParentId; private long mParentId;
private String mSnippet; private String mSnippet;
private int mType; private int mType;

@ -16,6 +16,7 @@
package net.micode.notes.ui; package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
@ -60,6 +61,8 @@ import android.widget.PopupMenu;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import net.micode.notes.R; import net.micode.notes.R;
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
@ -93,7 +96,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private enum ListEditState { private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
}; }
private ListEditState mState; private ListEditState mState;
@ -164,17 +167,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
InputStream in = null; InputStream in = null;
try { try {
in = getResources().openRawResource(R.raw.introduction); in = getResources().openRawResource(R.raw.introduction);
if (in != null) { InputStreamReader isr = new InputStreamReader(in);
InputStreamReader isr = new InputStreamReader(in); BufferedReader br = new BufferedReader(isr);
BufferedReader br = new BufferedReader(isr); char [] buf = new char[1024];
char [] buf = new char[1024]; int len = 0;
int len = 0; while ((len = br.read(buf)) > 0) {
while ((len = br.read(buf)) > 0) { sb.append(buf, 0, len);
sb.append(buf, 0, len);
}
} else {
Log.e(TAG, "Read introduction file error");
return;
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -195,7 +193,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
ResourceParser.RED); ResourceParser.RED);
note.setWorkingText(sb.toString()); note.setWorkingText(sb.toString());
if (note.saveNote()) { if (note.saveNote()) {
sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit(); sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).apply();
} else { } else {
Log.e(TAG, "Save introduction note error"); Log.e(TAG, "Save introduction note error");
return; return;
@ -209,6 +207,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
startAsyncNotesListQuery(); startAsyncNotesListQuery();
} }
@SuppressLint({"ClickableViewAccessibility", "InflateParams"})
private void initResources() { private void initResources() {
mContentResolver = this.getContentResolver(); mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver()); mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -234,12 +233,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener { private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu; private DropdownMenu mDropDownMenu;
private ActionMode mActionMode; private ActionMode mActionMode;
private MenuItem mMoveMenu;
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.note_list_options, menu); getMenuInflater().inflate(R.menu.note_list_options, menu);
menu.findItem(R.id.delete).setOnMenuItemClickListener(this); menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
mMoveMenu = menu.findItem(R.id.move); MenuItem mMoveMenu = menu.findItem(R.id.move);
if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER if (mFocusNoteDataItem.getParentId() == Notes.ID_CALL_RECORD_FOLDER
|| DataUtils.getUserFolderCount(mContentResolver) == 0) { || DataUtils.getUserFolderCount(mContentResolver) == 0) {
mMoveMenu.setVisible(false); mMoveMenu.setVisible(false);
@ -252,7 +250,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mNotesListView.setLongClickable(false); mNotesListView.setLongClickable(false);
mAddNewNote.setVisibility(View.GONE); mAddNewNote.setVisibility(View.GONE);
View customView = LayoutInflater.from(NotesListActivity.this).inflate( @SuppressLint("InflateParams") View customView = LayoutInflater.from(NotesListActivity.this).inflate(
R.layout.note_list_dropdown_menu, null); R.layout.note_list_dropdown_menu, null);
mode.setCustomView(customView); mode.setCustomView(customView);
mDropDownMenu = new DropdownMenu(NotesListActivity.this, mDropDownMenu = new DropdownMenu(NotesListActivity.this,
@ -312,7 +310,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
updateMenu(); updateMenu();
} }
public boolean onMenuItemClick(MenuItem item) { @SuppressLint("NonConstantResourceId")
public boolean onMenuItemClick(@NonNull MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) { if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none), Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
Toast.LENGTH_SHORT).show(); Toast.LENGTH_SHORT).show();
@ -348,6 +347,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private class NewNoteOnTouchListener implements OnTouchListener { private class NewNoteOnTouchListener implements OnTouchListener {
@SuppressLint("ClickableViewAccessibility")
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) { switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: { case MotionEvent.ACTION_DOWN: {
@ -406,7 +406,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return false; return false;
} }
}; }
private void startAsyncNotesListQuery() { private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
@ -417,6 +417,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC"); }, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
} }
@SuppressLint("HandlerLeak")
private final class BackgroundQueryHandler extends AsyncQueryHandler { private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) { public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver); super(contentResolver);
@ -469,6 +470,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE); this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
} }
@SuppressLint("StaticFieldLeak")
private void batchDelete() { private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() { new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) { protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
@ -557,13 +559,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar.setVisibility(View.VISIBLE); mTitleBar.setVisibility(View.VISIBLE);
} }
@SuppressLint("NonConstantResourceId")
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { if (v.getId() == R.id.btn_new_note) {
case R.id.btn_new_note: createNewNote();
createNewNote();
break;
default:
break;
} }
} }
@ -719,7 +718,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}; };
@Override @Override
public void onContextMenuClosed(Menu menu) { public void onContextMenuClosed(@NonNull Menu menu) {
if (mNotesListView != null) { if (mNotesListView != null) {
mNotesListView.setOnCreateContextMenuListener(null); mNotesListView.setOnCreateContextMenuListener(null);
} }
@ -727,7 +726,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
@Override @Override
public boolean onContextItemSelected(MenuItem item) { public boolean onContextItemSelected(@NonNull MenuItem item) {
if (mFocusNoteDataItem == null) { if (mFocusNoteDataItem == null) {
Log.e(TAG, "The long click data item is null"); Log.e(TAG, "The long click data item is null");
return false; return false;
@ -778,6 +777,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true; return true;
} }
@SuppressLint("NonConstantResourceId")
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
@ -824,6 +824,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true; return true;
} }
@SuppressLint("StaticFieldLeak")
private void exportNoteToText() { private void exportNoteToText() {
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this); final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
new AsyncTask<Void, Void, Integer>() { new AsyncTask<Void, Void, Integer>() {
@ -867,7 +868,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
private boolean isSyncMode() { private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0; return !NotesPreferenceActivity.getSyncAccountName(this).trim().isEmpty();
} }
private void startPreferenceActivity() { private void startPreferenceActivity() {

@ -33,15 +33,15 @@ import java.util.Iterator;
public class NotesListAdapter extends CursorAdapter { public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter"; private static final String TAG = "NotesListAdapter";
private Context mContext; private final Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex; private final HashMap<Integer, Boolean> mSelectedIndex;
private int mNotesCount; private int mNotesCount;
private boolean mChoiceMode; private boolean mChoiceMode;
public static class AppWidgetAttribute { public static class AppWidgetAttribute {
public int widgetId; public int widgetId;
public int widgetType; public int widgetType;
}; }
public NotesListAdapter(Context context) { public NotesListAdapter(Context context) {
super(context, null); super(context, null);
@ -92,8 +92,8 @@ public class NotesListAdapter extends CursorAdapter {
public HashSet<Long> getSelectedItemIds() { public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>(); HashSet<Long> itemSet = new HashSet<Long>();
for (Integer position : mSelectedIndex.keySet()) { for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) { if (Boolean.TRUE.equals(mSelectedIndex.get(position))) {
Long id = getItemId(position); long id = getItemId(position);
if (id == Notes.ID_ROOT_FOLDER) { if (id == Notes.ID_ROOT_FOLDER) {
Log.d(TAG, "Wrong item id, should not happen"); Log.d(TAG, "Wrong item id, should not happen");
} else { } else {
@ -108,7 +108,7 @@ public class NotesListAdapter extends CursorAdapter {
public HashSet<AppWidgetAttribute> getSelectedWidget() { public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>(); HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) { for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) { if (Boolean.TRUE.equals(mSelectedIndex.get(position))) {
Cursor c = (Cursor) getItem(position); Cursor c = (Cursor) getItem(position);
if (c != null) { if (c != null) {
AppWidgetAttribute widget = new AppWidgetAttribute(); AppWidgetAttribute widget = new AppWidgetAttribute();
@ -130,13 +130,10 @@ public class NotesListAdapter extends CursorAdapter {
public int getSelectedCount() { public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values(); Collection<Boolean> values = mSelectedIndex.values();
if (null == values) {
return 0;
}
Iterator<Boolean> iter = values.iterator(); Iterator<Boolean> iter = values.iterator();
int count = 0; int count = 0;
while (iter.hasNext()) { while (iter.hasNext()) {
if (true == iter.next()) { if (iter.next()) {
count++; count++;
} }
} }
@ -152,7 +149,7 @@ public class NotesListAdapter extends CursorAdapter {
if (null == mSelectedIndex.get(position)) { if (null == mSelectedIndex.get(position)) {
return false; return false;
} }
return mSelectedIndex.get(position); return Boolean.TRUE.equals(mSelectedIndex.get(position));
} }
@Override @Override

@ -16,6 +16,7 @@
package net.micode.notes.ui; package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.View; import android.view.View;
@ -31,12 +32,12 @@ import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
public class NotesListItem extends LinearLayout { public class NotesListItem extends LinearLayout {
private ImageView mAlert; private final ImageView mAlert;
private TextView mTitle; private final TextView mTitle;
private TextView mTime; private final TextView mTime;
private TextView mCallName; private final TextView mCallName;
private NoteItemData mItemData; private NoteItemData mItemData;
private CheckBox mCheckBox; private final CheckBox mCheckBox;
public NotesListItem(Context context) { public NotesListItem(Context context) {
super(context); super(context);
@ -48,6 +49,7 @@ public class NotesListItem extends LinearLayout {
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
} }
@SuppressLint("SetTextI18n")
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
if (choiceMode && data.getType() == Notes.TYPE_NOTE) { if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
mCheckBox.setVisibility(View.VISIBLE); mCheckBox.setVisibility(View.VISIBLE);

@ -18,6 +18,7 @@ package net.micode.notes.ui;
import android.accounts.Account; import android.accounts.Account;
import android.accounts.AccountManager; import android.accounts.AccountManager;
import android.annotation.SuppressLint;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
@ -47,6 +48,8 @@ import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService; import net.micode.notes.gtask.remote.GTaskSyncService;
import java.util.Objects;
public class NotesPreferenceActivity extends PreferenceActivity { public class NotesPreferenceActivity extends PreferenceActivity {
public static final String PREFERENCE_NAME = "notes_preferences"; public static final String PREFERENCE_NAME = "notes_preferences";
@ -69,12 +72,13 @@ public class NotesPreferenceActivity extends PreferenceActivity {
private boolean mHasAddedAccount; private boolean mHasAddedAccount;
@SuppressLint("UnspecifiedRegisterReceiverFlag")
@Override @Override
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
/* using the app icon for navigation */ /* using the app icon for navigation */
getActionBar().setDisplayHomeAsUpEnabled(true); Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
addPreferencesFromResource(R.xml.preferences); addPreferencesFromResource(R.xml.preferences);
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY); mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
@ -292,12 +296,8 @@ public class NotesPreferenceActivity extends PreferenceActivity {
if (!getSyncAccountName(this).equals(account)) { if (!getSyncAccountName(this).equals(account)) {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
if (account != null) { editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, Objects.requireNonNullElse(account, ""));
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account); editor.apply();
} else {
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
editor.commit();
// clean up last sync time // clean up last sync time
setLastSyncTime(this, 0); setLastSyncTime(this, 0);
@ -327,7 +327,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) { if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
editor.remove(PREFERENCE_LAST_SYNC_TIME); editor.remove(PREFERENCE_LAST_SYNC_TIME);
} }
editor.commit(); editor.apply();
// clean up local gtask related info // clean up local gtask related info
new Thread(new Runnable() { new Thread(new Runnable() {
@ -351,7 +351,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time); editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
editor.commit(); editor.apply();
} }
public static long getLastSyncTime(Context context) { public static long getLastSyncTime(Context context) {
@ -375,14 +375,12 @@ public class NotesPreferenceActivity extends PreferenceActivity {
} }
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { if (item.getItemId() == android.R.id.home) {
case android.R.id.home: Intent intent = new Intent(this, NotesListActivity.class);
Intent intent = new Intent(this, NotesListActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);
startActivity(intent); return true;
return true;
default:
return false;
} }
return false;
} }
} }

@ -24,7 +24,7 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser; import net.micode.notes.tool.ResourceParser;
public class NoteWidgetProvider_4x extends NoteWidgetProvider { public class NoteWidgetProvider_4x extends NoteWidgetProvider {
@Override @Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds); super.update(context, appWidgetManager, appWidgetIds);

@ -31,7 +31,7 @@
android:id="@+id/hour" android:id="@+id/hour"
android:layout_width="50dip" android:layout_width="50dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dip" android:layout_marginStart="5dip"
android:focusable="true" android:focusable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
/> />
@ -40,7 +40,7 @@
android:id="@+id/minute" android:id="@+id/minute"
android:layout_width="50dip" android:layout_width="50dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dip" android:layout_marginStart="5dip"
android:focusable="true" android:focusable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
/> />
@ -49,7 +49,7 @@
android:id="@+id/amPm" android:id="@+id/amPm"
android:layout_width="50dip" android:layout_width="50dip"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dip" android:layout_marginStart="5dip"
android:focusable="true" android:focusable="true"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
/> />

@ -15,7 +15,7 @@
limitations under the License. limitations under the License.
--> -->
<FrameLayout <FrameLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:background="@drawable/list_background" android:background="@drawable/list_background"
@ -37,8 +37,9 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:layout_gravity="left|center_vertical" android:layout_gravity="left|center_vertical"
android:layout_marginRight="8dip" android:layout_marginEnd="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" /> android:textAppearance="@style/TextAppearanceSecondaryItem"
tools:ignore="RtlHardcoded" />
<ImageView <ImageView
android:id="@+id/iv_alert_icon" android:id="@+id/iv_alert_icon"
@ -52,8 +53,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginLeft="2dip" android:layout_marginStart="2dip"
android:layout_marginRight="8dip" android:layout_marginEnd="8dip"
android:textAppearance="@style/TextAppearanceSecondaryItem" /> android:textAppearance="@style/TextAppearanceSecondaryItem" />
<ImageButton <ImageButton
@ -81,11 +82,13 @@
android:scrollbars="none" android:scrollbars="none"
android:overScrollMode="never" android:overScrollMode="never"
android:layout_gravity="left|top" android:layout_gravity="left|top"
android:fadingEdgeLength="0dip"> android:fadingEdgeLength="0dip"
tools:ignore="RtlHardcoded">
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="wrap_content"
android:orientation="horizontal">
<net.micode.notes.ui.NoteEditText <net.micode.notes.ui.NoteEditText
android:id="@+id/note_edit_view" android:id="@+id/note_edit_view"
@ -97,14 +100,15 @@
android:linksClickable="false" android:linksClickable="false"
android:minLines="12" android:minLines="12"
android:textAppearance="@style/TextAppearancePrimaryItem" android:textAppearance="@style/TextAppearancePrimaryItem"
android:lineSpacingMultiplier="1.2" /> android:lineSpacingMultiplier="1.2"
tools:ignore="RtlHardcoded" />
<LinearLayout <LinearLayout
android:id="@+id/note_edit_list" android:id="@+id/note_edit_list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:layout_marginLeft="-10dip" android:layout_marginStart="-10dip"
android:visibility="gone" /> android:visibility="gone" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>
@ -121,7 +125,8 @@
android:layout_height="43dip" android:layout_height="43dip"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:background="@drawable/bg_color_btn_mask" android:background="@drawable/bg_color_btn_mask"
android:layout_gravity="top|right" /> android:layout_gravity="top|right"
tools:ignore="RtlHardcoded" />
<LinearLayout <LinearLayout
android:id="@+id/note_bg_color_selector" android:id="@+id/note_bg_color_selector"
@ -129,9 +134,11 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/note_edit_color_selector_panel" android:background="@drawable/note_edit_color_selector_panel"
android:layout_marginTop="30dip" android:layout_marginTop="30dip"
android:layout_marginRight="8dip" android:layout_marginEnd="8dip"
android:layout_gravity="top|right" android:layout_gravity="top|right"
android:visibility="gone"> android:baselineAligned="false"
android:visibility="gone"
tools:ignore="RtlHardcoded">
<FrameLayout <FrameLayout
android:layout_width="0dip" android:layout_width="0dip"
@ -151,7 +158,8 @@
android:layout_marginRight="5dip" android:layout_marginRight="5dip"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
@ -172,7 +180,8 @@
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:layout_marginRight="3dip" android:layout_marginRight="3dip"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
@ -193,7 +202,8 @@
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:layout_marginRight="2dip" android:layout_marginRight="2dip"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
@ -213,7 +223,8 @@
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
@ -233,7 +244,8 @@
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
@ -243,6 +255,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/font_size_selector_bg" android:background="@drawable/font_size_selector_bg"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:baselineAligned="false"
android:visibility="gone"> android:visibility="gone">
<FrameLayout <FrameLayout
@ -256,7 +269,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center"> android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -276,11 +290,12 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
android:layout_marginRight="6dip" android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip" android:layout_marginBottom="-7dip"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
@ -294,7 +309,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center"> android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -316,9 +332,10 @@
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:layout_marginRight="6dip" android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip" android:layout_marginBottom="-7dip"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
@ -332,7 +349,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center"> android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -354,9 +372,10 @@
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:layout_marginRight="6dip" android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip" android:layout_marginBottom="-7dip"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
<FrameLayout <FrameLayout
@ -370,7 +389,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:layout_gravity="center" android:layout_gravity="center"
android:gravity="center"> android:gravity="center"
tools:ignore="UseCompoundDrawables">
<ImageView <ImageView
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -392,9 +412,10 @@
android:layout_gravity="bottom|right" android:layout_gravity="bottom|right"
android:focusable="false" android:focusable="false"
android:visibility="gone" android:visibility="gone"
android:layout_marginRight="6dip" android:layout_marginEnd="6dip"
android:layout_marginBottom="-7dip" android:layout_marginBottom="-7dip"
android:src="@drawable/selected" /> android:src="@drawable/selected"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
</FrameLayout> </FrameLayout>

@ -17,6 +17,7 @@
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -26,7 +27,8 @@
android:layout_height="28dip" android:layout_height="28dip"
android:checked="false" android:checked="false"
android:focusable="false" android:focusable="false"
android:layout_gravity="top|left" /> android:layout_gravity="top|left"
tools:ignore="RtlHardcoded" />
<net.micode.notes.ui.NoteEditText <net.micode.notes.ui.NoteEditText
android:id="@+id/et_edit_text" android:id="@+id/et_edit_text"

@ -17,6 +17,7 @@
<FrameLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/note_item" android:id="@+id/note_item"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent">
@ -39,7 +40,8 @@
android:layout_height="0dip" android:layout_height="0dip"
android:layout_weight="1" android:layout_weight="1"
android:textAppearance="@style/TextAppearancePrimaryItem" android:textAppearance="@style/TextAppearancePrimaryItem"
android:visibility="gone" /> android:visibility="gone"
tools:ignore="NestedWeights" />
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -74,5 +76,6 @@
android:id="@+id/iv_alert_icon" android:id="@+id/iv_alert_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="top|right"/> android:layout_gravity="top|right"
tools:ignore="RtlHardcoded" />
</FrameLayout> </FrameLayout>

@ -45,7 +45,7 @@
android:cacheColorHint="@null" android:cacheColorHint="@null"
android:listSelector="@android:color/transparent" android:listSelector="@android:color/transparent"
android:divider="@null" android:divider="@null"
android:fadingEdge="@null" /> android:fadingEdge="none" />
</LinearLayout> </LinearLayout>
<Button <Button

@ -17,7 +17,8 @@
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navigation_bar" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/navigation_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal">
@ -28,5 +29,6 @@
android:gravity="left|center_vertical" android:gravity="left|center_vertical"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
style="?android:attr/borderlessButtonStyle" /> style="?android:attr/borderlessButtonStyle"
tools:ignore="RtlHardcoded" />
</LinearLayout> </LinearLayout>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.
Loading…
Cancel
Save