pull/16/head
eazzy 11 months ago committed by SheYu
parent 0421d505d1
commit 0d297c98af

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -35,7 +35,8 @@
<application
android:icon="@drawable/icon_app"
android:label="@string/app_name" >
android:label="@string/app_name"
android:testOnly="true" >
<activity
android:name=".ui.NotesListActivity"
android:configChanges="keyboardHidden|orientation|screenSize"

@ -14,7 +14,7 @@
* limitations under the License.
*/
package net.micode.notes.data;
package net.micode.notes.data;//属于data这个包
import android.content.Context;
import android.database.Cursor;
@ -25,17 +25,27 @@ import android.util.Log;
import java.util.HashMap;
/**
* @Package: net.micode.notes.data
* @ClassName: Contact
* @Description:
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:26
* @Version: 1.0
* @Package: net.micode.notes.data
* @ClassName: Contact
* @Description:
* Contact
* HashMap
* getContact
*
* SQL
* 线线使
* @Author: YangYizhe
* @CreateDate: 12/17/2023 10:10 AM
* @Version: 1.0
*/
public class Contact {
/**
* ,
*/
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
private static final String TAG = "Contact";//设置日志TAG标签
//查询联系人的SQL筛选语句
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
@ -52,36 +62,35 @@ public class Contact {
* @return: String
*/
public static String getContact(Context context, String phoneNumber) {
//
if(sContactCache == null) {
if(sContactCache == null) {/*如果缓存为空,就新建一个*/
sContactCache = new HashMap<String, String>();
}
if(sContactCache.containsKey(phoneNumber)) {
if(sContactCache.containsKey(phoneNumber)) {/*如果缓存中已经有该电话号码对应的联系人名字,就直接返回*/
return sContactCache.get(phoneNumber);
}
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));//将电话号码转换为最小匹配模式,用于筛选
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
selection,
selection,//使用筛选条件
new String[] { phoneNumber },
null);
if (cursor != null && cursor.moveToFirst()) {
if (cursor != null && cursor.moveToFirst()) {//如果找到了符合条件的联系人
try {
String name = cursor.getString(0);
sContactCache.put(phoneNumber, name);
return name;
String name = cursor.getString(0);//获取联系人名字
sContactCache.put(phoneNumber, name);//将电话号码和联系人名字添加到缓存中
return name;//返回联系人名字
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, " Cursor get string error " + e.toString());
return null;
} finally {
cursor.close();
cursor.close();//关闭游标
}
} else {
} else {/*没找到*/
Log.d(TAG, "No contact matched with number:" + phoneNumber);
return null;
}

@ -15,17 +15,17 @@
*/
package net.micode.notes.model;
import android.content.ContentProviderOperation;//批量的更新、插入、删除数据
import android.content.ContentProviderResult;//操作的结果
import android.content.ContentUris;//用于添加和获取Uri后面的ID
import android.content.ContentValues;//一种用来存储基本数据类型数据的存储机制
import android.content.Context;//需要用该类来弄清楚调用者的实例
import android.content.OperationApplicationException;//操作应用程序容错
import android.net.Uri;//表示待操作的数据
import android.os.RemoteException;//远程容错
import android.util.Log;//输出日志,比如说出错、警告等
import net.micode.notes.data.Notes;//小米便签的数据库,
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.OperationApplicationException;
import android.net.Uri;
import android.os.RemoteException;
import android.util.Log;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
@ -33,17 +33,32 @@ import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
/**
* @Package: net.micode.notes.model
* @ClassName: Note
* @Description:
* @Author: YangYizhe
* @CreateDate: 12/17/2023 10:06 AM
* @UpdateUser: none
* @UpdateDate: 12/17/2023 10:06 AM
* @UpdateRemark: none
* @Version: 1.0
*/
public class Note {
private ContentValues mNoteDiffValues;//
private ContentValues mNoteDiffValues;
private NoteData mNoteData;
private static final String TAG = "Note";
/**
* Create a new note id for adding a new note to databases
* 便
* @method getNewNoteId
* @description ID
* @date: 12/20/2023 11:23 PM
* @author: YangYizhe
* @param folderId Id
* @return noteId Id
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// Create a new note in the database 在数据库中创建新的便签
// Create a new note in the database
// 在数据库中创建一个新的笔记
ContentValues values = new ContentValues();
long createdTime = System.currentTimeMillis();
values.put(NoteColumns.CREATED_DATE, createdTime);
@ -53,7 +68,6 @@ public class Note {
values.put(NoteColumns.PARENT_ID, folderId);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);
/*try-catch异常处理*/
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1));
@ -67,51 +81,94 @@ public class Note {
return noteId;
}
//定义两个变量用来存储便签的数据,一个是存储便签属性、一个是存储便签内容
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
/**
* @method setNoteValue
* @description
* @date: 12/20/2023 11:31 PM
* @author: YangYizhe
* @param key
* @param value
*/
public void setNoteValue(String key, String value) {
/*设置数据库表格的标签属性数据,设置便签属性*/
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
* @method setTextData
* @description
* @date: 12/20/2023 11:31 PM
* @author: YangYizhe
* @param key
* @param value
*/
public void setTextData(String key, String value) {
/*设置数据库表格的标签文本内容的数据*/
mNoteData.setTextData(key, value);
}
/**
* @method setTextDataId
* @description ID
* @date: 12/20/2023 11:33 PM
* @author: YangYizhe
* @param id
*/
public void setTextDataId(long id) {
/*设置文本ID*/
mNoteData.setTextDataId(id);
}
/**
* @method getTextDataId
* @description Id
* @date: 12/20/2023 11:34 PM
* @author: YangYizhe
* @return mTextDataId Id
*/
public long getTextDataId() {
/*获取文本ID*/
return mNoteData.mTextDataId;
}
/**
* @method setCallDataId
* @description ID
* @date: 12/20/2023 11:35 PM
* @author: YangYizhe
* @param id id
*/
public void setCallDataId(long id) {
/*设置电话ID*/
mNoteData.setCallDataId(id);
}
/**
* @method setCallData
* @description
* @date: 12/20/2023 11:36 PM
* @author: YangYizhe
* @param key
* @param value
*/
public void setCallData(String key, String value) {
/*获取电话*/
mNoteData.setCallData(key, value);
}
/**
* @method isLocalModified
* @description
* @date: 12/20/2023 11:38 PM
* @author: YangYizhe
* @return bool
*/
public boolean isLocalModified() {
/*判断是否本地修改*/
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
//同步便签在WorkingNote中用到
/**
* @method syncNote
* @description
* @date: 12/20/2023 11:42 PM
* @author: YangYizhe
* @param context
* @param noteId ID
* @return bool
*/
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
@ -142,7 +199,7 @@ public class Note {
return true;
}
private class NoteData {//定义一个基本的便签内容的数据类,主要包含文本数据和电话号码数据
private class NoteData {
private long mTextDataId;
private ContentValues mTextDataValues;

@ -31,7 +31,17 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
* @Package: net.micode.notes.model
* @ClassName: WorkingNote
* @Description:
*
* Note
* WorkingNote Note
* @Author: YangYizhe
* @CreateDate: 12/20/2023 11:48 PM
* @Version: 1.0
*/
public class WorkingNote {
// Note for the working note
private Note mNote;
@ -59,12 +69,12 @@ public class WorkingNote {
private static final String TAG = "WorkingNote";
private boolean mIsDeleted;
/**
*
*/
private NoteSettingChangedListener mNoteSettingStatusListener;
// 声明 DATA_PROJECTION字符串数组
public static final String[] DATA_PROJECTION = new String[] {//与便签数组对应
//每个便签的数据
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
@ -74,9 +84,7 @@ public class WorkingNote {
DataColumns.DATA4,
};
// 声明 NOTE_PROJECTION字符串数组
public static final String[] NOTE_PROJECTION = new String[] {//便签数组
//每个便签的成员
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,
@ -105,7 +113,15 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct 构造函数?
// New note construct
/**
* @method WorkingNote
* @description
* @date: 12/20/2023 11:54 PM
* @author: YangYizhe
* @param context
* @param folderId ID
*/
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
@ -117,8 +133,16 @@ public class WorkingNote {
mMode = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
// Existing note construct 构造函数?
/**
* @method WorkingNote
* @description
* @date: 12/20/2023 11:54 PM
* @author: YangYizhe
* @param context
* @param noteId ID
* @param folderId ID
*/
// Existing note construct
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
@ -127,8 +151,12 @@ public class WorkingNote {
mNote = new Note();
loadNote();
}
// 加载NoteData
/**
* @method loadNote
* @description
* @date: 12/20/2023 11:55 PM
* @author: YangYizhe
*/
private void loadNote() {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
@ -150,7 +178,12 @@ public class WorkingNote {
}
loadNoteData();
}
/**
* @method loadNoteData
* @description Data
* @date: 12/20/2023 11:55 PM
* @author: YangYizhe
*/
private void loadNoteData() {
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
@ -178,9 +211,18 @@ public class WorkingNote {
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
}
}
// 创建空的Note
// 传参context文件夹idwidget背景颜色
/**
* @method createEmptyNote
* @description
* @date: 12/20/2023 11:56 PM
* @author: YangYizhe
* @param context
* @param folderId ID
* @param widgetId ID
* @param widgetType
* @param defaultBgColorId ID
* @return note
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
@ -194,7 +236,6 @@ public class WorkingNote {
return new WorkingNote(context, id, 0);
}
// 保存Note
public synchronized boolean saveNote() {
if (isWorthSaving()) {
if (!existInDatabase()) {
@ -255,7 +296,6 @@ public class WorkingNote {
}
}
// 设定背景颜色
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
@ -351,8 +391,6 @@ public class WorkingNote {
return mWidgetType;
}
// 创建接口 NoteSettingChangedListener,便签更新监视
// 为NoteEditActivity提供接口
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed

@ -1,20 +1,4 @@
/*
* 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;//声明一个包
package net.micode.notes.ui;
import android.app.Activity;
import android.app.AlertDialog;
@ -38,34 +22,54 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.DataUtils;
import java.io.IOException;
/**
* @Package: net.micode.notes.ui
* @ClassName: AlarmAlertActivity
* @Description:
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:02 AM
* @Version: 1.0
*/
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
private long mNoteId;
private String mSnippet;
private long mNoteId; //文本在数据库存储中的ID号
private String mSnippet; //闹钟提示时出现的文本片段
private static final int SNIPPET_PREW_MAX_LEN = 60;
MediaPlayer mPlayer;
/**
* @method onCreate
* @description Activity
* @date: 12/21/2023 12:05 AM
* @author: YangYizhe
* @param savedInstanceState Activity Bundle
* @return null
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置界面显示——无标题
requestWindowFeature(Window.FEATURE_NO_TITLE);
final Window win = getWindow();
// 设置窗体属性——在锁屏时显示
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
if (!isScreenOn()) {
// 设置窗体属性——保持点亮、点亮屏幕、允许点亮时解锁
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
| WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
}
// 获取传递的 Intent
Intent intent = getIntent();
try {
// 从 Intent 中获取数据并处理——获取标签 ID
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));
// 根据 ID 从数据库中获取标签内容
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
// 判断标签片段是否达到符合长度
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
: mSnippet;
@ -76,21 +80,26 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
mPlayer = new MediaPlayer();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
// 显示对话框
showActionDialog();
// 播放闹钟提示音
playAlarmSound();
} else {
// 结束当前 Activity
finish();
}
}
private boolean isScreenOn() {
//判断屏幕是否锁屏,调用系统函数判断,最后返回值是布尔类型
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
private void playAlarmSound() {
//闹钟提示音激发
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
//调用系统的铃声管理URI得到闹钟提示音
int silentModeStreams = Settings.System.getInt(getContentResolver(),
Settings.System.MODE_RINGER_STREAMS_AFFECTED, 0);
@ -101,12 +110,19 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
try {
mPlayer.setDataSource(this, url);
//方法setDataSource(Context context, Uri uri)
//解释:无返回值,设置多媒体数据来源【根据 Uri】
mPlayer.prepare();
//准备同步
mPlayer.setLooping(true);
//设置是否循环播放
mPlayer.start();
//开始播放
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//e.printStackTrace()函数功能是抛出异常, 还将显示出更深的调用信息
//System.out.println(e),这个方法打印出异常,并且输出在哪里出现的异常
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -121,38 +137,59 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
private void showActionDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
/* AlertDialogProtected
* newAlertDialogAlertDialog
* AlertDialogAlertDialog.Buildercreate()
* dialogAlertDialog
*/
dialog.setTitle(R.string.app_name);
//为对话框设置标题
dialog.setMessage(mSnippet);
//为对话框设置内容
dialog.setPositiveButton(R.string.notealert_ok, this);
//给对话框添加"Yes"按钮
if (isScreenOn()) {
dialog.setNegativeButton(R.string.notealert_enter, this);
}
}//对话框添加"No"按钮
dialog.show().setOnDismissListener(this);
}
public void onClick(DialogInterface dialog, int which) {
switch (which) {
//用which来选择click后下一步的操作
case DialogInterface.BUTTON_NEGATIVE:
//这是取消操作
Intent intent = new Intent(this, NoteEditActivity.class);
//实现两个类间的数据传输
intent.setAction(Intent.ACTION_VIEW);
//设置动作属性
intent.putExtra(Intent.EXTRA_UID, mNoteId);
//实现key-value对
//EXTRA_UID为keymNoteId为键
startActivity(intent);
//开始动作
break;
default:
//这是确定操作
break;
}
}
public void onDismiss(DialogInterface dialog) {
//忽略
stopAlarmSound();
//停止闹钟声音
finish();
//完成该动作
}
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop();
//停止播放
mPlayer.release();
//释放MediaPlayer对象
mPlayer = null;
}
}
}
}

@ -11,7 +11,16 @@ import android.database.Cursor;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
* @Package: net.micode.notes.ui
* @ClassName: AlarmInitReceiver
* @Description:
* AlarmInitReceiver 广BroadcastReceiver
* 广 Android 广
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:09 AM
* @Version: 1.0
*/
public class AlarmInitReceiver extends BroadcastReceiver {
private static final String [] PROJECTION = new String [] {
@ -49,8 +58,5 @@ public class AlarmInitReceiver extends BroadcastReceiver {
}
c.close();
}
//然而通过网上查找资料发现,对于闹钟机制的启动,通常需要上面的几个步骤
//如新建Intent、PendingIntent以及AlarmManager等
//这里就是根据数据库里的闹钟时间创建一个闹钟机制
}
}

@ -3,7 +3,17 @@ package net.micode.notes.ui;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* @Package: net.micode.notes.ui
* @ClassName: AlarmReceiver
* @Description:
* @Author: YangYizhe
* @CreateDate: 12/17/2023 10:02 AM
* @UpdateUser: none
* @UpdateDate: 12/17/2023 10:02 AM
* @UpdateRemark: none
* @Version: 1.0
*/
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

@ -11,10 +11,22 @@ import android.text.format.DateFormat;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.NumberPicker;
/**
* @Package: net.micode.notes.ui
* @ClassName: DateTimePicker
* @Description: FrameLayout
* 便
*
* /
* 2412
* /
* OnDateTimeChangedListener
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:18 AM
* @Version: 1.0
*/
public class DateTimePicker extends FrameLayout {
//FrameLayout是布局模板之一
//所有的子元素全部在屏幕的右上方
private static final boolean DEFAULT_ENABLE_STATE = true;
private static final int HOURS_IN_HALF_DAY = 12;
@ -30,15 +42,17 @@ public class DateTimePicker extends FrameLayout {
private static final int MINUT_SPINNER_MAX_VAL = 59;
private static final int AMPM_SPINNER_MIN_VAL = 0;
private static final int AMPM_SPINNER_MAX_VAL = 1;
//初始化控件
/**
*
* NumberPicker
*
*/
private final NumberPicker mDateSpinner;
private final NumberPicker mHourSpinner;
private final NumberPicker mMinuteSpinner;
private final NumberPicker mAmPmSpinner;
//NumberPicker是数字选择器
//这里定义的四个变量全部是在设置闹钟时需要选择的变量(如日期、时、分、上午或者下午)
private Calendar mDate;
//定义了Calendar类型的变量mDate用于操作时间
private Calendar mDate;
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
private boolean mIsAm;
@ -59,7 +73,7 @@ public class DateTimePicker extends FrameLayout {
onDateTimeChanged();
}
};//OnValueChangeListener这是时间改变监听器这里主要是对日期的监听
//将现在日期的值传递给mDateupdateDateControl是同步操作
private NumberPicker.OnValueChangeListener mOnHourChangedListener = new NumberPicker.OnValueChangeListener() {
//这里是对 小时Hour 的监听
@ -162,14 +176,18 @@ public class DateTimePicker extends FrameLayout {
void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute);
}
/**
*
*/
public DateTimePicker(Context context) {
//通过对数据库的访问,获取当前的系统时间
this(context, System.currentTimeMillis());
}//通过对数据库的访问,获取当前的系统时间
}
public DateTimePicker(Context context, long date) {
//上面函数的得到的是一个天文数字1970至今的秒数需要DateFormat将其变得有意义
this(context, date, DateFormat.is24HourFormat(context));
}//上面函数的得到的是一个天文数字1970至今的秒数需要DateFormat将其变得有意义
}
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
@ -217,6 +235,18 @@ public class DateTimePicker extends FrameLayout {
mInitialising = false;
}
/**
* @method setEnabled
* @description
*
* enabled
*
* setEnabled
* /setEnabledenabled
* @date: 12/21/2023 12:27 AM
* @author: YangYizhe
* @param enabled
*/
@Override
public void setEnabled(boolean enabled) {
if (mIsEnabled == enabled) {
@ -229,9 +259,6 @@ public class DateTimePicker extends FrameLayout {
mAmPmSpinner.setEnabled(enabled);
mIsEnabled = enabled;
}
//存在疑问setEnabled的作用
//下面的代码通过原程序的注释已经比较清晰,另外可以通过函数名来判断
//下面的各函数主要是对上面代码引用到的各函数功能的实现
@Override
public boolean isEnabled() {
return mIsEnabled;
@ -256,7 +283,7 @@ public class DateTimePicker extends FrameLayout {
cal.setTimeInMillis(date);
setCurrentDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH),
cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE));
}//实现函数功能——设置当前的时间参数是date
}
/**
* Set the current date
@ -274,14 +301,13 @@ public class DateTimePicker extends FrameLayout {
setCurrentDay(dayOfMonth);
setCurrentHour(hourOfDay);
setCurrentMinute(minute);
}//实现函数功能——设置当前的时间,参数是各详细的变量
}
/**
* Get current year
*
* @return The current year
*/
//下面是得到year、month、day等值
public int getCurrentYear() {
return mDate.get(Calendar.YEAR);
}
@ -439,7 +465,10 @@ public class DateTimePicker extends FrameLayout {
setCurrentHour(hour);
updateAmPmControl();
}
/**
* /
*
*/
private void updateDateControl() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(mDate.getTimeInMillis());
@ -452,7 +481,7 @@ public class DateTimePicker extends FrameLayout {
mDateSpinner.setDisplayedValues(mDateDisplayValues);
mDateSpinner.setValue(DAYS_IN_ALL_WEEK / 2);
mDateSpinner.invalidate();
}// 对于星期几的算法
}
private void updateAmPmControl() {
if (mIs24HourView) {
@ -461,7 +490,7 @@ public class DateTimePicker extends FrameLayout {
int index = mIsAm ? Calendar.AM : Calendar.PM;
mAmPmSpinner.setValue(index);
mAmPmSpinner.setVisibility(View.VISIBLE);
}// 对于上下午操作的算法
}
}
private void updateHourControl() {
@ -471,7 +500,7 @@ public class DateTimePicker extends FrameLayout {
} else {
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW);
mHourSpinner.setMaxValue(HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW);
}// 对与小时的算法
}
}
/**

@ -12,29 +12,45 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
/**
* @Package: net.micode.notes.ui
* @ClassName: DateTimePickerDialog
* @Description:
* DateTimePickerDialog
* AlertDialogOnClickListener
* DateTimePicker
* OnDateTimeSetListener
* 24使
* onClick
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:32 AM
* @Version: 1.0
*/
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
private Calendar mDate = Calendar.getInstance();
//创建一个Calendar类型的变量 mDate方便时间的操作
private boolean mIs24HourView;
private OnDateTimeSetListener mOnDateTimeSetListener;
//声明一个时间日期滚动选择控件 mOnDateTimeSetListener
private DateTimePicker mDateTimePicker;
//DateTimePicker控件控件一般用于让用户可以从日期列表中选择单个值。
//运行时,单击控件边上的下拉箭头,会显示为两个部分:一个下拉列表,一个用于选择日期的
/**
*
*/
public interface OnDateTimeSetListener {
void OnDateTimeSet(AlertDialog dialog, long date);
}
/**
* DateTimePickerDialog
*
* @param context
* @param date
*/
public DateTimePickerDialog(Context context, long date) {
//对该界面对话框的实例化
super(context);
//对数据库的操作
mDateTimePicker = new DateTimePicker(context);
setView(mDateTimePicker);
//添加一个子视图
mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
public void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute) {
@ -43,45 +59,64 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
mDate.set(Calendar.MINUTE, minute);
//将视图中的各选项设置为系统当前时间
updateTitle(mDate.getTimeInMillis());
}
});
mDate.setTimeInMillis(date);
//得到系统时间
mDate.set(Calendar.SECOND, 0);
//将秒数设置为0
mDateTimePicker.setCurrentDate(mDate.getTimeInMillis());
setButton(context.getString(R.string.datetime_dialog_ok), this);
setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null);
//设置按钮
setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener) null);
set24HourView(DateFormat.is24HourFormat(this.getContext()));
//时间标准化打印
updateTitle(mDate.getTimeInMillis());
}
/**
* 24
*
* @param is24HourView 24truefalse
*/
public void set24HourView(boolean is24HourView) {
mIs24HourView = is24HourView;
}
/**
*
*
* @param callBack
*/
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
mOnDateTimeSetListener = callBack;
}//将时间日期滚动选择控件实例化
}
/**
* 使
*
* @param date
*/
private void updateTitle(long date) {
int flag =
DateUtils.FORMAT_SHOW_YEAR |
DateUtils.FORMAT_SHOW_DATE |
DateUtils.FORMAT_SHOW_TIME;
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_24HOUR;
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
}//android开发中常见日期管理工具类API——DateUtils按照上下午显示时间
}
/**
*
*
* @param arg0
* @param arg1
*/
public void onClick(DialogInterface arg0, int arg1) {
if (mOnDateTimeSetListener != null) {
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
}
}//第一个参数arg0是接收到点击事件的对话框
//第二个参数arg1是该对话框上的按钮
}
}

@ -10,7 +10,20 @@ import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R;
/**
* @Package: net.micode.notes.ui
* @ClassName: DropdownMenu
* @Description:
* DropdownMenu
* 使ButtonPopupMenu
* ButtonID
* setOnDropdownMenuItemClickListener
* findItem
* setTitle
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:36 AM
* @Version: 1.0
*/
public class DropdownMenu {
private Button mButton;
private PopupMenu mPopupMenu;
@ -36,7 +49,7 @@ public class DropdownMenu {
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
if (mPopupMenu != null) {
mPopupMenu.setOnMenuItemClickListener(listener);
}//设置菜单的监听
}
}
public MenuItem findItem(int id) {

@ -12,7 +12,19 @@ import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
* @Package: net.micode.notes.ui
* @ClassName: FoldersListAdapter
* @Description:
* FoldersListAdapter便
* CursorAdapter便
* PROJECTION
* newViewbindView
* getFolderName便
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:37 AM
* @Version: 1.0
*/
public class FoldersListAdapter extends CursorAdapter {
//CursorAdapter是Cursor和ListView的接口
//FoldersListAdapter继承了CursorAdapter的类

@ -55,9 +55,21 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @Package: net.micode.notes.ui
* @ClassName: NoteEditActivity
* @Description:
*
*
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:47 AM
* @Version: 1.0
*/
public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener {
/**
*
*/
private class HeadViewHolder {
public TextView tvModified;
@ -67,7 +79,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public ImageView ibSetBgColor;
}
//使用Map实现数据存储
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
static {
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
@ -75,7 +86,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sBgSelectorBtnsMap.put(R.id.iv_bg_blue, ResourceParser.BLUE);
sBgSelectorBtnsMap.put(R.id.iv_bg_green, ResourceParser.GREEN);
sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
//put函数是将指定值和指定键相连
}
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
@ -85,7 +95,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sBgSelectorSelectionMap.put(ResourceParser.BLUE, R.id.iv_bg_blue_select);
sBgSelectorSelectionMap.put(ResourceParser.GREEN, R.id.iv_bg_green_select);
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
//put函数是将指定值和指定键相连
}
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
@ -94,7 +103,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
sFontSizeBtnsMap.put(R.id.ll_font_normal, ResourceParser.TEXT_MEDIUM);
sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
//put函数是将指定值和指定键相连
}
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
@ -103,31 +111,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
sFontSelectorSelectionMap.put(ResourceParser.TEXT_MEDIUM, R.id.iv_medium_select);
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
//put函数是将指定值和指定键相连
}
private static final String TAG = "NoteEditActivity";
private HeadViewHolder mNoteHeaderHolder;
private View mHeadViewPanel;
//私有化一个界面操作mHeadViewPanel对表头的操作
private View mNoteBgColorSelector;
//私有化一个界面操作mNoteBgColorSelector对背景颜色的操作
private View mFontSizeSelector;
//私有化一个界面操作mFontSizeSelector对标签字体的操作
private EditText mNoteEditor;
//声明编辑控件,对文本操作
private View mNoteEditorPanel;
//私有化一个界面操作mNoteEditorPanel文本编辑的控制板
//private WorkingNote mWorkingNote;
public WorkingNote mWorkingNote;
//对模板WorkingNote的初始化
private SharedPreferences mSharedPrefs;
//私有化SharedPreferences的数据存储方式
//它的本质是基于XML文件存储key-value键值对数据
private int mFontSizeId;
//用于操作字体的大小
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
@ -136,15 +132,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
private LinearLayout mEditTextList;
//线性布局
private String mUserQuery;
private Pattern mPattern;
/**
* Activity
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.note_edit);
//对数据库的访问操作
if (savedInstanceState == null && !initActivityState(getIntent())) {
finish();
return;
@ -167,9 +164,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return;
}
Log.d(TAG, "Restoring from killed activity");
}//为防止内存不足时程序的终止,在这里有一个保存现场的函数
}
}
private boolean initActivityState(Intent intent) {
/**
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
@ -179,7 +177,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
mUserQuery = "";
//如果用户实例化标签时系统并未给出标签ID
/**
* Starting from the searched result
*/
@ -207,14 +204,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false;
}
}
//setSoftInputMode——软键盘输入模式
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
// intent.getAction()
// 大多用于broadcast发送广播时给机制intent设置一个action就是一个字符串
// 用户可以通过receive接受intent通过 getAction得到的字符串来决定做什么
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
@ -222,8 +215,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
Notes.TYPE_WIDGET_INVALIDE);
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
ResourceParser.getDefaultBgId(this));
// intent.getIntLong、StringExtra是对各变量的语法分析
// Parse call-record note
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
if (callDate != 0 && phoneNumber != null) {
@ -239,17 +230,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
finish();
return false;
}
//将电话号码与手机的号码簿相关
} else {
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
widgetType, bgResId);
mWorkingNote.convertToCallNote(phoneNumber, callDate);
//
}
} else {
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
bgResId);
}//创建一个新的WorkingNote
}
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
@ -263,17 +252,17 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
@Override
protected void onResume() {
super.onResume();
initNoteScreen();
}
private void initNoteScreen() {
//对界面的初始化操作
mNoteEditor.setTextAppearance(this, TextAppearanceResources
.getTexAppearanceResource(mFontSizeId));
//设置外观
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
switchToListMode(mWorkingNote.getContent());
} else {
@ -297,32 +286,31 @@ public class NoteEditActivity extends Activity implements OnClickListener,
*/
showAlertHeader();
}
//设置闹钟的显示
private void showAlertHeader() {
if (mWorkingNote.hasClockAlert()) {
long time = System.currentTimeMillis();
if (time > mWorkingNote.getAlertDate()) {
mNoteHeaderHolder.tvAlertDate.setText(R.string.note_alert_expired);
}
//如果系统时间大于了闹钟设置的时间,那么闹钟失效
else {
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
mNoteHeaderHolder.tvAlertDate.setText(DateUtils.getRelativeTimeSpanString(
mWorkingNote.getAlertDate(), time, DateUtils.MINUTE_IN_MILLIS));
}
mNoteHeaderHolder.tvAlertDate.setVisibility(View.VISIBLE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.VISIBLE);
//显示闹钟开启的图标
} else {
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
};
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
initActivityState(intent);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -334,29 +322,25 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (!mWorkingNote.existInDatabase()) {
saveNote();
}
//在创建一个新的标签时,先在数据库中匹配
//如果不存在,那么先在数据库中存储
outState.putLong(Intent.EXTRA_UID, mWorkingNote.getNoteId());
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
}
@Override
//MotionEvent是对屏幕触控的传递机制
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
&& !inRangeOfView(mNoteBgColorSelector, ev)) {
mNoteBgColorSelector.setVisibility(View.GONE);
return true;
}//颜色选择器在屏幕上可见
}
if (mFontSizeSelector.getVisibility() == View.VISIBLE
&& !inRangeOfView(mFontSizeSelector, ev)) {
mFontSizeSelector.setVisibility(View.GONE);
return true;
}//字体大小选择器在屏幕上可见
}
return super.dispatchTouchEvent(ev);
}
//对屏幕触控的坐标进行操作
private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2];
view.getLocationOnScreen(location);
@ -366,7 +350,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|| ev.getX() > (x + view.getWidth())
|| ev.getY() < y
|| ev.getY() > (y + view.getHeight()))
//如果触控的位置超出了给定的范围返回false
{
return false;
}
@ -387,13 +370,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
for (int id : sBgSelectorBtnsMap.keySet()) {
ImageView iv = (ImageView) findViewById(id);
iv.setOnClickListener(this);
}//对标签各项属性内容的初始化
}
mFontSizeSelector = findViewById(R.id.font_size_selector);
for (int id : sFontSizeBtnsMap.keySet()) {
View view = findViewById(id);
view.setOnClickListener(this);
};//对字体大小的选择
};
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
/**
@ -415,7 +398,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
clearSettingState();
}
//和桌面小工具的同步
private void updateWidget() {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
@ -435,13 +417,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
setResult(RESULT_OK, intent);
}
public void onClick(View v) {
int id = v.getId();
if (id == R.id.btn_set_bg_color) {
mNoteBgColorSelector.setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.VISIBLE);
} else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(View.GONE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.GONE);
mWorkingNote.setBgColorId(sBgSelectorBtnsMap.get(id));
mNoteBgColorSelector.setVisibility(View.GONE);
} else if (sFontSizeBtnsMap.containsKey(id)) {
@ -458,7 +443,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
mFontSizeSelector.setVisibility(View.GONE);
}
}//************************存在问题
}
@Override
public void onBackPressed() {
@ -480,16 +465,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
return false;
}
public void onBackgroundColorChanged() {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.VISIBLE);
mNoteEditorPanel.setBackgroundResource(mWorkingNote.getBgColorResId());
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
}
@Override
//对选择菜单的准备
public boolean onPrepareOptionsMenu(Menu menu) {
if (isFinishing()) {
return true;
@ -498,7 +480,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
menu.clear();
if (mWorkingNote.getFolderId() == Notes.ID_CALL_RECORD_FOLDER) {
getMenuInflater().inflate(R.menu.call_note_edit, menu);
// MenuInflater是用来实例化Menu目录下的Menu布局文件的
} else {
getMenuInflater().inflate(R.menu.note_edit, menu);
}
@ -514,226 +495,146 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
return true;
}
@Override
/*
*
*
*/
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();//根据菜单的id来编剧相关项目
if (itemId == R.id.menu_new_note) {//创建一个新的便签
int itemId = item.getItemId();
if (itemId == R.id.menu_new_note) {
createNewNote();
} else if (itemId == R.id.menu_delete) {//删除便签
}
else if (itemId == R.id.menu_delete) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//创建关于删除操作的对话框
builder.setTitle(getString(R.string.alert_title_delete));
// 设置标签的标题为alert_title_delete
builder.setIcon(android.R.drawable.ic_dialog_alert);
//设置对话框图标
builder.setMessage(getString(R.string.alert_message_delete_note));
//设置对话框内容
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
//建立按键监听器
public void onClick(DialogInterface dialog, int which) {
//点击所触发事件
deleteCurrentNote();
// 删除单签便签
finish();
}
});
//添加“YES”按钮
builder.setNegativeButton(android.R.string.cancel, null);
//添加“NO”的按钮
builder.show();
//显示对话框
} else if (itemId == R.id.menu_font_size) {//字体大小的编辑
} else if (itemId == R.id.menu_font_size) {
mFontSizeSelector.setVisibility(View.VISIBLE);
// 将字体选择器置为可见
findViewById(sFontSelectorSelectionMap.get(mFontSizeId)).setVisibility(View.VISIBLE);
// 通过id找到相应的大小
} else if (itemId == R.id.menu_list_mode) {//选择列表模式
} else if (itemId == R.id.menu_list_mode) {
mWorkingNote.setCheckListMode(mWorkingNote.getCheckListMode() == 0 ?
TextNote.MODE_CHECK_LIST : 0);
} else if (itemId == R.id.menu_share) {//菜单共享
} else if (itemId == R.id.menu_share) {
getWorkingText();
sendTo(this, mWorkingNote.getContent());
// 用sendto函数将运行文本发送到遍历的本文内
} else if (itemId == R.id.menu_send_to_desktop) {//发送到桌面
} else if (itemId == R.id.menu_send_to_desktop) {
sendToDesktop();
} else if (itemId == R.id.menu_alert) {//创建提醒器
} else if (itemId == R.id.menu_alert) {
setReminder();
} else if (itemId == R.id.menu_delete_remind) {//删除日期提醒
} else if (itemId == R.id.menu_delete_remind) {
mWorkingNote.setAlertDate(0, false);
}
return true;
}
/*
*
*
*/
private void setReminder() {
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
// 建立修改时间日期的对话框
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
public void OnDateTimeSet(AlertDialog dialog, long date) {
mWorkingNote.setAlertDate(date , true);
//选择提醒的日期
}
});
//建立时间日期的监听器
d.show();
//显示对话框
}
/**
* Share note to apps that support {@link Intent#ACTION_SEND} action
* and {@text/plain} type
*/
/*
* 便
*
*/
private void sendTo(Context context, String info) {
Intent intent = new Intent(Intent.ACTION_SEND);
//建立intent链接选项
intent.putExtra(Intent.EXTRA_TEXT, info);
//将需要传递的便签信息放入text文件中
intent.setType("text/plain");
//编辑连接器的类型
context.startActivity(intent);
//在acti中进行链接
}
/*
* 便
*
*/
private void createNewNote() {
// Firstly, save current editing notes
//保存当前便签
saveNote();
// For safety, start a new NoteEditActivity
finish();
Intent intent = new Intent(this, NoteEditActivity.class);
//设置链接器
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
//该活动定义为创建或编辑
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mWorkingNote.getFolderId());
//将运行便签的id添加到INTENT_EXTRA_FOLDER_ID标记中
startActivity(intent);
//开始activity并链接
}
/*
* 便
*
*/
private void deleteCurrentNote() {
if (mWorkingNote.existInDatabase()) {
//假如当前运行的便签内存有数据
HashSet<Long> ids = new HashSet<Long>();
long id = mWorkingNote.getNoteId();
if (id != Notes.ID_ROOT_FOLDER) {
ids.add(id);
//如果不是头文件夹建立一个hash表把便签id存起来
} else {
Log.d(TAG, "Wrong note id, should not happen");
//否则报错
}
if (!isSyncMode()) {
//在非同步模式情况下
//删除操作
if (!DataUtils.batchDeleteNotes(getContentResolver(), ids)) {
Log.e(TAG, "Delete Note error");
}
} else {
//同步模式
//移动至垃圾文件夹的操作
if (!DataUtils.batchMoveToFolder(getContentResolver(), ids, Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens");
}
}
}
mWorkingNote.markDeleted(true);
//将这些标签的删除标记置为true
}
/*
*
* NotesPreferenceActivity
*/
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
/*
*
*
*/
public void onClockAlertChanged(long date, boolean set) {
/**
* User could set clock to an unsaved note, so before setting the
* alert clock, we should save the note first
*/
if (!mWorkingNote.existInDatabase()) {
//首先保存已有的便签
saveNote();
}
if (mWorkingNote.getNoteId() > 0) {
Intent intent = new Intent(this, AlarmReceiver.class);
intent.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mWorkingNote.getNoteId()));
//若有有运行的便签就是建立一个链接器将标签id都存在uri中
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
//设置提醒管理器
showAlertHeader();
if(!set) {
alarmManager.cancel(pendingIntent);
} else {
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
}
//如果用户设置了时间,就通过提醒管理器设置一个监听事项
} else {
/**
* There is the condition that user has input nothing (the note is
* not worthy saving), we have no note id, remind the user that he
* should input something
*/
//没有运行的便签就报错
Log.e(TAG, "Clock alert setting error");
showToast(R.string.error_note_empty_for_clock);
}
}
/*
* Widget
*/
public void onWidgetChanged() {
updateWidget();//更新Widget
updateWidget();
}
/*
*
*
*/
public void onEditTextDelete(int index, String text) {
int childCount = mEditTextList.getChildCount();
if (childCount == 1) {
return;
}
//没有编辑框的话直接返回
for (int i = index + 1; i < childCount; i++) {
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
.setIndex(i - 1);
//通过id把编辑框存在便签编辑框中
}
mEditTextList.removeViewAt(index);
//删除特定位置的视图
NoteEditText edit = null;
if(index == 0) {
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
@ -742,101 +643,65 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit = (NoteEditText) mEditTextList.getChildAt(index - 1).findViewById(
R.id.et_edit_text);
}
//通过id把编辑框存在空的NoteEditText中
int length = edit.length();
edit.append(text);
edit.requestFocus();//请求优先完成该此 编辑
edit.setSelection(length);//定位到length位置处的条目
edit.requestFocus();
edit.setSelection(length);
}
/*
*
*
*/
public void onEditTextEnter(int index, String text) {
/**
* Should not happen, check for debug
*/
if(index > mEditTextList.getChildCount()) {
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
//越界把偶偶
}
View view = getListItem(text, index);
mEditTextList.addView(view, index);
//建立一个新的视图并添加到编辑文本框内
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
edit.requestFocus();//请求优先操作
edit.setSelection(0);//定位到起始位置
edit.requestFocus();
edit.setSelection(0);
for (int i = index + 1; i < mEditTextList.getChildCount(); i++) {
((NoteEditText) mEditTextList.getChildAt(i).findViewById(R.id.et_edit_text))
.setIndex(i);
//遍历子文本框并设置对应对下标
}
}
/*
*
*
*/
private void switchToListMode(String text) {
mEditTextList.removeAllViews();
String[] items = text.split("\n");
int index = 0;
//清空所有视图,初始化下标
for (String item : items) {
if(!TextUtils.isEmpty(item)) {
mEditTextList.addView(getListItem(item, index));
index++;
//遍历所有文本单元并添加到文本框中
}
}
mEditTextList.addView(getListItem("", index));
mEditTextList.getChildAt(index).findViewById(R.id.et_edit_text).requestFocus();
//优先请求此操作
mNoteEditor.setVisibility(View.GONE);
//便签编辑器不可见
mEditTextList.setVisibility(View.VISIBLE);
//将文本编辑框置为可见
}
/*
*
*
*/
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
//新建一个效果选项
if (!TextUtils.isEmpty(userQuery)) {
mPattern = Pattern.compile(userQuery);
//将用户的询问进行解析
Matcher m = mPattern.matcher(fullText);
//建立一个状态机检查Pattern并进行匹配
int start = 0;
while (m.find(start)) {
spannable.setSpan(
new BackgroundColorSpan(this.getResources().getColor(
R.color.user_query_highlight)), m.start(), m.end(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
//设置背景颜色
start = m.end();
//跟新起始位置
}
}
return spannable;
}
/*
*
*
*/
private View getListItem(String item, int index) {
View view = LayoutInflater.from(this).inflate(R.layout.note_edit_list_item, null);
//创建一个视图
final NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
edit.setTextAppearance(this, TextAppearanceResources.getTexAppearanceResource(mFontSizeId));
//创建一个文本编辑框并设置可见性
CheckBox cb = ((CheckBox) view.findViewById(R.id.cb_edit_item));
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -847,15 +712,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
});
//建立一个打钩框并设置监听器
if (item.startsWith(TAG_CHECKED)) {
//选择勾选
cb.setChecked(true);
edit.setPaintFlags(edit.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
item = item.substring(TAG_CHECKED.length(), item.length()).trim();
} else if (item.startsWith(TAG_UNCHECKED)) {
//选择不勾选
cb.setChecked(false);
edit.setPaintFlags(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
item = item.substring(TAG_UNCHECKED.length(), item.length()).trim();
@ -864,32 +726,20 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit.setOnTextViewChangeListener(this);
edit.setIndex(index);
edit.setText(getHighlightQueryResult(item, mUserQuery));
//运行编辑框的监听器对该行为作出反应,并设置下标及文本内容
return view;
}
/*
* 便
*
*/
public void onTextChange(int index, boolean hasText) {
if (index >= mEditTextList.getChildCount()) {
Log.e(TAG, "Wrong index, should not happen");
return;
//越界报错
}
if(hasText) {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
} else {
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
}
//如果内容不为空则将其子编辑框可见性置为可见,否则不可见
}
/*
*
*
*/
public void onCheckListModeChanged(int oldMode, int newMode) {
if (newMode == TextNote.MODE_CHECK_LIST) {
switchToListMode(mNoteEditor.getText().toString());
@ -906,11 +756,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//修改文本编辑器的内容和可见性
}
}
/*
*
*
*/
private boolean getWorkingText() {
boolean hasChecked = false;
//初始化check标记
@ -920,7 +765,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
//创建可变字符串
for (int i = 0; i < mEditTextList.getChildCount(); i++) {
View view = mEditTextList.getChildAt(i);
//遍历所有子编辑框的视图
//遍历所有子编辑框的视图
NoteEditText edit = (NoteEditText) view.findViewById(R.id.et_edit_text);
if (!TextUtils.isEmpty(edit.getText())) {
//若文本不为空
@ -943,7 +788,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
return hasChecked;
}
/*
* 便
*
@ -966,10 +810,6 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return saved;
}
/*
* 便
*
*/
private void sendToDesktop() {
/**
* Before send message to home, we should make sure that current
@ -978,16 +818,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
*/
if (!mWorkingNote.existInDatabase()) {
saveNote();
//若不存在数据也就是新的标签就保存起来先
}
if (mWorkingNote.getNoteId() > 0) {
//若是有内容
Intent sender = new Intent();
Intent shortcutIntent = new Intent(this, NoteEditActivity.class);
//建立发送到桌面的连接器
shortcutIntent.setAction(Intent.ACTION_VIEW);
//链接为一个视图
shortcutIntent.putExtra(Intent.EXTRA_UID, mWorkingNote.getNoteId());
sender.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
@ -995,12 +831,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));
sender.putExtra("duplicate", true);
//将便签的相关信息都添加到要发送的文件里
sender.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
//设置sneder的行为是发送
showToast(R.string.info_note_enter_desktop);
sendBroadcast(sender);
//显示到桌面
} else {
/**
* There is the condition that user has input nothing (the note is
@ -1009,14 +842,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
*/
Log.e(TAG, "Send to desktop error");
showToast(R.string.error_note_empty_for_send_to_desktop);
//空便签直接报错
}
}
/*
*
*
*/
private String makeShortcutIconTitle(String content) {
content = content.replace(TAG_CHECKED, "");
content = content.replace(TAG_UNCHECKED, "");
@ -1024,20 +851,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
//直接设置为content中的内容并返回有勾选和未勾选2种
}
/*
*
*
*/
private void showToast(int resId) {
showToast(resId, Toast.LENGTH_SHORT);
}
/*
*
* duration
*/
private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show();
}
}
}

@ -37,21 +37,28 @@ import net.micode.notes.R;
import java.util.HashMap;
import java.util.Map;
//类便签编辑文本类继承了Android控件EditText
/**
* @Package: net.micode.notes.ui
* @ClassName: NoteEditText
* @Description:
* @Author: YangYizhe
* @CreateDate: 12/21/2023 12:38 AM
* @Version: 1.0
*/
public class NoteEditText extends EditText {
//语句:常量标识
//常量标识
private static final String TAG = "NoteEditText";
//语句:声明整型变量,文本索引
//声明整型变量,文本索引
private int mIndex;
//语句:声明整型变量
//声明整型变量
private int mSelectionStartBeforeDelete;
//语句:声明字符串常量,标志电话、网址、邮件
//声明字符串常量,标志电话、网址、邮件
private static final String SCHEME_TEL = "tel:" ;
private static final String SCHEME_HTTP = "http:" ;
private static final String SCHEME_EMAIL = "mailto:" ;
//语句块:设置映射,将文本内容(电话、网址、邮件)做链接处理
//设置映射,将文本内容(电话、网址、邮件)做链接处理
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
static {
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
@ -61,60 +68,75 @@ public class NoteEditText extends EditText {
/**
* Call by the {@link NoteEditActivity} to delete or add edit text
* TextView
* TextView
*/
public interface OnTextViewChangeListener {
/**
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens
* and the text is null
* delete
* delete
*/
void onEditTextDelete(int index, String text);
/**
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER}
* happen
* enter
* enter
*/
void onEditTextEnter(int index, String text);
/**
* Hide or show item option when text change
*
*
*/
void onTextChange(int index, boolean hasText);
}
//语句:声明文本视图变化监听器
//声明文本视图变化监听器
private OnTextViewChangeListener mOnTextViewChangeListener;
//方法构造方法实例化NoteEditText
/**
* NoteEditText
*/
public NoteEditText(Context context) {
super(context, null);
mIndex = 0;
}
//方法:设置索引号
//设置索引号
public void setIndex(int index) {
mIndex = index;
}
//方法:设置文本视图变化监听器
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
/**
*
*/
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
mOnTextViewChangeListener = listener;
}
//方法构造方法是由参数集文本编辑风格实例化NoteEditText
public NoteEditText(Context context, AttributeSet attrs) {
/**
* NoteEditText
*/
public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle);
}
//方法构造方法是由参数集文本编辑风格、定义风格实例化NoteEditText
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
/**
* NoteEditText
*/
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
//方法:监听触摸事件
/**
* @method onTouchEvent
* @description
* @date: 12/21/2023 12:41 AM
* @author: YangYizhe
* @param
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
@ -126,22 +148,19 @@ public class NoteEditText extends EditText {
y -= getTotalPaddingTop();
x += getScrollX();
y += getScrollY();
//语句:获取布局
Layout layout = getLayout();
//语句:获取纵向的行数
int line = layout.getLineForVertical(y);
//语句:获取横向的偏移量
int off = layout.getOffsetForHorizontal(line, x);
Selection.setSelection(getText(), off);
break;
}
//语句:继续调用父类的监听事件方法
return super.onTouchEvent(event);
}
/**
*
* @method onKeyDown
* @description
* @date: 12/21/2023 12:40 AM
* @author: YangYizhe
* @param keyCode
* @param event
* @return boolean
@ -149,16 +168,12 @@ public class NoteEditText extends EditText {
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
//语句块:按下回车键
case KeyEvent.KEYCODE_ENTER:
//语句块:如果文本视图没有变化
if (mOnTextViewChangeListener != null) {
return false;
}
break;
//语句块:按下删除键
case KeyEvent.KEYCODE_DEL:
//语句:获取删除文本的开始位置
mSelectionStartBeforeDelete = getSelectionStart();
break;
default:
@ -167,45 +182,34 @@ public class NoteEditText extends EditText {
return super.onKeyDown(keyCode, event);
}
/**
*
* @method onKeyUp
* @description
* @date: 12/21/2023 12:39 AM
* @author: YangYizhe
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch(keyCode) {
//语句块:抬起删除键
case KeyEvent.KEYCODE_DEL:
//语句块:如果文本视图发生变化
if (mOnTextViewChangeListener != null) {
//语句块:选择了删除的文字
if (0 == mSelectionStartBeforeDelete && mIndex != 0) {
//语句:监听文本的删除
mOnTextViewChangeListener.onEditTextDelete(mIndex, getText().toString());
return true;
}
} else {
//语句:报告文本视图变化监听器没有设置
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
//语句块:抬起回车键
case KeyEvent.KEYCODE_ENTER:
//语句块:如果文本视图发生变化
if (mOnTextViewChangeListener != null) {
//语句:获取选择区域的起点位置
int selectionStart = getSelectionStart();
//语句:获取选择区域后面的文本信息
String text = getText().subSequence(selectionStart, length()).toString();
//语句:实现文本换行的功能
setText(getText().subSequence(0, selectionStart));
//语句:将选择区域内的文字移到下一行
mOnTextViewChangeListener.onEditTextEnter(mIndex + 1, text);
} else {
//语句:报告文本视图变化监听器没有设置
Log.d(TAG, "OnTextViewChangeListener was not seted");
}
break;
@ -216,16 +220,17 @@ public class NoteEditText extends EditText {
}
/**
*
* @method onFocusChanged
* @description
* @date: 12/21/2023 12:39 AM
* @author: YangYizhe
* @param focused
* @param direction
* @param previouslyFocusedRect 访
*/
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
//语句块:如果文本视图发生变化
if (mOnTextViewChangeListener != null) {
//语句块:当焦点存在或者当前文本不为空时,监听文本的变化
if (!focused && TextUtils.isEmpty(getText())) {
mOnTextViewChangeListener.onTextChange(mIndex, false);
} else {
@ -236,12 +241,16 @@ public class NoteEditText extends EditText {
}
/**
*
* @method onCreateContextMenu
* @description
* @date: 12/21/2023 12:39 AM
* @author: YangYizhe
* @param
* @return
*/
@Override
protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) {
//语句块:获取高亮元素
int selStart = getSelectionStart();
int selEnd = getSelectionEnd();
@ -249,7 +258,6 @@ public class NoteEditText extends EditText {
int max = Math.max(selStart, selEnd);
final URLSpan[] urls = ((Spanned) getText()).getSpans(min, max, URLSpan.class);
//语句块:针对不同的高亮元素,使用不同的操作进行处理
if (urls.length == 1) {
int defaultResId = 0;
for(String schema: sSchemaActionResMap.keySet()) {
@ -262,7 +270,6 @@ public class NoteEditText extends EditText {
if (defaultResId == 0) {
defaultResId = R.string.note_link_other;
}
//语句块:添加环境菜单的点击事件
menu.add(0, 0, 0, defaultResId).setOnMenuItemClickListener(
new OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {

@ -1,6 +1,5 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -62,16 +61,12 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
//主界面,一进入就是这个界面
/**
* @Package: net.micode.notes.ui
* @ClassName: NotesListActivity
* @Description:
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:02
* @Version: 1.0
* @author k
*
*/
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener { //没有用特定的标签加注释。。。感觉没有什么用
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
private static final int FOLDER_LIST_QUERY_TOKEN = 1;
@ -82,7 +77,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private static final int MENU_FOLDER_CHANGE_NAME = 2;
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; //单行超过80个字符
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
@ -127,67 +122,58 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
@Override
/**
* @method onCreate
* @description final Javafinal
* finalfinalfinal
* final
* final
* final
* @date: 2023/12/20 23:13
* @author: WUSHUXIAN
* @param void
* @return void
*/
protected void onCreate(final Bundle savedInstanceState) {
/**
* @method onCreate
* @description
* @date: 9:58 AM
* @author: YangYizhe
* @param [savedInstanceState]
* @return void
*/
protected void onCreate(final Bundle savedInstanceState) { //需要是final类型 根据程序上下文环境Java关键字final有“这是无法改变的”或者“终态的”含义它可以修饰非抽象类、非抽象类成员方法和变量。你可能出于两种理解而需要阻止改变设计或效率。
// final类不能被继承没有子类final类中的方法默认是final的。
//final方法不能被子类的方法覆盖但可以被继承。
//final成员变量表示常量只能被赋值一次赋值后值不再改变。
//final不能用于修饰构造方法。
super.onCreate(savedInstanceState); // 调用父类的onCreate函数
setContentView(R.layout.note_list);
initResources();
/**
* Insert an introduction when user firstly use this application
*/
setAppInfoFromRawRes();
}
@Override
/**
* @method onActivityResult
* @description:
*
* requestCode
* resultCode
* data
* @date: 2023/12/20 23:26
* @author: WUSHUXIAN
* @param void
* @return void
*/
// 返回一些子模块完成的数据交给主Activity处理
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 结果值 和 要求值 符合要求
if (resultCode == RESULT_OK
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
mNotesListAdapter.changeCursor(null);
} else {
super.onActivityResult(requestCode, resultCode, data);// 调用 Activity 的onActivityResult()
super.onActivityResult(requestCode, resultCode, data);
// 调用 Activity 的onActivityResult
}
}
/**
* @method setAppInfoFromRawRes
* @description:
* @date: 2023/12/20 23:24
* @author: WUSHUXIAN
* @param
* @return
*/
private void setAppInfoFromRawRes() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);// Android平台给我们提供了一个SharedPreferences类它是一个轻量级的存储类特别适合用于保存软件配置参数。
// Android平台给我们提供了一个SharedPreferences类它是一个轻量级的存储类特别适合用于保存软件配置参数。
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder();
InputStream in = null;
try {
// 把资源文件放到应用程序的/raw/raw下那么就可以在应用中使用getResources获取资源后,以openRawResource方法不带后缀的资源文件名打开这个文件。
// 把资源文件放到应用程序的/raw/raw下那么就可以在应用中使用getResources获取资源后,
// 以openRawResource方法不带后缀的资源文件名打开这个文件。
in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024];
char [] buf = new char[1024]; // 自行定义的数值,使用者不知道有什么意义
int len = 0;
while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len);
@ -230,14 +216,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
super.onStart();
startAsyncNotesListQuery();
}
/**
* @method initResources
* @description
* @date: 2023/12/20 23:09
* @author: WUSHUXIAN
* @param
* @return
*/
// 初始化资源
private void initResources() {
mContentResolver = this.getContentResolver(); // 获取应用程序的数据,得到类似数据表的东西
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -262,15 +242,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mModeCallBack = new ModeCallback();
}
//
/**
* @Package: net.micode.notes.ui
* @ClassName: ModeCallback
* @Description: ListView.MultiChoiceModeListener OnMenuItemClickListener
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:37
* @Version: 1.0
*/
// 继承自ListView.MultiChoiceModeListener 和 OnMenuItemClickListener
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu;
private ActionMode mActionMode;
@ -308,14 +280,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
return true;
}
/**
* @method updateMenu
* @description
* @date: 2023/12/16 23:36
* @author: WUSHUXIAN
* @param
* @return
*/
// 更新菜单
private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount();
// Update dropdown menu
@ -358,14 +324,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mNotesListAdapter.setCheckedItem(position, checked);
updateMenu();
}
/**
* @method onMenuItemClick
* @description:
* @date: 2023/12/20 23:39
* @author: WUSHUXIAN
* @param
* @return
*/
public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
@ -397,8 +356,9 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
}
//接口的实现
private class NewNoteOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
@ -458,44 +418,22 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
};
/**
* @method startAsyncNotesListQuery
* @description: Notes
* @date: 2023/12/20 23:45
* @author: WUSHUXIAN
* @param
* @return
*/
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION : NORMAL_SELECTION;
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {String.valueOf(mCurrentFolderId)},
NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
String.valueOf(mCurrentFolderId)
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
/**
* @Package: net.micode.notes.ui
* @ClassName: BackgroundQueryHandler
* @Description: AsyncQueryHandler
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/21 0:01
* @Version: 1.0
*/
private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
}
@Override
/**
* @method onQueryComplete
* @description:
* @date: 2023/12/20 23:56
* @author: WUSHUXIAN
* @param token
* @param cookie cookie
* @param cursor
* @return void
*/
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
switch (token) {
case FOLDER_NOTE_LIST_QUERY_TOKEN:
@ -541,29 +479,21 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
/**
* @method batchDelete
* @description: 便
* @date: 2023/12/21 0:14
* @author: WUSHUXIAN
* @param
* @return void
*/
@SuppressLint("StaticFieldLeak")
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
//如果没有同步,直接删除
if (!isSyncMode()) {
// if not synced, delete notes directly
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) {
} else {
Log.e(TAG, "Delete notes error, should not happens");
}
}
//已同步,将删除的便签移到垃圾桶
else {
} else {
// in sync mode, we'll move the deleted note into the trash
// folder
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens");
@ -586,14 +516,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}.execute();
}
/**
* @method deleteFolder
* @description:
* @date: 2023/12/21 0:32
* @author: WUSHUXIAN
* @param folderId
* @return void
*/
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -662,14 +585,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
* @method showCreateOrModifyFolderDialog
* @description:
* @date: 2023/12/21 0:39
* @author: WUSHUXIAN
* @param create
* @return void
*/
private void showCreateOrModifyFolderDialog(final boolean create) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
View view = LayoutInflater.from(this).inflate(R.layout.dialog_edit_text, null);
@ -727,10 +643,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
dialog.dismiss();
}
});
//如果便签名是空的,则禁用确认按钮
if (TextUtils.isEmpty(etName.getText())) {
positive.setEnabled(false);
}
/**
* When the name edit text is null, disable the positive button
*/
etName.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
@ -757,8 +676,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
*
*/
@Override
public void onBackPressed() {
switch (mState) {
public void onBackPressed() { switch (mState) {
case SUB_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
@ -803,14 +721,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
sendBroadcast(intent);
setResult(RESULT_OK, intent);
}
/**
* @method OnCreateContextMenuListener
* @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) {
if (mFocusNoteDataItem != null) {

Loading…
Cancel
Save