You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

`Node.java`
```java
/*
* 版权所有 (c) 2010-2011, MiCode 开源社区 (www.micode.net)
*
* 根据 Apache 许可证 2.0 版(“许可证”)授权;
* 除非遵守许可证的规定,否则不得使用此文件。
* 您可以在以下位置获取许可证的副本:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 除非适用法律要求或书面同意,否则根据许可证分发的软件按“原样”分发,
* 不附带任何明示或暗示的保证或条件。
* 请参阅许可证,了解有关权限和限制的具体语言。
*/
package net.micode.notes.gtask.data;
import android.database.Cursor;
import org.json.JSONObject;
/**
* 节点类,用于表示 Google 任务数据的抽象节点.
*/
public abstract class Node {
// 同步操作常量
public static final int SYNC_ACTION_NONE = 0; // 无操作
public static final int SYNC_ACTION_ADD_REMOTE = 1; // 添加到远程
public static final int SYNC_ACTION_ADD_LOCAL = 2; // 添加到本地
public static final int SYNC_ACTION_DEL_REMOTE = 3; // 从远程删除
public static final int SYNC_ACTION_DEL_LOCAL = 4; // 从本地删除
public static final int SYNC_ACTION_UPDATE_REMOTE = 5; // 更新远程
public static final int SYNC_ACTION_UPDATE_LOCAL = 6; // 更新本地
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7; // 更新冲突
public static final int SYNC_ACTION_ERROR = 8; // 错误
// Google 任务 ID
private String mGid;
// 节点名称
private String mName;
// 最后修改时间
private long mLastModified;
// 是否已删除
private boolean mDeleted;
/**
* 构造函数.
*/
public Node() {
mGid = null;
mName = "";
mLastModified = 0;
mDeleted = false;
}
/**
* 获取创建操作的 JSON 对象.
* @param actionId 操作 ID
* @return 创建操作的 JSON 对象
*/
public abstract JSONObject getCreateAction(int actionId);
/**
* 获取更新操作的 JSON 对象.
* @param actionId 操作 ID
* @return 更新操作的 JSON 对象
*/
public abstract JSONObject getUpdateAction(int actionId);
/**
* 通过远程 JSON 对象设置内容.
* @param js 远程 JSON 对象
*/
public abstract void setContentByRemoteJSON(JSONObject js);
/**
* 通过本地 JSON 对象设置内容.
* @param js 本地 JSON 对象
*/
public abstract void setContentByLocalJSON(JSONObject js);
/**
* 从内容获取本地 JSON 对象.
* @return 本地 JSON 对象
*/
public abstract JSONObject getLocalJSONFromContent();
/**
* 获取同步操作.
* @param c 游标
* @return 同步操作
*/
public abstract int getSyncAction(Cursor c);
/**
* 设置 Google 任务 ID.
* @param gid Google 任务 ID
*/
public void setGid(String gid) {
this.mGid = gid;
}
/**
* 设置节点名称.
* @param name 节点名称
*/
public void setName(String name) {
this.mName = name;
}
/**
* 设置最后修改时间.
* @param lastModified 最后修改时间
*/
public void setLastModified(long lastModified) {
this.mLastModified = lastModified;
}
/**
* 设置是否已删除.
* @param deleted 是否已删除
*/
public void setDeleted(boolean deleted) {
this.mDeleted = deleted;
}
/**
* 获取 Google 任务 ID.
* @return Google 任务 ID
*/
public String getGid() {
return this.mGid;
}
/**
* 获取节点名称.
* @return 节点名称
*/
public String getName() {
return this.mName;
}
/**
* 获取最后修改时间.
* @return 最后修改时间
*/
public long getLastModified() {
return this.mLastModified;
}
/**
* 获取是否已删除.
* @return 是否已删除
*/
public boolean getDeleted() {
return this.mDeleted;
}
}
```