添加注释

dev
Xilipikalang 4 years ago
parent 5b1250059d
commit 972b0a3b62

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownEnhProjectSettings">
<AnnotatorSettings targetHasSpaces="true" linkCaseMismatch="true" wikiCaseMismatch="true" wikiLinkHasDashes="true" notUnderWikiHome="true" targetNotWikiPageExt="true" notUnderSourceWikiHome="true" targetNameHasAnchor="true" targetPathHasAnchor="true" wikiLinkHasSlash="true" wikiLinkHasSubdir="true" wikiLinkHasOnlyAnchor="true" linkTargetsWikiHasExt="true" linkTargetsWikiHasBadExt="true" notUnderSameRepo="true" targetNotUnderVcs="false" linkNeedsExt="true" linkHasBadExt="true" linkTargetNeedsExt="true" linkTargetHasBadExt="true" wikiLinkNotInWiki="true" imageTargetNotInRaw="true" repoRelativeAcrossVcsRoots="true" multipleWikiTargetsMatch="true" unresolvedLinkReference="true" linkIsIgnored="true" anchorIsIgnored="true" anchorIsUnresolved="true" anchorLineReferenceIsUnresolved="true" anchorLineReferenceFormat="true" anchorHasDuplicates="true" abbreviationDuplicates="true" abbreviationNotUsed="true" attributeIdDuplicateDefinition="true" attributeIdNotUsed="true" footnoteDuplicateDefinition="true" footnoteUnresolved="true" footnoteDuplicates="true" footnoteNotUsed="true" macroDuplicateDefinition="true" macroUnresolved="true" macroDuplicates="true" macroNotUsed="true" referenceDuplicateDefinition="true" referenceUnresolved="true" referenceDuplicates="true" referenceNotUsed="true" referenceUnresolvedNumericId="true" enumRefDuplicateDefinition="true" enumRefUnresolved="true" enumRefDuplicates="true" enumRefNotUsed="true" enumRefLinkUnresolved="true" enumRefLinkDuplicates="true" simTocUpdateNeeded="true" simTocTitleSpaceNeeded="true" />
<HtmlExportSettings updateOnSave="false" parentDir="" targetDir="" cssDir="css" scriptDir="js" plainHtml="false" imageDir="" copyLinkedImages="false" imagePathType="0" targetPathType="2" targetExt="" useTargetExt="false" noCssNoScripts="false" useElementStyleAttribute="false" linkToExportedHtml="true" exportOnSettingsChange="true" regenerateOnProjectOpen="false" linkFormatType="HTTP_ABSOLUTE" />
<LinkMapSettings>
<textMaps />
</LinkMapSettings>
</component>
</project>

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownProjectSettings">
<PreviewSettings splitEditorLayout="SPLIT" splitEditorPreview="PREVIEW" useGrayscaleRendering="false" zoomFactor="1.0" maxImageWidth="0" synchronizePreviewPosition="true" highlightPreviewType="LINE" highlightFadeOut="5" highlightOnTyping="true" synchronizeSourcePosition="true" verticallyAlignSourceAndPreviewSyncPosition="true" showSearchHighlightsInPreview="true" showSelectionInPreview="true" lastLayoutSetsDefault="false">
<PanelProvider>
<provider providerId="com.vladsch.md.nav.editor.swing.html.panel" providerName="Default - Swing" />
</PanelProvider>
</PreviewSettings>
<ParserSettings gitHubSyntaxChange="false" correctedInvalidSettings="false" emojiShortcuts="1" emojiImages="0">
<PegdownExtensions>
<option name="ATXHEADERSPACE" value="true" />
<option name="FENCED_CODE_BLOCKS" value="true" />
<option name="INTELLIJ_DUMMY_IDENTIFIER" value="true" />
<option name="RELAXEDHRULES" value="true" />
<option name="STRIKETHROUGH" value="true" />
<option name="TABLES" value="true" />
<option name="TASKLISTITEMS" value="true" />
</PegdownExtensions>
<ParserOptions>
<option name="COMMONMARK_LISTS" value="true" />
<option name="EMOJI_SHORTCUTS" value="true" />
<option name="GFM_TABLE_RENDERING" value="true" />
<option name="PRODUCTION_SPEC_PARSER" value="true" />
<option name="SIM_TOC_BLANK_LINE_SPACER" value="true" />
</ParserOptions>
</ParserSettings>
<HtmlSettings headerTopEnabled="false" headerBottomEnabled="false" bodyTopEnabled="false" bodyBottomEnabled="false" addPageHeader="false" addAnchorLinks="true" anchorLinksWrapText="false" imageUriSerials="false" addDocTypeHtml="true" noParaTags="false" defaultUrlTitle="false" migratedPlantUml="false" migratedAnchorLinks="false" plantUmlConversion="0">
<GeneratorProvider>
<provider providerId="com.vladsch.md.nav.editor.text.html.generator" providerName="Unmodified HTML Generator" />
</GeneratorProvider>
<headerTop />
<headerBottom />
<bodyTop />
<bodyBottom />
<fencedCodeConversions />
</HtmlSettings>
<CssSettings previewScheme="UI_SCHEME" cssUri="" isCssUriEnabled="false" isCssUriSerial="true" isCssTextEnabled="false" isDynamicPageWidth="true">
<StylesheetProvider>
<provider providerId="com.vladsch.md.nav.editor.text.html.css" providerName="No Stylesheet" />
</StylesheetProvider>
<ScriptProviders />
<cssText />
<cssUriHistory />
</CssSettings>
</component>
</project>

@ -17,4 +17,8 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
<component name="sonarModuleSettings">
<option name="localAnalysisScripName" value="&lt;PROJECT&gt;" />
<option name="serverName" value="&lt;PROJECT&gt;" />
</component>
</module> </module>

@ -50,4 +50,8 @@
<orderEntry type="library" name="Gradle: com.android.support:appcompat-v7:22.2.1@aar" level="project" /> <orderEntry type="library" name="Gradle: com.android.support:appcompat-v7:22.2.1@aar" level="project" />
<orderEntry type="library" name="Gradle: com.android.support:support-v4:22.2.1@aar" level="project" /> <orderEntry type="library" name="Gradle: com.android.support:support-v4:22.2.1@aar" level="project" />
</component> </component>
<component name="sonarModuleSettings">
<option name="localAnalysisScripName" value="&lt;PROJECT&gt;" />
<option name="serverName" value="&lt;PROJECT&gt;" />
</component>
</module> </module>

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="issues">
<option name="index">
<map>
<entry key="$PROJECT_DIR$/app/src/main/java/net/micode/notes/gtask/data/MetaData.java">
<value>
<set />
</value>
</entry>
<entry key="$PROJECT_DIR$/app/src/main/java/net/micode/notes/gtask/data/Node.java">
<value>
<set />
</value>
</entry>
<entry key="$PROJECT_DIR$/app/src/main/java/net/micode/notes/gtask/data/SqlData.java">
<value>
<set />
</value>
</entry>
<entry key="$PROJECT_DIR$/app/src/main/java/net/micode/notes/gtask/data/SqlNote.java">
<value>
<set />
</value>
</entry>
<entry key="$PROJECT_DIR$/app/src/main/java/net/micode/notes/gtask/data/Task.java">
<value>
<set />
</value>
</entry>
<entry key="$PROJECT_DIR$/app/src/main/java/net/micode/notes/gtask/data/TaskList.java">
<value>
<set />
</value>
</entry>
</map>
</option>
</component>
</project>

@ -0,0 +1,5 @@
2
java:S2386,"Make this member "protected".(¤íÂX
n
java:S3776¢"RRefactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.(®‘‡§øÿÿÿÿ

@ -0,0 +1,3 @@
[
java:S1124"EReorder the modifiers to comply with the Java Language Specification.(ð«¦í

@ -0,0 +1,3 @@
i
java:S3776"RRefactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed.(´ÇŽª

@ -0,0 +1,8 @@
r
java:S3923Ø"[Remove this conditional structure or edit its code blocks so that they're not all the same.(†ÈÔ¡
Œ
java:S1319à"pThe return type of this method should be an interface such as "List" rather than the implementation "ArrayList".(ëï·ºüÿÿÿÿ
t
java:S2293*"YReplace the type specification in this constructor call with the diamond operator ("<>").(¡Ê©ëùÿÿÿÿ
Y java:S125Å"<This block of commented-out lines of code should be removed.(¿¯ˆ§8ѽâ.

@ -0,0 +1,13 @@
h
java:S3776Ó"RRefactor this method to reduce its Cognitive Complexity from 32 to the 15 allowed.(ë®Æ
u
java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(Ÿ“<C5B8>…üÿÿÿÿ
u
java:S2293¦"YReplace the type specification in this constructor call with the diamond operator ("<>").(Ÿ“<C5B8>…üÿÿÿÿ
n
java:S3776ñ"RRefactor this method to reduce its Cognitive Complexity from 91 to the 15 allowed.(¸ŸêÉýÿÿÿÿ
2
java:S2386."Make this member "protected".(êÝÐu
u
java:S2293<18>"YReplace the type specification in this constructor call with the diamond operator ("<>").(Ÿ“<C5B8>…üÿÿÿÿ

@ -0,0 +1,15 @@
@
app/build.gradle,f\4\f4a01d6a4fcb971362ec00a83903fd3902f52164
k
;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88
g
7app/src/main/java/net/micode/notes/gtask/data/Node.java,3\a\3aac5305cb73bfbdeb8078cd264d04323fa80e92
j
:app/src/main/java/net/micode/notes/gtask/data/SqlData.java,9\3\934a4e2abf19d28a53f6aeb1dcd99248c44b6892
j
:app/src/main/java/net/micode/notes/gtask/data/SqlNote.java,f\1\f1226eeacd46c914d51f3d1a6d6f27377490d2a4
g
7app/src/main/java/net/micode/notes/gtask/data/Task.java,d\1\d187f1271655c3d91661a39fe6de395b6a9f290a
k
;app/src/main/java/net/micode/notes/gtask/data/TaskList.java,e\0\e094aec5c3e1b6f44539adff3114f5a1ad603ddc

@ -24,39 +24,51 @@ import net.micode.notes.tool.GTaskStringUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
// 功能描述主要是描述数据属性property的信息用来支持例如指示存储位置、历史数据、资源查找、文件记录等功能。
//实现继承task类用于记录数据的变化
public class MetaData extends Task { public class MetaData extends Task {
// 调用getSimpleName ()函数得到类的简写名称存入字符串TAG中
private final static String TAG = MetaData.class.getSimpleName(); private final static String TAG = MetaData.class.getSimpleName();
// 相关GID文件 GID文件用来保存帮助文件的信息
private String mRelatedGid = null; private String mRelatedGid = null;
// 调用JSONObject库函数put ()Task类中的setNotes ()和setName ()函数,实现设置数据,即生成元数据库
public void setMeta(String gid, JSONObject metaInfo) { public void setMeta(String gid, JSONObject metaInfo) {
try { try {
// 将这对键值放入metaInfo这个jsonobject对象中
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid); metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
// 捕捉异常放入TAG
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "failed to put related gid"); Log.e(TAG, "failed to put related gid");
} }
// 设置便签将json类的metainfo转换为String
setNotes(metaInfo.toString()); setNotes(metaInfo.toString());
// 设置gtask名字
setName(GTaskStringUtils.META_NOTE_NAME); setName(GTaskStringUtils.META_NOTE_NAME);
} }
// 获取相关联的Gid
public String getRelatedGid() { public String getRelatedGid() {
return mRelatedGid; return mRelatedGid;
} }
@Override @Override
//判断是否值得存放,即当前数据是否有效,若数据非空则返回真值
public boolean isWorthSaving() { public boolean isWorthSaving() {
return getNotes() != null; return getNotes() != null;
} }
@Override @Override
//功能使用远程json数据对象设置元数据内容
//实现调用父类Task中的setContentByRemoteJSON ()函数如果获取的notes非空则去掉获取notes的空格后存入metaInfo中并从metaInfo获取键值来获取相关gid如果为空则抛出异常
//参数js属于JSONObject类属于远程的数据
public void setContentByRemoteJSON(JSONObject js) { public void setContentByRemoteJSON(JSONObject js) {
//普通的直接引用。与this类似super相当于是指向当前对象的父类这样就可以用super.xxx来引用父类的成员。
super.setContentByRemoteJSON(js); super.setContentByRemoteJSON(js);
if (getNotes() != null) { if (getNotes() != null) {
try { try {
JSONObject metaInfo = new JSONObject(getNotes().trim()); JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID); mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) { } catch (JSONException e) {
// 输出异常
Log.w(TAG, "failed to get related gid"); Log.w(TAG, "failed to get related gid");
mRelatedGid = null; mRelatedGid = null;
} }
@ -64,17 +76,20 @@ public class MetaData extends Task {
} }
@Override @Override
//功能使用本地json数据对象设置元数据内容一般不会用到若用到则抛出异常
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
// this function should not be called // this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called"); throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
} }
@Override @Override
// 功能从元数据内容中获取本地json对象一般不会用到若用到则抛出异常
public JSONObject getLocalJSONFromContent() { public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called"); throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
} }
@Override @Override
// 功能:获取同步动作状态,一般不会用到,若用到,则抛出异常
public int getSyncAction(Cursor c) { public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called"); throw new IllegalAccessError("MetaData:getSyncAction should not be called");
} }

@ -20,6 +20,7 @@ import android.database.Cursor;
import org.json.JSONObject; import org.json.JSONObject;
// 建立node类来提供模板设置各种参数及定义各种函数会在别的地方用到定义了各种同步活动的标识码
public abstract class Node { public abstract class Node {
public static final int SYNC_ACTION_NONE = 0; public static final int SYNC_ACTION_NONE = 0;
@ -46,14 +47,14 @@ public abstract class Node {
private long mLastModified; private long mLastModified;
private boolean mDeleted; private boolean mDeleted;
//实现设置mgid为空名字为空最后一次修改时间为0没有修改mDeleted为false表示未删除。
public Node() { public Node() {
mGid = null; mGid = null;
mName = ""; mName = "";
mLastModified = 0; mLastModified = 0;
mDeleted = false; mDeleted = false;
} }
// 创建JSONObject对象创建操作和更新操作参数为int actionid
public abstract JSONObject getCreateAction(int actionId); public abstract JSONObject getCreateAction(int actionId);
public abstract JSONObject getUpdateAction(int actionId); public abstract JSONObject getUpdateAction(int actionId);

@ -36,6 +36,7 @@ import org.json.JSONObject;
public class SqlData { public class SqlData {
//调用getSimpleName ()函数将类的简写名称存入string类型变量TAG中
private static final String TAG = SqlData.class.getSimpleName(); private static final String TAG = SqlData.class.getSimpleName();
private static final int INVALID_ID = -99999; private static final int INVALID_ID = -99999;
@ -70,7 +71,8 @@ public class SqlData {
private String mDataContentData3; private String mDataContentData3;
private ContentValues mDiffDataValues; private ContentValues mDiffDataValues;
//功能:第一种构造函数,初始化
//参数类型为context从上下文获取初始化其中变量
public SqlData(Context context) { public SqlData(Context context) {
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
mIsCreate = true; mIsCreate = true;
@ -81,14 +83,17 @@ public class SqlData {
mDataContentData3 = ""; mDataContentData3 = "";
mDiffDataValues = new ContentValues(); mDiffDataValues = new ContentValues();
} }
//功能:第二中构造函数,初始化
//实现通过游标cursor c来获取数据进行替换
//参数游标c是将传进来的参数替换掉初始的数值
public SqlData(Context context, Cursor c) { public SqlData(Context context, Cursor c) {
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
mIsCreate = false; mIsCreate = false;
loadFromCursor(c); loadFromCursor(c);
mDiffDataValues = new ContentValues(); mDiffDataValues = new ContentValues();
} }
//功能从光标处加载数据DATA_ID_COLUMN等参数为01234应为获取五列参数
//实现用各种get函数获取相关值
private void loadFromCursor(Cursor c) { private void loadFromCursor(Cursor c) {
mDataId = c.getLong(DATA_ID_COLUMN); mDataId = c.getLong(DATA_ID_COLUMN);
mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN); mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
@ -96,16 +101,23 @@ public class SqlData {
mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN); mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN); mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
} }
//功能:设置共享数据并提供异常抛出与处理机制
//实现首先js判断是否有DataColumns.ID然后判断是否为第一种构造方式将DataColumns.ID列和对应dataId列值加入到SQLData中
//然后更新mDataId最后判断并设置mDataMimeType、mDataContent等需共享的数据
public void setContent(JSONObject js) throws JSONException { public void setContent(JSONObject js) throws JSONException {
// 如果传入JSONObject有DataColumns.ID则dataID = DataColumns.ID否则设置为INVALID_ID=-99999
long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID; long dataId = js.has(DataColumns.ID) ? js.getLong(DataColumns.ID) : INVALID_ID;
//如果mIsCreate为True根据第一种构造方式或者mDataId当前数据的ID与dataId元数据的ID不符。
//第一种构造方式只是简单的初始化,没具体内容
if (mIsCreate || mDataId != dataId) { if (mIsCreate || mDataId != dataId) {
// 将DataColumns.ID列和对应dataId列值加入到SQLData中
mDiffDataValues.put(DataColumns.ID, dataId); mDiffDataValues.put(DataColumns.ID, dataId);
} }
mDataId = dataId; mDataId = dataId;
// 判断并更新
String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE) String dataMimeType = js.has(DataColumns.MIME_TYPE) ? js.getString(DataColumns.MIME_TYPE)
: DataConstants.NOTE; : DataConstants.NOTE;
// 这个对象的MimeType不和dataMimeType共享数据一样则将共享数据.MIME_TYPE加入数据库中
if (mIsCreate || !mDataMimeType.equals(dataMimeType)) { if (mIsCreate || !mDataMimeType.equals(dataMimeType)) {
mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType); mDiffDataValues.put(DataColumns.MIME_TYPE, dataMimeType);
} }
@ -129,7 +141,8 @@ public class SqlData {
} }
mDataContentData3 = dataContentData3; mDataContentData3 = dataContentData3;
} }
//功能:获取共享的数据内容,并提供异常抛出与处理机制
//实现根据mIsCreate判断初始化类型如果为第一种无内容的初始化则返回null否则将要共享的内容存入JSONObject类的js中
public JSONObject getContent() throws JSONException { public JSONObject getContent() throws JSONException {
if (mIsCreate) { if (mIsCreate) {
Log.e(TAG, "it seems that we haven't created this in database yet"); Log.e(TAG, "it seems that we haven't created this in database yet");
@ -143,7 +156,9 @@ public class SqlData {
js.put(DataColumns.DATA3, mDataContentData3); js.put(DataColumns.DATA3, mDataContentData3);
return js; return js;
} }
//功能commit 函数用于把当前所做的修改保存到数据库
//实现首先判断构造方式如果为第一种构造方式判断是否为有效然后更新共享数据如果为第二种构造方式首先判断要共享的数据mDiffDataValues是否存在然后确认版本如果版本还没有确认则记录id和data如果已经确认则更新对应版本ID最后将要共享的数据清空回到初始化表示已经共享
//参数long类型的noteIdboolean类型的validateVersion用于版本确认long类型的version为版本号
public void commit(long noteId, boolean validateVersion, long version) { public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) { if (mIsCreate) {
@ -182,7 +197,7 @@ public class SqlData {
mDiffDataValues.clear(); mDiffDataValues.clear();
mIsCreate = false; mIsCreate = false;
} }
// 获取当前ID
public long getId() { public long getId() {
return mDataId; return mDataId;
} }

@ -77,13 +77,13 @@ public class SqlNote {
public static final int WIDGET_TYPE_COLUMN = 11; public static final int WIDGET_TYPE_COLUMN = 11;
public static final int SYNC_ID_COLUMN = 12; public static final int SYNC_ID_COLUMN = 12;
// 本地修改的符号
public static final int LOCAL_MODIFIED_COLUMN = 13; public static final int LOCAL_MODIFIED_COLUMN = 13;
// 在进入临时文件夹之前原始的父id未使用
public static final int ORIGIN_PARENT_ID_COLUMN = 14; public static final int ORIGIN_PARENT_ID_COLUMN = 14;
// 用户id
public static final int GTASK_ID_COLUMN = 15; public static final int GTASK_ID_COLUMN = 15;
//版本
public static final int VERSION_COLUMN = 16; public static final int VERSION_COLUMN = 16;
private Context mContext; private Context mContext;
@ -121,7 +121,8 @@ public class SqlNote {
private ContentValues mDiffNoteValues; private ContentValues mDiffNoteValues;
private ArrayList<SqlData> mDataList; private ArrayList<SqlData> mDataList;
//第一种构造函数
//构造函数参数只有context初始化新建的对象中的所有变量
public SqlNote(Context context) { public SqlNote(Context context) {
mContext = context; mContext = context;
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
@ -142,7 +143,8 @@ public class SqlNote {
mDiffNoteValues = new ContentValues(); mDiffNoteValues = new ContentValues();
mDataList = new ArrayList<SqlData>(); mDataList = new ArrayList<SqlData>();
} }
//第二种构造函数
//参数有context和cursor对cursor指向的对象进行初始化
public SqlNote(Context context, Cursor c) { public SqlNote(Context context, Cursor c) {
mContext = context; mContext = context;
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
@ -154,7 +156,8 @@ public class SqlNote {
mDiffNoteValues = new ContentValues(); mDiffNoteValues = new ContentValues();
} }
//第三种构造方式
//构造函数,参数有 context 和 id对 id 指向的对象进行初始化
public SqlNote(Context context, long id) { public SqlNote(Context context, long id) {
mContext = context; mContext = context;
mContentResolver = context.getContentResolver(); mContentResolver = context.getContentResolver();
@ -165,9 +168,11 @@ public class SqlNote {
loadDataContent(); loadDataContent();
mDiffNoteValues = new ContentValues(); mDiffNoteValues = new ContentValues();
} }
//功能通过id从光标处加载数据
//实现通过id获取ContentResolver中的相应内容并赋给cursor如果有内容就将移入文档并再次等待光标的内容否则日志显示警告最后关闭光标方法完毕
private void loadFromCursor(long id) { private void loadFromCursor(long id) {
Cursor c = null; Cursor c = null;
//避免异常
try { try {
c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)", c = mContentResolver.query(Notes.CONTENT_NOTE_URI, PROJECTION_NOTE, "(_id=?)",
new String[] { new String[] {
@ -184,7 +189,8 @@ public class SqlNote {
c.close(); c.close();
} }
} }
//功能通过cursor从光标加载数据
//实现各种get类型的函数通过光标c获取参数
private void loadFromCursor(Cursor c) { private void loadFromCursor(Cursor c) {
mId = c.getLong(ID_COLUMN); mId = c.getLong(ID_COLUMN);
mAlertDate = c.getLong(ALERTED_DATE_COLUMN); mAlertDate = c.getLong(ALERTED_DATE_COLUMN);
@ -199,7 +205,10 @@ public class SqlNote {
mWidgetType = c.getInt(WIDGET_TYPE_COLUMN); mWidgetType = c.getInt(WIDGET_TYPE_COLUMN);
mVersion = c.getLong(VERSION_COLUMN); mVersion = c.getLong(VERSION_COLUMN);
} }
//功能通过content机制获取共享数据并加载到数据库当前光标处
//实现获取ID对应content内容如果查询到该note的id确实有对应项即cursor有对应获取ID对应content内容
//如果光标处有内容提示note无数据warning当记录数量不为0则循环直到记录不存在不断地取出记录放到DataList中
//如果cursor为空警告最终判断光标为空则关闭
private void loadDataContent() { private void loadDataContent() {
Cursor c = null; Cursor c = null;
mDataList.clear(); mDataList.clear();
@ -225,16 +234,23 @@ public class SqlNote {
c.close(); c.close();
} }
} }
//功能设置通过content机制用于共享的数据信息
//实现:先判断是不是系统文件夹,再判断是否为文件夹类型,如果共享数据存在摘要,则将其赋给声明的 snippet变量否则变量为空
//如果SQLNote采用的是第一种构造方式,或者snippet为空则将snippet这一项键值存入contentvalue中尽管是“”
//如果是note获取提示日期设置用于共享数据的信息最后遍历 dataArray查找 id 为 dataId 的数据更新sqlData
public boolean setContent(JSONObject js) { public boolean setContent(JSONObject js) {
try { try {
JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE);
// 判断是不是系统文件夹
if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) {
Log.w(TAG, "cannot set system folder"); Log.w(TAG, "cannot set system folder");
// 判断是否为文件夹类型
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) {
// snnipet——片段、片断
// for folder we can only update the snnipet and type // for folder we can only update the snnipet and type
String snippet = note.has(NoteColumns.SNIPPET) ? note String snippet = note.has(NoteColumns.SNIPPET) ? note
.getString(NoteColumns.SNIPPET) : ""; .getString(NoteColumns.SNIPPET) : "";
// 如果SQLNote采用的是第一种构造方式,或者snippet为空则将snippet这一项键值存入contentvalue中尽管是“”
if (mIsCreate || !mSnippet.equals(snippet)) { if (mIsCreate || !mSnippet.equals(snippet)) {
mDiffNoteValues.put(NoteColumns.SNIPPET, snippet); mDiffNoteValues.put(NoteColumns.SNIPPET, snippet);
} }
@ -246,7 +262,9 @@ public class SqlNote {
mDiffNoteValues.put(NoteColumns.TYPE, type); mDiffNoteValues.put(NoteColumns.TYPE, type);
} }
mType = type; mType = type;
//如果是NOTE
} else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) { } else if (note.getInt(NoteColumns.TYPE) == Notes.TYPE_NOTE) {
// 获取提示日期
JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA);
long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID; long id = note.has(NoteColumns.ID) ? note.getLong(NoteColumns.ID) : INVALID_ID;
if (mIsCreate || mId != id) { if (mIsCreate || mId != id) {
@ -358,7 +376,10 @@ public class SqlNote {
} }
return true; return true;
} }
//功能获取content机制提供的数据并加载到note中
//实现:判断采用的是第一种构造方式,自然实施初始化而已,显示错误:没创建数据库
//再判断如果对象的类型是note类型这个对象的13项按键值对方式ID, mIdALERTED_DATE, mAlertDate···加入note中
//类型为系统文件或目录文件时将id类型以及摘要存入jsonobject,然后对应META_HEAD_NOTE键存入共享
public JSONObject getContent() { public JSONObject getContent() {
try { try {
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
@ -392,7 +413,9 @@ public class SqlNote {
} }
} }
js.put(GTaskStringUtils.META_HEAD_DATA, dataArray); js.put(GTaskStringUtils.META_HEAD_DATA, dataArray);
// 类型为系统文件或目录文件时
} else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) { } else if (mType == Notes.TYPE_FOLDER || mType == Notes.TYPE_SYSTEM) {
// 将id类型以及摘要存入jsonobject,然后对应META_HEAD_NOTE键存入共享
note.put(NoteColumns.ID, mId); note.put(NoteColumns.ID, mId);
note.put(NoteColumns.TYPE, mType); note.put(NoteColumns.TYPE, mType);
note.put(NoteColumns.SNIPPET, mSnippet); note.put(NoteColumns.SNIPPET, mSnippet);
@ -406,7 +429,7 @@ public class SqlNote {
} }
return null; return null;
} }
// 设置当前 id 的父 id
public void setParentId(long id) { public void setParentId(long id) {
mParentId = id; mParentId = id;
mDiffNoteValues.put(NoteColumns.PARENT_ID, id); mDiffNoteValues.put(NoteColumns.PARENT_ID, id);

@ -31,7 +31,7 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
// 创建Task类继承自父类Node
public class Task extends Node { public class Task extends Node {
private static final String TAG = Task.class.getSimpleName(); private static final String TAG = Task.class.getSimpleName();
@ -44,7 +44,8 @@ public class Task extends Node {
private Task mPriorSibling; private Task mPriorSibling;
private TaskList mParent; private TaskList mParent;
//功能Task类的构造函数对对象进行初始化
//实现:调用父类构造方法,对变量初始化
public Task() { public Task() {
super(); super();
mCompleted = false; mCompleted = false;
@ -53,12 +54,16 @@ public class Task extends Node {
mParent = null; mParent = null;
mMetaInfo = null; mMetaInfo = null;
} }
//功能获取创建的action。获取当前创建的action的属性值比如说它的id号、类型、index值。
//实现:首先新建一个 JSONObject 的对象js用来存放同步过程中所用到的 task 信息然后在共享数据js里存入action_type、action_id、index
//再新建一个 JSONObject 对象entity打包存放 namecreator idtype task判断是否有notes有则将其也放入entity中
//最后将entity、parent_id、dest_parent_type、list_id存入js中判断如果存在优先兄弟 task则将其 id 放入 js 中
public JSONObject getCreateAction(int actionId) { public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
try { try {
// action_type // action_type
// 共享数据存入动作类型action_ type
js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE); GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE);
@ -69,11 +74,13 @@ public class Task extends Node {
js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this)); js.put(GTaskStringUtils.GTASK_JSON_INDEX, mParent.getChildTaskIndex(this));
// entity_delta // entity_delta
// 新建一个 JSONObject 对象打包存放 namecreator idtype task
JSONObject entity = new JSONObject(); JSONObject entity = new JSONObject();
entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName());
entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null");
entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE,
GTaskStringUtils.GTASK_JSON_TYPE_TASK); GTaskStringUtils.GTASK_JSON_TYPE_TASK);
// 如果存在 notes ,则将其也放入 entity 中
if (getNotes() != null) { if (getNotes() != null) {
entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes()); entity.put(GTaskStringUtils.GTASK_JSON_NOTES, getNotes());
} }
@ -102,7 +109,8 @@ public class Task extends Node {
return js; return js;
} }
//功能获取更新的action
//实现和上面getCreateAction差不多
public JSONObject getUpdateAction(int actionId) { public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
@ -134,7 +142,8 @@ public class Task extends Node {
return js; return js;
} }
//功能通过远端的jsonobject获取任务内容
//实现首先判断js是否非空接着判断如果有id这个变量就进行gid的设置同样方法设置last_modified、name等变量
public void setContentByRemoteJSON(JSONObject js) { public void setContentByRemoteJSON(JSONObject js) {
if (js != null) { if (js != null) {
try { try {
@ -174,7 +183,10 @@ public class Task extends Node {
} }
} }
} }
//功能通过本地的jsonobject获取内容
//实现首先判断js是否为空或者没有META_HEAD_NOTE为空则显示日志创建JSONObject类note存入js的META_HEAD_NOTE
//创建JSONArray类dataArray存入META_HEAD_DATA判断note的TYPE不能匹配Notes的TYPE则无效
//最后遍历 dataArray 查找与数据库中DataConstants.NOTE 记录信息一致的 data
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)
|| !js.has(GTaskStringUtils.META_HEAD_DATA)) { || !js.has(GTaskStringUtils.META_HEAD_DATA)) {
@ -203,7 +215,8 @@ public class Task extends Node {
} }
} }
} }
//功能通过Content机制获取本地JSON数据。
//实现通过判断元数据是否存在如果不存在则创建一个新的对象并将信息完善。最后返回js对象。
public JSONObject getLocalJSONFromContent() { public JSONObject getLocalJSONFromContent() {
String name = getName(); String name = getName();
try { try {
@ -246,7 +259,8 @@ public class Task extends Node {
return null; return null;
} }
} }
//功能:设置元数据信息
//参数MetaData类 metaData元数据
public void setMetaInfo(MetaData metaData) { public void setMetaInfo(MetaData metaData) {
if (metaData != null && metaData.getNotes() != null) { if (metaData != null && metaData.getNotes() != null) {
try { try {
@ -257,7 +271,8 @@ public class Task extends Node {
} }
} }
} }
//功能:获取同步操作
//实现判断mMetaInfo是否被删除或者远程数据被删除然后判断光标传入的note ID是否匹配并判断本地的便签数据是否已更新
public int getSyncAction(Cursor c) { public int getSyncAction(Cursor c) {
try { try {
JSONObject noteInfo = null; JSONObject noteInfo = null;
@ -310,16 +325,17 @@ public class Task extends Node {
return SYNC_ACTION_ERROR; return SYNC_ACTION_ERROR;
} }
//功能:判断是否值得存放,即当前数据是否有效,若数据非空 或 名字合法存在且去除空格后的名字长度大于零则返回真值。
// 其它trim() 的作用是去除字符串前后的空格public String trim()返回字符串的副本,忽略前导空白和尾部空白
public boolean isWorthSaving() { public boolean isWorthSaving() {
return mMetaInfo != null || (getName() != null && getName().trim().length() > 0) return mMetaInfo != null || (getName() != null && getName().trim().length() > 0)
|| (getNotes() != null && getNotes().trim().length() > 0); || (getNotes() != null && getNotes().trim().length() > 0);
} }
// 将task设置为修改完毕
public void setCompleted(boolean completed) { public void setCompleted(boolean completed) {
this.mCompleted = completed; this.mCompleted = completed;
} }
// 设定mNotes
public void setNotes(String notes) { public void setNotes(String notes) {
this.mNotes = notes; this.mNotes = notes;
} }

@ -42,7 +42,8 @@ public class TaskList extends Node {
mChildren = new ArrayList<Task>(); mChildren = new ArrayList<Task>();
mIndex = 1; mIndex = 1;
} }
//功能:获取生成动作
//实现创建JSONObject js存入action_type、action_id、index、entity_delta生成并返回一个包含了一定数据的JSONObject实体
public JSONObject getCreateAction(int actionId) { public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
@ -73,7 +74,8 @@ public class TaskList extends Node {
return js; return js;
} }
//功能接受更新action返回jsonobject
//实现同上面getCreateAction类似
public JSONObject getUpdateAction(int actionId) { public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
@ -102,7 +104,8 @@ public class TaskList extends Node {
return js; return js;
} }
//功能:通过云端 JSON 数据设置实例化对象 js 的内容
//实现通过传入的js判断非空然后设置id、last_modified、name
public void setContentByRemoteJSON(JSONObject js) { public void setContentByRemoteJSON(JSONObject js) {
if (js != null) { if (js != null) {
try { try {
@ -128,7 +131,8 @@ public class TaskList extends Node {
} }
} }
} }
//功能:通过本地 JSON 数据设置对象 js 内容
//实现实现方法也与上面setContentByRemoteJSON类似不过设置的是根据本地js传入
public void setContentByLocalJSON(JSONObject js) { public void setContentByLocalJSON(JSONObject js) {
if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) {
Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); Log.w(TAG, "setContentByLocalJSON: nothing is avaiable");
@ -159,7 +163,8 @@ public class TaskList extends Node {
e.printStackTrace(); e.printStackTrace();
} }
} }
//功能从content获取本地json
//实现getname()函数获取文件夹名称
public JSONObject getLocalJSONFromContent() { public JSONObject getLocalJSONFromContent() {
try { try {
JSONObject js = new JSONObject(); JSONObject js = new JSONObject();
@ -185,7 +190,12 @@ public class TaskList extends Node {
return null; return null;
} }
} }
//功能:通过 cursor 获取同步信息
//实现首先判断本地记录是否被修改如果没有修改再判断光标处的ID与最后一次修改是否相等
//如果相等则返回“不同步”,如果不等则返回“同步”
//如果本地记录已经修改则判断获取的ID是否匹配若不匹配则返回同步动作失败
//其它“同步”是指将remote端更新至local端。另外为什么 if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified())
//为什么这个判断最后 if else返回的都是SYNC_ACTION_UPDATE_REMOTE
public int getSyncAction(Cursor c) { public int getSyncAction(Cursor c) {
try { try {
if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) { if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
@ -222,7 +232,10 @@ public class TaskList extends Node {
public int getChildTaskCount() { public int getChildTaskCount() {
return mChildren.size(); return mChildren.size();
} }
//功能:在当前任务表中添加新的子任务
//实现:如果传入的子任务不是空并且当前的子任务序列中不含有该任务,就将这个任务加入子任务中
//然后设置兄弟任务优先级,若子任务为空,返回 NULL否则返回子任务数量-1最后设置该任务的父任务
//返回值为是否成功添加任务
public boolean addChildTask(Task task) { public boolean addChildTask(Task task) {
boolean ret = false; boolean ret = false;
if (task != null && !mChildren.contains(task)) { if (task != null && !mChildren.contains(task)) {
@ -236,7 +249,9 @@ public class TaskList extends Node {
} }
return ret; return ret;
} }
//功能:在当前任务表的指定位置添加新的任务。
//实现先获取要添加的任务在任务表中的位置在索引位置添加任务update the task list
//然后让插入的任务与前后连在一块,将下一个任务设置兄弟任务优先级
public boolean addChildTask(Task task, int index) { public boolean addChildTask(Task task, int index) {
if (index < 0 || index > mChildren.size()) { if (index < 0 || index > mChildren.size()) {
Log.e(TAG, "add child task: invalid index"); Log.e(TAG, "add child task: invalid index");
@ -262,7 +277,8 @@ public class TaskList extends Node {
return true; return true;
} }
//功能删除TaskList中的一个Task
//实现方法同addChildTask类似
public boolean removeChildTask(Task task) { public boolean removeChildTask(Task task) {
boolean ret = false; boolean ret = false;
int index = mChildren.indexOf(task); int index = mChildren.indexOf(task);
@ -283,7 +299,7 @@ public class TaskList extends Node {
} }
return ret; return ret;
} }
// 功能将当前TaskList中含有的某个Task移到index位置
public boolean moveChildTask(Task task, int index) { public boolean moveChildTask(Task task, int index) {
if (index < 0 || index >= mChildren.size()) { if (index < 0 || index >= mChildren.size()) {
@ -301,7 +317,8 @@ public class TaskList extends Node {
return true; return true;
return (removeChildTask(task) && addChildTask(task, index)); return (removeChildTask(task) && addChildTask(task, index));
} }
//功能通过Gid寻找子任务未使用
//实现从头至尾遍历整个任务列表判断任务的gid与传入的gid是否相等
public Task findChildTaskByGid(String gid) { public Task findChildTaskByGid(String gid) {
for (int i = 0; i < mChildren.size(); i++) { for (int i = 0; i < mChildren.size(); i++) {
Task t = mChildren.get(i); Task t = mChildren.get(i);
@ -311,11 +328,11 @@ public class TaskList extends Node {
} }
return null; return null;
} }
// 获取子任务索引列表
public int getChildTaskIndex(Task task) { public int getChildTaskIndex(Task task) {
return mChildren.indexOf(task); return mChildren.indexOf(task);
} }
// 返回指定index的Task
public Task getChildTaskByIndex(int index) { public Task getChildTaskByIndex(int index) {
if (index < 0 || index >= mChildren.size()) { if (index < 0 || index >= mChildren.size()) {
Log.e(TAG, "getTaskByIndex: invalid index"); Log.e(TAG, "getTaskByIndex: invalid index");
@ -323,7 +340,7 @@ public class TaskList extends Node {
} }
return mChildren.get(index); return mChildren.get(index);
} }
// 返回指定gid的Task
public Task getChilTaskByGid(String gid) { public Task getChilTaskByGid(String gid) {
for (Task task : mChildren) { for (Task task : mChildren) {
if (task.getGid().equals(gid)) if (task.getGid().equals(gid))
@ -331,7 +348,7 @@ public class TaskList extends Node {
} }
return null; return null;
} }
//获取子任务列表
public ArrayList<Task> getChildTaskList() { public ArrayList<Task> getChildTaskList() {
return this.mChildren; return this.mChildren;
} }

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle. # Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the # For customization when using a Version Control System, please read the
# header note. # header note.
#Sat Nov 21 11:26:00 CST 2020 #Wed Dec 02 20:10:32 CST 2020
sdk.dir=D\:\\Sdk sdk.dir=C\:\\Users\\95459\\AppData\\Local\\Android\\Sdk

Loading…
Cancel
Save