Compare commits
17 Commits
lzx_branch
...
master
Author | SHA1 | Date |
---|---|---|
LWJ | 202c78eab3 | 1 year ago |
LWJ | 5af2a57d47 | 1 year ago |
LWJ | 87d17414e8 | 1 year ago |
LWJ | 172a9881ab | 1 year ago |
LWJ | 7ff029d41e | 1 year ago |
LWJ | 89af40b9c3 | 1 year ago |
LWJ | 59f3e1459b | 1 year ago |
LWJ | fe06515a77 | 1 year ago |
LWJ | 0cbcbc5efc | 1 year ago |
LWJ | 37fa3414a7 | 2 years ago |
LWJ | 531bdd05ab | 2 years ago |
LWJ | a1cf16893f | 2 years ago |
LWJ | 83bb9090f2 | 2 years ago |
LWJ | 1fb13cb91d | 2 years ago |
LWJ | 126d4b0e53 | 2 years ago |
LWJ | d6cdaa8362 | 2 years ago |
LWJ | d1ae975e8d | 2 years ago |
After Width: | Height: | Size: 144 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 62 KiB |
After Width: | Height: | Size: 104 KiB |
After Width: | Height: | Size: 211 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 128 KiB |
After Width: | Height: | Size: 88 KiB |
After Width: | Height: | Size: 125 KiB |
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 147 KiB |
@ -0,0 +1,255 @@
|
||||
/*
|
||||
* 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.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;//输出日志,比如说出错、警告等
|
||||
|
||||
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.NoteColumns;
|
||||
import net.micode.notes.data.Notes.TextNote;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class Note {
|
||||
// private ContentValues mNoteDiffValues;
|
||||
private ContentValues mNoteDiffValues;
|
||||
private NoteData mNoteData;
|
||||
private static final String TAG = "Note";
|
||||
/**
|
||||
* Create a new note id for adding a new note to databases
|
||||
*/
|
||||
public static synchronized long getNewNoteId(Context context, long folderId) {
|
||||
// Create a new note in the database
|
||||
ContentValues values = new ContentValues();
|
||||
long createdTime = System.currentTimeMillis();
|
||||
values.put(NoteColumns.CREATED_DATE, createdTime);
|
||||
values.put(NoteColumns.MODIFIED_DATE, createdTime);
|
||||
values.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
|
||||
values.put(NoteColumns.LOCAL_MODIFIED, 1);
|
||||
values.put(NoteColumns.PARENT_ID, folderId);//将数据写入数据库表格
|
||||
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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";
|
||||
// 定义字符串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;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
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);
|
||||
}//布局文件,设置标题
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
#Fri Apr 14 10:37:54 CST 2023
|
||||
gradle.version=6.1.1
|
@ -0,0 +1,3 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="11" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="BintrayJCenter" />
|
||||
<option name="name" value="BintrayJCenter" />
|
||||
<option name="url" value="https://jcenter.bintray.com/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="Android" />
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,19 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 22
|
||||
buildToolsVersion "21.0.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "net.micode.notes"
|
||||
minSdkVersion 14
|
||||
//targetSdkVersion 14
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
}
|