From ef154867a68be8779c1291afd484ffb3f04fd580 Mon Sep 17 00:00:00 2001 From: seven332 Date: Tue, 29 Jul 2014 09:24:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BF=AB=E9=80=9F=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- res/layout/list_menu_right.xml | 40 +++-- res/values-zh-rCN/strings.xml | 7 +- res/values/strings.xml | 7 +- .../ehviewer/ui/GalleryListActivity.java | 29 ++-- .../hippo/ehviewer/widget/TagListView.java | 138 +++++++++--------- 5 files changed, 125 insertions(+), 96 deletions(-) diff --git a/res/layout/list_menu_right.xml b/res/layout/list_menu_right.xml index 240dd369b..9d38d164f 100644 --- a/res/layout/list_menu_right.xml +++ b/res/layout/list_menu_right.xml @@ -1,5 +1,6 @@ - - + \ No newline at end of file + android:layout_height="match_parent" > + + + + + + \ No newline at end of file diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml index 9c8d27266..ef29c1be0 100644 --- a/res/values-zh-rCN/strings.xml +++ b/res/values-zh-rCN/strings.xml @@ -82,10 +82,11 @@ 已添加到收藏 已添加到下载列表 - + 未找到 无 %s 第 %d 页 + 您可以再左侧栏搜索项中添加快速搜索 发现新版本:%s\n大小:%s\n%s\n\n是否更新? @@ -97,7 +98,7 @@ 正在下载更新 下载更新失败 - + 页数 : %s (%s) 语言 : %s 平均得分:%s @@ -115,7 +116,7 @@ 踩 相同标签 - + 载入上一页 已是第一页 开始继续载入 diff --git a/res/values/strings.xml b/res/values/strings.xml index 51f9b31fd..a77a1c8db 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -84,10 +84,11 @@ Add to favourite Add to download list - + No hits found None %s Page %d + Quick search can be added via search in left drawer Found new version : %s\nSize : %s\n%s\n\nUpdate ? @@ -99,7 +100,7 @@ Downloading the update Download the update Failed - + Pages : %s (%s) Language : %s Content Warning @@ -115,7 +116,7 @@ Vote down Show tagged - + Load previous page First page ! Start reloading diff --git a/src/com/hippo/ehviewer/ui/GalleryListActivity.java b/src/com/hippo/ehviewer/ui/GalleryListActivity.java index 85959bcd2..81754e330 100644 --- a/src/com/hippo/ehviewer/ui/GalleryListActivity.java +++ b/src/com/hippo/ehviewer/ui/GalleryListActivity.java @@ -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(); diff --git a/src/com/hippo/ehviewer/widget/TagListView.java b/src/com/hippo/ehviewer/widget/TagListView.java index 93dcf9b9c..c554da502 100644 --- a/src/com/hippo/ehviewer/widget/TagListView.java +++ b/src/com/hippo/ehviewer/widget/TagListView.java @@ -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 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 mItemIdTopMap = new HashMap(); - + final LongSparseArray mItemIdTopMap = new LongSparseArray(); + 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 sBoundEvaluator = new TypeEvaluator() { + @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;