Compare commits

..

3 Commits

Author SHA1 Message Date
lilium-saber 2ae28433c8 更改
2 years ago
lilium-saber 26662d5255 gy
2 years ago
lilium-saber 9f50a77930 all
2 years ago

@ -1,6 +0,0 @@
成员 负责模块
郭德宁 data and model
高源 ui
陈鹤林 gtask
段逸群 tool and widget

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,350 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
import android.content.Context;
import android.database.Cursor;
import android.os.Environment;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;//////
//添加包。类。对象等
public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff
private static BackupUtils sInstance;
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {// 如果实例为空则创建新实例
sInstance = new BackupUtils(context);
} // 返回实例
return sInstance;
}
/**
* Following states are signs to represents backup or restore
* status
*/
// Currently, the sdcard is not mounted
public static final int STATE_SD_CARD_UNMOUONTED = 0;
// The backup file not exist
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
// The data is not well formated, may be changed by other programs
public static final int STATE_DATA_DESTROIED = 2;
// Some run-time exception which causes restore or backup fails
public static final int STATE_SYSTEM_ERROR = 3;
// Backup or restore success
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport;
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
}
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
// 将笔记·导出文本,返回导出时的状态码
public int exportToText() {
return mTextExport.exportToText();
}
// 获取导出文本文件名
public String getExportedTextFileName() {
return mTextExport.mFileName;
}
// 获得到处文本文件目录
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
}
// 负责将笔记导出为文本
private static class TextExport {
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
NoteColumns.MODIFIED_DATE,
NoteColumns.SNIPPET,
NoteColumns.TYPE
};
private static final int NOTE_COLUMN_ID = 0;// 查询结果中笔记id所在列的索引
private static final int NOTE_COLUMN_MODIFIED_DATE = 1;// 查询结果中笔记上次修改时间所在的索引
private static final int NOTE_COLUMN_SNIPPET = 2;// 查询摘要所在索引
private static final String[] DATA_PROJECTION = {
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
DataColumns.DATA2,
DataColumns.DATA3,
DataColumns.DATA4,
};// 定义静态不可变数据列
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_MIME_TYPE = 1;
private static final int DATA_COLUMN_CALL_DATE = 2;
private static final int DATA_COLUMN_PHONE_NUMBER = 4;// 定义以上数据列MIME类呼叫日期号码的索引初始值
private final String[] TEXT_FORMAT;// 定义带有3个元素字符串数组TEXT_FORMAT
private static final int FORMAT_FOLDER_NAME = 0;// 格式化后目录名称FORMAT_FOLDER_NAME= 0
private static final int FORMAT_NOTE_DATE = 1;
private static final int FORMAT_NOTE_CONTENT = 2;// 格式化后的笔记内容索引为2
private Context mContext;// 声名Context类型和字符串类型
private String mFileName;// 文件名称
private String mFileDirectory;// 文件目录路径
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);// 初始化文件名称变量为控字符串
mContext = context;
mFileName = "";
mFileDirectory = "";
}// 初始化文件路径mFileDirectory = ""为空
// 创建TextExport对象
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
/**
* Export the folder identified by folder id to text
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
folderId
}, null);
if (notesCursor != null) {
if (notesCursor.moveToFirst()) {
do {
// Print note's last modified date
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (notesCursor.moveToNext());
}
notesCursor.close();
}
}
/**
* Export note identified by id to a print stream
*/
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, // 查询CONTENT_DATA_URI对应的数据表
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId
}, null);
// 使用DataColumns.NOTE_ID是否为限制查询条件并查询noted对应的数据行
if (dataCursor != null) {// 若查询不为空,则执行以下代码:
if (dataCursor.moveToFirst()) {// 移动游标为第一条记录并循环记录
do {
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);// 获取MIME_TYPE的值
if (DataConstants.CALL_NOTE.equals(mimeType)) {
// Print phone number
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
String location = dataCursor.getString(DATA_COLUMN_CONTENT);// 从记录中获取phonenumber和calldate的值并输出号码
if (!TextUtils.isEmpty(phoneNumber)) {// 若电话号码不为空
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
phoneNumber));// 输出电话号码输出到PrintStream实例PS中
}
// Print call date
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
.format(mContext.getString(R.string.format_datetime_mdhm),
callDate)));// 输出通话日期信息到PrintStream中
// Print call attachment location
if (!TextUtils.isEmpty(location)) {// 若位置信息不为空
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location));
} // 输出位置信息到PrintStream实例PS中
} else if (DataConstants.NOTE.equals(mimeType)) {// 若数据类型为Note则执行以下语句
String content = dataCursor.getString(DATA_COLUMN_CONTENT);// 从Cursor中获取信息
if (!TextUtils.isEmpty(content)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
content));// 将内容信息格式化输出rintStream实例PS中
}
}
} while (dataCursor.moveToNext());
}
dataCursor.close();
}
// print a line separator between note
try {
ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
});
} catch (IOException e) {// 若出现IO异常则廖永Log类的e方法将异常信息输出日志中
Log.e(TAG, e.toString());
}
}
// 使用rintStream实例PS的write方法写入字节数组到输出流中包括换行和字母数字
/**
* Note will be exported as text which is user readable
*/
public int exportToText() {// 定义exportToText(),返回值类型为整型
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted");
return STATE_SD_CARD_UNMOUONTED;
}
// 若外部存储不可用输出日记信息返回表示Media was not mounted
PrintStream ps = getExportToTextPrintStream();// 获取打印输出
if (ps == null) {
Log.e(TAG, "get print stream error");
return STATE_SYSTEM_ERROR;
} // 若获取不到打印输出输出get print stream error",并返回错误
// First export folder and its notes
Cursor folderCursor = mContext.getContentResolver().query(// 声名Cursor类的变量folder存储调查结果
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, // 调用getContentResolver()查询目标为Note表中数据和NOTE_PROJECTION指定列
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER,
null, null);
// 限定查询条件为文件夹且父类文件夹不是回收站
if (folderCursor != null) {// 判断folder是否为空
if (folderCursor.moveToFirst()) {
do {
// Print folder's name
String folderName = "";// 遍历查询文件夹中所有文件夹记录
if (folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
folderName = mContext.getString(R.string.call_record_folder_name);// 若记录对应通话记录文件夹给folder赋值Notes.ID_CALL_RECORD_FOLDER
} else {// 否则folder赋值为记录的摘要字段值
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
}
if (!TextUtils.isEmpty(folderName)) {
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
}
String folderId = folderCursor.getString(NOTE_COLUMN_ID);// 获取当前记录对应文件夹id并赋值给folder
exportFolderToText(folderId, ps);
} while (folderCursor.moveToNext());// 将当前记录文件夹导出为文本形式结果写入PS中
}
folderCursor.close();
}
// Export notes in root's folder
Cursor noteCursor = mContext.getContentResolver().query(// 通过getContentResolver()获取resolver对象并调用querty方法查询
Notes.CONTENT_NOTE_URI, // 查询URI
NOTE_PROJECTION, // 查询列
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0",
null, null);// 限制查询类型为Notes.TYPE_NOTE且父id为0的note记录
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {// 将游标移到查询结果的第一条记录
do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));// 根据时间格式化字符串的时间戳,将时间转换成字符串格式
// Query data belong to this note
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
} // 或i去当前Note记录的id吧id对应数据写入输出流中
noteCursor.close();
}
ps.close();// 关闭游标
return STATE_SUCCESS;
}
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
*/
private PrintStream getExportToTextPrintStream() {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path, // 使用getExportToTextPrintStream()再sd卡上生成指定名称和路径的文本文件
R.string.file_name_txt_format);
if (file == null) {
Log.e(TAG, "create file to exported failed");
return null;// 若生成文件失败返回null再logcat输出错误信息
}
mFileName = file.getName();
mFileDirectory = mContext.getString(R.string.file_path);// 将成功创建文件保存为FoleNAMe路径柏村委mFileDiectory
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos);// 创建对象fos用于写入文件
} catch (FileNotFoundException e) {// 使用fos创建PrintStream对象PS一边向文件夹写入数据
e.printStackTrace();
return null;// 若无法找到写入目标文件再logcat输出错误信息并返回null
} catch (NullPointerException e) {
e.printStackTrace();
return null;
}
return ps;
}
}
/**
* Generate the text file to store imported data
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();
sb.append(Environment.getExternalStorageDirectory());// 再strtingbuilder中添加SD卡根目录路径
sb.append(context.getString(filePathResId));
File filedir = new File(sb.toString());// 添加文件路径字符串资源id并返回file对象表示该目录
sb.append(context.getString(
fileNameFormatResId,
DateFormat.format(context.getString(R.string.format_date_ymd),
System.currentTimeMillis())));// 再StringBuilder添加文件名格式字符串资源id并使用dateFormat替换为当前日期格式化字符串
File file = new File(sb.toString());
// 返回表示最终创建的文件夹对象
try {
if (!filedir.exists()) {
filedir.mkdir();
} // 判断指定目录是否存在,若不存在创建
if (!file.exists()) {
file.createNewFile();
} // 判断指定目录是否存在,若不存在创建
return file;// 返回创建对象
} catch (SecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} // 如果不能在指定目录下创建新的文件则抛出IOException异常
return null;
}
}

@ -0,0 +1,304 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.os.RemoteException;
import android.util.Log;
//导入android 包content、database等
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;
//导入net-micode包下数据
import java.util.ArrayList;
import java.util.HashSet;
//导入JAVA ArrayList和HashSet类
public class DataUtils {// 对DataUtils类进行定义
public static final String TAG = "DataUtils";// 定义静态不可变字TAG符串常量"DataUtils"
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
}
if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset");
return true;
}
// 定义批量删除笔记。若ids参数为null输出"the ids is null"并返回true若ids参数为0输出"no id is in the
// hashset"并返回true
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 定义操作列表存储ContentProviderOperation对象
for (long id : ids) {// 遍历id列表
if (id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root");
continue;
} // 如果id为系统根目录打印"不要删除系统根目录"并进行下一次循环
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());// 创造builder对象删除指定id的ContentProviderOperation
}
try {// 调用applybatch
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
return true;// 若返回为空或第一个结果为null输出删除失败返回false否则返回true
} catch (RemoteException 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()));
} // 若remoteexeption或operationapplicationexception异常返回false
return false;
}
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();// 创建contentValues对象
values.put(NoteColumns.PARENT_ID, desFolderId);// 移动笔记至目标文件夹
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);
// 更新笔记
}
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {// 若ids为空打印log并返回true
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
} // 用于批量移动笔记至文件夹
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {// 遍历笔记id集合
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());// 添加操作至操作列表
}
try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);// 应用操作列表
if (results == null || results.length == 0 || results[0] == null) {// 如果结果为空或者第一个结果为空打印log并返回false
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
return true;// true表示操作成功
} catch (RemoteException 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()));
}
return false;// false表示操作失败
}
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
*/
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[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER) },
null);
int count = 0;
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString());
} finally {
cursor.close();
}
}
}
return count;
}// 检查笔记是否在数据库中可见,若不可见输出"get folder count failed:"
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
new String[] { String.valueOf(type) },
null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
// 检查数据是否在数据库中存在
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
// 检查文件名称是否可见
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
" AND " + NoteColumns.SNIPPET + "=?",
new String[] { name }, null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
// 查询文件夹中所有小部件id和类型
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
NoteColumns.PARENT_ID + "=?",
new String[] { String.valueOf(folderId) },
null);
HashSet<AppWidgetAttribute> set = null;
if (c != null) {
if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>();
// 遍历查询结果将小部件id和类型存入hashSET中
do {
try {
AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0);
widget.widgetType = c.getInt(1);
set.add(widget);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, e.toString());
}
} while (c.moveToNext());
}
c.close();
} // 返回文件夹中所有小部件HashSet集合
return set;
}
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {// 获取一段笔记的getCallNumberByNoteId
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String[] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
new String[] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
null);
if (cursor != null && cursor.moveToFirst()) {
try {
return cursor.getString(0);
} catch (IndexOutOfBoundsException e) {// 如果查询结果不为空且有数据,则返回该行的电话号码
Log.e(TAG, "Get call number fails " + e.toString());// 如果获取电话号码失败,则打印错误日志
} finally {
cursor.close();
} // 关闭游标,释放资源
}
return "";// 如果没有查询结果,则返回空串
}
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
// 使用ContentResover对象来查询数据并返回Cursor对象
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI, // 查询Note id字段
new String[] { CallNote.NOTE_ID }, // 通过童话日期,电话号码扽给查询
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
+ CallNote.PHONE_NUMBER + ",?)", // 传入查询参数
new String[] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
return cursor.getLong(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString());
}
}
cursor.close();
}
return 0;
}
public static String getSnippetById(ContentResolver resolver, long noteId) {// 使用ContentResovler对象查询数据返回Cursor对象
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, // 查询snippet字段
new String[] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?",
new String[] { String.valueOf(noteId) },
null);
if (cursor != null) {
String snippet = "";
if (cursor.moveToFirst()) {// 获取查询结果中第0列的值即snippet字段值
snippet = cursor.getString(0);
}
cursor.close();
return snippet;
}
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}// 通过noteld获取信息返回字符串
public static String getFormattedSnippet(String snippet) {
if (snippet != null) {
snippet = snippet.trim();
int index = snippet.indexOf('\n');
if (index != -1) {
snippet = snippet.substring(0, index);
}
}
return snippet;
}
}

@ -0,0 +1,185 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
import android.content.Context;
import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
public class ResourceParser {
// 定义常量,用于表示颜色和字体大小
public static final int YELLOW = 0;// 黄色
public static final int BLUE = 1;// 蓝
public static final int WHITE = 2;// bai
public static final int GREEN = 3;
public static final int RED = 4;
public static final int BG_DEFAULT_COLOR = YELLOW;// 默认背景颜色为黄色
public static final int TEXT_SMALL = 0;// 字体小号
public static final int TEXT_MEDIUM = 1;// 中
public static final int TEXT_LARGE = 2;// da
public static final int TEXT_SUPER = 3;// chaoda
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;// 默认大小为中
public static class NoteBgResources {
private final static int[] BG_EDIT_RESOURCES = new int[] {
R.drawable.edit_yellow,
R.drawable.edit_blue,
R.drawable.edit_white,
R.drawable.edit_green,
R.drawable.edit_red
};// 定义私有静态常量G_EDIT_RESOURCES 用于储存图片资源id
private final static int[] BG_EDIT_TITLE_RESOURCES = new int[] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
R.drawable.edit_title_white,
R.drawable.edit_title_green,
R.drawable.edit_title_red
};// 定义另一个私有静态常量用于储存笔记编辑页面标题背景资源id
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}// 初始化编辑页面标题背景资源id
public static int getDefaultBgId(Context context) {// 获取应用配置信息,判断用户是否自定义背景颜色
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
} else {
return BG_DEFAULT_COLOR;// 若没有定义,返回默认颜色白色
}
}
public static class NoteItemBgResources {
private final static int[] BG_FIRST_RESOURCES = new int[] { // 定义final整型数组 BG_FIRST_RESOURCES
R.drawable.list_yellow_up, // 黄色背景上边框图案id
R.drawable.list_blue_up, // 蓝色背景上边框图案id
R.drawable.list_white_up, // 白色背景边框图案id
R.drawable.list_green_up, // 绿色背景边框图案id
R.drawable.list_red_up// 红色背景边框图案id
};
private final static int[] BG_NORMAL_RESOURCES = new int[] {
R.drawable.list_yellow_middle, // 黄色背景中间边框图案id
R.drawable.list_blue_middle, // 蓝色背景中间边框图案id
R.drawable.list_white_middle, // 白色背景中间边框图案id
R.drawable.list_green_middle, // 绿色背景中间边框图案id
R.drawable.list_red_middle// 红色背景中间边框图案id
};
private final static int[] BG_LAST_RESOURCES = new int[] {
R.drawable.list_yellow_down, // 黄色背景中下间边框图案id
R.drawable.list_blue_down, // 蓝色背景中下间边框图案id
R.drawable.list_white_down, // 白色背景中下间边框图案id
R.drawable.list_green_down, // 绿色背景中下间边框图案id
R.drawable.list_red_down,// 红色背景中下间边框图案id
};
private final static int[] BG_SINGLE_RESOURCES = new int[] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
R.drawable.list_white_single,
R.drawable.list_green_single,
R.drawable.list_red_single
};
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
// 定义getNoteBgFirstRes方法用于返回G_FIRST_RESOURCES[id]
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
// 定义getNoteBgLastRes方法用于返回 BG_LAST_RESOURCES[id]
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
// 定义getNoteBgSingleRes方法用于返回BG_SINGLE_RESOURCES[id]
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
// 定义etNoteBgNormalRes方法用于返回BG_NORMAL_RESOURCES[id]
public static int getFolderBgRes() {
return R.drawable.list_folder;
}// 定义getFolderBgRes方法用于返回 R.drawable.list_folder
}
public static class WidgetBgResources {// 定义静态内部类WidgetBgResources
private final static int[] BG_2X_RESOURCES = new int[] {
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
R.drawable.widget_2x_white,
R.drawable.widget_2x_green,
R.drawable.widget_2x_red,
};// 管理小部件2x2格式不同颜色资源图片
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
private final static int[] BG_4X_RESOURCES = new int[] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
R.drawable.widget_4x_white,
R.drawable.widget_4x_green,
R.drawable.widget_4x_red
};// 管理小部件4x4格式不同颜色资源图片
public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id];
}
}
public static class TextAppearanceResources {// 定义TextAppearanceResources 静态内部类
private final static int[] TEXTAPPEARANCE_RESOURCES = new int[] {
R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium,
R.style.TextAppearanceLarge,
R.style.TextAppearanceSuper
};// 分别对应中等,大号,超大的文本外观样式
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
}
return TEXTAPPEARANCE_RESOURCES[id];
}
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}

@ -0,0 +1,133 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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;//导入包
import android.appwidget.AppWidgetProvider;//导入包
import android.content.ContentValues;
import android.content.Context;
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;
public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String[] PROJECTION = new String[] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET
};// 定义字符串数组PROJECTION包含IDB G_COLOR_ID 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";
@Override
public void onDeleted(Context context, int[] appWidgetIds) {// 创建一个ContentValues对象values存储键值对数据
ContentValues values = new ContentValues();
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);// 将无效小部件id存储ContentValues中
for (int i = 0; i < appWidgetIds.length; i++) {
context.getContentResolver().update(Notes.CONTENT_NOTE_URI,
values,
NoteColumns.WIDGET_ID + "=?",
new String[] { String.valueOf(appWidgetIds[i]) });// 通过getcontent函数获取程序contentValues对象用update方法更新
}
}
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION, // 获取ContentResovler对象并用querty方法查询数据·
NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",
new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },
null);
}// 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) {
for (int i = 0; i < appWidgetIds.length; i++) {// 判断当前小部件id是否合法若合法才可进行操作
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
int bgId = ResourceParser.getDefaultBgId(context);// 获取默认背景图片id并将其作为当前部件的背景
String snippet = "";
Intent intent = new Intent(context, NoteEditActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);// 创建internet对象设置flag标志
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) {
Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]);
c.close();
return;
} // 判断数据库查询结果c是否为空若查询结果大于1则记录日志错误并返回
snippet = c.getString(COLUMN_SNIPPET);
bgId = c.getInt(COLUMN_BG_COLOR_ID);
intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
intent.setAction(Intent.ACTION_VIEW);// 将当前记录id作为extra数据存入启动internet对象中
} else {
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);
/**
* Generate the pending intent to start host for the widget
*/
PendingIntent pendingIntent = null;
if (privacyMode) {// 判断是否处于隐私模式
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);// 如果是将小部件文本设置为“访问模式下”并创建一个PendingIntent使点击小部件时跳转至NotesListActivity
} else {
rv.setTextViewText(R.id.widget_text, snippet);
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent,
PendingIntent.FLAG_UPDATE_CURRENT);
} // 如果不是将小部件文本设置为片段内容并创建一个PendingIntent使点击小部件时跳转至NoteEditActivity
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
}
}
}
protected abstract int getBgResourceId(int bgId);
protected abstract int getLayoutId();
protected abstract int getWidgetType();// 获取背景资源id布局资源id小部件类型
}

@ -0,0 +1,198 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Bundle;
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;
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener { // 实现OnClickListener接口用于监听对话框按钮的点击事件
private long mNoteId; // 用于存储笔记Id
private String mSnippet; // 用于存储笔记内容摘要
private static final int SNIPPET_PREW_MAX_LEN = 60;// 限制笔记长度
MediaPlayer mPlayer;
// onCreate() 函数在 Activity 初始化时调用,用于初始化
// savedInstanceState 该参数用于恢复 Activity 状态。
@Override
protected void onCreate(Bundle savedInstanceState) {// 重写onCreate()方法用于初始化该方法在Activity初始化时调用
super.onCreate(savedInstanceState);
// 界面显示:无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);// 设置窗口没有标题
// 获取 Window 对象,添加 FLAG_SHOW_WHEN_LOCKED 标记
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);// 设置窗口在锁屏时仍然显示
// 如果屏幕没亮,添加一系列 屏幕唤醒标记
if (!isScreenOn()) {
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON // 保持窗口常亮
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON // 点亮窗口
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON // 允许在窗口点亮时锁屏
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
}
// 获取Intent对象
Intent intent = getIntent();
// 从Intent对象中获取笔记的 Id 和内容
try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
// 根据便签Id从数据库中获取便签内容
// getContentResolver() 实现数据共享,实例存储
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
: mSnippet;
} catch (IllegalArgumentException e) {
e.printStackTrace();
return;
}
// 创建 MediaPlayer 对象,根据笔记是否存在数据库中来展示操作对话框或者直接退出
mPlayer = new MediaPlayer();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog();
playAlarmSound();
} else {
finish();
}
}
// 用于判断屏幕是否被唤醒(亮着)
private boolean isScreenOn() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
// 用于实现报警铃声的播放
private void playAlarmSound() {
// 获取系统默认的铃声
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
// 获取静音模式下允许响铃的类型
int silentModeStreams = Settings.System.getInt(getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
// 判断闹钟铃声是否被静音模式影响
// 若被影响则设置播放音频类型为允许响铃的类型
// 若违背影响则设置音频为默认类型
if ((silentModeStreams & (1 << AudioManager.STREAM_ALARM)) != 0) {
mPlayer.setAudioStreamType(silentModeStreams);
} else {
mPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
}
try {
mPlayer.setDataSource(this, url); // 设置报警铃声
mPlayer.prepare(); // 准备同步
mPlayer.setLooping(true); // 设置循环播放
mPlayer.start(); // 开始播放
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
// 以下的 e.printStackTrace() 函数功能是抛出异常,还将显示出更深的调用信息
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
e.printStackTrace();
}
}
// 创建一个对话框标题为app的名字内容为mSnippet确定按钮为notealert_ok
// 当屏幕开启时取消按钮为notealert_enter点击弹出框外部可以隐藏弹出框
private void showActionDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
// 为对话框设置标题
dialog.setTitle(R.string.app_name);
// 为对话框设置内容
dialog.setMessage(mSnippet);
// 给对话框添加“OK”按钮
dialog.setPositiveButton(R.string.notealert_ok, this);
if (isScreenOn()) {
// 给对话框添加“CANCEL”按钮
dialog.setNegativeButton(R.string.notealert_enter, this);
}
// 给对话框设置监听器
dialog.show().setOnDismissListener(this);
}
// 当对话框界面内某个按钮被点击时调用以下方法
// 接收 对话框界面 和 点击的按钮位置which 为参数
public void onClick(DialogInterface dialog, int which) {
// switch语句根据按钮位置的不同执行不同的操作
switch (which) {
// 当点击点击的是返回按键
case DialogInterface.BUTTON_NEGATIVE:
// 将编辑的便签内容传输到特定类中
Intent intent = new Intent(this, NoteEditActivity.class);
// 设置操作属性
intent.setAction(Intent.ACTION_VIEW);
// 创建一个特定的Note Id传输给便签
intent.putExtra(Intent.EXTRA_UID, mNoteId);
// 开始操作
startActivity(intent);
break;
// 如果是其他按钮被点击则不执行任何操作
default:
break;
}
}
public void onDismiss(DialogInterface dialog) {
// 终止报警声音
stopAlarmSound();
// 完成动作
finish();
}
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop();// 停止播放
mPlayer.release();
// 释放 MediaPlayer(媒体播放器)对象
mPlayer = null;
}
}
}

@ -0,0 +1,73 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.app.AlarmManager;//闹钟管理器
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
//定时向用户推送闹钟提醒
public class AlarmInitReceiver extends BroadcastReceiver {// 继承BroadcastReceiver类,用于接收广播,并且在接收到广播后启动AlarmAlertActivity
// 对数据库的操作调用笔记Id和时钟时间
private static final String[] PROJECTION = new String[] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE
};
private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1;
// 重写 BroadcastReceiver 的 onReceive 方法
@Override
public void onReceive(Context context, Intent intent) {
// 获取当前系统时间
long currentDate = System.currentTimeMillis();
// 查询数据库,找出大于当前系统时间、类型相等的笔记的记录
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
new String[] { String.valueOf(currentDate) },
null);
// 当查询结果不为空时
if (c != null) {
// 如果有符合要求的记录,就遍历每一条记录
if (c.moveToFirst()) {
do {
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);
AlarmManager alermManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
} while (c.moveToNext());
}
c.close();
}
}
}

@ -0,0 +1,32 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.BroadcastReceiver;//广播接收器
import android.content.Context;
import android.content.Intent;
public class AlarmReceiver extends BroadcastReceiver { // 继承BroadcastReceiver类,用于接收广播,并且在接收到广播后启动AlarmAlertActivity
@Override
public void onReceive(Context context, Intent intent) {
intent.setClass(context, AlarmAlertActivity.class);// 设置intent的类为AlarmAlertActivity,可以用于启动Activity
// 为intent对象添加一个标志表示它将启动一个新的任务栈
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);// 启动Activity
}
}

@ -0,0 +1,93 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.Context;
import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
// 指定每个列表项的布局模板指定Cursor中的每个字段应该绑定到那些视图上
// 以文件夹的形式展现给用户
public class FoldersListAdapter extends CursorAdapter {
// 指定查询时返回的列NoteColumns是一个接口
public static final String[] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
};
// 定义查询文件夹表是返回的列的索引
public static final int ID_COLUMN = 0;
public static final int NAME_COLUMN = 1;
// 在列表视图中显示文件夹数据
public FoldersListAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
// 创建一个新视图,并初始化子标签
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new FolderListItem(context);// 返回一个FolderListItem对象该对象继承自LinearLayout用于显示文件夹名称
}
// 用于绑定视图和数据
@Override
public void bindView(View view, Context context, Cursor cursor) {
// 判断视图对象是否为 FolderListItem 的实例
if (view instanceof FolderListItem) {
String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);// 获取文件夹名称,如果是根文件夹,则显示“上一级”,否则显示文件夹名称
((FolderListItem) view).bind(folderName);// 将获取到的文件夹名称设置到FolderListItem对象中
}
}
// 获取对应文件夹名称
public String getFolderName(Context context, int position) {
Cursor cursor = (Cursor) getItem(position);
// 根据文件夹id获取文件夹的名称
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
}
// 用于显示文件夹名称
private class FolderListItem extends LinearLayout {// 继承自LinearLayout用于显示文件夹名称该类只有一个TextView对象
private TextView mName;// 用于显示文件夹名称该类只有一个TextView对象
public FolderListItem(Context context) {// 构造函数
super(context);
// 将布局文件加载到当前视图
inflate(context, R.layout.folder_list_item, this);
// 将获取到的TextView对象赋值给mName
mName = (TextView) findViewById(R.id.tv_folder_name);
}
// 将给定的名称设置到mName中
public void bind(String name) {
mName.setText(name);
}
}
}

@ -71,7 +71,6 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener {
// 头部视图空间
@ -176,7 +175,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
/**
* Current activity may be killed when the memory is low. Once it is killed, for another time
* Current activity may be killed when the memory is low. Once it is killed, for
* another time
* user load this activity, we should restore the former state
*/
// 为防止内存不足时程序的终止,在这里有一个保存现场的函数
@ -200,12 +200,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
// 用于返回活动初始化状态
private boolean initActivityState(Intent intent) {
private boolean initActivityState(Intent intent) { // 这是一个初始化活动状态的函数, 用于在活动创建时执行一些操作
/**
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with
* id,
* then jump to the NotesListActivity
*/
mWorkingNote = null;
mWorkingNote = null; // 将mWorkingNote置空
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
mUserQuery = "";
@ -221,7 +222,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
// 如果在内容提供者中noteId对应的笔记不可见或者不是笔记类型
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
Intent jump = new Intent(this, NotesListActivity.class);
//程序将跳转到上面声明的intent——jump
// 程序将跳转到上面声明的intent——jump
startActivity(jump);
showToast(R.string.error_note_not_exist);
finish();
@ -240,7 +241,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
} else if (TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) { // 如果用户指定的动作为Intent.ACTION_INSERT_OR_EDIT
// New note
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
@ -305,14 +306,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
switchToListMode(mWorkingNote.getContent());
} else {
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
mNoteEditor.setSelection(mNoteEditor.getText().length());
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery)); // 设置笔记编辑器的文字
mNoteEditor.setSelection(mNoteEditor.getText().length());// 设置光标位置
}
for (Integer id : sBgSelectorSelectionMap.keySet()) {
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);
findViewById(sBgSelectorSelectionMap.get(id)).setVisibility(View.GONE);// 设置背景选择器不可见
}
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId()); // 设置标题背景
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());// 设置笔记编辑器的背景
mNoteHeaderHolder.tvModified.setText(DateUtils.formatDateTime(this,
mWorkingNote.getModifiedDate(), DateUtils.FORMAT_SHOW_DATE
@ -320,7 +321,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
| DateUtils.FORMAT_SHOW_YEAR));
/**
* TODO: Add the menu for setting alert. Currently disable it because the DateTimePicker
* TODO: Add the menu for setting alert. Currently disable it because the
* DateTimePicker
* is not ready
*/
showAlertHeader();
@ -345,7 +347,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
// 如果当前的笔记没有闹钟提醒,就将警告日期文本和警告图标设置为不可见
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
};
}
;
}
@Override
@ -355,15 +358,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
@Override
protected void onSaveInstanceState(Bundle outState) {
protected void onSaveInstanceState(Bundle outState) {// 保存当前的工作笔记的id
super.onSaveInstanceState(outState);
/**
* For new note without note id, we should firstly save it to
* generate a id. If the editing note is not worth saving, there
* is no id which is equivalent to create new note
*/
//在创建一个新的标签时,先在数据库中匹配
//如果不存在,那么先在数据库中存储
// 在创建一个新的标签时,先在数据库中匹配
// 如果不存在,那么先在数据库中存储
if (!mWorkingNote.existInDatabase()) {
saveNote();
}
@ -371,7 +374,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
}
//用于分发触摸事件到合适的视图中
// 用于分发触摸事件到合适的视图中
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// 判断当前笔记的颜色选择器在屏幕上是否可见,且在可触控范围内
@ -392,7 +395,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
// 对屏幕触控的坐标进行操作
private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2];
int[] location = new int[2];
view.getLocationOnScreen(location);
int x = location[0];
int y = location[1];
@ -406,7 +409,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
//对标签各项属性内容的初始化
// 对标签各项属性内容的初始化
private void initResources() {
mHeadViewPanel = findViewById(R.id.note_title);
mNoteHeaderHolder = new HeadViewHolder();
@ -423,12 +426,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
iv.setOnClickListener(this);
}
//对字体大小的选择
// 对字体大小的选择
mFontSizeSelector = findViewById(R.id.font_size_selector);
for (int id : sFontSizeBtnsMap.keySet()) {
View view = findViewById(id);
view.setOnClickListener(this);
};
}
;
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
/**
@ -436,7 +440,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
if (mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
}
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
@ -446,7 +450,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
protected void onPause() {
super.onPause();
// 尝试保存当前笔记数据,并判断是否保持成功
if(saveNote()) {
if (saveNote()) {
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
}
// 清除一些设置状态
@ -481,7 +485,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
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);
@ -506,7 +510,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
// 当按下返回键时执行操作
@Override
public void onBackPressed() {
if(clearSettingState()) {
if (clearSettingState()) {
return;
}
@ -602,8 +606,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
break;
case R.id.menu_list_mode:
// 根据当前笔记是否是清单模式,切换到相反的模式,并更新笔记的清单模式属性
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
TextNote.MODE_CHECK_LIST : 0);
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ? TextNote.MODE_CHECK_LIST : 0);
break;
case R.id.menu_share:
getWorkingText();
@ -635,7 +638,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
// 根据用户选择的日期时间,设置当前笔记的提醒日期,并更新数据库
public void OnDateTimeSet(AlertDialog dialog, long date) {
mWorkingNote.setAlertDate(date , true);
mWorkingNote.setAlertDate(date, true);
}
});
// 显示对话框,让用户选择一个日期时间
@ -720,7 +723,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
showAlertHeader();
// 判断是否设置提醒
if(!set) {
if (!set) {
// 取消之前设置的闹钟
alarmManager.cancel(pendingIntent);
} else {
@ -756,7 +759,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mEditTextList.removeViewAt(index);
NoteEditText edit = null;
if(index == 0) {
if (index == 0) {
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
R.id.et_edit_text);
} else {
@ -769,7 +772,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit.setSelection(length);
}
/*
/*
*
*
*
*/
@ -777,7 +781,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
/**
* Should not happen, check for debug
*/
if(index > mEditTextList.getChildCount()) {
if (index > mEditTextList.getChildCount()) {
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
}
@ -798,7 +802,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
String[] items = text.split("\n");
int index = 0;
for (String item : items) {
if(!TextUtils.isEmpty(item)) {
if (!TextUtils.isEmpty(item)) {
mEditTextList.addView(getListItem(item, index));
index++;
}
@ -820,7 +824,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
while (m.find(start)) {
spannable.setSpan(
new BackgroundColorSpan(this.getResources().getColor(
R.color.user_query_highlight)), m.start(), m.end(),
R.color.user_query_highlight)),
m.start(), m.end(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
start = m.end();
}
@ -866,7 +871,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
Log.e(TAG, "Wrong index, should not happen");
return;
}
if(hasText) {
if (hasText) {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
} else {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);

@ -0,0 +1,233 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.Context;
import android.graphics.Rect;
import android.text.Layout;
import android.text.Selection;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.URLSpan;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ContextMenu;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.MotionEvent;
import android.widget.EditText;
import net.micode.notes.R;
import java.util.HashMap;
import java.util.Map;
// 继承EditText设置标签设置文本框
public class NoteEditText extends EditText {
private static final String TAG = "NoteEditText";
private int mIndex;
private int mSelectionStartBeforeDelete;
private static final String SCHEME_TEL = "tel:";
private static final String SCHEME_HTTP = "http:";
private static final String SCHEME_EMAIL = "mailto:";
// 建立一个字符和整数的hash表用于链接电话网站还有邮箱
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
static {
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
sSchemaActionResMap.put(SCHEME_HTTP, R.string.note_link_web);
sSchemaActionResMap.put(SCHEME_EMAIL, R.string.note_link_email);
}
/**
* Call by the {@link NoteEditActivity} to delete or add edit text
*/
// 在NoteEditActivity中删除或添加文本的操作可以看做是一个文本是否被变的标记
public interface OnTextViewChangeListener {
/**
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens
* and the text is null
*/
void onEditTextDelete(int index, String text);
/**
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER}
* happen
*/
void onEditTextEnter(int index, String text);
/**
* Hide or show item option when text change
*/
void onTextChange(int index, boolean hasText);
}
private OnTextViewChangeListener mOnTextViewChangeListener;
// 根据context设置文本
public NoteEditText(Context context) {
super(context, null);
mIndex = 0;
}
// 设置当前光标
public void setIndex(int index) {
mIndex = index;
}
// 初始化文本修改标记
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
mOnTextViewChangeListener = listener;
}
// 初始化便签
public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle);
}
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
// 根据用户触摸的位置,获取对应的文本偏移量,并设置为选择状态。
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
int x = (int) event.getX();
int y = (int) event.getY();
x -= getTotalPaddingLeft();
y -= getTotalPaddingTop();
x += getScrollX();
y += getScrollY();
Layout layout = getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);
Selection.setSelection(getText(), off);
break;
}
return super.onTouchEvent(event);
}
// 处理用户按下一个键盘按键时会触发 的事件
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
if (mOnTextViewChangeListener != null) {
return false;
}
break;
case KeyEvent.KEYCODE_DEL:
mSelectionStartBeforeDelete = getSelectionStart();
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
// 处理用户松开一个键盘按键时会触发 的事件
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_DEL:
// 如果被修改过
if (mOnTextViewChangeListener != null) {
// 如果被修改过且文档不为空
if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
return true;
}
} else {
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
case KeyEvent.KEYCODE_ENTER:
if (mOnTextViewChangeListener != null) {
int selectionStart = getSelectionStart();
String text = getText().subSequence(selectionStart, length()).toString();
setText(getText().subSequence(0, selectionStart));
mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text);
} else {
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
default:
break;
}
return super.onKeyUp(keyCode, event);
}
// 当焦点发生变化时,会自动调用该方法来处理焦点改变的事件
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (mOnTextViewChangeListener != null) {
// 获取到焦点并且文本不为空
if (!focused && TextUtils.isEmpty(getText())) {
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
mOnTextViewChangeListener.onTextChange(mIndex, true);
}
}
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
// 生成上下文菜单
@Override
protected void onCreateContextMenu(ContextMenu menu) {
// 如果有文本存在
if (getText() instanceof Spanned) {
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
int min = Math.min(selStart, selEnd);
int max = Math.max(selStart, selEnd);
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
if (urls.length == 1) {
int defaultResId = 0;
for (String schema : sSchemaActionResMap.keySet()) {
if (urls[0].getURL().indexOf(schema) >= 0) {
defaultResId = sSchemaActionResMap.get(schema);
break;
}
}
if (defaultResId == 0) {
defaultResId = R.string.note_link_other;
}
// 建立菜单
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// goto a new intent
urls[0].onClick(NoteEditText.this);
return true;
}
});
}
}
super.onCreateContextMenu(menu);
}
}

@ -115,7 +115,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private long mCurrentFolderId;
private ContentResolver mContentResolver;
private ContentResolver mContentResolver;// 用于操作数据库
private ModeCallback mModeCallBack;
@ -123,14 +123,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
private NoteItemData mFocusNoteDataItem;
private NoteItemData mFocusNoteDataItem;// 当前选中的item
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";// 是否是文件夹
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
+ NoteColumns.NOTES_COUNT + ">0)";
+ NoteColumns.NOTES_COUNT + ">0)";// 是否是根目录,根目录下的文件夹和文件,以及通话记录文件夹
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
@ -167,7 +167,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
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);
@ -180,7 +180,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
e.printStackTrace();
return;
} finally {
if(in != null) {
if (in != null) {
try {
in.close();
} catch (IOException e) {
@ -258,7 +258,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mDropDownMenu = new DropdownMenu(NotesListActivity.this,
(Button) customView.findViewById(R.id.selection_menu),
R.menu.note_list_dropdown);
mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener(){
mDropDownMenu.setOnDropdownMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
mNotesListAdapter.selectAll(!mNotesListAdapter.isAllSelected());
updateMenu();
@ -337,7 +337,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
builder.show();
break;
case R.id.move:
startQueryDestinationFolders();
startQueryDestinationFolders();// 是否需要查询,如果不需要,直接调用startMove
break;
default:
return false;
@ -346,7 +346,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
private class NewNoteOnTouchListener implements OnTouchListener {
private class NewNoteOnTouchListener implements OnTouchListener {// 为了解决点击新建按钮时,点击到下面的item的问题
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
@ -408,7 +408,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
};
private void startAsyncNotesListQuery() {
private void startAsyncNotesListQuery() {// 查询数据,并显示
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
@ -417,7 +417,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
private final class BackgroundQueryHandler extends AsyncQueryHandler {
private final class BackgroundQueryHandler extends AsyncQueryHandler {// 异步查询
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
}
@ -449,7 +449,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
public void onClick(DialogInterface dialog, int which) {
DataUtils.batchMoveToFolder(mContentResolver,
mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));
mNotesListAdapter.getSelectedItemIds(), adapter.getItemId(which));// 为了能够在子文件夹中移动便签,这里需要使用adapter.getItemId(which)而不是which
Toast.makeText(
NotesListActivity.this,
getString(R.string.format_move_notes_to_folder,
@ -469,7 +469,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
private void batchDelete() {
private void batchDelete() {// 批量删除,这里的删除是指移动到回收站
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
@ -506,7 +506,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
private void deleteFolder(long folderId) {
private void deleteFolder(long folderId) {// 删除文件夹
if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
return;
@ -579,7 +579,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
private void showCreateOrModifyFolderDialog(final boolean create) {
private void showCreateOrModifyFolderDialog(final boolean create) {// 创建或修改文件夹
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
final EditText etName = (EditText) view.findViewById(R.id.et_foler_name);
@ -605,7 +605,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
final Dialog dialog = builder.setView(view).show();
final Button positive = (Button)dialog.findViewById(android.R.id.button1);
final Button positive = (Button) dialog.findViewById(android.R.id.button1);
positive.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
hideSoftInput(etName);
@ -623,7 +623,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
values.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
mContentResolver.update(Notes.CONTENT_NOTE_URI, values, NoteColumns.ID
+ "=?", new String[] {
+ "=?",
new String[] {
String.valueOf(mFocusNoteDataItem.getId())
});
}
@ -727,7 +728,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
@Override
public boolean onContextItemSelected(MenuItem item) {
public boolean onContextItemSelected(MenuItem item) {// 为了解决长按菜单无法弹出的问题将此方法改为public
if (mFocusNoteDataItem == null) {
Log.e(TAG, "The long click data item is null");
return false;
@ -761,7 +762,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
public boolean onPrepareOptionsMenu(Menu menu) {// 是否显示,显示后的操作
menu.clear();
if (mState == ListEditState.NOTE_LIST) {
getMenuInflater().inflate(R.menu.note_list, menu);
@ -779,7 +780,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
public boolean onOptionsItemSelected(MenuItem item) {// 是否选中,选中后的操作
switch (item.getItemId()) {
case R.id.menu_new_folder: {
showCreateOrModifyFolderDialog(true);
@ -824,7 +825,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
private void exportNoteToText() {
private void exportNoteToText() {// 是否有SD卡是否有权限
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
new AsyncTask<Void, Void, Integer>() {
@ -849,7 +850,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
.getString(R.string.success_sdcard_export));
builder.setMessage(NotesListActivity.this.getString(
R.string.format_exported_file_location, backup
.getExportedTextFileName(), backup.getExportedTextFileDir()));
.getExportedTextFileName(),
backup.getExportedTextFileDir()));
builder.setPositiveButton(android.R.string.ok, null);
builder.show();
} else if (result == BackupUtils.STATE_SYSTEM_ERROR) {
@ -866,17 +868,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
private boolean isSyncMode() {
private boolean isSyncMode() {// 是否同步模式
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
private void startPreferenceActivity() {
private void startPreferenceActivity() {// 启动设置界面
Activity from = getParent() != null ? getParent() : this;
Intent intent = new Intent(from, NotesPreferenceActivity.class);
from.startActivityIfNeeded(intent, -1);
}
private class OnListItemClickListener implements OnItemClickListener {
private class OnListItemClickListener implements OnItemClickListener {// 列表点击事件
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
@ -917,10 +919,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
private void startQueryDestinationFolders() {
private void startQueryDestinationFolders() {// 查询目标文件夹,用于移动笔记,复制笔记,删除笔记
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
selection = (mState == ListEditState.NOTE_LIST) ? selection:
"(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";
selection = (mState == ListEditState.NOTE_LIST) ? selection
: "(" + selection + ") OR (" + NoteColumns.ID + "=" + Notes.ID_ROOT_FOLDER + ")";// 如果是笔记列表,则不显示根目录,如果是子文件夹,则显示根目录,用于移动笔记
mBackgroundQueryHandler.startQuery(FOLDER_LIST_QUERY_TOKEN,
null,
@ -932,10 +934,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
String.valueOf(Notes.ID_TRASH_FOLER),
String.valueOf(mCurrentFolderId)
},
NoteColumns.MODIFIED_DATE + " DESC");
NoteColumns.MODIFIED_DATE + " DESC");// 查询文件夹列表,按修改时间排序,最近修改的排在最前面
}
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {// 长按进入多选模式
if (view instanceof NotesListItem) {
mFocusNoteDataItem = ((NotesListItem) view).getItemData();
if (mFocusNoteDataItem.getType() == Notes.TYPE_NOTE && !mNotesListAdapter.isInChoiceMode()) {

@ -0,0 +1,197 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import net.micode.notes.data.Notes;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
// 用于创建笔记应用的列表适配器
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
private Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex;
private int mNotesCount;
private boolean mChoiceMode;
public static class AppWidgetAttribute {
public int widgetId;
public int widgetType;
};
public NotesListAdapter(Context context) {
super(context, null);
mSelectedIndex = new HashMap<Integer, Boolean>();
mContext = context;
mNotesCount = 0;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
// 用于绑定视图和数据
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) {
NoteItemData itemData = new NoteItemData(context, cursor);
((NotesListItem) view).bind(context, itemData, mChoiceMode,
isSelectedItem(cursor.getPosition()));
}
}
// 设置勾选框,并更新视图
public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked);
notifyDataSetChanged();
}
// 判断单选按钮是否勾选
public boolean isInChoiceMode() {
return mChoiceMode;
}
// 设置单项选项框
public void setChoiceMode(boolean mode) {
mSelectedIndex.clear();
mChoiceMode = mode;
}
// 根据参数checked选择或取消选择所有的便签项
public void selectAll(boolean checked) {
Cursor cursor = getCursor();
for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) {
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
setCheckedItem(i, checked);
}
}
}
}
// 获取所有选中的项的id
public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>();// 创建一个HashSet对象,用于存放选中的项的id
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
Long id = getItemId(position);
if (id == Notes.ID_ROOT_FOLDER) {
Log.d(TAG, "Wrong item id, should not happen");
} else {
itemSet.add(id);
}
}
}
return itemSet;// 返回所有选中的项的id
}
// 获取所有选中的项的小部件属性
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
Cursor c = (Cursor) getItem(position);
if (c != null) {
AppWidgetAttribute widget = new AppWidgetAttribute();
NoteItemData item = new NoteItemData(mContext, c);
widget.widgetId = item.getWidgetId();
widget.widgetType = item.getWidgetType();
itemSet.add(widget);
/**
* Don't close cursor here, only the adapter could close it
*/
} else {
Log.e(TAG, "Invalid cursor");
return null;
}
}
}
return itemSet;
}
// 获取选中的项的数量,并返回一个整数。
public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values();
if (null == values) {
return 0;
}
Iterator<Boolean> iter = values.iterator();
int count = 0;
while (iter.hasNext()) {
if (true == iter.next()) {
count++;
}
}
return count;
}
// 判断是否所有项都被选中
public boolean isAllSelected() {
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);
}
// 判断是否被选中
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
return false;
}
return mSelectedIndex.get(position);
}
// 内容发生变化时,重新计算便签数量
@Override
protected void onContentChanged() {
super.onContentChanged();
calcNotesCount();
}
// 光标发生变动时,回调该函数计算便签数量
@Override
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
calcNotesCount();
}
// 计算便签数量
private void calcNotesCount() {
mNotesCount = 0;
for (int i = 0; i < getCount(); i++) {
Cursor c = (Cursor) getItem(i);
if (c != null) {
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
mNotesCount++;
}
} else {
Log.e(TAG, "Invalid cursor");
return;
}
}
}
}

@ -0,0 +1,413 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.ActionBar;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
public class NotesPreferenceActivity extends PreferenceActivity {
public static final String PREFERENCE_NAME = "notes_preferences";
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
private static final String AUTHORITIES_FILTER_KEY = "authorities";
private PreferenceCategory mAccountCategory;
private GTaskReceiver mReceiver;
private Account[] mOriAccounts;
private boolean mHasAddedAccount;
// 在活动创建时执行一些初始化操作
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
/* using the app icon for navigation */
getActionBar().setDisplayHomeAsUpEnabled(true);
// 从xml文件中加载活动的偏好设置
addPreferencesFromResource(R.xml.preferences);
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
mReceiver = new GTaskReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
registerReceiver(mReceiver, filter);
mOriAccounts = null;
// 从xml文件中加载了一个视图并赋值给header这个局部变量
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
// 将这个视图添加到列表的头部
getListView().addHeaderView(header, null, true);
}
@Override
protected void onResume() {
super.onResume();
// need to set sync account automatically if user has added a new
// account
if (mHasAddedAccount) {
Account[] accounts = getGoogleAccounts();
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
for (Account accountNew : accounts) {
boolean found = false;
for (Account accountOld : mOriAccounts) {
if (TextUtils.equals(accountOld.name, accountNew.name)) {
found = true;
break;
}
}
if (!found) {
setSyncAccount(accountNew.name);
break;
}
}
}
}
// 刷新用户界面
refreshUI();
}
// 在活动销毁时执行一些清理操作
@Override
protected void onDestroy() {
if (mReceiver != null) {
unregisterReceiver(mReceiver);
}
super.onDestroy();
}
// 加载账户相关的偏好设置
private void loadAccountPreference() {
mAccountCategory.removeAll();
Preference accountPref = new Preference(this);
final String defaultAccount = getSyncAccountName(this);
accountPref.setTitle(getString(R.string.preferences_account_title));
accountPref.setSummary(getString(R.string.preferences_account_summary));
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
if (!GTaskSyncService.isSyncing()) {
if (TextUtils.isEmpty(defaultAccount)) {
// the first time to set account
showSelectAccountAlertDialog();
} else {
// if the account has already been set, we need to promp
// user about the risk
showChangeAccountConfirmAlertDialog();
}
} else {
Toast.makeText(NotesPreferenceActivity.this,
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
.show();
}
return true;
}
});
mAccountCategory.addPreference(accountPref);
}
// 加载同步按钮和同步状态的显示
private void loadSyncButton() {
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
// set button state
if (GTaskSyncService.isSyncing()) {
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
syncButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
}
});
} else {
syncButton.setText(getString(R.string.preferences_button_sync_immediately));
syncButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
GTaskSyncService.startSync(NotesPreferenceActivity.this);
}
});
}
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
// set last sync time
if (GTaskSyncService.isSyncing()) {
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
lastSyncTimeView.setVisibility(View.VISIBLE);
} else {
long lastSyncTime = getLastSyncTime(this);
if (lastSyncTime != 0) {
lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
DateFormat.format(getString(R.string.preferences_last_sync_time_format),
lastSyncTime)));
lastSyncTimeView.setVisibility(View.VISIBLE);
} else {
lastSyncTimeView.setVisibility(View.GONE);
}
}
}
// 刷新界面
private void refreshUI() {
loadAccountPreference();
loadSyncButton();
}
// 显示账户选择的对话框并进行账户的设置
private void showSelectAccountAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
// 设置标题以及子标题内容
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));
// 设置对话框的自定义标题
dialogBuilder.setCustomTitle(titleView);
dialogBuilder.setPositiveButton(null, null);
// 获取同步账户信息
Account[] accounts = getGoogleAccounts();
String defAccount = getSyncAccountName(this);
mOriAccounts = accounts;
mHasAddedAccount = false;
// 如果账户不为空
if (accounts.length > 0) {
CharSequence[] items = new CharSequence[accounts.length];
final CharSequence[] itemMapping = items;
int checkedItem = -1;
int index = 0;
for (Account account : accounts) {
if (TextUtils.equals(account.name, defAccount)) {
checkedItem = index;
}
items[index++] = account.name;
}
// 在对话框建立一个单选的复选框
dialogBuilder.setSingleChoiceItems(items, checkedItem,
new DialogInterface.OnClickListener() {
// 设置点击后执行的事件,包括检录新同步账户和刷新标签界面
public void onClick(DialogInterface dialog, int which) {
setSyncAccount(itemMapping[which].toString());
dialog.dismiss();
refreshUI();
}
});
}
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
dialogBuilder.setView(addAccountView);
final AlertDialog dialog = dialogBuilder.show();
addAccountView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mHasAddedAccount = true;
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
"gmail-ls"
});
startActivityForResult(intent, -1);
dialog.dismiss();
}
});
}
// 显示一个更改账户的确认对话框
private void showChangeAccountConfirmAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
// 根据同步修改的账户信息设置标题以及子标题的内容
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
getSyncAccountName(this)));
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
// 设置对话框的自定义标题
dialogBuilder.setCustomTitle(titleView);
CharSequence[] menuItemArray = new CharSequence[] {
getString(R.string.preferences_menu_change_account),
getString(R.string.preferences_menu_remove_account),
getString(R.string.preferences_menu_cancel)
};
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
showSelectAccountAlertDialog();
} else if (which == 1) {
removeSyncAccount();
refreshUI();
}
}
});
dialogBuilder.show();
}
// 获取谷歌账户
private Account[] getGoogleAccounts() {
AccountManager accountManager = AccountManager.get(this);
return accountManager.getAccountsByType("com.google");
}
// 设置同步账户
private void setSyncAccount(String account) {
if (!getSyncAccountName(this).equals(account)) {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
if (account != null) {
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
} else {
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
editor.commit();
// clean up last sync time
setLastSyncTime(this, 0);
// clean up local gtask related info
new Thread(new Runnable() {
public void run() {
ContentValues values = new ContentValues();
values.put(NoteColumns.GTASK_ID, "");
values.put(NoteColumns.SYNC_ID, 0);
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
}
}).start();
Toast.makeText(NotesPreferenceActivity.this,
getString(R.string.preferences_toast_success_set_accout, account),
Toast.LENGTH_SHORT).show();
}
}
// 删除同步账户
private void removeSyncAccount() {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
}
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
editor.remove(PREFERENCE_LAST_SYNC_TIME);
}
editor.commit();
// clean up local gtask related info
new Thread(new Runnable() {
public void run() {
ContentValues values = new ContentValues();
values.put(NoteColumns.GTASK_ID, "");
values.put(NoteColumns.SYNC_ID, 0);
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
}
}).start();
}
// 获取同步账户名称
public static String getSyncAccountName(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
// 设置最终同步时间
public static void setLastSyncTime(Context context, long time) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
editor.commit();
}
// 获取最终同步时间
public static long getLastSyncTime(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
}
// 接收同步状态和信息
private class GTaskReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
refreshUI();
if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) {
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
syncStatus.setText(intent
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
}
}
}
// 处理菜单选项
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(this, NotesListActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
default:
return false;
}
}
}

@ -21,9 +21,9 @@ import android.net.Uri;
public class Notes { // 定义类,给模块的其他类提供变量定义
public static final String AUTHORITY = "micode_notes"; // 设置AUTHORITY
public static final String TAG = "Notes"; // 设置TAG
public static final int TYPE_NOTE = 0;
public static final int TYPE_FOLDER = 1;
public static final int TYPE_SYSTEM = 2;
public static final int TYPE_NOTE = 0; // 设置便签类型
public static final int TYPE_FOLDER = 1; // 设置文件夹类型
public static final int TYPE_SYSTEM = 2; // 设置系统类型
/**
* Following IDs are system folders' identifiers
@ -31,10 +31,10 @@ public class Notes { // 定义类,给模块的其他类提供变量定义
* {@link Notes#ID_TEMPARAY_FOLDER } is for notes belonging no folder
* {@link Notes#ID_CALL_RECORD_FOLDER} is to store call records
*/
public static final int ID_ROOT_FOLDER = 0;
public static final int ID_TEMPARAY_FOLDER = -1;
public static final int ID_CALL_RECORD_FOLDER = -2;
public static final int ID_TRASH_FOLER = -3;
public static final int ID_ROOT_FOLDER = 0;// 根文件夹
public static final int ID_TEMPARAY_FOLDER = -1;// 临时文件夹
public static final int ID_CALL_RECORD_FOLDER = -2;// 通话记录文件夹
public static final int ID_TRASH_FOLER = -3; // 垃圾箱
public static final String INTENT_EXTRA_ALERT_DATE = "net.micode.notes.alert_date";// 设置提醒日期
public static final String INTENT_EXTRA_BACKGROUND_ID = "net.micode.notes.background_color_id";
@ -216,7 +216,7 @@ public class Notes { // 定义类,给模块的其他类提供变量定义
* Type : BLOB
* </P>
*/
public static final String PICTURE = "picture"; // 图片****
public static final String PICTURE = "picture"; // 图片路径****
}

@ -60,10 +60,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper { // 该类为便签SQ
NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.LOCKED + " INTEGER NOT NULL DEFAULT 0" +
NoteColumns.PICTURE_URI + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.LOCKED + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.PICTURE + " TEXT NOT NULL DEFAULT ''" +
")";

@ -0,0 +1,255 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
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"; // 设置TAG为Note
/**
* Create a new note id for adding a new note to databases
*/
public static synchronized long getNewNoteId(Context context, long folderId) { // 为一个新的便签创建id返回数据库
// Create a new note in the database
ContentValues values = new ContentValues(); // 用于保存创建日期等字段的值
long createdTime = System.currentTimeMillis(); // 获取创建时间
values.put(NoteColumns.CREATED_DATE, createdTime);
values.put(NoteColumns.MODIFIED_DATE, createdTime);
values.put(NoteColumns.TYPE, Notes.TYPE_NOTE); // 设置便签类型为便签
values.put(NoteColumns.LOCAL_MODIFIED, 1);
values.put(NoteColumns.PARENT_ID, folderId);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); // 将values插入数据库中并返回uri
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1)); // 解析uri获取新笔记id
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString()); // 解析失败日志
noteId = 0;
}
if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId); // 获取id出错抛出异常
}
return noteId;
}
public Note() {
mNoteDiffValues = new ContentValues(); // 创建新对象
mNoteData = new NoteData(); // 创建新对象
}
public void setNoteValue(String key, String value) { // 设置便签的值
mNoteDiffValues.put(key, value); // key为属性values为新值
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); // 本地修改标识为1标识被修改
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); // 表示修改时间,用于服务器时间比较
}
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value); // 添加键值对
} // 设置文本数据
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
} // 设置文本数据id
public long getTextDataId() {
return mNoteData.mTextDataId;
} // 获取文本数据id
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
} // 设置通讯数据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
* note data info
*/
if (context.getContentResolver().update( // 打包并同步
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null,
null) == 0) {
Log.e(TAG, "Update note error, should not happen");
// 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;
} // 检查便签是否再本地修改
void setTextDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0");
}
mTextDataId = id;
} // 设置便签文本标识符
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0");
}
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) { // 将文本数据与通讯数据添加到context
/**
* Check for safety
*/
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId); // 抛出异常
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null;
if (mTextDataValues.size() > 0) { // 检查文本数据
mTextDataValues.put(DataColumns.NOTE_ID, noteId); // 将便签id与数据值相关联
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); // 并将键值对添加到mTextDataValues中
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues); // 插入新的数据行保存返回的uri
try {
setTextDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new text data fail with noteId" + noteId); // 异常日志
mTextDataValues.clear();
return null;
}
} else { // 表示需要更新现有数据行
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId));
builder.withValues(mTextDataValues);
operationList.add(builder.build());
}
mTextDataValues.clear(); // 清空mTextDataValues
}
if (mCallDataValues.size() > 0) { // 检查通讯数据,代码内容功能同上
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) {
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues);
try {
setCallDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new call data fail with noteId" + noteId);
mCallDataValues.clear();
return null;
}
} else {
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mCallDataId));
builder.withValues(mCallDataValues);
operationList.add(builder.build());
}
mCallDataValues.clear();
}
if (operationList.size() > 0) { // 检查operationList对载入的操作进行批量提交
try {
ContentProviderResult[] results = context.getContentResolver().applyBatch(
Notes.AUTHORITY, operationList);
return (results == null || results.length == 0 || results[0] == null) ? null
: ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId);
} catch (RemoteException 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()));
return null;
}
}
return null;
}
}
}

@ -0,0 +1,2 @@
#Sun Jun 04 20:08:15 HKT 2023
gradle.version=7.5

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="11" />
</component>
</project>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<targetSelectedWithDropDown>
<Target>
<type value="QUICK_BOOT_TARGET" />
<deviceKey>
<Key>
<type value="VIRTUAL_DEVICE_PATH" />
<value value="C:\Users\82590\.android\avd\Pixel_6_Pro_API_28_1.avd" />
</Key>
</deviceKey>
</Target>
</targetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-06-03T16:26:33.294608400Z" />
</component>
</project>

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>

@ -0,0 +1,11 @@
s
java:S4144Æ"\Update this method so that its implementation is not identical to "getParentId" on line 190.(ø¦¯ÿ
>
java:S1125X"(Remove the unnecessary boolean literals.(ú«€É
m
java:S3776u"RRefactor this method to reduce its Cognitive Complexity from 18 to the 15 allowed.(Ñý¨úýÿÿÿÿ
C
java:S1125v"(Remove the unnecessary boolean literals.(¢´—Öÿÿÿÿÿ
>
java:S1125w"(Remove the unnecessary boolean literals.(ãêÛì

@ -0,0 +1,39 @@
t
java:S22931"YReplace the type specification in this constructor call with the diamond operator ("<>").(àÉ™âùÿÿÿÿ
o
java:S2293d"YReplace the type specification in this constructor call with the diamond operator ("<>").(œ€ÄÑ
o
java:S2293u"YReplace the type specification in this constructor call with the diamond operator ("<>").(¾<>Ȫ
J
java:S1066["/Merge this if statement with the enclosing one.(ßÚ§µúÿÿÿÿ
ˆ
java:S1319c"mThe return type of this method should be an interface such as "Set" rather than the implementation "HashSet".(“Ÿóßûÿÿÿÿ
ˆ
java:S1319t"mThe return type of this method should be an interface such as "Set" rather than the implementation "HashSet".(•Ñòóýÿÿÿÿ
j
java:S1104+"TMake widgetId a static final constant or non-public and provide accessors if needed.(åÇŽ<C387>
q
java:S1104,"VMake widgetType a static final constant or non-public and provide accessors if needed.(ö漬þÿÿÿÿ
C
java:S5411f"(Use a primitive boolean expression here.(ɯÀÐüÿÿÿÿ
C
java:S5411w"(Use a primitive boolean expression here.(ɯÀÐüÿÿÿÿ
D
java:S5411"(Use a primitive boolean expression here.( „Œ¢ùÿÿÿÿ
7
java:S1116-"Remove this empty statement.(ôŸŽìúÿÿÿÿ
D
java:S18740".Remove this use of "<init>"; it is deprecated.(ÌÖçü
J
java:S2864e"4Iterate over the "entrySet" instead of the "keySet".(਷â
B
java:S1125f"'Remove the unnecessary boolean literal.(ɯÀÐüÿÿÿÿ
J
java:S2864v"4Iterate over the "entrySet" instead of the "keySet".(਷â
B
java:S1125w"'Remove the unnecessary boolean literal.(ɯÀÐüÿÿÿÿ
B
java:S1168"+Return an empty collection instead of null.(¥¹ï<C2B9>
C
java:S1125"'Remove the unnecessary boolean literal.( „Œ¢ùÿÿÿÿ

@ -0,0 +1,39 @@
t
java:S22932"YReplace the type specification in this constructor call with the diamond operator ("<>").(áºÐ»ûÿÿÿÿ
t
java:S2293\"YReplace the type specification in this constructor call with the diamond operator ("<>").(áºÐ»ûÿÿÿÿ
u
java:S2293Õ"YReplace the type specification in this constructor call with the diamond operator ("<>").(Ûª¡úÿÿÿÿ
b
java:S1192E"GDefine a constant instead of duplicating this literal "%s: %s" 4 times.(ÇÇ÷«ùÿÿÿÿ
c
java:S1192z"HDefine a constant instead of duplicating this literal "=? AND " 4 times.(„¼¹<C2BC>úÿÿÿÿ
K
java:S1066"/Merge this if statement with the enclosing one.(䲜¼øÿÿÿÿ
v
java:S1319("`The type of "ids" should be an interface such as "Set" rather than the implementation "HashSet".(îîè“
{
java:S1319U"`The type of "ids" should be an interface such as "Set" rather than the implementation "HashSet".(󆱋ÿÿÿÿÿ

java:S1319Ê"mThe return type of this method should be an interface such as "Set" rather than the implementation "HashSet".(ÛëÈðýÿÿÿÿ
Z
java:S2589g"8Remove this expression which always evaluates to "false"(Е¬Áùÿÿÿÿ8åÃ˦ˆ1
Z
java:S2589?"8Remove this expression which always evaluates to "false"(ÎŽŽéûÿÿÿÿ8æÃ˦ˆ1
O
java:S1118&":Add a private constructor to hide the implicit public one.(•ã P
T
java:S1155-">Use isEmpty() to check whether the collection is empty or not.(´¤”Ó
Z
java:S2147F"DCombine this catch with the one at line 68, which has the same body.(æš©›
b
java:S2147n"ECombine this catch with the one at line 108, which has the same body.(ˆúðþ8ÔÄ˦ˆ1
k
java:S3252ê"OUse static access with "net.micode.notes.data.Notes$DataColumns" for "NOTE_ID".(ž“ñ§ûÿÿÿÿ
m
java:S3252ê"QUse static access with "net.micode.notes.data.Notes$DataColumns" for "MIME_TYPE".(ž“ñ§ûÿÿÿÿ
m
java:S3252ý"OUse static access with "net.micode.notes.data.Notes$DataColumns" for "NOTE_ID".(²û‹Á8ÞÄ˦ˆ1
m
java:S3252þ"QUse static access with "net.micode.notes.data.Notes$DataColumns" for "MIME_TYPE".(±ðŒ“úÿÿÿÿ

@ -0,0 +1,14 @@
o
java:S22933"YReplace the type specification in this constructor call with the diamond operator ("<>").(§þ¢¾
D
java:S1604Ý"(Make this anonymous inner class a lambda(¯<>Àžÿÿÿÿÿ
f
java:S1301o"KReplace this "switch" statement by "if" statements to increase readability.(ãÁð™øÿÿÿÿ
M
java:S1135i"2Complete the task associated to this TODO comment.(ƒŠ® úÿÿÿÿ
< java:S131o""Add a default case to this switch.(ãÁð™øÿÿÿÿ
^
java:S1126º"BReplace this if-then-else statement by a single method invocation.(‚å¿¥ûÿÿÿÿ
P
java:S2864Ñ"4Iterate over the "entrySet" instead of the "keySet".(ΚŸ<C5A1>ûÿÿÿÿ

@ -0,0 +1,9 @@
m
java:S37766"RRefactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.(üßú–ùÿÿÿÿ
V
java:S1874F"9Remove this use of "setTextAppearance"; it is deprecated.(¤ñÝ×8„¿ªˆ1
V
java:S1874M"9Remove this use of "setTextAppearance"; it is deprecated.(Á†<C381>ö8…¿ªˆ1
V
java:S1874W"9Remove this use of "setTextAppearance"; it is deprecated.(¤ñÝ×8…¿ªˆ1

@ -0,0 +1,7 @@
:
java:S2386$"Make this member "protected".(±ê™–8Çõô¥ˆ1
K
java:S1874/".Remove this use of "<init>"; it is deprecated.(椱8Ðõô¥ˆ1
T
java:S11350"2Complete the task associated to this TODO comment.(ƒŠ® úÿÿÿÿ8Ðõô¥ˆ1

@ -0,0 +1,41 @@
d
4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f
7
gradlew,5\b\5bbfa66edb4db3c7c33c5181f43510990d3307f9
g
7app/src/main/java/net/micode/notes/ui/NoteEditText.java,5\0\503adcf2a0be1ecdb94a15efba4433b6589877b9
j
:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5
b
2app/src/main/java/net/micode/notes/model/Note.java,d\d\dd970bd8ce083850fca1d4d159647ccd110e57cb
i
9app/src/main/java/net/micode/notes/model/WorkingNote.java,8\7\876016634c6642b35109680ccac740dc8271b236
p
@app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java,1\e\1eb2363b523dbcae43d3c6e4790c64436af61b13
h
8app/src/main/java/net/micode/notes/ui/NotesListItem.java,5\d\5dfe6902d8ec740690f88d644e74362c3be08fad
r
Bapp/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java,d\a\da57ce446af85bbd9aefee65e969869f0cff78b0
f
6app/src/main/java/net/micode/notes/tool/DataUtils.java,3\2\32360bf24febc78f20db52498c7576b3d8650d56
k
;app/src/main/java/net/micode/notes/ui/NotesListAdapter.java,2\8\283f16cc23da56ca65616082bc810304d3511d0a
g
7app/src/main/java/net/micode/notes/ui/NoteItemData.java,0\8\08c35f02f11c35ae9ebf8db0a482054dfa1cf493
k
;app/src/main/java/net/micode/notes/ui/NoteEditActivity.java,5\7\577f30d26378ec8a2bd2e4a43f3c79b3f04c402c
b
2app/src/main/java/net/micode/notes/data/Notes.java,a\7\a7641cfac724321d508c2a284223a711011a93f5
P
app/src/main/AndroidManifest.xml,8\c\8c55c3ccc257e5907959013f99656e4c8ec3903e
<
build.gradle,f\0\f07866736216be0ee2aba49e392191aeae700a35
m
=app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java,f\9\f9f49497f95afd327db7a7a512612aa1089003d4
p
@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312
@
app/build.gradle,f\4\f4a01d6a4fcb971362ec00a83903fd3902f52164
l
<app/src/main/java/net/micode/notes/ui/NotesListActivity.java,a\d\ad72331a1bed265bb9c0fe838faa74dbf69fce32

@ -0,0 +1,41 @@
d
4app/src/main/java/net/micode/notes/data/Contact.java,9\a\9a3a19793537958b8b1b03a81985999e22705a2f
7
gradlew,5\b\5bbfa66edb4db3c7c33c5181f43510990d3307f9
g
7app/src/main/java/net/micode/notes/ui/NoteEditText.java,5\0\503adcf2a0be1ecdb94a15efba4433b6589877b9
j
:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5
b
2app/src/main/java/net/micode/notes/model/Note.java,d\d\dd970bd8ce083850fca1d4d159647ccd110e57cb
f
6app/src/main/java/net/micode/notes/tool/DataUtils.java,3\2\32360bf24febc78f20db52498c7576b3d8650d56
i
9app/src/main/java/net/micode/notes/model/WorkingNote.java,8\7\876016634c6642b35109680ccac740dc8271b236
p
@app/src/main/java/net/micode/notes/data/NotesDatabaseHelper.java,1\e\1eb2363b523dbcae43d3c6e4790c64436af61b13
r
Bapp/src/main/java/net/micode/notes/ui/NotesPreferenceActivity.java,d\a\da57ce446af85bbd9aefee65e969869f0cff78b0
h
8app/src/main/java/net/micode/notes/ui/NotesListItem.java,5\d\5dfe6902d8ec740690f88d644e74362c3be08fad
k
;app/src/main/java/net/micode/notes/ui/NotesListAdapter.java,2\8\283f16cc23da56ca65616082bc810304d3511d0a
g
7app/src/main/java/net/micode/notes/ui/NoteItemData.java,0\8\08c35f02f11c35ae9ebf8db0a482054dfa1cf493
k
;app/src/main/java/net/micode/notes/ui/NoteEditActivity.java,5\7\577f30d26378ec8a2bd2e4a43f3c79b3f04c402c
P
app/src/main/AndroidManifest.xml,8\c\8c55c3ccc257e5907959013f99656e4c8ec3903e
b
2app/src/main/java/net/micode/notes/data/Notes.java,a\7\a7641cfac724321d508c2a284223a711011a93f5
<
build.gradle,f\0\f07866736216be0ee2aba49e392191aeae700a35
m
=app/src/main/java/net/micode/notes/ui/FoldersListAdapter.java,f\9\f9f49497f95afd327db7a7a512612aa1089003d4
p
@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312
@
app/build.gradle,f\4\f4a01d6a4fcb971362ec00a83903fd3902f52164
l
<app/src/main/java/net/micode/notes/ui/NotesListActivity.java,a\d\ad72331a1bed265bb9c0fe838faa74dbf69fce32

@ -0,0 +1,24 @@
apply plugin: 'com.android.application'
android {
compileSdk 24
buildToolsVersion "33.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "net.micode.notes"
minSdkVersion 24
targetSdkVersion 24
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
implementation 'org.jetbrains:annotations:15.0'
implementation 'androidx.annotation:annotation-jvm:+'
}

@ -0,0 +1,12 @@
/**
* Automatically generated file. DO NOT MODIFY
*/
package net.micode.notes;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "net.micode.notes";
public static final String BUILD_TYPE = "debug";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "0.1";
}

@ -0,0 +1,2 @@
#- File Locator -
listingFile=../../../outputs/apk/debug/output-metadata.json

@ -0,0 +1,2 @@
appMetadataVersion=1.1
androidGradlePluginVersion=7.4.2

@ -0,0 +1,10 @@
{
"version": 3,
"artifactType": {
"type": "COMPATIBLE_SCREEN_MANIFEST",
"kind": "Directory"
},
"applicationId": "net.micode.notes",
"variantName": "debug",
"elements": []
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save