main
liuyuxia 7 months ago
parent 6f3dea8052
commit f3aa50205a

@ -16,18 +16,45 @@
package net.micode.notes.gtask.exception; package net.micode.notes.gtask.exception;
/**
* ActionFailureException Google
* RuntimeException
*/
public class ActionFailureException extends RuntimeException { public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L; private static final long serialVersionUID = 4425249765923293627L;
/**
* ActionFailureException
*/
public ActionFailureException() { public ActionFailureException() {
super(); super();
} }
/**
* ActionFailureException
* @param paramString
*/
public ActionFailureException(String paramString) { public ActionFailureException(String paramString) {
super(paramString); super(paramString);
} }
/**
* ActionFailureException
* @param paramString
* @param paramThrowable
*/
public ActionFailureException(String paramString, Throwable paramThrowable) { public ActionFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable); super(paramString, paramThrowable);
} }
} }
/**
*
ActionFailureException Google RuntimeException
serialVersionUID
ActionFailureException() ActionFailureException
ActionFailureException(String paramString) ActionFailureException
ActionFailureException(String paramString, Throwable paramThrowable) ActionFailureException
*/

@ -15,17 +15,46 @@
*/ */
package net.micode.notes.gtask.exception; package net.micode.notes.gtask.exception;
/**
* NetworkFailureException
* Exception
*/
public class NetworkFailureException extends Exception { public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L; private static final long serialVersionUID = 2107610287180234136L;
/**
* NetworkFailureException
*/
public NetworkFailureException() { public NetworkFailureException() {
super(); super();
} }
/**
* NetworkFailureException
* @param paramString
*/
public NetworkFailureException(String paramString) { public NetworkFailureException(String paramString) {
super(paramString); super(paramString);
} }
/**
* NetworkFailureException
* @param paramString
* @param paramThrowable
*/
public NetworkFailureException(String paramString, Throwable paramThrowable) { public NetworkFailureException(String paramString, Throwable paramThrowable) {
super(paramString, paramThrowable); super(paramString, paramThrowable);
} }
} }
/**
*
NetworkFailureException Exception
serialVersionUID
NetworkFailureException() NetworkFailureException
NetworkFailureException(String paramString) NetworkFailureExceptionparamString
NetworkFailureException(String paramString, Throwable paramThrowable) NetworkFailureExceptionparamString paramThrowable
*/

@ -1,145 +1,155 @@
/* package net.micode.notes.gtask.remote;
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.gtask.remote; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.app.Notification; import net.micode.notes.R;
import android.app.NotificationManager; import net.micode.notes.ui.NotesListActivity;
import android.app.PendingIntent; import net.micode.notes.ui.NotesPreferenceActivity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import net.micode.notes.R; /**
import net.micode.notes.ui.NotesListActivity; * Google
import net.micode.notes.ui.NotesPreferenceActivity; * AsyncTask Google
*/
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
/** private static int GTASK_SYNC_NOTIFICATION_ID = 5234235; // 同步通知的ID
* Google
*/
public class GTaskASyncTask extends AsyncTask<Void, String, Integer> {
private static int GTASK_SYNC_NOTIFICATION_ID = 5234235; // 同步通知的ID /**
*
*
*/
public interface OnCompleteListener {
void onComplete(); // 当同步完成时调用
}
/** private Context mContext; // 应用程序上下文
* private NotificationManager mNotifiManager; // 通知管理器
*/ private GTaskManager mTaskManager; // Google 任务管理器
public interface OnCompleteListener { private OnCompleteListener mOnCompleteListener; // 完成监听器
void onComplete(); // 当同步完成时调用
}
private Context mContext; // 应用程序上下文 /**
private NotificationManager mNotifiManager; // 通知管理器 *
private GTaskManager mTaskManager; // Google任务管理器 * @param context
private OnCompleteListener mOnCompleteListener; // 完成监听器 * @param listener
*/
public GTaskASyncTask(Context context, OnCompleteListener listener) {
mContext = context;
mOnCompleteListener = listener;
mNotifiManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mTaskManager = GTaskManager.getInstance();
}
/** /**
* *
* @param context * Google cancelSync
* @param listener */
*/ public void cancelSync() {
public GTaskASyncTask(Context context, OnCompleteListener listener) { mTaskManager.cancelSync();
mContext = context; }
mOnCompleteListener = listener;
mNotifiManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
mTaskManager = GTaskManager.getInstance();
}
/** /**
* *
*/ * @param message
public void cancelSync() { */
mTaskManager.cancelSync(); public void publishProgess(String message) {
} publishProgress(new String[] { message });
}
/** /**
* *
* @param message * @param tickerId ID
*/ * @param content
public void publishProgess(String message) { */
publishProgress(new String[] { message }); private void showNotification(int tickerId, String content) {
} Notification notification = new Notification(R.drawable.notification, mContext.getString(tickerId), System.currentTimeMillis());
notification.defaults = Notification.DEFAULT_LIGHTS; // 设置默认灯光
notification.flags = Notification.FLAG_AUTO_CANCEL; // 设置通知自动取消
PendingIntent pendingIntent; // 待决意图
/** // 根据 tickerId 设置不同的待决意图
* if (tickerId != R.string.ticker_success) {
* @param tickerId ID pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, NotesPreferenceActivity.class), 0);
* @param content } else {
*/ pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, NotesListActivity.class), 0);
private void showNotification(int tickerId, String content) { }
Notification notification = new Notification(R.drawable.notification, mContext.getString(tickerId), System.currentTimeMillis()); notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, pendingIntent); // 设置通知信息
notification.defaults = Notification.DEFAULT_LIGHTS; // 设置默认灯光 mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); // 显示通知
notification.flags = Notification.FLAG_AUTO_CANCEL; // 设置通知自动取消 }
PendingIntent pendingIntent; // 待决意图
// 根据tickerId设置不同的待决意图 /**
if (tickerId != R.string.ticker_success) { *
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, NotesPreferenceActivity.class), 0); * @return
} else { */
pendingIntent = PendingIntent.getActivity(mContext, 0, new Intent(mContext, NotesListActivity.class), 0); @Override
} protected Integer doInBackground(Void... unused) {
notification.setLatestEventInfo(mContext, mContext.getString(R.string.app_name), content, pendingIntent); // 设置通知信息 publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity.getSyncAccountName(mContext)));
mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); // 显示通知 return mTaskManager.sync(mContext, this); // 同步任务
} }
/** /**
* *
* @return * @param progress
*/ */
@Override @Override
protected Integer doInBackground(Void... unused) { protected void onProgressUpdate(String... progress) {
publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity.getSyncAccountName(mContext))); showNotification(R.string.ticker_syncing, progress[0]); // 显示同步中的通知
return mTaskManager.sync(mContext, this); // 同步任务 if (mContext instanceof GTaskSyncService) {
} ((GTaskSyncService) mContext).sendBroadcast(progress[0]); // 如果上下文是 GTaskSyncService发送广播
}
}
/** /**
* *
* @param progress * @param result
*/ */
@Override @Override
protected void onProgressUpdate(String... progress) { protected void onPostExecute(Integer result) {
showNotification(R.string.ticker_syncing, progress[0]); // 显示同步中的通知 // 根据结果状态显示不同的通知
if (mContext instanceof GTaskSyncService) { if (result == GTaskManager.STATE_SUCCESS) {
((GTaskSyncService) mContext).sendBroadcast(progress[0]); // 如果上下文是GTaskSyncService发送广播 showNotification(R.string.ticker_success, mContext.getString(R.string.success_sync_account, mTaskManager.getSyncAccount()));
} NotesPreferenceActivity.setLastSyncTime(mContext, System.currentTimeMillis()); // 设置最后同步时间
} } else if (result == GTaskManager.STATE_NETWORK_ERROR) {
showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_network));
} else if (result == GTaskManager.STATE_INTERNAL_ERROR) {
showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_internal));
} else if (result == GTaskManager.STATE_SYNC_CANCELLED) {
showNotification(R.string.ticker_cancel, mContext.getString(R.string.error_sync_cancelled));
}
// 如果设置了完成监听器,则在新线程中调用 onComplete 方法
if (mOnCompleteListener != null) {
new Thread(new Runnable() {
public void run() {
mOnCompleteListener.onComplete();
}
}).start();
}
}
}
/** /**
* *
* @param result GTaskASyncTask Google AsyncTask Google
*/
@Override GTASK_SYNC_NOTIFICATION_ID ID
protected void onPostExecute(Integer result) {
// 根据结果状态显示不同的通知 OnCompleteListener
if (result == GTaskManager.STATE_SUCCESS) {
showNotification(R.string.ticker_success, mContext.getString(R.string.success_sync_account, mTaskManager.getSyncAccount())); mContext
NotesPreferenceActivity.setLastSyncTime(mContext, System.currentTimeMillis()); // 设置最后同步时间 mNotifiManager
} else if (result == GTaskManager.STATE_NETWORK_ERROR) { mTaskManagerGoogle
showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_network)); mOnCompleteListener
} else if (result == GTaskManager.STATE_INTERNAL_ERROR) {
showNotification(R.string.ticker_fail, mContext.getString(R.string.error_sync_internal)); GTaskASyncTask(Context context, OnCompleteListener listener) Google
} else if (result == GTaskManager.STATE_SYNC_CANCELLED) {
showNotification(R.string.ticker_cancel, mContext.getString(R.string.error_sync_cancelled)); cancelSync() Google cancelSync
} publishProgess(String message) publishProgress
// 如果设置了完成监听器则在新线程中调用onComplete方法 showNotification(int tickerId, String content) tickerId
if (mOnCompleteListener != null) { doInBackground(Void... unused) Google sync
new Thread(new Runnable() { onProgressUpdate(String... progress) GTaskSyncService广
public void run() { onPostExecute(Integer result)线 onComplete
mOnCompleteListener.onComplete(); */
}
}).start();
}
}
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save