|
|
/*
|
|
|
* 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.
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
* 文件: GTaskSyncService.java
|
|
|
* 描述: Google Tasks同步服务,负责处理便签与Google Tasks的同步操作
|
|
|
* 作用: 提供便签与Google Tasks的同步功能,包括开始同步、取消同步等操作
|
|
|
* 注意: 当前版本中,同步功能已临时禁用
|
|
|
*/
|
|
|
package net.micode.notes.gtask.remote;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
import android.app.Service;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.IBinder;
|
|
|
|
|
|
/**
|
|
|
* Google Tasks同步服务类
|
|
|
*
|
|
|
* 该服务负责处理便签与Google Tasks的同步操作
|
|
|
* 提供开始同步、取消同步等功能,并通过广播通知同步状态
|
|
|
* 注意:当前版本中,同步功能已临时禁用
|
|
|
*/
|
|
|
public class GTaskSyncService extends Service {
|
|
|
/** Intent参数:同步动作类型 */
|
|
|
public final static String ACTION_STRING_NAME = "sync_action_type";
|
|
|
|
|
|
/** 同步动作:开始同步 */
|
|
|
public final static int ACTION_START_SYNC = 0;
|
|
|
|
|
|
/** 同步动作:取消同步 */
|
|
|
public final static int ACTION_CANCEL_SYNC = 1;
|
|
|
|
|
|
/** 同步动作:无效动作 */
|
|
|
public final static int ACTION_INVALID = 2;
|
|
|
|
|
|
/** 广播Action名称,用于通知同步状态 */
|
|
|
public final static String GTASK_SERVICE_BROADCAST_NAME = "net.micode.notes.gtask.remote.gtask_sync_service";
|
|
|
|
|
|
/** 广播参数:是否正在同步 */
|
|
|
public final static String GTASK_SERVICE_BROADCAST_IS_SYNCING = "isSyncing";
|
|
|
|
|
|
/** 广播参数:同步进度消息 */
|
|
|
public final static String GTASK_SERVICE_BROADCAST_PROGRESS_MSG = "progressMsg";
|
|
|
|
|
|
// /** 同步任务对象 */
|
|
|
// private static GTaskASyncTask mSyncTask = null;
|
|
|
|
|
|
/** 同步进度消息 */
|
|
|
private static String mSyncProgress = "";
|
|
|
|
|
|
/**
|
|
|
* 开始同步操作
|
|
|
*
|
|
|
* 注意:当前版本中,此功能已临时禁用
|
|
|
*/
|
|
|
private void startSync() {
|
|
|
// Temporarily disabled sync functionality
|
|
|
sendBroadcast("Sync functionality temporarily disabled");
|
|
|
stopSelf();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 取消同步操作
|
|
|
*
|
|
|
* 注意:当前版本中,此功能已临时禁用
|
|
|
*/
|
|
|
private void cancelSync() {
|
|
|
// Temporarily disabled sync functionality
|
|
|
sendBroadcast("Sync cancelled");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 服务创建时的回调方法
|
|
|
*
|
|
|
* 注意:当前版本中,同步功能已临时禁用,此方法为空实现
|
|
|
*/
|
|
|
@Override
|
|
|
public void onCreate() {
|
|
|
// Temporarily disabled sync functionality
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 服务启动时的回调方法
|
|
|
*
|
|
|
* 根据Intent中的参数执行相应的同步操作
|
|
|
*
|
|
|
* @param intent 启动服务的Intent
|
|
|
* @param flags 服务启动标志
|
|
|
* @param startId 服务启动ID
|
|
|
* @return 服务启动模式
|
|
|
*/
|
|
|
@Override
|
|
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
|
// 从Intent中获取同步动作类型
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
if (bundle != null && bundle.containsKey(ACTION_STRING_NAME)) {
|
|
|
switch (bundle.getInt(ACTION_STRING_NAME, ACTION_INVALID)) {
|
|
|
case ACTION_START_SYNC:
|
|
|
startSync();
|
|
|
break;
|
|
|
case ACTION_CANCEL_SYNC:
|
|
|
cancelSync();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
return START_STICKY;
|
|
|
}
|
|
|
return super.onStartCommand(intent, flags, startId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 内存不足时的回调方法
|
|
|
*
|
|
|
* 注意:当前版本中,同步功能已临时禁用,此方法为空实现
|
|
|
*/
|
|
|
@Override
|
|
|
public void onLowMemory() {
|
|
|
// Temporarily disabled sync functionality
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 绑定服务时的回调方法
|
|
|
*
|
|
|
* @param intent 绑定服务的Intent
|
|
|
* @return 返回null,不支持绑定
|
|
|
*/
|
|
|
public IBinder onBind(Intent intent) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 发送同步状态广播
|
|
|
*
|
|
|
* @param msg 同步进度消息
|
|
|
*/
|
|
|
public void sendBroadcast(String msg) {
|
|
|
// 保存同步进度消息
|
|
|
mSyncProgress = msg;
|
|
|
// 创建广播Intent
|
|
|
Intent intent = new Intent(GTASK_SERVICE_BROADCAST_NAME);
|
|
|
// 设置同步状态参数
|
|
|
intent.putExtra(GTASK_SERVICE_BROADCAST_IS_SYNCING, false);
|
|
|
intent.putExtra(GTASK_SERVICE_BROADCAST_PROGRESS_MSG, msg);
|
|
|
// 发送广播
|
|
|
sendBroadcast(intent);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 静态方法:启动同步服务
|
|
|
*
|
|
|
* @param activity 活动上下文
|
|
|
*/
|
|
|
public static void startSync(Activity activity) {
|
|
|
// Temporarily disabled sync functionality
|
|
|
Intent intent = new Intent(activity, GTaskSyncService.class);
|
|
|
intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_START_SYNC);
|
|
|
activity.startService(intent);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 静态方法:取消同步操作
|
|
|
*
|
|
|
* @param context 上下文环境
|
|
|
*/
|
|
|
public static void cancelSync(Context context) {
|
|
|
Intent intent = new Intent(context, GTaskSyncService.class);
|
|
|
intent.putExtra(GTaskSyncService.ACTION_STRING_NAME, GTaskSyncService.ACTION_CANCEL_SYNC);
|
|
|
context.startService(intent);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 静态方法:检查是否正在同步
|
|
|
*
|
|
|
* @return 当前版本始终返回false,因为同步功能已临时禁用
|
|
|
*/
|
|
|
public static boolean isSyncing() {
|
|
|
return false; // Temporarily disabled sync functionality
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 静态方法:获取同步进度消息
|
|
|
*
|
|
|
* @return 同步进度消息
|
|
|
*/
|
|
|
public static String getProgressString() {
|
|
|
return mSyncProgress;
|
|
|
}
|
|
|
}
|