完善注释

pull/8/head
s2_cc 1 month ago
parent d226591280
commit 247e6513c8

@ -28,8 +28,16 @@ import net.micode.notes.data.Notes.NoteColumns;
/**
*
*
* (Data Layer - Database Helper)
* <p>
*
* 1. SQLite (onCreate, onUpgrade)
* 2. 便
* 3. SQL (SNIPPET)
* 4.
* <p>
* 线
* {@link NotesProvider}
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
@ -38,12 +46,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db";
/**
*
* {@link #onUpgrade}
*/
private static final int DB_VERSION = 4;
/**
*
* <p>
*
* 1. {@link #NOTE}便
* 2. {@link #DATA}便 MIME
*/
public interface TABLE {
/**
@ -63,10 +75,21 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "NotesDatabaseHelper";
/**
*
* {@link #getInstance(Context)}
*/
private static NotesDatabaseHelper mInstance;
/**
* 便 (note) SQL
* <p>
*
* - {@link NoteColumns#PARENT_ID}: ID
* - {@link NoteColumns#SNIPPET}: data
* - {@link NoteColumns#TYPE}:
* - {@link NoteColumns#BG_COLOR_ID}: ID2025 AI AI
* - {@link NoteColumns#GTASK_ID}: Google ID
* - {@link NoteColumns#VERSION}:
*/
private static final String CREATE_NOTE_TABLE_SQL =
"CREATE TABLE " + TABLE.NOTE + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," +
@ -88,6 +111,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")";
/**
* (data) SQL
* <p>
* EAV (Entity-Attribute-Value)
*
* - {@link DataColumns#MIME_TYPE}: CONTENT
* - {@link DataColumns#NOTE_ID}: note ID
* - {@link DataColumns#CONTENT}:
* - DATA1~DATA5: MIME_TYPE
*/
private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" +
DataColumns.ID + " INTEGER PRIMARY KEY," +
@ -103,12 +136,17 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")";
/**
* data NOTE_ID SQL
* <p>
* 便 ID
*/
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
/**
* Increase folder's note count when move note to the folder
* 便便
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+
@ -120,7 +158,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Decrease folder's note count when move note from folder
* 便便
* <p>
* 0
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
@ -133,7 +173,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Increase folder's note count when insert new note to the folder
* 便
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
@ -145,7 +185,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Decrease folder's note count when delete note from the folder
* 便
* <p>
* 0
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
@ -158,7 +200,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
* data {@link DataConstants#NOTE}
* note 便 {@link NoteColumns#SNIPPET}
* <p>
*
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
@ -171,7 +216,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Update note's content when data with {@link DataConstants#NOTE} type has changed
* data {@link DataConstants#NOTE} 便
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " +
@ -184,7 +229,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
* data {@link DataConstants#NOTE} 便
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " +
@ -197,7 +242,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Delete datas belong to note which has been deleted
* note 便/
* data ({@link DataColumns#NOTE_ID})
* <p>
* 使 FOREIGN KEY
*/
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
@ -208,7 +256,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Delete notes belong to folder which has been deleted
* TYPE
* 便 PARENT_ID
* <p>
* {@link #NOTE_DELETE_DATA_ON_DELETE_TRIGGER}
*/
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
@ -219,7 +270,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Move notes belong to folder which has been moved to trash folder
* PARENT_ID {@link Notes#ID_TRASH_FOLER}
* 便 PARENT_ID ID
* <p>
*
*/
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " +
@ -232,16 +286,23 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
*
* @param context
* {@link #getInstance(Context)}
*
* @param context
*/
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
/**
*
* @param db
* 便 (note)
* <p>
*
* 1. SQL
* 2.
* 3.
*
* @param db
*/
public void createNoteTable(SQLiteDatabase db) {
// 执行创建表SQL
@ -254,8 +315,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
* @param db
* note SQL
* <p>
*
*
*
* @param db
*/
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
// 删除旧触发器(如果存在)
@ -278,8 +343,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
* @param db
*
* <p>
*
* 1. ({@link Notes#ID_CALL_RECORD_FOLDER})
* 2. ({@link Notes#ID_ROOT_FOLDER})
* 3. ({@link Notes#ID_TEMPARAY_FOLDER})便
* 4. ({@link Notes#ID_TRASH_FOLER})便
*
* @param db
*/
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
@ -317,8 +389,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
* @param db
* (data)
*
* @param db
*/
public void createDataTable(SQLiteDatabase db) {
// 执行创建表SQL
@ -331,8 +404,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
* @param db
* data SQL
* <p>
* note SNIPPET data CONTENT
*
* @param db
*/
private void reCreateDataTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
@ -345,9 +421,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
* @param context
* @return
*
* <p>
* 线 synchronized 线
*
* @param context
* @return NotesDatabaseHelper
*/
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
@ -357,8 +436,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
* @param db
*
* <p>
* note data
*
* @param db
*/
@Override
public void onCreate(SQLiteDatabase db) {
@ -369,38 +451,48 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
*
* @param db
* @param oldVersion
* @param newVersion
*
* <p>
*
* v1v4
*
* @param db
* @param oldVersion
* @param newVersion {@link #DB_VERSION}
* @throws IllegalStateException
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
boolean skipV2 = false;
// 1. 从版本1升级
if (oldVersion == 1) {
upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3
oldVersion++;
}
// 2. 从版本2升级如果未跳过
if (oldVersion == 2 && !skipV2) {
upgradeToV3(db);
reCreateTriggers = true;
oldVersion++;
}
// 3. 从版本3升级
if (oldVersion == 3) {
upgradeToV4(db);
oldVersion++;
}
// 4. 如果表结构在v3升级中发生较大变更需要重建触发器以确保兼容性
if (reCreateTriggers) {
reCreateNoteTableTriggers(db);
reCreateDataTableTriggers(db);
}
// 5. 最终版本校验:确保所有升级步骤已执行完毕
if (oldVersion != newVersion) {
throw new IllegalStateException("Upgrade notes database to version " + newVersion
+ "fails");
@ -408,8 +500,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
* 2
* @param db
* 2
* <p>
* {@link #onCreate}
* 使
* <b></b>
*
* @param db
*/
private void upgradeToV2(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
@ -419,8 +516,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
* 3
* @param db
* 3
* <p>
* (ALTER TABLE)
*
* 1.
* 2. Google ID ({@link NoteColumns#GTASK_ID})
* 3.
*
* @param db
*/
private void upgradeToV3(SQLiteDatabase db) {
// drop unused triggers
@ -438,11 +542,17 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
/**
* 4
* @param db
* 4
* <p>
*
* ({@link NoteColumns#VERSION})
* <p>
*
*
* @param db
*/
private void upgradeToV4(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0");
}
}
}

@ -324,28 +324,21 @@ public class GTaskClient {
Log.d(TAG, "encoding: " + contentEncoding);
}
InputStream input = entity.getContent();
if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) {
input = new GZIPInputStream(entity.getContent());
} else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) {
Inflater inflater = new Inflater(true);
input = new InflaterInputStream(entity.getContent(), inflater);
}
try {
InputStreamReader isr = new InputStreamReader(input);
BufferedReader br = new BufferedReader(isr);
try (InputStream input = entity.getContent();
InputStream finalInput = (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip"))
? new GZIPInputStream(input)
: (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate"))
? new InflaterInputStream(input, new Inflater(true))
: input;
InputStreamReader isr = new InputStreamReader(finalInput);
BufferedReader br = new BufferedReader(isr)) {
StringBuilder sb = new StringBuilder();
while (true) {
String buff = br.readLine();
if (buff == null) {
return sb.toString();
}
sb = sb.append(buff);
String buff;
while ((buff = br.readLine()) != null) {
sb.append(buff);
}
} finally {
input.close();
return sb.toString();
}
}

@ -236,67 +236,69 @@ public class BackupUtils {
return STATE_SD_CARD_UNMOUONTED;
}
// 获取输出流
PrintStream ps = getExportToTextPrintStream();
if (ps == null) {
Log.e(TAG, "get print stream error");
return STATE_SYSTEM_ERROR;
}
// 第一部分:导出文件夹及其中的笔记
// 查询所有文件夹(排除回收站,但包含通话记录文件夹)
Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
if (folderCursor != null) {
if (folderCursor.moveToFirst()) {
do {
// 输出文件夹名称
String folderName = "";
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
folderName = mContext.getString(R.string.call_record_folder_name);
} else {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
}
if (!TextUtils.isEmpty(folderName)) {
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
}
// 导出该文件夹下的所有笔记
String folderId = folderCursor.getString(NOTE_COLUMN_ID);
exportFolderToText(folderId, ps);
} while (folderCursor.moveToNext());
// 使用try-with-resources自动关闭输出流
try (PrintStream ps = getExportToTextPrintStream()) {
if (ps == null) {
Log.e(TAG, "get print stream error");
return STATE_SYSTEM_ERROR;
}
folderCursor.close();
}
// 第二部分:导出根目录下的笔记(不属于任何文件夹的笔记)
Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0", null, null);
// 第一部分:导出文件夹及其中的笔记
// 查询所有文件夹(排除回收站,但包含通话记录文件夹)
Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
if (folderCursor != null) {
if (folderCursor.moveToFirst()) {
do {
// 输出文件夹名称
String folderName = "";
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
folderName = mContext.getString(R.string.call_record_folder_name);
} else {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
}
if (!TextUtils.isEmpty(folderName)) {
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
}
// 导出该文件夹下的所有笔记
String folderId = folderCursor.getString(NOTE_COLUMN_ID);
exportFolderToText(folderId, ps);
} while (folderCursor.moveToNext());
}
folderCursor.close();
}
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {
do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// 导出该笔记的内容
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
// 第二部分:导出根目录下的笔记(不属于任何文件夹的笔记)
Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0", null, null);
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {
do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// 导出该笔记的内容
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
}
noteCursor.close();
}
noteCursor.close();
}
// 关闭输出流
ps.close();
return STATE_SUCCESS;
return STATE_SUCCESS;
} catch (Exception e) {
Log.e(TAG, "Export text failed: " + e.getMessage());
return STATE_SYSTEM_ERROR;
}
}
/**

@ -153,15 +153,10 @@ public class DataUtils {
int count = 0;
if(cursor != null) {
if(cursor.moveToFirst()) {
try {
count = cursor.getInt(0); // 获取计数结果
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString());
} finally {
cursor.close();
}
if(cursor.moveToFirst() && cursor.getColumnCount() > 0) {
count = cursor.getInt(0); // 获取计数结果
}
cursor.close();
}
return count;
}
@ -181,14 +176,14 @@ public class DataUtils {
new String [] {String.valueOf(type)},
null);
boolean exist = false;
boolean exists = false;
if (cursor != null) {
if (cursor.getCount() > 0) { // 如果查询结果数量大于0则表示存在
exist = true;
exists = true;
}
cursor.close();
}
return exist;
return exists;
}
/**
@ -202,14 +197,14 @@ public class DataUtils {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
boolean exist = false;
boolean exists = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
exists = true;
}
cursor.close();
}
return exist;
return exists;
}
/**
@ -223,14 +218,14 @@ public class DataUtils {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
boolean exist = false;
boolean exists = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
exists = true;
}
cursor.close();
}
return exist;
return exists;
}
/**
@ -246,14 +241,14 @@ public class DataUtils {
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
" AND " + NoteColumns.SNIPPET + "=?",
new String[] { name }, null);
boolean exist = false;
boolean exists = false;
if(cursor != null) {
if(cursor.getCount() > 0) {
exist = true;
exists = true;
}
cursor.close();
}
return exist;
return exists;
}
/**
@ -275,13 +270,12 @@ public class DataUtils {
if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>();
do {
try {
AppWidgetAttribute widget = new AppWidgetAttribute();
AppWidgetAttribute widget = new AppWidgetAttribute();
// 确保列索引有效
if (c.getColumnCount() > 1) {
widget.widgetId = c.getInt(0); // 小部件ID
widget.widgetType = c.getInt(1); // 小部件类型
set.add(widget);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, e.toString());
}
} while (c.moveToNext());
}
@ -306,9 +300,9 @@ public class DataUtils {
if (cursor != null && cursor.moveToFirst()) {
try {
return cursor.getString(0); // 返回电话号码
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString());
if (cursor.getColumnCount() > 0) {
return cursor.getString(0); // 返回电话号码
}
} finally {
cursor.close();
}
@ -328,17 +322,13 @@ public class DataUtils {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
+ CallNote.PHONE_NUMBER + ",?)",
+ CallNote.PHONE_NUMBER + ",?)" ,
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
return cursor.getLong(0); // 返回笔记ID
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString());
}
if (cursor.moveToFirst() && cursor.getColumnCount() > 0) {
return cursor.getLong(0); // 返回笔记ID
}
cursor.close();
}

@ -22,6 +22,8 @@ import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
import java.security.SecureRandom;
public class ResourceParser {
// 笔记背景颜色常量定义
public static final int YELLOW = 0; // 黄色背景
@ -92,8 +94,9 @@ public class ResourceParser {
// 检查用户是否启用了随机背景颜色功能
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
// 随机选择一个背景颜色
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
// 使用密码学安全的随机数生成器随机选择一个背景颜色
SecureRandom secureRandom = new SecureRandom();
return secureRandom.nextInt(NoteBgResources.BG_EDIT_RESOURCES.length);
} else {
// 使用默认的背景颜色(黄色)
return BG_DEFAULT_COLOR;

@ -177,13 +177,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
// 检查是否已添加过介绍笔记
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder();
InputStream in = null;
try {
try (InputStream in = getResources().openRawResource(R.raw.introduction);
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr)) {
// 从raw资源读取介绍文件
in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024];
int len = 0;
while ((len = br.read(buf)) > 0) {
@ -196,14 +194,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
if(in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// 创建空白笔记并设置介绍文本

@ -118,15 +118,15 @@ public class NotesPreferenceActivity extends PreferenceActivity {
// 检查是否有新账户添加
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
for (Account accountNew : accounts) {
boolean found = false;
boolean isFound = false;
for (Account accountOld : mOriAccounts) {
if (TextUtils.equals(accountOld.name, accountNew.name)) {
found = true;
isFound = true;
break;
}
}
// 发现新账户,自动设置为同步账户
if (!found) {
if (!isFound) {
setSyncAccount(accountNew.name);
break;
}

Loading…
Cancel
Save