给ResourceParser.java和GTaskStringUtils.java添加代码注释

pull/2/head
HZXhuang 2 years ago
parent 5504b6c762
commit 7e3f9a8e44

@ -56,10 +56,10 @@ public class WorkingNote {
// 便签的背景颜色
private int mBgColorId;
// 便签的小件ID
// 便签的小件ID
private int mWidgetId;
// 便签的小件类型
// 便签的小件类型
private int mWidgetType;
// 便签所处的文件夹ID
@ -461,12 +461,12 @@ public class WorkingNote {
return mFolderId;
}
// 获取小件ID
// 获取小件ID
public int getWidgetId() {
return mWidgetId;
}
// 获取小件类型
// 获取小件类型
public int getWidgetType() {
return mWidgetType;
}
@ -489,7 +489,7 @@ public class WorkingNote {
/**
* Call when user create note from widget
* 便
* 便
*/
void onWidgetChanged();

@ -34,9 +34,21 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList;
import java.util.HashSet;
/**
* @author hzx
* 1.0
* 2023/10/29
* DataUtils
*/
public class DataUtils {
public static final String TAG = "DataUtils";
/**
* 便
* @param resolver
* @param ids 便ID
* @return
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null");
@ -47,19 +59,26 @@ public class DataUtils {
return true;
}
// 内容操作列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历便签ID集合
for (long id : ids) {
if(id == Notes.ID_ROOT_FOLDER) {
if(id == Notes.ID_ROOT_FOLDER) { // 如果是根文件夹
// 根文件夹不能被删除
Log.e(TAG, "Don't delete system folder root");
continue;
}
// 创建一个删除操作
ContentProviderOperation.Builder builder = ContentProviderOperation
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
// 将删除操作加入到操作列表中
operationList.add(builder.build());
}
try {
// 批量处理删除便签的操作
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
// 删除便签失败
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
@ -67,6 +86,7 @@ public class DataUtils {
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
// 执行删除操作发生错误
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
}
return false;

@ -16,6 +16,12 @@
package net.micode.notes.tool;
/**
* @author hzx
* 1.0
* 2023/10/29
* GTaskStringUtils google
*/
public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_ID = "action_id";

@ -22,24 +22,43 @@ import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
* @author hzx
* 1.0
* 2023/10/29
* ResourceParser
* IDID
*/
public class ResourceParser {
/**
*
*/
public static final int YELLOW = 0;
public static final int BLUE = 1;
public static final int WHITE = 2;
public static final int GREEN = 3;
public static final int RED = 4;
// 默认的颜色 黄色 0
public static final int BG_DEFAULT_COLOR = YELLOW;
/**
*
*/
public static final int TEXT_SMALL = 0;
public static final int TEXT_MEDIUM = 1;
public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3;
// 默认的字体大小 中等 1
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
/**
* 便
*/
public static class NoteBgResources {
// 编辑界面背景资源数组
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
R.drawable.edit_blue,
@ -48,6 +67,7 @@ public class ResourceParser {
R.drawable.edit_red
};
// 编辑标题背景资源数组
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
@ -56,25 +76,39 @@ public class ResourceParser {
R.drawable.edit_title_red
};
// 根据背景颜色ID获取便签背景资源ID
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
// 根据背景颜色ID获取便签标题背景资源ID
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
/**
* ID
* @param context
* @return ID
*/
public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
// 设置了随机背景颜色
// 返回一个随机背景颜色ID
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
} else {
// 返回默认的背景颜色ID
return BG_DEFAULT_COLOR;
}
}
/**
* 便
*/
public static class NoteItemBgResources {
// 开头背景资源
private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up,
R.drawable.list_blue_up,
@ -83,6 +117,7 @@ public class ResourceParser {
R.drawable.list_red_up
};
// 正常背景资源
private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle,
R.drawable.list_blue_middle,
@ -91,6 +126,7 @@ public class ResourceParser {
R.drawable.list_red_middle
};
// 结尾背景资源
private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down,
R.drawable.list_blue_down,
@ -99,6 +135,7 @@ public class ResourceParser {
R.drawable.list_red_down,
};
// 单独的背景资源
private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
@ -107,28 +144,37 @@ public class ResourceParser {
R.drawable.list_red_single
};
// 根据背景颜色ID获取开头背景资源ID
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
// 根据背景颜色ID获取结尾背景资源ID
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
// 根据背景颜色ID获取单独的背景资源ID
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
// 根据背景颜色ID获取普通背景资源ID
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
// 获取文件夹背景资源ID
public static int getFolderBgRes() {
return R.drawable.list_folder;
}
}
/**
*
*/
public static class WidgetBgResources {
// 2x的小部件背景资源
private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
@ -137,10 +183,12 @@ public class ResourceParser {
R.drawable.widget_2x_red,
};
// 根据背景颜色ID获取小部件背景资源ID
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
// 4x的小部件背景资源
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
@ -149,12 +197,17 @@ public class ResourceParser {
R.drawable.widget_4x_red
};
// 根据背景颜色ID获取小部件背景资源ID
public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id];
}
}
/**
*
*/
public static class TextAppearanceResources {
// 字体资源
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium,
@ -162,18 +215,21 @@ public class ResourceParser {
R.style.TextAppearanceSuper
};
// 根据字体大小ID获取字体资源ID
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
// 防止数组索引越界
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
}
return TEXTAPPEARANCE_RESOURCES[id];
}
// 获取字体资源数组的长度
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

Loading…
Cancel
Save