branch01
Liujing 8 months ago
commit 7cc40a0912

Binary file not shown.

@ -64,6 +64,6 @@
<style name="NoteActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions" />
<item name="android:visibility">gone</item>
<item name="android:visibility">visible</item>
</style>
</resources>

@ -26,9 +26,13 @@ import android.util.Log;
import java.util.HashMap;
public class Contact {
// 缓存联系人信息,键为电话号码,值为联系人姓名
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
// 定义字符串CALLER_ID_SELECTION
// 用于查询联系人信息的选择条件
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
@ -36,17 +40,24 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
// 获取联系人姓名
public static String getContact(Context context, String phoneNumber) {
// 如果联系人缓存为空,进行初始化
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 如果缓存中已包含该电话号码对应的联系人姓名,则直接返回姓名
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
// 构建查询条件
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 查询联系人信息
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
@ -54,20 +65,34 @@ public class Contact {
new String[] { phoneNumber },
null);
// 处理查询结果
// moveToFirst()返回第一条
if (cursor != null && cursor.moveToFirst()) {
try {
// 获取联系人姓名
String name = cursor.getString(0);
// 将姓名加入缓存
sContactCache.put(phoneNumber, name);
return name;
} catch (IndexOutOfBoundsException e) {
// 捕获异常,记录错误日志
Log.e(TAG, " Cursor get string error " + e.toString());
return null;
} finally {
cursor.close();
}
} else {
// 如果没有找到匹配的联系人,记录日志并返回空
Log.d(TAG, "No contact matched with number:" + phoneNumber);
return null;
}
}
}
/*
Java Contact getContact
sContactCache
TAG
CALLER_ID_SELECTION
getContact
*/

@ -17,9 +17,14 @@
package net.micode.notes.data;
import android.net.Uri;
// Notes 类中定义了很多常量这些常量大多是int型和string型
public class Notes {
// 权限
public static final String AUTHORITY = "micode_notes";
// 日志标签
public static final String TAG = "Notes";
// 笔记类型
public static final int TYPE_NOTE = 0;
public static final int TYPE_FOLDER = 1;
public static final int TYPE_SYSTEM = 2;
@ -30,60 +35,75 @@ 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";
public static final String INTENT_EXTRA_WIDGET_ID = "net.micode.notes.widget_id";
public static final String INTENT_EXTRA_WIDGET_TYPE = "net.micode.notes.widget_type";
public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id";
public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date";
// 笔记小部件类型
public static final int TYPE_WIDGET_INVALIDE = -1;
public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1;
// 数据类型常量
public static class DataConstants {
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
}
// 内容提供者的URI
/**
* Uri to query all notes and folders
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
//定义查询便签和文件夹的指针
/**
* Uri to query data
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
//定义查找数据的指针
// 笔记列的接口
// 定义NoteColumns的常量,用于后面创建数据库的表头
public interface NoteColumns {
/**
* The unique ID for a row
* <P> Type: INTEGER (long) </P>
*/
// 行的唯一ID
public static final String ID = "_id";
/**
* The parent's id for note or folder
* <P> Type: INTEGER (long) </P>
*/
// 笔记或文件夹的父ID
public static final String PARENT_ID = "parent_id";
/**
* Created data for note or folder
* <P> Type: INTEGER (long) </P>
*/
// 创建日期
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
* <P> Type: INTEGER (long) </P>
*/
// 最后修改日期
public static final String MODIFIED_DATE = "modified_date";
@ -91,30 +111,35 @@ public class Notes {
* Alert date
* <P> Type: INTEGER (long) </P>
*/
// 提醒日期
public static final String ALERTED_DATE = "alert_date";
/**
* Folder's name or text content of note
* <P> Type: TEXT </P>
*/
// 文件夹名称或笔记的文本内容
public static final String SNIPPET = "snippet";
/**
* Note's widget id
* <P> Type: INTEGER (long) </P>
*/
// 笔记的小部件ID
public static final String WIDGET_ID = "widget_id";
/**
* Note's widget type
* <P> Type: INTEGER (long) </P>
*/
// 笔记的小部件类型
public static final String WIDGET_TYPE = "widget_type";
/**
* Note's background color's id
* <P> Type: INTEGER (long) </P>
*/
// 笔记的背景颜色ID
public static final String BG_COLOR_ID = "bg_color_id";
/**
@ -122,86 +147,102 @@ public class Notes {
* note, it has at least one attachment
* <P> Type: INTEGER </P>
*/
// 笔记是否有附件
public static final String HAS_ATTACHMENT = "has_attachment";
/**
* Folder's count of notes
* <P> Type: INTEGER (long) </P>
*/
// 文件夹中的笔记数量
public static final String NOTES_COUNT = "notes_count";
/**
* The file type: folder or note
* <P> Type: INTEGER </P>
*/
// 文件类型:文件夹或笔记
public static final String TYPE = "type";
/**
* The last sync id
* <P> Type: INTEGER (long) </P>
*/
// 最后同步ID
public static final String SYNC_ID = "sync_id";
/**
* Sign to indicate local modified or not
* <P> Type: INTEGER </P>
*/
// 本地修改标志
public static final String LOCAL_MODIFIED = "local_modified";
/**
* Original parent id before moving into temporary folder
* <P> Type : INTEGER </P>
*/
// 移动到临时文件夹之前的原始父ID
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
/**
* The gtask id
* <P> Type : TEXT </P>
*/
// Gtask ID
public static final String GTASK_ID = "gtask_id";
/**
* The version code
* <P> Type : INTEGER (long) </P>
*/
// 版本号
public static final String VERSION = "version";
}
}//这些常量主要是定义便签的属性的
// 数据列的接口
// 定义DataColumns的常量,用于后面创建数据库的表头
public interface DataColumns {
/**
* The unique ID for a row
* <P> Type: INTEGER (long) </P>
*/
// 行的唯一ID
public static final String ID = "_id";
/**
* The MIME type of the item represented by this row.
* <P> Type: Text </P>
*/
// 该行所代表项的MIME类型
public static final String MIME_TYPE = "mime_type";
/**
* The reference id to note that this data belongs to
* <P> Type: INTEGER (long) </P>
*/
// 该数据所属笔记的引用ID
public static final String NOTE_ID = "note_id";
/**
* Created data for note or folder
* <P> Type: INTEGER (long) </P>
*/
// 创建日期
public static final String CREATED_DATE = "created_date";
/**
* Latest modified date
* <P> Type: INTEGER (long) </P>
*/
// 最后修改日期
public static final String MODIFIED_DATE = "modified_date";
/**
* Data's content
* <P> Type: TEXT </P>
*/
// 数据内容
public static final String CONTENT = "content";
@ -210,6 +251,7 @@ public class Notes {
* integer data type
* <P> Type: INTEGER </P>
*/
// 通用数据列意义由MIME类型决定用于整型数据类型
public static final String DATA1 = "data1";
/**
@ -217,6 +259,7 @@ public class Notes {
* integer data type
* <P> Type: INTEGER </P>
*/
// 通用数据列意义由MIME类型决定用于整型数据类型
public static final String DATA2 = "data2";
/**
@ -224,6 +267,7 @@ public class Notes {
* TEXT data type
* <P> Type: TEXT </P>
*/
// 通用数据列意义由MIME类型决定用于整型数据类型
public static final String DATA3 = "data3";
/**
@ -231,6 +275,7 @@ public class Notes {
* TEXT data type
* <P> Type: TEXT </P>
*/
// 通用数据列意义由MIME类型决定用于整型数据类型
public static final String DATA4 = "data4";
/**
@ -238,14 +283,18 @@ public class Notes {
* TEXT data type
* <P> Type: TEXT </P>
*/
// 通用数据列意义由MIME类型决定用于整型数据类型
public static final String DATA5 = "data5";
}
// 文本笔记的数据列
//主要是定义存储便签内容数据的
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
* <P> Type: Integer 1:check list mode 0: normal mode </P>
*/
// 表示文本为检查列表模式或非检查列表模式的模式
public static final String MODE = DATA1;
public static final int MODE_CHECK_LIST = 1;
@ -255,19 +304,22 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
}//文本内容的数据结构
// 通话笔记的数据列
public static final class CallNote implements DataColumns {
/**
* Call date for this record
* <P> Type: INTEGER (long) </P>
*/
// 记录的通话日期
public static final String CALL_DATE = DATA1;
/**
* Phone number for this record
* <P> Type: TEXT </P>
*/
// 记录的电话号码
public static final String PHONE_NUMBER = DATA3;
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note";
@ -275,5 +327,13 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
}
}//电话内容的数据结构
}
/*
Java Notes MIMEURI
NoteColumns DataColumns
TextNote CallNote MIMEURI
* */

@ -28,10 +28,13 @@ import net.micode.notes.data.Notes.NoteColumns;
public class NotesDatabaseHelper extends SQLiteOpenHelper {
// 数据库名称
private static final String DB_NAME = "note.db";
// 数据库版本
private static final int DB_VERSION = 4;
// 数据表
public interface TABLE {
public static final String NOTE = "note";
@ -360,3 +363,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
+ " INTEGER NOT NULL DEFAULT 0");
}
}
/*
*Java NotesDatabaseHelper SQLiteOpenHelper
SQL
onCreate onUpgrade
* */

@ -16,18 +16,31 @@
package net.micode.notes.gtask.exception;
// 自定义异常类,表示操作失败
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;
// 无参构造函数
public ActionFailureException() {
super();
}
// 带有错误信息的构造函数
public ActionFailureException(String paramString) {
super(paramString);
}
// 带有错误信息和原因的构造函数
public ActionFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}
}
/*
*
* Java ActionFailureException RuntimeException
ActionFailureException
serialVersionUIDUID
ActionFailureException()
ActionFailureException(String paramString)
ActionFailureException(String paramString, Throwable paramThrowable)*/

@ -16,18 +16,30 @@
package net.micode.notes.gtask.exception;
// 自定义异常类,表示网络操作失败
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;
// 无参构造函数
public NetworkFailureException() {
super();
}
// 带有错误信息的构造函数
public NetworkFailureException(String paramString) {
super(paramString);
}
// 带有错误信息和原因的构造函数
public NetworkFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable);
}
}
/*
* Java NetworkFailureException Exception
NetworkFailureException
serialVersionUIDUID
NetworkFailureException()
NetworkFailureException(String paramString)
NetworkFailureException(String paramString, Throwable paramThrowable)*/

@ -32,19 +32,23 @@ 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
};
// 定义查询结果的列索引
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 = new ContentValues();
@ -57,6 +61,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
// 从数据库中获取特定小部件的信息
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
@ -65,10 +70,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
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++) {
@ -104,7 +111,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
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) {
@ -124,9 +131,22 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
// 获取小部件背景资源ID的抽象方法
protected abstract int getBgResourceId(int bgId);
// 获取小部件布局ID的抽象方法
protected abstract int getLayoutId();
// 获取小部件类型的抽象方法
protected abstract int getWidgetType();
}
/*
* Java NoteWidgetProvider AppWidgetProvider
NoteWidgetProvider便
PROJECTION
COLUMN_IDCOLUMN_BG_COLOR_IDCOLUMN_SNIPPET
onDeleted
getNoteWidgetInfo
update
getBgResourceIdgetLayoutIdgetWidgetTypeIDID*/

@ -24,24 +24,38 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
// 便签小部件提供程序用于2x大小的小部件
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
// 当小部件更新时调用
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
// 获取小部件布局ID
@Override
protected int getLayoutId() {
return R.layout.widget_2x;
}
// 获取小部件背景资源ID
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
// 获取小部件类型
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;
}
}
/*Java NoteWidgetProvider_2x NoteWidgetProvider
NoteWidgetProvider_2x便2x
onUpdate
getLayoutId ID
getBgResourceId ID
getWidgetType
*/

@ -24,23 +24,38 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
// 便签小部件提供程序用于4x大小的小部件
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
// 当小部件更新时调用
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
// 获取小部件布局ID
protected int getLayoutId() {
return R.layout.widget_4x;
}
// 获取小部件背景资源ID
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
// 获取小部件类型
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;
}
}
/*
* Java NoteWidgetProvider_2x NoteWidgetProvider
NoteWidgetProvider_2x便2x
onUpdate
getLayoutId ID
getBgResourceId ID
getWidgetType
* */
Loading…
Cancel
Save