|  |  |  | @ -13,9 +13,9 @@ | 
			
		
	
		
			
				
					|  |  |  |  |  * See the License for the specific language governing permissions and | 
			
		
	
		
			
				
					|  |  |  |  |  * limitations under the License. | 
			
		
	
		
			
				
					|  |  |  |  |  */ | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  | package net.micode.notes.ui; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  | import android.accounts.Account; | 
			
		
	
		
			
				
					|  |  |  |  | import android.accounts.AccountManager; | 
			
		
	
		
			
				
					|  |  |  |  | import android.app.ActionBar; | 
			
		
	
	
		
			
				
					|  |  |  | @ -41,74 +41,59 @@ import android.view.View; | 
			
		
	
		
			
				
					|  |  |  |  | import android.widget.Button; | 
			
		
	
		
			
				
					|  |  |  |  | import android.widget.TextView; | 
			
		
	
		
			
				
					|  |  |  |  | import android.widget.Toast; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  | import net.micode.notes.R; | 
			
		
	
		
			
				
					|  |  |  |  | import net.micode.notes.data.Notes; | 
			
		
	
		
			
				
					|  |  |  |  | import net.micode.notes.data.Notes.NoteColumns; | 
			
		
	
		
			
				
					|  |  |  |  | import net.micode.notes.gtask.remote.GTaskSyncService; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  | // 设置界面活动类,继承自PreferenceActivity
 | 
			
		
	
		
			
				
					|  |  |  |  | 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_SET_BG_COLOR_KEY = "pref_key_bg_random_appear"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 定义偏好设置中同步账户键(用于UI显示)
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 定义过滤器键,用于添加账户设置
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     private static final String AUTHORITIES_FILTER_KEY = "authorities"; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 定义账户类别,在UI中用于显示账户相关的偏好设置
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     private PreferenceCategory mAccountCategory; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 定义一个GTaskReceiver实例,用于接收同步状态更新的广播
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     private GTaskReceiver mReceiver; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 存储原始的Google账户列表
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     private Account[] mOriAccounts; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |     // 标记用户是否添加了新账户
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     private boolean mHasAddedAccount; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 创建活动时初始化界面
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     protected void onCreate(Bundle icicle) { | 
			
		
	
		
			
				
					|  |  |  |  |         super.onCreate(icicle); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置ActionBar的返回按钮,以便用户可以通过点击应用图标返回上一级活动
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         /* 使用应用图标进行导航 */ | 
			
		
	
		
			
				
					|  |  |  |  |         getActionBar().setDisplayHomeAsUpEnabled(true); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 从指定的XML资源文件加载偏好设置
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         addPreferencesFromResource(R.xml.preferences); | 
			
		
	
		
			
				
					|  |  |  |  |         // 找到XML中定义的账户类别PreferenceCategory,并赋值给mAccountCategory
 | 
			
		
	
		
			
				
					|  |  |  |  |         mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY); | 
			
		
	
		
			
				
					|  |  |  |  |         // 创建GTaskReceiver实例,并注册广播接收器,用于接收同步服务的状态广播
 | 
			
		
	
		
			
				
					|  |  |  |  |         mReceiver = new GTaskReceiver(); | 
			
		
	
		
			
				
					|  |  |  |  |         IntentFilter filter = new IntentFilter(); | 
			
		
	
		
			
				
					|  |  |  |  |         filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME); | 
			
		
	
		
			
				
					|  |  |  |  |         registerReceiver(mReceiver, filter); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 初始化账户列表,目前为空,将在其他方法中进行填充
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         mOriAccounts = null; | 
			
		
	
		
			
				
					|  |  |  |  |         // 创建并添加自定义的头部视图到设置界面,该视图通常用于显示额外的信息或操作
 | 
			
		
	
		
			
				
					|  |  |  |  |         View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null); | 
			
		
	
		
			
				
					|  |  |  |  |         getListView().addHeaderView(header, null, true); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 恢复活动时刷新界面
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     protected void onResume() { | 
			
		
	
		
			
				
					|  |  |  |  |         super.onResume(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         // 如果用户添加了新账户,自动设置同步账户
 | 
			
		
	
		
			
				
					|  |  |  |  |         if (mHasAddedAccount) { | 
			
		
	
		
			
				
					|  |  |  |  |             Account[] accounts = getGoogleAccounts(); | 
			
		
	
	
		
			
				
					|  |  |  | @ -128,11 +113,10 @@ public class NotesPreferenceActivity extends PreferenceActivity { | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 刷新用户界面,包括账户偏好设置和同步按钮
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         refreshUI(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 销毁活动时注销广播接收器
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     protected void onDestroy() { | 
			
		
	
	
		
			
				
					|  |  |  | @ -141,36 +125,26 @@ public class NotesPreferenceActivity extends PreferenceActivity { | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         super.onDestroy(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 加载账户偏好设置
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void loadAccountPreference() { | 
			
		
	
		
			
				
					|  |  |  |  |         // 清空账户类别中的所有偏好设置项
 | 
			
		
	
		
			
				
					|  |  |  |  |         mAccountCategory.removeAll(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 创建一个新的Preference实例,用于显示账户偏好设置
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         Preference accountPref = new Preference(this); | 
			
		
	
		
			
				
					|  |  |  |  |         // 获取当前设置的同步账户名称
 | 
			
		
	
		
			
				
					|  |  |  |  |         final String defaultAccount = getSyncAccountName(this); | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置偏好设置项的标题
 | 
			
		
	
		
			
				
					|  |  |  |  |         accountPref.setTitle(getString(R.string.preferences_account_title)); | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置偏好设置项的摘要信息
 | 
			
		
	
		
			
				
					|  |  |  |  |         accountPref.setSummary(getString(R.string.preferences_account_summary)); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置偏好设置项的点击监听器
 | 
			
		
	
		
			
				
					|  |  |  |  |         accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { | 
			
		
	
		
			
				
					|  |  |  |  |             @Override | 
			
		
	
		
			
				
					|  |  |  |  |             public boolean onPreferenceClick(Preference preference) { | 
			
		
	
		
			
				
					|  |  |  |  |                 // 如果当前没有正在进行的同步操作
 | 
			
		
	
		
			
				
					|  |  |  |  |                 if (!GTaskSyncService.isSyncing()) { | 
			
		
	
		
			
				
					|  |  |  |  |                     // 如果同步账户名称为空,表示第一次设置账户
 | 
			
		
	
		
			
				
					|  |  |  |  |                     if (TextUtils.isEmpty(defaultAccount)) { | 
			
		
	
		
			
				
					|  |  |  |  |                         // 第一次设置账户
 | 
			
		
	
		
			
				
					|  |  |  |  |                         showSelectAccountAlertDialog(); | 
			
		
	
		
			
				
					|  |  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |  |                         // 如果账户已经设置,提示用户切换账户的风险
 | 
			
		
	
		
			
				
					|  |  |  |  |                         showChangeAccountConfirmAlertDialog(); | 
			
		
	
		
			
				
					|  |  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |  |                     // 如果正在同步,显示提示信息,告知用户无法在同步过程中更改账户
 | 
			
		
	
		
			
				
					|  |  |  |  |                     Toast.makeText(NotesPreferenceActivity.this, | 
			
		
	
		
			
				
					|  |  |  |  |                             R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT) | 
			
		
	
		
			
				
					|  |  |  |  |                             .show(); | 
			
		
	
	
		
			
				
					|  |  |  | @ -178,49 +152,38 @@ public class NotesPreferenceActivity extends PreferenceActivity { | 
			
		
	
		
			
				
					|  |  |  |  |                 return true; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 将账户偏好设置项添加到账户类别中
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         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); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 根据同步服务的状态设置按钮的文本和点击事件
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置按钮状态
 | 
			
		
	
		
			
				
					|  |  |  |  |         if (GTaskSyncService.isSyncing()) { | 
			
		
	
		
			
				
					|  |  |  |  |             // 如果正在同步,设置按钮文本为取消同步,并添加点击事件以取消同步
 | 
			
		
	
		
			
				
					|  |  |  |  |             syncButton.setText(getString(R.string.preferences_button_sync_cancel)); | 
			
		
	
		
			
				
					|  |  |  |  |             syncButton.setOnClickListener(new View.OnClickListener() { | 
			
		
	
		
			
				
					|  |  |  |  |                 @Override | 
			
		
	
		
			
				
					|  |  |  |  |                 public void onClick(View v) { | 
			
		
	
		
			
				
					|  |  |  |  |                     GTaskSyncService.cancelSync(NotesPreferenceActivity.this); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |  |             // 如果没有同步,设置按钮文本为立即同步,并添加点击事件以开始同步
 | 
			
		
	
		
			
				
					|  |  |  |  |             syncButton.setText(getString(R.string.preferences_button_sync_immediately)); | 
			
		
	
		
			
				
					|  |  |  |  |             syncButton.setOnClickListener(new View.OnClickListener() { | 
			
		
	
		
			
				
					|  |  |  |  |                 @Override | 
			
		
	
		
			
				
					|  |  |  |  |                 public void onClick(View v) { | 
			
		
	
		
			
				
					|  |  |  |  |                     GTaskSyncService.startSync(NotesPreferenceActivity.this); | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 根据同步账户名称是否为空设置按钮是否可用
 | 
			
		
	
		
			
				
					|  |  |  |  |         syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this))); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 根据同步服务的状态设置上次同步时间的显示
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置上次同步时间
 | 
			
		
	
		
			
				
					|  |  |  |  |         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, | 
			
		
	
	
		
			
				
					|  |  |  | @ -232,83 +195,58 @@ public class NotesPreferenceActivity extends PreferenceActivity { | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 刷新用户界面
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void refreshUI() { | 
			
		
	
		
			
				
					|  |  |  |  |         // 加载账户偏好设置
 | 
			
		
	
		
			
				
					|  |  |  |  |         loadAccountPreference(); | 
			
		
	
		
			
				
					|  |  |  |  |         // 加载同步按钮
 | 
			
		
	
		
			
				
					|  |  |  |  |         loadSyncButton(); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 显示选择账户的对话框
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void showSelectAccountAlertDialog() { | 
			
		
	
		
			
				
					|  |  |  |  |         // 创建一个AlertDialog.Builder实例
 | 
			
		
	
		
			
				
					|  |  |  |  |         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数组来存储账户名称
 | 
			
		
	
		
			
				
					|  |  |  |  |             CharSequence[] items = new CharSequence[accounts.length]; | 
			
		
	
		
			
				
					|  |  |  |  |             // 由于items是CharSequence数组,需要一个final引用以便在内部类中使用
 | 
			
		
	
		
			
				
					|  |  |  |  |             final CharSequence[] itemMapping = items; | 
			
		
	
		
			
				
					|  |  |  |  |             int checkedItem = -1; | 
			
		
	
		
			
				
					|  |  |  |  |             int index = 0; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             // 遍历账户列表,将账户名称存储到items数组中,并标记默认账户
 | 
			
		
	
		
			
				
					|  |  |  |  |             for (Account account : accounts) { | 
			
		
	
		
			
				
					|  |  |  |  |                 if (TextUtils.equals(account.name, defAccount)) { | 
			
		
	
		
			
				
					|  |  |  |  |                     checkedItem = index; | 
			
		
	
		
			
				
					|  |  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |  |                 items[index++] = account.name; | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             // 设置对话框为单选列表,包含所有的Google账户
 | 
			
		
	
		
			
				
					|  |  |  |  |             dialogBuilder.setSingleChoiceItems(items, checkedItem, | 
			
		
	
		
			
				
					|  |  |  |  |                     new DialogInterface.OnClickListener() { | 
			
		
	
		
			
				
					|  |  |  |  |                         @Override | 
			
		
	
		
			
				
					|  |  |  |  |                         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() { | 
			
		
	
		
			
				
					|  |  |  |  |             @Override | 
			
		
	
		
			
				
					|  |  |  |  |             public void onClick(View v) { | 
			
		
	
		
			
				
					|  |  |  |  |                 mHasAddedAccount = true; | 
			
		
	
		
			
				
					|  |  |  |  |                 Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); | 
			
		
	
	
		
			
				
					|  |  |  | @ -320,194 +258,145 @@ public class NotesPreferenceActivity extends PreferenceActivity { | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 显示更改账户确认对话框
 | 
			
		
	
		
			
				
					|  |  |  |  |     private void showChangeAccountConfirmAlertDialog() { | 
			
		
	
		
			
				
					|  |  |  |  |         // 创建一个AlertDialog.Builder实例
 | 
			
		
	
		
			
				
					|  |  |  |  |         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数组来存储对话框中的菜单项
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         CharSequence[] menuItemArray = new CharSequence[] { | 
			
		
	
		
			
				
					|  |  |  |  |                 getString(R.string.preferences_menu_change_account), | 
			
		
	
		
			
				
					|  |  |  |  |                 getString(R.string.preferences_menu_remove_account), | 
			
		
	
		
			
				
					|  |  |  |  |                 getString(R.string.preferences_menu_cancel) | 
			
		
	
		
			
				
					|  |  |  |  |         }; | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 设置对话框的菜单项
 | 
			
		
	
		
			
				
					|  |  |  |  |         dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() { | 
			
		
	
		
			
				
					|  |  |  |  |             @Override | 
			
		
	
		
			
				
					|  |  |  |  |             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); | 
			
		
	
		
			
				
					|  |  |  |  |         // 返回所有类型为"com.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 editor = settings.edit(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |             // 如果新的账户名称不为空,则将其存储到偏好设置中
 | 
			
		
	
		
			
				
					|  |  |  |  |             if (account != null) { | 
			
		
	
		
			
				
					|  |  |  |  |                 editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account); | 
			
		
	
		
			
				
					|  |  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |  |                 // 如果新的账户名称为空,则将其设置为空字符串
 | 
			
		
	
		
			
				
					|  |  |  |  |                 editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, ""); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |             // 提交偏好设置更改
 | 
			
		
	
		
			
				
					|  |  |  |  |             editor.commit(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |             // 清除上次同步时间
 | 
			
		
	
		
			
				
					|  |  |  |  |             setLastSyncTime(this, 0); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |             // 清除本地Gtask相关信息
 | 
			
		
	
		
			
				
					|  |  |  |  |             new Thread(new Runnable() { | 
			
		
	
		
			
				
					|  |  |  |  |                 @Override | 
			
		
	
		
			
				
					|  |  |  |  |                 public void run() { | 
			
		
	
		
			
				
					|  |  |  |  |                     ContentValues values = new ContentValues(); | 
			
		
	
		
			
				
					|  |  |  |  |                     // 将Gtask ID和SYNC ID设置为空和0
 | 
			
		
	
		
			
				
					|  |  |  |  |                     values.put(NoteColumns.GTASK_ID, ""); | 
			
		
	
		
			
				
					|  |  |  |  |                     values.put(NoteColumns.SYNC_ID, 0); | 
			
		
	
		
			
				
					|  |  |  |  |                     // 更新本地Notes数据库中的相关字段
 | 
			
		
	
		
			
				
					|  |  |  |  |                     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 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); | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |         // 提交偏好设置更改
 | 
			
		
	
		
			
				
					|  |  |  |  |         editor.commit(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         // 清除本地Gtask相关信息
 | 
			
		
	
		
			
				
					|  |  |  |  |         new Thread(new Runnable() { | 
			
		
	
		
			
				
					|  |  |  |  |             @Override | 
			
		
	
		
			
				
					|  |  |  |  |             public void run() { | 
			
		
	
		
			
				
					|  |  |  |  |                 ContentValues values = new ContentValues(); | 
			
		
	
		
			
				
					|  |  |  |  |                 // 将Gtask ID和SYNC ID设置为空和0
 | 
			
		
	
		
			
				
					|  |  |  |  |                 values.put(NoteColumns.GTASK_ID, ""); | 
			
		
	
		
			
				
					|  |  |  |  |                 values.put(NoteColumns.SYNC_ID, 0); | 
			
		
	
		
			
				
					|  |  |  |  |                 // 更新本地Notes数据库中的相关字段
 | 
			
		
	
		
			
				
					|  |  |  |  |                 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 editor = settings.edit(); | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |         // 将上次同步时间存储到偏好设置中
 | 
			
		
	
		
			
				
					|  |  |  |  |         editor.putLong(PREFERENCE_LAST_SYNC_TIME, time); | 
			
		
	
		
			
				
					|  |  |  |  |         // 提交偏好设置更改
 | 
			
		
	
		
			
				
					|  |  |  |  |         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 syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview); | 
			
		
	
		
			
				
					|  |  |  |  |                 // 更新文本为同步进度信息
 | 
			
		
	
		
			
				
					|  |  |  |  |                 syncStatus.setText(intent | 
			
		
	
		
			
				
					|  |  |  |  |                         .getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG)); | 
			
		
	
		
			
				
					|  |  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |  |   | 
			
		
	
		
			
				
					|  |  |  |  |     // 选项菜单项点击事件处理
 | 
			
		
	
		
			
				
					|  |  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |  |     public boolean onOptionsItemSelected(MenuItem item) { | 
			
		
	
		
			
				
					|  |  |  |  |         switch (item.getItemId()) { | 
			
		
	
		
			
				
					|  |  |  |  |             case android.R.id.home: | 
			
		
	
		
			
				
					|  |  |  |  |                 // 如果用户点击了返回按钮,启动NotesListActivity并清除当前活动栈中的其他活动
 | 
			
		
	
		
			
				
					|  |  |  |  |                 Intent intent = new Intent(this, NotesListActivity.class); | 
			
		
	
		
			
				
					|  |  |  |  |                 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | 
			
		
	
		
			
				
					|  |  |  |  |                 startActivity(intent); | 
			
		
	
		
			
				
					|  |  |  |  |                 return true; | 
			
		
	
		
			
				
					|  |  |  |  |             default: | 
			
		
	
		
			
				
					|  |  |  |  |                 // 对于其他选项,返回false表示不处理
 | 
			
		
	
		
			
				
					|  |  |  |  |                 return false; | 
			
		
	
		
			
				
					|  |  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  |  | } | 
			
		
	
		
			
				
					|  |  |  |  | } |