# Conflicts:
#	src/Notes-master/src/net/micode/notes/data/Notes.java
#	src/Notes-master/src/net/micode/notes/data/NotesDatabaseHelper.java
#	src/Notes-master/src/net/micode/notes/data/NotesProvider.java
#	src/Notes-master/src/net/micode/notes/model/Note.java
#	src/Notes-master/src/net/micode/notes/model/WorkingNote.java
#	src/Notes-master/src/net/micode/notes/tool/BackupUtils.java
#	src/Notes-master/src/net/micode/notes/tool/DataUtils.java
#	src/Notes-master/src/net/micode/notes/tool/GTaskStringUtils.java
#	src/Notes-master/src/net/micode/notes/tool/ResourceParser.java
#	src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider.java
#	src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_2x.java
#	src/Notes-master/src/net/micode/notes/widget/NoteWidgetProvider_4x.java
main
zhm 8 months ago
commit 154a29d984

@ -0,0 +1,104 @@
package net.micode.notes.gtask.data;
public class MetaData extends Task {
/*
* 功能描述得到类的简写名称存入字符串TAG中
* 实现过程调用getSimpleName ()函数
*/
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
/*
* 功能描述:设置数据,即生成元数据库
* 实现过程调用JSONObject库函数put ()Task类中的setNotes ()和setName ()函数
* 参数注解:
*/
public void setMeta(String gid, JSONObject metaInfo)
{
//对函数块进行注释
try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
/*
* 将这对键值放入metaInfo这个jsonobject对象中
*/
} catch (JSONException e) {
Log.e(TAG, "failed to put related gid");
/*
* 输出错误信息
*/
}
setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME);
}
/*
* 功能描述获取相关联的Gid
*/
public String getRelatedGid() {
return mRelatedGid;
}
/*
* 功能描述:判断当前数据是否为空,若为空则返回真即值得保存
* Made By CuiCan
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/*
* 功能描述使用远程json数据对象设置元数据内容
* 实现过程调用父类Task中的setContentByRemoteJSON ()函数,并
* 参数注解:
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes() != null) {
try {
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
Log.w(TAG, "failed to get related gid");
/*
* 输出警告信息
*/
mRelatedGid = null;
}
}
}
/*
* 功能描述使用本地json数据对象设置元数据内容一般不会用到若用到则抛出异常
* Made By CuiCan
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
/*
* 传递非法参数异常
*/
}
/*
* 功能描述从元数据内容中获取本地json对象一般不会用到若用到则抛出异常
* Made By CuiCan
*/
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
/*
* 传递非法参数异常
* Made By Cui Can
*/
}
/*
* 功能描述:获取同步动作状态,一般不会用到,若用到,则抛出异常
* Made By CuiCan
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");
/*
* 传递非法参数异常
* Made By Cui Can
*/
}
}

@ -0,0 +1,90 @@
package net.micode.notes.gtask.data;
import android.database.Cursor;
import org.json.JSONObject;
/**
* 应该是同步操作的基础数据类型,定义了相关指示同步操作的常量
* 关键字abstract
*/
public abstract class Node {
//定义了各种用于表征同步状态的常量
public static final int SYNC_ACTION_NONE = 0;// 本地和云端都无可更新内容(即本地和云端内容一致)
public static final int SYNC_ACTION_ADD_REMOTE = 1;// 需要在远程云端增加内容
public static final int SYNC_ACTION_ADD_LOCAL = 2;// 需要在本地增加内容
public static final int SYNC_ACTION_DEL_REMOTE = 3;// 需要在远程云端删除内容
public static final int SYNC_ACTION_DEL_LOCAL = 4;// 需要在本地删除内容
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;// 需要将本地内容更新到远程云端
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;// 需要将远程云端内容更新到本地
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;// 同步出现冲突
public static final int SYNC_ACTION_ERROR = 8;// 同步出现错误
private String mGid;
private String mName;
private long mLastModified;//记录最后一次修改时间
private boolean mDeleted;//表征是否被删除
public Node() {
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
public abstract JSONObject getCreateAction(int actionId);
public abstract JSONObject getUpdateAction(int actionId);
public abstract void setContentByRemoteJSON(JSONObject js);
public abstract void setContentByLocalJSON(JSONObject js);
public abstract JSONObject getLocalJSONFromContent();
public abstract int getSyncAction(Cursor c);
public void setGid(String gid) {
this.mGid = gid;
}
public void setName(String name) {
this.mName = name;
}
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
public String getGid() {
return this.mGid;
}
public String getName() {
return this.mName;
}
public long getLastModified() {
return this.mLastModified;
}
public boolean getDeleted() {
return this.mDeleted;
}
}

@ -0,0 +1,224 @@
/*
* Description用于支持小米便签最底层的数据库相关操作和sqlnote的关系上是子集关系即data是note的子集节点
* SqlData其实就是也就是所谓数据中的数据
*/
package net.micode.notes.gtask.data;
/*
* 功能描述:
* 实现过程:
* 参数注解:
* Made By CuiCan
*/
public class SqlData {
/*
* 功能描述得到类的简写名称存入字符串TAG中
* 实现过程调用getSimpleName ()函数
* Made By CuiCan
*/
private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999;//为mDataId置初始值-99999
/**
* 来自Notes类中定义的DataColumn中的一些常量
*/
// 集合了interface DataColumns中所有SF常量
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
/**
* 以下五个变量作为sql表中5列的编号
*/
public static final int DATA_ID_COLUMN = 0;
public static final int DATA_MIME_TYPE_COLUMN = 1;
public static final int DATA_CONTENT_COLUMN = 2;
public static final int DATA_CONTENT_DATA_1_COLUMN = 3;
public static final int DATA_CONTENT_DATA_3_COLUMN = 4;
private ContentResolver mContentResolver;
//判断是否直接用Content生成是为true否则为false
private boolean mIsCreate;
private long mDataId;
private String mDataMimeType;
private String mDataContent;
private long mDataContentData1;
private String mDataContentData3;
private ContentValues mDiffDataValues;
/*
* 功能描述:构造函数,用于初始化数据
* 参数注解mContentResolver用于获取ContentProvider提供的数据
* 参数注解: mIsCreate表征当前数据是用哪种方式创建两种构造函数的参数不同
* 参数注解:
* Made By CuiCan
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
mDataId = INVALID_ID;//mDataId置初始值-99999
mDataMimeType = DataConstants.NOTE;
mDataContent = "";
mDataContentData1 = 0;
mDataContentData3 = "";
mDiffDataValues = new ContentValues();
}
/*
* 功能描述:构造函数,初始化数据
* 参数注解mContentResolver用于获取ContentProvider提供的数据
* 参数注解: mIsCreate表征当前数据是用哪种方式创建两种构造函数的参数不同
* 参数注解:
* Made By CuiCan
*/
public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(c);
mDiffDataValues = new ContentValues();
}
/*
* 功能描述:从光标处加载数据
* 从当前的光标处将五列的数据加载到该类的对象
* Made By CuiCan
*/
private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
mDataContent = c.getString(DATA_CONTENT_COLUMN);
mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}
/*
* 功能描述:设置用于共享的数据,并提供异常抛出与处理机制
* 参数注解:
* Made By CuiCan
*/
public void setContent(JSONObject js) throws JSONException {
//如果传入的JSONObject对象中有DataColumns.ID这一项则设置否则设为INVALID_ID
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
if (mIsCreate || mDataId != dataId) {
mDiffDataValues.put(DataColumns.ID, dataId);
}
mDataId = dataId;
String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE)
: DataConstants.NOTE;
if (mIsCreate || !mDataMimeType.equals(dataMimeType)) {
mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType);
}
mDataMimeType = dataMimeType;
String dataContent = js.has(DataColumns.CONTENT) ? js.getString(DataColumns.CONTENT) : "";
if (mIsCreate || !mDataContent.equals(dataContent)) {
mDiffDataValues.put(DataColumns.CONTENT, dataContent);
}
mDataContent = dataContent;
long dataContentData1 = js.has(DataColumns.DATA1) ? js.getLong(DataColumns.DATA1) : 0;
if (mIsCreate || mDataContentData1 != dataContentData1) {
mDiffDataValues.put(DataColumns.DATA1, dataContentData1);
}
mDataContentData1 = dataContentData1;
String dataContentData3 = js.has(DataColumns.DATA3) ? js.getString(DataColumns.DATA3) : "";
if (mIsCreate || !mDataContentData3.equals(dataContentData3)) {
mDiffDataValues.put(DataColumns.DATA3, dataContentData3);
}
mDataContentData3 = dataContentData3;
}
/*
* 功能描述:获取共享的数据内容,并提供异常抛出与处理机制
* 参数注解:
* Made By CuiCan
*/
public JSONObject getContent() throws JSONException {
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
return null;
}
//创建JSONObject对象。并将相关数据放入其中并返回。
JSONObject js = new JSONObject();
js.put(DataColumns.ID, mDataId);
js.put(DataColumns.MIME_TYPE, mDataMimeType);
js.put(DataColumns.CONTENT, mDataContent);
js.put(DataColumns.DATA1, mDataContentData1);
js.put(DataColumns.DATA3, mDataContentData3);
return js;
}
/*
* 功能描述commit函数用于把当前造作所做的修改保存到数据库
* 参数注解:
* Made By CuiCan
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
mDiffDataValues.remove(DataColumns.ID);
}
mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
try {
mDataId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
}
} else {
if (mDiffDataValues.size() > 0) {
int result = 0;
if (!validateVersion) {
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
} else {
result = mContentResolver.update(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues,
" ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.VERSION + "=?)", new String[] {
String.valueOf(noteId), String.valueOf(version)
});
}
if (result == 0) {
Log.w(TAG, "there is no update. maybe user updates note when syncing");
}
}
}
mDiffDataValues.clear();
mIsCreate = false;
}
/*
* 功能描述获取当前id
* 实现过程:
* 参数注解:
* Made By CuiCan
*/
public long getId() {
return mDataId;
}
}

@ -0,0 +1,577 @@
/*
* Description用于支持小米便签最底层的数据库相关操作和sqldata的关系上是父集关系即note是data的子父集。
* 和SqlData相比SqlNote算是真正意义上的数据了。
*/
package net.micode.notes.gtask.data;
/*
* 功能描述:
* 实现过程:
* 参数注解:
* Made By CuiCan
*/
public class SqlNote {
/*
* 功能描述得到类的简写名称存入字符串TAG中
* 实现过程调用getSimpleName ()函数
* Made By CuiCan
*/
private static final String TAG = SqlNote.class.getSimpleName();
private static final int INVALID_ID = -99999;
// 集合了interface NoteColumns中所有SF常量17个
public static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
NoteColumns.NOTES_COUNT, NoteColumns.PARENT_ID, NoteColumns.SNIPPET, NoteColumns.TYPE,
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE, NoteColumns.SYNC_ID,
NoteColumns.LOCAL_MODIFIED, NoteColumns.ORIGIN_PARENT_ID, NoteColumns.GTASK_ID,
NoteColumns.VERSION
};
//以下设置17个列的编号
public static final int ID_COLUMN = 0;
public static final int ALERTED_DATE_COLUMN = 1;
public static final int BG_COLOR_ID_COLUMN = 2;
public static final int CREATED_DATE_COLUMN = 3;
public static final int HAS_ATTACHMENT_COLUMN = 4;
public static final int MODIFIED_DATE_COLUMN = 5;
public static final int NOTES_COUNT_COLUMN = 6;
public static final int PARENT_ID_COLUMN = 7;
public static final int SNIPPET_COLUMN = 8;
public static final int TYPE_COLUMN = 9;
public static final int WIDGET_ID_COLUMN = 10;
public static final int WIDGET_TYPE_COLUMN = 11;
public static final int SYNC_ID_COLUMN = 12;
public static final int LOCAL_MODIFIED_COLUMN = 13;
public static final int ORIGIN_PARENT_ID_COLUMN = 14;
public static final int GTASK_ID_COLUMN = 15;
public static final int VERSION_COLUMN = 16;
//一下定义了17个内部的变量其中12个可以由content中获得5个需要初始化为0或者new
private Context mContext;
private ContentResolver mContentResolver;
private boolean mIsCreate;
private long mId;
private long mAlertDate;
private int mBgColorId;
private long mCreatedDate;
private int mHasAttachment;
private long mModifiedDate;
private long mParentId;
private String mSnippet;
private int mType;
private int mWidgetId;
private int mWidgetType;
private long mOriginParent;
private long mVersion;
private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList;
/*
* 功能描述:构造函数
* 参数注解: mIsCreate用于标示构造方式
* 参数注解:
* Made By CuiCan
*/
//构造函数只有context对所有的变量进行初始化
public SqlNote(Context context) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = true;
mId = INVALID_ID;
mAlertDate = 0;
mBgColorId = ResourceParser.getDefaultBgId(context);
mCreatedDate = System.currentTimeMillis();//调用系统函数获得创建时间
mHasAttachment = 0;
mModifiedDate = System.currentTimeMillis();//最后一次修改时间初始化为创建时间
mParentId = 0;
mSnippet = "";
mType = Notes.TYPE_NOTE;
mWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
mOriginParent = 0;
mVersion = 0;
mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>();
}
/*
* 功能描述:构造函数
* 参数注解: mIsCreate用于标示构造方式
* 参数注解:
* Made By CuiCan
*/
//构造函数有context和一个数据库的cursor多数变量通过cursor指向的一条记录直接进行初始化
public SqlNote(Context context, Cursor c) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(c);
mDataList = new ArrayList<SqlData>();
//
if (mType == Notes.TYPE_NOTE)
loadDataContent();
mDiffNoteValues = new ContentValues();
}
/*
* 功能描述:构造函数
* 参数注解: mIsCreate用于标示构造方式
* 参数注解:
* Made By CuiCan
*/
public SqlNote(Context context, long id) {
mContext = context;
mContentResolver = context.getContentResolver();
mIsCreate = false;
loadFromCursor(id);
mDataList = new ArrayList<SqlData>();
if (mType == Notes.TYPE_NOTE)
loadDataContent();
mDiffNoteValues = new ContentValues();
}
/*
* 功能描述通过id从光标处加载数据
* Made By CuiCan
*/
private void loadFromCursor(long id) {
Cursor c = null;
try {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
new String[] {
String.valueOf(id)
}, null);//通过id获得对应的ContentResolver中的cursor
if (c != null) {
c.moveToNext();
loadFromCursor(c);//然后加载数据进行初始化,这样函数
//SqlNote(Context context, long id)与SqlNote(Context context, long id)的实现方式基本相同
} else {
Log.w(TAG, "loadFromCursor: cursor = null");
}
} finally {
if (c != null)
c.close();
}
}
/*
* 功能描述:通过游标从光标处加载数据
* Made By CuiCan
*/
private void loadFromCursor(Cursor c) {
//直接从一条记录中的获得以下变量的初始值
mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
mBgColorId = c.getInt(BG_COLOR_ID_COLUMN);
mCreatedDate = c.getLong(CREATED_DATE_COLUMN);
mHasAttachment = c.getInt(HAS_ATTACHMENT_COLUMN);
mModifiedDate = c.getLong(MODIFIED_DATE_COLUMN);
mParentId = c.getLong(PARENT_ID_COLUMN);
mSnippet = c.getString(SNIPPET_COLUMN);
mType = c.getInt(TYPE_COLUMN);
mWidgetId = c.getInt(WIDGET_ID_COLUMN);
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
mVersion = c.getLong(VERSION_COLUMN);
}
/*
* 功能描述通过content机制获取共享数据并加载到数据库当前游标处
* 参数注解:
* Made By CuiCan
*/
private void loadDataContent() {
Cursor c = null;
mDataList.clear();
try {
c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA,
"(note_id=?)", new String[] {
String.valueOf(mId)
}, null);
if (c != null) {
if (c.getCount() == 0) {
Log.w(TAG, "it seems that the note has not data");
return;
}
while (c.moveToNext()) {
SqlData data = new SqlData(mContext, c);
mDataList.add(data);
}
} else {
Log.w(TAG, "loadDataContent: cursor = null");
}
} finally {
if (c != null)
c.close();
}
}
/*
* 功能描述设置通过content机制用于共享的数据信息
* 参数注解:
* Made By CuiCan
*/
public boolean setContent(JSONObject js) {
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
Log.w(TAG, "cannot set system folder");
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
// for folder we can only update the snnipet and type
String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : "";
if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
}
mSnippet = snippet;
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE;
if (mIsCreate || mType != type) {
mDiffNoteValues.put(NoteColumns.TYPE, type);
}
mType = type;
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
if (mIsCreate || mId != id) {
mDiffNoteValues.put(NoteColumns.ID, id);
}
mId = id;
long alertDate = note.has(NoteColumns.ALERTED_DATE) ? note
.getLong(NoteColumns.ALERTED_DATE) : 0;
if (mIsCreate || mAlertDate != alertDate) {
mDiffNoteValues.put(NoteColumns.ALERTED_DATE, alertDate);
}
mAlertDate = alertDate;
int bgColorId = note.has(NoteColumns.BG_COLOR_ID) ? note
.getInt(NoteColumns.BG_COLOR_ID) : ResourceParser.getDefaultBgId(mContext);
if (mIsCreate || mBgColorId != bgColorId) {
mDiffNoteValues.put(NoteColumns.BG_COLOR_ID, bgColorId);
}
mBgColorId = bgColorId;
long createDate = note.has(NoteColumns.CREATED_DATE) ? note
.getLong(NoteColumns.CREATED_DATE) : System.currentTimeMillis();
if (mIsCreate || mCreatedDate != createDate) {
mDiffNoteValues.put(NoteColumns.CREATED_DATE, createDate);
}
mCreatedDate = createDate;
int hasAttachment = note.has(NoteColumns.HAS_ATTACHMENT) ? note
.getInt(NoteColumns.HAS_ATTACHMENT) : 0;
if (mIsCreate || mHasAttachment != hasAttachment) {
mDiffNoteValues.put(NoteColumns.HAS_ATTACHMENT, hasAttachment);
}
mHasAttachment = hasAttachment;
long modifiedDate = note.has(NoteColumns.MODIFIED_DATE) ? note
.getLong(NoteColumns.MODIFIED_DATE) : System.currentTimeMillis();
if (mIsCreate || mModifiedDate != modifiedDate) {
mDiffNoteValues.put(NoteColumns.MODIFIED_DATE, modifiedDate);
}
mModifiedDate = modifiedDate;
long parentId = note.has(NoteColumns.PARENT_ID) ? note
.getLong(NoteColumns.PARENT_ID) : 0;
if (mIsCreate || mParentId != parentId) {
mDiffNoteValues.put(NoteColumns.PARENT_ID, parentId);
}
mParentId = parentId;
String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : "";
if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
}
mSnippet = snippet;
int type = note.has(NoteColumns.TYPE) ? note.getInt(NoteColumns.TYPE)
: Notes.TYPE_NOTE;
if (mIsCreate || mType != type) {
mDiffNoteValues.put(NoteColumns.TYPE, type);
}
mType = type;
int widgetId = note.has(NoteColumns.WIDGET_ID) ? note.getInt(NoteColumns.WIDGET_ID)
: AppWidgetManager.INVALID_APPWIDGET_ID;
if (mIsCreate || mWidgetId != widgetId) {
mDiffNoteValues.put(NoteColumns.WIDGET_ID, widgetId);
}
mWidgetId = widgetId;
int widgetType = note.has(NoteColumns.WIDGET_TYPE) ? note
.getInt(NoteColumns.WIDGET_TYPE) : Notes.TYPE_WIDGET_INVALIDE;
if (mIsCreate || mWidgetType != widgetType) {
mDiffNoteValues.put(NoteColumns.WIDGET_TYPE, widgetType);
}
mWidgetType = widgetType;
long originParent = note.has(NoteColumns.ORIGIN_PARENT_ID) ? note
.getLong(NoteColumns.ORIGIN_PARENT_ID) : 0;
if (mIsCreate || mOriginParent != originParent) {
mDiffNoteValues.put(NoteColumns.ORIGIN_PARENT_ID, originParent);
}
mOriginParent = originParent;
for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i);
SqlData sqlData = null;
if (data.has(DataColumns.ID)) {
long dataId = data.getLong(DataColumns.ID);
for (SqlData temp : mDataList) {
if (dataId == temp.getId()) {
sqlData = temp;
}
}
}
if (sqlData == null) {
sqlData = new SqlData(mContext);
mDataList.add(sqlData);
}
sqlData.setContent(data);
}
}
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
return false;
}
return true;
}
/*
* 功能描述获取content机制提供的数据并加载到note中
* 参数注解:
* Made By CuiCan
*/
public JSONObject getContent() {
try {
JSONObject js = new JSONObject();
if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet");
return null;
}
JSONObject note = new JSONObject();
if (mType == Notes.TYPE_NOTE) {//类型为note时
note.put(NoteColumns.ID, mId);
note.put(NoteColumns.ALERTED_DATE, mAlertDate);
note.put(NoteColumns.BG_COLOR_ID, mBgColorId);
note.put(NoteColumns.CREATED_DATE, mCreatedDate);
note.put(NoteColumns.HAS_ATTACHMENT, mHasAttachment);
note.put(NoteColumns.MODIFIED_DATE, mModifiedDate);
note.put(NoteColumns.PARENT_ID, mParentId);
note.put(NoteColumns.SNIPPET, mSnippet);
note.put(NoteColumns.TYPE, mType);
note.put(NoteColumns.WIDGET_ID, mWidgetId);
note.put(NoteColumns.WIDGET_TYPE, mWidgetType);
note.put(NoteColumns.ORIGIN_PARENT_ID, mOriginParent);
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
JSONArray dataArray = new JSONArray();
for (SqlData sqlData : mDataList) {
JSONObject data = sqlData.getContent();
if (data != null) {
dataArray.put(data);
}
}
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {//类型为文件夹或者
note.put(NoteColumns.ID, mId);
note.put(NoteColumns.TYPE, mType);
note.put(NoteColumns.SNIPPET, mSnippet);
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
}
return js;
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
return null;
}
/*
* 功能描述给当前id设置父id
* 参数注解:
* Made By CuiCan
*/
public void setParentId(long id) {
mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id);
}
/*
* 功能描述给当前id设置Gtaskid
* 参数注解:
* Made By CuiCan
*/
public void setGtaskId(String gid) {
mDiffNoteValues.put(NoteColumns.GTASK_ID, gid);
}
/*
* 功能描述给当前id设置同步id
* 参数注解:
* Made By CuiCan
*/
public void setSyncId(long syncId) {
mDiffNoteValues.put(NoteColumns.SYNC_ID, syncId);
}
/*
* 功能描述:初始化本地修改,即撤销所有当前修改
* 参数注解:
* Made By CuiCan
*/
public void resetLocalModified() {
mDiffNoteValues.put(NoteColumns.LOCAL_MODIFIED, 0);
}
/*
* 功能描述获得当前id
* 参数注解:
* Made By CuiCan
*/
public long getId() {
return mId;
}
/*
* 功能描述获得当前id的父id
* 参数注解:
* Made By CuiCan
*/
public long getParentId() {
return mParentId;
}
/*
* 功能描述:获取小片段即用于显示的部分便签内容
* 参数注解:
* Made By CuiCan
*/
public String getSnippet() {
return mSnippet;
}
/*
* 功能描述:判断是否为便签类型
* 参数注解:
* Made By CuiCan
*/
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/*
* 功能描述commit函数用于把当前造作所做的修改保存到数据库
* 参数注解:
* Made By CuiCan
*/
public void commit(boolean validateVersion) {
if (mIsCreate) {
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {
mDiffNoteValues.remove(NoteColumns.ID);
}
Uri uri = mContentResolver.insert(Notes.CONTENT_NOTE_URI, mDiffNoteValues);
try {
mId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
throw new ActionFailureException("create note failed");
}
if (mId == 0) {
throw new IllegalStateException("Create thread id failed");
}
if (mType == Notes.TYPE_NOTE) {
for (SqlData sqlData : mDataList) {//直接使用sqldata中的实现
sqlData.commit(mId, false, -1);
}
}
} else {
if (mId <= 0 && mId != Notes.ID_ROOT_FOLDER && mId != Notes.ID_CALL_RECORD_FOLDER) {
Log.e(TAG, "No such note");
throw new IllegalStateException("Try to update note with invalid id");
}
if (mDiffNoteValues.size() > 0) {
mVersion ++;
int result = 0;
if (!validateVersion) {//构造字符串
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?)", new String[] {
String.valueOf(mId)
});
} else {
result = mContentResolver.update(Notes.CONTENT_NOTE_URI, mDiffNoteValues, "("
+ NoteColumns.ID + "=?) AND (" + NoteColumns.VERSION + "<=?)",
new String[] {
String.valueOf(mId), String.valueOf(mVersion)
});
}
if (result == 0) {
Log.w(TAG, "there is no update. maybe user updates note when syncing");
}
}
if (mType == Notes.TYPE_NOTE) {
for (SqlData sqlData : mDataList) {
sqlData.commit(mId, validateVersion, mVersion);
}
}
}
// refresh local info
loadFromCursor(mId);
if (mType == Notes.TYPE_NOTE)
loadDataContent();
mDiffNoteValues.clear();
mIsCreate = false;
}
}

@ -0,0 +1,323 @@
package net.micode.notes.gtask.data;
public class Task extends Node {
private static final String TAG = Task.class.getSimpleName();
private boolean mCompleted;//是否完成
private String mNotes;
private JSONObject mMetaInfo;//将在实例中存储数据的类型
private Task mPriorSibling;//对应的优先兄弟Task的指针待完善
private TaskList mParent;//所在的任务列表的指针
public Task() {
super();
mCompleted = false;
mNotes = null;
mPriorSibling = null;//TaskList中当前Task前面的Task的指针
mParent = null;//当前Task所在的TaskList
mMetaInfo = null;
}
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// index
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));
// entity_delta
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
GTaskStringUtils.GTASK_JSON_TYPE_TASK);
if (getNotes() != null) {
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
}
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
// parent_id
if (mParent!= null) {
js.put(GTaskStringUtils.GTASK_JSON_PARENT_ID, mParent.getGid());
}
// dest_parent_type
js.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT_TYPE,
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
// list_id
if (mParent!= null) {
js.put(GTaskStringUtils.GTASK_JSON_LIST_ID, mParent.getGid());
}
// prior_sibling_id
if (mPriorSibling != null) {
js.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, mPriorSibling.getGid());
}
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to generate task-create jsonobject");
}
return js;
}
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// id
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// entity_delta
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
if (getNotes() != null) {
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
}
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to generate task-update jsonobject");
}
return js;
}
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
// id
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
}
// last_modified
if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
}
// name
if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
}
// notes
if (js.has(GTaskStringUtils.GTASK_JSON_NOTES)) {
setNotes(js.getString(GTaskStringUtils.GTASK_JSON_NOTES));
}
// deleted
if (js.has(GTaskStringUtils.GTASK_JSON_DELETED)) {
setDeleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_DELETED));
}
// completed
if (js.has(GTaskStringUtils.GTASK_JSON_COMPLETED)) {
setCompleted(js.getBoolean(GTaskStringUtils.GTASK_JSON_COMPLETED));
}
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to get task content from jsonobject");
}
}
}
public void setContentByLocalJSON(JSONObject js) { // metadata ʵʩ
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
}
try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
if (note.getInt(NoteColumns.TYPE) != Notes.TYPE_NOTE) {
Log.e(TAG, "invalid type");
return;
}
for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i);
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
setName(data.getString(DataColumns.CONTENT));
break;
}
}
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
}
public JSONObject getLocalJSONFromContent() {
String name = getName();
try {
if (mMetaInfo == null) {
// new task created from web
if (name == null) {
Log.w(TAG, "the note seems to be an empty one");
return null;
}
JSONObject js = new JSONObject();
JSONObject note = new JSONObject();
JSONArray dataArray = new JSONArray();
JSONObject data = new JSONObject();
data.put(DataColumns.CONTENT, name);
dataArray.put(data);
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
js.put(GTaskStringUtils.META_HEAD_NOTE, note);
return js;
} else {
// synced task
JSONObject note = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
JSONArray dataArray = mMetaInfo.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
for (int i = 0; i < dataArray.length(); i++) {
JSONObject data = dataArray.getJSONObject(i);
if (TextUtils.equals(data.getString(DataColumns.MIME_TYPE), DataConstants.NOTE)) {
data.put(DataColumns.CONTENT, getName());
break;
}
}
note.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
return mMetaInfo;
}
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
return null;
}
}
public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) {
try {
mMetaInfo = new JSONObject(metaData.getNotes());
} catch (JSONException e) {
Log.w(TAG, e.toString());
mMetaInfo = null;
}
}
}
public int getSyncAction(Cursor c) {
try {
JSONObject noteInfo = null;
if (mMetaInfo != null && mMetaInfo.has(GTaskStringUtils.META_HEAD_NOTE)) {
noteInfo = mMetaInfo.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
}
if (noteInfo == null) {
Log.w(TAG, "it seems that note meta has been deleted");
return SYNC_ACTION_UPDATE_REMOTE;
}
if (!noteInfo.has(NoteColumns.ID)) {
Log.w(TAG, "remote note id seems to be deleted");
return SYNC_ACTION_UPDATE_LOCAL;
}
// validate the note id now
if (c.getLong(SqlNote.ID_COLUMN) != noteInfo.getLong(NoteColumns.ID)) {
Log.w(TAG, "note id doesn't match");
return SYNC_ACTION_UPDATE_LOCAL;
}
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
// there is no local update
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// no update both side
return SYNC_ACTION_NONE;
} else {
// apply remote to local
return SYNC_ACTION_UPDATE_LOCAL;
}
} else {
// validate gtask id
if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
Log.e(TAG, "gtask id doesn't match");
return SYNC_ACTION_ERROR;
}
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// local modification only
return SYNC_ACTION_UPDATE_REMOTE;
} else {
return SYNC_ACTION_UPDATE_CONFLICT;
}
}
} catch (Exception e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
return SYNC_ACTION_ERROR;
}
public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0);
}
public void setCompleted(boolean completed) {
this.mCompleted = completed;
}
public void setNotes(String notes) {
this.mNotes = notes;
}
public void setPriorSibling(Task priorSibling) {
this.mPriorSibling = priorSibling;
}
public void setParent(TaskList parent) {
this.mParent = parent;
}
public boolean getCompleted() {
return this.mCompleted;
}
public String getNotes() {
return this.mNotes;
}
public Task getPriorSibling() {
return this.mPriorSibling;
}
public TaskList getParent() {
return this.mParent;
}
}

@ -0,0 +1,370 @@
package net.micode.notes.gtask.data;
public class TaskList extends Node {
private static final String TAG = TaskList.class.getSimpleName();//tag标记
private int mIndex;//当前TaskList的指针
private ArrayList<Task> mChildren;//类中主要的保存数据的单元用来实现一个以Task为元素的ArrayList
public TaskList() {
super();
mChildren = new ArrayList<Task>();
mIndex = 1;
}
/* (non-Javadoc)
* @see net.micode.notes.gtask.data.Node#getCreateAction(int)
* 生成并返回一个包含了一定数据的JSONObject实体
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// index
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex);
// entity_delta
JSONObject entity = new JSONObject();//entity实体
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
GTaskStringUtils.GTASK_JSON_TYPE_GROUP);
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to generate tasklist-create jsonobject");
}
return js;
}
/* (non-Javadoc)
* @see net.micode.notes.gtask.data.Node#getUpdateAction(int)
* 生成并返回一个包含了一定数据的JSONObject实体
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();
try {
// action_type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE);
// action_id
js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId);
// id
js.put(GTaskStringUtils.GTASK_JSON_ID, getGid());
// entity_delta
JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted());
js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity);
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to generate tasklist-update jsonobject");
}
return js;
}
public void setContentByRemoteJSON(JSONObject js) {
if (js != null) {
try {
// id
if (js.has(GTaskStringUtils.GTASK_JSON_ID)) {
setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID));
}
// last_modified
if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) {
setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED));
}
// name
if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) {
setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME));
}
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
throw new ActionFailureException("fail to get tasklist content from jsonobject");
}
}
}
public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
}
try {
JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
String name = folder.getString(NoteColumns.SNIPPET);
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name);
} else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER)
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT);
else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER)
setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX
+ GTaskStringUtils.FOLDER_CALL_NOTE);
else
Log.e(TAG, "invalid system folder");
} else {
Log.e(TAG, "error type");
}
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
}
public JSONObject getLocalJSONFromContent() {
try {
JSONObject js = new JSONObject();
JSONObject folder = new JSONObject();
String folderName = getName();
if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX))
folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(),
folderName.length());
folder.put(NoteColumns.SNIPPET, folderName);
if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT)
|| folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE))
folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
else
folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER);
js.put(GTaskStringUtils.META_HEAD_NOTE, folder);
return js;
} catch (JSONException e) {
Log.e(TAG, e.toString());
e.printStackTrace();
return null;
}
}
public int getSyncAction(Cursor c) {
try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
// there is no local update
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// no update both side
return SYNC_ACTION_NONE;
} else {
// apply remote to local
return SYNC_ACTION_UPDATE_LOCAL;
}
} else {
// validate gtask id
if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
Log.e(TAG, "gtask id doesn't match");
return SYNC_ACTION_ERROR;
}
if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
// local modification only
return SYNC_ACTION_UPDATE_REMOTE;
} else {
// for folder conflicts, just apply local modification
return SYNC_ACTION_UPDATE_REMOTE;
}
}
} catch (Exception e) {
Log.e(TAG, e.toString());
e.printStackTrace();
}
return SYNC_ACTION_ERROR;
}
/**
* @return
* 功能获得TaskList的大小即mChildren的大小
*/
public int getChildTaskCount() {
return mChildren.size();
}
/**
* @param task
* @return 返回值为是否成功添加任务。
* 功能:在当前任务表末尾添加新的任务。
*/
public boolean addChildTask(Task task) {
boolean ret = false;
if (task != null && !mChildren.contains(task)) {
ret = mChildren.add(task);
if (ret) {
// need to set prior sibling and parent
task.setPriorSibling(mChildren.isEmpty() ? null : mChildren
.get(mChildren.size() - 1));
task.setParent(this);
//注意每一次ArrayList的变化都要紧跟相关Task中PriorSibling的更改
//,接下来几个函数都有相关操作
}
}
return ret;
}
/**
* @param task
* @param index
* @return
* 功能:在当前任务表的指定位置添加新的任务。
*/
public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index");
return false;
}
int pos = mChildren.indexOf(task);
if (task != null && pos == -1) {
mChildren.add(index, task);
// update the task list
Task preTask = null;
Task afterTask = null;
if (index != 0)
preTask = mChildren.get(index - 1);
if (index != mChildren.size() - 1)
afterTask = mChildren.get(index + 1);
task.setPriorSibling(preTask);
if (afterTask != null)
afterTask.setPriorSibling(task);
}
return true;
}
/**
* @param task
* @return 返回删除是否成功
* 功能删除TaskList中的一个Task
*/
public boolean removeChildTask(Task task) {
boolean ret = false;
int index = mChildren.indexOf(task);
if (index != -1) {
ret = mChildren.remove(task);
if (ret) {
// reset prior sibling and parent
task.setPriorSibling(null);
task.setParent(null);
// update the task list
if (index != mChildren.size()) {
mChildren.get(index).setPriorSibling(
index == 0 ? null : mChildren.get(index - 1));
}
}
}
return ret;
}
/**
* @param task
* @param index
* @return
* 功能将当前TaskList中含有的某个Task移到index位置
*/
public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "move child task: invalid index");
return false;
}
int pos = mChildren.indexOf(task);
if (pos == -1) {
Log.e(TAG, "move child task: the task should in the list");
return false;
}
if (pos == index)
return true;
return (removeChildTask(task) && addChildTask(task, index));
//利用已实现好的功能完成当下功能;
}
/**
* @param gid
* @return返回寻找结果
* 功能按gid寻找Task
*/
public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i);
if (t.getGid().equals(gid)) {
return t;
}
}
return null;
}
/**
* @param task
* @return
* 功能返回指定Task的index
*/
public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task);
}
/**
* @param index
* @return
* 功能返回指定index的Task
*/
public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index");
return null;
}
return mChildren.get(index);
}
/**
* @param gid
* @return
* 功能返回指定gid的Task
*/
public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) {//一种常见的ArrayList的遍历方法四种见精读笔记
if (task.getGid().equals(gid))
return task;
}
return null;
}
public ArrayList<Task> getChildTaskList() {
return this.mChildren;
}
public void setIndex(int index) {
this.mIndex = index;
}
public int getIndex() {
return this.mIndex;
}
}

@ -17,6 +17,7 @@
package net.micode.notes.data;
import android.net.Uri;
<<<<<<< HEAD
public class Notes {
public static final String AUTHORITY = "micode_notes"; // 内容提供者的授权标识
@ -55,34 +56,92 @@ public class Notes {
/**
* URI
=======
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;
/**
* Following IDs are system folders' identifiers
* {@link Notes#ID_ROOT_FOLDER } is default folder
* {@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 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 to query all notes and folders
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note");
/**
<<<<<<< HEAD
* URI
=======
* Uri to query data
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
public interface NoteColumns {
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER (long) </P>
=======
* The unique ID for a row
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String ID = "_id";
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER (long) </P>
=======
* The parent's id for note or folder
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String PARENT_ID = "parent_id";
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
=======
* Created data for note or folder
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String CREATED_DATE = "created_date";
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
*/
@ -91,114 +150,212 @@ public class Notes {
/**
*
* <P> : INTEGER (long) </P>
=======
* Latest modified date
* <P> Type: INTEGER (long) </P>
*/
public static final String MODIFIED_DATE = "modified_date";
/**
* Alert date
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String ALERTED_DATE = "alert_date";
/**
<<<<<<< HEAD
*
* <P> : TEXT </P>
=======
* Folder's name or text content of note
* <P> Type: TEXT </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String SNIPPET = "snippet";
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER (long) </P>
=======
* Note's widget id
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String WIDGET_ID = "widget_id";
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
=======
* Note's widget type
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String WIDGET_TYPE = "widget_type";
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER (long) </P>
=======
* Note's background color's id
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String BG_COLOR_ID = "bg_color_id";
/**
<<<<<<< HEAD
*
* <P> : INTEGER </P>
=======
* For text note, it doesn't has attachment, for multi-media
* note, it has at least one attachment
* <P> Type: INTEGER </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String HAS_ATTACHMENT = "has_attachment";
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
=======
* Folder's count of notes
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String NOTES_COUNT = "notes_count";
/**
<<<<<<< HEAD
*
* <P> : INTEGER </P>
=======
* The file type: folder or note
* <P> Type: INTEGER </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String TYPE = "type";
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER (long) </P>
=======
* The last sync id
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String SYNC_ID = "sync_id";
/**
<<<<<<< HEAD
*
* <P> : INTEGER </P>
=======
* Sign to indicate local modified or not
* <P> Type: INTEGER </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String LOCAL_MODIFIED = "local_modified";
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER </P>
=======
* Original parent id before moving into temporary folder
* <P> Type : INTEGER </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String ORIGIN_PARENT_ID = "origin_parent_id";
/**
<<<<<<< HEAD
* gtask ID
* <P> : TEXT </P>
=======
* The gtask id
* <P> Type : TEXT </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String GTASK_ID = "gtask_id";
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
=======
* The version code
* <P> Type : INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String VERSION = "version";
}
public interface DataColumns {
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER (long) </P>
=======
* The unique ID for a row
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String ID = "_id";
/**
<<<<<<< HEAD
* MIME
* <P> : Text </P>
=======
* The MIME type of the item represented by this row.
* <P> Type: Text </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String MIME_TYPE = "mime_type";
/**
<<<<<<< HEAD
* ID
* <P> : INTEGER (long) </P>
=======
* The reference id to note that this data belongs to
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String NOTE_ID = "note_id";
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
=======
* Created data for note or folder
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String CREATED_DATE = "created_date";
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
=======
* Latest modified date
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String MODIFIED_DATE = "modified_date";
/**
<<<<<<< HEAD
*
* <P> : TEXT </P>
*/
@ -207,36 +364,73 @@ public class Notes {
/**
* {@link #MIMETYPE}
* <P> : INTEGER </P>
=======
* Data's content
* <P> Type: TEXT </P>
*/
public static final String CONTENT = "content";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* integer data type
* <P> Type: INTEGER </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String DATA1 = "data1";
/**
<<<<<<< HEAD
* {@link #MIMETYPE}
* <P> : INTEGER </P>
=======
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* integer data type
* <P> Type: INTEGER </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String DATA2 = "data2";
/**
<<<<<<< HEAD
* {@link #MIMETYPE}
* <P> : TEXT </P>
=======
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* TEXT data type
* <P> Type: TEXT </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String DATA3 = "data3";
/**
<<<<<<< HEAD
* {@link #MIMETYPE}
* <P> : TEXT </P>
=======
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* TEXT data type
* <P> Type: TEXT </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String DATA4 = "data4";
/**
<<<<<<< HEAD
* {@link #MIMETYPE}
* <P> : TEXT </P>
=======
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* TEXT data type
* <P> Type: TEXT </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String DATA5 = "data5";
}
public static final class TextNote implements DataColumns {
/**
<<<<<<< HEAD
*
* <P> : Integer 1: 0: </P>
*/
@ -249,16 +443,36 @@ 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"); // 笔记内容URI
=======
* 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;
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";
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");
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
public static final class CallNote implements DataColumns {
/**
<<<<<<< HEAD
*
* <P> : INTEGER (long) </P>
=======
* Call date for this record
* <P> Type: INTEGER (long) </P>
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public static final String CALL_DATE = DATA1;
/**
<<<<<<< HEAD
*
* <P> : TEXT </P>
*/
@ -270,4 +484,18 @@ public class Notes {
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); // 通话记录内容URI
}
}
}
=======
* 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";
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");
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -26,6 +26,7 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
<<<<<<< HEAD
public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db"; // 数据库名称
private static final int DB_VERSION = 4; // 数据库版本
@ -77,11 +78,71 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
")";
// 创建数据表的索引
=======
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";
public static final String DATA = "data";
}
private static final String TAG = "NotesDatabaseHelper";
private static NotesDatabaseHelper mInstance;
private static final String CREATE_NOTE_TABLE_SQL =
"CREATE TABLE " + TABLE.NOTE + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," +
NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +
NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +
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" +
")";
private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" +
DataColumns.ID + " INTEGER PRIMARY KEY," +
DataColumns.MIME_TYPE + " TEXT NOT NULL," +
DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA1 + " INTEGER," +
DataColumns.DATA2 + " INTEGER," +
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")";
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
<<<<<<< HEAD
// 触发器:更新笔记时增加文件夹的笔记数量
=======
/**
* Increase folder's note count when move note to the folder
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -91,7 +152,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
" END";
<<<<<<< HEAD
// 触发器:更新笔记时减少文件夹的笔记数量
=======
/**
* Decrease folder's note count when move note from folder
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
@ -102,7 +169,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" AND " + NoteColumns.NOTES_COUNT + ">0" + ";" +
" END";
<<<<<<< HEAD
// 触发器:插入新笔记时增加文件夹的笔记数量
=======
/**
* Increase folder's note count when insert new note to the folder
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
" AFTER INSERT ON " + TABLE.NOTE +
@ -112,7 +185,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
" END";
<<<<<<< HEAD
// 触发器:删除笔记时减少文件夹的笔记数量
=======
/**
* Decrease folder's note count when delete note from the folder
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -123,7 +202,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" AND " + NoteColumns.NOTES_COUNT + ">0;" +
" END";
<<<<<<< HEAD
// 触发器:插入数据时更新笔记内容
=======
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
" AFTER INSERT ON " + TABLE.DATA +
@ -134,7 +219,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
" END";
<<<<<<< HEAD
// 触发器:更新数据时更新笔记内容
=======
/**
* Update note's content when data with {@link DataConstants#NOTE} type has changed
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " +
" AFTER UPDATE ON " + TABLE.DATA +
@ -145,7 +236,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
" END";
<<<<<<< HEAD
// 触发器:删除数据时更新笔记内容
=======
/**
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " +
" AFTER delete ON " + TABLE.DATA +
@ -156,7 +253,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" +
" END";
<<<<<<< HEAD
// 触发器:删除笔记时删除相关数据
=======
/**
* Delete datas belong to note which has been deleted
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -165,7 +268,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" +
" END";
<<<<<<< HEAD
// 触发器:删除文件夹时删除相关笔记
=======
/**
* Delete notes belong to folder which has been deleted
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
" AFTER DELETE ON " + TABLE.NOTE +
@ -174,7 +283,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
<<<<<<< HEAD
// 触发器:将移动到垃圾箱的文件夹中的笔记移动到垃圾箱
=======
/**
* Move notes belong to folder which has been moved to trash folder
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " +
" AFTER UPDATE ON " + TABLE.NOTE +
@ -185,11 +300,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
<<<<<<< HEAD
// 构造函数,初始化数据库助手
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
<<<<<<< HEAD
// 创建笔记表
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL); // 执行创建表的SQL
@ -201,6 +320,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
// 重新创建笔记表的触发器
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
// 删除旧的触发器
=======
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
createSystemFolder(db);
Log.d(TAG, "note table has been created");
}
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_delete");
@ -209,7 +338,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("DROP TRIGGER IF EXISTS folder_delete_notes_on_delete");
db.execSQL("DROP TRIGGER IF EXISTS folder_move_notes_on_trash");
<<<<<<< HEAD
// 创建新的触发器
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER);
db.execSQL(NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER);
@ -219,34 +351,62 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
<<<<<<< HEAD
// 创建系统文件夹
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
// 创建通话记录文件夹
=======
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
/**
* call record foler for call notes
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
values.put(NoteColumns.ID, Notes.ID_CALL_RECORD_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
<<<<<<< HEAD
// 创建根文件夹
=======
/**
* root folder which is default folder
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
values.clear();
values.put(NoteColumns.ID, Notes.ID_ROOT_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
<<<<<<< HEAD
// 创建临时文件夹
=======
/**
* temporary folder which is used for moving note
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
values.clear();
values.put(NoteColumns.ID, Notes.ID_TEMPARAY_FOLDER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
<<<<<<< HEAD
// 创建垃圾箱文件夹
=======
/**
* create trash folder
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
values.clear();
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
}
<<<<<<< HEAD
// 创建数据表
public void createDataTable(SQLiteDatabase db) {
db.execSQL(CREATE_DATA_TABLE_SQL); // 执行创建表的SQL
@ -258,58 +418,106 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
// 重新创建数据表的触发器
private void reCreateDataTableTriggers(SQLiteDatabase db) {
// 删除旧的触发器
=======
public void createDataTable(SQLiteDatabase db) {
db.execSQL(CREATE_DATA_TABLE_SQL);
reCreateDataTableTriggers(db);
db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);
Log.d(TAG, "data table has been created");
}
private void reCreateDataTableTriggers(SQLiteDatabase db) {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_delete");
<<<<<<< HEAD
// 创建新的触发器
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER);
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER);
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
<<<<<<< HEAD
// 获取单例实例
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context); // 创建新实例
}
return mInstance; // 返回实例
=======
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
}
return mInstance;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
@Override
public void onCreate(SQLiteDatabase db) {
<<<<<<< HEAD
createNoteTable(db); // 创建笔记表
createDataTable(db); // 创建数据表
=======
createNoteTable(db);
createDataTable(db);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
<<<<<<< HEAD
boolean reCreateTriggers = false; // 是否重新创建触发器
boolean skipV2 = false; // 是否跳过版本2的升级
if (oldVersion == 1) {
upgradeToV2(db); // 升级到版本2
skipV2 = true; // 跳过版本2
=======
boolean reCreateTriggers = false;
boolean skipV2 = false;
if (oldVersion == 1) {
upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
oldVersion++;
}
if (oldVersion == 2 && !skipV2) {
<<<<<<< HEAD
upgradeToV3(db); // 升级到版本3
reCreateTriggers = true; // 需要重新创建触发器
=======
upgradeToV3(db);
reCreateTriggers = true;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
oldVersion++;
}
if (oldVersion == 3) {
<<<<<<< HEAD
upgradeToV4(db); // 升级到版本4
oldVersion++;
}
// 如果需要,重新创建触发器
=======
upgradeToV4(db);
oldVersion++;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (reCreateTriggers) {
reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db);
}
<<<<<<< HEAD
// 检查版本是否一致
if (oldVersion != newVersion) {
throw new IllegalStateException("Upgrade notes database to version " + newVersion
@ -335,15 +543,47 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID
+ " TEXT NOT NULL DEFAULT ''");
// 添加垃圾箱系统文件夹
=======
if (oldVersion != newVersion) {
throw new IllegalStateException("Upgrade notes database to version " + newVersion
+ "fails");
}
}
private void upgradeToV2(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
createNoteTable(db);
createDataTable(db);
}
private void upgradeToV3(SQLiteDatabase db) {
// drop unused triggers
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_delete");
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_update");
// add a column for gtask id
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.GTASK_ID
+ " TEXT NOT NULL DEFAULT ''");
// add a trash system folder
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
ContentValues values = new ContentValues();
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
}
<<<<<<< HEAD
// 升级到版本4
private void upgradeToV4(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0"); // 添加版本号列
}
}
}
=======
private void upgradeToV4(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0");
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -16,6 +16,10 @@
package net.micode.notes.data;
<<<<<<< HEAD
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentUris;
@ -33,6 +37,7 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
<<<<<<< HEAD
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher; // URI匹配器
@ -52,6 +57,26 @@ public class NotesProvider extends ContentProvider {
static {
mMatcher = new UriMatcher(UriMatcher.NO_MATCH); // 初始化URI匹配器
// 添加URI匹配规则
=======
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
private NotesDatabaseHelper mHelper;
private static final String TAG = "NotesProvider";
private static final int URI_NOTE = 1;
private static final int URI_NOTE_ITEM = 2;
private static final int URI_DATA = 3;
private static final int URI_DATA_ITEM = 4;
private static final int URI_SEARCH = 5;
private static final int URI_SEARCH_SUGGEST = 6;
static {
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
@ -62,8 +87,13 @@ public class NotesProvider extends ContentProvider {
}
/**
<<<<<<< HEAD
* x'0A'sqlite'\n'
* '\n'
=======
* x'0A' represents the '\n' character in sqlite. For title and content in the search result,
* we will trim '\n' and white space in order to show more information.
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
@ -73,7 +103,10 @@ public class NotesProvider extends ContentProvider {
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
<<<<<<< HEAD
// 搜索笔记摘要的SQL查询
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
+ " FROM " + TABLE.NOTE
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
@ -82,13 +115,19 @@ public class NotesProvider extends ContentProvider {
@Override
public boolean onCreate() {
<<<<<<< HEAD
mHelper = NotesDatabaseHelper.getInstance(getContext()); // 获取数据库助手实例
return true; // 创建成功
=======
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
<<<<<<< HEAD
Cursor c = null; // 游标
SQLiteDatabase db = mHelper.getReadableDatabase(); // 获取可读数据库
String id = null; // ID变量
@ -114,11 +153,38 @@ public class NotesProvider extends ContentProvider {
case URI_SEARCH:
case URI_SEARCH_SUGGEST:
// 不允许在搜索查询中指定排序、选择、选择参数或投影
=======
Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null;
switch (mMatcher.match(uri)) {
case URI_NOTE:
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
sortOrder);
break;
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
break;
case URI_DATA:
c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
sortOrder);
break;
case URI_DATA_ITEM:
id = uri.getPathSegments().get(1);
c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
break;
case URI_SEARCH:
case URI_SEARCH_SUGGEST:
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (sortOrder != null || projection != null) {
throw new IllegalArgumentException(
"do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
}
<<<<<<< HEAD
String searchString = null; // 搜索字符串
if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
if (uri.getPathSegments().size() > 1) {
@ -147,10 +213,41 @@ public class NotesProvider extends ContentProvider {
c.setNotificationUri(getContext().getContentResolver(), uri); // 设置通知URI
}
return c; // 返回游标
=======
String searchString = null;
if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
if (uri.getPathSegments().size() > 1) {
searchString = uri.getPathSegments().get(1);
}
} else {
searchString = uri.getQueryParameter("pattern");
}
if (TextUtils.isEmpty(searchString)) {
return null;
}
try {
searchString = String.format("%%%s%%", searchString);
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
new String[] { searchString });
} catch (IllegalStateException ex) {
Log.e(TAG, "got exception: " + ex.toString());
}
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (c != null) {
c.setNotificationUri(getContext().getContentResolver(), uri);
}
return c;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
@Override
public Uri insert(Uri uri, ContentValues values) {
<<<<<<< HEAD
SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写数据库
long dataId = 0, noteId = 0, insertedId = 0; // ID变量
switch (mMatcher.match(uri)) { // 根据URI匹配
@ -169,22 +266,51 @@ public class NotesProvider extends ContentProvider {
throw new IllegalArgumentException("Unknown URI " + uri); // 未知URI异常
}
// 通知笔记URI
=======
SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) {
case URI_NOTE:
insertedId = noteId = db.insert(TABLE.NOTE, null, values);
break;
case URI_DATA:
if (values.containsKey(DataColumns.NOTE_ID)) {
noteId = values.getAsLong(DataColumns.NOTE_ID);
} else {
Log.d(TAG, "Wrong data format without note id:" + values.toString());
}
insertedId = dataId = db.insert(TABLE.DATA, null, values);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
// Notify the note uri
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (noteId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
}
<<<<<<< HEAD
// 通知数据URI
=======
// Notify the data uri
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (dataId > 0) {
getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
}
<<<<<<< HEAD
return ContentUris.withAppendedId(uri, insertedId); // 返回插入的URI
=======
return ContentUris.withAppendedId(uri, insertedId);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
<<<<<<< HEAD
int count = 0; // 删除计数
String id = null; // ID变量
SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写数据库
@ -223,10 +349,55 @@ public class NotesProvider extends ContentProvider {
getContext().getContentResolver().notifyChange(uri, null); // 通知数据URI
}
return count; // 返回删除计数
=======
int count = 0;
String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean deleteData = false;
switch (mMatcher.match(uri)) {
case URI_NOTE:
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
count = db.delete(TABLE.NOTE, selection, selectionArgs);
break;
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
/**
* ID that smaller than 0 is system folder which is not allowed to
* trash
*/
long noteId = Long.valueOf(id);
if (noteId <= 0) {
break;
}
count = db.delete(TABLE.NOTE,
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
break;
case URI_DATA:
count = db.delete(TABLE.DATA, selection, selectionArgs);
deleteData = true;
break;
case URI_DATA_ITEM:
id = uri.getPathSegments().get(1);
count = db.delete(TABLE.DATA,
DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
deleteData = true;
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (count > 0) {
if (deleteData) {
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
}
getContext().getContentResolver().notifyChange(uri, null);
}
return count;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
<<<<<<< HEAD
int count = 0; // 更新计数
String id = null; // ID变量
SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写数据库
@ -254,10 +425,40 @@ public class NotesProvider extends ContentProvider {
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri); // 未知URI异常
=======
int count = 0;
String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean updateData = false;
switch (mMatcher.match(uri)) {
case URI_NOTE:
increaseNoteVersion(-1, selection, selectionArgs);
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
break;
case URI_NOTE_ITEM:
id = uri.getPathSegments().get(1);
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs);
break;
case URI_DATA:
count = db.update(TABLE.DATA, values, selection, selectionArgs);
updateData = true;
break;
case URI_DATA_ITEM:
id = uri.getPathSegments().get(1);
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
+ parseSelection(selection), selectionArgs);
updateData = true;
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
if (count > 0) {
if (updateData) {
<<<<<<< HEAD
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null); // 通知笔记URI
}
getContext().getContentResolver().notifyChange(uri, null); // 通知数据URI
@ -266,17 +467,32 @@ public class NotesProvider extends ContentProvider {
}
// 解析选择条件
=======
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
}
getContext().getContentResolver().notifyChange(uri, null);
}
return count;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
<<<<<<< HEAD
// 增加笔记版本
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120); // SQL语句构建器
=======
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
sql.append("UPDATE ");
sql.append(TABLE.NOTE);
sql.append(" SET ");
sql.append(NoteColumns.VERSION);
<<<<<<< HEAD
sql.append("=" + NoteColumns.VERSION + "+1 "); // 增加版本号
if (id > 0 || !TextUtils.isEmpty(selection)) {
@ -284,21 +500,46 @@ public class NotesProvider extends ContentProvider {
}
if (id > 0) {
sql.append(NoteColumns.ID + "=" + String.valueOf(id)); // 根据ID更新
=======
sql.append("=" + NoteColumns.VERSION + "+1 ");
if (id > 0 || !TextUtils.isEmpty(selection)) {
sql.append(" WHERE ");
}
if (id > 0) {
sql.append(NoteColumns.ID + "=" + String.valueOf(id));
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
if (!TextUtils.isEmpty(selection)) {
String selectString = id > 0 ? parseSelection(selection) : selection;
for (String args : selectionArgs) {
<<<<<<< HEAD
selectString = selectString.replaceFirst("\\?", args); // 替换选择参数
}
sql.append(selectString); // 添加选择条件
}
mHelper.getWritableDatabase().execSQL(sql.toString()); // 执行SQL语句
=======
selectString = selectString.replaceFirst("\\?", args);
}
sql.append(selectString);
}
mHelper.getWritableDatabase().execSQL(sql.toString());
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub
<<<<<<< HEAD
return null; // 返回类型(未实现)
}
}
}
=======
return null;
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -15,7 +15,10 @@
*/
package net.micode.notes.model;
<<<<<<< HEAD
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentUris;
@ -34,6 +37,7 @@ import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
<<<<<<< HEAD
public class Note {
private ContentValues mNoteDiffValues; // 存储笔记的差异值
private NoteData mNoteData; // 存储笔记数据的对象
@ -189,10 +193,162 @@ public class Note {
// 推送数据到内容解析器
Uri pushIntoContentResolver(Context context, long noteId) {
// 检查笔记ID有效性
=======
public class Note {
private ContentValues mNoteDiffValues;
private NoteData mNoteData;
private static final String TAG = "Note";
/**
* Create a new note id for adding a new note to databases
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// 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);
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0;
}
if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId);
}
return noteId;
}
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
public long getTextDataId() {
return mNoteData.mTextDataId;
}
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
}
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
if (!isLocalModified()) {
return true;
}
/**
* In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and
* {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the
* 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) {
/**
* Check for safety
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
<<<<<<< HEAD
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); // 操作列表
ContentProviderOperation.Builder builder = null; // 操作构建器
@ -260,4 +416,71 @@ public class Note {
return null; // 返回null
}
}
}
}
=======
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null;
if(mTextDataValues.size() > 0) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues);
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();
}
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) {
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;
}
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -31,6 +31,7 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
<<<<<<< HEAD
public class WorkingNote {
// 当前工作笔记对象
private Note mNote;
@ -54,6 +55,39 @@ public class WorkingNote {
private NoteSettingChangedListener mNoteSettingStatusListener; // 笔记设置状态监听器
// 数据投影
=======
public class WorkingNote {
// Note for the working note
private Note mNote;
// Note Id
private long mNoteId;
// Note content
private String mContent;
// Note mode
private int mMode;
private long mAlertDate;
private long mModifiedDate;
private int mBgColorId;
private int mWidgetId;
private int mWidgetType;
private long mFolderId;
private Context mContext;
private static final String TAG = "WorkingNote";
private boolean mIsDeleted;
private NoteSettingChangedListener mNoteSettingStatusListener;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
@ -64,7 +98,10 @@ public class WorkingNote {
DataColumns.DATA4,
};
<<<<<<< HEAD
// 笔记投影
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
@ -74,6 +111,7 @@ public class WorkingNote {
NoteColumns.MODIFIED_DATE
};
<<<<<<< HEAD
// 数据列索引
private static final int DATA_ID_COLUMN = 0;
private static final int DATA_CONTENT_COLUMN = 1;
@ -89,11 +127,35 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// 新建笔记构造函数
=======
private static final int DATA_ID_COLUMN = 0;
private static final int DATA_CONTENT_COLUMN = 1;
private static final int DATA_MIME_TYPE_COLUMN = 2;
private static final int DATA_MODE_COLUMN = 3;
private static final int NOTE_PARENT_ID_COLUMN = 0;
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
private static final int NOTE_WIDGET_ID_COLUMN = 3;
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
mModifiedDate = System.currentTimeMillis();
mFolderId = folderId;
<<<<<<< HEAD
mNote = new Note(); // 初始化笔记对象
mNoteId = 0;
mIsDeleted = false;
@ -102,16 +164,33 @@ public class WorkingNote {
}
// 现有笔记构造函数
=======
mNote = new Note();
mNoteId = 0;
mIsDeleted = false;
mMode = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
// Existing note construct
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
mFolderId = folderId;
mIsDeleted = false;
<<<<<<< HEAD
mNote = new Note(); // 初始化笔记对象
loadNote(); // 加载笔记数据
}
// 加载笔记信息
=======
mNote = new Note();
loadNote();
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private void loadNote() {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
@ -119,7 +198,10 @@ public class WorkingNote {
if (cursor != null) {
if (cursor.moveToFirst()) {
<<<<<<< HEAD
// 从游标中获取笔记信息
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
@ -127,15 +209,25 @@ public class WorkingNote {
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
}
<<<<<<< HEAD
cursor.close(); // 关闭游标
=======
cursor.close();
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
} else {
Log.e(TAG, "No note with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
}
<<<<<<< HEAD
loadNoteData(); // 加载笔记数据
}
// 加载笔记数据
=======
loadNoteData();
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private void loadNoteData() {
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
@ -149,21 +241,32 @@ public class WorkingNote {
if (DataConstants.NOTE.equals(type)) {
mContent = cursor.getString(DATA_CONTENT_COLUMN);
mMode = cursor.getInt(DATA_MODE_COLUMN);
<<<<<<< HEAD
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN)); // 设置文本数据ID
} else if (DataConstants.CALL_NOTE.equals(type)) {
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN)); // 设置通话数据ID
=======
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
} else if (DataConstants.CALL_NOTE.equals(type)) {
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
} else {
Log.d(TAG, "Wrong note type with type:" + type);
}
} while (cursor.moveToNext());
}
<<<<<<< HEAD
cursor.close(); // 关闭游标
=======
cursor.close();
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
} else {
Log.e(TAG, "No data with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
}
}
<<<<<<< HEAD
// 创建空笔记
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
@ -175,11 +278,25 @@ public class WorkingNote {
}
// 加载现有笔记
=======
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
note.setBgColorId(defaultBgColorId);
note.setWidgetId(widgetId);
note.setWidgetType(widgetType);
return note;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0);
}
<<<<<<< HEAD
// 保存笔记
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public synchronized boolean saveNote() {
if (isWorthSaving()) {
if (!existInDatabase()) {
@ -189,9 +306,17 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
mNote.syncNote(mContext, mNoteId); // 同步笔记到数据库
// 更新小部件内容
=======
mNote.syncNote(mContext, mNoteId);
/**
* Update widget content if there exist any widget of this note
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
&& mNoteSettingStatusListener != null) {
@ -203,12 +328,18 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 检查笔记是否存在于数据库中
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public boolean existInDatabase() {
return mNoteId > 0;
}
<<<<<<< HEAD
// 检查笔记是否值得保存
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
@ -218,12 +349,18 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 设置笔记设置状态监听器
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
<<<<<<< HEAD
// 设置提醒日期
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
@ -234,7 +371,10 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 标记笔记为已删除
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void markDeleted(boolean mark) {
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -243,7 +383,10 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 设置背景颜色ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
@ -254,7 +397,10 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 设置检查列表模式
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
@ -265,7 +411,10 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 设置小部件类型
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
@ -273,7 +422,10 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 设置小部件ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
@ -281,7 +433,10 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 设置工作文本
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;
@ -289,95 +444,159 @@ public class WorkingNote {
}
}
<<<<<<< HEAD
// 转换为通话笔记
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
}
<<<<<<< HEAD
// 检查是否有提醒
public boolean hasClockAlert() {
return (mAlertDate > 0);
}
// 获取笔记内容
=======
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public String getContent() {
return mContent;
}
<<<<<<< HEAD
// 获取提醒日期
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getAlertDate() {
return mAlertDate;
}
<<<<<<< HEAD
// 获取修改日期
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getModifiedDate() {
return mModifiedDate;
}
<<<<<<< HEAD
// 获取背景颜色资源ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
<<<<<<< HEAD
// 获取背景颜色ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getBgColorId() {
return mBgColorId;
}
<<<<<<< HEAD
// 获取标题背景资源ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
<<<<<<< HEAD
// 获取检查列表模式
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getCheckListMode() {
return mMode;
}
<<<<<<< HEAD
// 获取笔记ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getNoteId() {
return mNoteId;
}
<<<<<<< HEAD
// 获取文件夹ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getFolderId() {
return mFolderId;
}
<<<<<<< HEAD
// 获取小部件ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getWidgetId() {
return mWidgetId;
}
<<<<<<< HEAD
// 获取小部件类型
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getWidgetType() {
return mWidgetType;
}
<<<<<<< HEAD
// 笔记设置状态监听器接口
public interface NoteSettingChangedListener {
/**
*
=======
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
void onBackgroundColorChanged();
/**
<<<<<<< HEAD
*
=======
* Called when user set clock
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
void onClockAlertChanged(long date, boolean set);
/**
<<<<<<< HEAD
*
=======
* Call when user create note from widget
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
void onWidgetChanged();
/**
<<<<<<< HEAD
*
* @param oldMode
* @param newMode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}
}
}
=======
* Call when switch between check list mode and normal mode
* @param oldMode is previous mode before change
* @param newMode is new mode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -35,6 +35,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
<<<<<<< HEAD
public class BackupUtils {
private static final String TAG = "BackupUtils"; // 日志标签
// Singleton instance
@ -44,11 +45,23 @@ public class BackupUtils {
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
sInstance = new BackupUtils(context); // 创建实例
=======
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);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
return sInstance;
}
/**
<<<<<<< HEAD
*
*/
// 当前SD卡未挂载
@ -69,26 +82,61 @@ public class BackupUtils {
}
// 检查外部存储是否可用
=======
* 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);
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
<<<<<<< HEAD
// 导出到文本文件
public int exportToText() {
return mTextExport.exportToText(); // 调用文本导出方法
}
// 获取导出的文本文件名
=======
public int exportToText() {
return mTextExport.exportToText();
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public String getExportedTextFileName() {
return mTextExport.mFileName;
}
<<<<<<< HEAD
// 获取导出的文本文件目录
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
}
<<<<<<< HEAD
// 内部类用于文本导出
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static class TextExport {
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
@ -98,7 +146,13 @@ public class BackupUtils {
};
private static final int NOTE_COLUMN_ID = 0;
<<<<<<< HEAD
private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
=======
private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private static final int NOTE_COLUMN_SNIPPET = 2;
private static final String[] DATA_PROJECTION = {
@ -111,6 +165,7 @@ public class BackupUtils {
};
private static final int DATA_COLUMN_CONTENT = 0;
<<<<<<< HEAD
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;
@ -126,17 +181,41 @@ public class BackupUtils {
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); // 获取格式数组
=======
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;
private final String [] TEXT_FORMAT;
private static final int FORMAT_FOLDER_NAME = 0;
private static final int FORMAT_NOTE_DATE = 1;
private static final int FORMAT_NOTE_CONTENT = 2;
private Context mContext;
private String mFileName;
private String mFileDirectory;
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
mContext = context;
mFileName = "";
mFileDirectory = "";
}
<<<<<<< HEAD
// 获取指定格式的字符串
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
/**
<<<<<<< HEAD
*
*/
private void exportFolderToText(String folderId, PrintStream ps) {
@ -144,11 +223,21 @@ public class BackupUtils {
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[]{
folderId
=======
* 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
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}, null);
if (notesCursor != null) {
if (notesCursor.moveToFirst()) {
do {
<<<<<<< HEAD
// 打印笔记的最后修改日期
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
@ -159,16 +248,37 @@ public class BackupUtils {
} while (notesCursor.moveToNext());
}
notesCursor.close(); // 关闭游标
=======
// 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();
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
}
/**
<<<<<<< HEAD
* ID
*/
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[]{
noteId
=======
* 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,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}, null);
if (dataCursor != null) {
@ -176,13 +286,18 @@ public class BackupUtils {
do {
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
if (DataConstants.CALL_NOTE.equals(mimeType)) {
<<<<<<< HEAD
// 打印电话号码
=======
// Print phone number
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
String location = dataCursor.getString(DATA_COLUMN_CONTENT);
if (!TextUtils.isEmpty(phoneNumber)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
<<<<<<< HEAD
phoneNumber)); // 打印电话号码
}
// 打印通话日期
@ -190,6 +305,15 @@ public class BackupUtils {
.format(mContext.getString(R.string.format_datetime_mdhm),
callDate)));
// 打印通话附件位置
=======
phoneNumber));
}
// Print call date
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
.format(mContext.getString(R.string.format_datetime_mdhm),
callDate)));
// Print call attachment location
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (!TextUtils.isEmpty(location)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location));
@ -198,16 +322,28 @@ public class BackupUtils {
String content = dataCursor.getString(DATA_COLUMN_CONTENT);
if (!TextUtils.isEmpty(content)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
<<<<<<< HEAD
content)); // 打印笔记内容
=======
content));
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
}
} while (dataCursor.moveToNext());
}
<<<<<<< HEAD
dataCursor.close(); // 关闭游标
}
// 在笔记之间打印分隔行
try {
ps.write(new byte[]{
=======
dataCursor.close();
}
// print a line separator between note
try {
ps.write(new byte[] {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
});
} catch (IOException e) {
@ -216,11 +352,16 @@ public class BackupUtils {
}
/**
<<<<<<< HEAD
*
=======
* Note will be exported as text which is user readable
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
public int exportToText() {
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted");
<<<<<<< HEAD
return STATE_SD_CARD_UNMOUONTED; // SD卡未挂载
}
@ -230,6 +371,17 @@ public class BackupUtils {
return STATE_SYSTEM_ERROR; // 系统错误
}
// 首先导出文件夹及其笔记
=======
return STATE_SD_CARD_UNMOUONTED;
}
PrintStream ps = getExportToTextPrintStream();
if (ps == null) {
Log.e(TAG, "get print stream error");
return STATE_SYSTEM_ERROR;
}
// First export folder and its notes
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
@ -240,14 +392,21 @@ public class BackupUtils {
if (folderCursor != null) {
if (folderCursor.moveToFirst()) {
do {
<<<<<<< HEAD
// 打印文件夹名称
String folderName = "";
if (folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
=======
// Print folder's name
String folderName = "";
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
folderName = mContext.getString(R.string.call_record_folder_name);
} else {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
}
if (!TextUtils.isEmpty(folderName)) {
<<<<<<< HEAD
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName)); // 打印文件夹名称
}
String folderId = folderCursor.getString(NOTE_COLUMN_ID);
@ -262,6 +421,22 @@ public class BackupUtils {
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
=======
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
}
String folderId = folderCursor.getString(NOTE_COLUMN_ID);
exportFolderToText(folderId, ps);
} while (folderCursor.moveToNext());
}
folderCursor.close();
}
// Export notes in root's folder
Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
+ "=0", null, null);
if (noteCursor != null) {
@ -270,6 +445,7 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
<<<<<<< HEAD
// 查询属于该笔记的数据
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps); // 导出笔记数据
@ -306,10 +482,49 @@ public class BackupUtils {
return null; // 空指针异常
}
return ps; // 返回打印流
=======
// Query data belong to this note
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
}
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,
R.string.file_name_txt_format);
if (file == null) {
Log.e(TAG, "create file to exported failed");
return null;
}
mFileName = file.getName();
mFileDirectory = mContext.getString(R.string.file_path);
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
e.printStackTrace();
return null;
} catch (NullPointerException e) {
e.printStackTrace();
return null;
}
return ps;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
}
/**
<<<<<<< HEAD
*
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
@ -339,4 +554,38 @@ public class BackupUtils {
return null; // 返回null表示失败
}
}
}
=======
* 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());
sb.append(context.getString(filePathResId));
File filedir = new File(sb.toString());
sb.append(context.getString(
fileNameFormatResId,
DateFormat.format(context.getString(R.string.format_date_ymd),
System.currentTimeMillis())));
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();
}
return null;
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -34,6 +34,7 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList;
import java.util.HashSet;
<<<<<<< HEAD
public class DataUtils {
public static final String TAG = "DataUtils"; // 日志标签
@ -46,10 +47,24 @@ public class DataUtils {
if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset");
return true; // 如果没有ID返回true
=======
public class DataUtils {
public static final String 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;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {
<<<<<<< HEAD
if (id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root"); // 不允许删除根文件夹
continue;
@ -89,10 +104,49 @@ public class DataUtils {
if (ids == null) {
Log.d(TAG, "the ids is null");
return true; // 如果ID集合为空返回true
=======
if(id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root");
continue;
}
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());
}
try {
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;
} 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;
}
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {
<<<<<<< HEAD
// 创建更新操作
ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
@ -143,16 +197,70 @@ public class DataUtils {
}
// 检查笔记是否在数据库中可见
=======
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.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
return 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;
}
/**
* 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;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
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,
<<<<<<< HEAD
new String[] { String.valueOf(type) },
=======
new String [] {String.valueOf(type)},
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
<<<<<<< HEAD
exist = true; // 存在
}
cursor.close(); // 关闭游标
@ -161,6 +269,15 @@ public class DataUtils {
}
// 检查笔记是否存在于数据库中
=======
exist = true;
}
cursor.close();
}
return exist;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -168,6 +285,7 @@ public class DataUtils {
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
<<<<<<< HEAD
exist = true; // 存在
}
cursor.close(); // 关闭游标
@ -176,6 +294,15 @@ public class DataUtils {
}
// 检查数据是否存在于数据数据库中
=======
exist = true;
}
cursor.close();
}
return exist;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
@ -183,6 +310,7 @@ public class DataUtils {
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
<<<<<<< HEAD
exist = true; // 存在
}
cursor.close(); // 关闭游标
@ -191,6 +319,15 @@ public class DataUtils {
}
// 检查文件夹名称是否可见
=======
exist = true;
}
cursor.close();
}
return exist;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
@ -198,6 +335,7 @@ public class DataUtils {
" AND " + NoteColumns.SNIPPET + "=?",
new String[] { name }, null);
boolean exist = false;
<<<<<<< HEAD
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true; // 存在
@ -208,6 +346,17 @@ public class DataUtils {
}
// 获取指定文件夹的笔记小部件
=======
if(cursor != null) {
if(cursor.getCount() > 0) {
exist = true;
}
cursor.close();
}
return exist;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
@ -222,6 +371,7 @@ public class DataUtils {
do {
try {
AppWidgetAttribute widget = new AppWidgetAttribute();
<<<<<<< HEAD
widget.widgetId = c.getInt(0); // 获取小部件ID
widget.widgetType = c.getInt(1); // 获取小部件类型
set.add(widget); // 添加到集合
@ -241,10 +391,31 @@ public class DataUtils {
new String[] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
new String[] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
=======
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();
}
return set;
}
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
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 },
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
null);
if (cursor != null && cursor.moveToFirst()) {
try {
<<<<<<< HEAD
return cursor.getString(0); // 返回通话号码
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString()); // 记录异常
@ -262,11 +433,30 @@ public class DataUtils {
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
+ CallNote.PHONE_NUMBER + ",?)",
new String[] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
=======
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) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
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 },
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
<<<<<<< HEAD
return cursor.getLong(0); // 返回笔记ID
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString()); // 记录异常
@ -283,11 +473,29 @@ public class DataUtils {
new String[] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?",
new String[] { String.valueOf(noteId) },
=======
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) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?",
new String [] { String.valueOf(noteId)},
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
null);
if (cursor != null) {
String snippet = "";
if (cursor.moveToFirst()) {
<<<<<<< HEAD
snippet = cursor.getString(0); // 获取摘要
}
cursor.close(); // 关闭游标
@ -307,4 +515,25 @@ public class DataUtils {
}
return snippet; // 返回格式化后的摘要
}
}
}
=======
snippet = cursor.getString(0);
}
cursor.close();
return snippet;
}
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
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;
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -16,6 +16,7 @@
package net.micode.notes.tool;
<<<<<<< HEAD
// GTaskStringUtils类用于定义与Google任务GTask相关的常量字符串
public class GTaskStringUtils {
@ -68,4 +69,101 @@ public class GTaskStringUtils {
public final static String META_HEAD_NOTE = "meta_note"; // 元数据头部:笔记
public final static String META_HEAD_DATA = "meta_data"; // 元数据头部:数据
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE"; // 元数据笔记名称
}
}
=======
public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_ID = "action_id";
public final static String GTASK_JSON_ACTION_LIST = "action_list";
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
public final static String GTASK_JSON_COMPLETED = "completed";
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
public final static String GTASK_JSON_DELETED = "deleted";
public final static String GTASK_JSON_DEST_LIST = "dest_list";
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
public final static String GTASK_JSON_ID = "id";
public final static String GTASK_JSON_INDEX = "index";
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
public final static String GTASK_JSON_LIST_ID = "list_id";
public final static String GTASK_JSON_LISTS = "lists";
public final static String GTASK_JSON_NAME = "name";
public final static String GTASK_JSON_NEW_ID = "new_id";
public final static String GTASK_JSON_NOTES = "notes";
public final static String GTASK_JSON_PARENT_ID = "parent_id";
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
public final static String GTASK_JSON_RESULTS = "results";
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
public final static String GTASK_JSON_TASKS = "tasks";
public final static String GTASK_JSON_TYPE = "type";
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
public final static String GTASK_JSON_TYPE_TASK = "TASK";
public final static String GTASK_JSON_USER = "user";
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
public final static String FOLDER_DEFAULT = "Default";
public final static String FOLDER_CALL_NOTE = "Call_Note";
public final static String FOLDER_META = "METADATA";
public final static String META_HEAD_GTASK_ID = "meta_gid";
public final static String META_HEAD_NOTE = "meta_note";
public final static String META_HEAD_DATA = "meta_data";
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -22,6 +22,7 @@ import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
<<<<<<< HEAD
// ResourceParser类用于解析和管理与笔记相关的资源如背景颜色、字体大小等
public class ResourceParser {
@ -45,6 +46,26 @@ public class ResourceParser {
// 笔记背景资源管理
public static class NoteBgResources {
// 编辑状态下的背景资源数组
=======
public class ResourceParser {
public static final int YELLOW = 0;
public static final int BLUE = 1;
public static final int WHITE = 2;
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;
public static final int TEXT_SUPER = 3;
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
public static class NoteBgResources {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
R.drawable.edit_blue,
@ -53,7 +74,10 @@ public class ResourceParser {
R.drawable.edit_red
};
<<<<<<< HEAD
// 编辑状态下标题的背景资源数组
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
@ -62,6 +86,7 @@ public class ResourceParser {
R.drawable.edit_title_red
};
<<<<<<< HEAD
// 根据ID获取笔记背景资源
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id]; // 返回对应ID的背景资源
@ -88,6 +113,27 @@ public class ResourceParser {
// 笔记项背景资源管理
public static class NoteItemBgResources {
// 列表中第一个笔记项的背景资源数组
=======
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[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 {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up,
R.drawable.list_blue_up,
@ -96,7 +142,10 @@ public class ResourceParser {
R.drawable.list_red_up
};
<<<<<<< HEAD
// 列表中正常状态的笔记项背景资源数组
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle,
R.drawable.list_blue_middle,
@ -105,7 +154,10 @@ public class ResourceParser {
R.drawable.list_red_middle
};
<<<<<<< HEAD
// 列表中最后一个笔记项的背景资源数组
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down,
R.drawable.list_blue_down,
@ -114,7 +166,10 @@ public class ResourceParser {
R.drawable.list_red_down,
};
<<<<<<< HEAD
// 列表中单个笔记项的背景资源数组
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
@ -123,26 +178,39 @@ public class ResourceParser {
R.drawable.list_red_single
};
<<<<<<< HEAD
// 根据ID获取第一个笔记项的背景资源
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
<<<<<<< HEAD
// 根据ID获取最后一个笔记项的背景资源
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
<<<<<<< HEAD
// 根据ID获取单个笔记项的背景资源
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
<<<<<<< HEAD
// 根据ID获取正常状态的笔记项背景资源
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
<<<<<<< HEAD
// 获取文件夹背景资源
public static int getFolderBgRes() {
return R.drawable.list_folder; // 返回文件夹背景资源
@ -152,6 +220,14 @@ public class ResourceParser {
// 小部件背景资源管理
public static class WidgetBgResources {
// 2x小部件的背景资源数组
=======
public static int getFolderBgRes() {
return R.drawable.list_folder;
}
}
public static class WidgetBgResources {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
@ -160,12 +236,18 @@ public class ResourceParser {
R.drawable.widget_2x_red,
};
<<<<<<< HEAD
// 根据ID获取2x小部件的背景资源
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
<<<<<<< HEAD
// 4x小部件的背景资源数组
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
@ -174,12 +256,16 @@ public class ResourceParser {
R.drawable.widget_4x_red
};
<<<<<<< HEAD
// 根据ID获取4x小部件的背景资源
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id];
}
}
<<<<<<< HEAD
// 文本外观资源管理
public static class TextAppearanceResources {
// 文本外观资源数组
@ -191,6 +277,16 @@ public class ResourceParser {
};
// 根据ID获取文本外观资源
=======
public static class TextAppearanceResources {
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium,
R.style.TextAppearanceLarge,
R.style.TextAppearanceSuper
};
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
@ -198,6 +294,7 @@ public class ResourceParser {
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
<<<<<<< HEAD
return BG_DEFAULT_FONT_SIZE; // 如果ID超出范围返回默认字体大小
}
return TEXTAPPEARANCE_RESOURCES[id]; // 返回对应ID的文本外观资源
@ -208,4 +305,16 @@ public class ResourceParser {
return TEXTAPPEARANCE_RESOURCES.length; // 返回文本外观资源的数量
}
}
}
}
=======
return BG_DEFAULT_FONT_SIZE;
}
return TEXTAPPEARANCE_RESOURCES[id];
}
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -15,7 +15,10 @@
*/
package net.micode.notes.widget;
<<<<<<< HEAD
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
@ -33,6 +36,7 @@ import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
<<<<<<< HEAD
// NoteWidgetProvider是一个抽象类负责管理笔记小部件的更新和交互
public abstract class NoteWidgetProvider extends AppWidgetProvider {
// 定义查询所需的列
@ -43,10 +47,20 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
};
// 列索引常量
=======
public abstract class NoteWidgetProvider extends AppWidgetProvider {
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET
};
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static final int COLUMN_ID = 0;
public static final int COLUMN_BG_COLOR_ID = 1;
public static final int COLUMN_SNIPPET = 2;
<<<<<<< HEAD
private static final String TAG = "NoteWidgetProvider"; // 日志标签
// 当小部件被删除时调用
@ -56,6 +70,15 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); // 设置无效的小部件ID
for (int i = 0; i < appWidgetIds.length; i++) {
// 更新数据库清除小部件ID
=======
private static final String TAG = "NoteWidgetProvider";
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
ContentValues values = new ContentValues();
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
for (int i = 0; i < appWidgetIds.length; i++) {
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
context.getContentResolver().update(Notes.CONTENT_NOTE_URI,
values,
NoteColumns.WIDGET_ID + "=?",
@ -63,7 +86,10 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
<<<<<<< HEAD
// 获取小部件相关的笔记信息
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
@ -72,16 +98,24 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
null);
}
<<<<<<< HEAD
// 更新小部件的方法
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false); // 默认不使用隐私模式
}
// 更新小部件的具体实现
=======
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false);
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) {
for (int i = 0; i < appWidgetIds.length; i++) {
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
<<<<<<< HEAD
int bgId = ResourceParser.getDefaultBgId(context); // 获取默认背景ID
String snippet = ""; // 初始化摘要
Intent intent = new Intent(context, NoteEditActivity.class); // 创建编辑笔记的意图
@ -116,25 +150,73 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId); // 传递背景ID
/**
* PendingIntent
=======
int bgId = ResourceParser.getDefaultBgId(context);
String snippet = "";
Intent intent = new Intent(context, NoteEditActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]);
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType());
Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]);
if (c != null && c.moveToFirst()) {
if (c.getCount() > 1) {
Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]);
c.close();
return;
}
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);
} 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
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
PendingIntent pendingIntent = null;
if (privacyMode) {
rv.setTextViewText(R.id.widget_text,
<<<<<<< HEAD
context.getString(R.string.widget_under_visit_mode)); // 设置隐私模式文本
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent(
context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
} else {
rv.setTextViewText(R.id.widget_text, snippet); // 设置摘要文本
=======
context.getString(R.string.widget_under_visit_mode));
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent(
context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
} else {
rv.setTextViewText(R.id.widget_text, snippet);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
<<<<<<< HEAD
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent); // 设置点击事件
appWidgetManager.updateAppWidget(appWidgetIds[i], rv); // 更新小部件
=======
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
}
}
}
<<<<<<< HEAD
// 抽象方法获取背景资源ID
protected abstract int getBgResourceId(int bgId);
@ -143,4 +225,12 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
// 抽象方法,获取小部件类型
protected abstract int getWidgetType();
}
}
=======
protected abstract int getBgResourceId(int bgId);
protected abstract int getLayoutId();
protected abstract int getWidgetType();
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -23,6 +23,7 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
<<<<<<< HEAD
// NoteWidgetProvider_2x类继承自NoteWidgetProvider专门用于处理2x大小的小部件
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
// 更新小部件时调用的方法
@ -48,4 +49,28 @@ public class NoteWidgetProvider_2x extends NoteWidgetProvider {
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X; // 返回2x小部件的类型常量
}
}
}
=======
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
@Override
protected int getLayoutId() {
return R.layout.widget_2x;
}
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -23,6 +23,7 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
<<<<<<< HEAD
// NoteWidgetProvider_4x类继承自NoteWidgetProvider专门用于处理4x大小的小部件
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
// 更新小部件时调用的方法
@ -48,4 +49,27 @@ public class NoteWidgetProvider_4x extends NoteWidgetProvider {
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X; // 返回4x小部件的类型常量
}
}
}
=======
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
protected int getLayoutId() {
return R.layout.widget_4x;
}
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -0,0 +1,6 @@
军 512650 dz 512651 jdy 512652
073187022650
报修 87022078
jdy 17608499969
dz 18873173510
救护 87027672
Loading…
Cancel
Save