zjb 9 months ago
parent 7dddb24200
commit a75d39ea34

Binary file not shown.

@ -2,17 +2,13 @@
"ExpandedNodes": [
"",
"\\app",
"\\app\\build",
"\\app\\build\\tmp",
"\\app\\build\\tmp\\compileDebugJavaWithJavac",
"\\app\\src",
"\\app\\src\\main",
"\\app\\src\\main\\java",
"\\app\\src\\main\\java\\net",
"\\app\\src\\main\\java\\net\\micode",
"\\app\\src\\main\\java\\net\\micode\\notes",
"\\app\\src\\main\\java\\net\\micode\\notes\\data"
"\\app\\src\\main\\java\\net\\micode\\notes"
],
"SelectedNode": "\\app\\build.gradle",
"SelectedNode": "\\app\\src\\main\\java\\net\\micode\\notes\\widget",
"PreviewInSolutionExplorer": false
}

Binary file not shown.

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//包声明,用于区分不同类
package net.micode.notes.tool;
import android.content.Context;
@ -36,8 +36,8 @@ import java.io.IOException;
import java.io.PrintStream;
public class BackupUtils {
private static final String TAG = "BackupUtils";
public class BackupUtils {//备份工具类,用于备份或恢复笔记数据到文本文件
private static final String TAG = "BackupUtils";//日志标签
// 单例模式相关变量
private static BackupUtils sInstance;
@ -49,7 +49,7 @@ public class BackupUtils {
*/
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
sInstance = new BackupUtils(context);
sInstance = new BackupUtils(context);//创建BackupUtils的单例实例
}
return sInstance;
}
@ -68,7 +68,7 @@ public class BackupUtils {
// 备份或恢复成功
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport;
private TextExport mTextExport;//文本导出功能实列
/**
* BackupUtils
@ -76,7 +76,7 @@ public class BackupUtils {
* @param context
*/
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
mTextExport = new TextExport(context);//初始化
}
/**
@ -103,7 +103,7 @@ public class BackupUtils {
* @return
*/
public String getExportedTextFileName() {
return mTextExport.mFileName;
return mTextExport.mFileName;//获取文件名
}
/**
@ -112,7 +112,7 @@ public class BackupUtils {
* @return
*/
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
return mTextExport.mFileDirectory;//获取文件目录
}
/**
@ -216,10 +216,10 @@ public class BackupUtils {
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// 导出该笔记的内容到文本
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
exportNoteToText(noteId, ps);//获取笔记内容并写入打印流
} while (notesCursor.moveToNext());
}
notesCursor.close();
notesCursor.close();//关闭Cursor
}
}
@ -290,14 +290,14 @@ public class BackupUtils {
// 检查外部存储器是否可用
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted");
return STATE_SD_CARD_UNMOUONTED;
return STATE_SD_CARD_UNMOUONTED;//返回SD卡未挂载状态
}
// 获取用于导出的打印流
PrintStream ps = getExportToTextPrintStream();
if (ps == null) {
Log.e(TAG, "get print stream error");
return STATE_SYSTEM_ERROR;
return STATE_SYSTEM_ERROR;//返回系统错误状态
}
// 首先导出文件夹及其包含的笔记
@ -383,7 +383,7 @@ public class BackupUtils {
e.printStackTrace();
return null; // 文件未找到异常返回null
} catch (NullPointerException e) {
e.printStackTrace();
e.printStackTrace();//打印异常堆栈
return null; // 空指针异常返回null
}
return ps; // 返回PrintStream对象

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 包声明,标识该类属于 net.micode.notes.tool 包
package net.micode.notes.tool;
import android.content.ContentProviderOperation;
@ -26,17 +26,17 @@ import android.database.Cursor;
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.NoteColumns;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import net.micode.notes.data.Notes; // 导入 Notes 数据结构
import net.micode.notes.data.Notes.CallNote; // 导入 CallNote 数据结构
import net.micode.notes.data.Notes.NoteColumns; // 导入 NoteColumn 数据结构
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; // 导入小部件属性结构
import java.util.ArrayList;
import java.util.HashSet;
// DataUtils 类,提供与数据相关的实用方法
public class DataUtils {
public static final String TAG = "DataUtils";
public static final String TAG = "DataUtils";// 日志标签
/**
*
@ -47,11 +47,11 @@ public class DataUtils {
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null");
Log.d(TAG, "the ids is null"); // 记录ID为空的情况
return true;
}
if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset");
Log.d(TAG, "no id is in the hashset"); // 记录ID集合为空的情况
return true;
}
@ -60,11 +60,11 @@ public class DataUtils {
for (long id : ids) {
if (id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root");
continue;
continue;// 跳过此ID
}
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));// 创建删除操作
operationList.add(builder.build());// 添加到操作列表
}
try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
@ -75,7 +75,7 @@ public class DataUtils {
}
return true;
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
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()));
}
@ -91,11 +91,11 @@ public class DataUtils {
* @param desFolderId ID
*/
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
ContentValues values = new ContentValues();// 存储更新的内容
values.put(NoteColumns.PARENT_ID, desFolderId);// 更新笔记的父级文件夹ID
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);// 存储原始文件夹ID
values.put(NoteColumns.LOCAL_MODIFIED, 1);// 标记为已修改
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);// 更新笔记
}
/**
@ -117,10 +117,10 @@ public class DataUtils {
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {
ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
builder.withValue(NoteColumns.PARENT_ID, folderId);
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
operationList.add(builder.build());
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));// 创建更新操作
builder.withValue(NoteColumns.PARENT_ID, folderId);// 更新目标文件夹ID
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);// 标记为已修改
operationList.add(builder.build());// 添加到操作列表
}
try {
@ -132,9 +132,9 @@ public class DataUtils {
}
return true;
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
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;
}
@ -147,8 +147,8 @@ public class DataUtils {
*/
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String[]{"COUNT(*)"},
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
new String[]{"COUNT(*)"},// 查询计数
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",// 条件:文件夹且不为回收站
new String[]{String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
null);
@ -158,7 +158,7 @@ public class DataUtils {
try {
count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString());
Log.e(TAG, "get folder count failed:" + e.toString());// 处理索引越界异常
} finally {
cursor.close();
}
@ -274,12 +274,12 @@ public class DataUtils {
HashSet<AppWidgetAttribute> set = null;
if (c != null) {
if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>();
set = new HashSet<AppWidgetAttribute>();// 维护一个小部件信息的集合
do {
try {
AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0);
widget.widgetType = c.getInt(1);
AppWidgetAttribute widget = new AppWidgetAttribute();// 创建小部件属性实例
widget.widgetId = c.getInt(0);// 获取小部件ID
widget.widgetType = c.getInt(1);// 获取小部件类型
set.add(widget);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, e.toString());
@ -307,14 +307,14 @@ public class DataUtils {
if (cursor != null && cursor.moveToFirst()) {
try {
return cursor.getString(0);
return cursor.getString(0);// 返回通话号码
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString());
} finally {
cursor.close();
}
}
return "";
return "";// 若未找到返回空字符串
}
/**

@ -95,8 +95,8 @@ public class DateTimePicker extends FrameLayout {
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
// 根据新旧值的差异更新日期
mDate.add(Calendar.DAY_OF_YEAR, newVal - oldVal);
updateDateControl();
onDateTimeChanged();
updateDateControl();// 更新日期控制
onDateTimeChanged();// 通知日期时间变化
}
};
@ -120,8 +120,8 @@ public class DateTimePicker extends FrameLayout {
}
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();
mIsAm = !mIsAm;// 切换上午和下午
updateAmPmControl();// 更新AM/PM控制
}
} else {
// 处理24小时制下的日期变化
@ -138,7 +138,7 @@ public class DateTimePicker extends FrameLayout {
// 更新小时并触发日期时间改变事件
int newHour = mHourSpinner.getValue() % HOURS_IN_HALF_DAY + (mIsAm ? 0 : HOURS_IN_HALF_DAY);
mDate.set(Calendar.HOUR_OF_DAY, newHour);
onDateTimeChanged();
onDateTimeChanged();// 通知时间变化
// 如果日期有变化,则更新年月日
if (isDateChanged) {
setCurrentYear(cal.get(Calendar.YEAR));
@ -158,18 +158,18 @@ public class DateTimePicker extends FrameLayout {
int maxValue = mMinuteSpinner.getMaxValue();
int offset = 0;
if (oldVal == maxValue && newVal == minValue) {
offset += 1;
offset += 1;// 从最大值到最小值
} else if (oldVal == minValue && newVal == maxValue) {
offset -= 1;
offset -= 1;// 从最小值到最大值
}
// 根据偏移量更新日期和小时选择器并检查是否需要切换AM/PM
if (offset != 0) {
mDate.add(Calendar.HOUR_OF_DAY, offset);
mHourSpinner.setValue(getCurrentHour());
mHourSpinner.setValue(getCurrentHour());// 更新小时选择器
updateDateControl();
int newHour = getCurrentHourOfDay();
if (newHour >= HOURS_IN_HALF_DAY) {
mIsAm = false;
mIsAm = false;// 设置为下午
updateAmPmControl();
} else {
mIsAm = true;
@ -178,7 +178,7 @@ public class DateTimePicker extends FrameLayout {
}
// 更新分钟值并触发日期变化的回调
mDate.set(Calendar.MINUTE, newVal);
onDateTimeChanged();
onDateTimeChanged();// 通知时间变化
}
};
@ -188,9 +188,9 @@ public class DateTimePicker extends FrameLayout {
// 切换AM/PM状态并更新日期和AM/PM选择器
mIsAm = !mIsAm;
if (mIsAm) {
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);
mDate.add(Calendar.HOUR_OF_DAY, -HOURS_IN_HALF_DAY);// 减去12小时
} else {
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);
mDate.add(Calendar.HOUR_OF_DAY, HOURS_IN_HALF_DAY);// 加上12小时
}
updateAmPmControl();
onDateTimeChanged();
@ -568,7 +568,7 @@ public class DateTimePicker extends FrameLayout {
* @param callback null
*/
public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) {
mOnDateTimeChangedListener = callback;
mOnDateTimeChangedListener = callback;// 设置改变监听器
}
/**

@ -61,20 +61,20 @@ public class NoteItemData {
private static final int WIDGET_TYPE_COLUMN = 11;
// 笔记的各项数据
private long mId;
private long mAlertDate;
private int mBgColorId;
private long mCreatedDate;
private boolean mHasAttachment;
private long mModifiedDate;
private int mNotesCount;
private long mParentId;
private String mSnippet;
private int mType;
private int mWidgetId;
private int mWidgetType;
private String mName;
private String mPhoneNumber;
private long mId; // 笔记ID
private long mAlertDate; // 提醒日期
private int mBgColorId; // 背景颜色ID
private long mCreatedDate; // 创建日期
private boolean mHasAttachment; // 是否有附件
private long mModifiedDate; // 修改日期
private int mNotesCount; // 笔记计数
private long mParentId; // 父ID
private String mSnippet; // 笔记摘要
private int mType; // 笔记类型
private int mWidgetId; // 小部件ID
private int mWidgetType; // 小部件类型
private String mName; // 联系人姓名
private String mPhoneNumber; // 联系人电话号码
// 用于标识笔记在列表中的位置状态
private boolean mIsLastItem;

Loading…
Cancel
Save