Merge branch 'master' of https://bdgit.educoder.net/pfqs8cjuk/gitProject
# Conflicts: # other/06_标注/210340013_李赫桐_代码标注/BackupUtils.java # other/06_标注/210340013_李赫桐_代码标注/DataUtils.java # other/06_标注/210340013_李赫桐_代码标注/GTaskStringUtils.java # other/06_标注/210340013_李赫桐_代码标注/Note.java # other/06_标注/210340013_李赫桐_代码标注/ResourceParser.java # other/06_标注/210340013_李赫桐_代码标注/WorkingNote.java # other/06_标注/210340013_李赫桐_代码标注/widget.java # other/06_标注/210340024_阮钰琳_代码标注/FoldersListAdapter.doc # other/06_标注/210340024_阮钰琳_代码标注/FoldersListAdapter.java # other/06_标注/210340024_阮钰琳_代码标注/NoteEditActivity.doc # other/06_标注/210340024_阮钰琳_代码标注/NoteEditActivity.java # other/06_标注/210340024_阮钰琳_代码标注/NoteEditText.doc # other/06_标注/210340024_阮钰琳_代码标注/NoteEditText.java # other/06_标注/210340024_阮钰琳_代码标注/NoteItemData.doc # other/06_标注/210340024_阮钰琳_代码标注/NoteItemData.java # other/06_标注/210340024_阮钰琳_代码标注/NotesListActivity.doc # other/06_标注/210340024_阮钰琳_代码标注/NotesListActivity.java # other/06_标注/210340024_阮钰琳_代码标注/NotesListAdapter.doc # other/06_标注/210340024_阮钰琳_代码标注/NotesListAdapter.java # other/06_标注/210340041_郑培萱_代码标注/AlarmAlertActivity.java # other/06_标注/210340041_郑培萱_代码标注/AlarmInitReceiver.java # other/06_标注/210340041_郑培萱_代码标注/AlarmReceiver.java # other/06_标注/210340041_郑培萱_代码标注/DateTimePicker.java # other/06_标注/210340041_郑培萱_代码标注/DateTimePickerDialog.java # other/06_标注/210340041_郑培萱_代码标注/DropdownMenu.java # other/06_标注/210340041_郑培萱_代码标注/FoldersListAdapter.java # other/06_标注/210340041_郑培萱_代码标注/NotesListItem.java # other/06_标注/210340041_郑培萱_代码标注/NotesPreferenceActivity.java # other/06_标注/210340042-周施怡_代码标注/ActionFailureException.java # other/06_标注/210340042-周施怡_代码标注/GTaskASyncTask.java # other/06_标注/210340042-周施怡_代码标注/GTaskClient.java # other/06_标注/210340042-周施怡_代码标注/MetaData.java # other/06_标注/210340042-周施怡_代码标注/NetworkFailureException.java # other/06_标注/210340042-周施怡_代码标注/Node.java # other/06_标注/210340042-周施怡_代码标注/SqlData.java # other/06_标注/210340042-周施怡_代码标注/SqlNote.java # other/06_标注/210340042-周施怡_代码标注/Task.java # other/06_标注/210340042-周施怡_代码标注/TaskList.java # other/06_标注/210340044_左丹妮_代码标注/Contact.docx # other/06_标注/210340044_左丹妮_代码标注/Contact.java # other/06_标注/210340044_左丹妮_代码标注/Data_Notes_NoteColumns.jpg # other/06_标注/210340044_左丹妮_代码标注/GTaskManager.docx # other/06_标注/210340044_左丹妮_代码标注/GTaskManager.java # other/06_标注/210340044_左丹妮_代码标注/GTaskSyncService.docx # other/06_标注/210340044_左丹妮_代码标注/GTaskSyncService.java # other/06_标注/210340044_左丹妮_代码标注/Gtask_remote_GTaskMnager.jpg # other/06_标注/210340044_左丹妮_代码标注/Gtask_remote_GTaskMnager_initGTaskList.jpg # other/06_标注/210340044_左丹妮_代码标注/Gtask_remote_GTaskMnager_initGTaskList2.jpg # other/06_标注/210340044_左丹妮_代码标注/Gtask_remote_GTaskMnager_initGTaskList3.jpg # other/06_标注/210340044_左丹妮_代码标注/Gtask_remote_GTaskMnager_syncContent.jpg # other/06_标注/210340044_左丹妮_代码标注/Gtask_remote_GTaskMnager_updateRemoteNodejpg.jpg # other/06_标注/210340044_左丹妮_代码标注/Gtask_remote_GTaskSyncService_onBind.jpg # other/06_标注/210340044_左丹妮_代码标注/Notes.docx # other/06_标注/210340044_左丹妮_代码标注/Notes.java # other/06_标注/210340044_左丹妮_代码标注/NotesDatabaseHelper.docx # other/06_标注/210340044_左丹妮_代码标注/NotesDatabaseHelper.java # other/06_标注/210340044_左丹妮_代码标注/NotesProvider.docx # other/06_标注/210340044_左丹妮_代码标注/NotesProvider.javamaster
@ -1,232 +0,0 @@
|
||||
package net.micode.notes.model;
|
||||
|
||||
import android.content.ContentProviderOperation;//批量的更新、插入、删除数据。
|
||||
import android.content.ContentProviderResult;//操作的结果
|
||||
import android.content.ContentUris;//用于添加和获取Uri后面的ID
|
||||
import android.content.ContentValues;//一种用来存储基本数据类型数据的存储机制
|
||||
import android.content.Context;//需要用该类来弄清楚调用者的实例
|
||||
import android.content.OperationApplicationException;//操作应用程序容错
|
||||
import android.net.Uri;//表示待操作的数据
|
||||
import android.os.RemoteException;//远程容错
|
||||
import android.util.Log;//输出日志,比如说出错、警告等
|
||||
|
||||
public class Note {
|
||||
// private ContentValues mNoteDiffValues;
|
||||
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);
|
||||
//ContentResolver()主要是实现外部应用对ContentProvider中的数据
|
||||
//进行添加、删除、修改和查询操作
|
||||
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;
|
||||
}//try-catch异常处理
|
||||
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);
|
||||
}//设置文本数据的ID
|
||||
|
||||
public long getTextDataId() {
|
||||
return mNoteData.mTextDataId;
|
||||
}//得到文本数据的ID
|
||||
|
||||
public void setCallDataId(long id) {
|
||||
mNoteData.setCallDataId(id);
|
||||
}//设置电话号码数据的ID
|
||||
|
||||
public void setCallData(String key, String value) {
|
||||
mNoteData.setCallData(key, value);
|
||||
}//得到电话号码数据的ID
|
||||
|
||||
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的操作存储到数据库
|
||||
Uri pushIntoContentResolver(Context context, long noteId) {
|
||||
/**
|
||||
* Check for safety
|
||||
*/
|
||||
if (noteId <= 0) {
|
||||
throw new IllegalArgumentException("Wrong note id:" + noteId);
|
||||
}//判断数据是否合法
|
||||
|
||||
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();
|
||||
}//把文本数据存入DataColumns
|
||||
|
||||
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();
|
||||
}//把电话号码数据存入DataColumns
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
.micode.notes.widget;
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import net.micode.notes.R;
|
||||
import net.micode.notes.data.Notes;
|
||||
import net.micode.notes.data.Notes.NoteColumns;
|
||||
import net.micode.notes.tool.ResourceParser;
|
||||
import net.micode.notes.ui.NoteEditActivity;
|
||||
import net.micode.notes.ui.NotesListActivity;
|
||||
|
||||
public abstract class NoteWidgetProvider extends AppWidgetProvider {
|
||||
public static final String [] PROJECTION = new String [] {
|
||||
NoteColumns.ID,
|
||||
NoteColumns.BG_COLOR_ID,
|
||||
NoteColumns.SNIPPET
|
||||
};
|
||||
|
||||
public static final int COLUMN_ID = 0;
|
||||
public static final int COLUMN_BG_COLOR_ID = 1;
|
||||
public static final int COLUMN_SNIPPET = 2;
|
||||
|
||||
private static final String TAG = "NoteWidgetProvider";
|
||||
|
||||
@Override
|
||||
public void onDeleted(Context context, int[] appWidgetIds) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||
for (int i = 0; i < appWidgetIds.length; i++) {
|
||||
context.getContentResolver().update(Notes.CONTENT_NOTE_URI,
|
||||
values,
|
||||
NoteColumns.WIDGET_ID + "=?",
|
||||
new String[] { String.valueOf(appWidgetIds[i])});
|
||||
}
|
||||
}
|
||||
|
||||
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
|
||||
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
|
||||
PROJECTION,
|
||||
NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",
|
||||
new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },
|
||||
null);
|
||||
}
|
||||
|
||||
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
update(context, appWidgetManager, appWidgetIds, false);
|
||||
}
|
||||
|
||||
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
|
||||
boolean privacyMode) {
|
||||
for (int i = 0; i < appWidgetIds.length; i++) {
|
||||
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
|
||||
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
|
||||
*/
|
||||
PendingIntent pendingIntent = null;
|
||||
if (privacyMode) {
|
||||
rv.setTextViewText(R.id.widget_text,
|
||||
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);
|
||||
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
|
||||
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract int getBgResourceId(int bgId);
|
||||
|
||||
protected abstract int getLayoutId();
|
||||
|
||||
protected abstract int getWidgetType();
|
||||
}
|
@ -1,68 +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.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);
|
||||
}
|
||||
}
|
@ -1,82 +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;
|
||||
//change
|
||||
public class Contact { //联系人
|
||||
private static HashMap<String, String> sContactCache;
|
||||
private static final String TAG = "Contact";
|
||||
|
||||
// 定义字符串CALLER_ID_SELECTION
|
||||
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
|
||||
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
|
||||
+ " AND " + Data.RAW_CONTACT_ID + " IN "
|
||||
+ "(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>();
|
||||
}
|
||||
|
||||
// 查找HashMap中是否已有phoneNumber信息
|
||||
if(sContactCache.containsKey(phoneNumber)) {
|
||||
return sContactCache.get(phoneNumber);
|
||||
}
|
||||
|
||||
String selection = CALLER_ID_SELECTION.replace("+",
|
||||
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
|
||||
// 查找数据库中phoneNumber的信息
|
||||
Cursor cursor = context.getContentResolver().query(
|
||||
Data.CONTENT_URI,
|
||||
new String [] { Phone.DISPLAY_NAME },
|
||||
selection,
|
||||
new String[] { phoneNumber },
|
||||
null);
|
||||
|
||||
// 判定查询结果
|
||||
// moveToFirst()返回第一条
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
try {
|
||||
// 找到相关信息
|
||||
String name = cursor.getString(0);
|
||||
sContactCache.put(phoneNumber, name);
|
||||
return name;
|
||||
// 异常
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Log.e(TAG, " Cursor get string error " + e.toString());
|
||||
return null;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
// 未找到相关信息
|
||||
} else {
|
||||
Log.d(TAG, "No contact matched with number:" + phoneNumber);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,82 +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;
|
||||
//change
|
||||
public class Contact { //联系人
|
||||
private static HashMap<String, String> sContactCache;
|
||||
private static final String TAG = "Contact";
|
||||
|
||||
// 定义字符串CALLER_ID_SELECTION
|
||||
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
|
||||
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
|
||||
+ " AND " + Data.RAW_CONTACT_ID + " IN "
|
||||
+ "(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>();
|
||||
}
|
||||
|
||||
// 查找HashMap中是否已有phoneNumber信息
|
||||
if(sContactCache.containsKey(phoneNumber)) {
|
||||
return sContactCache.get(phoneNumber);
|
||||
}
|
||||
|
||||
String selection = CALLER_ID_SELECTION.replace("+",
|
||||
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
|
||||
// 查找数据库中phoneNumber的信息
|
||||
Cursor cursor = context.getContentResolver().query(
|
||||
Data.CONTENT_URI,
|
||||
new String [] { Phone.DISPLAY_NAME },
|
||||
selection,
|
||||
new String[] { phoneNumber },
|
||||
null);
|
||||
|
||||
// 判定查询结果
|
||||
// moveToFirst()返回第一条
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
try {
|
||||
// 找到相关信息
|
||||
String name = cursor.getString(0);
|
||||
sContactCache.put(phoneNumber, name);
|
||||
return name;
|
||||
// 异常
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
Log.e(TAG, " Cursor get string error " + e.toString());
|
||||
return null;
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
// 未找到相关信息
|
||||
} else {
|
||||
Log.d(TAG, "No contact matched with number:" + phoneNumber);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 107 KiB |
Before Width: | Height: | Size: 104 KiB |
Before Width: | Height: | Size: 165 KiB |
Before Width: | Height: | Size: 139 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 37 KiB |
Before Width: | Height: | Size: 17 KiB |