为ui包、model包、widget包以及MainActivity.java添加代码注释 #3

Merged
p3f2h9ljk merged 5 commits from taojunyu_branch into master 3 weeks ago

@ -1,5 +1,13 @@
package net.micode.notes;
/**
*
* <p>
*
* </p>
*/
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
@ -10,6 +18,15 @@ import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
/**
*
* <p>
*
* UI
* </p>
*
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

@ -34,12 +34,38 @@ import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
/**
*
* <p>
*
* ContentResolver
* </p>
*/
public class Note {
/**
*
*/
private ContentValues mNoteDiffValues;
/**
*
*/
private NoteData mNoteData;
private static final String TAG = "Note";
/**
*
*/
private static final String TAG = Note.class.getSimpleName();
/**
* Create a new note id for adding a new note to databases
* ID
* <p>
* ID
*
* </p>
*
* @param context ContentResolver
* @param folderId ID
* @return ID
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// Create a new note in the database
@ -65,41 +91,114 @@ public class Note {
return noteId;
}
/**
*
*/
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
/**
*
* <p>
*
* </p>
*
* @param key NoteColumns
* @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());
}
/**
*
* <p>
*
* </p>
*
* @param key TextNote
* @param value
*/
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
/**
* ID
* <p>
* ID
* </p>
*
* @param id ID
*/
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
/**
* ID
* <p>
* ID
* </p>
*
* @return ID
*/
public long getTextDataId() {
return mNoteData.mTextDataId;
}
/**
* ID
* <p>
* ID
* </p>
*
* @param id ID
*/
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
/**
*
* <p>
*
* </p>
*
* @param key CallNote
* @param value
*/
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
}
/**
*
* <p>
*
* </p>
*
* @return truefalse
*/
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
/**
*
* <p>
*
*
* </p>
*
* @param context ContentResolver
* @param noteId ID
* @return truefalse
*/
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
@ -130,17 +229,42 @@ public class Note {
return true;
}
/**
*
* <p>
*
*
* </p>
*/
private class NoteData {
/**
* ID
*/
private long mTextDataId;
/**
*
*/
private ContentValues mTextDataValues;
/**
* ID
*/
private long mCallDataId;
/**
*
*/
private ContentValues mCallDataValues;
private static final String TAG = "NoteData";
/**
*
*/
private static final String TAG = NoteData.class.getSimpleName();
/**
*
*/
public NoteData() {
mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues();
@ -148,10 +272,26 @@ public class Note {
mCallDataId = 0;
}
/**
*
* <p>
*
* </p>
*
* @return truefalse
*/
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
/**
* ID
* <p>
* ID
* </p>
*
* @param id ID
*/
void setTextDataId(long id) {
if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0");
@ -159,6 +299,14 @@ public class Note {
mTextDataId = id;
}
/**
* ID
* <p>
* ID
* </p>
*
* @param id ID
*/
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0");
@ -166,18 +314,47 @@ public class Note {
mCallDataId = id;
}
/**
*
* <p>
*
* </p>
*
* @param key CallNote
* @param value
*/
void setCallData(String key, String value) {
mCallDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
* <p>
*
* </p>
*
* @param key TextNote
* @param value
*/
void setTextData(String key, String value) {
mTextDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
* ContentResolver
* <p>
*
* ID0
* </p>
*
* @param context ContentResolver
* @param noteId ID
* @return URInull
*/
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* Check for safety

@ -32,36 +32,87 @@ import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
* UI
* <p>
*
* UIUI
* </p>
*/
public class WorkingNote {
// Note for the working note
/**
*
*/
private Note mNote;
// Note Id
/**
* ID
*/
private long mNoteId;
// Note content
/**
*
*/
private String mContent;
// Note mode
/**
*
*/
private int mMode;
/**
*
*/
private long mAlertDate;
/**
*
*/
private long mModifiedDate;
/**
* ID
*/
private int mBgColorId;
/**
* ID
*/
private int mWidgetId;
/**
*
*/
private int mWidgetType;
/**
* ID
*/
private long mFolderId;
/**
*
*/
private Context mContext;
private static final String TAG = "WorkingNote";
/**
*
*/
private static final String TAG = WorkingNote.class.getSimpleName();
/**
*
*/
private boolean mIsDeleted;
/**
*
*/
private NoteSettingChangedListener mNoteSettingStatusListener;
/**
* ContentResolver
*/
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
@ -72,6 +123,9 @@ public class WorkingNote {
DataColumns.DATA4,
};
/**
* ContentResolver
*/
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
@ -81,27 +135,66 @@ public class WorkingNote {
NoteColumns.MODIFIED_DATE
};
/**
* ID
*/
private static final int DATA_ID_COLUMN = 0;
/**
*
*/
private static final int DATA_CONTENT_COLUMN = 1;
/**
*
*/
private static final int DATA_MIME_TYPE_COLUMN = 2;
/**
*
*/
private static final int DATA_MODE_COLUMN = 3;
/**
* ID
*/
private static final int NOTE_PARENT_ID_COLUMN = 0;
/**
*
*/
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
/**
* ID
*/
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
/**
* ID
*/
private static final int NOTE_WIDGET_ID_COLUMN = 3;
/**
*
*/
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
/**
*
*/
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
// New note construct
/**
*
* <p>
*
* </p>
*
* @param context
* @param folderId ID
*/
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
@ -115,6 +208,16 @@ public class WorkingNote {
}
// Existing note construct
/**
*
* <p>
* ID
* </p>
*
* @param context
* @param noteId ID
* @param folderId ID
*/
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
@ -124,6 +227,13 @@ public class WorkingNote {
loadNote();
}
/**
*
* <p>
* ContentResolverID
*
* </p>
*/
private void loadNote() {
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
@ -146,6 +256,12 @@ public class WorkingNote {
loadNoteData();
}
/**
*
* <p>
* ContentResolver
* </p>
*/
private void loadNoteData() {
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
@ -174,6 +290,19 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
* </p>
*
* @param context
* @param folderId ID
* @param widgetId ID
* @param widgetType
* @param defaultBgColorId ID
* @return
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
@ -183,10 +312,29 @@ public class WorkingNote {
return note;
}
/**
*
* <p>
* ID
* </p>
*
* @param context
* @param id ID
* @return
*/
public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0);
}
/**
*
* <p>
*
*
* </p>
*
* @return truefalse
*/
public synchronized boolean saveNote() {
if (isWorthSaving()) {
if (!existInDatabase()) {
@ -212,10 +360,27 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
* </p>
*
* @return truefalse
*/
public boolean existInDatabase() {
return mNoteId > 0;
}
/**
*
* <p>
*
*
* </p>
*
* @return truefalse
*/
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
@ -225,10 +390,28 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
*
* </p>
*
* @param l
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
/**
*
* <p>
*
* </p>
*
* @param date
* @param set
*/
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
@ -239,6 +422,14 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
* </p>
*
* @param mark
*/
public void markDeleted(boolean mark) {
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
@ -247,6 +438,14 @@ public class WorkingNote {
}
}
/**
* ID
* <p>
* ID
* </p>
*
* @param id ID
*/
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
@ -257,6 +456,14 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
* </p>
*
* @param mode
*/
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
@ -267,6 +474,14 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
* </p>
*
* @param type
*/
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
@ -274,6 +489,14 @@ public class WorkingNote {
}
}
/**
* ID
* <p>
* ID
* </p>
*
* @param id ID
*/
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
@ -281,6 +504,14 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
* </p>
*
* @param text
*/
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;
@ -288,80 +519,208 @@ public class WorkingNote {
}
}
/**
*
* <p>
*
* </p>
*
* @param phoneNumber
* @param callDate
*/
public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
}
/**
*
* <p>
*
* </p>
*
* @return truefalse
*/
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
/**
*
* <p>
*
* </p>
*
* @return
*/
public String getContent() {
return mContent;
}
/**
*
* <p>
*
* </p>
*
* @return
*/
public long getAlertDate() {
return mAlertDate;
}
/**
*
* <p>
*
* </p>
*
* @return
*/
public long getModifiedDate() {
return mModifiedDate;
}
/**
* ID
* <p>
* IDID
* </p>
*
* @return ID
*/
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
/**
* ID
* <p>
* ID
* </p>
*
* @return ID
*/
public int getBgColorId() {
return mBgColorId;
}
/**
* ID
* <p>
* IDID
* </p>
*
* @return ID
*/
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
/**
*
* <p>
*
* </p>
*
* @return
*/
public int getCheckListMode() {
return mMode;
}
/**
* ID
* <p>
* ID
* </p>
*
* @return ID
*/
public long getNoteId() {
return mNoteId;
}
/**
* ID
* <p>
* ID
* </p>
*
* @return ID
*/
public long getFolderId() {
return mFolderId;
}
/**
* ID
* <p>
* ID
* </p>
*
* @return ID
*/
public int getWidgetId() {
return mWidgetId;
}
/**
*
* <p>
*
* </p>
*
* @return
*/
public int getWidgetType() {
return mWidgetType;
}
/**
*
* <p>
*
*
* </p>
*/
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
*
* <p>
*
* </p>
*/
void onBackgroundColorChanged();
/**
* Called when user set clock
*
* <p>
*
* </p>
*
* @param date
* @param set
*/
void onClockAlertChanged(long date, boolean set);
/**
* Call when user create note from widget
*
* <p>
*
* </p>
*/
void onWidgetChanged();
/**
* Call when switch between check list mode and normal mode
* @param oldMode is previous mode before change
* @param newMode is new mode
*
* <p>
*
* </p>
*
* @param oldMode
* @param newMode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}

@ -40,12 +40,48 @@ import net.micode.notes.tool.DataUtils;
import java.io.IOException;
/**
*
* <p>
*
*
* </p>
*/
public class AlarmAlertActivity extends Activity implements OnClickListener, OnDismissListener {
/**
* ID
*/
private long mNoteId;
/**
*
*/
private String mSnippet;
/**
*
*/
private static final int SNIPPET_PREW_MAX_LEN = 60;
/**
*
*/
MediaPlayer mPlayer;
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4. IntentID
* 5. MediaPlayer
* 6.
* 7.
* </p>
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -83,11 +119,31 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
}
/**
*
* <p>
* PowerManager
* </p>
* @return truefalse
*/
private boolean isScreenOn() {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
return pm.isScreenOn();
}
/**
*
* <p>
*
* 1. URI
* 2. 使
* 3.
* 4. MediaPlayerURI
* 5. MediaPlayer
* 6.
* 7.
* </p>
*/
private void playAlarmSound() {
Uri url = RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_ALARM);
@ -119,6 +175,17 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4.
* 5.
* </p>
*/
private void showActionDialog() {
AlertDialog.Builder dialog = new AlertDialog.Builder(this);
dialog.setTitle(R.string.app_name);
@ -130,6 +197,18 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
dialog.show().setOnDismissListener(this);
}
/**
*
* <p>
* OnClickListener
* 1. IntentNoteEditActivity
* 2. IntentActionACTION_VIEWID
* 3. NoteEditActivity
* 4.
* </p>
* @param dialog
* @param which IDDialogInterface
*/
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_NEGATIVE:
@ -143,11 +222,29 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
}
/**
*
* <p>
* OnDismissListener
*
* </p>
* @param dialog
*/
public void onDismiss(DialogInterface dialog) {
stopAlarmSound();
finish();
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4. null
* </p>
*/
private void stopAlarmSound() {
if (mPlayer != null) {
mPlayer.stop();

@ -28,16 +28,44 @@ import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
* 广
* <p>
* 广
*
* </p>
*/
public class AlarmInitReceiver extends BroadcastReceiver {
/**
*
* <p>
* ID
* </p>
*/
private static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE
};
/**
* ID
*/
private static final int COLUMN_ID = 0;
/**
*
*/
private static final int COLUMN_ALERTED_DATE = 1;
/**
* 广
* <p>
* 广
* 使AlarmManager
* </p>
* @param context
* @param intent 广
*/
@Override
public void onReceive(Context context, Intent intent) {
long currentDate = System.currentTimeMillis();
@ -54,8 +82,8 @@ public class AlarmInitReceiver extends BroadcastReceiver {
Intent sender = new Intent(context, AlarmReceiver.class);
sender.setData(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, c.getLong(COLUMN_ID)));
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, sender, 0);
AlarmManager alermManager = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
AlarmManager alermManager = (AlarmManager)
context.getSystemService(Context.ALARM_SERVICE);
alermManager.set(AlarmManager.RTC_WAKEUP, alertDate, pendingIntent);
} while (c.moveToNext());
}

@ -20,7 +20,21 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* 广
* <p>
* 广
* </p>
*/
public class AlarmReceiver extends BroadcastReceiver {
/**
* 广
* <p>
* AlarmAlertActivity
* </p>
* @param context
* @param intent 广
*/
@Override
public void onReceive(Context context, Intent intent) {
intent.setClass(context, AlarmAlertActivity.class);

@ -28,40 +28,139 @@ import android.view.View;
import android.widget.FrameLayout;
import android.widget.NumberPicker;
/**
*
* <p>
* FrameLayout便
* 12/24NumberPicker
* AM/PM
* </p>
*/
public class DateTimePicker extends FrameLayout {
/**
*
*/
private static final boolean DEFAULT_ENABLE_STATE = true;
/**
* 12
*/
private static final int HOURS_IN_HALF_DAY = 12;
/**
* 24
*/
private static final int HOURS_IN_ALL_DAY = 24;
/**
* 7
*/
private static final int DAYS_IN_ALL_WEEK = 7;
/**
*
*/
private static final int DATE_SPINNER_MIN_VAL = 0;
/**
*
*/
private static final int DATE_SPINNER_MAX_VAL = DAYS_IN_ALL_WEEK - 1;
/**
* 24
*/
private static final int HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW = 0;
/**
* 24
*/
private static final int HOUR_SPINNER_MAX_VAL_24_HOUR_VIEW = 23;
/**
* 12
*/
private static final int HOUR_SPINNER_MIN_VAL_12_HOUR_VIEW = 1;
/**
* 12
*/
private static final int HOUR_SPINNER_MAX_VAL_12_HOUR_VIEW = 12;
/**
*
*/
private static final int MINUT_SPINNER_MIN_VAL = 0;
/**
*
*/
private static final int MINUT_SPINNER_MAX_VAL = 59;
/**
* AM/PM
*/
private static final int AMPM_SPINNER_MIN_VAL = 0;
/**
* AM/PM
*/
private static final int AMPM_SPINNER_MAX_VAL = 1;
/**
*
*/
private final NumberPicker mDateSpinner;
/**
*
*/
private final NumberPicker mHourSpinner;
/**
*
*/
private final NumberPicker mMinuteSpinner;
/**
* AM/PM
*/
private final NumberPicker mAmPmSpinner;
/**
*
*/
private Calendar mDate;
/**
*
*/
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
/**
*
*/
private boolean mIsAm;
/**
* 24
*/
private boolean mIs24HourView;
/**
*
*/
private boolean mIsEnabled = DEFAULT_ENABLE_STATE;
/**
*
*/
private boolean mInitialising;
/**
*
*/
private OnDateTimeChangedListener mOnDateTimeChangedListener;
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
@ -158,19 +257,49 @@ public class DateTimePicker extends FrameLayout {
}
};
/**
*
* <p>
*
* </p>
*/
public interface OnDateTimeChangedListener {
/**
*
* @param view
* @param year
* @param month 0-11
* @param dayOfMonth 1-31
* @param hourOfDay 0-23
* @param minute 0-59
*/
void onDateTimeChanged(DateTimePicker view, int year, int month,
int dayOfMonth, int hourOfDay, int minute);
}
/**
* 使
* @param context
*/
public DateTimePicker(Context context) {
this(context, System.currentTimeMillis());
}
/**
* 使使24
* @param context
* @param date
*/
public DateTimePicker(Context context, long date) {
this(context, date, DateFormat.is24HourFormat(context));
}
/**
* 使
* @param context
* @param date
* @param is24HourView 使24
*/
public DateTimePicker(Context context, long date, boolean is24HourView) {
super(context);
mDate = Calendar.getInstance();
@ -348,6 +477,15 @@ public class DateTimePicker extends FrameLayout {
return mDate.get(Calendar.HOUR_OF_DAY);
}
/**
*
* <p>
*
* - 240-23
* - 121-12
* </p>
* @return
*/
private int getCurrentHour() {
if (mIs24HourView){
return getCurrentHourOfDay();
@ -362,9 +500,8 @@ public class DateTimePicker extends FrameLayout {
}
/**
* Set current hour in 24 hour mode, in the range (0~23)
*
* @param hourOfDay
* 240-23
* @param hourOfDay 24
*/
public void setCurrentHour(int hourOfDay) {
if (!mInitialising && hourOfDay == getCurrentHourOfDay()) {
@ -390,16 +527,16 @@ public class DateTimePicker extends FrameLayout {
}
/**
* Get currentMinute
*
* @return The Current Minute
*
* @return 0-59
*/
public int getCurrentMinute() {
return mDate.get(Calendar.MINUTE);
}
/**
* Set current minute
*
* @param minute 0-59
*/
public void setCurrentMinute(int minute) {
if (!mInitialising && minute == getCurrentMinute()) {
@ -411,16 +548,16 @@ public class DateTimePicker extends FrameLayout {
}
/**
* @return true if this is in 24 hour view else false.
* 24
* @return true24false12
*/
public boolean is24HourView () {
return mIs24HourView;
}
/**
* Set whether in 24 hour or AM/PM mode.
*
* @param is24HourView True for 24 hour mode. False for AM/PM mode.
* 使24AM/PM
* @param is24HourView true使24false使AM/PM
*/
public void set24HourView(boolean is24HourView) {
if (mIs24HourView == is24HourView) {
@ -434,6 +571,12 @@ public class DateTimePicker extends FrameLayout {
updateAmPmControl();
}
/**
*
* <p>
*
* </p>
*/
private void updateDateControl() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(mDate.getTimeInMillis());
@ -448,6 +591,12 @@ public class DateTimePicker extends FrameLayout {
mDateSpinner.invalidate();
}
/**
* AM/PM
* <p>
* AM/PM
* </p>
*/
private void updateAmPmControl() {
if (mIs24HourView) {
mAmPmSpinner.setVisibility(View.GONE);
@ -458,6 +607,12 @@ public class DateTimePicker extends FrameLayout {
}
}
/**
*
* <p>
*
* </p>
*/
private void updateHourControl() {
if (mIs24HourView) {
mHourSpinner.setMinValue(HOUR_SPINNER_MIN_VAL_24_HOUR_VIEW);
@ -469,13 +624,19 @@ public class DateTimePicker extends FrameLayout {
}
/**
* Set the callback that indicates the 'Set' button has been pressed.
* @param callback the callback, if null will do nothing
*
* @param callback null
*/
public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) {
mOnDateTimeChangedListener = callback;
}
/**
*
* <p>
*
* </p>
*/
private void onDateTimeChanged() {
if (mOnDateTimeChangedListener != null) {
mOnDateTimeChangedListener.onDateTimeChanged(this, getCurrentYear(),

@ -29,17 +29,55 @@ import android.content.DialogInterface.OnClickListener;
import android.text.format.DateFormat;
import android.text.format.DateUtils;
/**
*
* <p>
* DateTimePicker便
*
*
* </p>
*/
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
/**
*
*/
private Calendar mDate = Calendar.getInstance();
/**
* 使24
*/
private boolean mIs24HourView;
/**
*
*/
private OnDateTimeSetListener mOnDateTimeSetListener;
/**
*
*/
private DateTimePicker mDateTimePicker;
/**
*
* <p>
*
* </p>
*/
public interface OnDateTimeSetListener {
/**
*
* @param dialog
* @param date
*/
void OnDateTimeSet(AlertDialog dialog, long date);
}
/**
* 使
* @param context
* @param date
*/
public DateTimePickerDialog(Context context, long date) {
super(context);
mDateTimePicker = new DateTimePicker(context);
@ -64,14 +102,29 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
updateTitle(mDate.getTimeInMillis());
}
/**
* 使24
* @param is24HourView true使24false使12
*/
public void set24HourView(boolean is24HourView) {
mIs24HourView = is24HourView;
}
/**
*
* @param callBack
*/
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
mOnDateTimeSetListener = callBack;
}
/**
*
* <p>
*
* </p>
* @param date
*/
private void updateTitle(long date) {
int flag =
DateUtils.FORMAT_SHOW_YEAR |
@ -81,6 +134,15 @@ public class DateTimePickerDialog extends AlertDialog implements OnClickListener
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
}
/**
*
* <p>
*
* </p>
* @param arg0
* @param arg1 ID
*/
@Override
public void onClick(DialogInterface arg0, int arg1) {
if (mOnDateTimeSetListener != null) {
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());

@ -27,11 +27,34 @@ import android.widget.PopupMenu.OnMenuItemClickListener;
import net.micode.notes.R;
/**
*
* <p>
* AndroidPopupMenu
* </p>
*/
public class DropdownMenu {
/**
*
*/
private Button mButton;
/**
*
*/
private PopupMenu mPopupMenu;
/**
*
*/
private Menu mMenu;
/**
*
* @param context
* @param button
* @param menuId ID
*/
public DropdownMenu(Context context, Button button, int menuId) {
mButton = button;
mButton.setBackgroundResource(R.drawable.dropdown_icon);
@ -45,16 +68,29 @@ public class DropdownMenu {
});
}
/**
*
* @param listener
*/
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
if (mPopupMenu != null) {
mPopupMenu.setOnMenuItemClickListener(listener);
}
}
/**
* ID
* @param id ID
* @return IDnull
*/
public MenuItem findItem(int id) {
return mMenu.findItem(id);
}
/**
*
* @param title
*/
public void setTitle(CharSequence title) {
mButton.setText(title);
}

@ -29,25 +29,62 @@ import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
/**
*
* <p>
* CursorAdapter便
* </p>
*/
public class FoldersListAdapter extends CursorAdapter {
/**
*
* <p>
* ID
* </p>
*/
public static final String [] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
};
/**
* ID
*/
public static final int ID_COLUMN = 0;
/**
*
*/
public static final int NAME_COLUMN = 1;
/**
*
* @param context
* @param c
*/
public FoldersListAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
/**
*
* @param context
* @param cursor
* @param parent
* @return
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new FolderListItem(context);
}
/**
*
* @param view
* @param context
* @param cursor
*/
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof FolderListItem) {
@ -57,21 +94,44 @@ public class FoldersListAdapter extends CursorAdapter {
}
}
/**
*
* @param context
* @param position
* @return
*/
public String getFolderName(Context context, int position) {
Cursor cursor = (Cursor) getItem(position);
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
}
/**
*
* <p>
*
* </p>
*/
private class FolderListItem extends LinearLayout {
/**
*
*/
private TextView mName;
/**
*
* @param context
*/
public FolderListItem(Context context) {
super(context);
inflate(context, R.layout.folder_list_item, this);
mName = (TextView) findViewById(R.id.tv_folder_name);
}
/**
*
* @param name
*/
public void bind(String name) {
mName.setText(name);
}

@ -72,8 +72,18 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* <p>
*
*
* </p>
*/
public class NoteEditActivity extends Activity implements OnClickListener,
NoteSettingChangedListener, OnTextViewChangeListener {
/**
*
*/
private class HeadViewHolder {
public TextView tvModified;
@ -84,6 +94,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
public ImageView ibSetBgColor;
}
/** 背景颜色选择按钮映射表将按钮ID映射到颜色ID */
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
static {
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
@ -93,6 +104,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
}
/** 背景颜色选择高亮映射表将颜色ID映射到高亮视图ID */
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
static {
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
@ -102,6 +114,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
}
/** 字体大小按钮映射表将按钮ID映射到字体大小ID */
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
static {
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
@ -110,6 +123,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
}
/** 字体大小选择高亮映射表将字体大小ID映射到高亮视图ID */
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
static {
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
@ -118,37 +132,59 @@ public class NoteEditActivity extends Activity implements OnClickListener,
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SUPER, R.id.iv_super_select);
}
/** 日志标签 */
private static final String TAG = "NoteEditActivity";
/** 头部视图持有者 */
private HeadViewHolder mNoteHeaderHolder;
/** 头部视图面板 */
private View mHeadViewPanel;
/** 背景颜色选择器视图 */
private View mNoteBgColorSelector;
/** 字体大小选择器视图 */
private View mFontSizeSelector;
/** 笔记编辑文本框 */
private EditText mNoteEditor;
/** 笔记编辑面板 */
private View mNoteEditorPanel;
/** 工作笔记对象,用于处理笔记数据 */
private WorkingNote mWorkingNote;
/** 共享偏好设置 */
private SharedPreferences mSharedPrefs;
/** 字体大小ID */
private int mFontSizeId;
/** 字体大小偏好设置键 */
private static final String PREFERENCE_FONT_SIZE = "pref_font_size";
/** 快捷图标标题最大长度 */
private static final int SHORTCUT_ICON_TITLE_MAX_LEN = 10;
/** 已选中标记 */
public static final String TAG_CHECKED = String.valueOf('\u221A');
/** 未选中标记 */
public static final String TAG_UNCHECKED = String.valueOf('\u25A1');
/** 清单模式下的编辑文本列表 */
private LinearLayout mEditTextList;
/** 用户查询字符串 */
private String mUserQuery;
/** 查询正则表达式模式 */
private Pattern mPattern;
/**
*
*
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -179,6 +215,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
* Intent
*
* @param intent Intent
* @return
*/
private boolean initActivityState(Intent intent) {
/**
* If the user specified the {@link Intent#ACTION_VIEW} but not provided with id,
@ -262,12 +304,18 @@ 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));
@ -295,6 +343,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
showAlertHeader();
}
/**
*
*/
private void showAlertHeader() {
if (mWorkingNote.hasClockAlert()) {
long time = System.currentTimeMillis();
@ -312,12 +363,22 @@ public class NoteEditActivity extends Activity implements OnClickListener,
};
}
/**
* Intent
*
* @param intent Intent
*/
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
initActivityState(intent);
}
/**
*
*
* @param outState Bundle
*/
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
@ -333,6 +394,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
Log.d(TAG, "Save working note id: " + mWorkingNote.getNoteId() + " onSaveInstanceState");
}
/**
*
*
* @param ev
* @return
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE
@ -349,6 +416,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return super.dispatchTouchEvent(ev);
}
/**
*
*
* @param view
* @param ev
* @return
*/
private boolean inRangeOfView(View view, MotionEvent ev) {
int []location = new int[2];
view.getLocationOnScreen(location);
@ -363,6 +437,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
/**
*
*/
private void initResources() {
mHeadViewPanel = findViewById(R.id.note_title);
mNoteHeaderHolder = new HeadViewHolder();
@ -397,6 +474,9 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
}
/**
*
*/
@Override
protected void onPause() {
super.onPause();
@ -406,6 +486,9 @@ 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) {
@ -425,6 +508,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
setResult(RESULT_OK, intent);
}
/**
*
*
* @param v
*/
public void onClick(View v) {
int id = v.getId();
if (id == R.id.btn_set_bg_color) {
@ -452,6 +540,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* <p>
*
* </p>
*/
@Override
public void onBackPressed() {
if(clearSettingState()) {
@ -462,6 +556,11 @@ public class NoteEditActivity extends Activity implements OnClickListener,
super.onBackPressed();
}
/**
*
*
* @return truefalse
*/
private boolean clearSettingState() {
if (mNoteBgColorSelector.getVisibility() == View.VISIBLE) {
mNoteBgColorSelector.setVisibility(View.GONE);
@ -473,6 +572,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return false;
}
/**
*
* <p>
*
* </p>
*/
public void onBackgroundColorChanged() {
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
View.VISIBLE);
@ -480,6 +585,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mHeadViewPanel.setBackgroundResource(mWorkingNote.getTitleBgResId());
}
/**
*
* <p>
*
*
* </p>
*
* @param menu
* @return
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (isFinishing()) {
@ -505,6 +620,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
/**
*
* <p>
*
*
* </p>
* @param item
* @return true
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -553,6 +677,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return true;
}
/**
*
* <p>
*
*
* </p>
*/
private void setReminder() {
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
@ -564,8 +695,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
/**
* Share note to apps that support {@link Intent#ACTION_SEND} action
* and {@text/plain} type
* {@link Intent#ACTION_SEND}{@text/plain}
* <p>
*
* </p>
* @param context
* @param info
*/
private void sendTo(Context context, String info) {
Intent intent = new Intent(Intent.ACTION_SEND);
@ -574,6 +709,13 @@ public class NoteEditActivity extends Activity implements OnClickListener,
context.startActivity(intent);
}
/**
*
* <p>
* NoteEditActivity
*
* </p>
*/
private void createNewNote() {
// Firstly, save current editing notes
saveNote();
@ -586,6 +728,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
startActivity(intent);
}
/**
*
* <p>
*
* 1. ID
* 2.
* 3.
* </p>
*/
private void deleteCurrentNote() {
if (mWorkingNote.existInDatabase()) {
HashSet<Long> ids = new HashSet<Long>();
@ -608,15 +759,28 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mWorkingNote.markDeleted(true);
}
/**
*
* <p>
*
* </p>
* @return truefalse
*/
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
/**
*
* <p>
*
*
* </p>
* @param date
* @param set truefalse
*/
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();
}
@ -642,10 +806,29 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* <p>
* updateWidget()
* </p>
*/
public void onWidgetChanged() {
updateWidget();
}
/**
*
* <p>
*
* 1.
* 2. 1
* 3.
* 4.
* 5.
* </p>
* @param index
* @param text
*/
public void onEditTextDelete(int index, String text) {
int childCount = mEditTextList.getChildCount();
if (childCount == 1) {
@ -672,10 +855,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
edit.setSelection(length);
}
/**
*
* <p>
*
* </p>
* @param index
* @param text
*/
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");
}
@ -691,6 +880,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* <p>
*
*
* </p>
* @param text
*/
private void switchToListMode(String text) {
mEditTextList.removeAllViews();
String[] items = text.split("\n");
@ -708,6 +905,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
mEditTextList.setVisibility(View.VISIBLE);
}
/**
*
* <p>
*
* </p>
* @param fullText
* @param userQuery
* @return Spannable
*/
private Spannable getHighlightQueryResult(String fullText, String userQuery) {
SpannableString spannable = new SpannableString(fullText == null ? "" : fullText);
if (!TextUtils.isEmpty(userQuery)) {
@ -725,6 +931,21 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return spannable;
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4.
* 5.
* 6.
* </p>
* @param item
* @param index
* @return
*/
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);
@ -756,6 +977,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return view;
}
/**
*
* <p>
*
*
* </p>
* @param index
* @param hasText
*/
public void onTextChange(int index, boolean hasText) {
if (index >= mEditTextList.getChildCount()) {
Log.e(TAG, "Wrong index, should not happen");
@ -768,6 +998,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* <p>
*
*
* </p>
* @param oldMode
* @param newMode
*/
public void onCheckListModeChanged(int oldMode, int newMode) {
if (newMode == TextNote.MODE_CHECK_LIST) {
switchToListMode(mNoteEditor.getText().toString());
@ -782,6 +1021,15 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* <p>
*
* 1.
* 2.
* </p>
* @return
*/
private boolean getWorkingText() {
boolean hasChecked = false;
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
@ -805,6 +1053,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return hasChecked;
}
/**
*
* <p>
* mWorkingNotesaveNote
* RESULT_OK/便
* </p>
* @return
*/
private boolean saveNote() {
getWorkingText();
boolean saved = mWorkingNote.saveNote();
@ -821,12 +1077,19 @@ public class NoteEditActivity extends Activity implements OnClickListener,
return saved;
}
/**
*
* <p>
*
* 1.
* 2. Intent
* 3.
* 4. 广
* 5.
* </p>
*/
private void sendToDesktop() {
/**
* Before send message to home, we should make sure that current
* editing note is exists in databases. So, for new note, firstly
* save it
*/
// 在发送到桌面之前,确保当前编辑的笔记已存在于数据库中。对于新笔记,首先保存它
if (!mWorkingNote.existInDatabase()) {
saveNote();
}
@ -837,7 +1100,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
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,
sender.putExtra(Intent.EXTRA_SHORTCUT_NAME,
makeShortcutIconTitle(mWorkingNote.getContent()));
sender.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(this, R.drawable.icon_app));
@ -856,6 +1119,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
}
}
/**
*
* <p>
*
* 1.
* 2.
* </p>
* @param content
* @return
*/
private String makeShortcutIconTitle(String content) {
content = content.replace(TAG_CHECKED, "");
content = content.replace(TAG_UNCHECKED, "");
@ -863,10 +1136,26 @@ public class NoteEditActivity extends Activity implements OnClickListener,
SHORTCUT_ICON_TITLE_MAX_LEN) : content;
}
/**
* Toast
* <p>
* showToast(int resId, int duration)便
* 使Toast.LENGTH_SHORT
* </p>
* @param resId ID
*/
private void showToast(int resId) {
showToast(resId, Toast.LENGTH_SHORT);
}
/**
* Toast
* <p>
* 使AndroidToast
* </p>
* @param resId ID
* @param duration Toast.LENGTH_SHORTToast.LENGTH_LONG
*/
private void showToast(int resId, int duration) {
Toast.makeText(this, resId, duration).show();
}

@ -37,15 +37,47 @@ import net.micode.notes.R;
import java.util.HashMap;
import java.util.Map;
/**
*
* <p>
* EditText便
*
* </p>
*/
public class NoteEditText extends EditText {
/**
*
*/
private static final String TAG = "NoteEditText";
/**
*
*/
private int mIndex;
/**
*
*/
private int mSelectionStartBeforeDelete;
/**
*
*/
private static final String SCHEME_TEL = "tel:" ;
/**
* HTTP
*/
private static final String SCHEME_HTTP = "http:" ;
/**
*
*/
private static final String SCHEME_EMAIL = "mailto:" ;
/**
* ID
*/
private static final Map<String, Integer> sSchemaActionResMap = new HashMap<String, Integer>();
static {
sSchemaActionResMap.put(SCHEME_TEL, R.string.note_link_tel);
@ -54,51 +86,86 @@ public class NoteEditText extends EditText {
}
/**
* Call by the {@link NoteEditActivity} to delete or add edit text
*
* <p>
* {@link NoteEditActivity}
* </p>
*/
public interface OnTextViewChangeListener {
/**
* Delete current edit text when {@link KeyEvent#KEYCODE_DEL} happens
* and the text is null
* {@link KeyEvent#KEYCODE_DEL}
*/
void onEditTextDelete(int index, String text);
/**
* Add edit text after current edit text when {@link KeyEvent#KEYCODE_ENTER}
* happen
* {@link KeyEvent#KEYCODE_ENTER}
*/
void onEditTextEnter(int index, String text);
/**
* Hide or show item option when text change
*
*/
void onTextChange(int index, boolean hasText);
}
/**
*
*/
private OnTextViewChangeListener mOnTextViewChangeListener;
/**
*
* @param context
*/
public NoteEditText(Context context) {
super(context, null);
mIndex = 0;
}
/**
*
* @param index
*/
public void setIndex(int index) {
mIndex = index;
}
/**
*
* @param listener
*/
public void setOnTextViewChangeListener(OnTextViewChangeListener listener) {
mOnTextViewChangeListener = listener;
}
/**
*
* @param context
* @param attrs
*/
public NoteEditText(Context context, AttributeSet attrs) {
super(context, attrs, android.R.attr.editTextStyle);
}
/**
*
* @param context
* @param attrs
* @param defStyle
*/
public NoteEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
/**
*
* <p>
*
* </p>
* @param event
* @return
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
@ -121,6 +188,15 @@ public class NoteEditText extends EditText {
return super.onTouchEvent(event);
}
/**
*
* <p>
*
* </p>
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
@ -138,6 +214,15 @@ public class NoteEditText extends EditText {
return super.onKeyDown(keyCode, event);
}
/**
*
* <p>
*
* </p>
* @param keyCode
* @param event
* @return
*/
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch(keyCode) {
@ -167,6 +252,16 @@ public class NoteEditText extends EditText {
return super.onKeyUp(keyCode, event);
}
/**
*
* <p>
*
*
* </p>
* @param focused
* @param direction
* @param previouslyFocusedRect
*/
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
if (mOnTextViewChangeListener != null) {
@ -179,6 +274,13 @@ public class NoteEditText extends EditText {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
/**
*
* <p>
*
* </p>
* @param menu
*/
@Override
protected void onCreateContextMenu(ContextMenu menu) {
if (getText() instanceof Spanned) {

@ -26,7 +26,20 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.tool.DataUtils;
/**
*
* <p>
* 便
*
* </p>
*/
public class NoteItemData {
/**
*
* <p>
*
* </p>
*/
static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.ALERTED_DATE,
@ -42,40 +55,166 @@ public class NoteItemData {
NoteColumns.WIDGET_TYPE,
};
/**
* ID
*/
private static final int ID_COLUMN = 0;
/**
*
*/
private static final int ALERTED_DATE_COLUMN = 1;
/**
* ID
*/
private static final int BG_COLOR_ID_COLUMN = 2;
/**
*
*/
private static final int CREATED_DATE_COLUMN = 3;
/**
*
*/
private static final int HAS_ATTACHMENT_COLUMN = 4;
/**
*
*/
private static final int MODIFIED_DATE_COLUMN = 5;
/**
*
*/
private static final int NOTES_COUNT_COLUMN = 6;
/**
* ID
*/
private static final int PARENT_ID_COLUMN = 7;
/**
*
*/
private static final int SNIPPET_COLUMN = 8;
/**
*
*/
private static final int TYPE_COLUMN = 9;
/**
* ID
*/
private static final int WIDGET_ID_COLUMN = 10;
/**
*
*/
private static final int WIDGET_TYPE_COLUMN = 11;
/**
* ID
*/
private long mId;
/**
*
*/
private long mAlertDate;
/**
* ID
*/
private int mBgColorId;
/**
*
*/
private long mCreatedDate;
/**
*
*/
private boolean mHasAttachment;
/**
*
*/
private long mModifiedDate;
/**
*
*/
private int mNotesCount;
/**
* ID
*/
private long mParentId;
/**
*
*/
private String mSnippet;
/**
*
*/
private int mType;
/**
* ID
*/
private int mWidgetId;
/**
*
*/
private int mWidgetType;
/**
*
*/
private String mName;
/**
*
*/
private String mPhoneNumber;
/**
*
*/
private boolean mIsLastItem;
/**
*
*/
private boolean mIsFirstItem;
/**
*
*/
private boolean mIsOnlyOneItem;
/**
*
*/
private boolean mIsOneNoteFollowingFolder;
/**
*
*/
private boolean mIsMultiNotesFollowingFolder;
/**
*
* @param context
* @param cursor
*/
public NoteItemData(Context context, Cursor cursor) {
mId = cursor.getLong(ID_COLUMN);
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
@ -109,6 +248,13 @@ public class NoteItemData {
checkPostion(cursor);
}
/**
*
* <p>
*
* </p>
* @param cursor
*/
private void checkPostion(Cursor cursor) {
mIsLastItem = cursor.isLast() ? true : false;
mIsFirstItem = cursor.isFirst() ? true : false;
@ -134,90 +280,179 @@ public class NoteItemData {
}
}
/**
*
* @return
*/
public boolean isOneFollowingFolder() {
return mIsOneNoteFollowingFolder;
}
/**
*
* @return
*/
public boolean isMultiFollowingFolder() {
return mIsMultiNotesFollowingFolder;
}
/**
*
* @return
*/
public boolean isLast() {
return mIsLastItem;
}
/**
*
* @return
*/
public String getCallName() {
return mName;
}
/**
*
* @return
*/
public boolean isFirst() {
return mIsFirstItem;
}
/**
*
* @return
*/
public boolean isSingle() {
return mIsOnlyOneItem;
}
/**
* ID
* @return ID
*/
public long getId() {
return mId;
}
/**
*
* @return
*/
public long getAlertDate() {
return mAlertDate;
}
/**
*
* @return
*/
public long getCreatedDate() {
return mCreatedDate;
}
/**
*
* @return
*/
public boolean hasAttachment() {
return mHasAttachment;
}
/**
*
* @return
*/
public long getModifiedDate() {
return mModifiedDate;
}
/**
* ID
* @return ID
*/
public int getBgColorId() {
return mBgColorId;
}
/**
* ID
* @return ID
*/
public long getParentId() {
return mParentId;
}
/**
*
* @return
*/
public int getNotesCount() {
return mNotesCount;
}
/**
* ID
* @return ID
*/
public long getFolderId () {
return mParentId;
}
/**
*
* @return
*/
public int getType() {
return mType;
}
/**
*
* @return
*/
public int getWidgetType() {
return mWidgetType;
}
/**
* ID
* @return ID
*/
public int getWidgetId() {
return mWidgetId;
}
/**
*
* @return
*/
public String getSnippet() {
return mSnippet;
}
/**
*
* @return
*/
public boolean hasAlert() {
return (mAlertDate > 0);
}
/**
*
* @return
*/
public boolean isCallRecord() {
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
}
/**
*
* @param cursor
* @return
*/
public static int getNoteType(Cursor cursor) {
return cursor.getInt(TYPE_COLUMN);
}

@ -78,63 +78,114 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
/**
*
* <p>
*
*
* </p>
*/
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;
/** 文件夹删除菜单ID */
private static final int MENU_FOLDER_DELETE = 0;
/** 文件夹查看菜单ID */
private static final int MENU_FOLDER_VIEW = 1;
/** 文件夹重命名菜单ID */
private static final int MENU_FOLDER_CHANGE_NAME = 2;
/** 偏好设置:是否添加了介绍笔记 */
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
/**
*
* <p>
*
* 1. NOTE_LIST
* 2. SUB_FOLDER
* 3. CALL_RECORD_FOLDER
* </p>
*/
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
};
/** 当前列表编辑状态 */
private ListEditState mState;
/** 后台查询处理器 */
private BackgroundQueryHandler mBackgroundQueryHandler;
/** 笔记列表适配器 */
private NotesListAdapter mNotesListAdapter;
/** 笔记列表视图 */
private ListView mNotesListView;
/** 新建笔记按钮 */
private Button mAddNewNote;
/** 是否分发触摸事件 */
private boolean mDispatch;
/** 原始Y坐标 */
private int mOriginY;
/** 分发Y坐标 */
private int mDispatchY;
/** 标题栏文本视图 */
private TextView mTitleBar;
/** 当前文件夹ID */
private long mCurrentFolderId;
/** 内容解析器 */
private ContentResolver mContentResolver;
/** 模式回调 */
private ModeCallback mModeCallBack;
/** 日志标签 */
private static final String TAG = "NotesListActivity";
/** 笔记列表视图滚动速率 */
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
/** 当前焦点的笔记数据项 */
private NoteItemData mFocusNoteDataItem;
/** 普通文件夹选择条件 */
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
/** 根文件夹选择条件 */
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>"
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)" + " OR ("
+ Notes.TYPE_SYSTEM + " AND " + NoteColumns.PARENT_ID + "=?)") + " OR ("
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
+ NoteColumns.NOTES_COUNT + ">0)";
/** 打开笔记请求码 */
private final static int REQUEST_CODE_OPEN_NODE = 102;
/** 新建笔记请求码 */
private final static int REQUEST_CODE_NEW_NODE = 103;
/**
*
* <p>
*
* 1.
* 2.
* 3. 使
* </p>
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -147,6 +198,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
setAppInfoFromRawRes();
}
/**
*
* <p>
*
* </p>
* @param requestCode
* @param resultCode
* @param data
*/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK
@ -203,12 +263,32 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* <p>
*
* </p>
*/
@Override
protected void onStart() {
super.onStart();
startAsyncNotesListQuery();
}
/**
*
* <p>
*
* 1.
* 2. IDID
* 3.
* 4.
* 5.
* 6.
* 7.
* 8.
* </p>
*/
private void initResources() {
mContentResolver = this.getContentResolver();
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -231,11 +311,40 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mModeCallBack = new ModeCallback();
}
/**
*
* <p>
* ListView.MultiChoiceModeListenerOnMenuItemClickListener
*
* </p>
*/
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
/** 下拉菜单 */
private DropdownMenu mDropDownMenu;
/** 动作模式 */
private ActionMode mActionMode;
/** 移动菜单 */
private MenuItem mMoveMenu;
/**
*
* <p>
*
* 1.
* 2.
* 3. ID
* 4.
* 5.
* 6.
* 7.
* 8.
* 9.
* 10.
* </p>
* @param mode
* @param menu
* @return true
*/
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
getMenuInflater().inflate(R.menu.note_list_options, menu);
menu.findItem(R.id.delete).setOnMenuItemClickListener(this);
@ -269,6 +378,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
/**
*
* <p>
*
* 1.
* 2.
* 3. /
* </p>
*/
private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount();
// Update dropdown menu
@ -286,32 +404,90 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* <p>
* false
* </p>
* @param mode
* @param menu
* @return false
*/
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
// TODO Auto-generated method stub
return false;
}
/**
*
* <p>
* false
* </p>
* @param mode
* @param item
* @return false
*/
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// TODO Auto-generated method stub
return false;
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* </p>
* @param mode
*/
public void onDestroyActionMode(ActionMode mode) {
mNotesListAdapter.setChoiceMode(false);
mNotesListView.setLongClickable(true);
mAddNewNote.setVisibility(View.VISIBLE);
}
/**
*
* <p>
* finish
* </p>
*/
public void finishActionMode() {
mActionMode.finish();
}
/**
*
* <p>
*
* 1.
* 2.
* </p>
* @param mode
* @param position
* @param id ID
* @param checked
*/
public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
boolean checked) {
mNotesListAdapter.setCheckedItem(position, checked);
updateMenu();
}
/**
*
* <p>
*
* 1.
* 2. ID
* - batchDelete
* - startQueryDestinationFolders
* </p>
* @param item
* @return true
*/
public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
@ -346,8 +522,34 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* <p>
* OnTouchListener
*
* </p>
*/
private class NewNoteOnTouchListener implements OnTouchListener {
/**
*
* <p>
*
* 1. ACTION_DOWN
* -
* - Y
* - SUB_FOLDER
* - y=-0.12x+94
* -
* 2. ACTION_MOVE
* -
* 3.
* -
* </p>
* @param v
* @param event
* @return true
*/
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
@ -408,6 +610,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
};
/**
*
* <p>
* IDBackgroundQueryHandler
* </p>
*/
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
@ -417,11 +625,35 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
/**
*
* <p>
* AsyncQueryHandler
*
* 1.
* 2.
* </p>
*/
private final class BackgroundQueryHandler extends AsyncQueryHandler {
/**
*
* @param contentResolver
*/
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
}
/**
*
* <p>
*
* 1.
* 2.
* </p>
* @param token
* @param cookie 使
* @param cursor
*/
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
switch (token) {
@ -462,6 +694,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
builder.show();
}
/**
*
* <p>
* NoteEditActivityID
* </p>
*/
private void createNewNote() {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
@ -469,6 +707,17 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4.
* 5.
* </p>
*/
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
@ -506,6 +755,18 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
/**
*
* <p>
*
* 1. IDID
* 2.
* 3.
* 4.
* 5.
* </p>
* @param folderId ID
*/
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -533,6 +794,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* <p>
* NoteEditActivityID
* </p>
* @param data
*/
private void openNode(NoteItemData data) {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
@ -540,6 +808,19 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
this.startActivityForResult(intent, REQUEST_CODE_OPEN_NODE);
}
/**
*
* <p>
*
* 1. ID
* 2.
* 3.
* - CALL_RECORD_FOLDER
* - SUB_FOLDER
* 4.
* </p>
* @param data
*/
private void openFolder(NoteItemData data) {
mCurrentFolderId = data.getId();
startAsyncNotesListQuery();
@ -557,6 +838,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar.setVisibility(View.VISIBLE);
}
/**
*
* <p>
*
* </p>
* @param v
*/
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_new_note:
@ -567,6 +855,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* <p>
* InputMethodManager
* </p>
*/
private void showSoftInput() {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
@ -574,11 +868,35 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* <p>
* InputMethodManager
* </p>
* @param view
*/
private void hideSoftInput(View view) {
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4. create
* - "修改文件夹名称"
* - "创建文件夹"
* 5.
* 6.
* 7.
* 8.
* </p>
* @param create truefalse
*/
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);
@ -664,6 +982,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* </p>
*/
@Override
public void onBackPressed() {
switch (mState) {
@ -688,6 +1015,22 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}
/**
*
* <p>
*
* 1. 广
* 2. 广
* - 2x2NoteWidgetProvider_2x
* - 4x4NoteWidgetProvider_4x
* -
* 3. ID
* 4. 广
* 5.
* </p>
* @param appWidgetId ID
* @param appWidgetType
*/
private void updateWidget(int appWidgetId, int appWidgetType) {
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
if (appWidgetType == Notes.TYPE_WIDGET_2X) {
@ -778,6 +1121,22 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
/**
*
* <p>
*
* 1.
* 2. exportNoteToText
* 3.
* -
* -
* 4.
* 5. createNewNote
* 6. onSearchRequested
* </p>
* @param item
* @return true
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@ -818,12 +1177,31 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
/**
*
* <p>
*
* </p>
* @return true
*/
@Override
public boolean onSearchRequested() {
startSearch(null, false, null /* appData */, false);
return true;
}
/**
*
* <p>
*
* 1. BackupUtils
* 2. exportToText
* 3.
* - SD
* -
* -
* </p>
*/
private void exportNoteToText() {
final BackupUtils backup = BackupUtils.getInstance(NotesListActivity.this);
new AsyncTask<Void, Void, Integer>() {
@ -866,18 +1244,62 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}.execute();
}
/**
*
* <p>
*
* </p>
* @return truefalse
*/
private boolean isSyncMode() {
return NotesPreferenceActivity.getSyncAccountName(this).trim().length() > 0;
}
/**
*
* <p>
*
* 1.
* 2. NotesPreferenceActivity
* 3.
* </p>
*/
private void startPreferenceActivity() {
Activity from = getParent() != null ? getParent() : this;
Intent intent = new Intent(from, NotesPreferenceActivity.class);
from.startActivityIfNeeded(intent, -1);
}
/**
*
* <p>
* OnItemClickListener
*
* </p>
*/
private class OnListItemClickListener implements OnItemClickListener {
/**
*
* <p>
*
* 1. NotesListItem
* 2.
* 3.
* -
* -
* 4.
* - NOTE_LIST
* - openFolder
* - openNode
* - SUB_FOLDERCALL_RECORD_FOLDER
* - openNode
* </p>
* @param parent
* @param view
* @param position
* @param id ID
*/
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
NoteItemData item = ((NotesListItem) view).getItemData();
@ -917,6 +1339,16 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
/**
*
* <p>
*
* 1.
* - IDIDIDID
* - NOTE_LISTID
* 2. BackgroundQueryHandler
* </p>
*/
private void startQueryDestinationFolders() {
String selection = NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>? AND " + NoteColumns.ID + "<>?";
selection = (mState == ListEditState.NOTE_LIST) ? selection:
@ -935,6 +1367,23 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
NoteColumns.MODIFIED_DATE + " DESC");
}
/**
*
* <p>
*
* 1. NotesListItem
* 2.
* 3.
* -
* -
* 4. false
* </p>
* @param parent
* @param view
* @param position
* @param id ID
* @return false
*/
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (view instanceof NotesListItem) {
mFocusNoteDataItem = ((NotesListItem) view).getItemData();

@ -31,18 +31,46 @@ import java.util.HashSet;
import java.util.Iterator;
/**
*
* <p>
* CursorAdapter
*
* ID
* </p>
*/
public class NotesListAdapter extends CursorAdapter {
/** 日志标签 */
private static final String TAG = "NotesListAdapter";
/** 上下文对象 */
private Context mContext;
/** 保存选中项目的位置和状态 */
private HashMap<Integer, Boolean> mSelectedIndex;
/** 笔记数量 */
private int mNotesCount;
/** 是否处于选择模式 */
private boolean mChoiceMode;
/**
*
* <p>
* ID
* </p>
*/
public static class AppWidgetAttribute {
/** 桌面组件ID */
public int widgetId;
/** 桌面组件类型 */
public int widgetType;
};
/**
*
* <p>
* NotesListAdapter
* </p>
* @param context
*/
public NotesListAdapter(Context context) {
super(context, null);
mSelectedIndex = new HashMap<Integer, Boolean>();
@ -50,11 +78,31 @@ public class NotesListAdapter extends CursorAdapter {
mNotesCount = 0;
}
/**
*
* <p>
* NotesListItem
* </p>
* @param context
* @param cursor
* @param parent
* @return
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
/**
*
* <p>
* NoteItemData
* NotesListItembind
* </p>
* @param view
* @param context
* @param cursor
*/
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) {
@ -64,20 +112,46 @@ public class NotesListAdapter extends CursorAdapter {
}
}
/**
*
* <p>
*
* </p>
* @param position
* @param checked
*/
public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked);
notifyDataSetChanged();
}
/**
*
* @return
*/
public boolean isInChoiceMode() {
return mChoiceMode;
}
/**
*
* <p>
*
* </p>
* @param mode
*/
public void setChoiceMode(boolean mode) {
mSelectedIndex.clear();
mChoiceMode = mode;
}
/**
*
* <p>
*
* </p>
* @param checked
*/
public void selectAll(boolean checked) {
Cursor cursor = getCursor();
for (int i = 0; i < getCount(); i++) {
@ -89,6 +163,13 @@ public class NotesListAdapter extends CursorAdapter {
}
}
/**
* ID
* <p>
* IDID
* </p>
* @return ID
*/
public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>();
for (Integer position : mSelectedIndex.keySet()) {
@ -105,6 +186,13 @@ public class NotesListAdapter extends CursorAdapter {
return itemSet;
}
/**
*
* <p>
*
* </p>
* @return null
*/
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
@ -128,6 +216,10 @@ public class NotesListAdapter extends CursorAdapter {
return itemSet;
}
/**
*
* @return
*/
public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values();
if (null == values) {
@ -143,11 +235,20 @@ public class NotesListAdapter extends CursorAdapter {
return count;
}
/**
*
* @return
*/
public boolean isAllSelected() {
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);
}
/**
*
* @param position
* @return
*/
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
return false;
@ -155,18 +256,37 @@ public class NotesListAdapter extends CursorAdapter {
return mSelectedIndex.get(position);
}
/**
*
* <p>
*
* </p>
*/
@Override
protected void onContentChanged() {
super.onContentChanged();
calcNotesCount();
}
/**
*
* <p>
*
* </p>
* @param cursor
*/
@Override
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
calcNotesCount();
}
/**
*
* <p>
* mNotesCount
* </p>
*/
private void calcNotesCount() {
mNotesCount = 0;
for (int i = 0; i < getCount(); i++) {

@ -30,14 +30,35 @@ import net.micode.notes.tool.DataUtils;
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
/**
*
* <p>
* UI
*
*
* </p>
*/
public class NotesListItem extends LinearLayout {
/** 提醒图标,用于显示笔记是否设置了提醒 */
private ImageView mAlert;
/** 笔记标题文本视图 */
private TextView mTitle;
/** 笔记时间文本视图 */
private TextView mTime;
/** 通话记录名称文本视图 */
private TextView mCallName;
/** 列表项数据对象,存储笔记的相关信息 */
private NoteItemData mItemData;
/** 选择框,用于选择模式下选择笔记 */
private CheckBox mCheckBox;
/**
*
* <p>
* NotesListItemUI
* </p>
* @param context
*/
public NotesListItem(Context context) {
super(context);
inflate(context, R.layout.note_item, this);
@ -48,6 +69,20 @@ public class NotesListItem extends LinearLayout {
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);
}
/**
*
* <p>
* UI
* 1.
* 2. UI
* 3.
* 4. setBackground
* </p>
* @param context
* @param data
* @param choiceMode
* @param checked
*/
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
mCheckBox.setVisibility(View.VISIBLE);
@ -99,6 +134,15 @@ public class NotesListItem extends LinearLayout {
setBackground(data);
}
/**
*
* <p>
*
* 1.
* 2. 使
* </p>
* @param data ID
*/
private void setBackground(NoteItemData data) {
int id = data.getBgColorId();
if (data.getType() == Notes.TYPE_NOTE) {
@ -116,6 +160,10 @@ public class NotesListItem extends LinearLayout {
}
}
/**
*
* @return
*/
public NoteItemData getItemData() {
return mItemData;
}

@ -48,27 +48,56 @@ import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.gtask.remote.GTaskSyncService;
/**
*
* <p>
*
* UIGTaskSyncService
* </p>
*/
public class NotesPreferenceActivity extends PreferenceActivity {
/** 偏好设置文件名 */
public static final String PREFERENCE_NAME = "notes_preferences";
/** 同步账户名的偏好键 */
public static final String PREFERENCE_SYNC_ACCOUNT_NAME = "pref_key_account_name";
/** 最后同步时间的偏好键 */
public static final String PREFERENCE_LAST_SYNC_TIME = "pref_last_sync_time";
/** 背景颜色随机出现的偏好键 */
public static final String PREFERENCE_SET_BG_COLOR_KEY = "pref_key_bg_random_appear";
/** 同步账户的偏好键 */
private static final String PREFERENCE_SYNC_ACCOUNT_KEY = "pref_sync_account_key";
/** 权限过滤器键 */
private static final String AUTHORITIES_FILTER_KEY = "authorities";
/** 账户偏好设置分类 */
private PreferenceCategory mAccountCategory;
/** GTask同步服务广播接收器 */
private GTaskReceiver mReceiver;
/** 原始账户列表 */
private Account[] mOriAccounts;
/** 是否添加了新账户 */
private boolean mHasAddedAccount;
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4. GTask广
* 5.
* </p>
* @param icicle
*/
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
@ -88,6 +117,14 @@ public class NotesPreferenceActivity extends PreferenceActivity {
getListView().addHeaderView(header, null, true);
}
/**
*
* <p>
*
* 1.
* 2. UI
* </p>
*/
@Override
protected void onResume() {
super.onResume();
@ -116,6 +153,13 @@ public class NotesPreferenceActivity extends PreferenceActivity {
refreshUI();
}
/**
*
* <p>
*
* 1. GTask广
* </p>
*/
@Override
protected void onDestroy() {
if (mReceiver != null) {
@ -124,6 +168,17 @@ public class NotesPreferenceActivity extends PreferenceActivity {
super.onDestroy();
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4.
* 5.
* </p>
*/
private void loadAccountPreference() {
mAccountCategory.removeAll();
@ -154,6 +209,16 @@ public class NotesPreferenceActivity extends PreferenceActivity {
mAccountCategory.addPreference(accountPref);
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* 4.
* </p>
*/
private void loadSyncButton() {
Button syncButton = (Button) findViewById(R.id.preference_sync_button);
TextView lastSyncTimeView = (TextView) findViewById(R.id.prefenerece_sync_status_textview);
@ -193,11 +258,28 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
/**
* UI
* <p>
* loadAccountPreferenceloadSyncButtonUI
* </p>
*/
private void refreshUI() {
loadAccountPreference();
loadSyncButton();
}
/**
*
* <p>
*
* 1.
* 2. Google
* 3.
* 4.
* 5.
* </p>
*/
private void showSelectAccountAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
@ -254,6 +336,15 @@ public class NotesPreferenceActivity extends PreferenceActivity {
});
}
/**
*
* <p>
*
* 1.
* 2.
* 3.
* </p>
*/
private void showChangeAccountConfirmAlertDialog() {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
@ -283,11 +374,29 @@ public class NotesPreferenceActivity extends PreferenceActivity {
dialogBuilder.show();
}
/**
* Google
* <p>
* AccountManagerGoogle
* </p>
* @return Google
*/
private Account[] getGoogleAccounts() {
AccountManager accountManager = AccountManager.get(this);
return accountManager.getAccountsByType("com.google");
}
/**
*
* <p>
*
* 1.
* 2.
* 3. GTask
* 4.
* </p>
* @param account
*/
private void setSyncAccount(String account) {
if (!getSyncAccountName(this).equals(account)) {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
@ -318,6 +427,15 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
/**
*
* <p>
*
* 1.
* 2.
* 3. GTask
* </p>
*/
private void removeSyncAccount() {
SharedPreferences settings = getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
@ -340,12 +458,28 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}).start();
}
/**
*
* <p>
*
* </p>
* @param context
* @return
*/
public static String getSyncAccountName(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getString(PREFERENCE_SYNC_ACCOUNT_NAME, "");
}
/**
*
* <p>
*
* </p>
* @param context
* @param time
*/
public static void setLastSyncTime(Context context, long time) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
@ -354,14 +488,38 @@ public class NotesPreferenceActivity extends PreferenceActivity {
editor.commit();
}
/**
*
* <p>
*
* </p>
* @param context
* @return 0
*/
public static long getLastSyncTime(Context context) {
SharedPreferences settings = context.getSharedPreferences(PREFERENCE_NAME,
Context.MODE_PRIVATE);
return settings.getLong(PREFERENCE_LAST_SYNC_TIME, 0);
}
/**
* GTask广
* <p>
* GTaskSyncService广UI
* </p>
*/
private class GTaskReceiver extends BroadcastReceiver {
/**
* 广
* <p>
*
* 1. UI
* 2.
* </p>
* @param context
* @param intent 广
*/
@Override
public void onReceive(Context context, Intent intent) {
refreshUI();
@ -374,6 +532,14 @@ public class NotesPreferenceActivity extends PreferenceActivity {
}
}
/**
*
* <p>
*
* </p>
* @param item
* @return
*/
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:

@ -32,19 +32,56 @@ import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
/**
*
* <p>
* UI
*
*
* </p>
*/
public abstract class NoteWidgetProvider extends AppWidgetProvider {
/**
*
* <p>
* IDID
* </p>
*/
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET
};
/**
* ID
*/
public static final int COLUMN_ID = 0;
/**
* ID
*/
public static final int COLUMN_BG_COLOR_ID = 1;
/**
*
*/
public static final int COLUMN_SNIPPET = 2;
/**
*
*/
private static final String TAG = "NoteWidgetProvider";
/**
*
* <p>
* WIDGET_ID
*
* </p>
* @param context
* @param appWidgetIds ID
*/
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
ContentValues values = new ContentValues();
@ -57,6 +94,15 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
/**
* ID
* <p>
* ID
* </p>
* @param context
* @param widgetId ID
* @return Cursor使PROJECTION
*/
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
@ -65,10 +111,34 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
null);
}
/**
* UI
* <p>
* update使
* </p>
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false);
}
/**
* UI
* <p>
*
* 1.
* 2.
* 3. PendingIntent
* 4.
* 5.
* </p>
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
* @param privacyMode
*/
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) {
for (int i = 0; i < appWidgetIds.length; i++) {
@ -124,9 +194,31 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
}
}
/**
* IDID
* <p>
* IDID
* </p>
* @param bgId ID
* @return ID
*/
protected abstract int getBgResourceId(int bgId);
/**
* ID
* <p>
* ID
* </p>
* @return ID
*/
protected abstract int getLayoutId();
/**
*
* <p>
*
* </p>
* @return
*/
protected abstract int getWidgetType();
}

@ -24,22 +24,60 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* 2x
* <p>
* NoteWidgetProvider2x
*
* </p>
*/
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
/**
* UI
* <p>
* AppWidgetProvideronUpdateupdate2x
* </p>
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* 2xID
* <p>
* 2xID
* </p>
* @return 2xID
*/
@Override
protected int getLayoutId() {
return R.layout.widget_2x;
}
/**
* ID2xID
* <p>
* ResourceParser2xID
* </p>
* @param bgId ID
* @return 2xID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
/**
* 2x
* <p>
* 2x
* </p>
* @return 2x
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;

@ -24,21 +24,60 @@ import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* 4x
* <p>
* NoteWidgetProvider4x
*
* </p>
*/
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
/**
* UI
* <p>
* AppWidgetProvideronUpdateupdate4x
* </p>
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* 4xID
* <p>
* 4xID
* </p>
* @return 4xID
*/
@Override
protected int getLayoutId() {
return R.layout.widget_4x;
}
/**
* ID4xID
* <p>
* ResourceParser4xID
* </p>
* @param bgId ID
* @return 4xID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
/**
* 4x
* <p>
* 4x
* </p>
* @return 4x
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;

Loading…
Cancel
Save