diff --git a/java/net/micode/notes/gtask/remote/GTaskASyncTask.java b/java/net/micode/notes/gtask/remote/GTaskASyncTask.java index 52c898a..1d91b1f 100644 --- a/java/net/micode/notes/gtask/remote/GTaskASyncTask.java +++ b/java/net/micode/notes/gtask/remote/GTaskASyncTask.java @@ -31,20 +31,20 @@ import net.micode.notes.ui.NotesPreferenceActivity; public class GTaskASyncTask extends AsyncTask { - private static int GTASK_SYNC_NOTIFICATION_ID = 5234235; + private static final int GTASK_SYNC_NOTIFICATION_ID = 5234235; + // 同步完成监听器接口 public interface OnCompleteListener { void onComplete(); } + // 相关上下文和管理器 private Context mContext; - private NotificationManager mNotifiManager; - private GTaskManager mTaskManager; - private OnCompleteListener mOnCompleteListener; + // 构造函数 public GTaskASyncTask(Context context, OnCompleteListener listener) { mContext = context; mOnCompleteListener = listener; @@ -53,10 +53,12 @@ public class GTaskASyncTask extends AsyncTask { mTaskManager = GTaskManager.getInstance(); } + // 取消同步 public void cancelSync() { mTaskManager.cancelSync(); } + // 发布进度信息 public void publishProgess(String message) { publishProgress(new String[] { message @@ -79,8 +81,11 @@ public class GTaskASyncTask extends AsyncTask { // } // notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, // pendingIntent); +// int GTASK_SYNC_NOTIFICATION_ID = 5234235; // mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); // } + +// 显示通知 private void showNotification(int tickerId, String content) { PendingIntent pendingIntent; if (tickerId != R.string.ticker_success) { @@ -101,6 +106,7 @@ private void showNotification(int tickerId, String content) { mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); } + // 后台执行同步任务 @Override protected Integer doInBackground(Void... unused) { publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity @@ -108,6 +114,7 @@ private void showNotification(int tickerId, String content) { return mTaskManager.sync(mContext, this); } + // 更新进度 @Override protected void onProgressUpdate(String... progress) { showNotification(R.string.ticker_syncing, progress[0]); @@ -116,6 +123,7 @@ private void showNotification(int tickerId, String content) { } } + // 同步完成后的处理 @Override protected void onPostExecute(Integer result) { if (result == GTaskManager.STATE_SUCCESS) { @@ -140,3 +148,5 @@ private void showNotification(int tickerId, String content) { } } } + +