|  |  | @ -64,50 +64,52 @@ import java.util.zip.InflaterInputStream; | 
			
		
	
		
		
			
				
					
					|  |  |  | public class GTaskClient { |  |  |  | public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final String TAG = GTaskClient.class.getSimpleName(); |  |  |  |     private static final String TAG = GTaskClient.class.getSimpleName(); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final String GTASK_URL = "https://mail.google.com/tasks/"; |  |  |  |     private static final String GTASK_URL = "https://mail.google.com/tasks/"; // GTask 的基础 URL
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig"; |  |  |  |     private static final String GTASK_GET_URL = "https://mail.google.com/tasks/ig"; // 获取 GTask 数据的 URL
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static final String GTASK_POST_URL = "https://mail.google.com/tasks/r/ig"; |  |  |  |     private static final String GTASK_POST_URL = "https://mail.google.com/tasks/r/ig"; // 提交 GTask 数据的 URL
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private static GTaskClient mInstance = null; |  |  |  |     private static GTaskClient mInstance = null; // 单例模式,保存 GTaskClient 的唯一实例
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private DefaultHttpClient mHttpClient; |  |  |  |     private DefaultHttpClient mHttpClient; // HTTP 客户端
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private String mGetUrl; |  |  |  |     private String mGetUrl; // 获取 GTask 数据的完整 URL
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private String mPostUrl; |  |  |  |     private String mPostUrl; // 提交 GTask 数据的完整 URL
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mClientVersion; |  |  |  |     private long mClientVersion; // 客户端版本号
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private boolean mLoggedin; |  |  |  |     private boolean mLoggedin; // 是否已登录
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private long mLastLoginTime; |  |  |  |     private long mLastLoginTime; // 上次登录时间
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private int mActionId; |  |  |  |     private int mActionId; // 操作 ID
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private Account mAccount; |  |  |  |     private Account mAccount; // GTask 帐户
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     private JSONArray mUpdateArray; |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private JSONArray mUpdateArray; // 待更新的 GTask 数据
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private GTaskClient() { |  |  |  |     private GTaskClient() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mHttpClient = null; |  |  |  |         mHttpClient = null; // 初始化 HTTP 客户端为 null
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mGetUrl = GTASK_GET_URL; |  |  |  |         mGetUrl = GTASK_GET_URL; // 初始化获取 GTask 数据的 URL
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mPostUrl = GTASK_POST_URL; |  |  |  |         mPostUrl = GTASK_POST_URL; // 初始化提交 GTask 数据的 URL
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mClientVersion = -1; |  |  |  |         mClientVersion = -1; // 初始化客户端版本号为 -1
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mLoggedin = false; |  |  |  |         mLoggedin = false; // 初始化登录状态为 false
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mLastLoginTime = 0; |  |  |  |         mLastLoginTime = 0; // 初始化上次登录时间为 0
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mActionId = 1; |  |  |  |         mActionId = 1; // 初始化操作 ID 为 1
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mAccount = null; |  |  |  |         mAccount = null; // 初始化 GTask 帐户为 null
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         mUpdateArray = null; |  |  |  |         mUpdateArray = null; // 初始化待更新的 GTask 数据为 null
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     }/*该构造方法用于创建GTaskClient的实例,其中将mHttpClient、mAccount、mUpdateArray等成员变量初始化为 null 或默认值,将mGetUrl和mPostUrl初始化为 GTask 的默认 URL,将mClientVersion初始化为 -1,将mLoggedin初始化为 false,将mLastLoginTime初始化为 0,将mActionId初始化为 1。 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     这里使用了默认访问控制符private,意味着该构造方法只能在GTaskClient类内部使用,不能在其他类中创建GTaskClient的实例。*/ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public static synchronized GTaskClient getInstance() { |  |  |  |     public static synchronized GTaskClient getInstance() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (mInstance == null) { |  |  |  |         if (mInstance == null) { // 如果唯一实例不存在
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             mInstance = new GTaskClient(); |  |  |  |             mInstance = new GTaskClient(); // 则创建一个新实例
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         return mInstance; |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return mInstance; // 返回唯一实例
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     }/*该方法是单例模式的实现,用于获取GTaskClient的唯一实例。在该方法内部,首先判断唯一实例是否已经存在,如果不存在则创建一个新实例,并将其赋值给mInstance。最后返回唯一实例。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     由于该方法可能被多个线程同时调用,所以使用了synchronized关键字来保证在同一时刻只有一个线程能够访问该方法。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     同时,该方法返回的是静态成员变量mInstance,因此可以通过GTaskClient.getInstance()的方式在任意位置获取GTaskClient的唯一实例。*/ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public boolean login(Activity activity) { |  |  |  |     public boolean login(Activity activity) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         // we suppose that the cookie would expire after 5 minutes
 |  |  |  |         // we suppose that the cookie would expire after 5 minutes
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -124,34 +126,34 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             mLoggedin = false; |  |  |  |             mLoggedin = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (mLoggedin) { |  |  |  |         if (mLoggedin) { // 如果已登录,则直接返回
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.d(TAG, "already logged in"); |  |  |  |             Log.d(TAG, "already logged in"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             return true; |  |  |  |             return true; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         mLastLoginTime = System.currentTimeMillis(); |  |  |  |         mLastLoginTime = System.currentTimeMillis(); // 记录登录时间
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         String authToken = loginGoogleAccount(activity, false); |  |  |  |         String authToken = loginGoogleAccount(activity, false); // 登录 Google 帐户,获取授权令牌
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         if (authToken == null) { |  |  |  |         if (authToken == null) { // 如果登录失败,则返回 false
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, "login google account failed"); |  |  |  |             Log.e(TAG, "login google account failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             return false; |  |  |  |             return false; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         // login with custom domain if necessary
 |  |  |  |         // login with custom domain if necessary
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase() |  |  |  |         if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase() | 
			
		
	
		
		
			
				
					
					|  |  |  |                 .endsWith("googlemail.com"))) { |  |  |  |                 .endsWith("googlemail.com"))) { // 如果不是 Gmail 或 Googlemail 帐户,则使用自定义域名登录
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             StringBuilder url = new StringBuilder(GTASK_URL).append("a/"); |  |  |  |             StringBuilder url = new StringBuilder(GTASK_URL).append("a/"); // 构造自定义域名的 URL
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             int index = mAccount.name.indexOf('@') + 1; |  |  |  |             int index = mAccount.name.indexOf('@') + 1; | 
			
		
	
		
		
			
				
					
					|  |  |  |             String suffix = mAccount.name.substring(index); |  |  |  |             String suffix = mAccount.name.substring(index); | 
			
		
	
		
		
			
				
					
					|  |  |  |             url.append(suffix + "/"); |  |  |  |             url.append(suffix + "/"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             mGetUrl = url.toString() + "ig"; |  |  |  |             mGetUrl = url.toString() + "ig"; // 更新获取 GTask 数据的 URL
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             mPostUrl = url.toString() + "r/ig"; |  |  |  |             mPostUrl = url.toString() + "r/ig"; // 更新提交 GTask 数据的 URL
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (tryToLoginGtask(activity, authToken)) { |  |  |  |             if (tryToLoginGtask(activity, authToken)) { // 尝试登录 GTask
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 mLoggedin = true; |  |  |  |                 mLoggedin = true; // 登录成功
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         // try to login with google official url
 |  |  |  |         // 如果自定义域名登录失败,则使用 Google 官方 URL 登录
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         if (!mLoggedin) { |  |  |  |         if (!mLoggedin) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             mGetUrl = GTASK_GET_URL; |  |  |  |             mGetUrl = GTASK_GET_URL; | 
			
		
	
		
		
			
				
					
					|  |  |  |             mPostUrl = GTASK_POST_URL; |  |  |  |             mPostUrl = GTASK_POST_URL; | 
			
		
	
	
		
		
			
				
					|  |  | @ -160,30 +162,35 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         mLoggedin = true; |  |  |  |         mLoggedin = true; // 登录成功
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         return true; |  |  |  |         return true; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     }/*该方法用于登录 GTask,首先检查上次登录时间是否超过 5 分钟,如果超过则需要重新登录,将mLoggedin设置为 false。 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     然后判断当前帐户是否发生切换,如果发生切换也需要重新登录,同样将mLoggedin设置为 false。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果已经登录,则直接返回 true。否则,记录本次登录时间,然后使用loginGoogleAccount()方法登录 Google 帐户,获取授权令牌。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果登录失败,则返回 false。接下来,如果当前帐户不是 Gmail 或 Googlemail 帐户,则使用自定义域名登录,更新获取 GTask 数据和提交 GTask 数据的 URL,然后尝试登录 GTask。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果自定义域名登录失败,则使用 Google 官方 URL 登录。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     无论使用哪种方式登录成功,最后将mLoggedin设置为 true,表示已经登录成功。*/ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private String loginGoogleAccount(Activity activity, boolean invalidateToken) { |  |  |  |     private String loginGoogleAccount(Activity activity, boolean invalidateToken) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         String authToken; |  |  |  |         String authToken; | 
			
		
	
		
		
			
				
					
					|  |  |  |         AccountManager accountManager = AccountManager.get(activity); |  |  |  |         AccountManager accountManager = AccountManager.get(activity); // 获取 AccountManager 实例
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         Account[] accounts = accountManager.getAccountsByType("com.google"); |  |  |  |         Account[] accounts = accountManager.getAccountsByType("com.google"); // 获取所有 Google 帐户
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (accounts.length == 0) { |  |  |  |         if (accounts.length == 0) { // 如果没有可用的 Google 帐户,则返回 null
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, "there is no available google account"); |  |  |  |             Log.e(TAG, "there is no available google account"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             return null; |  |  |  |             return null; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         String accountName = NotesPreferenceActivity.getSyncAccountName(activity); |  |  |  |         String accountName = NotesPreferenceActivity.getSyncAccountName(activity); // 获取设置中的同步帐户名称
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         Account account = null; |  |  |  |         Account account = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |         for (Account a : accounts) { |  |  |  |         for (Account a : accounts) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (a.name.equals(accountName)) { |  |  |  |             if (a.name.equals(accountName)) { // 如果找到同名帐户,则使用该帐户
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 account = a; |  |  |  |                 account = a; | 
			
		
	
		
		
			
				
					
					|  |  |  |                 break; |  |  |  |                 break; | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (account != null) { |  |  |  |         if (account != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             mAccount = account; |  |  |  |             mAccount = account; // 更新当前使用的帐户
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, "unable to get an account with the same name in the settings"); |  |  |  |             Log.e(TAG, "unable to get an account with the same name in the settings"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             return null; |  |  |  |             return null; | 
			
		
	
	
		
		
			
				
					|  |  | @ -191,39 +198,48 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         // get the token now
 |  |  |  |         // get the token now
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account, |  |  |  |         AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account, | 
			
		
	
		
		
			
				
					
					|  |  |  |                 "goanna_mobile", null, activity, null, null); |  |  |  |                 "goanna_mobile", null, activity, null, null); // 获取 token
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Bundle authTokenBundle = accountManagerFuture.getResult(); |  |  |  |             Bundle authTokenBundle = accountManagerFuture.getResult(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN); |  |  |  |             authToken = authTokenBundle.getString(AccountManager.KEY_AUTHTOKEN); // 从 Bundle 中获取 token
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             if (invalidateToken) { |  |  |  |             if (invalidateToken) { // 如果需要使 token 失效
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 accountManager.invalidateAuthToken("com.google", authToken); |  |  |  |                 accountManager.invalidateAuthToken("com.google", authToken); // 使 token 失效
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 loginGoogleAccount(activity, false); |  |  |  |                 loginGoogleAccount(activity, false); // 重新登录
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (Exception e) { |  |  |  |         } catch (Exception e) { // 获取 token 失败
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, "get auth token failed"); |  |  |  |             Log.e(TAG, "get auth token failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             authToken = null; |  |  |  |             authToken = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         return authToken; |  |  |  |         return authToken; // 返回 token
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*该方法的作用是获取 Google 帐户的 token,以用于访问 Google 服务。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     它首先获取所有的 Google 帐户,然后根据设置中的同步帐户名称选择使用哪个帐户。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     接着,它使用AccountManager获取该帐户的 token,并返回该 token。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果invalidateToken参数为true,则该方法会使 token 失效,并重新登录,以获取新的 token。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private boolean tryToLoginGtask(Activity activity, String authToken) { |  |  |  |     private boolean tryToLoginGtask(Activity activity, String authToken) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!loginGtask(authToken)) { |  |  |  |         if (!loginGtask(authToken)) { // 如果登录 GTask 失败
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             // maybe the auth token is out of date, now let's invalidate the
 |  |  |  |             // maybe the auth token is out of date, now let's invalidate the
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // token and try again
 |  |  |  |             // token and try again
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             authToken = loginGoogleAccount(activity, true); |  |  |  |             authToken = loginGoogleAccount(activity, true); // 使 token 失效并重新登录
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             if (authToken == null) { |  |  |  |             if (authToken == null) { // 如果重新登录失败,则返回 false
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 Log.e(TAG, "login google account failed"); |  |  |  |                 Log.e(TAG, "login google account failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return false; |  |  |  |                 return false; | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (!loginGtask(authToken)) { |  |  |  |             if (!loginGtask(authToken)) { // 如果重新登录 GTask 仍然失败,则返回 false
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 Log.e(TAG, "login gtask failed"); |  |  |  |                 Log.e(TAG, "login gtask failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 return false; |  |  |  |                 return false; | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |         return true; |  |  |  |         return true; // 登录 GTask 成功,返回 true
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*该方法的作用是尝试登录 GTask,它接收一个authToken参数,该参数是通过loginGoogleAccount()方法获取的 Google 帐户的 token。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果登录 GTask 失败,则会使 token 失效并重新登录,再次尝试登录 GTask。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果重新登录失败,则返回false,否则返回true。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private boolean loginGtask(String authToken) { |  |  |  |     private boolean loginGtask(String authToken) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         int timeoutConnection = 10000; |  |  |  |         int timeoutConnection = 10000; | 
			
		
	
	
		
		
			
				
					|  |  | @ -231,6 +247,8 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |         HttpParams httpParameters = new BasicHttpParams(); |  |  |  |         HttpParams httpParameters = new BasicHttpParams(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); |  |  |  |         HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection); | 
			
		
	
		
		
			
				
					
					|  |  |  |         HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); |  |  |  |         HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         // 设置 HttpClient 的参数
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         mHttpClient = new DefaultHttpClient(httpParameters); |  |  |  |         mHttpClient = new DefaultHttpClient(httpParameters); | 
			
		
	
		
		
			
				
					
					|  |  |  |         BasicCookieStore localBasicCookieStore = new BasicCookieStore(); |  |  |  |         BasicCookieStore localBasicCookieStore = new BasicCookieStore(); | 
			
		
	
		
		
			
				
					
					|  |  |  |         mHttpClient.setCookieStore(localBasicCookieStore); |  |  |  |         mHttpClient.setCookieStore(localBasicCookieStore); | 
			
		
	
	
		
		
			
				
					|  |  | @ -239,11 +257,10 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |         // login gtask
 |  |  |  |         // login gtask
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             String loginUrl = mGetUrl + "?auth=" + authToken; |  |  |  |             String loginUrl = mGetUrl + "?auth=" + authToken; | 
			
		
	
		
		
			
				
					
					|  |  |  |             HttpGet httpGet = new HttpGet(loginUrl); |  |  |  |             HttpGet httpGet = new HttpGet(loginUrl); // 创建 HTTP GET 请求
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             HttpResponse response = null; |  |  |  |             HttpResponse response = mHttpClient.execute(httpGet); // 执行请求
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             response = mHttpClient.execute(httpGet); |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // get the cookie now
 |  |  |  |             // 获取 cookie
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             List<Cookie> cookies = mHttpClient.getCookieStore().getCookies(); |  |  |  |             List<Cookie> cookies = mHttpClient.getCookieStore().getCookies(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             boolean hasAuthCookie = false; |  |  |  |             boolean hasAuthCookie = false; | 
			
		
	
		
		
			
				
					
					|  |  |  |             for (Cookie cookie : cookies) { |  |  |  |             for (Cookie cookie : cookies) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -255,7 +272,7 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Log.w(TAG, "it seems that there is no auth cookie"); |  |  |  |                 Log.w(TAG, "it seems that there is no auth cookie"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // get the client version
 |  |  |  |             // 获取客户端版本
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             String resString = getResponseContent(response.getEntity()); |  |  |  |             String resString = getResponseContent(response.getEntity()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             String jsBegin = "_setup("; |  |  |  |             String jsBegin = "_setup("; | 
			
		
	
		
		
			
				
					
					|  |  |  |             String jsEnd = ")}</script>"; |  |  |  |             String jsEnd = ")}</script>"; | 
			
		
	
	
		
		
			
				
					|  |  | @ -279,49 +296,63 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         return true; |  |  |  |         return true; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*该方法的作用是使用给定的authToken登录 GTask。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     它创建了一个 HTTP GET 请求,并将authToken添加到 URL 末尾,然后执行该请求并获取响应。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     它还获取了响应中包含的 cookie,并将客户端版本存储在mClientVersion中。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果登录成功,则返回true,否则返回false。如果发生异常,则返回false。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private int getActionId() { |  |  |  |     private int getActionId() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return mActionId++; |  |  |  |         return mActionId++; // 返回下一个 action ID,并将 mActionId 加 1
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private HttpPost createHttpPost() { |  |  |  |     private HttpPost createHttpPost() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         HttpPost httpPost = new HttpPost(mPostUrl); |  |  |  |         HttpPost httpPost = new HttpPost(mPostUrl); // 创建一个 HTTP POST 请求
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); |  |  |  |         httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // 设置请求头的 Content-Type
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         httpPost.setHeader("AT", "1"); |  |  |  |         httpPost.setHeader("AT", "1"); // 设置请求头的 AT 字段为 1
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         return httpPost; |  |  |  |         return httpPost; // 返回创建的 HTTP POST 请求
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     }/*getActionId()的作用是获取下一个 action ID,每次调用它都会将mActionId加 1,并返回加 1 后的值。 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     createHttpPost()的作用是创建一个 HTTP POST 请求,并设置请求头的 Content-Type 为application/x-www-form-urlencoded;charset=utf-8,设置请求头的 AT 字段为 1。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     它返回创建的 HTTP POST 请求对象。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private String getResponseContent(HttpEntity entity) throws IOException { |  |  |  |     private String getResponseContent(HttpEntity entity) throws IOException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         String contentEncoding = null; |  |  |  |         String contentEncoding = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (entity.getContentEncoding() != null) { |  |  |  |         if (entity.getContentEncoding() != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             contentEncoding = entity.getContentEncoding().getValue(); |  |  |  |             contentEncoding = entity.getContentEncoding().getValue(); // 获取响应内容的编码方式
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.d(TAG, "encoding: " + contentEncoding); |  |  |  |             Log.d(TAG, "encoding: " + contentEncoding); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         InputStream input = entity.getContent(); |  |  |  |         InputStream input = entity.getContent(); // 获取响应内容的输入流
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) { |  |  |  |         if (contentEncoding != null && contentEncoding.equalsIgnoreCase("gzip")) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             input = new GZIPInputStream(entity.getContent()); |  |  |  |             input = new GZIPInputStream(entity.getContent()); // 如果响应内容被 gzip 压缩了,则创建一个 GZIPInputStream 解压缩
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) { |  |  |  |         } else if (contentEncoding != null && contentEncoding.equalsIgnoreCase("deflate")) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Inflater inflater = new Inflater(true); |  |  |  |             Inflater inflater = new Inflater(true); | 
			
		
	
		
		
			
				
					
					|  |  |  |             input = new InflaterInputStream(entity.getContent(), inflater); |  |  |  |             input = new InflaterInputStream(entity.getContent(), inflater); // 如果响应内容被 deflate 压缩了,则创建一个 InflaterInputStream 解压缩
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             InputStreamReader isr = new InputStreamReader(input); |  |  |  |             InputStreamReader isr = new InputStreamReader(input); // 创建一个 InputStreamReader 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             BufferedReader br = new BufferedReader(isr); |  |  |  |             BufferedReader br = new BufferedReader(isr); // 创建一个 BufferedReader 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             StringBuilder sb = new StringBuilder(); |  |  |  |             StringBuilder sb = new StringBuilder(); // 创建一个 StringBuilder 对象
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             while (true) { |  |  |  |             while (true) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 String buff = br.readLine(); |  |  |  |                 String buff = br.readLine(); // 逐行读取响应内容
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 if (buff == null) { |  |  |  |                 if (buff == null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                     return sb.toString(); |  |  |  |                     return sb.toString(); // 如果读到了末尾,则返回读取到的响应内容
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |                 sb = sb.append(buff); |  |  |  |                 sb = sb.append(buff); // 将读取到的响应内容追加到 StringBuilder 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } finally { |  |  |  |         } finally { | 
			
		
	
		
		
			
				
					
					|  |  |  |             input.close(); |  |  |  |             input.close(); // 关闭输入流
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*getResponseContent(HttpEntity entity)的作用是从HttpEntity对象中获取响应内容,并将其解压(如果响应内容被压缩了)。它返回解压后的响应内容。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     首先获取响应内容的编码方式,然后根据编码方式创建对应的输入流。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果响应内容被 gzip 压缩了,则创建一个 GZIPInputStream 对象解压缩;如果响应内容被 deflate 压缩了,则创建一个 InflaterInputStream 对象解压缩。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      接着使用 InputStreamReader 和 BufferedReader 逐行读取响应内容,并将其追加到 StringBuilder 对象中。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      最后返回读取到的响应内容,并关闭输入流。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private JSONObject postRequest(JSONObject js) throws NetworkFailureException { |  |  |  |     private JSONObject postRequest(JSONObject js) throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!mLoggedin) { |  |  |  |         if (!mLoggedin) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -329,17 +360,17 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("not logged in"); |  |  |  |             throw new ActionFailureException("not logged in"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         HttpPost httpPost = createHttpPost(); |  |  |  |         HttpPost httpPost = createHttpPost(); // 创建 HTTP POST 请求
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>(); |  |  |  |             LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             list.add(new BasicNameValuePair("r", js.toString())); |  |  |  |             list.add(new BasicNameValuePair("r", js.toString())); // 将传入的 JSONObject 对象转为字符串,并添加到请求参数中
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8"); |  |  |  |             UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8"); // 创建一个 UrlEncodedFormEntity 对象,用于封装请求参数
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             httpPost.setEntity(entity); |  |  |  |             httpPost.setEntity(entity); // 将 UrlEncodedFormEntity 对象设置为 HTTP POST 请求的实体
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // execute the post
 |  |  |  |             // execute the post
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             HttpResponse response = mHttpClient.execute(httpPost); |  |  |  |             HttpResponse response = mHttpClient.execute(httpPost); // 执行 HTTP POST 请求
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             String jsString = getResponseContent(response.getEntity()); |  |  |  |             String jsString = getResponseContent(response.getEntity()); // 获取响应内容,并将其解压(如果响应内容被压缩了),然后转为字符串
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             return new JSONObject(jsString); |  |  |  |             return new JSONObject(jsString); // 将响应内容转为 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (ClientProtocolException e) { |  |  |  |         } catch (ClientProtocolException e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
	
		
		
			
				
					|  |  | @ -359,25 +390,30 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("error occurs when posting request"); |  |  |  |             throw new ActionFailureException("error occurs when posting request"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     /*postRequest(JSONObject js)的作用是向服务器发送 HTTP POST 请求,并将响应内容转为JSONObject对象返回。 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     首先检查用户是否已经登录,如果没有登录则抛出异常。然后创建一个 HTTP POST 请求,并将传入的 JSONObject 对象转为字符串,并添加到请求参数中。接着,创建一个 UrlEncodedFormEntity 对象,用于封装请求参数,并将其设置为 HTTP POST 请求的实体。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     执行 HTTP POST 请求,并获取响应内容。将响应内容解压(如果响应内容被压缩了),然后将其转为字符串,并通过 JSONObject 构造方法将其转为 JSONObject 对象。如果转换失败,则抛出异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果在执行 HTTP POST 请求或转换响应内容为 JSONObject 对象时出现异常,则抛出相应的异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void createTask(Task task) throws NetworkFailureException { |  |  |  |     public void createTask(Task task) throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         commitUpdate(); |  |  |  |         commitUpdate(); // 提交所有未提交的更新操作
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsPost = new JSONObject(); |  |  |  |             JSONObject jsPost = new JSONObject(); // 创建一个新的 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             JSONArray actionList = new JSONArray(); |  |  |  |             JSONArray actionList = new JSONArray(); // 创建一个新的 JSONArray 对象,用于存储操作列表
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // action_list
 |  |  |  |             // action_list
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             actionList.put(task.getCreateAction(getActionId())); |  |  |  |             actionList.put(task.getCreateAction(getActionId())); // 将新增任务的操作添加到操作列表中
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // 将操作列表添加到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // client_version
 |  |  |  |             // client_version
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 添加客户端版本号到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // post
 |  |  |  |             // post
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsResponse = postRequest(jsPost); |  |  |  |             JSONObject jsResponse = postRequest(jsPost); // 向服务器发送 HTTP POST 请求,并获取响应内容
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( |  |  |  |             JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( | 
			
		
	
		
		
			
				
					
					|  |  |  |                     GTaskStringUtils.GTASK_JSON_RESULTS).get(0); |  |  |  |                     GTaskStringUtils.GTASK_JSON_RESULTS).get(0); // 从响应内容中获取结果列表,并获取第一个结果
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             task.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); |  |  |  |             task.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); // 获取新任务的 ID,并将其设置为 Task 对象的 gid 属性
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (JSONException e) { |  |  |  |         } catch (JSONException e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
	
		
		
			
				
					|  |  | @ -385,25 +421,30 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("create task: handing jsonobject failed"); |  |  |  |             throw new ActionFailureException("create task: handing jsonobject failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     /*createTask(Task task)的作用是创建新任务。首先调用commitUpdate()方法提交所有未提交的更新操作。 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     然后创建一个新的 JSONObject 对象,并创建一个新的 JSONArray 对象,用于存储操作列表。将新增任务的操作添加到操作列表中,并将操作列表添加到 JSONObject 对象中。将客户端版本号也添加到 JSONObject 对象中。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     向服务器发送 HTTP POST 请求,并获取响应内容。从响应内容中获取结果列表,并获取第一个结果。从结果中获取新任务的 ID,并将其设置为 Task 对象的 gid 属性。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果在处理 JSONObject 对象时出现异常,则抛出相应的异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void createTaskList(TaskList tasklist) throws NetworkFailureException { |  |  |  |     public void createTaskList(TaskList tasklist) throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         commitUpdate(); |  |  |  |         commitUpdate(); // 提交所有未提交的更新操作
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsPost = new JSONObject(); |  |  |  |             JSONObject jsPost = new JSONObject(); // 创建一个新的 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             JSONArray actionList = new JSONArray(); |  |  |  |             JSONArray actionList = new JSONArray(); // 创建一个新的 JSONArray 对象,用于存储操作列表
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // action_list
 |  |  |  |             // action_list
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             actionList.put(tasklist.getCreateAction(getActionId())); |  |  |  |             actionList.put(tasklist.getCreateAction(getActionId())); // 将新增任务列表的操作添加到操作列表中
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // 将操作列表添加到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // client version
 |  |  |  |             // client_version
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 添加客户端版本号到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // post
 |  |  |  |             // post
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsResponse = postRequest(jsPost); |  |  |  |             JSONObject jsResponse = postRequest(jsPost); // 向服务器发送 HTTP POST 请求,并获取响应内容
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( |  |  |  |             JSONObject jsResult = (JSONObject) jsResponse.getJSONArray( | 
			
		
	
		
		
			
				
					
					|  |  |  |                     GTaskStringUtils.GTASK_JSON_RESULTS).get(0); |  |  |  |                     GTaskStringUtils.GTASK_JSON_RESULTS).get(0); // 从响应内容中获取结果列表,并获取第一个结果
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); |  |  |  |             tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID)); // 获取新任务列表的 ID,并将其设置为 TaskList 对象的 gid 属性
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (JSONException e) { |  |  |  |         } catch (JSONException e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
	
		
		
			
				
					|  |  | @ -411,20 +452,25 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("create tasklist: handing jsonobject failed"); |  |  |  |             throw new ActionFailureException("create tasklist: handing jsonobject failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     /*createTaskList(TaskList tasklist)的作用是创建新任务列表。首先调用commitUpdate()方法提交所有未提交的更新操作。 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     然后创建一个新的 JSONObject 对象,并创建一个新的 JSONArray 对象,用于存储操作列表。将新增任务列表的操作添加到操作列表中,并将操作列表添加到 JSONObject 对象中。将客户端版本号也添加到 JSONObject 对象中。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     向服务器发送 HTTP POST 请求,并获取响应内容。从响应内容中获取结果列表,并获取第一个结果。从结果中获取新任务列表的 ID,并将其设置为 TaskList 对象的 gid 属性。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果在处理 JSONObject 对象时出现异常,则抛出相应的异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void commitUpdate() throws NetworkFailureException { |  |  |  |     public void commitUpdate() throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (mUpdateArray != null) { |  |  |  |         if (mUpdateArray != null) { // 判断更新操作列表是否为空
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             try { |  |  |  |             try { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 JSONObject jsPost = new JSONObject(); |  |  |  |                 JSONObject jsPost = new JSONObject(); // 创建一个新的 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // action_list
 |  |  |  |                 // action_list
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, mUpdateArray); |  |  |  |                 jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, mUpdateArray); // 将更新操作列表添加到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // client_version
 |  |  |  |                 // client_version
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); |  |  |  |                 jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 添加客户端版本号到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 postRequest(jsPost); // 向服务器发送 HTTP POST 请求,提交更新操作
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 mUpdateArray = null; // 更新操作提交成功后,清空更新操作列表
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 postRequest(jsPost); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mUpdateArray = null; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             } catch (JSONException e) { |  |  |  |             } catch (JSONException e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 Log.e(TAG, e.toString()); |  |  |  |                 Log.e(TAG, e.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |                 e.printStackTrace(); |  |  |  |                 e.printStackTrace(); | 
			
		
	
	
		
		
			
				
					|  |  | @ -432,52 +478,63 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     /*commitUpdate()的作用是提交所有未提交的更新操作。如果更新操作列表不为空,则创建一个新的 JSONObject 对象,将更新操作列表添加到 JSONObject 对象中,并将客户端版本号也添加到 JSONObject 对象中。 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     向服务器发送 HTTP POST 请求,提交更新操作。提交成功后,清空更新操作列表。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果在处理 JSONObject 对象时出现异常,则抛出相应的异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void addUpdateNode(Node node) throws NetworkFailureException { |  |  |  |     public void addUpdateNode(Node node) throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (node != null) { |  |  |  |         if (node != null) { // 判断 Node 对象是否为空
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             // too many update items may result in an error
 |  |  |  |             // too many update items may result in an error
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // set max to 10 items
 |  |  |  |             // set max to 10 items
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (mUpdateArray != null && mUpdateArray.length() > 10) { |  |  |  |             if (mUpdateArray != null && mUpdateArray.length() > 10) { // 判断更新操作列表是否已满
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |                 commitUpdate(); |  |  |  |                 commitUpdate(); // 如果已满,则提交所有未提交的更新操作
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (mUpdateArray == null) |  |  |  |             if (mUpdateArray == null) | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mUpdateArray = new JSONArray(); |  |  |  |                 mUpdateArray = new JSONArray(); // 如果更新操作列表还未创建,则创建一个新的 JSONArray 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             mUpdateArray.put(node.getUpdateAction(getActionId())); |  |  |  |             mUpdateArray.put(node.getUpdateAction(getActionId())); // 将 Node 对象的更新操作添加到更新操作列表中
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     /*addUpdateNode(Node node)的作用是向更新操作列表中添加一个新的更新操作。首先判断 Node 对象是否为空。 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果更新操作列表已满(长度大于 10),则调用commitUpdate()方法提交所有未提交的更新操作。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果更新操作列表还未创建,则创建一个新的 JSONArray 对象。将 节点 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果 Node 对象为空,则不执行任何操作。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void moveTask(Task task, TaskList preParent, TaskList curParent) |  |  |  |     public void moveTask(Task task, TaskList preParent, TaskList curParent) | 
			
		
	
		
		
			
				
					
					|  |  |  |             throws NetworkFailureException { |  |  |  |             throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         commitUpdate(); |  |  |  |         commitUpdate(); // 先提交所有未提交的更新操作
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsPost = new JSONObject(); |  |  |  |             JSONObject jsPost = new JSONObject(); // 创建一个新的 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             JSONArray actionList = new JSONArray(); |  |  |  |             JSONArray actionList = new JSONArray(); // 创建一个新的 JSONArray 对象,用于存储更新操作
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject action = new JSONObject(); |  |  |  |             JSONObject action = new JSONObject(); // 创建一个新的 JSONObject 对象,用于存储移动任务的操作
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // action_list
 |  |  |  |             // action_list
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, | 
			
		
	
		
		
			
				
					
					|  |  |  |                     GTaskStringUtils.GTASK_JSON_ACTION_TYPE_MOVE); |  |  |  |                     GTaskStringUtils.GTASK_JSON_ACTION_TYPE_MOVE); // 设置操作类型为移动任务
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); // 设置操作 ID
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid()); |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid()); // 设置任务的 GID
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (preParent == curParent && task.getPriorSibling() != null) { |  |  |  |             if (preParent == curParent && task.getPriorSibling() != null) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // put prioring_sibing_id only if moving within the tasklist and
 |  |  |  |                 // put prioring_sibing_id only if moving within the tasklist and
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // it is not the first one
 |  |  |  |                 // it is not the first one
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling()); |  |  |  |                 action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling()); // 如果是在同一任务列表中移动任务,则设置前一个任务的 GID
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid()); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid()); |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid()); // 设置任务的原始任务列表的 GID
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid()); // 设置任务的目标任务列表的 GID
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (preParent != curParent) { |  |  |  |             if (preParent != curParent) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 // put the dest_list only if moving between tasklists
 |  |  |  |                 // put the dest_list only if moving between tasklists
 | 
			
		
	
		
		
			
				
					
					|  |  |  |                 action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid()); |  |  |  |                 action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid()); // 如果是在不同的任务列表之间移动任务,则设置任务的目标任务列表的 GID
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             actionList.put(action); |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); |  |  |  |             actionList.put(action); // 将移动任务的操作添加到更新操作列表中
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // 将更新操作列表添加到 JSONObject 对象中
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // client_version
 |  |  |  |             // client_version
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 添加客户端版本号到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             postRequest(jsPost); |  |  |  |             postRequest(jsPost); // 向服务器发送 HTTP POST 请求,提交更新操作
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (JSONException e) { |  |  |  |         } catch (JSONException e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
	
		
		
			
				
					|  |  | @ -485,101 +542,127 @@ public class GTaskClient { | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("move task: handing jsonobject failed"); |  |  |  |             throw new ActionFailureException("move task: handing jsonobject failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |     /*moveTask(Task task, TaskList preParent, TaskList curParent)的作用是移动一个任务到另一个任务列表中。 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     首先调用commitUpdate()方法提交所有未提交的更新操作。然后,创建一个新的 JSONObject 对象,用于存储移动任务的操作。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     在移动任务的操作中,设置操作类型为移动任务。设置操作 ID 和任务的 GID。如果是在同一任务列表中移动任务,则设置前一个任务的 GID。设置任务的原始任务列表的 GID 和任务的目标任务列表的 GID。如果是在不同的任务列表之间移动任务,则设置任务的目标任务列表的 GID。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     将移动任务的操作添加到更新操作列表中,然后将更新操作列表添加到 JSONObject 对象中。最后,添加客户端版本号到 JSONObject 对象中,向服务器发送 HTTP POST 请求,提交更新操作。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果处理 JSONObject 对象时出现异常,则抛出 ActionFailureException 异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     */ | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void deleteNode(Node node) throws NetworkFailureException { |  |  |  |     public void deleteNode(Node node) throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         commitUpdate(); |  |  |  |         commitUpdate(); // 先提交所有未提交的更新操作
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsPost = new JSONObject(); |  |  |  |             JSONObject jsPost = new JSONObject(); // 创建一个新的 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             JSONArray actionList = new JSONArray(); |  |  |  |             JSONArray actionList = new JSONArray(); // 创建一个新的 JSONArray 对象,用于存储更新操作
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // action_list
 |  |  |  |             // action_list
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             node.setDeleted(true); |  |  |  |             node.setDeleted(true); // 将节点标记为已删除
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             actionList.put(node.getUpdateAction(getActionId())); |  |  |  |             actionList.put(node.getUpdateAction(getActionId())); // 将节点的更新操作添加到更新操作列表中
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // 将更新操作列表添加到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // client_version
 |  |  |  |             // client_version
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 添加客户端版本号到 JSONObject 对象中
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             postRequest(jsPost); // 向服务器发送 HTTP POST 请求,提交更新操作
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             mUpdateArray = null; // 将更新操作数组置为空
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             postRequest(jsPost); |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |             mUpdateArray = null; |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (JSONException e) { |  |  |  |         } catch (JSONException e) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             e.printStackTrace(); |  |  |  |             e.printStackTrace(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("delete node: handing jsonobject failed"); |  |  |  |             throw new ActionFailureException("delete node: handing jsonobject failed"); // 处理 JSONObject 对象时出现异常,则抛出 ActionFailureException 异常
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*此方法的主要目的是删除一个节点,并将删除操作提交到服务器。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     方法首先提交所有未提交的更新操作,然后创建一个新的 JSONObject 对象,将节点的删除操作添加到该对象中,同时添加客户端版本号。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     最后,方法通过向服务器发送 HTTP POST 请求来提交更新操作,如果在处理 JSONObject 对象时出现异常,则会抛出 ActionFailureException 异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public JSONArray getTaskLists() throws NetworkFailureException { |  |  |  |     public JSONArray getTaskLists() throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (!mLoggedin) { |  |  |  |         if (!mLoggedin) { // 如果用户没有登录,则抛出 ActionFailureException 异常
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, "please login first"); |  |  |  |             Log.e(TAG, "please login first"); | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("not logged in"); |  |  |  |             throw new ActionFailureException("not logged in"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             HttpGet httpGet = new HttpGet(mGetUrl); |  |  |  |             HttpGet httpGet = new HttpGet(mGetUrl); // 创建一个新的 HttpGet 请求对象
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             HttpResponse response = null; |  |  |  |             HttpResponse response = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |             response = mHttpClient.execute(httpGet); |  |  |  |             response = mHttpClient.execute(httpGet); // 执行 HttpGet 请求
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // get the task list
 |  |  |  |             // get the task list
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             String resString = getResponseContent(response.getEntity()); |  |  |  |             String resString = getResponseContent(response.getEntity()); // 获取响应内容
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             String jsBegin = "_setup("; |  |  |  |             String jsBegin = "_setup("; | 
			
		
	
		
		
			
				
					
					|  |  |  |             String jsEnd = ")}</script>"; |  |  |  |             String jsEnd = ")}</script>"; | 
			
		
	
		
		
			
				
					
					|  |  |  |             int begin = resString.indexOf(jsBegin); |  |  |  |             int begin = resString.indexOf(jsBegin); | 
			
		
	
		
		
			
				
					
					|  |  |  |             int end = resString.lastIndexOf(jsEnd); |  |  |  |             int end = resString.lastIndexOf(jsEnd); | 
			
		
	
		
		
			
				
					
					|  |  |  |             String jsString = null; |  |  |  |             String jsString = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (begin != -1 && end != -1 && begin < end) { |  |  |  |             if (begin != -1 && end != -1 && begin < end) { // 如果响应内容中包含任务列表,那么提取出来
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 jsString = resString.substring(begin + jsBegin.length(), end); |  |  |  |                 jsString = resString.substring(begin + jsBegin.length(), end); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject js = new JSONObject(jsString); |  |  |  |             JSONObject js = new JSONObject(jsString); // 将任务列表转换成 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             return js.getJSONObject("t").getJSONArray(GTaskStringUtils.GTASK_JSON_LISTS); |  |  |  |             return js.getJSONObject("t").getJSONArray(GTaskStringUtils.GTASK_JSON_LISTS); // 返回任务列表数组
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (ClientProtocolException e) { |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } catch (ClientProtocolException e) { // 如果发生协议错误,则抛出 NetworkFailureException 异常
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             e.printStackTrace(); |  |  |  |             e.printStackTrace(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new NetworkFailureException("gettasklists: httpget failed"); |  |  |  |             throw new NetworkFailureException("gettasklists: httpget failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (IOException e) { |  |  |  |         } catch (IOException e) { // 如果发生 I/O 错误,则抛出 NetworkFailureException 异常
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             e.printStackTrace(); |  |  |  |             e.printStackTrace(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new NetworkFailureException("gettasklists: httpget failed"); |  |  |  |             throw new NetworkFailureException("gettasklists: httpget failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (JSONException e) { |  |  |  |         } catch (JSONException e) { // 如果处理 JSONObject 对象时出现异常,则抛出 ActionFailureException 异常
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             e.printStackTrace(); |  |  |  |             e.printStackTrace(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("get task lists: handing jasonobject failed"); |  |  |  |             throw new ActionFailureException("get task lists: handing jasonobject failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*此方法的主要目的是从服务器获取用户的任务列表,并将其作为 JSONArray 对象返回。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     方法首先检查用户是否已登录,然后创建一个新的 HttpGet 请求对象,并通过执行该请求来获取响应内容。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     接下来,方法从响应内容中提取出任务列表,并将其转换为 JSONObject 对象,最后返回任务列表数组。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果在执行 HttpGet 请求或处理 JSONObject 对象时发生错误,则会抛出 NetworkFailureException 或 ActionFailureException 异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public JSONArray getTaskList(String listGid) throws NetworkFailureException { |  |  |  |     public JSONArray getTaskList(String listGid) throws NetworkFailureException { | 
			
		
	
		
		
			
				
					
					|  |  |  |         commitUpdate(); |  |  |  |         commitUpdate(); // 提交所有未提交的更改
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         try { |  |  |  |         try { | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsPost = new JSONObject(); |  |  |  |             JSONObject jsPost = new JSONObject(); // 创建一个新的 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             JSONArray actionList = new JSONArray(); |  |  |  |             JSONArray actionList = new JSONArray(); // 创建一个新的 JSONArray 对象
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject action = new JSONObject(); |  |  |  |             JSONObject action = new JSONObject(); // 创建一个新的 JSONObject 对象
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // action_list
 |  |  |  |             // action_list
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, | 
			
		
	
		
		
			
				
					
					|  |  |  |                     GTaskStringUtils.GTASK_JSON_ACTION_TYPE_GETALL); |  |  |  |                     GTaskStringUtils.GTASK_JSON_ACTION_TYPE_GETALL); // 设置 action 的类型为 "getall"
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId()); // 设置 action 的 ID
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_LIST_ID, listGid); |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_LIST_ID, listGid); // 设置 action 操作的任务列表 ID
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_GET_DELETED, false); |  |  |  |             action.put(GTaskStringUtils.GTASK_JSON_GET_DELETED, false); // 设置是否获取已删除的任务
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             actionList.put(action); |  |  |  |             actionList.put(action); // 将 action 添加到 action_list 中
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList); // 将 action_list 添加到 jsPost 中
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             // client_version
 |  |  |  |             // client_version
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); |  |  |  |             jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion); // 设置客户端版本号
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             JSONObject jsResponse = postRequest(jsPost); |  |  |  |             JSONObject jsResponse = postRequest(jsPost); // 发送请求并获取响应
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             return jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_TASKS); |  |  |  |             return jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_TASKS); // 从响应中获取任务列表并返回
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         } catch (JSONException e) { |  |  |  | 
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } catch (JSONException e) { // 如果处理 JSONObject 对象时出现异常,则抛出 ActionFailureException 异常
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             Log.e(TAG, e.toString()); |  |  |  |             Log.e(TAG, e.toString()); | 
			
		
	
		
		
			
				
					
					|  |  |  |             e.printStackTrace(); |  |  |  |             e.printStackTrace(); | 
			
		
	
		
		
			
				
					
					|  |  |  |             throw new ActionFailureException("get task list: handing jsonobject failed"); |  |  |  |             throw new ActionFailureException("get task list: handing jsonobject failed"); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*此方法的主要目的是从服务器获取特定任务列表的任务,并将其作为 JSONArray 对象返回。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     方法首先提交所有未提交的更改,然后构造一个包含获取任务列表的请求并发送它。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     接下来,方法从响应中提取出任务列表,并将其作为 JSONArray 对象返回。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     如果在处理 JSONObject 对象时发生错误,则会抛出 ActionFailureException 异常。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public Account getSyncAccount() { |  |  |  |     public Account getSyncAccount() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         return mAccount; |  |  |  |         return mAccount; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //这个方法返回GTaskClient的同步账户(即当前使用的 Google 帐户)。
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void resetUpdateArray() { |  |  |  |     public void resetUpdateArray() { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mUpdateArray = null; |  |  |  |         mUpdateArray = null; | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     /*这个方法将GTaskClient的更新数组mUpdateArray设置为null,以清除未提交的更改。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     在更新任务列表之前,需要调用commitUpdate()方法提交所有未提交的更改,如果您想丢弃这些更改,可以调用resetUpdateArray()方法以清除它们。 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |      */ |