合并 #7

Merged
pgy6mavf3 merged 2 commits from main into MASTER 5 months ago

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings"> <component name="GradleSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<GradleProjectSettings> <GradleProjectSettings>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/src.iml" filepath="$PROJECT_DIR$/.idea/src.iml" />
</modules>
</component>
</project>

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/app/src/main/java/net/micode/notes/data/Notes.java" charset="GBK" />
<file url="PROJECT" charset="GBK" />
</component>
</project>

@ -1,4 +1,4 @@
#Mon Jun 03 18:57:13 CST 2024 #Fri Jun 14 17:22:29 CST 2024
C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\incremental\\mergeDebugResources\\stripped.dir\\layout\\account_dialog_title.xml=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\merged_res\\debug\\layout_account_dialog_title.xml.flat C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\incremental\\mergeDebugResources\\stripped.dir\\layout\\account_dialog_title.xml=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\merged_res\\debug\\layout_account_dialog_title.xml.flat
C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\incremental\\mergeDebugResources\\stripped.dir\\layout\\acticity_word.xml=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\merged_res\\debug\\layout_acticity_word.xml.flat C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\incremental\\mergeDebugResources\\stripped.dir\\layout\\acticity_word.xml=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\merged_res\\debug\\layout_acticity_word.xml.flat
C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\incremental\\mergeDebugResources\\stripped.dir\\layout\\activity_splash.xml=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\merged_res\\debug\\layout_activity_splash.xml.flat C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\incremental\\mergeDebugResources\\stripped.dir\\layout\\activity_splash.xml=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\merged_res\\debug\\layout_activity_splash.xml.flat

@ -1,4 +1,4 @@
#Mon Jun 03 18:57:31 CST 2024 #Fri Jun 14 17:25:48 CST 2024
base.0=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\dex\\debug\\mergeDexDebug\\classes.dex base.0=C\:\\RGDL\\ReadCodeAndAnalyse\\src\\Notesmaster\\app\\build\\intermediates\\dex\\debug\\mergeDexDebug\\classes.dex
path.0=classes.dex path.0=classes.dex
renamed.0=classes.dex renamed.0=classes.dex

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_20" default="true" project-jdk-name="20" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/notes.iml" filepath="$PROJECT_DIR$/notes.iml" />
</modules>
</component>
</project>

@ -1,19 +1,3 @@
/*
* 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; package net.micode.notes.data;
import android.content.Context; import android.content.Context;
@ -26,50 +10,50 @@ import android.util.Log;
import java.util.HashMap; import java.util.HashMap;
public class Contact { public class Contact {
private static HashMap<String, String> sContactCache; private static HashMap<String, String> sContactCache; // 联系人缓存
private static final String TAG = "Contact"; private static final String TAG = "Contact"; // 标记为联系人
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'" + ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'" // 选择ID的查询条件
+ " AND " + Data.RAW_CONTACT_ID + " IN " + " AND " + Data.RAW_CONTACT_ID + " IN "
+ "(SELECT raw_contact_id " + "(SELECT raw_contact_id "
+ " FROM phone_lookup" + " FROM phone_lookup"
+ " WHERE min_match = '+')"; + " WHERE min_match = '+')"; // 原始联系人ID查询条件
//TODO //TODO
//识别电话号码 //识别电话号码
public static String getContact(Context context, String phoneNumber) { public static String getContact(Context context, String phoneNumber) { // 获取联系人信息
if(sContactCache == null) { if(sContactCache == null) { // 如果联系人缓存为空
sContactCache = new HashMap<String, String>(); sContactCache = new HashMap<String, String>(); // 创建联系人缓存
} }
if(sContactCache.containsKey(phoneNumber)) { if(sContactCache.containsKey(phoneNumber)) { // 如果联系人缓存包含该电话号码
return sContactCache.get(phoneNumber); return sContactCache.get(phoneNumber); // 返回缓存中的联系人信息
} }
String selection = CALLER_ID_SELECTION.replace("+", String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); // 替换查询条件中的+
Cursor cursor = context.getContentResolver().query( Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI, Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME }, new String [] { Phone.DISPLAY_NAME },
selection, selection,
new String[] { phoneNumber }, new String[] { phoneNumber },
null); null); // 通过内容解析器查询联系人信息
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) { // 如果查询结果不为空且移动到第一条记录
try { try {
String name = cursor.getString(0); String name = cursor.getString(0); // 获取联系人姓名
sContactCache.put(phoneNumber, name); sContactCache.put(phoneNumber, name); // 将联系人信息放入缓存
return name; return name; // 返回联系人姓名
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
Log.e(TAG, " Cursor get string error " + e.toString()); Log.e(TAG, " Cursor get string error " + e.toString()); // 捕获索引越界异常并记录日志
return null; return null; // 返回空值
} finally { } finally {
cursor.close(); cursor.close(); // 关闭游标
} }
} else { } else {
Log.d(TAG, "No contact matched with number:" + phoneNumber); Log.d(TAG, "No contact matched with number:" + phoneNumber); // 记录日志,未找到匹配的联系人
return null; return null; // 返回空值
} }
} }
} }

@ -19,15 +19,11 @@ import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
public class DataFetch extends AppCompatActivity { public class DataFetch extends AppCompatActivity {
/*** // 判断文件是否存在
*
* @param strFile
* @return
*/
public boolean fileIsExists(Context context, String strFile) { public boolean fileIsExists(Context context, String strFile) {
boolean fileExistFlag; boolean fileExistFlag;
try{ try{
context.openFileInput(strFile); context.openFileInput(strFile); // 打开文件输入流
fileExistFlag = true; fileExistFlag = true;
} catch (FileNotFoundException e){ } catch (FileNotFoundException e){
fileExistFlag = false; fileExistFlag = false;
@ -35,45 +31,35 @@ public class DataFetch extends AppCompatActivity {
return fileExistFlag; return fileExistFlag;
} }
/** // 文件内容写函数
*
* @param context
* @param file_name
* @param key
*/
public void writeFile(Context context, String file_name, String key){ public void writeFile(Context context, String file_name, String key){
try { try {
FileOutputStream fos = context.openFileOutput(file_name, Context.MODE_PRIVATE); FileOutputStream fos = context.openFileOutput(file_name, Context.MODE_PRIVATE); // 打开文件输出流
OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); // 创建输出流写入器
osw.write(key); osw.write(key); // 写入内容
osw.flush(); osw.flush(); // 刷新写入器
fos.flush(); //输出缓冲区中所有的内容 fos.flush(); //输出缓冲区中所有的内容
osw.close(); osw.close(); // 关闭写入器
fos.close(); fos.close(); // 关闭输出流
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/** // 文件内容读取函数
*
* @param context
* @param filename
*/
public String readFile(Context context, String filename) { public String readFile(Context context, String filename) {
try { try {
FileInputStream fis = context.openFileInput(filename); FileInputStream fis = context.openFileInput(filename); // 打开文件输入流
InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); InputStreamReader isr = new InputStreamReader(fis, "UTF-8"); // 创建输入流读取器
char[] input = new char[fis.available()]; //available()用于获取filename内容的长度,但是对中文有问题建议使用BufferReader char[] input = new char[fis.available()]; //available()用于获取filename内容的长度,但是对中文有问题建议使用BufferReader
isr.read(input); //读取并存储到input中 isr.read(input); //读取并存储到input中
isr.close(); isr.close(); // 关闭读取器
fis.close();//读取完成后关闭 fis.close();//读取完成后关闭
String str = new String(input); String str = new String(input); // 将字符数组转换为字符串
return str; return str; // 返回读取的字符串
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace(); // 打印异常信息
} }
return "error"; return "error"; // 返回错误信息
} }
} }

@ -20,9 +20,9 @@ import android.net.Uri;
public class Notes { public class Notes {
public static final String AUTHORITY = "micode_notes"; public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes"; public static final String TAG = "Notes";
public static final int TYPE_NOTE = 0; public static final int TYPE_NOTE = 0;
public static final int TYPE_FOLDER = 1; public static final int TYPE_FOLDER = 1;
public static final int TYPE_SYSTEM = 2; public static final int TYPE_SYSTEM = 2;
/** /**
* Following IDs are system folders' identifiers * Following IDs are system folders' identifiers
@ -42,9 +42,9 @@ public class Notes {
public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id"; public static final String INTENT_EXTRA_FOLDER_ID = "net.micode.notes.folder_id";
public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date"; public static final String INTENT_EXTRA_CALL_DATE = "net.micode.notes.call_date";
public static final int TYPE_WIDGET_INVALIDE = -1; public static final int TYPE_WIDGET_INVALIDE = -1;
public static final int TYPE_WIDGET_2X = 0; public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1; public static final int TYPE_WIDGET_4X = 1;
public static class DataConstants { public static class DataConstants {
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE; public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
@ -246,15 +246,15 @@ public class Notes {
* Mode to indicate the text in check list mode or not * Mode to indicate the text in check list mode or not
* <P> Type: Integer 1:check list mode 0: normal mode </P> * <P> Type: Integer 1:check list mode 0: normal mode </P>
*/ */
public static final String MODE = DATA1; public static final String MODE = DATA1; // 用于指示文本是否处于检查列表模式的模式
public static final int MODE_CHECK_LIST = 1; public static final int MODE_CHECK_LIST = 1; // 检查列表模式的值为1
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note"; // 内容类型为文本笔记的目录类型
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note"; public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note"; // 内容类型为文本笔记的项目类型
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note"); // 内容URI
} }
public static final class CallNote implements DataColumns { public static final class CallNote implements DataColumns {
@ -262,18 +262,18 @@ public class Notes {
* Call date for this record * Call date for this record
* <P> Type: INTEGER (long) </P> * <P> Type: INTEGER (long) </P>
*/ */
public static final String CALL_DATE = DATA1; public static final String CALL_DATE = DATA1; // 该记录的通话日期
/** /**
* Phone number for this record * Phone number for this record
* <P> Type: TEXT </P> * <P> Type: TEXT </P>
*/ */
public static final String PHONE_NUMBER = DATA3; public static final String PHONE_NUMBER = DATA3; // 该记录的电话号码
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; public static final String CONTENT_TYPE = "vnd.android.cursor.dir/call_note"; // 内容类型为通话笔记的目录类型
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note"; public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note"; // 内容类型为通话笔记的项目类型
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note"); // 内容URI
} }
} }

@ -81,13 +81,15 @@ public class NotesProvider extends ContentProvider {
@Override @Override
public boolean onCreate() { public boolean onCreate() {
// 在创建时,获取数据库帮助类的实例
mHelper = NotesDatabaseHelper.getInstance(getContext()); mHelper = NotesDatabaseHelper.getInstance(getContext());
return true; return true;
} }
@Override @Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) { String sortOrder) {
// 查询方法用于查询URI、投影、选择、选择参数和排序
Cursor c = null; Cursor c = null;
SQLiteDatabase db = mHelper.getReadableDatabase(); SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null; String id = null;
@ -149,6 +151,7 @@ public class NotesProvider extends ContentProvider {
@Override @Override
public Uri insert(Uri uri, ContentValues values) { public Uri insert(Uri uri, ContentValues values) {
// 插入方法用于插入URI和内容值
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0; long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) { switch (mMatcher.match(uri)) {
@ -166,13 +169,13 @@ public class NotesProvider extends ContentProvider {
default: default:
throw new IllegalArgumentException("Unknown URI " + uri); throw new IllegalArgumentException("Unknown URI " + uri);
} }
// Notify the note uri // 通知笔记URI
if (noteId > 0) { if (noteId > 0) {
getContext().getContentResolver().notifyChange( getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null); ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
} }
// Notify the data uri // 通知数据URI
if (dataId > 0) { if (dataId > 0) {
getContext().getContentResolver().notifyChange( getContext().getContentResolver().notifyChange(
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null); ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
@ -183,6 +186,7 @@ public class NotesProvider extends ContentProvider {
@Override @Override
public int delete(Uri uri, String selection, String[] selectionArgs) { public int delete(Uri uri, String selection, String[] selectionArgs) {
// 删除方法用于删除URI、选择和选择参数
int count = 0; int count = 0;
String id = null; String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
@ -229,6 +233,7 @@ public class NotesProvider extends ContentProvider {
@Override @Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
// 更新方法用于更新URI、内容值、选择和选择参数
int count = 0; int count = 0;
String id = null; String id = null;
SQLiteDatabase db = mHelper.getWritableDatabase(); SQLiteDatabase db = mHelper.getWritableDatabase();
@ -268,10 +273,12 @@ public class NotesProvider extends ContentProvider {
} }
private String parseSelection(String selection) { private String parseSelection(String selection) {
// 解析选择方法,用于解析选择
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""); return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
} }
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) { private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
// 定义一个方法,用于增加笔记版本号
StringBuilder sql = new StringBuilder(120); StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE "); sql.append("UPDATE ");
sql.append(TABLE.NOTE); sql.append(TABLE.NOTE);
@ -279,6 +286,7 @@ public class NotesProvider extends ContentProvider {
sql.append(NoteColumns.VERSION); sql.append(NoteColumns.VERSION);
sql.append("=" + NoteColumns.VERSION + "+1 "); sql.append("=" + NoteColumns.VERSION + "+1 ");
// 添加更新的条件
if (id > 0 || !TextUtils.isEmpty(selection)) { if (id > 0 || !TextUtils.isEmpty(selection)) {
sql.append(" WHERE "); sql.append(" WHERE ");
} }
@ -293,6 +301,7 @@ public class NotesProvider extends ContentProvider {
sql.append(selectString); sql.append(selectString);
} }
// 执行SQL查询
mHelper.getWritableDatabase().execSQL(sql.toString()); mHelper.getWritableDatabase().execSQL(sql.toString());
} }

@ -24,12 +24,12 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
// 元数据类,继承自任务类
public class MetaData extends Task { public class MetaData extends Task {
private final static String TAG = MetaData.class.getSimpleName(); private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null; private String mRelatedGid = null;
// 设置元数据信息
public void setMeta(String gid, JSONObject metaInfo) { public void setMeta(String gid, JSONObject metaInfo) {
try { try {
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
@ -39,7 +39,7 @@ public class MetaData extends Task {
setNotes(metaInfo.toString()); setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME); setName(GTaskStringUtils.META_NOTE_NAME);
} }
// 获取相关的GID
public String getRelatedGid() { public String getRelatedGid() {
return mRelatedGid; return mRelatedGid;
} }
@ -48,7 +48,7 @@ public class MetaData extends Task {
public boolean isWorthSaving() { public boolean isWorthSaving() {
return getNotes() != null; return getNotes() != null;
} }
// 设置元数据信息
@Override @Override
public void setContentByRemoteJSON(JSONObject js) { public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js); super.setContentByRemoteJSON(js);
@ -62,7 +62,7 @@ public class MetaData extends Task {
} }
} }
} }
// 不应调用此函数
@Override @Override
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
// this function should not be called // this function should not be called

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" packagePrefix="net.micode.notes" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Loading…
Cancel
Save