parent
dfcbfd2df2
commit
c39d1c5661
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!-- 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<item android:color="#50000000" />
|
||||||
|
<!--
|
||||||
|
定义了默认颜色
|
||||||
|
-->
|
||||||
|
</selector>
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.PopupMenu;
|
||||||
|
import android.widget.PopupMenu.OnMenuItemClickListener;
|
||||||
|
|
||||||
|
import net.micode.notes.R;
|
||||||
|
|
||||||
|
public class DropdownMenu {
|
||||||
|
private Button mButton;
|
||||||
|
private PopupMenu mPopupMenu;//下拉菜单
|
||||||
|
private Menu mMenu;
|
||||||
|
|
||||||
|
//响应用户下拉菜单
|
||||||
|
public DropdownMenu(Context context, Button button, int menuId) {
|
||||||
|
mButton = button;
|
||||||
|
mButton.setBackgroundResource(R.drawable.dropdown_icon);//设置背景
|
||||||
|
mPopupMenu = new PopupMenu(context, mButton);//mButton代表下拉菜单要通过点击mButton来打开
|
||||||
|
mMenu = mPopupMenu.getMenu();
|
||||||
|
mPopupMenu.getMenuInflater().inflate(menuId, mMenu);//获取布局文件
|
||||||
|
mButton.setOnClickListener(new OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
mPopupMenu.show();
|
||||||
|
}
|
||||||
|
});//监听用户点击
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置监听下拉菜单中选项被选中的监听器
|
||||||
|
public void setOnDropdownMenuItemClickListener(OnMenuItemClickListener listener) {
|
||||||
|
if (mPopupMenu != null) {
|
||||||
|
mPopupMenu.setOnMenuItemClickListener(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//查找菜单中的项
|
||||||
|
public MenuItem findItem(int id) {
|
||||||
|
return mMenu.findItem(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
//设置按钮的显示文本
|
||||||
|
public void setTitle(CharSequence title) {
|
||||||
|
mButton.setText(title);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,229 @@
|
|||||||
|
/*
|
||||||
|
* 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.text.TextUtils;
|
||||||
|
|
||||||
|
import net.micode.notes.data.Contact;
|
||||||
|
import net.micode.notes.data.Notes;
|
||||||
|
import net.micode.notes.data.Notes.NoteColumns;
|
||||||
|
import net.micode.notes.tool.DataUtils;
|
||||||
|
|
||||||
|
|
||||||
|
public class NoteItemData {
|
||||||
|
//数据库中保存的便签的属性
|
||||||
|
static final String [] PROJECTION = new String [] {
|
||||||
|
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,
|
||||||
|
NoteColumns.TYPE,
|
||||||
|
NoteColumns.WIDGET_ID,
|
||||||
|
NoteColumns.WIDGET_TYPE,
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final int ID_COLUMN = 0;
|
||||||
|
private static final int ALERTED_DATE_COLUMN = 1;
|
||||||
|
private static final int BG_COLOR_ID_COLUMN = 2;
|
||||||
|
private static final int CREATED_DATE_COLUMN = 3;
|
||||||
|
private static final int HAS_ATTACHMENT_COLUMN = 4;
|
||||||
|
private static final int MODIFIED_DATE_COLUMN = 5;
|
||||||
|
private static final int NOTES_COUNT_COLUMN = 6;
|
||||||
|
private static final int PARENT_ID_COLUMN = 7;
|
||||||
|
private static final int SNIPPET_COLUMN = 8;
|
||||||
|
private static final int TYPE_COLUMN = 9;
|
||||||
|
private static final int WIDGET_ID_COLUMN = 10;
|
||||||
|
private static final int WIDGET_TYPE_COLUMN = 11;//设置属性值
|
||||||
|
|
||||||
|
private long mId;
|
||||||
|
private long mAlertDate;
|
||||||
|
private int mBgColorId;
|
||||||
|
private long mCreatedDate;
|
||||||
|
private boolean mHasAttachment;
|
||||||
|
private long mModifiedDate;
|
||||||
|
private int mNotesCount;
|
||||||
|
private long mParentId;
|
||||||
|
private String mSnippet;
|
||||||
|
private int mType;
|
||||||
|
private int mWidgetId;
|
||||||
|
private int mWidgetType;
|
||||||
|
private String mName;
|
||||||
|
private String mPhoneNumber;
|
||||||
|
|
||||||
|
private boolean mIsLastItem;
|
||||||
|
private boolean mIsFirstItem;
|
||||||
|
private boolean mIsOnlyOneItem;
|
||||||
|
private boolean mIsOneNoteFollowingFolder;
|
||||||
|
private boolean mIsMultiNotesFollowingFolder;
|
||||||
|
|
||||||
|
//构造函数,设置通过光标能获得的属性
|
||||||
|
public NoteItemData(Context context, Cursor cursor) {
|
||||||
|
mId = cursor.getLong(ID_COLUMN);
|
||||||
|
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
|
||||||
|
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
|
||||||
|
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
|
||||||
|
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;
|
||||||
|
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
|
||||||
|
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
|
||||||
|
mParentId = cursor.getLong(PARENT_ID_COLUMN);
|
||||||
|
mSnippet = cursor.getString(SNIPPET_COLUMN);
|
||||||
|
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(
|
||||||
|
NoteEditActivity.TAG_UNCHECKED, "");
|
||||||
|
mType = cursor.getInt(TYPE_COLUMN);
|
||||||
|
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
|
||||||
|
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
|
||||||
|
|
||||||
|
//初始化电话号
|
||||||
|
mPhoneNumber = "";
|
||||||
|
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
|
||||||
|
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
|
||||||
|
if (!TextUtils.isEmpty(mPhoneNumber)) {
|
||||||
|
mName = Contact.getContact(context, mPhoneNumber);
|
||||||
|
if (mName == null) {
|
||||||
|
mName = mPhoneNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mName == null) {
|
||||||
|
mName = "";
|
||||||
|
}
|
||||||
|
checkPostion(cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
//检测cursor指定项的位置
|
||||||
|
private void checkPostion(Cursor cursor) {
|
||||||
|
mIsLastItem = cursor.isLast() ? true : false;
|
||||||
|
mIsFirstItem = cursor.isFirst() ? true : false;
|
||||||
|
mIsOnlyOneItem = (cursor.getCount() == 1);
|
||||||
|
mIsMultiNotesFollowingFolder = false;
|
||||||
|
mIsOneNoteFollowingFolder = false;
|
||||||
|
|
||||||
|
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {
|
||||||
|
int position = cursor.getPosition();
|
||||||
|
if (cursor.moveToPrevious()) {
|
||||||
|
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER
|
||||||
|
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
|
||||||
|
if (cursor.getCount() > (position + 1)) {
|
||||||
|
mIsMultiNotesFollowingFolder = true;
|
||||||
|
} else {
|
||||||
|
mIsOneNoteFollowingFolder = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!cursor.moveToNext()) {
|
||||||
|
throw new IllegalStateException("cursor move to previous but can't move back");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//都是获取便签项的信息的方法
|
||||||
|
public boolean isOneFollowingFolder() {
|
||||||
|
return mIsOneNoteFollowingFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMultiFollowingFolder() {
|
||||||
|
return mIsMultiNotesFollowingFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLast() {
|
||||||
|
return mIsLastItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCallName() {
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFirst() {
|
||||||
|
return mIsFirstItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSingle() {
|
||||||
|
return mIsOnlyOneItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return mId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getAlertDate() {
|
||||||
|
return mAlertDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCreatedDate() {
|
||||||
|
return mCreatedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAttachment() {
|
||||||
|
return mHasAttachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getModifiedDate() {
|
||||||
|
return mModifiedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBgColorId() {
|
||||||
|
return mBgColorId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getParentId() {
|
||||||
|
return mParentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNotesCount() {
|
||||||
|
return mNotesCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFolderId () {
|
||||||
|
return mParentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidgetType() {
|
||||||
|
return mWidgetType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidgetId() {
|
||||||
|
return mWidgetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSnippet() {
|
||||||
|
return mSnippet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasAlert() {
|
||||||
|
return (mAlertDate > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCallRecord() {
|
||||||
|
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getNoteType(Cursor cursor) {
|
||||||
|
return cursor.getInt(TYPE_COLUMN);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue