|
|
|
@ -36,26 +36,16 @@ import net.micode.notes.gtask.remote.GTaskSyncService;
|
|
|
|
|
* 继承了PreferenceActivity主要功能为对系统信息和配置进行自动保存的Activity
|
|
|
|
|
*/
|
|
|
|
|
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";
|
|
|
|
|
//同步账号
|
|
|
|
|
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
|
|
|
|
|
//同步时间
|
|
|
|
|
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_LAST_SYNC_TIME = "pref_last_sync_time";//同步时间
|
|
|
|
|
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 AUTHORITIES_FILTER_KEY = "authorities";
|
|
|
|
|
//本地密码
|
|
|
|
|
private PreferenceCategory mAccountCategory;
|
|
|
|
|
//账户分组
|
|
|
|
|
private GTaskReceiver mReceiver;
|
|
|
|
|
//同步任务接收器
|
|
|
|
|
private Account[] mOriAccounts;
|
|
|
|
|
//账户
|
|
|
|
|
private boolean mHasAddedAccount;
|
|
|
|
|
//账户的hash标记
|
|
|
|
|
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";//同步密码
|
|
|
|
|
private static final String AUTHORITIES_FILTER_KEY = "authorities";//本地密码
|
|
|
|
|
private PreferenceCategory mAccountCategory;//账户分组
|
|
|
|
|
private GTaskReceiver mReceiver;//同步任务接收器
|
|
|
|
|
private Account[] mOriAccounts;//账户
|
|
|
|
|
private boolean mHasAddedAccount;//账户的hash标记
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
/*创建一个activity*/
|
|
|
|
@ -231,19 +221,13 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
*函数功能:刷新标签界面
|
|
|
|
|
*函数实现:调用上文设置账号和设置按键两个函数来实现
|
|
|
|
|
*/
|
|
|
|
|
/*函数功能:刷新标签界面*/
|
|
|
|
|
private void refreshUI() {
|
|
|
|
|
loadAccountPreference();
|
|
|
|
|
loadSyncButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 函数功能:显示账户选择的对话框并进行账户的设置
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
*/
|
|
|
|
|
/*函数功能:显示账户选择的对话框并进行账户的设置*/
|
|
|
|
|
private void showSelectAccountAlertDialog() {
|
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
//创建一个新的对话框
|
|
|
|
@ -313,10 +297,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
//建立新加账户对话框的监听器
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 函数功能:显示账户选择对话框和相关账户操作
|
|
|
|
|
* 函数实现:如下注释
|
|
|
|
|
*/
|
|
|
|
|
/*函数功能:显示账户选择对话框和相关账户操作*/
|
|
|
|
|
private void showChangeAccountConfirmAlertDialog() {
|
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
//创建一个新的对话框
|
|
|
|
@ -353,19 +334,13 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
//显示对话框
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
*函数功能:获取谷歌账户
|
|
|
|
|
*函数实现:通过账户管理器直接获取
|
|
|
|
|
*/
|
|
|
|
|
/*函数功能:获取谷歌账户*/
|
|
|
|
|
private Account[] getGoogleAccounts() {
|
|
|
|
|
AccountManager accountManager = AccountManager.get(this);
|
|
|
|
|
return accountManager.getAccountsByType("com.google");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 函数功能:设置同步账户
|
|
|
|
|
* 函数实现:如下注释:
|
|
|
|
|
*/
|
|
|
|
|
/*函数功能:设置同步账户*/
|
|
|
|
|
private void setSyncAccount(String account) {
|
|
|
|
|
if (!getSyncAccountName(this).equals(account)) {
|
|
|
|
|
//假如该账号不在同步账号列表中
|
|
|
|
@ -403,10 +378,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
//将toast的文本信息置为“设置账户成功”并显示出来
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* 函数功能:删除同步账户
|
|
|
|
|
* 函数实现:如下注释:
|
|
|
|
|
*/
|
|
|
|
|
/*函数功能:删除同步账户*/
|
|
|
|
|
private void removeSyncAccount() {
|
|
|
|
|
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
|
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
@ -435,20 +407,14 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
//重置当地同步任务的信息
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 函数功能:获取同步账户名称
|
|
|
|
|
* 函数实现:通过共享的首选项里的信息直接获取
|
|
|
|
|
*/
|
|
|
|
|
/*函数功能:获取同步账户名称*/
|
|
|
|
|
public static String getSyncAccountName(Context context) {
|
|
|
|
|
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 settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
@ -458,10 +424,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
editor.commit();
|
|
|
|
|
//编辑最终同步时间并提交更新
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* 函数功能:获取最终同步时间
|
|
|
|
|
* 函数实现:通过共享的首选项里的信息直接获取
|
|
|
|
|
*/
|
|
|
|
|
/* 函数功能:获取最终同步时间*/
|
|
|
|
|
public static long getLastSyncTime(Context context) {
|
|
|
|
|
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
|
|
|
|
|
Context.MODE_PRIVATE);
|
|
|
|
|