pull/4/head
p9j8zlmnf 2 years ago
commit 31bf7c5828

@ -36,15 +36,23 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
/**
*
*
*/
public static String getContact(Context context, String phoneNumber) {
if (sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
// 查找HashMap中是否已有phoneNumber信息如果存在则返回phoneNumber信息
if (sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
/**
* phoneNumber
*/
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
Cursor cursor = context.getContentResolver().query(
@ -54,12 +62,22 @@ public class Contact {
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) {
}
/**
*
*/
catch (IndexOutOfBoundsException e) {
Log.e(TAG, " Cursor get string error " + e.toString());
return null;
} finally {

@ -67,6 +67,9 @@ public class Notes {
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
/**
* NoteColumns,
*/
public interface NoteColumns {
/**
* The unique ID for a row
@ -172,6 +175,9 @@ public class Notes {
*/
public static final String VERSION = "version";
}
/**
* 便
*/
public interface DataColumns {
/**
@ -245,7 +251,9 @@ public class Notes {
* <P> Type: TEXT </P>
*/
public static final String DATA5 = "data5";
}
}/**
* DATA便
*/
public static final class TextNote implements DataColumns {
/**
@ -261,7 +269,9 @@ 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 +291,7 @@ 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");
}
}/**
*
*/
}

@ -26,7 +26,9 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
/**
*note
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db";
@ -42,6 +44,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static NotesDatabaseHelper mInstance;
/**
*
*/
private static final String CREATE_NOTE_TABLE_SQL =
"CREATE TABLE " + TABLE.NOTE + "(" +
NoteColumns.ID + " INTEGER PRIMARY KEY," +
@ -63,6 +68,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")";
/**
*
*/
private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" +
DataColumns.ID + " INTEGER PRIMARY KEY," +
@ -78,12 +86,16 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
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 + ");";
/**
* Increase folder's note count when move note to the folder
* Note
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update " +
@ -96,6 +108,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Decrease folder's note count when move note from folder
* Note
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
@ -109,6 +122,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Increase folder's note count when insert new note to the folder
* Note
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
@ -121,6 +135,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Decrease folder's note count when delete note from the folder
* Note
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
@ -134,6 +149,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
* Note
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
@ -147,6 +163,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Update note's content when data with {@link DataConstants#NOTE} type has changed
* Note
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER update_note_content_on_update " +
@ -160,6 +177,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
* Note
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
"CREATE TRIGGER update_note_content_on_delete " +
@ -173,6 +191,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Delete datas belong to note which has been deleted
* 便
*/
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
@ -184,6 +203,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
/**
* Delete notes belong to folder which has been deleted
* 便
*/
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
@ -208,8 +228,11 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
}/**构造函数,传入数据库的名称和版本*/
/**
*
*/
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
@ -217,6 +240,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "note table has been created");
}
/**
*
*/
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
@ -294,6 +320,9 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
return mInstance;
}
/**
*
*/
@Override
public void onCreate(SQLiteDatabase db) {
createNoteTable(db);

@ -35,6 +35,15 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
/**
*
* ContentProvider
* query
* insert
* update
* delete
* getType
*/
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
@ -79,12 +88,19 @@ public class NotesProvider extends ContentProvider {
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
/**
* onCreate()Context
* mHelper
*/
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
/**
*uri
*/
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
@ -112,6 +128,9 @@ public class NotesProvider extends ContentProvider {
break;
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");
@ -147,6 +166,9 @@ public class NotesProvider extends ContentProvider {
return c;
}
/**
* uri
*/
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -181,6 +203,9 @@ public class NotesProvider extends ContentProvider {
return ContentUris.withAppendedId(uri, insertedId);
}
/**
* uri
*/
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
@ -227,6 +252,9 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
* uri
*/
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
@ -267,6 +295,9 @@ public class NotesProvider extends ContentProvider {
return count;
}
/**
*
*/
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
@ -292,7 +323,7 @@ public class NotesProvider extends ContentProvider {
}
sql.append(selectString);
}
/** execSQL()方法可以执行insert、delete、update和CREATE TABLE之类有更改行为的SQL语句 */
mHelper.getWritableDatabase().execSQL(sql.toString());
}

@ -53,7 +53,9 @@ public class Note {
values.put(NoteColumns.LOCAL_MODIFIED, 1);
values.put(NoteColumns.PARENT_ID, folderId);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);
/**
ContentResolver()ContentProvider
*/
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1));
@ -67,6 +69,9 @@ public class Note {
return noteId;
}
/**
便便便
*/
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
@ -81,18 +86,30 @@ public class Note {
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
/**
ID
*/
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
/**
ID
*/
public long getTextDataId() {
return mNoteData.mTextDataId;
}
/**
ID
*/
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
/**
ID
*/
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
@ -132,6 +149,9 @@ public class Note {
return true;
}
/**
* 便
*/
private class NoteData {
private long mTextDataId;
@ -187,6 +207,9 @@ public class Note {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
/**
*
*/
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null;
@ -212,6 +235,9 @@ public class Note {
}
mTextDataValues.clear();
}
/**
* DataColumns
*/
if (mCallDataValues.size() > 0) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId);

@ -62,6 +62,9 @@ public class WorkingNote {
private NoteSettingChangedListener mNoteSettingStatusListener;
/**
* DATA_PROJECTION
*/
public static final String[] DATA_PROJECTION = new String[]{
DataColumns.ID,
DataColumns.CONTENT,
@ -102,6 +105,10 @@ public class WorkingNote {
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
/**
* WorkingNote
* */
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
@ -124,6 +131,9 @@ public class WorkingNote {
loadNote();
}
/**
* query
*/
private void loadNote() {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
@ -151,7 +161,9 @@ public class WorkingNote {
DataColumns.NOTE_ID + "=?", new String[]{
String.valueOf(mNoteId)
}, null);
/**
*
*/
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
@ -174,6 +186,9 @@ public class WorkingNote {
}
}
/**
* Note contextidwidget
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
@ -229,6 +244,10 @@ public class WorkingNote {
mNoteSettingStatusListener = l;
}
/**
* AlertDate
* mAlertDatedatamAlertDateNoteValue
*/
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
@ -239,6 +258,9 @@ public class WorkingNote {
}
}
/**
*
*/
public void markDeleted(boolean mark) {
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -247,6 +269,9 @@ public class WorkingNote {
}
}
/**
*
*/
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
@ -257,6 +282,9 @@ public class WorkingNote {
}
}
/**
*
*/
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
@ -267,6 +295,9 @@ public class WorkingNote {
}
}
/**
*WidgetType
*/
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
@ -274,6 +305,9 @@ public class WorkingNote {
}
}
/**
*WidgetId
*/
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
@ -281,6 +315,9 @@ public class WorkingNote {
}
}
/**
*setWorkingText
*/
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;

Loading…
Cancel
Save