parent
8d860e7a00
commit
c1a759803c
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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";// 用于日志输出的 TAG
|
||||
|
||||
// 查询电话号码与联系人名字匹配的过滤条件
|
||||
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 = '+')";
|
||||
/*
|
||||
* 获取电话号码对应的联系人名字
|
||||
* @param context 上下文
|
||||
* @param phoneNumber 电话号码
|
||||
* @return 电话号码对应的联系人名字
|
||||
*/
|
||||
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 {// 如果未能查询到联系人信息,输出日志并返回 null
|
||||
Log.d(TAG, "No contact matched with number:" + phoneNumber);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
public class GTaskStringUtils {
|
||||
|
||||
public final static String GTASK_JSON_ACTION_ID = "action_id";// 行动 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";// 创建者 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";// 当前清单 ID
|
||||
|
||||
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id"; // 默认清单 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";// 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"; // 清单 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";// 新 ID
|
||||
|
||||
public final static String GTASK_JSON_NOTES = "notes";// 备注
|
||||
|
||||
public final static String GTASK_JSON_PARENT_ID = "parent_id";// 父 ID
|
||||
|
||||
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";// 上一个同级 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]"; // MIUI 笔记前缀
|
||||
|
||||
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";// GTASK ID 元数据头
|
||||
|
||||
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";// 元数据笔记名称
|
||||
|
||||
}
|
Loading…
Reference in new issue