NoteListActivity

pull/8/head
eazzy 11 months ago
parent 9011d852d6
commit c62e68375d

@ -42,7 +42,6 @@
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@style/NoteTheme"
android:uiOptions="splitActionBarWhenNarrow"
android:windowSoftInputMode="adjustPan" >
<intent-filter>

@ -1,5 +1,6 @@
package net.micode.notes.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
@ -61,12 +62,16 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
//主界面,一进入就是这个界面
/**
* @author k
*
* @Package: net.micode.notes.ui
* @ClassName: NotesListActivity
* @Description:
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:02
* @Version: 1.0
*/
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener { //没有用特定的标签加注释。。。感觉没有什么用
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;
@ -77,7 +82,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private static final int MENU_FOLDER_CHANGE_NAME = 2;
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction"; //单行超过80个字符
private static final String PREFERENCE_ADD_INTRODUCTION = "net.micode.notes.introduction";
private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
@ -122,58 +127,62 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103;
@Override
/**
* @method onCreate
* @description
* @date: 9:58 AM
* @author: YangYizhe
* @param [savedInstanceState]
* @return void
* @method onCreate
* @description:
* @date: 2023/12/21 1:52
* @author: WUSHUXIAN
* @param void
* @return void
*/
protected void onCreate(final Bundle savedInstanceState) { //需要是final类型 根据程序上下文环境Java关键字final有“这是无法改变的”或者“终态的”含义它可以修饰非抽象类、非抽象类成员方法和变量。你可能出于两种理解而需要阻止改变设计或效率。
// final类不能被继承没有子类final类中的方法默认是final的。
//final方法不能被子类的方法覆盖但可以被继承。
//final成员变量表示常量只能被赋值一次赋值后值不再改变。
//final不能用于修饰构造方法。
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // 调用父类的onCreate函数
setContentView(R.layout.note_list);
initResources();
/**
* Insert an introduction when user firstly use this application
*/
setAppInfoFromRawRes();
}
@Override
// 返回一些子模块完成的数据交给主Activity处理
/**
* @method onActivityResult
* @description:
*
* requestCode
* resultCode
* data
* @date: 2023/12/20 23:26
* @author: WUSHUXIAN
* @param void
* @return void
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 结果值 和 要求值 符合要求
if (resultCode == RESULT_OK
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
mNotesListAdapter.changeCursor(null);
} else {
super.onActivityResult(requestCode, resultCode, data);
// 调用 Activity 的onActivityResult
super.onActivityResult(requestCode, resultCode, data);// 调用 Activity 的onActivityResult()
}
}
/**
* @method setAppInfoFromRawRes
* @description:
* @date: 2023/12/20 23:24
* @author: WUSHUXIAN
* @param
* @return
*/
private void setAppInfoFromRawRes() {
// Android平台给我们提供了一个SharedPreferences类它是一个轻量级的存储类特别适合用于保存软件配置参数。
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);// Android平台给我们提供了一个SharedPreferences类它是一个轻量级的存储类特别适合用于保存软件配置参数。
if (!sp.getBoolean(PREFERENCE_ADD_INTRODUCTION, false)) {
StringBuilder sb = new StringBuilder();
InputStream in = null;
try {
// 把资源文件放到应用程序的/raw/raw下那么就可以在应用中使用getResources获取资源后,
// 以openRawResource方法不带后缀的资源文件名打开这个文件。
in = getResources().openRawResource(R.raw.introduction);
if (in != null) {
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
char [] buf = new char[1024]; // 自行定义的数值,使用者不知道有什么意义
char [] buf = new char[1024];
int len = 0;
while ((len = br.read(buf)) > 0) {
sb.append(buf, 0, len);
@ -216,8 +225,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
super.onStart();
startAsyncNotesListQuery();
}
// 初始化资源
/**
* @method initResources
* @description
* @date: 2023/12/20 23:09
* @author: WUSHUXIAN
* @param
* @return
*/
private void initResources() {
mContentResolver = this.getContentResolver(); // 获取应用程序的数据,得到类似数据表的东西
mBackgroundQueryHandler = new BackgroundQueryHandler(this.getContentResolver());
@ -242,7 +257,15 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mModeCallBack = new ModeCallback();
}
// 继承自ListView.MultiChoiceModeListener 和 OnMenuItemClickListener
//
/**
* @Package: net.micode.notes.ui
* @ClassName: ModeCallback
* @Description: ListView.MultiChoiceModeListener OnMenuItemClickListener
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/20 23:37
* @Version: 1.0
*/
private class ModeCallback implements ListView.MultiChoiceModeListener, OnMenuItemClickListener {
private DropdownMenu mDropDownMenu;
private ActionMode mActionMode;
@ -280,8 +303,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
return true;
}
// 更新菜单
/**
* @method updateMenu
* @description
* @date: 2023/12/16 23:36
* @author: WUSHUXIAN
* @param
* @return
*/
private void updateMenu() {
int selectedCount = mNotesListAdapter.getSelectedCount();
// Update dropdown menu
@ -324,7 +353,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mNotesListAdapter.setCheckedItem(position, checked);
updateMenu();
}
/**
* @method onMenuItemClick
* @description:
* @date: 2023/12/20 23:39
* @author: WUSHUXIAN
* @param
* @return
*/
public boolean onMenuItemClick(MenuItem item) {
if (mNotesListAdapter.getSelectedCount() == 0) {
Toast.makeText(NotesListActivity.this, getString(R.string.menu_select_none),
@ -356,9 +392,8 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
return true;
}
}
//接口的实现
private class NewNoteOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
@ -418,22 +453,44 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
};
/**
* @method startAsyncNotesListQuery
* @description: Notes
* @date: 2023/12/20 23:45
* @author: WUSHUXIAN
* @param
* @return
*/
private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION;
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION : NORMAL_SELECTION;
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
String.valueOf(mCurrentFolderId)
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {String.valueOf(mCurrentFolderId)},
NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
/**
* @Package: net.micode.notes.ui
* @ClassName: BackgroundQueryHandler
* @Description: AsyncQueryHandler
* @Author: WUSHUXIAN
* @CreateDate: 2023/12/21 0:01
* @Version: 1.0
*/
private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) {
super(contentResolver);
}
@Override
/**
* @method onQueryComplete
* @description:
* @date: 2023/12/20 23:56
* @author: WUSHUXIAN
* @param token
* @param cookie cookie
* @param cursor
* @return void
*/
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
switch (token) {
case FOLDER_NOTE_LIST_QUERY_TOKEN:
@ -472,28 +529,44 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
});
builder.show();
}
/**
* @method createNewNote
* @description 便
* @date: 12/21/2023 1:58 AM
* @author: YangYizhe
* @param
* @return
*/
private void createNewNote() {
Intent intent = new Intent(this, NoteEditActivity.class);
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
intent.putExtra(Notes.INTENT_EXTRA_FOLDER_ID, mCurrentFolderId);
this.startActivityForResult(intent, REQUEST_CODE_NEW_NODE);
}
/**
* @method batchDelete
* @description:
* 便
* @date: 2023/12/21 0:14
* @author: WUSHUXIAN
* @param
* @return void
*/
@SuppressLint("StaticFieldLeak")
private void batchDelete() {
new AsyncTask<Void, Void, HashSet<AppWidgetAttribute>>() {
protected HashSet<AppWidgetAttribute> doInBackground(Void... unused) {
HashSet<AppWidgetAttribute> widgets = mNotesListAdapter.getSelectedWidget();
//如果没有同步,直接删除
if (!isSyncMode()) {
// if not synced, delete notes directly
if (DataUtils.batchDeleteNotes(mContentResolver, mNotesListAdapter
.getSelectedItemIds())) {
} else {
Log.e(TAG, "Delete notes error, should not happens");
}
} else {
// in sync mode, we'll move the deleted note into the trash
// folder
}
//已同步,将删除的便签移到垃圾桶
else {
if (!DataUtils.batchMoveToFolder(mContentResolver, mNotesListAdapter
.getSelectedItemIds(), Notes.ID_TRASH_FOLER)) {
Log.e(TAG, "Move notes to trash folder error, should not happens");
@ -516,7 +589,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
}.execute();
}
/**
* @method deleteFolder
* @description:
* @date: 2023/12/21 0:32
* @author: WUSHUXIAN
* @param folderId
* @return void
*/
private void deleteFolder(long folderId) {
if (folderId == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Wrong folder id, should not happen " + folderId);
@ -585,7 +665,14 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
/**
* @method showCreateOrModifyFolderDialog
* @description:
* @date: 2023/12/21 0:39
* @author: WUSHUXIAN
* @param create
* @return void
*/
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);
@ -643,13 +730,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
dialog.dismiss();
}
});
//如果便签名是空的,则禁用确认按钮
if (TextUtils.isEmpty(etName.getText())) {
positive.setEnabled(false);
}
/**
* When the name edit text is null, disable the positive button
*/
etName.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
@ -676,26 +760,27 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
*
*/
@Override
public void onBackPressed() { switch (mState) {
case SUB_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
startAsyncNotesListQuery();
mTitleBar.setVisibility(View.GONE);
break;
case CALL_RECORD_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
mAddNewNote.setVisibility(View.VISIBLE);
mTitleBar.setVisibility(View.GONE);
startAsyncNotesListQuery();
break;
case NOTE_LIST:
super.onBackPressed();
break;
default:
break;
}
public void onBackPressed() {
switch (mState) {
case SUB_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
startAsyncNotesListQuery();
mTitleBar.setVisibility(View.GONE);
break;
case CALL_RECORD_FOLDER:
mCurrentFolderId = Notes.ID_ROOT_FOLDER;
mState = ListEditState.NOTE_LIST;
mAddNewNote.setVisibility(View.VISIBLE);
mTitleBar.setVisibility(View.GONE);
startAsyncNotesListQuery();
break;
case NOTE_LIST:
super.onBackPressed();
break;
default:
break;
}
}
/**
@ -721,9 +806,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
sendBroadcast(intent);
setResult(RESULT_OK, intent);
}
/**
*
* @method OnCreateContextMenuListener
* @description: 便
* @date: 2023/12/21 1:16
* @author: WUSHUXIAN
* @param
* @return
*/
private final OnCreateContextMenuListener mFolderOnCreateContextMenuListener = new OnCreateContextMenuListener() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
@ -900,7 +989,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
}
/**
* @author k
* 便
*/
private class OnListItemClickListener implements OnItemClickListener {

@ -64,6 +64,6 @@
<style name="NoteActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions" />
<item name="android:visibility">gone</item>
<item name="android:visibility">visible</item>
</style>
</resources>
Loading…
Cancel
Save