parent
03aa61caa0
commit
6564f0086c
Binary file not shown.
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.data;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||
import android.provider.ContactsContract.Data;
|
||||
import android.telephony.PhoneNumberUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Contact {
|
||||
private static HashMap<String, String> sContactCache;
|
||||
private static final String TAG = "Contact";
|
||||
|
||||
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
|
||||
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
|
||||
+ " AND " + Data.RAW_CONTACT_ID + " IN "
|
||||
+ "(SELECT raw_contact_id "
|
||||
+ " FROM phone_lookup"
|
||||
+ " WHERE min_match = '+')";
|
||||
|
||||
public static String getContact(Context context, String phoneNumber) {
|
||||
if(sContactCache == null) {
|
||||
sContactCache = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
if(sContactCache.containsKey(phoneNumber)) {
|
||||
return sContactCache.get(phoneNumber);
|
||||
}
|
||||
|
||||
String selection = CALLER_ID_SELECTION.replace("+",
|
||||
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
|
||||
Cursor cursor = context.getContentResolver().query(
|
||||
Data.CONTENT_URI,
|
||||
new String [] { Phone.DISPLAY_NAME },
|
||||
selection,
|
||||
new String[] { phoneNumber },
|
||||
null);
|
||||
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
try {
|
||||
String name = cursor.getString(0);
|
||||
sContactCache.put(phoneNumber, name);
|
||||
return name;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Log.e(TAG, " Cursor get string error " + e.toString());
|
||||
return null;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "No contact matched with number:" + phoneNumber);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,589 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.data;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.util.Log;
|
||||
|
||||
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; // 数据库版本
|
||||
|
||||
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; // 单例实例
|
||||
|
||||
// 创建笔记表的SQL语句
|
||||
private static final String CREATE_NOTE_TABLE_SQL =
|
||||
"CREATE TABLE " + TABLE.NOTE + "(" +
|
||||
NoteColumns.ID + " INTEGER PRIMARY KEY," + // 笔记ID
|
||||
NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + // 父ID
|
||||
NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," + // 提醒日期
|
||||
NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," + // 背景颜色ID
|
||||
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," + // 小部件ID
|
||||
NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," + // 小部件类型
|
||||
NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," + // 同步ID
|
||||
NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," + // 本地修改标记
|
||||
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + // 原始父ID
|
||||
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," + // gtask ID
|
||||
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" + // 版本号
|
||||
")";
|
||||
|
||||
// 创建数据表的SQL语句
|
||||
private static final String CREATE_DATA_TABLE_SQL =
|
||||
"CREATE TABLE " + TABLE.DATA + "(" +
|
||||
DataColumns.ID + " INTEGER PRIMARY KEY," + // 数据ID
|
||||
DataColumns.MIME_TYPE + " TEXT NOT NULL," + // MIME类型
|
||||
DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," + // 关联的笔记ID
|
||||
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," + // 通用数据列1
|
||||
DataColumns.DATA2 + " INTEGER," + // 通用数据列2
|
||||
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," + // 通用数据列3
|
||||
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," + // 通用数据列4
|
||||
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" + // 通用数据列5
|
||||
")";
|
||||
|
||||
// 创建数据表的索引
|
||||
=======
|
||||
|
||||
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 +
|
||||
" BEGIN " +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
||||
" 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 +
|
||||
" BEGIN " +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
||||
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
||||
" 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 +
|
||||
" BEGIN " +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
||||
" 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 +
|
||||
" BEGIN " +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
||||
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
||||
" 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 +
|
||||
" WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
||||
" BEGIN" +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
||||
" 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 +
|
||||
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
||||
" BEGIN" +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
||||
" 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 +
|
||||
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
||||
" BEGIN" +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.SNIPPET + "=''" +
|
||||
" 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 +
|
||||
" BEGIN" +
|
||||
" DELETE FROM " + TABLE.DATA +
|
||||
" 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 +
|
||||
" BEGIN" +
|
||||
" DELETE FROM " + TABLE.NOTE +
|
||||
" 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 +
|
||||
" WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
||||
" BEGIN" +
|
||||
" UPDATE " + TABLE.NOTE +
|
||||
" SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
||||
" 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
|
||||
reCreateNoteTableTriggers(db); // 重新创建触发器
|
||||
createSystemFolder(db); // 创建系统文件夹
|
||||
Log.d(TAG, "note table has been created"); // 日志记录
|
||||
}
|
||||
|
||||
// 重新创建笔记表的触发器
|
||||
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");
|
||||
db.execSQL("DROP TRIGGER IF EXISTS delete_data_on_delete");
|
||||
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_insert");
|
||||
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);
|
||||
db.execSQL(NOTE_DELETE_DATA_ON_DELETE_TRIGGER);
|
||||
db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);
|
||||
db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);
|
||||
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
|
||||
reCreateDataTableTriggers(db); // 重新创建触发器
|
||||
db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL); // 创建索引
|
||||
Log.d(TAG, "data table has been created"); // 日志记录
|
||||
}
|
||||
|
||||
// 重新创建数据表的触发器
|
||||
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
|
||||
+ " fails"); // 抛出异常
|
||||
}
|
||||
}
|
||||
|
||||
// 升级到版本2
|
||||
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); // 创建数据表
|
||||
}
|
||||
|
||||
// 升级到版本3
|
||||
private void upgradeToV3(SQLiteDatabase db) {
|
||||
// 删除未使用的触发器
|
||||
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");
|
||||
// 为gtask ID添加新列
|
||||
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
|
@ -1,602 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.model;
|
||||
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import net.micode.notes.data.Notes;
|
||||
import net.micode.notes.data.Notes.CallNote;
|
||||
import net.micode.notes.data.Notes.DataColumns;
|
||||
import net.micode.notes.data.Notes.DataConstants;
|
||||
import net.micode.notes.data.Notes.NoteColumns;
|
||||
import net.micode.notes.data.Notes.TextNote;
|
||||
import net.micode.notes.tool.ResourceParser.NoteBgResources;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public class WorkingNote {
|
||||
// 当前工作笔记对象
|
||||
private Note mNote;
|
||||
// 笔记ID
|
||||
private long mNoteId;
|
||||
// 笔记内容
|
||||
private String mContent;
|
||||
// 笔记模式
|
||||
private int mMode;
|
||||
|
||||
private long mAlertDate; // 提醒日期
|
||||
private long mModifiedDate; // 修改日期
|
||||
private int mBgColorId; // 背景颜色ID
|
||||
private int mWidgetId; // 小部件ID
|
||||
private int mWidgetType; // 小部件类型
|
||||
private long mFolderId; // 文件夹ID
|
||||
private Context mContext; // 上下文
|
||||
|
||||
private static final String TAG = "WorkingNote"; // 日志标签
|
||||
private boolean mIsDeleted; // 是否已删除
|
||||
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,
|
||||
DataColumns.MIME_TYPE,
|
||||
DataColumns.DATA1,
|
||||
DataColumns.DATA2,
|
||||
DataColumns.DATA3,
|
||||
DataColumns.DATA4,
|
||||
};
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 笔记投影
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public static final String[] NOTE_PROJECTION = new String[] {
|
||||
NoteColumns.PARENT_ID,
|
||||
NoteColumns.ALERTED_DATE,
|
||||
NoteColumns.BG_COLOR_ID,
|
||||
NoteColumns.WIDGET_ID,
|
||||
NoteColumns.WIDGET_TYPE,
|
||||
NoteColumns.MODIFIED_DATE
|
||||
};
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 数据列索引
|
||||
private static final int DATA_ID_COLUMN = 0;
|
||||
private static final int DATA_CONTENT_COLUMN = 1;
|
||||
private static final int DATA_MIME_TYPE_COLUMN = 2;
|
||||
private static final int DATA_MODE_COLUMN = 3;
|
||||
|
||||
// 笔记列索引
|
||||
private static final int NOTE_PARENT_ID_COLUMN = 0;
|
||||
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
|
||||
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
|
||||
private static final int NOTE_WIDGET_ID_COLUMN = 3;
|
||||
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
|
||||
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
|
||||
|
||||
// 新建笔记构造函数
|
||||
=======
|
||||
private 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;
|
||||
mMode = 0;
|
||||
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; // 默认小部件类型
|
||||
}
|
||||
|
||||
// 现有笔记构造函数
|
||||
=======
|
||||
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,
|
||||
null, null);
|
||||
|
||||
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);
|
||||
mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
|
||||
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[] {
|
||||
String.valueOf(mNoteId)
|
||||
}, null);
|
||||
|
||||
if (cursor != null) {
|
||||
if (cursor.moveToFirst()) {
|
||||
do {
|
||||
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
|
||||
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) {
|
||||
WorkingNote note = new WorkingNote(context, folderId);
|
||||
note.setBgColorId(defaultBgColorId); // 设置默认背景颜色
|
||||
note.setWidgetId(widgetId); // 设置小部件ID
|
||||
note.setWidgetType(widgetType); // 设置小部件类型
|
||||
return note;
|
||||
}
|
||||
|
||||
// 加载现有笔记
|
||||
=======
|
||||
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()) {
|
||||
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
|
||||
Log.e(TAG, "Create new note fail with id:" + mNoteId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< 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) {
|
||||
mNoteSettingStatusListener.onWidgetChanged();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 检查笔记是否存在于数据库中
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public boolean existInDatabase() {
|
||||
return mNoteId > 0;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 检查笔记是否值得保存
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
private boolean isWorthSaving() {
|
||||
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|
||||
|| (existInDatabase() && !mNote.isLocalModified())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 设置笔记设置状态监听器
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
|
||||
mNoteSettingStatusListener = l;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 设置提醒日期
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void setAlertDate(long date, boolean set) {
|
||||
if (date != mAlertDate) {
|
||||
mAlertDate = date;
|
||||
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
|
||||
}
|
||||
if (mNoteSettingStatusListener != null) {
|
||||
mNoteSettingStatusListener.onClockAlertChanged(date, set);
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 标记笔记为已删除
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void markDeleted(boolean mark) {
|
||||
mIsDeleted = mark;
|
||||
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
|
||||
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
|
||||
mNoteSettingStatusListener.onWidgetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 设置背景颜色ID
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void setBgColorId(int id) {
|
||||
if (id != mBgColorId) {
|
||||
mBgColorId = id;
|
||||
if (mNoteSettingStatusListener != null) {
|
||||
mNoteSettingStatusListener.onBackgroundColorChanged();
|
||||
}
|
||||
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 设置检查列表模式
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void setCheckListMode(int mode) {
|
||||
if (mMode != mode) {
|
||||
if (mNoteSettingStatusListener != null) {
|
||||
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
|
||||
}
|
||||
mMode = mode;
|
||||
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 设置小部件类型
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void setWidgetType(int type) {
|
||||
if (type != mWidgetType) {
|
||||
mWidgetType = type;
|
||||
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 设置小部件ID
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void setWidgetId(int id) {
|
||||
if (id != mWidgetId) {
|
||||
mWidgetId = id;
|
||||
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
// 设置工作文本
|
||||
=======
|
||||
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
|
||||
public void setWorkingText(String text) {
|
||||
if (!TextUtils.equals(mContent, text)) {
|
||||
mContent = text;
|
||||
mNote.setTextData(DataColumns.CONTENT, mContent);
|
||||
}
|
||||
}
|
||||
|
||||
<<<<<<< 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
|
@ -1,591 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.micode.notes.tool;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.os.Environment;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
|
||||
import net.micode.notes.R;
|
||||
import net.micode.notes.data.Notes;
|
||||
import net.micode.notes.data.Notes.DataColumns;
|
||||
import net.micode.notes.data.Notes.DataConstants;
|
||||
import net.micode.notes.data.Notes.NoteColumns;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
<<<<<<< HEAD
|
||||
public class BackupUtils {
|
||||
private static final String TAG = "BackupUtils"; // 日志标签
|
||||
// Singleton instance
|
||||
private static BackupUtils sInstance;
|
||||
|
||||
// 获取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卡未挂载
|
||||
public static final int STATE_SD_CARD_UNMOUONTED = 0;
|
||||
// 备份文件不存在
|
||||
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
|
||||
// 数据格式不正确,可能被其他程序更改
|
||||
public static final int STATE_DATA_DESTROIED = 2;
|
||||
// 运行时异常导致备份或恢复失败
|
||||
public static final int STATE_SYSTEM_ERROR = 3;
|
||||
// 备份或恢复成功
|
||||
public static final int STATE_SUCCESS = 4;
|
||||
|
||||
private TextExport mTextExport; // 文本导出工具
|
||||
|
||||
private BackupUtils(Context context) {
|
||||
mTextExport = new TextExport(context); // 初始化文本导出工具
|
||||
}
|
||||
|
||||
// 检查外部存储是否可用
|
||||
=======
|
||||
* 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,
|
||||
NoteColumns.MODIFIED_DATE,
|
||||
NoteColumns.SNIPPET,
|
||||
NoteColumns.TYPE
|
||||
};
|
||||
|
||||
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 = {
|
||||
DataColumns.CONTENT,
|
||||
DataColumns.MIME_TYPE,
|
||||
DataColumns.DATA1,
|
||||
DataColumns.DATA2,
|
||||
DataColumns.DATA3,
|
||||
DataColumns.DATA4,
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
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); // 获取格式数组
|
||||
=======
|
||||
|
||||
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) {
|
||||
// 查询属于该文件夹的笔记
|
||||
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),
|
||||
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
|
||||
// 查询属于该笔记的数据
|
||||
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
|
||||
exportNoteToText(noteId, ps); // 导出笔记数据
|
||||
} 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) {
|
||||
if (dataCursor.moveToFirst()) {
|
||||
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)); // 打印电话号码
|
||||
}
|
||||
// 打印通话日期
|
||||
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
|
||||
.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));
|
||||
}
|
||||
} else if (DataConstants.NOTE.equals(mimeType)) {
|
||||
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) {
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
<<<<<<< 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卡未挂载
|
||||
}
|
||||
|
||||
PrintStream ps = getExportToTextPrintStream(); // 获取打印流
|
||||
if (ps == null) {
|
||||
Log.e(TAG, "get print stream error");
|
||||
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,
|
||||
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
|
||||
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
|
||||
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
|
||||
|
||||
if (folderCursor != null) {
|
||||
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);
|
||||
exportFolderToText(folderId, ps); // 导出文件夹中的笔记
|
||||
} while (folderCursor.moveToNext());
|
||||
}
|
||||
folderCursor.close(); // 关闭游标
|
||||
}
|
||||
|
||||
// 导出根文件夹中的笔记
|
||||
Cursor noteCursor = mContext.getContentResolver().query(
|
||||
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) {
|
||||
if (noteCursor.moveToFirst()) {
|
||||
do {
|
||||
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
|
||||
mContext.getString(R.string.format_datetime_mdhm),
|
||||
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
|
||||
<<<<<<< HEAD
|
||||
// 查询属于该笔记的数据
|
||||
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
|
||||
exportNoteToText(noteId, ps); // 导出笔记数据
|
||||
} while (noteCursor.moveToNext());
|
||||
}
|
||||
noteCursor.close(); // 关闭游标
|
||||
}
|
||||
ps.close(); // 关闭打印流
|
||||
|
||||
return STATE_SUCCESS; // 返回成功状态
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指向文件的打印流 {@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; // 返回打印流
|
||||
=======
|
||||
// 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) {
|
||||
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(); // IO异常
|
||||
}
|
||||
|
||||
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
|
@ -1,49 +0,0 @@
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.PopupMenu.OnMenuItemClickListener;
|
||||
|
||||
import net.micode.notes.R;
|
||||
|
||||
public class DropdownMenu {
|
||||
private Button mButton;
|
||||
private PopupMenu mPopupMenu;
|
||||
//声明一个下拉菜单
|
||||
private Menu mMenu;
|
||||
|
||||
public DropdownMenu(Context context, Button button, int menuId) {
|
||||
mButton = button;
|
||||
mButton.setBackgroundResource(R.drawable.dropdown_icon);
|
||||
//设置这个view的背景
|
||||
mPopupMenu = new PopupMenu(context, mButton);
|
||||
mMenu = mPopupMenu.getMenu();
|
||||
mPopupMenu.getMenuInflater().inflate(menuId, mMenu);
|
||||
//MenuInflater是用来实例化Menu目录下的Menu布局文件
|
||||
//根据ID来确认menu的内容选项
|
||||
mButton.setOnClickListener(new OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
mPopupMenu.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
|
||||
if (mPopupMenu != null) {
|
||||
mPopupMenu.setOnMenuItemClickListener(listener);
|
||||
}//设置菜单的监听
|
||||
}
|
||||
|
||||
public MenuItem findItem(int id) {
|
||||
return mMenu.findItem(id);
|
||||
}//对于菜单选项的初始化,根据索引搜索菜单需要的选项
|
||||
|
||||
public void setTitle(CharSequence title) {
|
||||
mButton.setText(title);
|
||||
}//布局文件,设置标题
|
||||
}
|
Loading…
Reference in new issue