Merge branch 'zxy_branch' into dev

# Conflicts:
#	.idea/modules.xml
#	app/src/main/java/net/micode/notes/ui/NotesListAdapter.java
#	src/.idea/misc.xml
#	src/.idea/modules/app/minote.app.iml
#	src/.idea/modules/app/minote.app.main.iml
#	src/.idea/modules/app/minote.app.unitTest.iml
#	src/app/src/main/java/net/micode/notes/ui/NotesListActivity.java
#	src/app/src/main/res/menu/note_list.xml
#	src/local.properties
#	src/minote.iml
pull/24/head
beitingnanxu 2 years ago
commit bca749855c

@ -0,0 +1,203 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.ui;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import net.micode.notes.data.Notes;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
private Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex;
private int mNotesCount;
private boolean mChoiceMode;
public static class AppWidgetAttribute {
public int widgetId;
public int widgetType;
};
public NotesListAdapter(Context context) {
super(context, null);
mSelectedIndex = new HashMap<Integer, Boolean>();
mContext = context;
mNotesCount = 0;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) {
NoteItemData itemData = new NoteItemData(context, cursor);
((NotesListItem) view).bind(context, itemData, mChoiceMode,
isSelectedItem(cursor.getPosition()));
}
}
public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked);
notifyDataSetChanged();
}
public boolean isInChoiceMode() {
return mChoiceMode;
}
public void setChoiceMode(boolean mode) {
mSelectedIndex.clear();
mChoiceMode = mode;
}
public void selectAll(boolean checked) {
Cursor cursor = getCursor();
for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) {
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
setCheckedItem(i, checked);
}
}
}
}
public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>();
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
Long id = getItemId(position);
if (id == Notes.ID_ROOT_FOLDER) {
Log.d(TAG, "Wrong item id, should not happen");
} else {
itemSet.add(id);
}
}
}
return itemSet;
}
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
Cursor c = (Cursor) getItem(position);
if (c != null) {
AppWidgetAttribute widget = new AppWidgetAttribute();
NoteItemData item = new NoteItemData(mContext, c);
widget.widgetId = item.getWidgetId();
widget.widgetType = item.getWidgetType();
itemSet.add(widget);
/**
* Don't close cursor here, only the adapter could close it
*/
} else {
Log.e(TAG, "Invalid cursor");
return null;
}
}
}
return itemSet;
}
public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values();
if (null == values) {
return 0;
}
Iterator<Boolean> iter = values.iterator();
int count = 0;
while (iter.hasNext()) {
if (true == iter.next()) {
count++;
}
}
return count;
}
public boolean isAllSelected() {
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);
}
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
return false;
}
return mSelectedIndex.get(position);
}
@Override
protected void onContentChanged() {
super.onContentChanged();
calcNotesCount();
}
@Override
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
calcNotesCount();
}
private void calcNotesCount() {
mNotesCount = 0;
for (int i = 0; i < getCount(); i++) {
Cursor c = (Cursor) getItem(i);
if (c != null) {
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
mNotesCount++;
}
} else {
Log.e(TAG, "Invalid cursor");
return;
}
}
}
public int retCount() {
int NotesCount = mNotesCount;
int ItemCount = getCount();
for (int i = 0; i < ItemCount; i++) {
Cursor c = (Cursor) getItem(i);
if (c != null) {
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
NoteItemData NoteItem = new NoteItemData(mContext, c);
NotesCount += NoteItem.getNotesCount();
}
} else {
Log.e(TAG, "Invalid cursor");
return -1;
}
}
return NotesCount;
}
}

@ -65,16 +65,19 @@ public abstract class NoteWidgetProvider extends AppWidgetProvider {
使 getContentResolver() ContentResolver update() NoteColumns.WIDGET_ID + "=?" NoteColumns.WIDGET_ID ID values NoteColumns.WIDGET_ID AppWidgetManager.INVALID_APPWIDGET_ID*/ 使 getContentResolver() ContentResolver update() NoteColumns.WIDGET_ID + "=?" NoteColumns.WIDGET_ID ID values NoteColumns.WIDGET_ID AppWidgetManager.INVALID_APPWIDGET_ID*/
private Cursor getNoteWidgetInfo(Context context, int widgetId) {// 使用 getContentResolver() 方法获取 ContentResolver 对象,通过该对象进行对笔记数据库的查询操作 private Cursor getNoteWidgetInfo(Context context, int widgetId) {
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI, // 使用 query() 方法查询笔记数据库,返回一个 Cursor 对象 return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
return context.getContentResolver().query(// 查询的 URI笔记数据库中笔记的内容保存在该 URI 下
PROJECTION, PROJECTION,
Notes.CONTENT_NOTE_URI, NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",
PROJECTION, new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },
NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",// 查询的列,即笔记 ID、笔记背景颜色 ID 和笔记摘录内容 null);
new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },//查询的条件,即笔记关联的小部件 ID 以及笔记的父 ID 不为回收站的笔记 }/*使ContentResolverNotes.CONTENT_NOTE_URIURI
null);// 排序方式,这里为 null 表示不排序
} PROJECTIONNoteColumns.WIDGET_IDNoteColumns.PARENT_IDNoteColumns.WIDGET_IDIDNoteColumns.PARENT_IDID
IDID使selectionArgssortOrdernull
CursorCursor*/
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
update(context, appWidgetManager, appWidgetIds, false); update(context, appWidgetManager, appWidgetIds, false);

@ -93,7 +93,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
private enum ListEditState { private enum ListEditState {
NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER NOTE_LIST, SUB_FOLDER, CALL_RECORD_FOLDER
} };
private ListEditState mState; private ListEditState mState;
@ -797,6 +797,7 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
case R.id.menu_export_text: { case R.id.menu_export_text: {
exportNoteToText(); exportNoteToText();
break; break;
} }
case R.id.menu_sync: { case R.id.menu_sync: {
if (isSyncMode()) { if (isSyncMode()) {
@ -818,6 +819,10 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
createNewNote(); createNewNote();
break; break;
} }
case R.id.menu_countallNotes: {
showNumberofNotes();
break;
}
case R.id.menu_search: case R.id.menu_search:
onSearchRequested(); onSearchRequested();
break; break;
@ -970,4 +975,11 @@ public class NotesListActivity extends Activity implements OnClickListener, OnIt
mTitleBar.setText("回收站"); mTitleBar.setText("回收站");
mTitleBar.setVisibility(View.VISIBLE); mTitleBar.setVisibility(View.VISIBLE);
} }
private void showNumberofNotes() {
AlertDialog.Builder btr = new AlertDialog.Builder(this);
btr.setTitle("目前便签数");
btr.setMessage("目前有 " + Integer.toString(mNotesListAdapter.retCount()) + "个便签");
btr.show();
}
} }

@ -19,23 +19,28 @@
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:id="@+id/menu_new_folder" android:id="@+id/menu_new_folder"
android:title="新建文件夹" /> android:title="@string/menu_create_folder"/>
<item <item
android:id="@+id/menu_export_text" android:id="@+id/menu_export_text"
android:title="导出文本" /> android:title="@string/menu_export_text"/>
<item <item
android:id="@+id/menu_sync" android:id="@+id/menu_sync"
android:title="同步" /> android:title="@string/menu_sync"/>
<item <item
android:id="@+id/menu_setting" android:id="@+id/menu_setting"
android:title="设置" /> android:title="@string/menu_setting" />
<item <item
android:id="@+id/menu_search" android:id="@+id/menu_search"
android:title="搜索" /> android:title="@string/menu_search"/>
<item
android:id="@+id/menu_countallNotes"
android:title="@string/menu_countallNotes"/>
<item <item
android:id="@+id/menu_restore" android:id="@+id/menu_restore"
android:title="回收站"/> android:title="回收站"/>

@ -119,6 +119,7 @@
<string name="button_delete">Delete</string> <string name="button_delete">Delete</string>
<string name="call_record_folder_name">Call notes</string> <string name="call_record_folder_name">Call notes</string>
<string name="hint_foler_name">Input name</string> <string name="hint_foler_name">Input name</string>
<string name="menu_countallNotes" translatable="false">countallNotes" </string>
<string name="search_label">Searching Notes</string> <string name="search_label">Searching Notes</string>
<string name="search_hint">Search notes</string> <string name="search_hint">Search notes</string>

Loading…
Cancel
Save