diff --git a/Notes-master/src/net/micode/notes/model/Note.java b/Notes-master/src/net/micode/notes/model/Note.java index 6ca854c..978dbf7 100644 --- a/Notes-master/src/net/micode/notes/model/Note.java +++ b/Notes-master/src/net/micode/notes/model/Note.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + package net.micode.notes.model; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; @@ -24,20 +24,21 @@ import android.content.OperationApplicationException; import android.net.Uri; import android.os.RemoteException; import android.util.Log; - + import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.CallNote; import net.micode.notes.data.Notes.DataColumns; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.TextNote; - + import java.util.ArrayList; - + // 代表一个笔记,包含笔记的基本信息和笔记数据 public class Note { private ContentValues mNoteDiffValues; private NoteData mNoteData; private static final String TAG = "Note"; + /** * Create a new note id for adding a new note to databases */ @@ -51,7 +52,7 @@ public class Note { values.put(NoteColumns.LOCAL_MODIFIED, 1); values.put(NoteColumns.PARENT_ID, folderId); Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); - + long noteId = 0; try { noteId = Long.valueOf(uri.getPathSegments().get(1)); @@ -64,59 +65,59 @@ public class Note { } return noteId; } - + public Note() { mNoteDiffValues = new ContentValues(); mNoteData = new NoteData(); } - + // 设置笔记的基本信息 public void setNoteValue(String key, String value) { mNoteDiffValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } - + // 设置文本笔记的数据 public void setTextData(String key, String value) { mNoteData.setTextData(key, value); } - + // 设置文本笔记的数据ID public void setTextDataId(long id) { mNoteData.setTextDataId(id); } - + // 获取文本笔记的数据ID public long getTextDataId() { return mNoteData.mTextDataId; } - + // 设置通话笔记的数据ID public void setCallDataId(long id) { mNoteData.setCallDataId(id); } - + // 设置通话笔记的数据 public void setCallData(String key, String value) { mNoteData.setCallData(key, value); } - + // 判断笔记是否被本地修改过 public boolean isLocalModified() { return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); } - + // 同步笔记到数据库 public boolean syncNote(Context context, long noteId) { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); } - + if (!isLocalModified()) { return true; } - + /** * In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and * {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the @@ -129,39 +130,39 @@ public class Note { // Do not return, fall through } mNoteDiffValues.clear(); - + if (mNoteData.isLocalModified() && (mNoteData.pushIntoContentResolver(context, noteId) == null)) { return false; } - + return true; } - + // 笔记数据类,包含文本数据和通话数据 private class NoteData { private long mTextDataId; - + private ContentValues mTextDataValues; - + private long mCallDataId; - + private ContentValues mCallDataValues; - + private static final String TAG = "NoteData"; - + public NoteData() { mTextDataValues = new ContentValues(); mCallDataValues = new ContentValues(); mTextDataId = 0; mCallDataId = 0; } - + // 判断笔记数据是否被本地修改过 boolean isLocalModified() { return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; } - + // 设置文本数据ID void setTextDataId(long id) { if(id <= 0) { @@ -169,7 +170,7 @@ public class Note { } mTextDataId = id; } - + // 设置通话数据ID void setCallDataId(long id) { if (id <= 0) { @@ -177,21 +178,21 @@ public class Note { } mCallDataId = id; } - + // 设置通话数据 void setCallData(String key, String value) { mCallDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } - + // 设置文本数据 void setTextData(String key, String value) { mTextDataValues.put(key, value); mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); } - + // 将笔记数据推送到内容解析器 Uri pushIntoContentResolver(Context context, long noteId) { /** @@ -200,10 +201,10 @@ public class Note { if (noteId <= 0) { throw new IllegalArgumentException("Wrong note id:" + noteId); } - + ArrayList operationList = new ArrayList(); ContentProviderOperation.Builder builder = null; - + if(mTextDataValues.size() > 0) { mTextDataValues.put(DataColumns.NOTE_ID, noteId); if (mTextDataId == 0) { @@ -225,7 +226,7 @@ public class Note { } mTextDataValues.clear(); } - + if(mCallDataValues.size() > 0) { mCallDataValues.put(DataColumns.NOTE_ID, noteId); if (mCallDataId == 0) { @@ -247,7 +248,7 @@ public class Note { } mCallDataValues.clear(); } - + if (operationList.size() > 0) { try { ContentProviderResult[] results = context.getContentResolver().applyBatch( diff --git a/Notes-master/src/net/micode/notes/model/WorkingNote.java b/Notes-master/src/net/micode/notes/model/WorkingNote.java index 606b742..4e90541 100644 --- a/Notes-master/src/net/micode/notes/model/WorkingNote.java +++ b/Notes-master/src/net/micode/notes/model/WorkingNote.java @@ -13,16 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + package net.micode.notes.model; - + import android.appwidget.AppWidgetManager; import android.content.ContentUris; import android.content.Context; import android.database.Cursor; import android.text.TextUtils; import android.util.Log; - + import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.CallNote; import net.micode.notes.data.Notes.DataColumns; @@ -30,7 +30,7 @@ import net.micode.notes.data.Notes.DataConstants; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.TextNote; import net.micode.notes.tool.ResourceParser.NoteBgResources; - + // 表示正在编辑的笔记类 public class WorkingNote { // Note for the working note @@ -41,27 +41,27 @@ public class WorkingNote { private String mContent; // Note mode private int mMode; - + private long mAlertDate; - + private long mModifiedDate; - + private int mBgColorId; - + private int mWidgetId; - + private int mWidgetType; - + private long mFolderId; - + private Context mContext; - + private static final String TAG = "WorkingNote"; - + private boolean mIsDeleted; - + private NoteSettingChangedListener mNoteSettingStatusListener; - + // 数据库查询笔记数据的列 public static final String[] DATA_PROJECTION = new String[] { DataColumns.ID, @@ -72,7 +72,7 @@ public class WorkingNote { DataColumns.DATA3, DataColumns.DATA4, }; - + // 数据库查询笔记信息的列 public static final String[] NOTE_PROJECTION = new String[] { NoteColumns.PARENT_ID, @@ -82,27 +82,27 @@ public class WorkingNote { NoteColumns.WIDGET_TYPE, NoteColumns.MODIFIED_DATE }; - + private static final int DATA_ID_COLUMN = 0; - + private static final int DATA_CONTENT_COLUMN = 1; - + private static final int DATA_MIME_TYPE_COLUMN = 2; - + private static final int DATA_MODE_COLUMN = 3; - + private static final int NOTE_PARENT_ID_COLUMN = 0; - + private static final int NOTE_ALERTED_DATE_COLUMN = 1; - + private static final int NOTE_BG_COLOR_ID_COLUMN = 2; - + private static final int NOTE_WIDGET_ID_COLUMN = 3; - + private static final int NOTE_WIDGET_TYPE_COLUMN = 4; - + private static final int NOTE_MODIFIED_DATE_COLUMN = 5; - + // 新笔记构造方法 private WorkingNote(Context context, long folderId) { mContext = context; @@ -115,7 +115,7 @@ public class WorkingNote { mMode = 0; mWidgetType = Notes.TYPE_WIDGET_INVALIDE; } - + // 已有笔记构造方法 private WorkingNote(Context context, long noteId, long folderId) { mContext = context; @@ -125,13 +125,13 @@ public class WorkingNote { mNote = new Note(); loadNote(); } - + // 从数据库加载笔记信息 private void loadNote() { Cursor cursor = mContext.getContentResolver().query( ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null, null, null); - + if (cursor != null) { if (cursor.moveToFirst()) { mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN); @@ -148,14 +148,14 @@ public class WorkingNote { } loadNoteData(); } - + // 从数据库加载笔记数据 private void loadNoteData() { Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] { String.valueOf(mNoteId) }, null); - + if (cursor != null) { if (cursor.moveToFirst()) { do { @@ -177,7 +177,7 @@ public class WorkingNote { throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId); } } - + // 创建一个空笔记 public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId, int widgetType, int defaultBgColorId) { @@ -187,12 +187,12 @@ public class WorkingNote { note.setWidgetType(widgetType); return note; } - + // 从数据库加载笔记 public static WorkingNote load(Context context, long id) { return new WorkingNote(context, id, 0); } - + // 保存笔记到数据库 public synchronized boolean saveNote() { if (isWorthSaving()) { @@ -202,9 +202,9 @@ public class WorkingNote { return false; } } - + mNote.syncNote(mContext, mNoteId); - + /** * Update widget content if there exist any widget of this note */ @@ -218,12 +218,12 @@ public class WorkingNote { return false; } } - + // 判断笔记是否存在于数据库中 public boolean existInDatabase() { return mNoteId > 0; } - + // 判断笔记是否值得保存 private boolean isWorthSaving() { if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent)) @@ -233,12 +233,12 @@ public class WorkingNote { return true; } } - + // 设置笔记信息改变监听器 public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) { mNoteSettingStatusListener = l; } - + // 设置闹钟提醒日期 public void setAlertDate(long date, boolean set) { if (date != mAlertDate) { @@ -249,7 +249,7 @@ public class WorkingNote { mNoteSettingStatusListener.onClockAlertChanged(date, set); } } - + // 标记笔记是否已删除 public void markDeleted(boolean mark) { mIsDeleted = mark; @@ -258,7 +258,7 @@ public class WorkingNote { mNoteSettingStatusListener.onWidgetChanged(); } } - + // 设置笔记背景颜色ID public void setBgColorId(int id) { if (id != mBgColorId) { @@ -269,7 +269,7 @@ public class WorkingNote { mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id)); } } - + // 设置笔记的检查列表模式 public void setCheckListMode(int mode) { if (mMode != mode) { @@ -280,23 +280,23 @@ public class WorkingNote { mNote.setTextData(TextNote.MODE, String.valueOf(mMode)); } } - - // 设置笔记的窗口小部件类型 + + // 设置窗口小部件类型 public void setWidgetType(int type) { if (type != mWidgetType) { mWidgetType = type; mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType)); } } - - // 设置笔记的窗口小部件ID + + // 设置窗口小部件ID public void setWidgetId(int id) { if (id != mWidgetId) { mWidgetId = id; mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId)); } } - + // 设置工作文本内容 public void setWorkingText(String text) { if (!TextUtils.equals(mContent, text)) { @@ -304,91 +304,91 @@ public class WorkingNote { mNote.setTextData(DataColumns.CONTENT, mContent); } } - + // 将笔记转换为通话笔记 public void convertToCallNote(String phoneNumber, long callDate) { mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate)); mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber); mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER)); } - + // 检查笔记是否有闹钟提醒 public boolean hasClockAlert() { return (mAlertDate > 0 ? true : false); } - + // 获取笔记内容 public String getContent() { return mContent; } - + // 获取闹钟提醒日期 public long getAlertDate() { return mAlertDate; } - + // 获取笔记修改日期 public long getModifiedDate() { return mModifiedDate; } - + // 获取笔记背景颜色资源ID public int getBgColorResId() { return NoteBgResources.getNoteBgResource(mBgColorId); } - + // 获取笔记背景颜色ID public int getBgColorId() { return mBgColorId; } - + // 获取笔记标题背景颜色资源ID public int getTitleBgResId() { return NoteBgResources.getNoteTitleBgResource(mBgColorId); } - + // 获取检查列表模式 public int getCheckListMode() { return mMode; } - + // 获取笔记ID public long getNoteId() { return mNoteId; } - + // 获取笔记所在的文件夹ID public long getFolderId() { return mFolderId; } - + // 获取窗口小部件ID public int getWidgetId() { return mWidgetId; } - + // 获取窗口小部件类型 public int getWidgetType() { return mWidgetType; } - + // 笔记信息改变监听器接口 public interface NoteSettingChangedListener { /** * Called when the background color of current note has just changed */ void onBackgroundColorChanged(); - + /** * Called when user set clock */ void onClockAlertChanged(long date, boolean set); - + /** * Call when user create note from widget */ void onWidgetChanged(); - + /** * Call when switch between check list mode and normal mode * @param oldMode is previous mode before change diff --git a/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java b/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java index d0e4fdb..7cdca97 100644 --- a/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java +++ b/Notes-master/src/net/micode/notes/ui/AlarmAlertActivity.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + package net.micode.notes.ui; - + import android.app.Activity; import android.app.AlertDialog; import android.content.Context; @@ -32,13 +32,13 @@ import android.os.PowerManager; import android.provider.Settings; import android.view.Window; import android.view.WindowManager; - + import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.tool.DataUtils; - + import java.io.IOException; - + /** * 闹钟提醒活动类,继承自Activity,实现了OnClickListener和OnDismissListener接口。 * 该活动用于在闹钟响起时显示提醒对话框,并播放默认的闹钟声音。 @@ -48,7 +48,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD private String mSnippet; // 保存笔记的摘要 private static final int SNIPPET_PREW_MAX_LEN = 60; // 笔记摘要的最大长度 MediaPlayer mPlayer; // 用于播放闹钟声音的MediaPlayer实例 - + /** * 创建活动时调用的方法。 * @param savedInstanceState 保存的实例状态数据包 @@ -57,10 +57,10 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // 请求无标题窗口 - + final Window win = getWindow(); // 获取当前窗口 win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // 设置窗口在锁屏时显示 - + // 如果屏幕未点亮,则添加更多标志以保持屏幕点亮并允许在锁屏时操作 if (!isScreenOn()) { win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON @@ -68,9 +68,9 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR); } - + Intent intent = getIntent(); // 获取启动该活动的Intent - + try { mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1)); // 从Intent中提取笔记ID mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId); // 根据笔记ID获取摘要 @@ -82,7 +82,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD e.printStackTrace(); // 打印异常信息 return; // 如果发生异常,则结束该方法 } - + mPlayer = new MediaPlayer(); // 创建MediaPlayer实例 // 检查数据库中是否存在指定ID的笔记 if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) { @@ -92,7 +92,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD finish(); // 如果笔记不存在,则结束该活动 } } - + /** * 检查屏幕是否点亮。 * @return 如果屏幕点亮则返回true,否则返回false @@ -101,18 +101,18 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // 获取电源管理服务 return pm.isScreenOn(); // 返回屏幕是否点亮的状态 } - + /** * 播放闹钟声音的方法。 */ private void playAlarmSound() { // 获取实际的默认闹钟铃声URI Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM); - + // 获取当前设置的静音模式影响的音频流类型 int silentModeStreams = Settings.System.getInt(getContentResolver(), Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0); - + // 如果静音模式影响了闹钟音频流,则设置MediaPlayer的音频流类型为silentModeStreams // 否则,设置为AudioManager.STREAM_ALARM if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) { @@ -135,7 +135,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD e.printStackTrace(); // 打印异常信息 } } - + /** * 显示操作对话框的方法。 */ @@ -150,7 +150,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD } dialog.show().setOnDismissListener(this); // 显示对话框并设置对话框消失监听器 } - + /** * 实现OnClickListener接口的方法,处理对话框按钮点击事件。 * @param dialog 触发点击事件的对话框 @@ -168,7 +168,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD break; } } - + /** * 实现OnDismissListener接口的方法,处理对话框消失事件。 * @param dialog 消失的对话框 @@ -177,7 +177,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD stopAlarmSound(); // 停止播放闹钟声音 finish(); // 结束该活动 } - + /** * 停止并释放MediaPlayer的方法。 */ diff --git a/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java b/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java index c5dfddd..549630d 100644 --- a/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java +++ b/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + package net.micode.notes.widget; import android.app.PendingIntent; import android.appwidget.AppWidgetManager; @@ -24,14 +24,14 @@ import android.content.Intent; import android.database.Cursor; import android.util.Log; import android.widget.RemoteViews; - + import net.micode.notes.R; import net.micode.notes.data.Notes; import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.tool.ResourceParser; import net.micode.notes.ui.NoteEditActivity; import net.micode.notes.ui.NotesListActivity; - + // 提供笔记小部件功能的抽象类,继承自AppWidgetProvider public abstract class NoteWidgetProvider extends AppWidgetProvider { // 查询笔记时使用的投影列 @@ -40,15 +40,15 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { NoteColumns.BG_COLOR_ID, NoteColumns.SNIPPET }; - + // 投影列对应的索引 public static final int COLUMN_ID = 0; public static final int COLUMN_BG_COLOR_ID = 1; public static final int COLUMN_SNIPPET = 2; - + // 日志标签 private static final String TAG = "NoteWidgetProvider"; - + // 当小部件被删除时调用,更新数据库中的小部件ID为无效值 @Override public void onDeleted(Context context, int[] appWidgetIds) { @@ -61,7 +61,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { new String[] { String.valueOf(appWidgetIds[i])}); } } - + // 根据小部件ID获取笔记信息 private Cursor getNoteWidgetInfo(Context context, int widgetId) { return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, @@ -70,12 +70,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) }, null); } - + // 更新小部件视图 protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { update(context, appWidgetManager, appWidgetIds, false); } - + // 更新小部件视图,支持隐私模式 private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds, boolean privacyMode) { @@ -87,7 +87,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]); intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType()); - + Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]); if (c != null && c.moveToFirst()) { if (c.getCount() > 1) { @@ -103,11 +103,11 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { snippet = context.getResources().getString(R.string.widget_havenot_content); intent.setAction(Intent.ACTION_INSERT_OR_EDIT); } - + if (c != null) { c.close(); } - + RemoteViews rv = new RemoteViews(context.getPackageName(), getLayoutId()); rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId)); intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId); @@ -125,19 +125,19 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider { pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent, PendingIntent.FLAG_UPDATE_CURRENT); } - + rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], rv); } } } - + // 获取背景资源ID的方法,由子类实现 protected abstract int getBgResourceId(int bgId); - + // 获取布局ID的方法,由子类实现 protected abstract int getLayoutId(); - + // 获取小部件类型的ID,由子类实现 protected abstract int getWidgetType(); } \ No newline at end of file