|
|
@ -47,53 +47,63 @@ import net.micode.notes.data.Notes;
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
import net.micode.notes.gtask.remote.GTaskSyncService;
|
|
|
|
import net.micode.notes.gtask.remote.GTaskSyncService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* NotesPreferenceActivity 是便签应用的设置界面,负责管理用户偏好设置和Google任务同步功能。
|
|
|
|
|
|
|
|
* 提供账户绑定、同步控制和同步状态显示等功能,通过PreferenceActivity实现设置界面。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
|
|
|
// 偏好设置文件名
|
|
|
|
public static final String PREFERENCE_NAME = "notes_preferences";
|
|
|
|
public static final String PREFERENCE_NAME = "notes_preferences";
|
|
|
|
|
|
|
|
// 存储同步账户名的键
|
|
|
|
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
|
|
|
|
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
|
|
|
|
|
|
|
|
// 存储上次同步时间的键
|
|
|
|
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
|
|
|
|
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
|
|
|
|
|
|
|
|
// 存储背景随机显示设置的键
|
|
|
|
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
|
|
|
|
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
|
|
|
|
|
|
|
|
|
|
|
|
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
|
|
|
|
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
|
|
|
|
|
|
|
|
|
|
|
|
private static final String AUTHORITIES_FILTER_KEY = "authorities";
|
|
|
|
private static final String AUTHORITIES_FILTER_KEY = "authorities";
|
|
|
|
|
|
|
|
|
|
|
|
private PreferenceCategory mAccountCategory;
|
|
|
|
private PreferenceCategory mAccountCategory; // 账户设置分类
|
|
|
|
|
|
|
|
private GTaskReceiver mReceiver; // 接收同步服务广播
|
|
|
|
private GTaskReceiver mReceiver;
|
|
|
|
private Account[] mOriAccounts; // 原始账户列表
|
|
|
|
|
|
|
|
private boolean mHasAddedAccount; // 是否添加了新账户
|
|
|
|
private Account[] mOriAccounts;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean mHasAddedAccount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 初始化Activity,设置布局和加载偏好设置。
|
|
|
|
|
|
|
|
* 注册广播接收器监听同步服务状态变化,并添加自定义头部视图。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
super.onCreate(icicle);
|
|
|
|
super.onCreate(icicle);
|
|
|
|
|
|
|
|
|
|
|
|
/* using the app icon for navigation */
|
|
|
|
// 设置返回导航
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 加载偏好设置布局
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
|
|
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
|
|
|
|
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 注册广播接收器监听同步服务状态
|
|
|
|
mReceiver = new GTaskReceiver();
|
|
|
|
mReceiver = new GTaskReceiver();
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
|
|
|
|
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
|
|
|
|
registerReceiver(mReceiver, filter);
|
|
|
|
registerReceiver(mReceiver, filter);
|
|
|
|
|
|
|
|
|
|
|
|
mOriAccounts = null;
|
|
|
|
mOriAccounts = null;
|
|
|
|
|
|
|
|
// 添加自定义头部视图
|
|
|
|
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
|
|
|
|
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
|
|
|
|
getListView().addHeaderView(header, null, true);
|
|
|
|
getListView().addHeaderView(header, null, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Activity恢复时调用,检查是否添加了新账户并自动设置,刷新UI显示。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
super.onResume();
|
|
|
|
|
|
|
|
|
|
|
|
// need to set sync account automatically if user has added a new
|
|
|
|
// 如果添加了新账户,自动设置同步账户
|
|
|
|
// account
|
|
|
|
|
|
|
|
if (mHasAddedAccount) {
|
|
|
|
if (mHasAddedAccount) {
|
|
|
|
Account[] accounts = getGoogleAccounts();
|
|
|
|
Account[] accounts = getGoogleAccounts();
|
|
|
|
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
|
|
|
|
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
|
|
|
@ -116,6 +126,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
refreshUI();
|
|
|
|
refreshUI();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Activity销毁时调用,注销广播接收器以避免内存泄漏。
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
|
|
|
protected void onDestroy() {
|
|
|
|
if (mReceiver != null) {
|
|
|
|
if (mReceiver != null) {
|
|
|
@ -124,6 +137,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
super.onDestroy();
|
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 加载账户设置偏好项,设置点击事件处理。
|
|
|
|
|
|
|
|
* 如果未设置账户,点击显示选择账户对话框;如果已设置,显示变更确认对话框。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void loadAccountPreference() {
|
|
|
|
private void loadAccountPreference() {
|
|
|
|
mAccountCategory.removeAll();
|
|
|
|
mAccountCategory.removeAll();
|
|
|
|
|
|
|
|
|
|
|
@ -135,14 +152,14 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
public boolean onPreferenceClick(Preference preference) {
|
|
|
|
if (!GTaskSyncService.isSyncing()) {
|
|
|
|
if (!GTaskSyncService.isSyncing()) {
|
|
|
|
if (TextUtils.isEmpty(defaultAccount)) {
|
|
|
|
if (TextUtils.isEmpty(defaultAccount)) {
|
|
|
|
// the first time to set account
|
|
|
|
// 首次设置账户
|
|
|
|
showSelectAccountAlertDialog();
|
|
|
|
showSelectAccountAlertDialog();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// if the account has already been set, we need to promp
|
|
|
|
// 已设置账户,提示变更风险
|
|
|
|
// user about the risk
|
|
|
|
|
|
|
|
showChangeAccountConfirmAlertDialog();
|
|
|
|
showChangeAccountConfirmAlertDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 同步进行中,禁止更改账户
|
|
|
|
Toast.makeText(NotesPreferenceActivity.this,
|
|
|
|
Toast.makeText(NotesPreferenceActivity.this,
|
|
|
|
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
|
|
|
|
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
|
|
|
|
.show();
|
|
|
|
.show();
|
|
|
@ -154,11 +171,14 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
mAccountCategory.addPreference(accountPref);
|
|
|
|
mAccountCategory.addPreference(accountPref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 加载同步按钮和上次同步时间显示,根据当前同步状态设置按钮文本和点击事件。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void loadSyncButton() {
|
|
|
|
private void loadSyncButton() {
|
|
|
|
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
|
|
|
|
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
|
|
|
|
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
|
|
|
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
|
|
|
|
|
|
|
|
|
|
|
// set button state
|
|
|
|
// 设置按钮状态
|
|
|
|
if (GTaskSyncService.isSyncing()) {
|
|
|
|
if (GTaskSyncService.isSyncing()) {
|
|
|
|
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
|
|
|
|
syncButton.setText(getString(R.string.preferences_button_sync_cancel));
|
|
|
|
syncButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
syncButton.setOnClickListener(new View.OnClickListener() {
|
|
|
@ -176,7 +196,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
|
|
|
|
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));
|
|
|
|
|
|
|
|
|
|
|
|
// set last sync time
|
|
|
|
// 设置上次同步时间
|
|
|
|
if (GTaskSyncService.isSyncing()) {
|
|
|
|
if (GTaskSyncService.isSyncing()) {
|
|
|
|
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
|
|
|
|
lastSyncTimeView.setText(GTaskSyncService.getProgressString());
|
|
|
|
lastSyncTimeView.setVisibility(View.VISIBLE);
|
|
|
|
lastSyncTimeView.setVisibility(View.VISIBLE);
|
|
|
@ -193,14 +213,22 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 刷新设置界面UI,重新加载账户设置和同步按钮状态。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void refreshUI() {
|
|
|
|
private void refreshUI() {
|
|
|
|
loadAccountPreference();
|
|
|
|
loadAccountPreference();
|
|
|
|
loadSyncButton();
|
|
|
|
loadSyncButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 显示选择账户对话框,列出设备上的Google账户供用户选择。
|
|
|
|
|
|
|
|
* 同时提供添加新账户的选项。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void showSelectAccountAlertDialog() {
|
|
|
|
private void showSelectAccountAlertDialog() {
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置对话框标题和提示信息
|
|
|
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
|
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
|
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
|
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
|
|
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
|
|
|
|
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
|
|
|
@ -217,6 +245,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
mHasAddedAccount = false;
|
|
|
|
mHasAddedAccount = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (accounts.length > 0) {
|
|
|
|
if (accounts.length > 0) {
|
|
|
|
|
|
|
|
// 显示账户列表
|
|
|
|
CharSequence[] items = new CharSequence[accounts.length];
|
|
|
|
CharSequence[] items = new CharSequence[accounts.length];
|
|
|
|
final CharSequence[] itemMapping = items;
|
|
|
|
final CharSequence[] itemMapping = items;
|
|
|
|
int checkedItem = -1;
|
|
|
|
int checkedItem = -1;
|
|
|
@ -237,6 +266,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 添加"添加账户"选项
|
|
|
|
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
|
|
|
|
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
|
|
|
|
dialogBuilder.setView(addAccountView);
|
|
|
|
dialogBuilder.setView(addAccountView);
|
|
|
|
|
|
|
|
|
|
|
@ -244,6 +274,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
addAccountView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
addAccountView.setOnClickListener(new View.OnClickListener() {
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
mHasAddedAccount = true;
|
|
|
|
mHasAddedAccount = true;
|
|
|
|
|
|
|
|
// 启动添加账户界面
|
|
|
|
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
|
|
|
|
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
|
|
|
|
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
|
|
|
|
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
|
|
|
|
"gmail-ls"
|
|
|
|
"gmail-ls"
|
|
|
@ -254,9 +285,13 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 显示变更账户确认对话框,提供变更账户、移除账户和取消三个选项。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void showChangeAccountConfirmAlertDialog() {
|
|
|
|
private void showChangeAccountConfirmAlertDialog() {
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置对话框标题和警告信息
|
|
|
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
|
|
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
|
|
|
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
|
|
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
|
|
|
|
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
|
|
|
|
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title,
|
|
|
@ -265,6 +300,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
|
|
|
|
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));
|
|
|
|
dialogBuilder.setCustomTitle(titleView);
|
|
|
|
dialogBuilder.setCustomTitle(titleView);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置选项菜单
|
|
|
|
CharSequence[] menuItemArray = new CharSequence[] {
|
|
|
|
CharSequence[] menuItemArray = new CharSequence[] {
|
|
|
|
getString(R.string.preferences_menu_change_account),
|
|
|
|
getString(R.string.preferences_menu_change_account),
|
|
|
|
getString(R.string.preferences_menu_remove_account),
|
|
|
|
getString(R.string.preferences_menu_remove_account),
|
|
|
@ -273,8 +309,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
|
|
|
|
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
if (which == 0) {
|
|
|
|
if (which == 0) {
|
|
|
|
|
|
|
|
// 变更账户
|
|
|
|
showSelectAccountAlertDialog();
|
|
|
|
showSelectAccountAlertDialog();
|
|
|
|
} else if (which == 1) {
|
|
|
|
} else if (which == 1) {
|
|
|
|
|
|
|
|
// 移除账户
|
|
|
|
removeSyncAccount();
|
|
|
|
removeSyncAccount();
|
|
|
|
refreshUI();
|
|
|
|
refreshUI();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -283,13 +321,20 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
dialogBuilder.show();
|
|
|
|
dialogBuilder.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取设备上的Google账户列表。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private Account[] getGoogleAccounts() {
|
|
|
|
private Account[] getGoogleAccounts() {
|
|
|
|
AccountManager accountManager = AccountManager.get(this);
|
|
|
|
AccountManager accountManager = AccountManager.get(this);
|
|
|
|
return accountManager.getAccountsByType("com.google");
|
|
|
|
return accountManager.getAccountsByType("com.google");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置同步账户,保存账户名到偏好设置,并清理本地同步相关数据。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void setSyncAccount(String account) {
|
|
|
|
private void setSyncAccount(String account) {
|
|
|
|
if (!getSyncAccountName(this).equals(account)) {
|
|
|
|
if (!getSyncAccountName(this).equals(account)) {
|
|
|
|
|
|
|
|
// 保存账户名到偏好设置
|
|
|
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
if (account != null) {
|
|
|
|
if (account != null) {
|
|
|
@ -299,10 +344,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
editor.commit();
|
|
|
|
|
|
|
|
|
|
|
|
// clean up last sync time
|
|
|
|
// 清理上次同步时间
|
|
|
|
setLastSyncTime(this, 0);
|
|
|
|
setLastSyncTime(this, 0);
|
|
|
|
|
|
|
|
|
|
|
|
// clean up local gtask related info
|
|
|
|
// 清理本地GTask相关信息(异步执行)
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
@ -318,6 +363,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 移除同步账户,从偏好设置中删除账户信息,并清理本地同步相关数据。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private void removeSyncAccount() {
|
|
|
|
private void removeSyncAccount() {
|
|
|
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
@ -329,7 +377,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
editor.commit();
|
|
|
|
editor.commit();
|
|
|
|
|
|
|
|
|
|
|
|
// clean up local gtask related info
|
|
|
|
// 清理本地GTask相关信息(异步执行)
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
@ -340,12 +388,18 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
}).start();
|
|
|
|
}).start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取当前设置的同步账户名。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static String getSyncAccountName(Context context) {
|
|
|
|
public static String getSyncAccountName(Context context) {
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
|
|
|
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 设置上次同步时间。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static void setLastSyncTime(Context context, long time) {
|
|
|
|
public static void setLastSyncTime(Context context, long time) {
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
@ -354,12 +408,18 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
editor.commit();
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取上次同步时间。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static long getLastSyncTime(Context context) {
|
|
|
|
public static long getLastSyncTime(Context context) {
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
|
|
|
|
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 广播接收器,监听GTask同步服务的状态变化,更新UI显示。
|
|
|
|
|
|
|
|
*/
|
|
|
|
private class GTaskReceiver extends BroadcastReceiver {
|
|
|
|
private class GTaskReceiver extends BroadcastReceiver {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -373,7 +433,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 处理选项菜单点击事件,实现返回导航功能。
|
|
|
|
|
|
|
|
*/
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
case android.R.id.home:
|
|
|
|