这是我的一些关于ui理解的注释

lrx_branch
LiuRuiXuan 2 years ago
parent 82b971b01e
commit 6e3ccbfad2

@ -67,7 +67,7 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
Intent intent = getIntent();//获取页面
try {
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));//
mNoteId = Long.valueOf(intent.getData().getPathSegments().get(1));//找到是否有对应的NoteId
mSnippet = DataUtils.getSnippetById(this.getContentResolver(), mNoteId);
mSnippet = mSnippet.length() > SNIPPET_PREW_MAX_LEN ? mSnippet.substring(0,
SNIPPET_PREW_MAX_LEN) + getResources().getString(R.string.notelist_string_info)
@ -78,9 +78,9 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
}
mPlayer = new MediaPlayer();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {
showActionDialog();
playAlarmSound();
if (DataUtils.visibleInNoteDatabase(getContentResolver(), mNoteId, Notes.TYPE_NOTE)) {//如果存在对应的便签
showActionDialog();//发出对话框
playAlarmSound();//发出声音
} else {
finish();
}

@ -30,10 +30,14 @@ import net.micode.notes.data.Notes.NoteColumns;
public class FoldersListAdapter extends CursorAdapter {
public static final String [] PROJECTION = {//投影
//CursorAdapter是Cursor和ListView的接口
//FoldersListAdapter继承了CursorAdapter的类
//主要作用是便签数据库和用户的交互
//这里就是用folder文件夹的形式展现给用户
public static final String [] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
};
};//调用数据库中便签的ID和片段
public static final int ID_COLUMN = 0;
public static final int NAME_COLUMN = 1;
@ -41,35 +45,35 @@ public class FoldersListAdapter extends CursorAdapter {
public FoldersListAdapter(Context context, Cursor c) {
super(context, c);
// TODO Auto-generated constructor stub
}
}//数据库操作
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new FolderListItem(context);
}
}//创建一个文件夹,对于各文件夹中子标签的初始化
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof FolderListItem) {
if (view instanceof FolderListItem) {//FolderListItem是显示子图如果view是该类的实例那么就去cursor中获取文件夹的名称并将其绑定到FolderListItem上
String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
((FolderListItem) view).bind(folderName);
}
}
}//将各个布局文件绑定起来
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);
}
}//根据数据库中标签的ID得到标签的各项内容
private class FolderListItem extends LinearLayout {
private TextView mName;
public FolderListItem(Context context) {
super(context);
super(context);//操作数据库
inflate(context, R.layout.folder_list_item, this);
mName = (TextView) findViewById(R.id.tv_folder_name);
mName = (TextView) findViewById(R.id.tv_folder_name);//根据布局文件的名字等信息将其找出来
}
public void bind(String name) {

@ -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());

Loading…
Cancel
Save