注释部分

zyh
sleephardzz 3 years ago
parent f0fd12419d
commit 0497b83ef0

@ -26,6 +26,8 @@ import android.util.Log;
import java.util.HashMap;
public class Contact {
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";

@ -26,54 +26,93 @@ import org.json.JSONObject;
public class MetaData extends Task {
/**
* @Description: TAG
*/
private final static String TAG = MetaData.class.getSimpleName();
private String mRelatedGid = null;
/**
* @Description:
*/
public void setMeta(String gid, JSONObject metaInfo) {
try {
/**
* @Description: json
*/
metaInfo.put(GTaskStringUtils.META_HEAD_GTASK_ID, gid);
} catch (JSONException e) {
/**
* @Description:
*/
Log.e(TAG, "failed to put related gid");
}
setNotes(metaInfo.toString());
setName(GTaskStringUtils.META_NOTE_NAME);
}
/**
* @Description: GET
*/
public String getRelatedGid() {
return mRelatedGid;
}
/**
* @Description:
* zyh
*/
@Override
public boolean isWorthSaving() {
return getNotes() != null;
}
/**
* @Description: json
*/
@Override
public void setContentByRemoteJSON(JSONObject js) {
super.setContentByRemoteJSON(js);
if (getNotes() != null) {
try {
/**
* @Description: json
*/
JSONObject metaInfo = new JSONObject(getNotes().trim());
mRelatedGid = metaInfo.getString(GTaskStringUtils.META_HEAD_GTASK_ID);
} catch (JSONException e) {
/**
* @Description:
*/
Log.w(TAG, "failed to get related gid");
mRelatedGid = null;
}
}
}
/**
* @Description: jsonSET
*/
@Override
public void setContentByLocalJSON(JSONObject js) {
// this function should not be called
throw new IllegalAccessError("MetaData:setContentByLocalJSON should not be called");
}
/**
* @Description: jsonGET
*/
@Override
public JSONObject getLocalJSONFromContent() {
throw new IllegalAccessError("MetaData:getLocalJSONFromContent should not be called");
}
/**
* @Description:
*/
@Override
public int getSyncAction(Cursor c) {
throw new IllegalAccessError("MetaData:getSyncAction should not be called");

@ -21,32 +21,62 @@ import android.database.Cursor;
import org.json.JSONObject;
public abstract class Node {
/**
* @Description:
*/
public static final int SYNC_ACTION_NONE = 0;
/**
* @Description:
*/
public static final int SYNC_ACTION_ADD_REMOTE = 1;
/**
* @Description:
*/
public static final int SYNC_ACTION_ADD_LOCAL = 2;
/**
* @Description:
*/
public static final int SYNC_ACTION_DEL_REMOTE = 3;
/**
* @Description:
*/
public static final int SYNC_ACTION_DEL_LOCAL = 4;
/**
* @Description:
*/
public static final int SYNC_ACTION_UPDATE_REMOTE = 5;
/**
* @Description:
*/
public static final int SYNC_ACTION_UPDATE_LOCAL = 6;
/**
* @Description:
*/
public static final int SYNC_ACTION_UPDATE_CONFLICT = 7;
/**
* @Description:
*/
public static final int SYNC_ACTION_ERROR = 8;
private String mGid;
private String mName;
/**
* @Description:
*/
private long mLastModified;
/**
* @Description:
*/
private boolean mDeleted;
/**
* @Description: GET\SET
*
*/
public Node() {
mGid = null;
mName = "";

@ -35,16 +35,34 @@ import org.json.JSONException;
import org.json.JSONObject;
/**
* @Description: 便sqlnotedatanote
* SqlData
*/
public class SqlData {
/**
* @Description: TAG
*/
private static final String TAG = SqlData.class.getSimpleName();
/**
* @Description: mDataId-99999
*/
private static final int INVALID_ID = -99999;
/**
* @Description: NotesDataColumn
*/
public static final String[] PROJECTION_DATA = new String[] {
DataColumns.ID, DataColumns.MIME_TYPE, DataColumns.CONTENT, DataColumns.DATA1,
DataColumns.DATA3
};
/**
* @Description: sql5
* @SQLTABLE
*
*/
public static final int DATA_ID_COLUMN = 0;
public static final int DATA_MIME_TYPE_COLUMN = 1;
@ -71,6 +89,11 @@ public class SqlData {
private ContentValues mDiffDataValues;
/**
* @Description:
* mContentResolver
* mIsCreate
*/
public SqlData(Context context) {
mContentResolver = context.getContentResolver();
mIsCreate = true;
@ -144,6 +167,9 @@ public class SqlData {
return js;
}
/**
* @Description: commit
*/
public void commit(long noteId, boolean validateVersion, long version) {
if (mIsCreate) {
@ -183,6 +209,9 @@ public class SqlData {
mIsCreate = false;
}
/**
* @Description: id GET
*/
public long getId() {
return mDataId;
}

@ -38,11 +38,21 @@ import org.json.JSONObject;
import java.util.ArrayList;
/**
* @Description: notedata
*/
public class SqlNote {
/**
* @Description: TAG
*/
private static final String TAG = SqlNote.class.getSimpleName();
/**
* @Description: mDataId-99999
*/
private static final int INVALID_ID = -99999;
/**
* @Description: NotesDataColumn
*/
public static final String[] PROJECTION_NOTE = new String[] {
NoteColumns.ID, NoteColumns.ALERTED_DATE, NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE, NoteColumns.HAS_ATTACHMENT, NoteColumns.MODIFIED_DATE,
@ -439,7 +449,9 @@ public class SqlNote {
public boolean isNoteType() {
return mType == Notes.TYPE_NOTE;
}
/**
* @Description: commit
*/
public void commit(boolean validateVersion) {
if (mIsCreate) {
if (mId == INVALID_ID && mDiffNoteValues.containsKey(NoteColumns.ID)) {

@ -33,16 +33,28 @@ import org.json.JSONObject;
public class Task extends Node {
/**
* @Description: TAG
*/
private static final String TAG = Task.class.getSimpleName();
/**
* @Description:
*/
private boolean mCompleted;
private String mNotes;
private JSONObject mMetaInfo;
/**
* @Description:
*/
private Task mPriorSibling;
/**
* @Description:
*/
private TaskList mParent;
public Task() {

@ -31,8 +31,12 @@ import java.util.ArrayList;
public class TaskList extends Node {
/**
* @Description: TAG
*/
private static final String TAG = TaskList.class.getSimpleName();
/**当前TaskList的指针*/
private int mIndex;
private ArrayList<Task> mChildren;
@ -43,6 +47,10 @@ public class TaskList extends Node {
mIndex = 1;
}
/** (non-Javadoc)
* @see net.micode.notes.gtask.data.Node#getCreateAction(int)
* JSONObject
*/
public JSONObject getCreateAction(int actionId) {
JSONObject js = new JSONObject();
@ -74,6 +82,10 @@ public class TaskList extends Node {
return js;
}
/** (non-Javadoc)
* @see net.micode.notes.gtask.data.Node#getUpdateAction(int)
* JSONObject
*/
public JSONObject getUpdateAction(int actionId) {
JSONObject js = new JSONObject();

@ -16,13 +16,30 @@
package net.micode.notes.gtask.exception;
/**
* @Description: 便
*/
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;
/**
* @Description:
* serialVersionUIDjava
* serialVersionUID
*/
public ActionFailureException() {
super();
}
/**
* @Description:
* public RuntimeException(String message) {
* throw new RuntimeException("Stub!");
* }
*/
public ActionFailureException(String paramString) {
super(paramString);
}

@ -16,13 +16,28 @@
package net.micode.notes.gtask.exception;
/**
* @Description: 便
*/
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;
/**
* @Description:
* serialVersionUIDjava
* serialVersionUID
*/
public NetworkFailureException() {
super();
}
/**
* @Description:
* public Exception(String message, Throwable cause) {
* throw new RuntimeException("Stub!");
* }
*/
public NetworkFailureException(String paramString) {
super(paramString);
}

@ -29,6 +29,15 @@ import net.micode.notes.ui.NotesListActivity;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
* @Description: *GTask
*
*private void showNotification(int tickerId, String content)
*protected Integer doInBackground(Void... unused) 线
*protected void onProgressUpdate(String... progress) 使 线
*protected void onPostExecute(Integer result) Handler UI使doInBackground UI
* @author zyh
*/
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
@ -57,6 +66,10 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
mTaskManager.cancelSync();
}
/**
* @Description: onProgressUpdate()
* @author zyh
*/
public void publishProgess(String message) {
publishProgress(new String[] {
message
@ -82,6 +95,11 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
// mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
// }
/**
* @Description: getString, NotesPreferenceActivity.getSyncAccountName(mContext))
* sync_progress_login
* @author zyh
*/
@Override
protected Integer doInBackground(Void... unused) {
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity

@ -61,9 +61,18 @@ import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
/**
* @Description: GTASKGTASK
* 使accountManager JSONObject HttpParams authToken Gid
* @author zyh
*/
public class GTaskClient {
private static final String TAG = GTaskClient.class.getSimpleName();
/**
* @Description: get\post
* @author zyh
*/
private static final String GTASK_URL = "https://mail.google.com/tasks/";
private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig";
@ -90,6 +99,10 @@ public class GTaskClient {
private JSONArray mUpdateArray;
/**
* @Description:
* @author zyh
*/
private GTaskClient() {
mHttpClient = null;
mGetUrl = GTASK_GET_URL;
@ -102,6 +115,12 @@ public class GTaskClient {
mUpdateArray = null;
}
/**
* @Description:
* 使 getInstance()
* mInstance
* @author zyh
*/
public static synchronized GTaskClient getInstance() {
if (mInstance == null) {
mInstance = new GTaskClient();
@ -109,27 +128,54 @@ public class GTaskClient {
return mInstance;
}
/**
* @Description: Activity
*
*使URL使URL
*truefalse
* @author zyh
*/
public boolean login(Activity activity) {
// we suppose that the cookie would expire after 5 minutes
// then we need to re-login
/**
* @Description: 5
* @author zyh
*/
final long interval = 1000 * 60 * 5;
if (mLastLoginTime + interval < System.currentTimeMillis()) {
mLoggedin = false;
}
// need to re-login after account switch
/**
* @Description:
* @author zyh
*/
if (mLoggedin
&& !TextUtils.equals(getSyncAccount().name, NotesPreferenceActivity
.getSyncAccountName(activity))) {
mLoggedin = false;
}
/**
* @Description:
* @author zyh
*/
if (mLoggedin) {
Log.d(TAG, "already logged in");
return true;
}
/**
* @Description:
* @author zyh
*/
mLastLoginTime = System.currentTimeMillis();
/**
* @Description:
* @author zyh
*/
String authToken = loginGoogleAccount(activity, false);
if (authToken == null) {
Log.e(TAG, "login google account failed");
@ -137,13 +183,25 @@ public class GTaskClient {
}
// login with custom domain if necessary
/**
* @Description: 使
* @author zyh
*/
if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase()
.endsWith("googlemail.com"))) {
StringBuilder url = new StringBuilder(GTASK_URL).append("a/");
int index = mAccount.name.indexOf('@') + 1;
String suffix = mAccount.name.substring(index);
url.append(suffix + "/");
/**
* @Description: getUrl
* @author zyh
*/
mGetUrl = url.toString() + "ig";
/**
* @Description: postUrl
* @author zyh
*/
mPostUrl = url.toString() + "r/ig";
if (tryToLoginGtask(activity, authToken)) {
@ -152,6 +210,10 @@ public class GTaskClient {
}
// try to login with google official url
/**
* @Description: 使URI
* @author zyh
*/
if (!mLoggedin) {
mGetUrl = GTASK_GET_URL;
mPostUrl = GTASK_POST_URL;
@ -164,9 +226,28 @@ public class GTaskClient {
return true;
}
/**
* @Description:
*使
*使AccountManager
*
* @author zyh
*/
private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
/**
* @Description:
* @author zyh
*/
String authToken;
/**
* @Description: AccountManager
* @author zyh
*/
AccountManager accountManager = AccountManager.get(activity);
/**
* @Description: com.googleaccoun
* @author zyh
*/
Account[] accounts = accountManager.getAccountsByType("com.google");
if (accounts.length == 0) {
@ -176,6 +257,10 @@ public class GTaskClient {
String accountName = NotesPreferenceActivity.getSyncAccountName(activity);
Account account = null;
/**
* @Description: accounts
* @author zyh
*/
for (Account a : accounts) {
if (a.name.equals(accountName)) {
account = a;
@ -190,11 +275,19 @@ public class GTaskClient {
}
// get the token now
/**
* @Description:
* @author zyh
*/
AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account,
"goanna_mobile", null, activity, null, null);
try {
Bundle authTokenBundle = accountManagerFuture.getResult();
authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN);
/**
* @Description: invalidateTokeninvalidateAuthToken(String, String)token
* @author zyh
*/
if (invalidateToken) {
accountManager.invalidateAuthToken("com.google", authToken);
loginGoogleAccount(activity, false);
@ -323,12 +416,24 @@ public class GTaskClient {
}
}
/**
* @Description: *JSON
*jsonjs
*UrlEncodedFormEntity entityhttpPost.setEntity(entity)jshttpPost
*使getResponseContent
*json
* @author zyh
*/
private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
if (!mLoggedin) {
Log.e(TAG, "please login first");
throw new ActionFailureException("not logged in");
}
/**
* @Description: httpPostjs
* @author zyh
*/
HttpPost httpPost = createHttpPost();
try {
LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
@ -337,6 +442,10 @@ public class GTaskClient {
httpPost.setEntity(entity);
// execute the post
/**
* @Description:
* @author zyh
*/
HttpResponse response = mHttpClient.execute(httpPost);
String jsString = getResponseContent(response.getEntity());
return new JSONObject(jsString);
@ -360,6 +469,14 @@ public class GTaskClient {
}
}
/**
* @Description:
* * .gtask.data.TaskTask
* * jsonTask,jsPost
* * postRequest
* * 使task.setGidtasknew_ID
* @author zyh
*/
public void createTask(Task task) throws NetworkFailureException {
commitUpdate();
try {
@ -386,6 +503,10 @@ public class GTaskClient {
}
}
/**
* @Description: createTasktasklistgid
* @author zyh
*/
public void createTaskList(TaskList tasklist) throws NetworkFailureException {
commitUpdate();
try {
@ -412,6 +533,12 @@ public class GTaskClient {
}
}
/**
* @Description:
* 使JSONObject使jsPost.putPutUpdateArrayClientVersion
* 使postRequestjspost,
* @author zyh
*/
public void commitUpdate() throws NetworkFailureException {
if (mUpdateArray != null) {
try {
@ -433,6 +560,11 @@ public class GTaskClient {
}
}
/**
* @Description:
* commitUpdate()
* @author zyh
*/
public void addUpdateNode(Node node) throws NetworkFailureException {
if (node != null) {
// too many update items may result in an error
@ -447,6 +579,13 @@ public class GTaskClient {
}
}
/**
* @Description: task, tasktask
* getGidtaskgid
* JSONObject.put(String name, Object value)task
* postRequest
* @author zyh
*/
public void moveTask(Task task, TaskList preParent, TaskList curParent)
throws NetworkFailureException {
commitUpdate();
@ -547,6 +686,10 @@ public class GTaskClient {
}
}
/**
* @Description: TASKListgid,
* @author zyh
*/
public JSONArray getTaskList(String listGid) throws NetworkFailureException {
commitUpdate();
try {

@ -87,8 +87,20 @@ public class GTaskManager {
private HashMap<Long, String> mNidToGid;
/**
* @Description:
* @author zyh
*/
private GTaskManager() {
/**
* @Description: flase
* @author zyh
*/
mSyncing = false;
/**
* @Description: flase
* @author zyh
*/
mCancelled = false;
mGTaskListHashMap = new HashMap<String, TaskList>();
mGTaskHashMap = new HashMap<String, Node>();
@ -99,6 +111,10 @@ public class GTaskManager {
mNidToGid = new HashMap<Long, String>();
}
/**
* @Description: synchronized线
* @author zyh
*/
public static synchronized GTaskManager getInstance() {
if (mInstance == null) {
mInstance = new GTaskManager();
@ -106,13 +122,26 @@ public class GTaskManager {
return mInstance;
}
/**
* @Description: synchronized线
* @author zyh
*/
public synchronized void setActivityContext(Activity activity) {
// used for getting authtoken
mActivity = activity;
}
/**
* @Description:
* @author zyh
*/
public int sync(Context context, GTaskASyncTask asyncTask) {
if (mSyncing) {
/**
* @Description: debug
* @author zyh
*/
Log.d(TAG, "Sync is in progress");
return STATE_SYNC_IN_PROGRESS;
}
@ -140,6 +169,10 @@ public class GTaskManager {
// get the task list from google
asyncTask.publishProgess(mContext.getString(R.string.sync_progress_init_list));
/**
* @Description: GoogleJSONtasklistTaskList
* @author zyh
*/
initGTaskList();
// do content sync work
@ -168,17 +201,35 @@ public class GTaskManager {
return mCancelled ? STATE_SYNC_CANCELLED : STATE_SUCCESS;
}
/**
* @Description: GtaskListGoogleJSONtasklistTaskList
* @author zyh
*/
private void initGTaskList() throws NetworkFailureException {
if (mCancelled)
return;
GTaskClient client = GTaskClient.getInstance();
try {
/**
* @Description: JsonName Value()MapJsonObjectbantouyan-jsonJsonJson
* {"key1":value1,"key2",value2....};key
* ajaxjsjson使
* @author zyh
*/
JSONArray jsTaskLists = client.getTaskLists();
// init meta list first
mMetaList = null;
for (int i = 0; i < jsTaskLists.length(); i++) {
/**
* @Description: JSONObjectJSONArrayJASONObjec
* @author zyh
*/
JSONObject object = jsTaskLists.getJSONObject(i);
/**
* @Description: GIDNAME
* @author zyh
*/
String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
@ -213,6 +264,10 @@ public class GTaskManager {
// init task list
for (int i = 0; i < jsTaskLists.length(); i++) {
/**
* @Description: getString
* @author zyh
*/
JSONObject object = jsTaskLists.getJSONObject(i);
String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID);
String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME);
@ -247,6 +302,10 @@ public class GTaskManager {
}
}
/**
* @Description:
* @author zyh
*/
private void syncContent() throws NetworkFailureException {
int syncType;
Cursor c = null;
@ -476,6 +535,11 @@ public class GTaskManager {
GTaskClient.getInstance().commitUpdate();
}
/**
* @Description: syncTypeaddLocalNodeaddRemoteNodedeleteNodeupdateLocalNodeupdateRemoteNode
* SWITCH CASE
* @author zyh
*/
private void doContentSync(int syncType, Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -522,6 +586,10 @@ public class GTaskManager {
}
}
/**
* @Description: Node
* @author zyh
*/
private void addLocalNode(Node node) throws NetworkFailureException {
if (mCancelled) {
return;
@ -596,6 +664,10 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
* @Description: updatenode
* @author zyh
*/
private void updateLocalNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -619,6 +691,10 @@ public class GTaskManager {
updateRemoteMeta(node.getGid(), sqlNote);
}
/**
* @Description: Node
* @author zyh
*/
private void addRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -692,6 +768,10 @@ public class GTaskManager {
mNidToGid.put(sqlNote.getId(), n.getGid());
}
/**
* @Description: Nodemeta(updateRemoteMeta)
* @author zyh
*/
private void updateRemoteNode(Node node, Cursor c) throws NetworkFailureException {
if (mCancelled) {
return;
@ -730,6 +810,10 @@ public class GTaskManager {
sqlNote.commit(true);
}
/**
* @Description: meta meta----------
* @author zyh
*/
private void updateRemoteMeta(String gid, SqlNote sqlNote) throws NetworkFailureException {
if (sqlNote != null && sqlNote.isNoteType()) {
MetaData metaData = mMetaHashMap.get(gid);
@ -746,6 +830,10 @@ public class GTaskManager {
}
}
/**
* @Description: syncID
* @author zyh
*/
private void refreshLocalSyncId() throws NetworkFailureException {
if (mCancelled) {
return;
@ -790,10 +878,18 @@ public class GTaskManager {
}
}
/**
* @Description: ,mAccount.name
* @author zyh
*/
public String getSyncAccount() {
return GTaskClient.getInstance().getSyncAccount().name;
}
/**
* @Description: mCancelledtrue
* @author zyh
*/
public void cancelSync() {
mCancelled = true;
}

Loading…
Cancel
Save