From 40cf91cf9e3d87faf49db49c6b72b01e0b2e95b4 Mon Sep 17 00:00:00 2001
From: JLY <1114836082@qq.com>
Date: Sun, 15 Jun 2025 01:59:05 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../net/micode/notes/data/NotesProvider.java | 166 ++++++++++--------
.../micode/notes/ui/AlarmInitReceiver.java | 2 +-
.../net/micode/notes/ui/NoteEditActivity.java | 61 ++++++-
.../net/micode/notes/ui/NoteEditText.java | 86 +++++++++
.../micode/notes/ui/NotesListActivity.java | 107 +++++++----
.../notes/widget/NoteWidgetProvider.java | 4 +-
app/src/main/res/drawable/ic_format_bold.xml | 10 ++
.../res/drawable/ic_format_color_text.xml | 10 ++
.../main/res/drawable/ic_format_italic.xml | 10 ++
app/src/main/res/layout/color_picker.xml | 72 ++++++++
app/src/main/res/layout/note_edit.xml | 33 ++++
app/src/main/res/values/strings.xml | 8 +
12 files changed, 446 insertions(+), 123 deletions(-)
create mode 100644 app/src/main/res/drawable/ic_format_bold.xml
create mode 100644 app/src/main/res/drawable/ic_format_color_text.xml
create mode 100644 app/src/main/res/drawable/ic_format_italic.xml
create mode 100644 app/src/main/res/layout/color_picker.xml
diff --git a/app/src/main/java/net/micode/notes/data/NotesProvider.java b/app/src/main/java/net/micode/notes/data/NotesProvider.java
index edb0a60..c54c8a3 100644
--- a/app/src/main/java/net/micode/notes/data/NotesProvider.java
+++ b/app/src/main/java/net/micode/notes/data/NotesProvider.java
@@ -89,95 +89,109 @@ public class NotesProvider extends ContentProvider {
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
Cursor c = null;
- SQLiteDatabase db = mHelper.getReadableDatabase();
- String id = null;
- switch (mMatcher.match(uri)) {
- case URI_NOTE:
- c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
- sortOrder);
- break;
- case URI_NOTE_ITEM:
- id = uri.getPathSegments().get(1);
- c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
- + parseSelection(selection), selectionArgs, null, null, sortOrder);
- break;
- case URI_DATA:
- c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
- sortOrder);
- break;
- case URI_DATA_ITEM:
- id = uri.getPathSegments().get(1);
- c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
- + parseSelection(selection), selectionArgs, null, null, sortOrder);
- break;
- case URI_SEARCH:
- case URI_SEARCH_SUGGEST:
- if (sortOrder != null || projection != null) {
- throw new IllegalArgumentException(
- "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
- }
+ SQLiteDatabase db = null;
+ try {
+ db = mHelper.getReadableDatabase();
+ String id = null;
+ switch (mMatcher.match(uri)) {
+ case URI_NOTE:
+ c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
+ sortOrder);
+ break;
+ case URI_NOTE_ITEM:
+ id = uri.getPathSegments().get(1);
+ c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
+ + parseSelection(selection), selectionArgs, null, null, sortOrder);
+ break;
+ case URI_DATA:
+ c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
+ sortOrder);
+ break;
+ case URI_DATA_ITEM:
+ id = uri.getPathSegments().get(1);
+ c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
+ + parseSelection(selection), selectionArgs, null, null, sortOrder);
+ break;
+ case URI_SEARCH:
+ case URI_SEARCH_SUGGEST:
+ if (sortOrder != null || projection != null) {
+ throw new IllegalArgumentException(
+ "do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
+ }
- String searchString = null;
- if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
- if (uri.getPathSegments().size() > 1) {
- searchString = uri.getPathSegments().get(1);
+ String searchString = null;
+ if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
+ if (uri.getPathSegments().size() > 1) {
+ searchString = uri.getPathSegments().get(1);
+ }
+ } else {
+ searchString = uri.getQueryParameter("pattern");
}
- } else {
- searchString = uri.getQueryParameter("pattern");
- }
- if (TextUtils.isEmpty(searchString)) {
- return null;
- }
+ if (TextUtils.isEmpty(searchString)) {
+ return null;
+ }
- try {
- searchString = String.format("%%%s%%", searchString);
- c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
- new String[] { searchString });
- } catch (IllegalStateException ex) {
- Log.e(TAG, "got exception: " + ex.toString());
- }
- break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
- if (c != null) {
- c.setNotificationUri(getContext().getContentResolver(), uri);
+ try {
+ searchString = String.format("%%%s%%", searchString);
+ c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
+ new String[] { searchString });
+ } catch (IllegalStateException ex) {
+ Log.e(TAG, "got exception: " + ex.toString());
+ }
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
+ if (c != null) {
+ c.setNotificationUri(getContext().getContentResolver(), uri);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Error querying database: " + e.getMessage());
+ if (c != null) {
+ c.close();
+ }
+ return null;
}
return c;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
- SQLiteDatabase db = mHelper.getWritableDatabase();
+ SQLiteDatabase db = null;
long dataId = 0, noteId = 0, insertedId = 0;
- switch (mMatcher.match(uri)) {
- case URI_NOTE:
- insertedId = noteId = db.insert(TABLE.NOTE, null, values);
- break;
- case URI_DATA:
- if (values.containsKey(DataColumns.NOTE_ID)) {
- noteId = values.getAsLong(DataColumns.NOTE_ID);
- } else {
- Log.d(TAG, "Wrong data format without note id:" + values.toString());
- }
- insertedId = dataId = db.insert(TABLE.DATA, null, values);
- break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
- // Notify the note uri
- if (noteId > 0) {
- getContext().getContentResolver().notifyChange(
- ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
- }
+ try {
+ db = mHelper.getWritableDatabase();
+ switch (mMatcher.match(uri)) {
+ case URI_NOTE:
+ insertedId = noteId = db.insert(TABLE.NOTE, null, values);
+ break;
+ case URI_DATA:
+ if (values.containsKey(DataColumns.NOTE_ID)) {
+ noteId = values.getAsLong(DataColumns.NOTE_ID);
+ } else {
+ Log.d(TAG, "Wrong data format without note id:" + values.toString());
+ }
+ insertedId = dataId = db.insert(TABLE.DATA, null, values);
+ break;
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
+ // Notify the note uri
+ if (noteId > 0) {
+ getContext().getContentResolver().notifyChange(
+ ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
+ }
- // Notify the data uri
- if (dataId > 0) {
- getContext().getContentResolver().notifyChange(
- ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
+ // Notify the data uri
+ if (dataId > 0) {
+ getContext().getContentResolver().notifyChange(
+ ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Error inserting into database: " + e.getMessage());
+ return null;
}
-
return ContentUris.withAppendedId(uri, insertedId);
}
diff --git a/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java b/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java
index f221202..b2d58ca 100644
--- a/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java
+++ b/app/src/main/java/net/micode/notes/ui/AlarmInitReceiver.java
@@ -53,7 +53,7 @@ public class AlarmInitReceiver extends BroadcastReceiver {
long alertDate = c.getLong(COLUMN_ALERTED_DATE);
Intent sender = new Intent(context, AlarmReceiver.class);
sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID)));
- PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0);
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, PendingIntent.FLAG_IMMUTABLE);
AlarmManager alermManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
diff --git a/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java b/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
index 96a9ff8..6cf2dda 100644
--- a/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
+++ b/app/src/main/java/net/micode/notes/ui/NoteEditActivity.java
@@ -27,6 +27,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.preference.PreferenceManager;
@@ -51,6 +52,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
+import android.widget.ImageButton;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
@@ -128,7 +130,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private View mFontSizeSelector;
- private EditText mNoteEditor;
+ private NoteEditText mNoteEditor;
private View mNoteEditorPanel;
@@ -149,6 +151,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private String mUserQuery;
private Pattern mPattern;
+ private ImageButton mBoldButton;
+ private ImageButton mItalicButton;
+ private ImageButton mTextColorButton;
+ private static final int[] COLORS = {
+ Color.BLACK, Color.RED, Color.GREEN, Color.BLUE,
+ Color.YELLOW, Color.CYAN, Color.MAGENTA, Color.GRAY
+ };
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -371,7 +381,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mNoteHeaderHolder.tvAlertDate = (TextView) findViewById(R.id.tv_alert_date);
mNoteHeaderHolder.ibSetBgColor = (ImageView) findViewById(R.id.btn_set_bg_color);
mNoteHeaderHolder.ibSetBgColor.setOnClickListener(this);
- mNoteEditor = (EditText) findViewById(R.id.note_edit_view);
+ mNoteEditor = (NoteEditText) findViewById(R.id.note_edit_view);
mNoteEditorPanel = findViewById(R.id.sv_note_edit);
mNoteBgColorSelector = findViewById(R.id.note_bg_color_selector);
for (int id : sBgSelectorBtnsMap.keySet()) {
@@ -395,6 +405,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
}
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
+
+ mBoldButton = (ImageButton) findViewById(R.id.btn_bold);
+ mItalicButton = (ImageButton) findViewById(R.id.btn_italic);
+ mTextColorButton = (ImageButton) findViewById(R.id.btn_text_color);
+
+ mBoldButton.setOnClickListener(this);
+ mItalicButton.setOnClickListener(this);
+ mTextColorButton.setOnClickListener(this);
}
@Override
@@ -425,12 +443,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
setResult(RESULT_OK, intent);
}
+ @Override
public void onClick(View v) {
int id = v.getId();
- if (id == R.id.btn_set_bg_color) {
+ if (id == R.id.btn_bold) {
+ mNoteEditor.setBold(!mNoteEditor.isBold());
+ } else if (id == R.id.btn_italic) {
+ mNoteEditor.setItalic(!mNoteEditor.isItalic());
+ } else if (id == R.id.btn_text_color) {
+ showColorPickerDialog();
+ } else if (id == R.id.btn_set_bg_color) {
mNoteBgColorSelector.setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- - View.VISIBLE);
+ View.VISIBLE);
} else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.GONE);
@@ -623,7 +648,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (mWorkingNote.getNoteId() > 0) {
Intent intent = new Intent(this, AlarmReceiver.class);
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
- PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_IMMUTABLE);
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
showAlertHeader();
if(!set) {
@@ -870,4 +895,30 @@ public class NoteEditActivity extends Activity implements OnClickListener,
private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show();
}
+
+ private void showColorPickerDialog() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.format_text_color);
+
+ final View colorView = getLayoutInflater().inflate(R.layout.color_picker, null);
+ builder.setView(colorView);
+
+ final AlertDialog dialog = builder.create();
+ dialog.show();
+
+ for (int i = 0; i < COLORS.length; i++) {
+ final int color = COLORS[i];
+ View colorButton = colorView.findViewWithTag("color_" + i);
+ if (colorButton != null) {
+ colorButton.setBackgroundColor(color);
+ colorButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ mNoteEditor.setTextColor(color);
+ dialog.dismiss();
+ }
+ });
+ }
+ }
+ }
}
diff --git a/app/src/main/java/net/micode/notes/ui/NoteEditText.java b/app/src/main/java/net/micode/notes/ui/NoteEditText.java
index 2afe2a8..adf8603 100644
--- a/app/src/main/java/net/micode/notes/ui/NoteEditText.java
+++ b/app/src/main/java/net/micode/notes/ui/NoteEditText.java
@@ -23,6 +23,9 @@ import android.text.Selection;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.URLSpan;
+import android.text.style.StyleSpan;
+import android.text.style.ForegroundColorSpan;
+import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
@@ -31,6 +34,8 @@ import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent;
import android.widget.EditText;
+import android.text.Spannable;
+import android.text.SpannableString;
import net.micode.notes.R;
@@ -214,4 +219,85 @@ public class NoteEditText extends EditText {
}
super.onCreateContextMenu(menu);
}
+
+ public void setBold(boolean bold) {
+ int start = getSelectionStart();
+ int end = getSelectionEnd();
+ if (start < end) {
+ SpannableString spannableString = new SpannableString(getText());
+ if (bold) {
+ spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ } else {
+ StyleSpan[] spans = spannableString.getSpans(start, end, StyleSpan.class);
+ for (StyleSpan span : spans) {
+ if (span.getStyle() == android.graphics.Typeface.BOLD) {
+ spannableString.removeSpan(span);
+ }
+ }
+ }
+ setText(spannableString);
+ setSelection(start, end);
+ }
+ }
+
+ public void setItalic(boolean italic) {
+ int start = getSelectionStart();
+ int end = getSelectionEnd();
+ if (start < end) {
+ SpannableString spannableString = new SpannableString(getText());
+ if (italic) {
+ spannableString.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ } else {
+ StyleSpan[] spans = spannableString.getSpans(start, end, StyleSpan.class);
+ for (StyleSpan span : spans) {
+ if (span.getStyle() == android.graphics.Typeface.ITALIC) {
+ spannableString.removeSpan(span);
+ }
+ }
+ }
+ setText(spannableString);
+ setSelection(start, end);
+ }
+ }
+
+ public void setTextColor(int color) {
+ int start = getSelectionStart();
+ int end = getSelectionEnd();
+ if (start < end) {
+ SpannableString spannableString = new SpannableString(getText());
+ spannableString.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ setText(spannableString);
+ setSelection(start, end);
+ }
+ }
+
+ public boolean isBold() {
+ int start = getSelectionStart();
+ int end = getSelectionEnd();
+ if (start < end) {
+ SpannableString spannableString = new SpannableString(getText());
+ StyleSpan[] spans = spannableString.getSpans(start, end, StyleSpan.class);
+ for (StyleSpan span : spans) {
+ if (span.getStyle() == android.graphics.Typeface.BOLD) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ public boolean isItalic() {
+ int start = getSelectionStart();
+ int end = getSelectionEnd();
+ if (start < end) {
+ SpannableString spannableString = new SpannableString(getText());
+ StyleSpan[] spans = spannableString.getSpans(start, end, StyleSpan.class);
+ for (StyleSpan span : spans) {
+ if (span.getStyle() == android.graphics.Typeface.ITALIC) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
diff --git a/app/src/main/java/net/micode/notes/ui/NotesListActivity.java b/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
index e843aec..44be747 100644
--- a/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
+++ b/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
@@ -141,10 +141,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
setContentView(R.layout.note_list);
initResources();
- /**
- * Insert an introduction when user firstly use this application
- */
- setAppInfoFromRawRes();
+ try {
+ setAppInfoFromRawRes();
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to set app info: " + e.getMessage());
+ // Continue without introduction note
+ }
}
@Override
@@ -163,11 +165,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
StringBuilder sb = new StringBuilder();
InputStream in = null;
try {
- in = getResources().openRawResource(R.raw.introduction);
+ in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
- char [] buf = new char[1024];
+ char[] buf = new char[1024];
int len = 0;
while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len);
@@ -177,28 +179,34 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return;
}
} catch (IOException e) {
- e.printStackTrace();
+ Log.e(TAG, "Failed to read introduction: " + e.getMessage());
return;
} finally {
- if(in != null) {
+ if (in != null) {
try {
in.close();
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ Log.e(TAG, "Failed to close introduction stream: " + e.getMessage());
}
}
}
- WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
- AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
- ResourceParser.RED);
- note.setWorkingText(sb.toString());
- if (note.saveNote()) {
- sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
- } else {
- Log.e(TAG, "Save introduction note error");
- return;
+ try {
+ WorkingNote note = WorkingNote.createEmptyNote(this, Notes.ID_ROOT_FOLDER,
+ AppWidgetManager.INVALID_APPWIDGET_ID, Notes.TYPE_WIDGET_INVALIDE,
+ ResourceParser.RED);
+ if (note != null) {
+ note.setWorkingText(sb.toString());
+ if (note.saveNote()) {
+ sp.edit().putBoolean(PREFERENCE_ADD_INTRODUCTION, true).commit();
+ } else {
+ Log.e(TAG, "Save introduction note error");
+ }
+ } else {
+ Log.e(TAG, "Failed to create empty note");
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to create introduction note: " + e.getMessage());
}
}
}
@@ -206,7 +214,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
@Override
protected void onStart() {
super.onStart();
- startAsyncNotesListQuery();
+ try {
+ startAsyncNotesListQuery();
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to start notes query: " + e.getMessage());
+ Toast.makeText(this, R.string.error_loading_notes, Toast.LENGTH_SHORT).show();
+ }
}
private void initResources() {
@@ -409,12 +422,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
};
private void startAsyncNotesListQuery() {
- String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
- : NORMAL_SELECTION;
- mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
- Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
- String.valueOf(mCurrentFolderId)
- }, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
+ try {
+ String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
+ : NORMAL_SELECTION;
+ mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
+ Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
+ String.valueOf(mCurrentFolderId)
+ }, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
+ } catch (Exception e) {
+ Log.e(TAG, "Failed to start notes query: " + e.getMessage());
+ Toast.makeText(this, R.string.error_loading_notes, Toast.LENGTH_SHORT).show();
+ }
}
private final class BackgroundQueryHandler extends AsyncQueryHandler {
@@ -424,19 +442,30 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- switch (token) {
- case FOLDER_NOTE_LIST_QUERY_TOKEN:
- mNotesListAdapter.changeCursor(cursor);
- break;
- case FOLDER_LIST_QUERY_TOKEN:
- if (cursor != null && cursor.getCount() > 0) {
- showFolderListMenu(cursor);
- } else {
- Log.e(TAG, "Query folder failed");
- }
- break;
- default:
- return;
+ try {
+ switch (token) {
+ case FOLDER_NOTE_LIST_QUERY_TOKEN:
+ if (cursor != null) {
+ mNotesListAdapter.changeCursor(cursor);
+ } else {
+ Log.e(TAG, "Query notes failed: cursor is null");
+ Toast.makeText(NotesListActivity.this, R.string.error_loading_notes, Toast.LENGTH_SHORT).show();
+ }
+ break;
+ case FOLDER_LIST_QUERY_TOKEN:
+ if (cursor != null && cursor.getCount() > 0) {
+ showFolderListMenu(cursor);
+ } else {
+ Log.e(TAG, "Query folder failed");
+ Toast.makeText(NotesListActivity.this, R.string.error_loading_folders, Toast.LENGTH_SHORT).show();
+ }
+ break;
+ default:
+ return;
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Error in query complete: " + e.getMessage());
+ Toast.makeText(NotesListActivity.this, R.string.error_loading_notes, Toast.LENGTH_SHORT).show();
}
}
}
diff --git a/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java b/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java
index ec6f819..5e3cdb0 100644
--- a/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java
+++ b/app/src/main/java/net/micode/notes/widget/NoteWidgetProvider.java
@@ -111,11 +111,11 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
rv.setTextViewText(R.id.widget_text,
context.getString(R.string.widget_under_visit_mode));
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent(
- context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
+ context, NotesListActivity.class), PendingIntent.FLAG_IMMUTABLE);
} else {
rv.setTextViewText(R.id.widget_text, snippet);
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent,
- PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent.FLAG_IMMUTABLE);
}
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
diff --git a/app/src/main/res/drawable/ic_format_bold.xml b/app/src/main/res/drawable/ic_format_bold.xml
new file mode 100644
index 0000000..6f8c78e
--- /dev/null
+++ b/app/src/main/res/drawable/ic_format_bold.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_format_color_text.xml b/app/src/main/res/drawable/ic_format_color_text.xml
new file mode 100644
index 0000000..e2819da
--- /dev/null
+++ b/app/src/main/res/drawable/ic_format_color_text.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_format_italic.xml b/app/src/main/res/drawable/ic_format_italic.xml
new file mode 100644
index 0000000..46cefd5
--- /dev/null
+++ b/app/src/main/res/drawable/ic_format_italic.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/color_picker.xml b/app/src/main/res/layout/color_picker.xml
new file mode 100644
index 0000000..6c75437
--- /dev/null
+++ b/app/src/main/res/layout/color_picker.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/note_edit.xml b/app/src/main/res/layout/note_edit.xml
index 10b2aa7..99ca7bf 100644
--- a/app/src/main/res/layout/note_edit.xml
+++ b/app/src/main/res/layout/note_edit.xml
@@ -63,6 +63,39 @@
android:background="@drawable/bg_btn_set_color" />
+
+
+
+
+
+
+
+
+
%1$s results for \"%2$s\"
+ Bold
+ Italic
+ Text Color
+
+
+ Failed to load notes
+ Failed to load folders
+