添加快速搜索提示

This commit is contained in:
seven332 committed 2014-07-29 09:24:01 +08:00
1 parent 8abe21c536
commit ef154867a6
5 files changed
+125 -96

No files matched your search

+29 -11
View File
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 Hippo Seven
<!--
Copyright (C) 2014 Hippo Seven
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -12,14 +13,31 @@
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.
-->
<com.hippo.ehviewer.widget.TagListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list_menu_tag_list"
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/holo_blue_dark"
android:choiceMode="singleChoice"
android:clickable="true"
android:divider="@color/detail_divider"
android:dividerHeight="1.0dp"
android:scrollbarThumbVertical="@drawable/scrollbar_white" />
android:layout_height="match_parent" >
<com.hippo.ehviewer.widget.TagListView
android:id="@+id/list_menu_tag_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:clickable="true"
android:divider="@color/detail_divider"
android:dividerHeight="1.0dp"
android:scrollbarThumbVertical="@drawable/scrollbar_white" />
<TextView
android:id="@+id/tip_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="18dp"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="18sp"
android:lineSpacingMultiplier="2"
android:text="@string/quick_search_tip" />
</RelativeLayout>
+4 -3
View File
@@ -82,10 +82,11 @@
<string name="toast_add_favourite">已添加到收藏</string>
<string name="toast_add_download">已添加到下载列表</string>
<!-- MangaListActivity -->
<!-- GalleryListActivity -->
<string name="no_found">未找到</string>
<string name="none">无</string>
<string name="list_title" formatted="false">%s 第 %d 页</string>
<string name="quick_search_tip">您可以再左侧栏搜索项中添加快速搜索</string>
<!-- Update -->
<string name="update_message" formatted="false">发现新版本:%s\n大小:%s\n%s\n\n是否更新?</string>
@@ -97,7 +98,7 @@
<string name="download_update">正在下载更新</string>
<string name="update_failed">下载更新失败</string>
<!-- MangaDetialActivity -->
<!-- GalleryDetialActivity -->
<string name="detail_pages_size" formatted="false">页数 : %s (%s)</string>
<string name="detail_language">语言 : %s</string>
<string name="detail_average">平均得分:%s</string>
@@ -115,7 +116,7 @@
<string name="vote_down">踩</string>
<string name="show_tagged">相同标签</string>
<!-- MangaActivity -->
<!-- GalleryActivity -->
<string name="load_pre">载入上一页</string>
<string name="first_page">已是第一页</string>
<string name="start_reloading">开始继续载入</string>
+4 -3
View File
@@ -84,10 +84,11 @@
<string name="toast_add_favourite">Add to favourite</string>
<string name="toast_add_download">Add to download list</string>
<!-- MangaListActivity -->
<!-- GalleryListActivity -->
<string name="no_found">No hits found</string>
<string name="none">None</string>
<string name="list_title" formatted="false">%s Page %d</string>
<string name="quick_search_tip">Quick search can be added via search in left drawer</string>
<!-- Update -->
<string name="update_message" formatted="false">Found new version : %s\nSize : %s\n%s\n\nUpdate ?</string>
@@ -99,7 +100,7 @@
<string name="download_update">Downloading the update</string>
<string name="update_failed">Download the update Failed</string>
<!-- MangaDetialActivity -->
<!-- GalleryDetialActivity -->
<string name="detail_pages_size" formatted="false">Pages : %s (%s)</string>
<string name="detail_language">Language : %s</string>
<string name="detail_offensive_title">Content Warning</string>
@@ -115,7 +116,7 @@
<string name="vote_down">Vote down</string>
<string name="show_tagged">Show tagged</string>
<!-- MangaActivity -->
<!-- GalleryActivity -->
<string name="load_pre">Load previous page</string>
<string name="first_page">First page !</string>
<string name="start_reloading">Start reloading</string>
@@ -152,6 +152,7 @@ public class GalleryListActivity extends AbstractGalleryActivity
private Button registerButton;
private Button logoutButton;
private View waitloginoutView;
private View mQuickSearchTip;
private StaggeredGridView mStaggeredGridView;
private BaseAdapter mAdapter;
@@ -883,14 +884,13 @@ public class GalleryListActivity extends AbstractGalleryActivity
mUserPanel = (LinearLayout)findViewById(R.id.user_panel);
itemListMenu = (ListView) findViewById(R.id.list_menu_item_list);
tagListMenu = (TagListView) findViewById(R.id.list_menu_tag_list);
avatar = (ImageView)mUserPanel.findViewById(R.id.avatar);
userView = (TextView)mUserPanel.findViewById(R.id.user);
loginButton = (Button)mUserPanel.findViewById(R.id.login);
registerButton = (Button)mUserPanel.findViewById(R.id.register);
logoutButton = (Button)mUserPanel.findViewById(R.id.logout);
waitloginoutView = mUserPanel.findViewById(R.id.wait);
mQuickSearchTip = findViewById(R.id.tip_text);
mStaggeredGridView = (StaggeredGridView)getContentView();
loginButton.setOnClickListener(this);
@@ -998,6 +998,19 @@ public class GalleryListActivity extends AbstractGalleryActivity
for (int i = 0; i < keys.size(); i++)
listMenuTag.add(keys.get(i));
tagsAdapter = new TagsAdapter(this, R.layout.menu_tag, listMenuTag);
tagsAdapter.setOnDataSetChangedListener(new TagsAdapter.OnDataSetChangedListener() {
@Override
public void OnDataSetChanged() {
if (listMenuTag.size() == 0)
mQuickSearchTip.setVisibility(View.VISIBLE);
else
mQuickSearchTip.setVisibility(View.GONE);
}
});
if (listMenuTag.size() == 0)
mQuickSearchTip.setVisibility(View.VISIBLE);
else
mQuickSearchTip.setVisibility(View.GONE);
tagListMenu.setClipToPadding(false);
tagListMenu.setAdapter(tagsAdapter);
tagListMenu.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
@@ -1062,17 +1075,6 @@ public class GalleryListActivity extends AbstractGalleryActivity
return true;
}
});
/*
mStaggeredGridView.setOnChangeColumnListener(new StaggeredGridView.OnChangeColumnListener() {
@Override
public void onChangeColumn(int columnCount, int width) {
// Here to get thumb height, width is fixed by column count
if (width == 0)
width = GalleryListActivity.this.getWindow()
.findViewById(Window.ID_ANDROID_CONTENT).getWidth();
mListModeThumbHeight = (width - ((columnCount + 1) * Ui.dp2pix(8))) / columnCount / 2 * 3;
}
});*/
FswView alignment = (FswView)findViewById(R.id.alignment);
alignment.addOnFitSystemWindowsListener(new OnFitSystemWindowsListener() {
@@ -1112,7 +1114,6 @@ public class GalleryListActivity extends AbstractGalleryActivity
// get MangeList
firstTimeRefresh();
// Show left column if first
if (Config.isFirstTime()) {
Config.firstTime();
+73 -65
View File
@@ -17,17 +17,21 @@
package com.hippo.ehviewer.widget;
import java.util.ArrayList;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.support.v4.util.LongSparseArray;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
@@ -37,9 +41,6 @@ import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.HashMap;
/**
* The dynamic listview is an extension of listview that supports cell dragging
* and swapping.
@@ -62,15 +63,16 @@ import java.util.HashMap;
* listview also scrolls on its own so as to reveal additional content.
*/
public class TagListView extends ListView {
private static final String TAG = "TagListView";
@SuppressWarnings("unused")
private static final String TAG = TagListView.class.getSimpleName();
private final int SMOOTH_SCROLL_AMOUNT_AT_EDGE = 15;
private final int MOVE_DURATION = 150;
private final int SENSITY = 5;
//public ArrayList<String> mItemList;
private int mLastEventX = -1;
private int mLastEventY = -1;
@@ -87,18 +89,18 @@ public class TagListView extends ListView {
private long mAboveItemId = INVALID_ID;
private long mMobileItemId = INVALID_ID;
private long mBelowItemId = INVALID_ID;
private int mStableItemCount = 0;
private BitmapDrawable mHoverCell;
private BitmapDrawable mDeleteCell;
private BitmapDrawable mModifyCell;
private Rect mHoverCellCurrentBounds;
private Rect mHoverCellOriginalBounds;
private boolean mIsDelete = false;
private boolean mIsModify = false;
private final int INVALID_POINTER_ID = -1;
private int mActivePointerId = INVALID_POINTER_ID;
@@ -109,7 +111,7 @@ public class TagListView extends ListView {
private OnMoveLister mMovelistener = null;
private OnDeleteListener mOnDeleteListener = null;
private OnSwapListener mOnSwapListener = null;
public TagListView(Context context) {
super(context);
init(context);
@@ -136,17 +138,18 @@ public class TagListView extends ListView {
* Listens for long clicks on any items in the listview. When a cell has
* been selected, the hover cell is created and set up.
*/
private AdapterView.OnItemLongClickListener mOnItemLongClickListener =
private final AdapterView.OnItemLongClickListener mOnItemLongClickListener =
new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
if (pos < mStableItemCount)
return true;
if (mMovelistener != null)
mMovelistener.onMoveStart();
mTotalOffset = 0;
int position = pointToPosition(mDownX, mDownY);
int itemNum = position - getFirstVisiblePosition();
@@ -188,57 +191,57 @@ public class TagListView extends ListView {
return drawable;
}
private BitmapDrawable getDeleteView(View v) {
Bitmap b = getDeleteBitmap(v);
BitmapDrawable drawable = new BitmapDrawable(getResources(), b);
drawable.setBounds(mHoverCellCurrentBounds);
return drawable;
}
private Bitmap getDeleteBitmap(View v) {
Bitmap bitmap = getBitmapFromView(v);
Canvas can = new Canvas(bitmap);
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
Paint paint = new Paint();
paint.setColor(0x8fff0000);
can.drawRect(rect, paint);
return bitmap;
}
private BitmapDrawable getModifyView(View v) {
Bitmap b = getModifyBitmap(v);
BitmapDrawable drawable = new BitmapDrawable(getResources(), b);
drawable.setBounds(mHoverCellCurrentBounds);
return drawable;
}
private Bitmap getModifyBitmap(View v) {
Bitmap bitmap = getBitmapFromView(v);
Canvas can = new Canvas(bitmap);
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
Paint paint = new Paint();
paint.setColor(0x8faa00ff);
can.drawRect(rect, paint);
return bitmap;
}
/** Draws a black border over the screenshot of the view passed in. */
private Bitmap getHoverBitmap(View v) {
Bitmap bitmap = getBitmapFromView(v);
Canvas can = new Canvas(bitmap);
Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
Paint paint = new Paint();
paint.setColor(0x8f00aadd);
can.drawRect(rect, paint);
return bitmap;
}
@@ -287,44 +290,44 @@ public class TagListView extends ListView {
return getPositionForView(v);
}
}
public void setStableItemCount(int stableItemCount) {
mStableItemCount = stableItemCount;
}
public interface OnModifyListener {
public void onModify(int position);
}
public void setOnModifyListener(OnModifyListener listener) {
this.mModifylistener = listener;
}
public interface OnMoveLister {
public void onMoveStart();
public void onMoveOver();
}
public void setOnMoveLister(OnMoveLister listener) {
this.mMovelistener = listener;
}
public interface OnDeleteListener {
public void onDelete(int position);
}
public void setOnDeleteListener(OnDeleteListener listener) {
mOnDeleteListener = listener;
}
public interface OnSwapListener {
public void onSwap(int positionOne, int positionTwo);
}
public void setOnSwapListener(OnSwapListener listener) {
mOnSwapListener = listener;
}
/**
* dispatchDraw gets invoked when all the child views are about to be drawn.
* By overriding this method, the hover cell (BitmapDrawable) can be drawn
@@ -346,6 +349,7 @@ public class TagListView extends ListView {
}
@Override
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent (MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
@@ -359,7 +363,7 @@ public class TagListView extends ListView {
}
int pointerIndex = event.findPointerIndex(mActivePointerId);
mLastEventX = (int) event.getX(pointerIndex);
mLastEventY = (int) event.getY(pointerIndex);
int deltaX = mLastEventX - mDownX;
@@ -370,12 +374,12 @@ public class TagListView extends ListView {
mIsDelete = true;
else
mIsDelete = false;
if (deltaX < -mHoverCellOriginalBounds.width() / SENSITY)
mIsModify = true;
else
mIsModify = false;
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left + deltaX,
mHoverCellOriginalBounds.top + deltaY + mTotalOffset);
//mHoverCell.setBounds(mHoverCellCurrentBounds);
@@ -450,13 +454,13 @@ public class TagListView extends ListView {
updateNeighborViewsForID(mMobileItemId);
return;
}
if (mOnSwapListener != null) {
mOnSwapListener.onSwap(originalItem, getPositionForView(switchView));
}
mDownY = mLastEventY;
final int switchViewStartTop = switchView.getTop();
mobileView.setVisibility(View.VISIBLE);
@@ -466,36 +470,37 @@ public class TagListView extends ListView {
final ViewTreeObserver observer = getViewTreeObserver();
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
observer.removeOnPreDrawListener(this);
View switchView = getViewForID(switchItemID);
mTotalOffset += deltaY;
int switchViewNewTop = switchView.getTop();
int delta = switchViewStartTop - switchViewNewTop;
switchView.setTranslationY(delta);
ObjectAnimator animator = ObjectAnimator.ofFloat(switchView,
View.TRANSLATION_Y, 0);
animator.setDuration(MOVE_DURATION);
animator.start();
return true;
}
});
}
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
private void swapElements(ArrayList arrayList, int indexOne, int indexTwo) {
Object temp = arrayList.get(indexOne);
arrayList.set(indexOne, arrayList.get(indexTwo));
arrayList.set(indexTwo, temp);
}
/**
* Resets all the appropriate fields to a default state while also animating
* the hover cell back to its correct location.
@@ -507,7 +512,7 @@ public class TagListView extends ListView {
mIsWaitingForScrollFinish = false;
mIsMobileScrolling = false;
mActivePointerId = INVALID_POINTER_ID;
if (mIsDelete) {
animateRemoval(mobileView);
mIsDelete = false;
@@ -521,14 +526,14 @@ public class TagListView extends ListView {
invalidate();
return;
}
if (mIsModify) {
mIsModify = false;
if (mModifylistener != null) {
mModifylistener.onModify(getPositionForID(mMobileItemId));
}
}
// If the autoscroller has not completed scrolling, we need to wait for it to
// finish in order to determine the final location of where the hover cell
// should be animated to.
@@ -536,7 +541,7 @@ public class TagListView extends ListView {
mIsWaitingForScrollFinish = true;
return;
}
mHoverCellCurrentBounds.offsetTo(mHoverCellOriginalBounds.left, mobileView.getTop());
ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds",
@@ -571,12 +576,12 @@ public class TagListView extends ListView {
touchEventsCancelled();
}
}
private void animateRemoval(View viewToRemove) {
int firstVisiblePosition = getFirstVisiblePosition();
final TagsAdapter mAdapter = (TagsAdapter)getAdapter();
final HashMap<Long, Integer> mItemIdTopMap = new HashMap<Long, Integer>();
final LongSparseArray<Integer> mItemIdTopMap = new LongSparseArray<Integer>();
for (int i = 0; i < getChildCount(); ++i) {
View child = getChildAt(i);
if (child != viewToRemove) {
@@ -589,9 +594,10 @@ public class TagListView extends ListView {
int position = getPositionForView(viewToRemove);
if (mOnDeleteListener != null)
mOnDeleteListener.onDelete(position);
final ViewTreeObserver observer = getViewTreeObserver();
observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
observer.removeOnPreDrawListener(this);
boolean firstAnimation = true;
@@ -633,7 +639,7 @@ public class TagListView extends ListView {
startTop = top + (i > 0 ? childHeight : -childHeight);
int delta = startTop - top;
child.setTranslationY(delta);
ObjectAnimator animator = ObjectAnimator.ofFloat(child,
View.TRANSLATION_Y, 0);
animator.setDuration(MOVE_DURATION);
@@ -659,8 +665,8 @@ public class TagListView extends ListView {
}
});
}
/**
* Resets all the appropriate fields to a default state.
@@ -690,6 +696,7 @@ public class TagListView extends ListView {
* BitmapDrawable's bounds.
*/
private final static TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {
@Override
public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
return new Rect(interpolate(startValue.left, endValue.left, fraction),
interpolate(startValue.top, endValue.top, fraction),
@@ -735,7 +742,7 @@ public class TagListView extends ListView {
return false;
}
/**
* This scroll listener is added to the listview in order to handle cell swapping
* when the cell is either at the top or bottom edge of the listview. If the hover
@@ -743,7 +750,7 @@ public class TagListView extends ListView {
* scrolling takes place, the listview continuously checks if new cells became visible
* and determines whether they are potential candidates for a cell swap.
*/
private AbsListView.OnScrollListener mScrollListener = new AbsListView.OnScrollListener () {
private final AbsListView.OnScrollListener mScrollListener = new AbsListView.OnScrollListener () {
private int mPreviousFirstVisibleItem = -1;
private int mPreviousVisibleItemCount = -1;
@@ -751,6 +758,7 @@ public class TagListView extends ListView {
private int mCurrentVisibleItemCount;
private int mCurrentScrollState;
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
int totalItemCount) {
mCurrentFirstVisibleItem = firstVisibleItem;