|
|
|
@ -18,6 +18,7 @@ package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
import android.accounts.Account;
|
|
|
|
|
import android.accounts.AccountManager;
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
|
import android.app.ActionBar;
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
@ -48,6 +49,9 @@ import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
import net.micode.notes.gtask.remote.GTaskSyncService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NotesPreferenceActivity在小米便签中主要实现的是对背景颜色和字体大小的数据储存。
|
|
|
|
|
*/
|
|
|
|
|
public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
public static final String PREFERENCE_NAME = "notes_preferences";
|
|
|
|
|
|
|
|
|
@ -69,14 +73,20 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
|
|
|
|
|
private boolean mHasAddedAccount;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 创建一个activity,在函数里要完成所有的正常静态设置
|
|
|
|
|
* @param icicle 存放当前状态
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle icicle) {
|
|
|
|
|
super.onCreate(icicle);
|
|
|
|
|
|
|
|
|
|
/* using the app icon for navigation */
|
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);//在左上角增加一个返回图标
|
|
|
|
|
|
|
|
|
|
//增加xml来源
|
|
|
|
|
addPreferencesFromResource(R.xml.preferences);
|
|
|
|
|
//同步账户关键码来初始化分组
|
|
|
|
|
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
|
|
|
|
|
mReceiver = new GTaskReceiver();
|
|
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
@ -84,10 +94,16 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
registerReceiver(mReceiver, filter);
|
|
|
|
|
|
|
|
|
|
mOriAccounts = null;
|
|
|
|
|
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
|
|
|
|
|
//获取listvivew,ListView的作用:用于列出所有选择
|
|
|
|
|
//View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);改成了注释形式
|
|
|
|
|
@SuppressLint("InflateParams") View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
|
|
|
|
|
//在listview组件上方添加其他组件
|
|
|
|
|
getListView().addHeaderView(header, null, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* activity交互功能的实现,用于接受用户的输入
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
super.onResume();
|
|
|
|
@ -116,6 +132,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
refreshUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 销毁一个activity
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
if (mReceiver != null) {
|
|
|
|
@ -124,6 +143,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 重新设置账户信息
|
|
|
|
|
*/
|
|
|
|
|
private void loadAccountPreference() {
|
|
|
|
|
mAccountCategory.removeAll();
|
|
|
|
|
|
|
|
|
@ -154,6 +176,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
mAccountCategory.addPreference(accountPref);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置按键的状态和最后同步的时间
|
|
|
|
|
*/
|
|
|
|
|
private void loadSyncButton() {
|
|
|
|
|
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
|
|
|
|
|
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
|
|
|
|
@ -193,11 +218,17 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 刷新标签界面,实时更新展示
|
|
|
|
|
*/
|
|
|
|
|
private void refreshUI() {
|
|
|
|
|
loadAccountPreference();
|
|
|
|
|
loadSyncButton();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示用户选择的对话框并进行账户的设置
|
|
|
|
|
*/
|
|
|
|
|
private void showSelectAccountAlertDialog() {
|
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
|
@ -254,6 +285,9 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 显示账户选择对话框和相关账户操作
|
|
|
|
|
*/
|
|
|
|
|
private void showChangeAccountConfirmAlertDialog() {
|
|
|
|
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
|
@ -283,6 +317,10 @@ public class NotesPreferenceActivity extends PreferenceActivity {
|
|
|
|
|
dialogBuilder.show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取谷歌账户
|
|
|
|
|
* @return 返回谷歌用户
|
|
|
|
|
*/
|
|
|
|
|
private Account[] getGoogleAccounts() {
|
|
|
|
|
AccountManager accountManager = AccountManager.get(this);
|
|
|
|
|
return accountManager.getAccountsByType("com.google");
|
|
|
|
|