zuo_branch
manic-zzz 3 months ago
parent 47f9c8b004
commit 669af3fb1a

@ -1,42 +1,16 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
/**
*
*/
package net.micode.notes.tool;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.os.RemoteException;
import android.util.Log;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList;
import java.util.HashSet;
public class DataUtils {
public static final String TAG = "DataUtils";
/**
*
*
* @param resolver ContentResolver
* @param ids ID
* @return truefalse
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null");
@ -72,6 +46,14 @@ public class DataUtils {
return false;
}
/**
*
*
* @param resolver ContentResolver
* @param id ID
* @param srcFolderId ID
* @param desFolderId ID
*/
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
@ -80,6 +62,14 @@ public class DataUtils {
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
/**
*
*
* @param resolver ContentResolver
* @param ids ID
* @param folderId ID
* @return truefalse
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
if (ids == null) {
@ -112,7 +102,10 @@ public class DataUtils {
}
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
*
*
* @param resolver ContentResolver
* @return
*/
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
@ -136,6 +129,14 @@ public class DataUtils {
return count;
}
/**
*
*
* @param resolver ContentResolver
* @param noteId ID
* @param type
* @return truefalse
*/
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
@ -153,6 +154,13 @@ public class DataUtils {
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param noteId ID
* @return truefalse
*/
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -167,6 +175,13 @@ public class DataUtils {
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param dataId ID
* @return truefalse
*/
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
@ -181,6 +196,13 @@ public class DataUtils {
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param name
* @return truefalse
*/
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
@ -197,6 +219,13 @@ public class DataUtils {
return exist;
}
/**
*
*
* @param resolver ContentResolver
* @param folderId ID
* @return
*/
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 },
@ -224,6 +253,13 @@ public class DataUtils {
return set;
}
/**
* ID
*
* @param resolver ContentResolver
* @param noteId ID
* @return
*/
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
@ -243,6 +279,14 @@ public class DataUtils {
return "";
}
/**
* ID
*
* @param resolver ContentResolver
* @param phoneNumber
* @param callDate
* @return ID0
*/
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
@ -264,6 +308,14 @@ public class DataUtils {
return 0;
}
/**
* ID
*
* @param resolver ContentResolver
* @param noteId ID
* @return
* @throws IllegalArgumentException ID
*/
public static String getSnippetById(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
@ -282,6 +334,12 @@ public class DataUtils {
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
/**
*
*
* @param snippet
* @return
*/
public static String getFormattedSnippet(String snippet) {
if (snippet != null) {
snippet = snippet.trim();
@ -292,4 +350,4 @@ public class DataUtils {
}
return snippet;
}
}
}

@ -16,98 +16,146 @@
package net.micode.notes.tool;
/**
* GoogleJSON
*/
public class GTaskStringUtils {
// Google任务JSON数据中的动作ID字段
public final static String GTASK_JSON_ACTION_ID = "action_id";
// Google任务JSON数据中的动作列表字段
public final static String GTASK_JSON_ACTION_LIST = "action_list";
// Google任务JSON数据中的动作类型字段
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
// Google任务JSON数据中的创建动作类型
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
// Google任务JSON数据中的获取所有动作类型
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
// Google任务JSON数据中的移动动作类型
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
// Google任务JSON数据中的更新动作类型
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
// Google任务JSON数据中的创建者ID字段
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
// Google任务JSON数据中的子实体字段
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
// Google任务JSON数据中的客户端版本字段
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
// Google任务JSON数据中的完成状态字段
public final static String GTASK_JSON_COMPLETED = "completed";
// Google任务JSON数据中的当前列表ID字段
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
// Google任务JSON数据中的默认列表ID字段
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
// Google任务JSON数据中的删除状态字段
public final static String GTASK_JSON_DELETED = "deleted";
// Google任务JSON数据中的目标列表字段
public final static String GTASK_JSON_DEST_LIST = "dest_list";
// Google任务JSON数据中的目标父级字段
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
// Google任务JSON数据中的目标父级类型字段
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
// Google任务JSON数据中的实体增量字段
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
// Google任务JSON数据中的实体类型字段
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
// Google任务JSON数据中的获取已删除字段
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
// Google任务JSON数据中的ID字段
public final static String GTASK_JSON_ID = "id";
// Google任务JSON数据中的索引字段
public final static String GTASK_JSON_INDEX = "index";
// Google任务JSON数据中的最后修改时间字段
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
// Google任务JSON数据中的最新同步点字段
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
// Google任务JSON数据中的列表ID字段
public final static String GTASK_JSON_LIST_ID = "list_id";
// Google任务JSON数据中的列表集合字段
public final static String GTASK_JSON_LISTS = "lists";
// Google任务JSON数据中的名称字段
public final static String GTASK_JSON_NAME = "name";
// Google任务JSON数据中的新ID字段
public final static String GTASK_JSON_NEW_ID = "new_id";
// Google任务JSON数据中的备注字段
public final static String GTASK_JSON_NOTES = "notes";
// Google任务JSON数据中的父级ID字段
public final static String GTASK_JSON_PARENT_ID = "parent_id";
// Google任务JSON数据中的前一个兄弟ID字段
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
// Google任务JSON数据中的结果字段
public final static String GTASK_JSON_RESULTS = "results";
// Google任务JSON数据中的源列表字段
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
// Google任务JSON数据中的任务集合字段
public final static String GTASK_JSON_TASKS = "tasks";
// Google任务JSON数据中的类型字段
public final static String GTASK_JSON_TYPE = "type";
// Google任务JSON数据中的组类型
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
// Google任务JSON数据中的任务类型
public final static String GTASK_JSON_TYPE_TASK = "TASK";
// Google任务JSON数据中的用户字段
public final static String GTASK_JSON_USER = "user";
// MIUI文件夹前缀
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";
// 元数据头部Google任务ID字段
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";
}
}

@ -22,24 +22,35 @@ import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
*
*/
public class ResourceParser {
// 定义笔记背景颜色常量
public static final int YELLOW = 0;
public static final int BLUE = 1;
public static final int WHITE = 2;
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 {
// 笔记编辑背景资源数组
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
R.drawable.edit_blue,
@ -48,6 +59,7 @@ public class ResourceParser {
R.drawable.edit_red
};
// 笔记编辑标题背景资源数组
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
@ -56,15 +68,33 @@ public class ResourceParser {
R.drawable.edit_title_red
};
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
/**
* ID
*
* @param context
* @return ID
*/
public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
@ -74,7 +104,11 @@ public class ResourceParser {
}
}
/**
*
*/
public static class NoteItemBgResources {
// 笔记列表项第一个的背景资源数组
private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up,
R.drawable.list_blue_up,
@ -83,6 +117,7 @@ public class ResourceParser {
R.drawable.list_red_up
};
// 笔记列表项中间的背景资源数组
private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle,
R.drawable.list_blue_middle,
@ -91,6 +126,7 @@ public class ResourceParser {
R.drawable.list_red_middle
};
// 笔记列表项最后一个的背景资源数组
private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down,
R.drawable.list_blue_down,
@ -99,6 +135,7 @@ public class ResourceParser {
R.drawable.list_red_down,
};
// 笔记列表项单个的背景资源数组
private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
@ -107,28 +144,61 @@ public class ResourceParser {
R.drawable.list_red_single
};
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
/**
* ID
*
* @param id ID
* @return ID
*/
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
/**
*
*
* @return ID
*/
public static int getFolderBgRes() {
return R.drawable.list_folder;
}
}
/**
*
*/
public static class WidgetBgResources {
// 2x小部件的背景资源数组
private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
@ -137,10 +207,17 @@ public class ResourceParser {
R.drawable.widget_2x_red,
};
/**
* ID2x
*
* @param id ID
* @return ID
*/
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
// 4x小部件的背景资源数组
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
@ -149,12 +226,22 @@ public class ResourceParser {
R.drawable.widget_4x_red
};
/**
* ID4x
*
* @param id ID
* @return ID
*/
public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id];
}
}
/**
*
*/
public static class TextAppearanceResources {
// 文本样式资源数组
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium,
@ -162,6 +249,13 @@ public class ResourceParser {
R.style.TextAppearanceSuper
};
/**
* ID
* IDID
*
* @param id ID
* @return ID
*/
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
@ -174,8 +268,13 @@ public class ResourceParser {
return TEXTAPPEARANCE_RESOURCES[id];
}
/**
*
*
* @return
*/
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}
}
Loading…
Cancel
Save