|
|
|
@ -63,6 +63,7 @@ import net.micode.notes.tool.ResourceParser.TextAppearanceResources;
|
|
|
|
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
|
|
|
|
import net.micode.notes.ui.DateTimePickerDialog.OnDateTimeSetListener;
|
|
|
|
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
|
|
|
import net.micode.notes.ui.NoteEditText.OnTextViewChangeListener;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_2x;
|
|
|
|
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_3x;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
|
|
|
import net.micode.notes.widget.NoteWidgetProvider_4x;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
@ -86,6 +87,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
// HeadViewHolder类定义了一组视图,用于在列表或网格中显示信息。这些视图包括一个TextView用于显示修改信息,一个ImageView用于显示警报图标,另一个TextView用于显示警报日期,还有一个ImageView用于选择背景颜色。
|
|
|
|
// HeadViewHolder类定义了一组视图,用于在列表或网格中显示信息。这些视图包括一个TextView用于显示修改信息,一个ImageView用于显示警报图标,另一个TextView用于显示警报日期,还有一个ImageView用于选择背景颜色。
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
|
@ -95,6 +97,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
|
|
|
@ -105,6 +108,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
// sBgSelectorBtnsMap是一个HashMap,将用于选择背景颜色的ImageView视图的资源ID映射到整数值,这些整数值在ResourceParser类中定义。同样,sBgSelectorSelectionMap将整数值映射到所选ImageView视图的资源ID。
|
|
|
|
// sBgSelectorBtnsMap是一个HashMap,将用于选择背景颜色的ImageView视图的资源ID映射到整数值,这些整数值在ResourceParser类中定义。同样,sBgSelectorSelectionMap将整数值映射到所选ImageView视图的资源ID。
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
|
|
|
@ -113,6 +117,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
static {
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
|
|
|
@ -224,7 +229,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
} else if (TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
// New note 如果用户指定了 Intent.ACTION_INSERT_OR_EDIT 动作,则获取笔记ID,如果笔记ID存在,则加载笔记,否则,创建一个新的笔记
|
|
|
|
// New note 如果用户指定了 Intent.ACTION_INSERT_OR_EDIT 动作,则获取笔记ID,如果笔记ID存在,则加载笔记,否则,创建一个新的笔记
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
@ -328,7 +333,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
// 如果mWorkingNote没有闹钟提醒,则将标题栏中的提醒日期文本和提醒图标设置为不可见。
|
|
|
|
// 如果mWorkingNote没有闹钟提醒,则将标题栏中的提醒日期文本和提醒图标设置为不可见。
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.tvAlertDate.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
mNoteHeaderHolder.ivAlertIcon.setVisibility(View.GONE);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@ -373,7 +379,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
private boolean inRangeOfView(View view, MotionEvent ev) {
|
|
|
|
// 获取视图在屏幕上的位置。
|
|
|
|
// 获取视图在屏幕上的位置。
|
|
|
|
int []location = new int[2];
|
|
|
|
int[] location = new int[2];
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
view.getLocationOnScreen(location);
|
|
|
|
int x = location[0];
|
|
|
|
int x = location[0];
|
|
|
|
int y = location[1];
|
|
|
|
int y = location[1];
|
|
|
|
@ -407,7 +413,8 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {
|
|
|
|
for (int id : sFontSizeBtnsMap.keySet()) {
|
|
|
|
View view = findViewById(id);
|
|
|
|
View view = findViewById(id);
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
;
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
|
|
|
mFontSizeId = mSharedPrefs.getInt(PREFERENCE_FONT_SIZE, ResourceParser.BG_DEFAULT_FONT_SIZE);
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
@ -415,7 +422,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
* The id may larger than the length of resources, in this case,
|
|
|
|
* The id may larger than the length of resources, in this case,
|
|
|
|
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
|
|
|
|
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if(mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
|
|
|
|
if (mFontSizeId >= TextAppearanceResources.getResourcesSize()) {
|
|
|
|
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
|
|
|
|
mFontSizeId = ResourceParser.BG_DEFAULT_FONT_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
mEditTextList = (LinearLayout) findViewById(R.id.note_edit_list);
|
|
|
|
@ -424,7 +431,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
|
|
|
super.onPause();
|
|
|
|
if(saveNote()) {
|
|
|
|
if (saveNote()) {
|
|
|
|
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
|
|
|
|
Log.d(TAG, "Note data was saved with length:" + mWorkingNote.getContent().length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
clearSettingState();
|
|
|
|
clearSettingState();
|
|
|
|
@ -434,14 +441,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_2X) {
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
intent.setClass(this, NoteWidgetProvider_2x.class);
|
|
|
|
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_3X) {
|
|
|
|
|
|
|
|
intent.setClass(this, NoteWidgetProvider_3x.class);
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
|
|
|
|
} else if (mWorkingNote.getWidgetType() == Notes.TYPE_WIDGET_4X) {
|
|
|
|
intent.setClass(this, NoteWidgetProvider_4x.class);
|
|
|
|
intent.setClass(this, NoteWidgetProvider_4x.class);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Log.e(TAG, "Unspported widget type");
|
|
|
|
Log.e(TAG, "Unsupported widget type");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] {
|
|
|
|
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[]{
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
mWorkingNote.getWidgetId()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@ -450,13 +459,12 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
}//updateWidget()方法更新与当前笔记相关联的小部件。它创建一个意图,并根据笔记的小部件类型设置相应的小部件提供程序类。然后它发送一个广播,带有小部件ID以更新小部件。
|
|
|
|
}//updateWidget()方法更新与当前笔记相关联的小部件。它创建一个意图,并根据笔记的小部件类型设置相应的小部件提供程序类。然后它发送一个广播,带有小部件ID以更新小部件。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
public void onClick(View v) {
|
|
|
|
int id = v.getId();
|
|
|
|
int id = v.getId();
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
if (id == R.id.btn_set_bg_color) {
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
mNoteBgColorSelector.setVisibility(View.VISIBLE);
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
- View.VISIBLE);
|
|
|
|
-View.VISIBLE);
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
} else if (sBgSelectorBtnsMap.containsKey(id)) {
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
findViewById(sBgSelectorSelectionMap.get(mWorkingNote.getBgColorId())).setVisibility(
|
|
|
|
View.GONE);
|
|
|
|
View.GONE);
|
|
|
|
@ -480,7 +488,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
|
|
|
public void onBackPressed() {
|
|
|
|
if(clearSettingState()) {
|
|
|
|
if (clearSettingState()) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -583,7 +591,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
DateTimePickerDialog d = new DateTimePickerDialog(this, System.currentTimeMillis());
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
d.setOnDateTimeSetListener(new OnDateTimeSetListener() {
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
public void OnDateTimeSet(AlertDialog dialog, long date) {
|
|
|
|
mWorkingNote.setAlertDate(date , true);
|
|
|
|
mWorkingNote.setAlertDate(date, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
d.show();
|
|
|
|
d.show();
|
|
|
|
@ -653,7 +661,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
|
|
|
|
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
|
|
|
|
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
|
|
|
|
AlarmManager alarmManager = ((AlarmManager) getSystemService(ALARM_SERVICE));
|
|
|
|
showAlertHeader();
|
|
|
|
showAlertHeader();
|
|
|
|
if(!set) {
|
|
|
|
if (!set) {
|
|
|
|
alarmManager.cancel(pendingIntent);
|
|
|
|
alarmManager.cancel(pendingIntent);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
|
|
|
|
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
|
|
|
|
@ -687,7 +695,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
mEditTextList.removeViewAt(index);
|
|
|
|
NoteEditText edit = null;
|
|
|
|
NoteEditText edit = null;
|
|
|
|
if(index == 0) {
|
|
|
|
if (index == 0) {
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
edit = (NoteEditText) mEditTextList.getChildAt(0).findViewById(
|
|
|
|
R.id.et_edit_text);
|
|
|
|
R.id.et_edit_text);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -705,7 +713,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Should not happen, check for debug
|
|
|
|
* Should not happen, check for debug
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if(index > mEditTextList.getChildCount()) {
|
|
|
|
if (index > mEditTextList.getChildCount()) {
|
|
|
|
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
|
|
|
|
Log.e(TAG, "Index out of mEditTextList boundrary, should not happen");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -725,7 +733,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
String[] items = text.split("\n");
|
|
|
|
int index = 0;
|
|
|
|
int index = 0;
|
|
|
|
for (String item : items) {
|
|
|
|
for (String item : items) {
|
|
|
|
if(!TextUtils.isEmpty(item)) {
|
|
|
|
if (!TextUtils.isEmpty(item)) {
|
|
|
|
mEditTextList.addView(getListItem(item, index));
|
|
|
|
mEditTextList.addView(getListItem(item, index));
|
|
|
|
index++;
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -793,7 +801,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
Log.e(TAG, "Wrong index, should not happen");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(hasText) {
|
|
|
|
if (hasText) {
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
|
|
|
mEditTextList.getChildAt(index).findViewById(R.id.cb_edit_item).setVisibility(View.GONE);
|
|
|
|
|