Compare commits

...

2 Commits

Author SHA1 Message Date
11111 1b798d3ba0 lrz commit
2 years ago
11111 b3e78ab3b7 123
2 years ago

@ -1,202 +1,296 @@
/* package net.micode.notes.ui;
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import net.micode.notes.data.Notes;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
private Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex;
private int mNotesCount;
private boolean mChoiceMode;
public static class AppWidgetAttribute {
public int widgetId;
public int widgetType;
};
public NotesListAdapter(Context context) {
super(context, null);
mSelectedIndex = new HashMap<Integer, Boolean>();
mContext = context;
mNotesCount = 0;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) {
NoteItemData itemData = new NoteItemData(context, cursor); import android.content.Context;
((NotesListItem) view).bind(context, itemData, mChoiceMode, import android.database.Cursor;
isSelectedItem(cursor.getPosition())); import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
}
}
public void setCheckedItem(final int position, final boolean checked) { import net.micode.notes.data.Notes;
mSelectedIndex.put(position, checked);
notifyDataSetChanged(); import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
} /**
* @Package: net.micode.notes.ui
* @ClassName: NotesListAdapter
public boolean isInChoiceMode() { * @Description:
return mChoiceMode; * 便CursorAdaptercursorListView
} * NotesListAdapter便
* @Author:
* @CreateDate: 12/23/2023 11:35 PM
public void setChoiceMode(boolean mode) { * @Version: 1.0
mSelectedIndex.clear(); */
mChoiceMode = mode; public class NotesListAdapter extends CursorAdapter {
} private static final String TAG = "NotesListAdapter";
private Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex;
public void selectAll(boolean checked) { private int mNotesCount; //便签数
Cursor cursor = getCursor(); private boolean mChoiceMode; //选择模式标记
for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) {
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
setCheckedItem(i, checked);
}
}
}
}
public HashSet<Long> getSelectedItemIds() { /*
HashSet<Long> itemSet = new HashSet<Long>(); * widget
*/
public static class AppWidgetAttribute {
public int widgetId;
public int widgetType;
};
/**
* @method NotesListAdapter
* @description
* 便
*
* @date: 12/23/2023 11:35 PM
*
* @param context
*/
public NotesListAdapter(Context context) {
super(context, null); //父类对象置空
mSelectedIndex = new HashMap<Integer, Boolean>(); //新建选项下标的hash表
mContext = context;
mNotesCount = 0;
}
for (Integer position : mSelectedIndex.keySet()) { @Override
if (mSelectedIndex.get(position) == true) { /**
Long id = getItemId(position); * @method newView
if (id == Notes.ID_ROOT_FOLDER) { * @description
Log.d(TAG, "Wrong item id, should not happen"); *
} else { * 使NotesListItem
itemSet.add(id); * @date: 12/23/2023 11:35 PM
} *
} * @param [context, cursor, parent]
} * @return android.view.View
*/
return itemSet; public View newView(Context context, Cursor cursor, ViewGroup parent) {
} return new NotesListItem(context);
}
@Override
/**
* @method bindView
* @description
* @date: 12/23/2023 11:41 PM
*
* @param [view, context, cursor]
* @return void
*/
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) {
//若view是NotesListItem的一个实例
//则新建一个项目选项并且用bind跟将view和鼠标内容便签数据捆绑在一起
NoteItemData itemData = new NoteItemData(context, cursor);
((NotesListItem) view).bind(context, itemData, mChoiceMode,
isSelectedItem(cursor.getPosition()));
}
}
/**
* @method setCheckedItem
* @description
* @date: 12/23/2023 11:41 PM
*
* @param checked
* @param position
* @return void
*/
public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked);
//根据定位和是否勾选设置下标
notifyDataSetChanged();
//在修改后刷新activity
}
public HashSet<AppWidgetAttribute> getSelectedWidget() { public boolean isInChoiceMode() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>(); return mChoiceMode;
for (Integer position : mSelectedIndex.keySet()) { }//判断单选按钮是否勾选
if (mSelectedIndex.get(position) == true) {
Cursor c = (Cursor) getItem(position);
if (c != null) {
AppWidgetAttribute widget = new AppWidgetAttribute();
NoteItemData item = new NoteItemData(mContext, c);
widget.widgetId = item.getWidgetId();
widget.widgetType = item.getWidgetType();
itemSet.add(widget);
} else {
Log.e(TAG, "Invalid cursor");
return null;
}
}
}
return itemSet;
}
public int getSelectedCount() { /**
Collection<Boolean> values = mSelectedIndex.values(); * @method setChoiceMode
if (null == values) { * @description
return 0; * @date: 12/23/2023 11:40 PM
} *
Iterator<Boolean> iter = values.iterator(); * @param
int count = 0; * @return
while (iter.hasNext()) { */
if (true == iter.next()) { public void setChoiceMode(boolean mode) {
count++; mSelectedIndex.clear();
} mChoiceMode = mode;
} }
return count;
}
public boolean isAllSelected() { /**
int checkedCount = getSelectedCount(); * @method selectAll
return (checkedCount != 0 && checkedCount == mNotesCount); * @description
} * @date: 12/23/2023 11:40 PM
*
* @param checked
*/
public void selectAll(boolean checked) {
Cursor cursor = getCursor();//获取光标位置
for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) {
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
setCheckedItem(i, checked);
}
}
}
//遍历所有光标可用的位置在判断为便签类型之后勾选单项框
}
/**
* @method getSelectedItemIds
* @description
* @date: 12/23/2023 11:39 PM
*
* @param
* @return
*/
public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>();//建立hash表
for (Integer position : mSelectedIndex.keySet()) {
//遍历所有的关键
if (mSelectedIndex.get(position) == true) {
//若光标位置可用
Long id = getItemId(position);
if (id == Notes.ID_ROOT_FOLDER) {
//原文件不需要添加
Log.d(TAG, "Wrong item id, should not happen");
} else {
itemSet.add(id);
}
}
}
public boolean isSelectedItem(final int position) { return itemSet;
if (null == mSelectedIndex.get(position)) { }
return false; /**
} * @method getSelectedWidget
return mSelectedIndex.get(position); * @description Widget
} * @date: 12/23/2023 11:39 PM
*
@Override * @param
* @return
*/
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
Cursor c = (Cursor) getItem(position);
//以上4句和getSelectedItemIds一样不再重复
if (c != null) {
//光标位置可用的话就建立新的Widget属性并编辑下标和类型最后添加到选项集中
AppWidgetAttribute widget = new AppWidgetAttribute();
NoteItemData item = new NoteItemData(mContext, c);
widget.widgetId = item.getWidgetId();
widget.widgetType = item.getWidgetType();
itemSet.add(widget);
/**
* Don't close cursor here, only the adapter could close it
*/
} else {
Log.e(TAG, "Invalid cursor");
return null;
}
}
}
return itemSet;
}
/**
* @method getSelectedCount
* @description
* @date: 12/23/2023 11:39 PM
*
*/
public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values();//首先获取选项下标的值
if (null == values) {
return 0;
}
Iterator<Boolean> iter = values.iterator();//初始化叠加器
int count = 0;
while (iter.hasNext()) {
if (true == iter.next()) {
count++;//若value值为真计数+1
}
}
return count;
}
protected void onContentChanged() { /**
super.onContentChanged(); * @method isAllSelected
* @description
* @date: 12/23/2023 11:38 PM
*
*/
public boolean isAllSelected() {
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);//获取选项数看是否等于便签的个数
}
/**
* @method isSelectedItem
* @description ,
* @date: 12/23/2023 11:38 PM
*
* @param
* @return
*/
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
return false;
}
return mSelectedIndex.get(position);
}
calcNotesCount(); @Override
} /**
* @method onContentChanged
@Override * @description activity便
public void changeCursor(Cursor cursor) { * @date: 12/23/2023 11:38 PM
super.changeCursor(cursor); *
calcNotesCount(); * @param []
} * @return void
*/
protected void onContentChanged() {
super.onContentChanged();
calcNotesCount();//执行基类函数
}
private void calcNotesCount() { @Override
mNotesCount = 0; /**
for (int i = 0; i < getCount(); i++) { * @method changeCursor
Cursor c = (Cursor) getItem(i); * @description activity便
if (c != null) { * @date: 12/23/2023 11:37 PM
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) { *
mNotesCount++; * @param [cursor]
} * @return void
} else { */
Log.e(TAG, "Invalid cursor"); public void changeCursor(Cursor cursor) {
return; super.changeCursor(cursor);
} calcNotesCount();//执行基类函数
} }
} /**
} * @method calcNotesCount
* @description 便
* @date: 12/23/2023 11:37 PM
*
* @param
* @return
*/
private void calcNotesCount() {
mNotesCount = 0;
for (int i = 0; i < getCount(); i++) {
//获取总数同时遍历
Cursor c = (Cursor) getItem(i);
if (c != null) {
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
mNotesCount++;//若该位置不为空并且文本类型为便签就+1
}
} else {
Log.e(TAG, "Invalid cursor");
return;
}
}
}
}

@ -1,131 +1,123 @@
/* package net.micode.notes.ui;
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.Context;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
public class NotesListItem extends LinearLayout {
private ImageView mAlert;
private TextView mTitle;
private TextView mTime;
private TextView mCallName;
private NoteItemData mItemData;
private CheckBox mCheckBox;
public NotesListItem(Context context) {
super(context);
inflate(context, R.layout.note_item, this);
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
mTitle = (TextView) findViewById(R.id.tv_title);
mTime = (TextView) findViewById(R.id.tv_time);
mCallName = (TextView) findViewById(R.id.tv_name);
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
}
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
mCheckBox.setVisibility(View.VISIBLE);
mCheckBox.setChecked(checked);
} else {
mCheckBox.setVisibility(View.GONE);
}
mItemData = data;
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { import android.content.Context;
mCallName.setVisibility(View.GONE); import android.text.format.DateUtils;
mAlert.setVisibility(View.VISIBLE); import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
mTitle.setText(context.getString(R.string.call_record_folder_name)
+ context.getString(R.string.format_folder_files_count, data.getNotesCount()));
mAlert.setImageResource(R.drawable.call_record);
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
mCallName.setVisibility(View.VISIBLE);
mCallName.setText(data.getCallName());
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
if (data.hasAlert()) { /**
mAlert.setImageResource(R.drawable.clock); * @Package: net.micode.notes.ui
mAlert.setVisibility(View.VISIBLE); * @ClassName: NotesListItem
} else { * @Description:
mAlert.setVisibility(View.GONE); * @Author:
} * @CreateDate: 12/23/2023 11:35 PM
} else { * @Version: 1.0
mCallName.setVisibility(View.GONE); */
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); public class NotesListItem extends LinearLayout {
private ImageView mAlert;//闹钟图片
if (data.getType() == Notes.TYPE_FOLDER) { private TextView mTitle; //标题
mTitle.setText(data.getSnippet() private TextView mTime; //时间
+ context.getString(R.string.format_folder_files_count, private TextView mCallName;
data.getNotesCount())); private NoteItemData mItemData; //标签数据
mAlert.setVisibility(View.GONE); private CheckBox mCheckBox; //打钩框
} else {
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
if (data.hasAlert()) {
mAlert.setImageResource(R.drawable.clock);
mAlert.setVisibility(View.VISIBLE);
} else {
mAlert.setVisibility(View.GONE);
}
}
}
mTime. setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
setBackground(data);
}
private void setBackground(NoteItemData data) {
int id = data.getBgColorId();
if (data.getType() == Notes.TYPE_NOTE) { /*初始化基本信息*/
public NotesListItem(Context context) {
super(context); //super()它的主要作用是调整调用父类构造函数的顺序
inflate(context, R.layout.note_item, this);//Inflate可用于将一个xml中定义的布局控件找出来,这里的xml是r。layout
//findViewById用于从contentView中查找指定ID的View转换出来的形式根据需要而定;
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
mTitle = (TextView) findViewById(R.id.tv_title);
mTime = (TextView) findViewById(R.id.tv_time);
mCallName = (TextView) findViewById(R.id.tv_name);
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
}
///根据data的属性对各个控件的属性的控制主要是可见性Visibility内容setText格式setTextAppearance
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
mCheckBox.setVisibility(View.VISIBLE); ///设置可见行为可见
mCheckBox.setChecked(checked); ///格子打钩
} else {
mCheckBox.setVisibility(View.GONE);
}
if (data.isSingle() || data.isOneFollowingFolder()) { mItemData = data;
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id)); ///设置控件属性一共三种情况由data的id和父id是否与保存到文件夹的id一致来决定
} else if (data.isLast()) { if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id)); mCallName.setVisibility(View.GONE);
} else if (data.isFirst() || data.isMultiFollowingFolder()) { mAlert.setVisibility(View.VISIBLE);
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id)); //设置该textview的style
} else { mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id)); //settext为设置内容
} mTitle.setText(context.getString(R.string.call_record_folder_name)
} else { + context.getString(R.string.format_folder_files_count, data.getNotesCount()));
mAlert.setImageResource(R.drawable.call_record);
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
mCallName.setVisibility(View.VISIBLE);
mCallName.setText(data.getCallName());
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
///关于闹钟的设置
if (data.hasAlert()) {
mAlert.setImageResource(R.drawable.clock);//图片来源的设置
mAlert.setVisibility(View.VISIBLE);
} else {
mAlert.setVisibility(View.GONE);
}
} else {
mCallName.setVisibility(View.GONE);
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);
///设置title格式
if (data.getType() == Notes.TYPE_FOLDER) {
mTitle.setText(data.getSnippet()
+ context.getString(R.string.format_folder_files_count,
data.getNotesCount()));
mAlert.setVisibility(View.GONE);
} else {
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
if (data.hasAlert()) {
mAlert.setImageResource(R.drawable.clock);///设置图片来源
mAlert.setVisibility(View.VISIBLE);
} else {
mAlert.setVisibility(View.GONE);
}
}
}
///设置内容获取相关时间从data里编辑的日期中获取
mTime. setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
setBackgroundResource(NoteItemBgResources.getFolderBgRes()); setBackground(data);
} }
} //根据data的文件属性来设置背景
public NoteItemData getItemData() { private void setBackground(NoteItemData data) {
return mItemData; int id = data.getBgColorId();
} //若是note型文件则4种情况对于4种不同情况的背景来源
} if (data.getType() == Notes.TYPE_NOTE) {
//单个数据并且只有一个子文件夹
if (data.isSingle() || data.isOneFollowingFolder()) {
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
} else if (data.isLast()) {//是最后一个数据
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
} else if (data.isFirst() || data.isMultiFollowingFolder()) {//是一个数据并有多个子文件夹
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
} else {
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
}
} else {
//若不是note直接调用文件夹的背景来源
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
}
}
public NoteItemData getItemData() {
return mItemData;
}
}

@ -1,422 +1,483 @@
/* package net.micode.notes.ui;
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* import android.accounts.Account;
* Licensed under the Apache License, Version 2.0 (the "License"); import android.accounts.AccountManager;
* you may not use this file except in compliance with the License. import android.app.ActionBar;
* You may obtain a copy of the License at import android.app.AlertDialog;
* import android.content.BroadcastReceiver;
* http://www.apache.org/licenses/LICENSE-2.0 import android.content.ContentValues;
* import android.content.Context;
* Unless required by applicable law or agreed to in writing, software import android.content.DialogInterface;
* distributed under the License is distributed on an "AS IS" BASIS, import android.content.Intent;
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import android.content.IntentFilter;
* See the License for the specific language governing permissions and import android.content.SharedPreferences;
* limitations under the License. import android.os.Bundle;
*/ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
package net.micode.notes.ui; import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.accounts.Account; import android.text.TextUtils;
import android.accounts.AccountManager; import android.text.format.DateFormat;
import android.app.ActionBar; import android.view.LayoutInflater;
import android.app.AlertDialog; import android.view.Menu;
import android.content.BroadcastReceiver; import android.view.MenuItem;
import android.content.ContentValues; import android.view.View;
import android.content.Context; import android.widget.Button;
import android.content.DialogInterface; import android.widget.TextView;
import android.content.Intent; import android.widget.Toast;
import android.content.IntentFilter;
import android.content.SharedPreferences; import net.micode.notes.R;
import android.os.Bundle; import net.micode.notes.data.Notes;
import android.preference.Preference; import net.micode.notes.data.Notes.NoteColumns;
import android.preference.Preference.OnPreferenceClickListener; import net.micode.notes.gtask.remote.GTaskSyncService;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.text.TextUtils; public class NotesPreferenceActivity extends PreferenceActivity {
import android.text.format.DateFormat; public static final String PREFERENCE_NAME = "notes_preferences";//优先名
import android.view.LayoutInflater; public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";//同步账号
import android.view.Menu; public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";//同步时间
import android.view.MenuItem; public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
import android.view.View; private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";//同步密码
import android.widget.Button; private static final String AUTHORITIES_FILTER_KEY = "authorities";
import android.widget.TextView; private PreferenceCategory mAccountCategory;//账户分组
import android.widget.Toast; private GTaskReceiver mReceiver;//同步任务接收器
private Account[] mOriAccounts;//账户
import net.micode.notes.R; private boolean mHasAddedAccount;//账户的hash标记
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns; @Override
import net.micode.notes.gtask.remote.GTaskSyncService; /**
* @method onCreate
* @description activity
public class NotesPreferenceActivity extends PreferenceActivity { * @date: 12/23/2023 11:43 PM
public static final String PREFERENCE_NAME = "notes_preferences"; * @author: YangYizhe
* @param [icicle]
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name"; * @return void
*/
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time"; protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear"; /* using the app icon for navigation */
getActionBar().setDisplayHomeAsUpEnabled(true);//给左上角图标的左边加上一个返回的图标
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key"; addPreferencesFromResource(R.xml.preferences);//添加xml来源并显示 xml
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);//根据同步账户关键码来初始化分组
private static final String AUTHORITIES_FILTER_KEY = "authorities"; mReceiver = new GTaskReceiver();
IntentFilter filter = new IntentFilter();
private PreferenceCategory mAccountCategory; filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
registerReceiver(mReceiver, filter);//初始化同步组件
private GTaskReceiver mReceiver; mOriAccounts = null;
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);//获取listvivewListView的作用:用于列出所有选择
private Account[] mOriAccounts; getListView().addHeaderView(header, null, true);//在listview组件上方添加其他组件
}
private boolean mHasAddedAccount;
@Override
/**
@Override * @method onResume
* @description activity
protected void onCreate(Bundle icicle) { * @date: 12/23/2023 11:44 PM
* @author: YangYizhe
super.onCreate(icicle); * @return void
*/
getActionBar().setDisplayHomeAsUpEnabled(true); protected void onResume() {
super.onResume();
addPreferencesFromResource(R.xml.preferences);
// need to set sync account automatically if user has added a new
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY); // account
mReceiver = new GTaskReceiver(); if (mHasAddedAccount) {
IntentFilter filter = new IntentFilter(); //若用户新加了账户则自动设置同步账户
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME); Account[] accounts = getGoogleAccounts();//获取google同步账户
registerReceiver(mReceiver, filter); if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
//若原账户不为空且当前账户有增加
mOriAccounts = null; for (Account accountNew : accounts) {
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null); boolean found = false;
getListView().addHeaderView(header, null, true); for (Account accountOld : mOriAccounts) {
} if (TextUtils.equals(accountOld.name, accountNew.name)) {
//更新账户
@Override found = true;
break;
protected void onResume() { }
}
super.onResume(); if (!found) {
setSyncAccount(accountNew.name);
if (mHasAddedAccount) { //若是没有找到旧的账户,那么同步账号中就只添加新账户
break;
Account[] accounts = getGoogleAccounts(); }
}
if (mOriAccounts != null && accounts.length > mOriAccounts.length) { }
for (Account accountNew : accounts) { }
boolean found = false;
for (Account accountOld : mOriAccounts) { refreshUI();//刷新标签界面
if (TextUtils.equals(accountOld.name, accountNew.name)) { }
found = true;
break; @Override
} protected void onDestroy() {
} if (mReceiver != null) {
if (!found) { unregisterReceiver(mReceiver);//注销接收器
setSyncAccount(accountNew.name); }
break; super.onDestroy();//执行父类的销毁动作
} }
}
} /**
} * @method loadAccountPreference
* @description
refreshUI(); * @date: 12/23/2023 11:45 PM
* @author: YangYizhe
} * @param
* @return
@Override */
private void loadAccountPreference() {
protected void onDestroy() { mAccountCategory.removeAll();//销毁所有的分组
if (mReceiver != null) { Preference accountPref = new Preference(this);//建立首选项
unregisterReceiver(mReceiver); final String defaultAccount = getSyncAccountName(this);
} accountPref.setTitle(getString(R.string.preferences_account_title));
super.onDestroy(); accountPref.setSummary(getString(R.string.preferences_account_summary));//设置首选项的大标题和小标题
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
} public boolean onPreferenceClick(Preference preference) {
//建立监听器
private void loadAccountPreference() { if (!GTaskSyncService.isSyncing()) {
mAccountCategory.removeAll(); if (TextUtils.isEmpty(defaultAccount)) {
// the first time to set account
Preference accountPref = new Preference(this); //若是第一次建立账户显示选择账户提示对话框
showSelectAccountAlertDialog();
final String defaultAccount = getSyncAccountName(this); } else {
accountPref.setTitle(getString(R.string.preferences_account_title)); // if the account has already been set, we need to promp
accountPref.setSummary(getString(R.string.preferences_account_summary)); // user about the risk
//若是已经建立则显示修改对话框并进行修改操作
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { showChangeAccountConfirmAlertDialog();
public boolean onPreferenceClick(Preference preference) { }
} else {
if (!GTaskSyncService.isSyncing()) { //若在没有同步的情况下则在toast中显示不能修改
if (TextUtils.isEmpty(defaultAccount)) { Toast.makeText(NotesPreferenceActivity.this,
showSelectAccountAlertDialog(); R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT)
} else { .show();
showChangeAccountConfirmAlertDialog(); }
} return true;
} else { }
Toast.makeText(NotesPreferenceActivity.this, });
R.string.preferences_toast_cannot_change_account, Toast.LENGTH_SHORT) mAccountCategory.addPreference(accountPref);//根据新建首选项编辑新的账户分组
.show(); }
} /**
return true; * @method loadSyncButton
} * @description
}); * @date: 12/23/2023 11:46 PM
* @author: YangYizhe
mAccountCategory.addPreference(accountPref); * @param
} * @return
*/
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);
if (GTaskSyncService.isSyncing()) { //获取同步按钮控件和最终同步时间的的窗口
// set button state
syncButton.setText(getString(R.string.preferences_button_sync_cancel)); //设置按钮的状态
syncButton.setOnClickListener(new View.OnClickListener() { if (GTaskSyncService.isSyncing()) {
public void onClick(View v) { //若是在同步状态下
GTaskSyncService.cancelSync(NotesPreferenceActivity.this); 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() { } else {
public void onClick(View v) { syncButton.setText(getString(R.string.preferences_button_sync_immediately));
GTaskSyncService.startSync(NotesPreferenceActivity.this); syncButton.setOnClickListener(new View.OnClickListener() {
} public void onClick(View v) {
}); GTaskSyncService.startSync(NotesPreferenceActivity.this);
}
} });//若是不同步则设置按钮显示的文本为“立即同步”以及对应监听器
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this))); }
syncButton.setEnabled(!TextUtils.isEmpty(getSyncAccountName(this)));//设置按键可用还是不可用
if (GTaskSyncService.isSyncing()) { // set last sync time
lastSyncTimeView.setText(GTaskSyncService.getProgressString()); // 设置最终同步时间
lastSyncTimeView.setVisibility(View.VISIBLE); if (GTaskSyncService.isSyncing()) {
//若是在同步的情况下
} else { lastSyncTimeView.setText(GTaskSyncService.getProgressString());
lastSyncTimeView.setVisibility(View.VISIBLE);
long lastSyncTime = getLastSyncTime(this); // 根据当前同步服务器设置时间显示框的文本以及可见性
if (lastSyncTime != 0) { } else {
lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time, //若是非同步情况
DateFormat.format(getString(R.string.preferences_last_sync_time_format), long lastSyncTime = getLastSyncTime(this);
lastSyncTime))); if (lastSyncTime != 0) {
lastSyncTimeView.setVisibility(View.VISIBLE); lastSyncTimeView.setText(getString(R.string.preferences_last_sync_time,
DateFormat.format(getString(R.string.preferences_last_sync_time_format),
} else { lastSyncTime)));
lastSyncTimeView.setVisibility(View.VISIBLE);
lastSyncTimeView.setVisibility(View.GONE); //则根据最后同步时间的信息来编辑时间显示框的文本内容和可见性
} } else {
} //若时间为空直接设置为不可见状态
} lastSyncTimeView.setVisibility(View.GONE);
}
private void refreshUI() { }
loadAccountPreference(); }
loadSyncButton(); /**
} * @method refreshUI
* @description
private void showSelectAccountAlertDialog() { *
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); *
* @date: 12/23/2023 11:46 PM
* @author: YangYizhe
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); */
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); private void refreshUI() {
titleTextView.setText(getString(R.string.preferences_dialog_select_account_title)); loadAccountPreference();
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle); loadSyncButton();
subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips)); }
/**
dialogBuilder.setCustomTitle(titleView); * @method showSelectAccountAlertDialog
dialogBuilder.setPositiveButton(null, null); * @description
* @date: 12/23/2023 11:47 PM
Account[] accounts = getGoogleAccounts(); * @author: YangYizhe
String defAccount = getSyncAccountName(this); * @param
* @return
mOriAccounts = accounts; */
mHasAddedAccount = false; private void showSelectAccountAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);//创建一个新的对话框
if (accounts.length > 0) {
CharSequence[] items = new CharSequence[accounts.length]; View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
final CharSequence[] itemMapping = items; TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
int checkedItem = -1; titleTextView.setText(getString(R.string.preferences_dialog_select_account_title));
int index = 0; TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle);
for (Account account : accounts) { subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));//设置标题以及子标题的内容
if (TextUtils.equals(account.name, defAccount)) { dialogBuilder.setCustomTitle(titleView);
checkedItem = index; dialogBuilder.setPositiveButton(null, null);//设置对话框的自定义标题建立一个YES的按钮
} Account[] accounts = getGoogleAccounts();
items[index++] = account.name; String defAccount = getSyncAccountName(this);//获取同步账户信息
} mOriAccounts = accounts;
dialogBuilder.setSingleChoiceItems(items, checkedItem, mHasAddedAccount = false;
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { if (accounts.length > 0) {
setSyncAccount(itemMapping[which].toString()); //若账户不为空
dialog.dismiss(); CharSequence[] items = new CharSequence[accounts.length];
refreshUI(); final CharSequence[] itemMapping = items;
} int checkedItem = -1;
}); int index = 0;
} for (Account account : accounts) {
if (TextUtils.equals(account.name, defAccount)) {
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null); checkedItem = index;//在账户列表中查询到所需账户
dialogBuilder.setView(addAccountView); }
items[index++] = account.name;
final AlertDialog dialog = dialogBuilder.show(); }
addAccountView.setOnClickListener(new View.OnClickListener() { dialogBuilder.setSingleChoiceItems(items, checkedItem,
public void onClick(View v) { //在对话框建立一个单选的复选框
mHasAddedAccount = true; new DialogInterface.OnClickListener() {
Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS"); public void onClick(DialogInterface dialog, int which) {
intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] { setSyncAccount(itemMapping[which].toString());
"gmail-ls" dialog.dismiss();//取消对话框
}); refreshUI();
startActivityForResult(intent, -1); }
});//建立对话框网络版的监听器
dialog.dismiss(); }
}
}); View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
dialogBuilder.setView(addAccountView);//给新加账户对话框设置自定义样式
}
final AlertDialog dialog = dialogBuilder.show();//显示对话框
private void showChangeAccountConfirmAlertDialog() { addAccountView.setOnClickListener(new View.OnClickListener() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); public void onClick(View v) {
mHasAddedAccount = true;
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null); //将新加账户的hash置true
TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title); Intent intent = new Intent("android.settings.ADD_ACCOUNT_SETTINGS");
titleTextView.setText(getString(R.string.preferences_dialog_change_account_title, //建立网络建立组件
getSyncAccountName(this))); intent.putExtra(AUTHORITIES_FILTER_KEY, new String[] {
TextView subtitleTextView = (TextView) titleView.findViewById(R.id.account_dialog_subtitle); "gmail-ls"
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg)); });
startActivityForResult(intent, -1);
dialogBuilder.setCustomTitle(titleView); //跳回上一个选项
dialog.dismiss();
CharSequence[] menuItemArray = new CharSequence[] { }
getString(R.string.preferences_menu_change_account), });//建立新加账户对话框的监听器
getString(R.string.preferences_menu_remove_account), }
getString(R.string.preferences_menu_cancel) /**
}; * @method showChangeAccountConfirmAlertDialog
* @description
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() { * @date: 12/23/2023 11:48 PM
public void onClick(DialogInterface dialog, int which) { * @author: YangYizhe
*/
if (which == 0) { private void showChangeAccountConfirmAlertDialog() {
showSelectAccountAlertDialog(); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);//创建一个新的对话框
} else if (which == 1) { View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
removeSyncAccount(); TextView titleTextView = (TextView) titleView.findViewById(R.id.account_dialog_title);
refreshUI(); 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.show(); dialogBuilder.setCustomTitle(titleView);//设置对话框的自定义标题
CharSequence[] menuItemArray = new CharSequence[] {
} getString(R.string.preferences_menu_change_account),
getString(R.string.preferences_menu_remove_account),
getString(R.string.preferences_menu_cancel)
private Account[] getGoogleAccounts() { };
AccountManager accountManager = AccountManager.get(this); dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
return accountManager.getAccountsByType("com.google"); //设置对话框要显示的一个list用于显示几个命令时,即changeremovecancel
} public void onClick(DialogInterface dialog, int which) {
//按键功能由which来决定
if (which == 0) {
private void setSyncAccount(String account) { //进入账户选择对话框
if (!getSyncAccountName(this).equals(account)) { showSelectAccountAlertDialog();
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); } else if (which == 1) {
SharedPreferences.Editor editor = settings.edit(); //删除账户并且跟新便签界面
removeSyncAccount();
if (account != null) { refreshUI();
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account); }
} else { }
editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, ""); });
} dialogBuilder.show();//显示对话框
}
editor.commit(); /**
* @method getGoogleAccounts
setLastSyncTime(this, 0); * @description
*
new Thread(new Runnable() { *
public void run() { * @date: 12/23/2023 11:49 PM
ContentValues values = new ContentValues(); * @author: YangYizhe
values.put(NoteColumns.GTASK_ID, ""); */
values.put(NoteColumns.SYNC_ID, 0); private Account[] getGoogleAccounts() {
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null); AccountManager accountManager = AccountManager.get(this);
} return accountManager.getAccountsByType("com.google");
}).start(); }
/**
Toast.makeText(NotesPreferenceActivity.this, * @method setSyncAccount
getString(R.string.preferences_toast_success_set_accout, account), * @description
Toast.LENGTH_SHORT).show(); * @date: 12/23/2023 11:49 PM
* @author: YangYizhe
} * @param account
} */
private void setSyncAccount(String account) {
private void removeSyncAccount() { if (!getSyncAccountName(this).equals(account)) {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE); //假如该账号不在同步账号列表中
SharedPreferences.Editor editor = settings.edit(); SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();//编辑共享的首选项
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) { if (account != null) {
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME); editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, account);
} } else {
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) { editor.putString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
editor.remove(PREFERENCE_LAST_SYNC_TIME); }//将该账号加入到首选项中
}
editor.commit(); editor.commit();//提交修改的数据
setLastSyncTime(this, 0);//将最后同步时间清零
// clean up local gtask related info
new Thread(new Runnable() { new Thread(new Runnable() {
public void run() { public void run() {
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(NoteColumns.GTASK_ID, ""); values.put(NoteColumns.GTASK_ID, "");
values.put(NoteColumns.SYNC_ID, 0); values.put(NoteColumns.SYNC_ID, 0);
getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null); getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
} }
}).start(); }).start();
//重置当地同步任务的信息
}
Toast.makeText(NotesPreferenceActivity.this,
getString(R.string.preferences_toast_success_set_accout, account),
public static String getSyncAccountName(Context context) { Toast.LENGTH_SHORT).show();
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, //将toast的文本信息置为“设置账户成功”并显示出来
Context.MODE_PRIVATE); }
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, ""); }
} /**
* @method removeSyncAccount
* @description
public static void setLastSyncTime(Context context, long time) { * @date: 12/23/2023 11:49 PM
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, * @author: YangYizhe
Context.MODE_PRIVATE); */
SharedPreferences.Editor editor = settings.edit(); private void removeSyncAccount() {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time); SharedPreferences.Editor editor = settings.edit();//设置共享首选项
editor.commit();
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
} editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);//假如当前首选项中有账户就删除
}
public static long getLastSyncTime(Context context) { if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME, editor.remove(PREFERENCE_LAST_SYNC_TIME);//删除当前首选项中有账户时间
Context.MODE_PRIVATE); }
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0); editor.commit();//提交更新后的数据
}
// clean up local gtask related info
new Thread(new Runnable() {
private class GTaskReceiver extends BroadcastReceiver { public void run() {
ContentValues values = new ContentValues();
@Override values.put(NoteColumns.GTASK_ID, "");
public void onReceive(Context context, Intent intent) { values.put(NoteColumns.SYNC_ID, 0);
refreshUI(); getContentResolver().update(Notes.CONTENT_NOTE_URI, values, null, null);
if (intent.getBooleanExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_IS_SYNCING, false)) { }
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview); }).start();
syncStatus.setText(intent //重置当地同步任务的信息
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG)); }
} /**
* @method getSyncAccountName
} * @description
} *
*
* @date: 12/23/2023 11:50 PM
public boolean onOptionsItemSelected(MenuItem item) { * @author: YangYizhe
switch (item.getItemId()) { * @param context
case android.R.id.home: */
Intent intent = new Intent(this, NotesListActivity.class); public static String getSyncAccountName(Context context) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
startActivity(intent); Context.MODE_PRIVATE);
return true; return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
default: }
return false; /**
} * @method setLastSyncTime
} * @description
} * @date: 12/23/2023 11:50 PM
* @author: YangYizhe
* @param
* @return
*/
public static void setLastSyncTime(Context context, long time) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();// 从共享首选项中找到相关账户并获取其编辑器
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
editor.commit();//编辑最终同步时间并提交更新
}
/**
* @method getLastSyncTime
* @description
*
*
* @date: 12/23/2023 11:51 PM
* @author: YangYizhe
* @param context
*/
public static long getLastSyncTime(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
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)) {
//获取随广播而来的Intent中的同步服务的数据
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
syncStatus.setText(intent
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));//通过获取的数据在设置系统的状态
}
}
}
/**
* @method onOptionsItemSelected
* @description
* @date: 12/23/2023 11:52 PM
* @author: YangYizhe
* @param item
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
//根据选项的id选择这里只有一个主页
case android.R.id.home:
Intent intent = new Intent(this, NotesListActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
//在主页情况下在创建连接组件intent发出清空的信号并开始一个相应的activity
default:
return false;
}
}
}
Loading…
Cancel
Save