|
|
|
@ -49,7 +49,6 @@ import net.micode.notes.gtask.remote.GTaskSyncService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
//定义常量键,用于引用特定的偏好设置
|
|
|
|
|
public static final String PREFERENCE_NAME = "notes_preferences";
|
|
|
|
|
|
|
|
|
|
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
|
|
|
|
@ -62,33 +61,29 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
|
|
|
|
|
private static final String AUTHORITIES_FILTER_KEY = "authorities";
|
|
|
|
|
|
|
|
|
|
//成员变量,用于管理偏好设置项
|
|
|
|
|
private PreferenceCategory mAccountCategory;
|
|
|
|
|
//广播接收器,用于接收相关相同操作广播通知
|
|
|
|
|
|
|
|
|
|
private GTaskReceiver mReceiver;
|
|
|
|
|
//存储原始的Google账号数组,用于比较之后是否有变化
|
|
|
|
|
|
|
|
|
|
private Account[] mOriAccounts;
|
|
|
|
|
//标志变量,记录是否添加了新账户
|
|
|
|
|
|
|
|
|
|
private boolean mHasAddedAccount;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
|
super.onCreate(icicle);
|
|
|
|
|
|
|
|
|
|
//启用向上导航使用应用程序图标
|
|
|
|
|
/* using the app icon for navigation */
|
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
//从Preferences.xml资源文件添加偏好设置项到这个活动
|
|
|
|
|
|
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
|
|
|
//通过键找到偏好设置分类,准备后续添加账户选项
|
|
|
|
|
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
|
|
|
|
|
//实例化广播接收器并注册,以便再同步服务发送广播时接收
|
|
|
|
|
mReceiver = new GTaskReceiver();
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
|
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
|
|
|
|
|
registerReceiver(mReceiver, filter);
|
|
|
|
|
//初始化账户数组为null
|
|
|
|
|
|
|
|
|
|
mOriAccounts = null;
|
|
|
|
|
//为设置列表添加表头View
|
|
|
|
|
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
|
|
|
|
|
getListView().addHeaderView(header, null, true);
|
|
|
|
|
}
|
|
|
|
@ -97,8 +92,8 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
|
|
//用户添加了新账户,自动设置同步账户
|
|
|
|
|
//通过比较原始账号和当前账户,确定新账户,并设置同步
|
|
|
|
|
// need to set sync account automatically if user has added a new
|
|
|
|
|
// account
|
|
|
|
|
if (mHasAddedAccount) {
|
|
|
|
|
Account[] accounts = getGoogleAccounts();
|
|
|
|
|
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
|
|
|
|
@ -117,13 +112,12 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//刷新UI界面,可能涉及到帐号显示的更新
|
|
|
|
|
|
|
|
|
|
refreshUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
//注销广播接收器
|
|
|
|
|
if (mReceiver != null) {
|
|
|
|
|
unregisterReceiver(mReceiver);
|
|
|
|
|
}
|
|
|
|
@ -131,10 +125,8 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadAccountPreference() {
|
|
|
|
|
//清空账户分类列表,然后重新添加账户偏好设置项
|
|
|
|
|
mAccountCategory.removeAll();
|
|
|
|
|
//创建一个账户偏好项,配置标题、概要、并设置点击监听
|
|
|
|
|
//如果正在同步过程中则无法更改账户
|
|
|
|
|
|
|
|
|
|
Preference accountPref = new Preference(this);
|
|
|
|
|
final String defaultAccount = getSyncAccountName(this);
|
|
|
|
|
accountPref.setTitle(getString(R.string.preferences_account_title));
|
|
|
|
@ -162,150 +154,117 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
mAccountCategory.addPreference(accountPref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//用于初始化并设置同步按钮的状态和功能的私有方法
|
|
|
|
|
private void loadSyncButton() {
|
|
|
|
|
// 通过 ID 查找同步按钮,它是一个 Button 对象
|
|
|
|
|
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
|
|
|
|
|
// 通过 ID 查找表示上次同步时间的 TextView 对象
|
|
|
|
|
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
|
|
|
|
|
|
|
|
|
//检查是否当前正在同步中,根据同步状态来设置按钮的文本和点击事件
|
|
|
|
|
// set button state
|
|
|
|
|
if (GTaskSyncService.isSyncing()) {
|
|
|
|
|
// 如果正在同步,设置按钮文本为“取消同步”并添加取消同步的点击事件
|
|
|
|
|
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
|
|
|
|
|
syncButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
// 当按钮被点击时,取消同步
|
|
|
|
|
GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// 如果不在同步,设置按钮文本为“立即同步”并添加启动同步的点击事件
|
|
|
|
|
syncButton.setText(getString(R.string.preferences_button_sync_immediately));
|
|
|
|
|
syncButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
//当按钮被点击时,启动同步
|
|
|
|
|
GTaskSyncService.startSync(NotesPreferenceActivity.this);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// 设置按钮的可用性,如果没有设置同步账户名称则按钮不可用
|
|
|
|
|
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
|
|
|
|
|
|
|
|
|
|
// 根据同步情况设置同步状态文本和其可见性
|
|
|
|
|
// set last sync time
|
|
|
|
|
if (GTaskSyncService.isSyncing()) {
|
|
|
|
|
//如果正在同步,展示当前同步进度
|
|
|
|
|
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
|
|
|
|
|
lastSyncTimeView.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
//// 如果不在同步,获取并展示上次同步的时间
|
|
|
|
|
long lastSyncTime = getLastSyncTime(this);
|
|
|
|
|
if (lastSyncTime != 0) {
|
|
|
|
|
//如果有上次同步时间,格式化并展示这个时间
|
|
|
|
|
lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
|
|
|
|
|
DateFormat.format(getString(R.string.preferences_last_sync_time_format),
|
|
|
|
|
lastSyncTime)));
|
|
|
|
|
lastSyncTimeView.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果没有上次同步时间,则隐藏这个视图
|
|
|
|
|
lastSyncTimeView.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 用来刷新界面的私有方法,可能是在操作后调用以更新用户界面状态
|
|
|
|
|
private void refreshUI() {
|
|
|
|
|
// 加载账户相关设置
|
|
|
|
|
loadAccountPreference();
|
|
|
|
|
// 重新加载并设置同步按钮的状态和功能
|
|
|
|
|
loadSyncButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示选择账户的对话框的私有方法
|
|
|
|
|
private void showSelectAccountAlertDialog() {
|
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
// 加载并设置对话框标题的布局
|
|
|
|
|
|
|
|
|
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
|
|
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
|
|
|
// 设置标题文本
|
|
|
|
|
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
|
|
|
|
|
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
|
|
|
|
|
// 设置子标题文本
|
|
|
|
|
subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));
|
|
|
|
|
// 对话框设置自定义标题布局
|
|
|
|
|
|
|
|
|
|
dialogBuilder.setCustomTitle(titleView);
|
|
|
|
|
// 设置了确定按钮,但没有事件,这可能意味着默认行为就是关闭对话框
|
|
|
|
|
dialogBuilder.setPositiveButton(null, null);
|
|
|
|
|
//获取当前设备上的 Google 账户列表
|
|
|
|
|
|
|
|
|
|
Account[] accounts = getGoogleAccounts();
|
|
|
|
|
// 获取当前已经设置的同步账户名称
|
|
|
|
|
String defAccount = getSyncAccountName(this);
|
|
|
|
|
// 存储初始账户的列表,这在此段代码中未使用,可能是类成员变量用于其他地方
|
|
|
|
|
|
|
|
|
|
mOriAccounts = accounts;
|
|
|
|
|
// 设置一个标记,表示是否添加了新账户,同样这是类成员变量
|
|
|
|
|
mHasAddedAccount = false;
|
|
|
|
|
// 如果存在账户,设置账户列表和单选按钮以供选择
|
|
|
|
|
|
|
|
|
|
if (accounts.length > 0) {
|
|
|
|
|
CharSequence[] items = new CharSequence[accounts.length];
|
|
|
|
|
final CharSequence[] itemMapping = items;
|
|
|
|
|
int checkedItem = -1;
|
|
|
|
|
int index = 0;
|
|
|
|
|
for (Account account : accounts) {
|
|
|
|
|
// 如果账户是默认账户,记录当前选中位置
|
|
|
|
|
if (TextUtils.equals(account.name, defAccount)) {
|
|
|
|
|
checkedItem = index;
|
|
|
|
|
}
|
|
|
|
|
// 填充账户名到列表中
|
|
|
|
|
items[index++] = account.name;
|
|
|
|
|
}
|
|
|
|
|
// 创建一个单选列表对话框
|
|
|
|
|
dialogBuilder.setSingleChoiceItems(items, checkedItem,
|
|
|
|
|
new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
// 当用户选择一个账户时,设置该账户为同步账户,并刷新UI
|
|
|
|
|
setSyncAccount(itemMapping[which].toString());
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
refreshUI();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// 加载并设置“添加账户”的视图
|
|
|
|
|
|
|
|
|
|
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
|
|
|
|
|
dialogBuilder.setView(addAccountView);
|
|
|
|
|
// 显示对话框
|
|
|
|
|
|
|
|
|
|
final AlertDialog dialog = dialogBuilder.show();
|
|
|
|
|
// 给“添加账户”视图添加点击事件,用来打开系统的添加账户页面
|
|
|
|
|
addAccountView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
// 设置标记表示已添加账户,并且开始添加账户的活动
|
|
|
|
|
mHasAddedAccount = true;
|
|
|
|
|
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
|
|
|
|
|
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
|
|
|
|
|
"gmail-ls"
|
|
|
|
|
});
|
|
|
|
|
// 启动活动,请求码设置为-1,可能表示这个启动是特殊的或者不需要处理返回结果
|
|
|
|
|
startActivityForResult(intent, -1);
|
|
|
|
|
// 关闭当前的对话框
|
|
|
|
|
dialog.dismiss();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 显示更改账户确认对话框的私有方法。
|
|
|
|
|
private void showChangeAccountConfirmAlertDialog() {
|
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
// 加载并设置对话框标题布局
|
|
|
|
|
|
|
|
|
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
|
|
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
|
|
|
// 设置标题文本为变更账户的提示,包括当前账户名称
|
|
|
|
|
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
|
|
|
|
|
getSyncAccountName(this)));
|
|
|
|
|
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
|
|
|
|
|
// 设置子标题文本为更改账户的警告信息
|
|
|
|
|
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
|
|
|
|
|
// 对话框设置自定义标题布局
|
|
|
|
|
dialogBuilder.setCustomTitle(titleView);
|
|
|
|
|
// 设置对话框的选项列表,包括“更改账户”、“移除账户”和“取消”
|
|
|
|
|
|
|
|
|
|
CharSequence[] menuItemArray = new CharSequence[] {
|
|
|
|
|
getString(R.string.preferences_menu_change_account),
|
|
|
|
|
getString(R.string.preferences_menu_remove_account),
|
|
|
|
@ -313,138 +272,100 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
};
|
|
|
|
|
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
// 当用户在列表中选择选项时,根据选择执行相应操作
|
|
|
|
|
if (which == 0) {
|
|
|
|
|
// 如果选择“更改账户”,显示选择账户的对话框
|
|
|
|
|
showSelectAccountAlertDialog();
|
|
|
|
|
} else if (which == 1) {
|
|
|
|
|
//如果选择“移除账户”,移除同步账户并刷新UI
|
|
|
|
|
removeSyncAccount();
|
|
|
|
|
refreshUI();
|
|
|
|
|
}
|
|
|
|
|
// 没有必要处理取消选项,因为点击会自动关闭对话框
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// 显示对话框
|
|
|
|
|
dialogBuilder.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取设备中所有Google账户的数组
|
|
|
|
|
private Account[] getGoogleAccounts() {
|
|
|
|
|
// 通过AccountManager获取账户管理实例
|
|
|
|
|
AccountManager accountManager = AccountManager.get(this);
|
|
|
|
|
//调用getAccountsByType方法获取类型为"com.google"的所有账户,即Google账户
|
|
|
|
|
return accountManager.getAccountsByType("com.google");
|
|
|
|
|
}
|
|
|
|
|
// 设定或改变同步账号
|
|
|
|
|
|
|
|
|
|
private void setSyncAccount(String account) {
|
|
|
|
|
// 如果当前同步账号不是用户选定的账号
|
|
|
|
|
if (!getSyncAccountName(this).equals(account)) {
|
|
|
|
|
// 获取SharedPreferences的实例来存储偏好设置
|
|
|
|
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
|
|
|
//创建一个SharedPreferences.Editor进行编辑
|
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
|
//如果传入账号不是null,将其存储到SharedPreferences
|
|
|
|
|
if (account != null) {
|
|
|
|
|
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
|
|
|
|
|
} else {
|
|
|
|
|
// 如果是null则存储空字符串""
|
|
|
|
|
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
|
|
|
|
}
|
|
|
|
|
// 将更改提交到SharedPreferences
|
|
|
|
|
editor.commit();
|
|
|
|
|
|
|
|
|
|
// 将最后同步时间设置为0(清空)
|
|
|
|
|
// clean up last sync time
|
|
|
|
|
setLastSyncTime(this, 0);
|
|
|
|
|
|
|
|
|
|
// 在新线程中清空与同步相关的本地信息
|
|
|
|
|
// clean up local gtask related info
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
//创建ContentValues以存储需要更新的值
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
values.put(NoteColumns.GTASK_ID, ""); // 清空GTASK_ID
|
|
|
|
|
values.put(NoteColumns.SYNC_ID, 0); // 设置SYNC_ID为0
|
|
|
|
|
// 调用ContentResolver以更新数据库中的信息
|
|
|
|
|
values.put(NoteColumns.GTASK_ID, "");
|
|
|
|
|
values.put(NoteColumns.SYNC_ID, 0);
|
|
|
|
|
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
|
|
|
|
|
// 显示提示信息,告知用户同步账号设置成功
|
|
|
|
|
Toast.makeText(NotesPreferenceActivity.this,
|
|
|
|
|
getString(R.string.preferences_toast_success_set_accout, account),
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 移除同步账号
|
|
|
|
|
private void removeSyncAccount() {
|
|
|
|
|
// 获取SharedPreferences的实例来存储偏好设置
|
|
|
|
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
|
|
|
// 创建一个SharedPreferences.Editor进行编辑
|
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
|
// 如果存在同步账号的设置项,将其删除
|
|
|
|
|
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
|
|
|
|
|
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
|
|
|
|
|
}
|
|
|
|
|
// 如果存在最后同步时间的设置项,将其删除
|
|
|
|
|
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
|
|
|
|
|
editor.remove(PREFERENCE_LAST_SYNC_TIME);
|
|
|
|
|
}
|
|
|
|
|
// 将更改提交到SharedPreferences
|
|
|
|
|
editor.commit();
|
|
|
|
|
|
|
|
|
|
// 在新线程中清空与同步相关的本地信息
|
|
|
|
|
// clean up local gtask related info
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
public void run() {
|
|
|
|
|
// 创建ContentValues以存储需要更新的值
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
values.put(NoteColumns.GTASK_ID, ""); // 清空GTASK_ID
|
|
|
|
|
values.put(NoteColumns.SYNC_ID, 0); // 设置SYNC_ID为0
|
|
|
|
|
values.put(NoteColumns.GTASK_ID, "");
|
|
|
|
|
values.put(NoteColumns.SYNC_ID, 0);
|
|
|
|
|
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取当前设定的同步账号
|
|
|
|
|
public static String getSyncAccountName(Context context) {
|
|
|
|
|
// 获取SharedPreferences的实例来存储偏好设置
|
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
|
// 返回存储的同步账号名称,如果没有则返回空字符串""
|
|
|
|
|
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置最后同步时间
|
|
|
|
|
public static void setLastSyncTime(Context context, long time) {
|
|
|
|
|
// 获取SharedPreferences的实例来存储偏好设置
|
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
|
// 创建一个SharedPreferences.Editor进行编辑
|
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
|
// 将同步时间设置为传入的time
|
|
|
|
|
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
|
|
|
|
|
// 将更改提交到SharedPreferences
|
|
|
|
|
editor.commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取最后同步时间
|
|
|
|
|
public static long getLastSyncTime(Context context) {
|
|
|
|
|
// 获取SharedPreferences的实例来存储偏好设置
|
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
|
// 返回存储的最后同步时间,如果没有则返回0
|
|
|
|
|
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 内部类,广播接收器,用于接收同步状态变更的广播
|
|
|
|
|
private class GTaskReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
|
// 刷新界面显示
|
|
|
|
|
refreshUI();
|
|
|
|
|
if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) {
|
|
|
|
|
// 找到同步状态的TextView,并设置显示文本
|
|
|
|
|
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
|
|
|
|
syncStatus.setText(intent
|
|
|
|
|
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
|
|
|
|
@ -453,12 +374,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理选项菜单的项被选择的事件
|
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
|
// 根据菜单项的ID进行不同的操作
|
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
|
case android.R.id.home:
|
|
|
|
|
// 如果是home项,创建意图,启动NotesListActivity
|
|
|
|
|
Intent intent = new Intent(this, NotesListActivity.class);
|
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
startActivity(intent);
|
|
|
|
|