pull/5/head
ps9up4ig6 2 years ago
commit a99473d8c2

3
.idea/.gitignore vendored

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/gitProject1.iml" filepath="$PROJECT_DIR$/.idea/gitProject1.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

@ -21,7 +21,6 @@
android:versionCode="1"
android:versionName="0.1" >
<!-- 添加 tools:ignore="GradleOverrides" 忽略 Gradle 对 minSdkVersion 的重写-->
<uses-sdk android:minSdkVersion="14"
tools:ignore="GradleOverrides" />
@ -40,8 +39,6 @@
android:icon="@drawable/icon_app"
android:label="@string/app_name" >
<!-- 添加android:exported="true" -->
<!-- 原因As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise. For launcher activities, this should be set to true.-->
<!-- 移除android:label="@string/app_name"-->
<!-- 原因Redundant label can be removed.冗余标签可以移除第41行已经给出-->
@ -60,9 +57,6 @@
</intent-filter>
</activity>
<!-- 添加android:exported="true" -->
<!-- 原因: As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise. For launcher activities, this should be set to true.-->
<activity
android:name=".ui.NoteEditActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
@ -95,8 +89,6 @@
android:resource="@xml/searchable" />
</activity>
<!-- 添加android:exported="false"-->
<!-- 原因Exported content providers can provide access to potentially sensitive data-->
<provider
android:name="net.micode.notes.data.NotesProvider"
@ -104,8 +96,6 @@
android:multiprocess="true"
android:exported="false" />
<!-- 添加android:exported="true" -->
<!-- 原因: As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise. For launcher activities, this should be set to true.-->
<receiver
android:name=".widget.NoteWidgetProvider_2x"
@ -122,9 +112,6 @@
android:resource="@xml/widget_2x_info" />
</receiver>
<!-- 添加android:exported="true" -->
<!-- 原因: As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise. For launcher activities, this should be set to true.-->
<receiver
android:name=".widget.NoteWidgetProvider_4x"
@ -142,9 +129,6 @@
android:resource="@xml/widget_4x_info" />
</receiver>
<!-- 添加android:exported="true" -->
<!-- 原因: As of Android 12, android:exported must be set; use true to make the activity available to other apps, and false otherwise. For launcher activities, this should be set to true.-->
<receiver android:name=".ui.AlarmInitReceiver"
android:exported="true">
@ -158,9 +142,6 @@
android:process=":remote" >
</receiver>
<!-- 移除android:label="@string/app_name"-->
<!-- 原因Redundant label can be removed.冗余标签可以移除第41行已经给出-->
<activity
android:name=".ui.AlarmAlertActivity"
android:launchMode="singleInstance"

@ -45,6 +45,7 @@ public class Notes {
public static final int TYPE_WIDGET_INVALIDE = -1;
public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1;
public static final int TYPE_WIDGET_3X = 2; // 3x3窗口小部件
public static class DataConstants {
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;

@ -40,7 +40,7 @@ public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff
private static BackupUtils sInstance;
//如果当前备份不存在,则新声明一个
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
sInstance = new BackupUtils(context);
@ -51,16 +51,17 @@ public class BackupUtils {
/**
* Following states are signs to represents backup or restore
* status
*
*/
// Currently, the sdcard is not mounted
// Currently, the sdcard is not mounted SD卡没有被装入手机
public static final int STATE_SD_CARD_UNMOUONTED = 0;
// The backup file not exist
// The backup file not exist 备份文件不存在
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
// The data is not well formated, may be changed by other programs
// The data is not well formated, may be changed by other programs 数据已被破坏,可能被修改
public static final int STATE_DATA_DESTROIED = 2;
// Some run-time exception which causes restore or backup fails
// Some run-time exception which causes restore or backup fails 超时异常
public static final int STATE_SYSTEM_ERROR = 3;
// Backup or restore success
// Backup or restore success 备份或还原成功
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport;
@ -72,34 +73,34 @@ public class BackupUtils {
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
//判断外部存储功能是否可用
public int exportToText() {
return mTextExport.exportToText();
}
//输出至文本
public String getExportedTextFileName() {
return mTextExport.mFileName;
}
//获取输出的文本文件名
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
}
private static class TextExport {
//获取输出文本文件目录
private static class TextExport {//内部类文本输出定义笔记ID、修改日期等笔记、内容、日期、电话号码的数据和格式等常量
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
NoteColumns.MODIFIED_DATE,
NoteColumns.SNIPPET,
NoteColumns.TYPE
};
//下面几行标识数组里属性值
private static final int NOTE_COLUMN_ID = 0;
private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
private static final int NOTE_COLUMN_SNIPPET = 2;
private static final String[] DATA_PROJECTION = {
private static final String[] DATA_PROJECTION = {//字符串储存便签的基本信息
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
@ -107,7 +108,7 @@ public class BackupUtils {
DataColumns.DATA3,
DataColumns.DATA4,
};
//标识设定数据内容标识为0媒体类型标识为1访问日期标识为2电话号码标识为4
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_MIME_TYPE = 1;
@ -115,17 +116,17 @@ public class BackupUtils {
private static final int DATA_COLUMN_CALL_DATE = 2;
private static final int DATA_COLUMN_PHONE_NUMBER = 4;
//文档格式标识名称标识为0;日期标识为1;内容标识为2
private final String [] TEXT_FORMAT;
private static final int FORMAT_FOLDER_NAME = 0;
private static final int FORMAT_NOTE_DATE = 1;
private static final int FORMAT_NOTE_CONTENT = 2;
//定义文件名、上下文、文件夹路径三个类
private Context mContext;
private String mFileName;
private String mFileDirectory;
public TextExport(Context context) {
public TextExport(Context context) {//从context获取便签的信息并给其中一些成员赋予初值
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
mContext = context;
mFileName = "";
@ -134,12 +135,13 @@ public class BackupUtils {
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
}//通过ID返回文件的格式信息
/**
* Export the folder identified by folder id to text
*/
private void exportFolderToText(String folderId, PrintStream ps) {
private void exportFolderToText(String folderId, PrintStream ps) {//
// 通过文件ID找到该文件下的便签并且打印出该便签最后修改的日期并且将该便签的内容输出并显示出来。
// Query notes belong to this folder
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
@ -166,6 +168,7 @@ public class BackupUtils {
* Export note identified by id to a print stream
*/
private void exportNoteToText(String noteId, PrintStream ps) {
//将便签的内容以文本的形式显示在屏幕上。比如电话号码、打电话的日期等。
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId
@ -206,7 +209,7 @@ public class BackupUtils {
dataCursor.close();
}
// print a line separator between note
try {
try {//在note下面输出一条线
ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
});
@ -218,26 +221,26 @@ public class BackupUtils {
/**
* Note will be exported as text which is user readable
*/
public int exportToText() {
if (!externalStorageAvailable()) {
public int exportToText() {//将note里面的内容输出到用户的屏幕
if (!externalStorageAvailable()) {//检查外部设备安装情况
Log.d(TAG, "Media was not mounted");
return STATE_SD_CARD_UNMOUONTED;
}
PrintStream ps = getExportToTextPrintStream();
if (ps == null) {
Log.e(TAG, "get print stream error");
Log.e(TAG, "get print stream error");//先导出对应的目录,然后导出对应的便签
return STATE_SYSTEM_ERROR;
}
// First export folder and its notes
Cursor folderCursor = mContext.getContentResolver().query(
Cursor folderCursor = mContext.getContentResolver().query(//定位需要导出的文件夹
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
if (folderCursor != null) {
if (folderCursor != null) {//导出文件夹,把里面的便签导出来
if (folderCursor.moveToFirst()) {
do {
// Print folder's name
@ -258,13 +261,13 @@ public class BackupUtils {
}
// Export notes in root's folder
Cursor noteCursor = mContext.getContentResolver().query(
Cursor noteCursor = mContext.getContentResolver().query(//输出根目录下的便签
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0", null, null);
if (noteCursor != null) {
if (noteCursor != null) {//输出修改的时间
if (noteCursor.moveToFirst()) {
do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
@ -285,17 +288,17 @@ public class BackupUtils {
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
*/
private PrintStream getExportToTextPrintStream() {
private PrintStream getExportToTextPrintStream() {//获取指向文件的打印流
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
R.string.file_name_txt_format);
if (file == null) {
Log.e(TAG, "create file to exported failed");
return null;
}
mFileName = file.getName();
mFileDirectory = mContext.getString(R.string.file_path);
}//初始化储存在SD卡中的文件如果为空创造失败
mFileName = file.getName();//得到文件名
mFileDirectory = mContext.getString(R.string.file_path);//得到文件路径
PrintStream ps = null;
try {
try {//将ps输出流输出到特定的文件目的就是导出到文件而不是直接输出
FileOutputStream fos = new FileOutputStream(file);
ps = new PrintStream(fos);
} catch (FileNotFoundException e) {
@ -313,6 +316,7 @@ public class BackupUtils {
* Generate the text file to store imported data
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
//生成存储文件安装在SD卡上
StringBuilder sb = new StringBuilder();
sb.append(Environment.getExternalStorageDirectory());
sb.append(context.getString(filePathResId));
@ -323,7 +327,7 @@ public class BackupUtils {
System.currentTimeMillis())));
File file = new File(sb.toString());
try {
try {//如果这些文件不存在,则新建
if (!filedir.exists()) {
filedir.mkdir();
}

@ -35,10 +35,10 @@ import java.util.ArrayList;
import java.util.HashSet;
public class DataUtils {
public class DataUtils {//定义便签的处理工具类
public static final String TAG = "DataUtils";
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {//一个处理批量删除便签的方法
if (ids == null) {//判断笔记是否为空
Log.d(TAG, "the ids is null");
return true;
}
@ -48,23 +48,23 @@ public class DataUtils {
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {
for (long id : ids) {//遍历便签id
if(id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root");
Log.e(TAG, "Don't delete system folder root");//.如果是根目录的文件夹输出Don't delete system folder root
continue;
}
ContentProviderOperation.Builder builder = ContentProviderOperation
ContentProviderOperation.Builder builder = ContentProviderOperation//批量的删除对应的ID
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());
}
try {
try {//返回被删除的数据如果返回为空则删除失败返回false打印异常信息删除成功返回true
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
return true;
} catch (RemoteException e) {
} catch (RemoteException e) {//错误处理
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
@ -73,6 +73,7 @@ public class DataUtils {
}
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
//将某便签移动到另一个目录下
ContentValues values = new ContentValues();
values.put(NoteColumns.PARENT_ID, desFolderId);
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
@ -80,7 +81,7 @@ public class DataUtils {
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,//批量移动
long folderId) {
if (ids == null) {
Log.d(TAG, "the ids is null");
@ -88,7 +89,7 @@ public class DataUtils {
}
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {
for (long id : ids) {//遍历便签ID
ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
builder.withValue(NoteColumns.PARENT_ID, folderId);
@ -96,7 +97,7 @@ public class DataUtils {
operationList.add(builder.build());
}
try {
try {//错误检测
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
@ -114,7 +115,7 @@ public class DataUtils {
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
*/
public static int getUserFolderCount(ContentResolver resolver) {
public static int getUserFolderCount(ContentResolver resolver) {//得到文件夹数目
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { "COUNT(*)" },
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
@ -136,14 +137,14 @@ public class DataUtils {
return count;
}
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {//在数据库中是否可见
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
new String [] {String.valueOf(type)},
null);
boolean exist = false;
boolean exist = false;//判断note是否在数据库中并返回相应的布尔值
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true;
@ -153,7 +154,7 @@ public class DataUtils {
return exist;
}
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {//通过便签ID搜索判断该note是否在数据库中存在
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -167,7 +168,7 @@ public class DataUtils {
return exist;
}
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {//通过名字查询是否在数据库中存在
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
@ -181,7 +182,7 @@ public class DataUtils {
return exist;
}
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {//检查文件名以获取文件是否存在
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
@ -197,7 +198,7 @@ public class DataUtils {
return exist;
}
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {//获得文件夹窗口小部件
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
NoteColumns.PARENT_ID + "=?",
@ -209,12 +210,12 @@ public class DataUtils {
if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>();
do {
try {
try {//把每一个条目对应的窗口id和type记录下来放到set里面。
AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0);
widget.widgetType = c.getInt(1);
set.add(widget);
} catch (IndexOutOfBoundsException e) {
} catch (IndexOutOfBoundsException e) {//当下标超过边界,那么返回错误
Log.e(TAG, e.toString());
}
} while (c.moveToNext());
@ -224,14 +225,14 @@ public class DataUtils {
return set;
}
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {//通过笔记ID获取号码
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
null);
if (cursor != null && cursor.moveToFirst()) {
if (cursor != null && cursor.moveToFirst()) {//获取电话号码,并处理异常
try {
return cursor.getString(0);
} catch (IndexOutOfBoundsException e) {
@ -243,7 +244,7 @@ public class DataUtils {
return "";
}
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {//通过号码和日期获取ID
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
@ -264,7 +265,7 @@ public class DataUtils {
return 0;
}
public static String getSnippetById(ContentResolver resolver, long noteId) {
public static String getSnippetById(ContentResolver resolver, long noteId) {//通过Note的Id获取Note的片段
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?",
@ -282,7 +283,7 @@ public class DataUtils {
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
public static String getFormattedSnippet(String snippet) {
public static String getFormattedSnippet(String snippet) {//格式化,对字符串进行格式处理,将字符串两头的空格去掉,同时将换行符去掉
if (snippet != null) {
snippet = snippet.trim();
int index = snippet.indexOf('\n');

@ -17,7 +17,8 @@
package net.micode.notes.tool;
public class GTaskStringUtils {
//定义了很多的静态字符串目的就是为了提供jsonObject中相应字符串的"key"
//把这些静态的定义单独写到了一个类里面,是非常好的编程规范
public final static String GTASK_JSON_ACTION_ID = "action_id";
public final static String GTASK_JSON_ACTION_LIST = "action_list";

@ -23,7 +23,7 @@ import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
public class ResourceParser {
//ResourceParser类资源分析实际上就是获取资源并且在程序中使用比如图片资源、布局资源、字体大小等
public static final int YELLOW = 0;
public static final int BLUE = 1;
public static final int WHITE = 2;
@ -39,7 +39,7 @@ public class ResourceParser {
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
public static class NoteBgResources {
public static class NoteBgResources {//背景资源的获取
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
R.drawable.edit_blue,
@ -59,13 +59,13 @@ public class ResourceParser {
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
//获取Note的背景颜色
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
public static int getDefaultBgId(Context context) {
//ID可以查找到编辑框的颜色的地址
public static int getDefaultBgId(Context context) {//直接获取默认的背景颜色
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
@ -74,7 +74,7 @@ public class ResourceParser {
}
}
public static class NoteItemBgResources {
public static class NoteItemBgResources {//便签背景资源类
private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up,
R.drawable.list_blue_up,
@ -128,8 +128,8 @@ public class ResourceParser {
}
}
public static class WidgetBgResources {
private final static int [] BG_2X_RESOURCES = new int [] {
public static class WidgetBgResources {//获取图片资源类
private final static int [] BG_2X_RESOURCES = new int [] {//通过id获得2x的小窗口背景资源
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
R.drawable.widget_2x_white,
@ -140,7 +140,7 @@ public class ResourceParser {
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
//通过ID获取较小的图片
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
@ -153,7 +153,7 @@ public class ResourceParser {
return BG_4X_RESOURCES[id];
}
}
//根据ID加载BG_4X_RESOURCES数组里的颜色资源序号。
public static class TextAppearanceResources {
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal,
@ -161,7 +161,7 @@ public class ResourceParser {
R.style.TextAppearanceLarge,
R.style.TextAppearanceSuper
};
//文本外观资源,包括默认字体,以及获取资源大小
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
@ -173,9 +173,10 @@ public class ResourceParser {
}
return TEXTAPPEARANCE_RESOURCES[id];
}
//防止输入的id大于资源总量若如此则自动返回默认的设置结果
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}
//直接返回为资源的长度

@ -63,6 +63,7 @@ import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
import net.micode.notes.widget.NoteWidgetProvider_2x;
import net.micode.notes.widget.NoteWidgetProvider_3x;
import net.micode.notes.widget.NoteWidgetProvider_4x;
import java.util.HashMap;
@ -412,8 +413,10 @@ public class NoteEditActivity extends Activity implements OnClickListener,
intent.setClass(this, NoteWidgetProvider_2x.class);
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
intent.setClass(this, NoteWidgetProvider_4x.class);
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_3X) {
intent.setClass(this, NoteWidgetProvider_3x.class);
} else {
Log.e(TAG, "Unspported widget type");
Log.e(TAG, "Unsupported widget type");
return;
}
@ -430,7 +433,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
if (id == R.id.btn_set_bg_color) {
mNoteBgColorSelector.setVisibility(View.VISIBLE);
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
- View.VISIBLE);
View.VISIBLE);
} else if (sBgSelectorBtnsMap.containsKey(id)) {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.GONE);

@ -70,6 +70,7 @@ import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import net.micode.notes.widget.NoteWidgetProvider_2x;
import net.micode.notes.widget.NoteWidgetProvider_3x;
import net.micode.notes.widget.NoteWidgetProvider_4x;
import java.io.BufferedReader;
@ -141,7 +142,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
setContentView(R.layout.note_list);
initResources();
/**
/*
* Insert an introduction when user firstly use this application
*/
setAppInfoFromRawRes();
@ -694,6 +695,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
intent.setClass(this, NoteWidgetProvider_2x.class);
} else if (appWidgetType == Notes.TYPE_WIDGET_4X) {
intent.setClass(this, NoteWidgetProvider_4x.class);
} else if (appWidgetType == Notes.TYPE_WIDGET_3X) {
intent.setClass(this, NoteWidgetProvider_3x.class);
} else {
Log.e(TAG, "Unspported widget type");
return;

@ -32,7 +32,8 @@ import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
public abstract class NoteWidgetProvider extends AppWidgetProvider {
// 该类实现了桌面中的窗口小部件
public abstract class NoteWidgetProvider extends AppWidgetProvider { // 小米便签窗口小部件
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
@ -46,7 +47,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
private static final String TAG = "NoteWidgetProvider";
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
public void onDeleted(Context context, int[] appWidgetIds) { // 重写删除窗口小部件函数
ContentValues values = new ContentValues();
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
for (int i = 0; i < appWidgetIds.length; i++) {
@ -57,7 +58,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
private Cursor getNoteWidgetInfo(Context context, int widgetId) { // 获取窗口小部件宽度信息
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",
@ -70,7 +71,7 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) {
boolean privacyMode) { // 更新窗口小部件中的内容
for (int i = 0; i < appWidgetIds.length; i++) {
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
int bgId = ResourceParser.getDefaultBgId(context);
@ -124,9 +125,9 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
protected abstract int getBgResourceId(int bgId);
protected abstract int getBgResourceId(int bgId); // 从背景资源中获取当前应用ID
protected abstract int getLayoutId();
protected abstract int getLayoutId(); // 获取布局ID
protected abstract int getWidgetType();
protected abstract int getWidgetType(); // 获取窗口小部件的类型即2x2型或者4x4型
}

@ -24,23 +24,23 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
@Override
public class NoteWidgetProvider_2x extends NoteWidgetProvider { // 2x2大小的窗口小部件
@Override // 重写窗口小部件中的更新函数
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
@Override
@Override // 重写窗口小部件中的获取布局ID函数
protected int getLayoutId() {
return R.layout.widget_2x;
}
@Override
@Override // 重写窗口小部件中的获取资源ID函数
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
@Override
@Override // 重写窗口小部件中的获取宽度类型函数
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;
}

@ -0,0 +1,31 @@
package net.micode.notes.widget;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
public class NoteWidgetProvider_3x extends NoteWidgetProvider{ // 3x3大小的窗口小部件
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
@Override // 重写窗口小部件中的获取布局ID函数
protected int getLayoutId() {
return R.layout.widget_3x;
}
@Override // 重写窗口小部件中的获取资源ID函数
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
@Override // 重写窗口小部件中的获取宽度类型函数
protected int getWidgetType() {
return Notes.TYPE_WIDGET_3X;
}
}

@ -24,22 +24,23 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
@Override
public class NoteWidgetProvider_4x extends NoteWidgetProvider { // 4x4大小的窗口小部件
@Override // 重写窗口小部件中的更新函数
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
@Override // 重写窗口小部件中的获取布局ID函数
protected int getLayoutId() {
return R.layout.widget_4x;
}
@Override
@Override // 重写窗口小部件中的获取资源ID函数
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
@Override
@Override // 重写窗口小部件中的获取宽度类型函数
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;
}

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="220dip"
android:layout_height="220dip">
<ImageView
android:id="@+id/widget_bg_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id="@+id/widget_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="30dip"
android:paddingLeft="15dip"
android:paddingRight="15dip"
android:textSize="14sp"
android:textColor="#FF663300"
android:maxLines="9"
android:lineSpacingMultiplier="1.2" />
</FrameLayout>
Loading…
Cancel
Save