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

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

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

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

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

@ -14,7 +14,14 @@ import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources; 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 { public class NotesListItem extends LinearLayout {
private ImageView mAlert;//闹钟图片 private ImageView mAlert;//闹钟图片
private TextView mTitle; //标题 private TextView mTitle; //标题

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

Loading…
Cancel
Save