|
|
|
@ -84,7 +84,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
public ImageView ibSetBgColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorBtnsMap = new HashMap<Integer, Integer>();//将小米便签的背景颜色映射成一个个值
|
|
|
|
|
static {
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_yellow, ResourceParser.YELLOW);
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_red, ResourceParser.RED);
|
|
|
|
@ -93,7 +93,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sBgSelectorBtnsMap.put(R.id.iv_bg_white, ResourceParser.WHITE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
private static final Map<Integer, Integer> sBgSelectorSelectionMap = new HashMap<Integer, Integer>();//将映射的颜色在反射为小米便签对应颜色的一个值
|
|
|
|
|
static {
|
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.YELLOW, R.id.iv_bg_yellow_select);
|
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.RED, R.id.iv_bg_red_select);
|
|
|
|
@ -102,7 +102,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sBgSelectorSelectionMap.put(ResourceParser.WHITE, R.id.iv_bg_white_select);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();
|
|
|
|
|
private static final Map<Integer, Integer> sFontSizeBtnsMap = new HashMap<Integer, Integer>();//将字体大小映射为一个值
|
|
|
|
|
static {
|
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_large, ResourceParser.TEXT_LARGE);
|
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_small, ResourceParser.TEXT_SMALL);
|
|
|
|
@ -110,7 +110,7 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
sFontSizeBtnsMap.put(R.id.ll_font_super, ResourceParser.TEXT_SUPER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();
|
|
|
|
|
private static final Map<Integer, Integer> sFontSelectorSelectionMap = new HashMap<Integer, Integer>();//将映射的值重新反射为字体大小对应的值
|
|
|
|
|
static {
|
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_LARGE, R.id.iv_large_select);
|
|
|
|
|
sFontSelectorSelectionMap.put(ResourceParser.TEXT_SMALL, R.id.iv_small_select);
|
|
|
|
@ -151,14 +151,14 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
this.setContentView(R.layout.note_edit);
|
|
|
|
|
super.onCreate(savedInstanceState);//执行父类的初始化操作
|
|
|
|
|
this.setContentView(R.layout.note_edit);//将布局文件node_edit加载到activity中,并设置为当前的试图
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {
|
|
|
|
|
if (savedInstanceState == null && !initActivityState(getIntent())) {//初始化失败
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initResources();
|
|
|
|
|
initResources();//进行资源的初始化和加载
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -166,16 +166,16 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
* user load this activity, we should restore the former state
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
|
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {//回复Activities的状态
|
|
|
|
|
super.onRestoreInstanceState(savedInstanceState);
|
|
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));
|
|
|
|
|
if (!initActivityState(intent)) {
|
|
|
|
|
if (savedInstanceState != null && savedInstanceState.containsKey(Intent.EXTRA_UID)) {//是否包含Intent.EXTRA_UID,如果包含则重新恢复
|
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);//创建新的对象并显示出来
|
|
|
|
|
intent.putExtra(Intent.EXTRA_UID, savedInstanceState.getLong(Intent.EXTRA_UID));//把之前的数据加载到该intent上面来
|
|
|
|
|
if (!initActivityState(intent)) {//如果不存在
|
|
|
|
|
finish();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Log.d(TAG, "Restoring from killed activity");
|
|
|
|
|
Log.d(TAG, "Restoring from killed activity");//状态恢复成功
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -186,93 +186,93 @@ public class NoteEditActivity extends Activity implements OnClickListener,
|
|
|
|
|
*/
|
|
|
|
|
mWorkingNote = null;
|
|
|
|
|
if (TextUtils.equals(Intent.ACTION_VIEW, intent.getAction())) {
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);
|
|
|
|
|
long noteId = intent.getLongExtra(Intent.EXTRA_UID, 0);//获取intent所携带的附加参数
|
|
|
|
|
mUserQuery = "";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Starting from the searched result
|
|
|
|
|
*/
|
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {
|
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));
|
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);
|
|
|
|
|
if (intent.hasExtra(SearchManager.EXTRA_DATA_KEY)) {//是否有额外的数据,有的话代表用户想要查看这一个便签
|
|
|
|
|
noteId = Long.parseLong(intent.getStringExtra(SearchManager.EXTRA_DATA_KEY));//取出来对应的id以便于之后数据库搜索
|
|
|
|
|
mUserQuery = intent.getStringExtra(SearchManager.USER_QUERY);//将mUserQuery设置为用户输入的查询的字符串
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {
|
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);
|
|
|
|
|
startActivity(jump);
|
|
|
|
|
showToast(R.string.error_note_not_exist);
|
|
|
|
|
finish();
|
|
|
|
|
if (!DataUtils.visibleInNoteDatabase(getContentResolver(), noteId, Notes.TYPE_NOTE)) {//这个便签不能在数据库中找到
|
|
|
|
|
Intent jump = new Intent(this, NotesListActivity.class);//跳转到对应NoteListActivities上
|
|
|
|
|
startActivity(jump);//跳转
|
|
|
|
|
showToast(R.string.error_note_not_exist);//输出这个便签不存在
|
|
|
|
|
finish();//关闭页面
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);//加载对应的便签
|
|
|
|
|
if (mWorkingNote == null) {//加载失败会记录当前的Activity
|
|
|
|
|
Log.e(TAG, "load note failed with note id" + noteId);//输出打开失败
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {
|
|
|
|
|
getWindow().setSoftInputMode(//设置窗口为软件盘模式,窗口会自动调整布局大小以适应软键盘的显示或隐藏
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN//此标志表示启动该 Activity 时软键盘不会自动弹出
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);//Activity 中的窗口大小会根据软键盘的状态自动调整
|
|
|
|
|
} else if(TextUtils.equals(Intent.ACTION_INSERT_OR_EDIT, intent.getAction())) {//如果是增添或者编辑
|
|
|
|
|
// New note
|
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);
|
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,
|
|
|
|
|
long folderId = intent.getLongExtra(Notes.INTENT_EXTRA_FOLDER_ID, 0);//获取FolderId
|
|
|
|
|
int widgetId = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_ID,//获取传入的组件Id,如果没有找到对应的组件Id,那么就会返回无效的ID
|
|
|
|
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
|
|
|
|
int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE,
|
|
|
|
|
int widgetType = intent.getIntExtra(Notes.INTENT_EXTRA_WIDGET_TYPE,//获取组件的类型
|
|
|
|
|
Notes.TYPE_WIDGET_INVALIDE);
|
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,
|
|
|
|
|
int bgResId = intent.getIntExtra(Notes.INTENT_EXTRA_BACKGROUND_ID,//获取组件的背景Id,如果没有就默认的背景颜色
|
|
|
|
|
ResourceParser.getDefaultBgId(this));
|
|
|
|
|
|
|
|
|
|
// Parse call-record note
|
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
|
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);
|
|
|
|
|
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);//获取手机号码
|
|
|
|
|
long callDate = intent.getLongExtra(Notes.INTENT_EXTRA_CALL_DATE, 0);//获取通话时间
|
|
|
|
|
if (callDate != 0 && phoneNumber != null) {
|
|
|
|
|
if (TextUtils.isEmpty(phoneNumber)) {
|
|
|
|
|
if (TextUtils.isEmpty(phoneNumber)) {//如果没有该电话号
|
|
|
|
|
Log.w(TAG, "The call record number is null");
|
|
|
|
|
}
|
|
|
|
|
long noteId = 0;
|
|
|
|
|
if ((noteId = DataUtils.getNoteIdByPhoneNumberAndCallDate(getContentResolver(),
|
|
|
|
|
phoneNumber, callDate)) > 0) {
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);
|
|
|
|
|
if (mWorkingNote == null) {
|
|
|
|
|
phoneNumber, callDate)) > 0) {//如果从数据库找到对应的电话号和日期号了那么就进行此操作
|
|
|
|
|
mWorkingNote = WorkingNote.load(this, noteId);//加载该便签
|
|
|
|
|
if (mWorkingNote == null) {//打开失败
|
|
|
|
|
Log.e(TAG, "load call note failed with note id" + noteId);
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
} else {//没有对应的日期或者没有对应的电话号码
|
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId,
|
|
|
|
|
widgetType, bgResId);
|
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);
|
|
|
|
|
widgetType, bgResId);//新建立一个便签
|
|
|
|
|
mWorkingNote.convertToCallNote(phoneNumber, callDate);//转化为电话记录便签
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
} else {//如果有一者为空那么就代表是创建一个普通的便签
|
|
|
|
|
mWorkingNote = WorkingNote.createEmptyNote(this, folderId, widgetId, widgetType,
|
|
|
|
|
bgResId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getWindow().setSoftInputMode(
|
|
|
|
|
getWindow().setSoftInputMode(//也是软键盘形式
|
|
|
|
|
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE
|
|
|
|
|
| WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
Log.e(TAG, "Intent not specified action, should not support");
|
|
|
|
|
Log.e(TAG, "Intent not specified action, should not support");//不支持此类操作。
|
|
|
|
|
finish();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);
|
|
|
|
|
mWorkingNote.setOnSettingStatusChangedListener(this);//建立好之后进行监听,对更改或删除便签做相应的改变
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
protected void onResume() {//当由后台到前台的时候进行调用
|
|
|
|
|
super.onResume();
|
|
|
|
|
initNoteScreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void initNoteScreen() {
|
|
|
|
|
mNoteEditor.setTextAppearance(this, TextAppearanceResources
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());
|
|
|
|
|
.getTexAppearanceResource(mFontSizeId));//获取用户当前字体的大小
|
|
|
|
|
if (mWorkingNote.getCheckListMode() == TextNote.MODE_CHECK_LIST) {//转化为清单模式
|
|
|
|
|
switchToListMode(mWorkingNote.getContent());//获取对应的内容
|
|
|
|
|
} else {
|
|
|
|
|
mNoteEditor.setText(getHighlightQueryResult(mWorkingNote.getContent(), mUserQuery));
|
|
|
|
|
mNoteEditor.setSelection(mNoteEditor.getText().length());
|
|
|
|
|