添加了关于ui的注释

pull/7/head
eazzy 11 months ago
parent 654bc37c15
commit 0d18ff8129

@ -22,26 +22,21 @@ import net.micode.notes.data.Notes.NoteColumns;
* @Version: 1.0
*/
public class AlarmInitReceiver extends BroadcastReceiver {
private static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE
};
//对数据库的操作调用标签ID和闹钟时间
};//对数据库的操作调用标签ID和闹钟时间
private static final int COLUMN_ID = 0;
private static final int COLUMN_ALERTED_DATE = 1;
@Override
public void onReceive(Context context, Intent intent) {
long currentDate = System.currentTimeMillis();
//System.currentTimeMillis()产生一个当前的毫秒
//这个毫秒其实就是自1970年1月1日0时起的毫秒数
long currentDate = System.currentTimeMillis();//System.currentTimeMillis()产生一个当前的毫秒
Cursor c = context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.ALERTED_DATE + ">? AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE,
new String[] { String.valueOf(currentDate) },
//将long变量currentDate转化为字符串
null);
null);//将long变量currentDate转化为字符串
//Cursor在这里的作用是通过查找数据库中的标签内容找到和当前系统时间相等的标签
if (c != null) {

@ -6,7 +6,7 @@ import android.content.Intent;
/**
* @Package: net.micode.notes.ui
* @ClassName: AlarmReceiver
* @Description:
* @Description: 广AlarmAlertActivity
* @Author: YangYizhe
* @CreateDate: 12/17/2023 10:02 AM
* @UpdateUser: none
@ -17,14 +17,9 @@ import android.content.Intent;
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
intent.setClass(context, AlarmAlertActivity.class);
//启动AlarmAlertActivity
intent.setClass(context, AlarmAlertActivity.class);//启动AlarmAlertActivity
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//activity要存在于activity的栈中而非activity的途径启动activity时必然不存在一个activity的栈
//所以要新起一个栈装入启动的activity
context.startActivity(intent);
context.startActivity(intent);//启动闹钟提醒界面
}
}
//这是实现alarm这个功能最接近用户层的包基于上面的两个包
//作用还需要深究但是对于setClass和addFlags的

@ -51,8 +51,7 @@ public class DateTimePicker extends FrameLayout {
private final NumberPicker mHourSpinner;
private final NumberPicker mMinuteSpinner;
private final NumberPicker mAmPmSpinner;
//定义了Calendar类型的变量mDate用于操作时间
private Calendar mDate;
private Calendar mDate;//定义了Calendar类型的变量mDate用于操作时间
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
private boolean mIsAm;
@ -180,25 +179,24 @@ public class DateTimePicker extends FrameLayout {
*
*/
public DateTimePicker(Context context) {
//通过对数据库的访问,获取当前的系统时间
this(context, System.currentTimeMillis());
this(context, System.currentTimeMillis());//通过对数据库的访问,获取当前的系统时间
}
public DateTimePicker(Context context, long date) {
//上面函数的得到的是一个天文数字1970至今的秒数需要DateFormat将其变得有意义
this(context, date, DateFormat.is24HourFormat(context));
this(context, date, DateFormat.is24HourFormat(context));//上面函数的得到的是一个天文数字1970至今的秒数需要DateFormat将其变得有意义
}
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
//获取系统时间
mDate = Calendar.getInstance();
mDate = Calendar.getInstance();//获取系统时间
mInitialising = true;
mIsAm = getCurrentHourOfDay() >= HOURS_IN_HALF_DAY;
inflate(context, R.layout.datetime_picker, this);
//如果当前Activity里用到别的layout比如对话框layout
//还要设置这个layout上的其他组件的内容就必须用inflate()方法先将对话框的layout找出来
//然后再用findViewById()找到它上面的其它组件
/*
* Activitylayoutlayout
* layoutinflate()layout
* findViewById()
*/
mDateSpinner = (NumberPicker) findViewById(R.id.date);
mDateSpinner.setMinValue(DATE_SPINNER_MIN_VAL);
mDateSpinner.setMaxValue(DATE_SPINNER_MAX_VAL);

@ -832,8 +832,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
* @description: 便
* @date: 2023/12/21 1:16
* @author: WUSHUXIAN
* @param
* @return
*/
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

@ -15,10 +15,15 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
/*
* 便CursorAdaptercursorListView
* NotesListAdapter便
/**
* @Package: net.micode.notes.ui
* @ClassName: NotesListAdapter
* @Description:
* 便CursorAdaptercursorListView
* NotesListAdapter便
* @Author: YangYizhe
* @CreateDate: 12/23/2023 11:35 PM
* @Version: 1.0
*/
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
@ -34,10 +39,14 @@ public class NotesListAdapter extends CursorAdapter {
public int widgetId;
public int widgetType;
};
/*
* 便
/**
* @method NotesListAdapter
* @description
* 便
*
* @date: 12/23/2023 11:35 PM
* @author: YangYizhe
* @param context
*/
public NotesListAdapter(Context context) {
super(context, null); //父类对象置空
@ -47,32 +56,45 @@ public class NotesListAdapter extends CursorAdapter {
}
@Override
/*
*
* 使NotesListItem
/**
* @method newView
* @description
*
* 使NotesListItem
* @date: 12/23/2023 11:35 PM
* @author: YangYizhe
* @param [context, cursor, parent]
* @return android.view.View
*/
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
/*
*
*
*/
@Override
/**
* @method bindView
* @description
* @date: 12/23/2023 11:41 PM
* @author: YangYizhe
* @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()));
//则新建一个项目选项并且用bind跟将view和鼠标内容便签数据捆绑在一起
}
}
/*
*
*
/**
* @method setCheckedItem
* @description
* @date: 12/23/2023 11:41 PM
* @author: YangYizhe
* @param checked
* @param position
* @return void
*/
public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked);
@ -81,29 +103,32 @@ public class NotesListAdapter extends CursorAdapter {
//在修改后刷新activity
}
/*
*
*/
public boolean isInChoiceMode() {
return mChoiceMode;
}
}//判断单选按钮是否勾选
/*
*
* mode
/**
* @method setChoiceMode
* @description
* @date: 12/23/2023 11:40 PM
* @author: YangYizhe
* @param
* @return
*/
public void setChoiceMode(boolean mode) {
mSelectedIndex.clear();
mChoiceMode = mode;
}
/*
*
*
/**
* @method selectAll
* @description
* @date: 12/23/2023 11:40 PM
* @author: YangYizhe
* @param checked
*/
public void selectAll(boolean checked) {
Cursor cursor = getCursor();
//获取光标位置
Cursor cursor = getCursor();//获取光标位置
for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) {
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
@ -113,14 +138,16 @@ public class NotesListAdapter extends CursorAdapter {
}
//遍历所有光标可用的位置在判断为便签类型之后勾选单项框
}
/*
*
*
/**
* @method getSelectedItemIds
* @description
* @date: 12/23/2023 11:39 PM
* @author: YangYizhe
* @param
* @return
*/
public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>();
//建立hash表
HashSet<Long> itemSet = new HashSet<Long>();//建立hash表
for (Integer position : mSelectedIndex.keySet()) {
//遍历所有的关键
if (mSelectedIndex.get(position) == true) {
@ -132,17 +159,18 @@ public class NotesListAdapter extends CursorAdapter {
} else {
itemSet.add(id);
}
//则将id该下标假如选项集合中
}
}
return itemSet;
}
/*
* Widget
*
/**
* @method getSelectedWidget
* @description Widget
* @date: 12/23/2023 11:39 PM
* @author: YangYizhe
* @param
* @return
*/
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
@ -169,41 +197,44 @@ public class NotesListAdapter extends CursorAdapter {
return itemSet;
}
/*
*
*
/**
* @method getSelectedCount
* @description
* @date: 12/23/2023 11:39 PM
* @author: YangYizhe
*/
public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values();
//首先获取选项下标的值
Collection<Boolean> values = mSelectedIndex.values();//首先获取选项下标的值
if (null == values) {
return 0;
}
Iterator<Boolean> iter = values.iterator();
//初始化叠加器
Iterator<Boolean> iter = values.iterator();//初始化叠加器
int count = 0;
while (iter.hasNext()) {
if (true == iter.next()) {
//若value值为真计数+1
count++;
count++;//若value值为真计数+1
}
}
return count;
}
/*
*
*
/**
* @method isAllSelected
* @description
* @date: 12/23/2023 11:38 PM
* @author: YangYizhe
*/
public boolean isAllSelected() {
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);
//获取选项数看是否等于便签的个数
return (checkedCount != 0 && checkedCount == mNotesCount);//获取选项数看是否等于便签的个数
}
/*
*
*
/**
* @method isSelectedItem
* @description ,
* @date: 12/23/2023 11:38 PM
* @author: YangYizhe
* @param
* @return
*/
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
@ -213,29 +244,39 @@ public class NotesListAdapter extends CursorAdapter {
}
@Override
/*
* activity便
*
/**
* @method onContentChanged
* @description activity便
* @date: 12/23/2023 11:38 PM
* @author: YangYizhe
* @param []
* @return void
*/
protected void onContentChanged() {
super.onContentChanged();
//执行基类函数
calcNotesCount();
calcNotesCount();//执行基类函数
}
@Override
/*
* activity便
/**
* @method changeCursor
* @description activity便
* @date: 12/23/2023 11:37 PM
* @author: YangYizhe
* @param [cursor]
* @return void
*/
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
//执行基类函数
calcNotesCount();
calcNotesCount();//执行基类函数
}
/*
* 便
*
/**
* @method calcNotesCount
* @description 便
* @date: 12/23/2023 11:37 PM
* @author: YangYizhe
* @param
* @return
*/
private void calcNotesCount() {
mNotesCount = 0;
@ -244,14 +285,12 @@ public class NotesListAdapter extends CursorAdapter {
Cursor c = (Cursor) getItem(i);
if (c != null) {
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
mNotesCount++;
//若该位置不为空并且文本类型为便签就+1
mNotesCount++;//若该位置不为空并且文本类型为便签就+1
}
} else {
Log.e(TAG, "Invalid cursor");
return;
}
//否则报错
}
}
}

@ -14,7 +14,14 @@ import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
//创建便签列表项目选项
/**
* @Package: net.micode.notes.ui
* @ClassName: NotesListItem
* @Description:
* @Author: YangYizhe
* @CreateDate: 12/23/2023 11:35 PM
* @Version: 1.0
*/
public class NotesListItem extends LinearLayout {
private ImageView mAlert;//闹钟图片
private TextView mTitle; //标题

@ -31,78 +31,68 @@ import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
/*
*NotesPreferenceActivity便
* PreferenceActivityActivity
/**
* @Package: net.micode.notes.ui
* @ClassName: NotesPreferenceActivity
* @Description:
* NotesPreferenceActivity便
* PreferenceActivityActivity
* @Author: YangYizhe
* @CreateDate: 12/23/2023 11:42 PM
* @Version: 1.0
*/
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 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 PreferenceCategory mAccountCategory;//账户分组
private GTaskReceiver mReceiver;//同步任务接收器
private Account[] mOriAccounts;//账户
private boolean mHasAddedAccount;//账户的hash标记
@Override
/*
*activity
*Bundle icicle activity
*
/**
* @method onCreate
* @description activity
* @date: 12/23/2023 11:43 PM
* @author: YangYizhe
* @param [icicle]
* @return void
*/
protected void onCreate(Bundle icicle) {
//先执行父类的创建函数
super.onCreate(icicle);
/* using the app icon for navigation */
getActionBar().setDisplayHomeAsUpEnabled(true);
//给左上角图标的左边加上一个返回的图标
addPreferencesFromResource(R.xml.preferences);
//添加xml来源并显示 xml
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);
//根据同步账户关键码来初始化分组
getActionBar().setDisplayHomeAsUpEnabled(true);//给左上角图标的左边加上一个返回的图标
addPreferencesFromResource(R.xml.preferences);//添加xml来源并显示 xml
mAccountCategory = (PreferenceCategory) findPreference(PREFERENCE_SYNC_ACCOUNT_KEY);//根据同步账户关键码来初始化分组
mReceiver = new GTaskReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(GTaskSyncService.GTASK_SERVICE_BROADCAST_NAME);
registerReceiver(mReceiver, filter);
//初始化同步组件
registerReceiver(mReceiver, filter);//初始化同步组件
mOriAccounts = null;
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);
//获取listvivewListView的作用:用于列出所有选择
getListView().addHeaderView(header, null, true);
//在listview组件上方添加其他组件
View header = LayoutInflater.from(this).inflate(R.layout.settings_header, null);//获取listvivewListView的作用:用于列出所有选择
getListView().addHeaderView(header, null, true);//在listview组件上方添加其他组件
}
@Override
/*
* activity
*
/**
* @method onResume
* @description activity
* @date: 12/23/2023 11:44 PM
* @author: YangYizhe
* @return void
*/
protected void onResume() {
//先执行父类 的交互实现
super.onResume();
// need to set sync account automatically if user has added a new
// account
if (mHasAddedAccount) {
//若用户新加了账户则自动设置同步账户
Account[] accounts = getGoogleAccounts();
//获取google同步账户
Account[] accounts = getGoogleAccounts();//获取google同步账户
if (mOriAccounts != null && accounts.length > mOriAccounts.length) {
//若原账户不为空且当前账户有增加
for (Account accountNew : accounts) {
@ -123,37 +113,31 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
refreshUI();
//刷新标签界面
refreshUI();//刷新标签界面
}
@Override
/*
* activity
*
*/
protected void onDestroy() {
if (mReceiver != null) {
unregisterReceiver(mReceiver);
//注销接收器
unregisterReceiver(mReceiver);//注销接收器
}
super.onDestroy();
//执行父类的销毁动作
super.onDestroy();//执行父类的销毁动作
}
/*
*
*
/**
* @method loadAccountPreference
* @description
* @date: 12/23/2023 11:45 PM
* @author: YangYizhe
* @param
* @return
*/
private void loadAccountPreference() {
mAccountCategory.removeAll();
//销毁所有的分组
Preference accountPref = new Preference(this);
//建立首选项
mAccountCategory.removeAll();//销毁所有的分组
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.setSummary(getString(R.string.preferences_account_summary));//设置首选项的大标题和小标题
accountPref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
//建立监听器
@ -177,14 +161,15 @@ public class NotesPreferenceActivity extends PreferenceActivity {
return true;
}
});
//根据新建首选项编辑新的账户分组
mAccountCategory.addPreference(accountPref);
mAccountCategory.addPreference(accountPref);//根据新建首选项编辑新的账户分组
}
/*
*
*
/**
* @method loadSyncButton
* @description
* @date: 12/23/2023 11:46 PM
* @author: YangYizhe
* @param
* @return
*/
private void loadSyncButton() {
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
@ -199,20 +184,16 @@ public class NotesPreferenceActivity extends PreferenceActivity {
public void onClick(View v) {
GTaskSyncService.cancelSync(NotesPreferenceActivity.this);
}
});
//设置按钮显示的文本为“取消同步”以及监听器
});//设置按钮显示的文本为“取消同步”以及监听器
} else {
syncButton.setText(getString(R.string.preferences_button_sync_immediately));
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)));//设置按键可用还是不可用
// set last sync time
// 设置最终同步时间
if (GTaskSyncService.isSyncing()) {
@ -235,35 +216,38 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
}
/*
*
*
/**
* @method refreshUI
* @description
*
*
* @date: 12/23/2023 11:46 PM
* @author: YangYizhe
*/
private void refreshUI() {
loadAccountPreference();
loadSyncButton();
}
/*
*
*
/**
* @method showSelectAccountAlertDialog
* @description
* @date: 12/23/2023 11:47 PM
* @author: YangYizhe
* @param
* @return
*/
private void showSelectAccountAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
//创建一个新的对话框
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);//创建一个新的对话框
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
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));
//设置标题以及子标题的内容
subtitleTextView.setText(getString(R.string.preferences_dialog_select_account_tips));//设置标题以及子标题的内容
dialogBuilder.setCustomTitle(titleView);
dialogBuilder.setPositiveButton(null, null);
//设置对话框的自定义标题建立一个YES的按钮
dialogBuilder.setPositiveButton(null, null);//设置对话框的自定义标题建立一个YES的按钮
Account[] accounts = getGoogleAccounts();
String defAccount = getSyncAccountName(this);
//获取同步账户信息
String defAccount = getSyncAccountName(this);//获取同步账户信息
mOriAccounts = accounts;
mHasAddedAccount = false;
@ -275,8 +259,7 @@ public class NotesPreferenceActivity extends PreferenceActivity {
int index = 0;
for (Account account : accounts) {
if (TextUtils.equals(account.name, defAccount)) {
checkedItem = index;
//在账户列表中查询到所需账户
checkedItem = index;//在账户列表中查询到所需账户
}
items[index++] = account.name;
}
@ -285,21 +268,16 @@ public class NotesPreferenceActivity extends PreferenceActivity {
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
setSyncAccount(itemMapping[which].toString());
dialog.dismiss();
//取消对话框
dialog.dismiss();//取消对话框
refreshUI();
}
//设置点击后执行的事件,包括检录新同步账户和刷新标签界面
});
//建立对话框网络版的监听器
});//建立对话框网络版的监听器
}
View addAccountView = LayoutInflater.from(this).inflate(R.layout.add_account_text, null);
dialogBuilder.setView(addAccountView);
//给新加账户对话框设置自定义样式
dialogBuilder.setView(addAccountView);//给新加账户对话框设置自定义样式
final AlertDialog dialog = dialogBuilder.show();
//显示对话框
final AlertDialog dialog = dialogBuilder.show();//显示对话框
addAccountView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mHasAddedAccount = true;
@ -313,32 +291,28 @@ public class NotesPreferenceActivity extends PreferenceActivity {
//跳回上一个选项
dialog.dismiss();
}
});
//建立新加账户对话框的监听器
});//建立新加账户对话框的监听器
}
/*
*
*
/**
* @method showChangeAccountConfirmAlertDialog
* @description
* @date: 12/23/2023 11:48 PM
* @author: YangYizhe
*/
private void showChangeAccountConfirmAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
//创建一个新的对话框
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);//创建一个新的对话框
View titleView = LayoutInflater.from(this).inflate(R.layout.account_dialog_title, null);
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);
//设置对话框的自定义标题
subtitleTextView.setText(getString(R.string.preferences_dialog_change_account_warn_msg));//根据同步修改的账户信息设置标题以及子标题的内容
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)
};
//定义一些标记字符串
dialogBuilder.setItems(menuItemArray, new DialogInterface.OnClickListener() {
//设置对话框要显示的一个list用于显示几个命令时,即changeremovecancel
public void onClick(DialogInterface dialog, int which) {
@ -353,42 +327,42 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
});
dialogBuilder.show();
//显示对话框
dialogBuilder.show();//显示对话框
}
/*
*
*
/**
* @method getGoogleAccounts
* @description
*
*
* @date: 12/23/2023 11:49 PM
* @author: YangYizhe
*/
private Account[] getGoogleAccounts() {
AccountManager accountManager = AccountManager.get(this);
return accountManager.getAccountsByType("com.google");
}
/*
*
*
/**
* @method setSyncAccount
* @description
* @date: 12/23/2023 11:49 PM
* @author: YangYizhe
* @param account
*/
private void setSyncAccount(String account) {
if (!getSyncAccountName(this).equals(account)) {
//假如该账号不在同步账号列表中
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
//编辑共享的首选项
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);
//将最后同步时间清零
editor.commit();//提交修改的数据
setLastSyncTime(this, 0);//将最后同步时间清零
// clean up local gtask related info
new Thread(new Runnable() {
@ -407,25 +381,23 @@ public class NotesPreferenceActivity extends PreferenceActivity {
//将toast的文本信息置为“设置账户成功”并显示出来
}
}
/*
*
*
/**
* @method removeSyncAccount
* @description
* @date: 12/23/2023 11:49 PM
* @author: YangYizhe
*/
private void removeSyncAccount() {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
//设置共享首选项
SharedPreferences.Editor editor = settings.edit();//设置共享首选项
if (settings.contains(PREFERENCE_SYNC_ACCOUNT_NAME)) {
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);
//假如当前首选项中有账户就删除
editor.remove(PREFERENCE_SYNC_ACCOUNT_NAME);//假如当前首选项中有账户就删除
}
if (settings.contains(PREFERENCE_LAST_SYNC_TIME)) {
editor.remove(PREFERENCE_LAST_SYNC_TIME);
//删除当前首选项中有账户时间
editor.remove(PREFERENCE_LAST_SYNC_TIME);//删除当前首选项中有账户时间
}
editor.commit();
//提交更新后的数据
editor.commit();//提交更新后的数据
// clean up local gtask related info
new Thread(new Runnable() {
@ -438,33 +410,43 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}).start();
//重置当地同步任务的信息
}
/*
*
*
/**
* @method getSyncAccountName
* @description
*
*
* @date: 12/23/2023 11:50 PM
* @author: YangYizhe
* @param context
*/
public static String getSyncAccountName(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
/*
*
*
/**
* @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();
// 从共享首选项中找到相关账户并获取其编辑器
SharedPreferences.Editor editor = settings.edit();// 从共享首选项中找到相关账户并获取其编辑器
editor.putLong(PREFERENCE_LAST_SYNC_TIME, time);
editor.commit();
//编辑最终同步时间并提交更新
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,
@ -472,10 +454,6 @@ public class NotesPreferenceActivity extends PreferenceActivity {
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
}
/*
*
* BroadcastReceiver
*/
private class GTaskReceiver extends BroadcastReceiver {
@Override
@ -485,17 +463,17 @@ public class NotesPreferenceActivity extends PreferenceActivity {
//获取随广播而来的Intent中的同步服务的数据
TextView syncStatus = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
syncStatus.setText(intent
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));
//通过获取的数据在设置系统的状态
.getStringExtra(GTaskSyncService.GTASK_SERVICE_BROADCAST_PROGRESS_MSG));//通过获取的数据在设置系统的状态
}
}
}
/*
*
*
* :MenuItem
/**
* @method onOptionsItemSelected
* @description
* @date: 12/23/2023 11:52 PM
* @author: YangYizhe
* @param item
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {

Loading…
Cancel
Save