实现背景及切换

修改了
menu/note_list.xml
strings.xml
layout/note_list.xml
NoteListActivity.java
pull/10/head
王润泽 11 months ago
parent 3efc053b12
commit a8223eb850

@ -79,6 +79,8 @@ import java.io.InputStreamReader;
import java.util.HashSet; import java.util.HashSet;
public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener { public class NotesListActivity extends Activity implements OnClickListener, OnItemLongClickListener {
//首页背景变换
private int mode = -1;
private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0; private static final int FOLDER_NOTE_LIST_QUERY_TOKEN = 0;
private static final int FOLDER_LIST_QUERY_TOKEN = 1; private static final int FOLDER_LIST_QUERY_TOKEN = 1;
@ -95,28 +97,38 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
}; };
// 声明一些私有成员变量。 private ListEditState mState;
private ListEditState mState; // 当前列表的编辑状态
private BackgroundQueryHandler mBackgroundQueryHandler; // 用于在后台执行查询的处理程序 private BackgroundQueryHandler mBackgroundQueryHandler;
private NotesListAdapter mNotesListAdapter; // 笔记列表的适配器
private ListView mNotesListView; // 显示笔记列表的视图 private NotesListAdapter mNotesListAdapter;
private Button mAddNewNote; // 添加新笔记的按钮
private boolean mDispatch; // 一个标志,可能用于控制事件分发 private ListView mNotesListView;
private int mOriginY; // 原始Y坐标可能用于触摸事件处理
private int mDispatchY; // 分发的Y坐标也可能用于触摸事件处理 private Button mAddNewNote;
private TextView mTitleBar; // 标题栏文本视图
private long mCurrentFolderId; // 当前文件夹的ID private boolean mDispatch;
private ContentResolver mContentResolver; // 内容解析器,用于访问应用的数据
private ModeCallback mModeCallBack; // 模式回调接口的实现,可能用于在不同的操作模式之间切换 private int mOriginY;
private int mDispatchY;
private TextView mTitleBar;
private long mCurrentFolderId;
private ContentResolver mContentResolver;
private ModeCallback mModeCallBack;
private static final String TAG = "NotesListActivity"; private static final String TAG = "NotesListActivity";
public static final int NOTES_LISTVIEW_SCROLL_RATE = 30; public static final int NOTES_LISTVIEW_SCROLL_RATE = 30;
//正在关注的笔记数据对象
private NoteItemData mFocusNoteDataItem; private NoteItemData mFocusNoteDataItem;
private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?"; private static final String NORMAL_SELECTION = NoteColumns.PARENT_ID + "=?";
//拼接访问串
private static final String ROOT_FOLDER_SELECTION = "(" + NoteColumns.TYPE + "<>" 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.ID + "=" + Notes.ID_CALL_RECORD_FOLDER + " AND "
@ -124,22 +136,12 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private final static int REQUEST_CODE_OPEN_NODE = 102; private final static int REQUEST_CODE_OPEN_NODE = 102;
private final static int REQUEST_CODE_NEW_NODE = 103; private final static int REQUEST_CODE_NEW_NODE = 103;
//表示是否在私密模式
public static int secret_mode = 0;
/**
* @classname: NotesListActivity
* @methodname onCreate
* @description:
* @date: 2024/1/4 11:47
* @author: Xia Yanbo
* @param:savedInstanceState
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//根据布局文件呈现菜单视图
setContentView(R.layout.note_list); setContentView(R.layout.note_list);
getWindow().setBackgroundDrawableResource(R.drawable.decade);//将decade作为初始背景
initResources(); initResources();
/** /**
@ -147,25 +149,13 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
*/ */
setAppInfoFromRawRes(); setAppInfoFromRawRes();
} }
/**
* @classname: NotesListActivity
* @methodname onActivityResult
* @description:
* @date: 2024/1/4 11:49
* @author: Xia Yanbo
* @param:requestCode
* @param:resultCode
* @param:data
*/
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// 根据请求的代码类型进行相应的处理 if (resultCode == RESULT_OK
if (resultCode == RESULT_OK // 如果返回的结果码是RESULT_OK表示操作成功 && (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) {
&& (requestCode == REQUEST_CODE_OPEN_NODE || requestCode == REQUEST_CODE_NEW_NODE)) { // 并且请求码是打开节点或新建节点
// 清空笔记列表的适配器游标(可能是在执行打开或新建节点操作后,刷新或重置列表)
mNotesListAdapter.changeCursor(null); mNotesListAdapter.changeCursor(null);
} else { // 其他情况 } else {
// 调用父类的onActivityResult方法将结果传递给上层处理。
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
} }
} }
@ -425,36 +415,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private void startAsyncNotesListQuery() { private void startAsyncNotesListQuery() {
String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION String selection = (mCurrentFolderId == Notes.ID_ROOT_FOLDER) ? ROOT_FOLDER_SELECTION
: NORMAL_SELECTION; : NORMAL_SELECTION;
if(secret_mode == 0) {
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null, mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] { Notes.CONTENT_NOTE_URI, NoteItemData.PROJECTION, selection, new String[] {
String.valueOf(mCurrentFolderId) String.valueOf(mCurrentFolderId)
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC"); }, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
} }
else{
String str1 = "520";
String [] PROJECTION = new String [] { //定义一个新的PROJECTION数组只换掉SNIPPET
NoteColumns.ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,
NoteColumns.CREATED_DATE,
NoteColumns.HAS_ATTACHMENT,
NoteColumns.MODIFIED_DATE,
NoteColumns.NOTES_COUNT,
NoteColumns.PARENT_ID,
// NoteColumns.SNIPPET,
str1,
NoteColumns.TYPE,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
};
mBackgroundQueryHandler.startQuery(FOLDER_NOTE_LIST_QUERY_TOKEN, null,
Notes.CONTENT_NOTE_URI, PROJECTION, selection, new String[]{
String.valueOf(mCurrentFolderId)
}, NoteColumns.TYPE + " DESC," + NoteColumns.MODIFIED_DATE + " DESC");
}
}
private final class BackgroundQueryHandler extends AsyncQueryHandler { private final class BackgroundQueryHandler extends AsyncQueryHandler {
public BackgroundQueryHandler(ContentResolver contentResolver) { public BackgroundQueryHandler(ContentResolver contentResolver) {
@ -810,16 +775,28 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} else { } else {
Log.e(TAG, "Wrong state:" + mState); Log.e(TAG, "Wrong state:" + mState);
} }
if(secret_mode == 1)
menu.findItem(R.id.menu_secret).setVisible(false); if(mode==-1){//decade
else menu.findItem(R.id.menu_decade).setVisible(false);
menu.findItem(R.id.menu_quit_secret).setVisible(false); }
else if(mode==1){//zio
menu.findItem(R.id.menu_zio).setVisible(false);
}
return true; return true;
} }
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==R.id.menu_new_folder){ if(item.getItemId()==R.id.menu_decade){
mode = -1;
getWindow().setBackgroundDrawableResource(R.drawable.decade);
}
else if(item.getItemId()==R.id.menu_zio){
mode = 1;
getWindow().setBackgroundDrawableResource(R.drawable.zio);
}
else if(item.getItemId()==R.id.menu_new_folder){
showCreateOrModifyFolderDialog(true); showCreateOrModifyFolderDialog(true);
} }
else if(item.getItemId()==R.id.menu_export_text ){ else if(item.getItemId()==R.id.menu_export_text ){
@ -846,50 +823,6 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
else if(item.getItemId()==R.id.menu_search) { else if(item.getItemId()==R.id.menu_search) {
onSearchRequested(); onSearchRequested();
} }
else if(item.getItemId()==R.id.menu_secret)
{//进入私密模式
secret_mode = 1;
AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this);
dialog.setTitle("重要提醒");
dialog.setMessage("您确认进入私密模式吗?");
dialog.setCancelable(false);
dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startAsyncNotesListQuery();
Toast.makeText(NotesListActivity.this,"您已进入私密模式",Toast.LENGTH_SHORT).show();
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which){}
});
dialog.show();
startAsyncNotesListQuery();
Toast.makeText(this,"您已进入私密模式",Toast.LENGTH_SHORT).show();
}
else if(item.getItemId()==R.id.menu_quit_secret)
{ //退出私密模式
secret_mode = 0;
AlertDialog.Builder dialog = new AlertDialog.Builder(NotesListActivity.this);
dialog.setTitle("重要提醒");
dialog.setMessage("您确认退出私密模式吗?");
dialog.setCancelable(false);
dialog.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startAsyncNotesListQuery();
Toast.makeText(NotesListActivity.this,"您已退出私密模式",Toast.LENGTH_SHORT).show();
}
});
dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which){}
});
dialog.show();
}
return true; return true;
} }
@ -1027,16 +960,4 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
} }
return false; return false;
} }
public static void setSecretMode() {
if(secret_mode==0)
{
secret_mode=1;
}
else{
secret_mode=0;
}
} }
}

@ -18,8 +18,8 @@
<FrameLayout <FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent">
android:background="@drawable/list_background"> <!--android:background="@drawable/list_background"-->
<LinearLayout <LinearLayout
android:layout_width="fill_parent" android:layout_width="fill_parent"

@ -36,12 +36,12 @@
<item <item
android:id="@+id/menu_search" android:id="@+id/menu_search"
android:title="@string/menu_search"/> android:title="@string/menu_search"/>
<item
android:id="@+id/menu_secret"
android:title="@string/menu_secret"/>
<item <item
android:id="@+id/menu_quit_secret" android:id="@+id/menu_decade"
android:title="@string/menu_quit_secret"/> android:title="@string/menu_decade"/>
<item
android:id="@+id/menu_zio"
android:title="@string/menu_zio"/>
</menu> </menu>

@ -39,6 +39,11 @@
<string name="file_path">/MIUI/notes/</string> <string name="file_path">/MIUI/notes/</string>
<string name="file_name_txt_format">notes_%s.txt</string> <string name="file_name_txt_format">notes_%s.txt</string>
<!-- notes list string --> <!-- notes list string -->
<!--首页背景切换-->
<string name="menu_decade">Background: decade</string>
<string name="menu_zio">Background: zio</string>
<string name="format_folder_files_count">(%d)</string> <string name="format_folder_files_count">(%d)</string>
<string name="menu_create_folder">New Folder</string> <string name="menu_create_folder">New Folder</string>
<string name="menu_export_text">Export text</string> <string name="menu_export_text">Export text</string>
@ -75,8 +80,6 @@
<string name="alert_message_delete_notes">Confirm to delete the selected %d notes?</string> <string name="alert_message_delete_notes">Confirm to delete the selected %d notes?</string>
<string name="alert_message_delete_note">Confirm to delete this note?</string> <string name="alert_message_delete_note">Confirm to delete this note?</string>
<string name="format_move_notes_to_folder">Have moved selected %1$d notes to %2$s folder</string> <string name="format_move_notes_to_folder">Have moved selected %1$d notes to %2$s folder</string>
<string name="menu_secret">secret model</string>
<string name="menu_quit_secret">quit secret model</string>
<!-- Error information --> <!-- Error information -->
<string name="error_sdcard_unmounted">SD card busy, not available now</string> <string name="error_sdcard_unmounted">SD card busy, not available now</string>
<string name="error_sdcard_export">Export failed, please check SD card</string> <string name="error_sdcard_export">Export failed, please check SD card</string>

Loading…
Cancel
Save