|
|
|
@ -31,20 +31,22 @@ import net.micode.notes.ui.NotesPreferenceActivity;
|
|
|
|
|
|
|
|
|
|
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
|
|
|
|
|
|
|
|
|
|
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;
|
|
|
|
|
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235;// 同步通知的唯一ID
|
|
|
|
|
|
|
|
|
|
// 完成监听器接口
|
|
|
|
|
public interface OnCompleteListener {
|
|
|
|
|
void onComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Context mContext;
|
|
|
|
|
private Context mContext; // 应用上下文
|
|
|
|
|
|
|
|
|
|
private NotificationManager mNotifiManager;
|
|
|
|
|
private NotificationManager mNotifiManager; // 通知管理器
|
|
|
|
|
|
|
|
|
|
private GTaskManager mTaskManager;
|
|
|
|
|
private GTaskManager mTaskManager; // Google Tasks管理器
|
|
|
|
|
|
|
|
|
|
private OnCompleteListener mOnCompleteListener;
|
|
|
|
|
private OnCompleteListener mOnCompleteListener; // 完成监听器
|
|
|
|
|
|
|
|
|
|
// 构造函数
|
|
|
|
|
public GTaskASyncTask(Context context, OnCompleteListener listener) {
|
|
|
|
|
mContext = context;
|
|
|
|
|
mOnCompleteListener = listener;
|
|
|
|
@ -53,10 +55,11 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
|
|
|
|
|
mTaskManager = GTaskManager.getInstance();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 取消同步操作
|
|
|
|
|
public void cancelSync() {
|
|
|
|
|
mTaskManager.cancelSync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 发布进度信息
|
|
|
|
|
public void publishProgess(String message) {
|
|
|
|
|
publishProgress(new String[] {
|
|
|
|
|
message
|
|
|
|
@ -81,6 +84,8 @@ public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
|
|
|
|
|
// pendingIntent);
|
|
|
|
|
//mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification);
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// 显示通知
|
|
|
|
|
private void showNotification(int tickerId, String content) {
|
|
|
|
|
PendingIntent pendingIntent;
|
|
|
|
|
if (tickerId != R.string.ticker_success) {
|
|
|
|
@ -100,7 +105,8 @@ private void showNotification(int tickerId, String content) {
|
|
|
|
|
Notification notification=builder.getNotification();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 更新UI线程中的进度
|
|
|
|
|
@Override
|
|
|
|
|
protected void onProgressUpdate(String... progress) {
|
|
|
|
|
showNotification(R.string.ticker_syncing, progress[0]);
|
|
|
|
@ -115,7 +122,8 @@ private void showNotification(int tickerId, String content) {
|
|
|
|
|
((GTaskSyncService) mContext).sendBroadcast(progress[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 同步完成后在UI线程执行
|
|
|
|
|
@Override
|
|
|
|
|
protected void onPostExecute(Integer result) {
|
|
|
|
|
if (result == GTaskManager.STATE_SUCCESS) {
|
|
|
|
@ -130,6 +138,7 @@ private void showNotification(int tickerId, String content) {
|
|
|
|
|
showNotification(R.string.ticker_cancel, mContext
|
|
|
|
|
.getString(R.string.error_sync_cancelled));
|
|
|
|
|
}
|
|
|
|
|
// 调用完成监听器
|
|
|
|
|
if (mOnCompleteListener != null) {
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
|
|
|
|
|