Compare commits

...

5 Commits
master ... lhn

@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "net.micode.notes",
"variantName": "debug",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "0.1",
"outputFile": "app-debug.apk"
}
],
"elementType": "File"
}

@ -0,0 +1,283 @@
net.micode.notes:xml/widget_4x_info = 0x7f0c0003
net.micode.notes:xml/preferences = 0x7f0c0000
net.micode.notes:style/TextAppearanceSecondaryItem = 0x7f0b0008
net.micode.notes:style/TextAppearanceNormal = 0x7f0b0006
net.micode.notes:style/TextAppearanceLarge = 0x7f0b0004
net.micode.notes:style/HighlightTextAppearancePrimary = 0x7f0b0000
net.micode.notes:string/widget_havenot_content = 0x7f0a0064
net.micode.notes:string/ticker_syncing = 0x7f0a0063
net.micode.notes:string/ticker_success = 0x7f0a0062
net.micode.notes:style/HighlightTextAppearanceSecondary = 0x7f0b0001
net.micode.notes:string/ticker_cancel = 0x7f0a0060
net.micode.notes:string/sync_progress_syncing = 0x7f0a005f
net.micode.notes:string/sync_progress_init_list = 0x7f0a005d
net.micode.notes:string/search_label = 0x7f0a0058
net.micode.notes:string/preferences_toast_success_set_accout = 0x7f0a0055
net.micode.notes:string/preferences_toast_cannot_change_account = 0x7f0a0054
net.micode.notes:string/preferences_title = 0x7f0a0053
net.micode.notes:string/preferences_menu_remove_account = 0x7f0a0052
net.micode.notes:style/NoteActionBarStyle = 0x7f0b0002
net.micode.notes:string/preferences_menu_change_account = 0x7f0a0051
net.micode.notes:string/preferences_menu_cancel = 0x7f0a0050
net.micode.notes:string/preferences_last_sync_time = 0x7f0a004e
net.micode.notes:string/preferences_dialog_select_account_title = 0x7f0a004d
net.micode.notes:string/preferences_dialog_change_account_warn_msg = 0x7f0a004b
net.micode.notes:string/preferences_button_sync_immediately = 0x7f0a0049
net.micode.notes:string/preferences_button_sync_cancel = 0x7f0a0048
net.micode.notes:string/preferences_account_summary = 0x7f0a0044
net.micode.notes:string/success_sdcard_export = 0x7f0a005b
net.micode.notes:string/notelist_string_info = 0x7f0a0043
net.micode.notes:string/notelist_menu_new = 0x7f0a0042
net.micode.notes:string/notealert_ok = 0x7f0a0041
net.micode.notes:string/notealert_enter = 0x7f0a0040
net.micode.notes:string/note_link_web = 0x7f0a003f
net.micode.notes:string/note_link_tel = 0x7f0a003e
net.micode.notes:string/note_link_other = 0x7f0a003d
net.micode.notes:string/note_link_email = 0x7f0a003c
net.micode.notes:string/note_alert_expired = 0x7f0a003b
net.micode.notes:string/menu_sync_cancel = 0x7f0a0039
net.micode.notes:string/menu_sync = 0x7f0a0038
net.micode.notes:string/menu_share = 0x7f0a0037
net.micode.notes:string/menu_select_title = 0x7f0a0034
net.micode.notes:style/TextAppearanceMedium = 0x7f0b0005
net.micode.notes:string/menu_select_none = 0x7f0a0033
net.micode.notes:string/menu_title_select_folder = 0x7f0a003a
net.micode.notes:string/menu_select_all = 0x7f0a0032
net.micode.notes:string/menu_search = 0x7f0a0031
net.micode.notes:string/menu_remove_remind = 0x7f0a0030
net.micode.notes:string/menu_normal_mode = 0x7f0a002f
net.micode.notes:string/menu_move_parent_folder = 0x7f0a002e
net.micode.notes:string/menu_move = 0x7f0a002d
net.micode.notes:string/menu_list_mode = 0x7f0a002c
net.micode.notes:string/menu_font_super = 0x7f0a002b
net.micode.notes:string/menu_font_small = 0x7f0a002a
net.micode.notes:string/menu_folder_change_name = 0x7f0a0024
net.micode.notes:string/menu_export_text = 0x7f0a0023
net.micode.notes:string/menu_deselect_all = 0x7f0a0022
net.micode.notes:string/menu_create_folder = 0x7f0a0020
net.micode.notes:style/TextAppearancePrimaryItem = 0x7f0b0007
net.micode.notes:string/folder_exist = 0x7f0a0017
net.micode.notes:string/hint_foler_name = 0x7f0a001d
net.micode.notes:string/format_date_ymd = 0x7f0a0018
net.micode.notes:string/file_path = 0x7f0a0016
net.micode.notes:string/set_remind_time_message = 0x7f0a005a
net.micode.notes:string/error_sync_network = 0x7f0a0013
net.micode.notes:string/error_sdcard_unmounted = 0x7f0a0010
net.micode.notes:string/datetime_dialog_ok = 0x7f0a000a
net.micode.notes:string/datetime_dialog_cancel = 0x7f0a0009
net.micode.notes:drawable/list_green_up = 0x7f040020
net.micode.notes:string/call_record_folder_name = 0x7f0a0008
net.micode.notes:drawable/new_note_normal = 0x7f040030
net.micode.notes:string/button_delete = 0x7f0a0007
net.micode.notes:string/app_widget2x2 = 0x7f0a0005
net.micode.notes:string/menu_font_normal = 0x7f0a0028
net.micode.notes:string/format_exported_file_location = 0x7f0a001a
net.micode.notes:raw/introduction = 0x7f090000
net.micode.notes:string/delete_remind_time_message = 0x7f0a000b
net.micode.notes:dimen/text_font_size_super = 0x7f030004
net.micode.notes:drawable/selected = 0x7f040035
net.micode.notes:plurals/search_results_title = 0x7f080000
net.micode.notes:menu/sub_folder = 0x7f070006
net.micode.notes:menu/note_edit = 0x7f070002
net.micode.notes:style/TextAppearanceSuper = 0x7f0b0009
net.micode.notes:color/secondary_text_dark = 0x7f020001
net.micode.notes:id/move = 0x7f05002e
net.micode.notes:id/iv_bg_yellow_select = 0x7f050017
net.micode.notes:menu/call_note_edit = 0x7f070000
net.micode.notes:drawable/new_note_pressed = 0x7f040031
net.micode.notes:id/iv_bg_blue = 0x7f05000e
net.micode.notes:layout/settings_header = 0x7f06000b
net.micode.notes:layout/note_list = 0x7f060008
net.micode.notes:drawable/list_white_single = 0x7f040027
net.micode.notes:layout/note_item = 0x7f060007
net.micode.notes:xml/widget_2x_info = 0x7f0c0002
net.micode.notes:string/alert_message_delete_folder = 0x7f0a0000
net.micode.notes:layout/datetime_picker = 0x7f060002
net.micode.notes:id/btn_new_note = 0x7f050004
net.micode.notes:layout/note_list_footer = 0x7f06000a
net.micode.notes:id/widget_text = 0x7f050042
net.micode.notes:id/tv_title_bar = 0x7f050040
net.micode.notes:drawable/widget_2x_blue = 0x7f040038
net.micode.notes:id/tv_time = 0x7f05003e
net.micode.notes:id/tv_name = 0x7f05003d
net.micode.notes:drawable/new_note = 0x7f04002f
net.micode.notes:id/sv_note_edit = 0x7f050039
net.micode.notes:id/selection_menu = 0x7f050038
net.micode.notes:string/error_sdcard_export = 0x7f0a000f
net.micode.notes:id/preference_sync_button = 0x7f050037
net.micode.notes:layout/note_edit = 0x7f060005
net.micode.notes:id/notes_list = 0x7f050035
net.micode.notes:string/alert_message_delete_notes = 0x7f0a0002
net.micode.notes:drawable/title_alert = 0x7f040036
net.micode.notes:id/note_title = 0x7f050034
net.micode.notes:string/preferences_last_sync_time_format = 0x7f0a004f
net.micode.notes:id/note_edit_view = 0x7f050032
net.micode.notes:id/navigation_bar = 0x7f05002f
net.micode.notes:string/app_widget4x4 = 0x7f0a0006
net.micode.notes:drawable/font_normal = 0x7f040011
net.micode.notes:id/minute = 0x7f05002d
net.micode.notes:drawable/font_super = 0x7f040014
net.micode.notes:id/menu_sync = 0x7f05002c
net.micode.notes:string/info_note_enter_desktop = 0x7f0a001e
net.micode.notes:id/menu_share = 0x7f05002b
net.micode.notes:id/menu_setting = 0x7f05002a
net.micode.notes:string/widget_under_visit_mode = 0x7f0a0065
net.micode.notes:id/menu_send_to_desktop = 0x7f050029
net.micode.notes:id/menu_search = 0x7f050028
net.micode.notes:drawable/list_green_down = 0x7f04001d
net.micode.notes:id/menu_new_note = 0x7f050027
net.micode.notes:string/error_note_not_exist = 0x7f0a000e
net.micode.notes:id/menu_new_folder = 0x7f050026
net.micode.notes:id/menu_list_mode = 0x7f050025
net.micode.notes:id/iv_medium_select = 0x7f050019
net.micode.notes:id/menu_export_text = 0x7f050023
net.micode.notes:string/menu_folder_view = 0x7f0a0026
net.micode.notes:id/menu_delete = 0x7f050021
net.micode.notes:string/ticker_fail = 0x7f0a0061
net.micode.notes:string/file_name_txt_format = 0x7f0a0015
net.micode.notes:drawable/edit_blue = 0x7f040006
net.micode.notes:id/prefenerece_sync_status_textview = 0x7f050036
net.micode.notes:string/menu_font_size = 0x7f0a0029
net.micode.notes:string/menu_alert = 0x7f0a001f
net.micode.notes:drawable/edit_title_yellow = 0x7f04000d
net.micode.notes:id/menu_alert = 0x7f050020
net.micode.notes:string/success_sync_account = 0x7f0a005c
net.micode.notes:id/ll_font_super = 0x7f05001f
net.micode.notes:id/ll_font_small = 0x7f05001e
net.micode.notes:menu/call_record_folder = 0x7f070001
net.micode.notes:id/ll_font_normal = 0x7f05001d
net.micode.notes:id/ll_font_large = 0x7f05001c
net.micode.notes:id/note_bg_color_selector = 0x7f050030
net.micode.notes:drawable/search_result = 0x7f040034
net.micode.notes:id/iv_super_select = 0x7f05001b
net.micode.notes:id/iv_bg_yellow = 0x7f050016
net.micode.notes:string/error_sync_cancelled = 0x7f0a0011
net.micode.notes:id/iv_bg_white_select = 0x7f050015
net.micode.notes:id/tv_alert_date = 0x7f05003a
net.micode.notes:dimen/text_font_size_large = 0x7f030000
net.micode.notes:drawable/notification = 0x7f040033
net.micode.notes:id/iv_bg_red = 0x7f050012
net.micode.notes:string/menu_font_large = 0x7f0a0027
net.micode.notes:drawable/widget_4x_blue = 0x7f04003d
net.micode.notes:id/iv_large_select = 0x7f050018
net.micode.notes:id/widget_bg_image = 0x7f050041
net.micode.notes:id/iv_bg_green_select = 0x7f050011
net.micode.notes:string/error_note_empty_for_clock = 0x7f0a000c
net.micode.notes:string/preferences_dialog_change_account_title = 0x7f0a004a
net.micode.notes:drawable/menu_move = 0x7f04002e
net.micode.notes:drawable/widget_4x_white = 0x7f040040
net.micode.notes:id/iv_bg_blue_select = 0x7f05000f
net.micode.notes:string/preferences_dialog_select_account_tips = 0x7f0a004c
net.micode.notes:id/font_size_selector = 0x7f05000b
net.micode.notes:id/et_edit_text = 0x7f050009
net.micode.notes:id/et_foler_name = 0x7f05000a
net.micode.notes:drawable/edit_green = 0x7f040007
net.micode.notes:layout/widget_4x = 0x7f06000d
net.micode.notes:string/search = 0x7f0a0056
net.micode.notes:id/cb_edit_item = 0x7f050006
net.micode.notes:id/btn_set_bg_color = 0x7f050005
net.micode.notes:id/account_dialog_subtitle = 0x7f050000
net.micode.notes:menu/note_list = 0x7f070003
net.micode.notes:id/account_dialog_title = 0x7f050001
net.micode.notes:id/iv_bg_green = 0x7f050010
net.micode.notes:id/amPm = 0x7f050003
net.micode.notes:drawable/widget_4x_green = 0x7f04003e
net.micode.notes:style/NoteTheme = 0x7f0b0003
net.micode.notes:id/hour = 0x7f05000c
net.micode.notes:drawable/note_edit_color_selector_panel = 0x7f040032
net.micode.notes:drawable/widget_2x_yellow = 0x7f04003c
net.micode.notes:string/format_move_notes_to_folder = 0x7f0a001c
net.micode.notes:drawable/widget_2x_red = 0x7f04003a
net.micode.notes:style/TextAppearanceUnderMenuIcon = 0x7f0b000a
net.micode.notes:id/delete = 0x7f050008
net.micode.notes:drawable/widget_2x_green = 0x7f040039
net.micode.notes:drawable/title_bar_bg = 0x7f040037
net.micode.notes:drawable/menu_delete = 0x7f04002d
net.micode.notes:string/error_sync_internal = 0x7f0a0012
net.micode.notes:drawable/list_green_single = 0x7f04001f
net.micode.notes:string/alert_message_delete_note = 0x7f0a0001
net.micode.notes:id/tv_modified_date = 0x7f05003c
net.micode.notes:drawable/list_blue_middle = 0x7f040018
net.micode.notes:id/iv_small_select = 0x7f05001a
net.micode.notes:menu/note_list_options = 0x7f070005
net.micode.notes:xml/searchable = 0x7f0c0001
net.micode.notes:string/menu_folder_delete = 0x7f0a0025
net.micode.notes:drawable/dropdown_icon = 0x7f040005
net.micode.notes:id/date = 0x7f050007
net.micode.notes:drawable/list_yellow_single = 0x7f04002b
net.micode.notes:drawable/list_red_up = 0x7f040024
net.micode.notes:drawable/widget_4x_yellow = 0x7f040041
net.micode.notes:drawable/list_yellow_middle = 0x7f04002a
net.micode.notes:id/tv_folder_name = 0x7f05003b
net.micode.notes:drawable/list_yellow_down = 0x7f040029
net.micode.notes:string/format_folder_files_count = 0x7f0a001b
net.micode.notes:drawable/clock = 0x7f040003
net.micode.notes:drawable/list_white_up = 0x7f040028
net.micode.notes:drawable/edit_title_blue = 0x7f040009
net.micode.notes:drawable/edit_red = 0x7f040008
net.micode.notes:id/iv_alert_icon = 0x7f05000d
net.micode.notes:layout/dialog_edit_text = 0x7f060003
net.micode.notes:string/preferences_account_title = 0x7f0a0045
net.micode.notes:drawable/edit_white = 0x7f04000e
net.micode.notes:drawable/list_white_middle = 0x7f040026
net.micode.notes:color/user_query_highlight = 0x7f020002
net.micode.notes:drawable/list_white_down = 0x7f040025
net.micode.notes:string/preferences_add_account = 0x7f0a0046
net.micode.notes:drawable/bg_btn_set_color = 0x7f040000
net.micode.notes:string/preferences_bg_random_appear_title = 0x7f0a0047
net.micode.notes:layout/widget_2x = 0x7f06000c
net.micode.notes:drawable/list_footer_bg = 0x7f04001c
net.micode.notes:string/alert_title_delete = 0x7f0a0003
net.micode.notes:drawable/edit_title_green = 0x7f04000a
net.micode.notes:drawable/icon_app = 0x7f040015
net.micode.notes:string/menu_send_to_desktop = 0x7f0a0035
net.micode.notes:drawable/list_red_single = 0x7f040023
net.micode.notes:string/failed_sdcard_export = 0x7f0a0014
net.micode.notes:drawable/widget_4x_red = 0x7f04003f
net.micode.notes:id/menu_delete_remind = 0x7f050022
net.micode.notes:drawable/list_red_down = 0x7f040021
net.micode.notes:drawable/list_red_middle = 0x7f040022
net.micode.notes:id/iv_bg_white = 0x7f050014
net.micode.notes:id/iv_bg_red_select = 0x7f050013
net.micode.notes:string/error_note_empty_for_send_to_desktop = 0x7f0a000d
net.micode.notes:layout/note_list_dropdown_menu = 0x7f060009
net.micode.notes:drawable/list_blue_down = 0x7f040017
net.micode.notes:id/action_select_all = 0x7f050002
net.micode.notes:string/format_datetime_mdhm = 0x7f0a0019
net.micode.notes:drawable/font_small = 0x7f040013
net.micode.notes:string/sync_progress_login = 0x7f0a005e
net.micode.notes:array/menu_share_ways = 0x7f010001
net.micode.notes:drawable/widget_2x_white = 0x7f04003b
net.micode.notes:layout/folder_list_item = 0x7f060004
net.micode.notes:layout/add_account_text = 0x7f060001
net.micode.notes:id/tv_title = 0x7f05003f
net.micode.notes:color/primary_text_dark = 0x7f020000
net.micode.notes:drawable/font_size_selector_bg = 0x7f040012
net.micode.notes:drawable/list_blue_up = 0x7f04001a
net.micode.notes:string/search_setting_description = 0x7f0a0059
net.micode.notes:drawable/list_blue_single = 0x7f040019
net.micode.notes:drawable/font_large = 0x7f040010
net.micode.notes:drawable/delete = 0x7f040004
net.micode.notes:drawable/edit_yellow = 0x7f04000f
net.micode.notes:id/note_item = 0x7f050033
net.micode.notes:drawable/edit_title_white = 0x7f04000c
net.micode.notes:id/note_edit_list = 0x7f050031
net.micode.notes:drawable/edit_title_red = 0x7f04000b
net.micode.notes:string/menu_delete = 0x7f0a0021
net.micode.notes:drawable/list_folder = 0x7f04001b
net.micode.notes:drawable/call_record = 0x7f040002
net.micode.notes:string/search_hint = 0x7f0a0057
net.micode.notes:id/menu_font_size = 0x7f050024
net.micode.notes:drawable/bg_color_btn_mask = 0x7f040001
net.micode.notes:drawable/list_yellow_up = 0x7f04002c
net.micode.notes:dimen/text_font_size_small = 0x7f030003
net.micode.notes:dimen/text_font_size_normal = 0x7f030002
net.micode.notes:drawable/list_green_middle = 0x7f04001e
net.micode.notes:drawable/list_background = 0x7f040016
net.micode.notes:string/app_name = 0x7f0a0004
net.micode.notes:menu/note_list_dropdown = 0x7f070004
net.micode.notes:string/menu_setting = 0x7f0a0036
net.micode.notes:dimen/text_font_size_medium = 0x7f030001
net.micode.notes:layout/note_edit_list_item = 0x7f060006
net.micode.notes:layout/account_dialog_title = 0x7f060000
net.micode.notes:array/format_for_exported_note = 0x7f010000

@ -25,46 +25,54 @@ import android.util.Log;
import java.util.HashMap;
/**
*
*/
public class Contact {
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
// 定义字符串CALLER_ID_SELECTION
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 "
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
//获取联系人
public static String getContact(Context context, String phoneNumber) {
if (sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 查找HashMap中是否已有phoneNumber信息
if (sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
// 查找数据库中phoneNumber的信息
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String[]{Phone.DISPLAY_NAME},
selection,
new String[]{phoneNumber},
null);
// 判定查询结果
// moveToFirst()返回第一条
if (cursor != null && cursor.moveToFirst()) {
try {
// 找到相关信息
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();
}
// 未找到相关信息
} else {
Log.d(TAG, "No contact matched with number:" + phoneNumber);
return null;

@ -26,6 +26,7 @@ import android.net.Uri;
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
//以下三个常量对NoteColumns.TYPE的值进行设置时会用到
public static final int TYPE_NOTE = 0;
public static final int TYPE_FOLDER = 1;
public static final int TYPE_SYSTEM = 2;
@ -172,7 +173,7 @@ public class Notes {
*/
public static final String VERSION = "version";
}
// 定义DataColumns的常量,用于后面创建数据库的表头
public interface DataColumns {
/**
* The unique ID for a row
@ -245,7 +246,7 @@ public class Notes {
* <P> Type: TEXT </P>
*/
public static final String DATA5 = "data5";
}
}//主要是定义存储便签内容数据的
public static final class TextNote implements DataColumns {
/**
@ -261,7 +262,7 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
}//文本内容的数据结构
public static final class CallNote implements DataColumns {
/**
@ -281,5 +282,5 @@ public class Notes {
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/call_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/call_note");
}
}//电话内容的数据结构
}

@ -32,7 +32,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final int DB_VERSION = 4;
public interface TABLE {
public interface TABLE {//接口分成note和data在后面的程序里分别使用过
public static final String NOTE = "note";
public static final String DATA = "data";
@ -61,7 +61,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")";
")";//数据库中需要存储的项目的名称,就相当于创建一个表格的表头的内容。
private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" +
@ -76,11 +76,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")";
")";//和上面的功能一样,主要是存储的项目不同
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";//存储便签编号的一个数据表格
/**
* Increase folder's note count when move note to the folder
@ -92,7 +92,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" UPDATE " + TABLE.NOTE +
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
" END";
" END";//在文件夹中移入一个Note之后需要更改的数据的表格。
/**
* Decrease folder's note count when move note from folder
@ -105,7 +105,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
" AND " + NoteColumns.NOTES_COUNT + ">0" + ";" +
" END";
" END";//在文件夹中移出一个Note之后需要更改的数据的表格。
/**
* Increase folder's note count when insert new note to the folder
@ -117,7 +117,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" UPDATE " + TABLE.NOTE +
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
" END";
" END";//在文件夹中插入一个Note之后需要更改的数据的表格。
/**
* Decrease folder's note count when delete note from the folder
@ -130,7 +130,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
" AND " + NoteColumns.NOTES_COUNT + ">0;" +
" END";
" END";//在文件夹中删除一个Note之后需要更改的数据的表格。
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
@ -143,7 +143,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" UPDATE " + TABLE.NOTE +
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
" END";
" END";//在文件夹中对一个Note导入新的数据之后需要更改的数据的表格。
/**
* Update note's content when data with {@link DataConstants#NOTE} type has changed
@ -156,7 +156,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" UPDATE " + TABLE.NOTE +
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
" END";
" END";//Note数据被修改后需要更改的数据的表格。
/**
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
@ -169,7 +169,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" UPDATE " + TABLE.NOTE +
" SET " + NoteColumns.SNIPPET + "=''" +
" WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" +
" END";
" END";//Note数据被删除后需要更改的数据的表格。
/**
* Delete datas belong to note which has been deleted
@ -180,7 +180,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" BEGIN" +
" DELETE FROM " + TABLE.DATA +
" WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" +
" END";
" END";//删除已删除的便签的数据后需要更改的数据的表格。
/**
* Delete notes belong to folder which has been deleted
@ -191,7 +191,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" BEGIN" +
" DELETE FROM " + TABLE.NOTE +
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
" END";//删除已删除的文件夹的便签后需要更改的数据的表格。
/**
* Move notes belong to folder which has been moved to trash folder
@ -204,18 +204,18 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" UPDATE " + TABLE.NOTE +
" SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
" END";//还原垃圾桶中便签后需要更改的数据的表格。
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
//构造函数,传入数据库的名称和版本
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
createSystemFolder(db);
Log.d(TAG, "note table has been created");
}
}//构造函数,传入数据库的名称和版本
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
@ -233,7 +233,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER);
db.execSQL(FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER);
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
}//execSQL是数据库操作的API主要是更改行为的SQL语句。
//在这里主要是用来重新创建上述定义的表格用的,先删除原来有的数据库的触发器再重新创建新的数据库
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
@ -268,14 +269,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
values.put(NoteColumns.ID, Notes.ID_TRASH_FOLER);
values.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM);
db.insert(TABLE.NOTE, null, values);
}
}//创建几个系统文件夹
public void createDataTable(SQLiteDatabase db) {
db.execSQL(CREATE_DATA_TABLE_SQL);
reCreateDataTableTriggers(db);
db.execSQL(CREATE_DATA_NOTE_ID_INDEX_SQL);
Log.d(TAG, "data table has been created");
}
}//创建表格(用来存储标签内容)
private void reCreateDataTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
@ -285,20 +286,22 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER);
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER);
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
}//同上面的execSQL
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
}
return mInstance;
}
}//上网查是为解决同一时刻只能有一个线程执行.
//在写程序库代码时,有时有一个类需要被所有的其它类使用,
//但又要求这个类只能被实例化一次,是个服务类,定义一次,其它类使用同一个这个类的实例
@Override
public void onCreate(SQLiteDatabase db) {
createNoteTable(db);
createDataTable(db);
}
}//实现两个表格(上面创建的两个表格)
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@ -331,7 +334,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
throw new IllegalStateException("Upgrade notes database to version " + newVersion
+ "fails");
}
}
}//数据库版本的更新(数据库内容的更改)
private void upgradeToV2(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);

@ -34,8 +34,17 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
/**
*
* ContentProvider
* query
* insert
* update
* update
* getType
*/
public class NotesProvider extends ContentProvider {
// UriMatcher用于匹配Uri
private static final UriMatcher mMatcher;
private NotesDatabaseHelper mHelper;
@ -51,7 +60,9 @@ public class NotesProvider extends ContentProvider {
private static final int URI_SEARCH_SUGGEST = 6;
static {
// 创建UriMatcher时调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
// 创建UriMatcher时调用UriMatcher(UriMatcher.NO_MATCH)表示不匹配任何路径的返回码
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
@ -80,18 +91,24 @@ public class NotesProvider extends ContentProvider {
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
@Override
// Context只有在onCreate()中才被初始化
// 对mHelper进行实例化
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
@Override
// 查询uri在数据库中对应的位置
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
Cursor c = null;
// 获取可读数据库
SQLiteDatabase db = mHelper.getReadableDatabase();
String id = null;
// 匹配查找uri
switch (mMatcher.match(uri)) {
// 对于不同的匹配值,在数据库中查找相应的条目
case URI_NOTE:
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
sortOrder);
@ -113,6 +130,7 @@ public class NotesProvider extends ContentProvider {
case URI_SEARCH:
case URI_SEARCH_SUGGEST:
if (sortOrder != null || projection != null) {
// 不合法的参数异常
throw new IllegalArgumentException(
"do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
}
@ -120,6 +138,8 @@ public class NotesProvider extends ContentProvider {
String searchString = null;
if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
if (uri.getPathSegments().size() > 1) {
// getPathSegments()方法得到一个String的List
// 在uri.getPathSegments().get(1)为第2个元素
searchString = uri.getPathSegments().get(1);
}
} else {
@ -139,6 +159,7 @@ public class NotesProvider extends ContentProvider {
}
break;
default:
//抛出异常
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (c != null) {
@ -148,7 +169,9 @@ public class NotesProvider extends ContentProvider {
}
@Override
// 插入一个uri
public Uri insert(Uri uri, ContentValues values) {
// 插入一个uri
SQLiteDatabase db = mHelper.getWritableDatabase();
long dataId = 0, noteId = 0, insertedId = 0;
switch (mMatcher.match(uri)) {
@ -183,8 +206,10 @@ public class NotesProvider extends ContentProvider {
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
//Uri代表要操作的数据Android上可用的每种资源 -包括 图像、视频片段、音频资源等都可以用Uri来表示。
int count = 0;
String id = null;
// 获得可写的数据库
SQLiteDatabase db = mHelper.getWritableDatabase();
boolean deleteData = false;
switch (mMatcher.match(uri)) {
@ -266,11 +291,11 @@ public class NotesProvider extends ContentProvider {
}
return count;
}
// 将字符串解析成规定格式
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
//增加一个noteVersion
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@ -292,7 +317,7 @@ public class NotesProvider extends ContentProvider {
}
sql.append(selectString);
}
// execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句
mHelper.getWritableDatabase().execSQL(sql.toString());
}

@ -16,8 +16,11 @@
package net.micode.notes.gtask.exception;
/**
* 便
*/
public class ActionFailureException extends RuntimeException {
private static final long serialVersionUID = 4425249765923293627L;
private static final long serialVersionUID = 4425249765923293627L;//serialVersionUID用于版本控制
public ActionFailureException() {
super();

@ -16,6 +16,9 @@
package net.micode.notes.gtask.exception;
/**
*
*/
public class NetworkFailureException extends Exception {
private static final long serialVersionUID = 2107610287180234136L;

Binary file not shown.

Binary file not shown.

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading…
Cancel
Save