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