Add Preference
This commit is contained in:
1 parent
c1af94afa0
commit
aa61dada92
44 files changed
+1447
-77
No files matched your search
@@ -0,0 +1,77 @@
|
||||
package com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.hippo.ehviewer.R;
|
||||
|
||||
public class IndicatingListView extends ListView {
|
||||
|
||||
private int mIndicatorHeight;
|
||||
|
||||
private Paint mPaint = new Paint();
|
||||
private Rect mTemp = new Rect();
|
||||
|
||||
public IndicatingListView(Context context) {
|
||||
super(context);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public IndicatingListView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init(context);
|
||||
}
|
||||
|
||||
public IndicatingListView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(context);
|
||||
}
|
||||
|
||||
private void init(Context context) {
|
||||
mIndicatorHeight = context.getResources().getDimensionPixelOffset(R.dimen.scroll_view_indicator_height);
|
||||
mPaint.setColor(context.getResources().getColor(R.color.scroll_view_indicator));
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
}
|
||||
|
||||
private void fillTopIndicatorDrawRect() {
|
||||
mTemp.set(0, 0, getWidth(), mIndicatorHeight);
|
||||
}
|
||||
|
||||
private void fillBottomIndicatorDrawRect() {
|
||||
mTemp.set(0, getHeight() - mIndicatorHeight, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
private boolean needShowTopIndicator() {
|
||||
return canScrollVertically(-1);
|
||||
}
|
||||
|
||||
private boolean needShowBottomIndicator() {
|
||||
return canScrollVertically(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(@NonNull Canvas canvas) {
|
||||
super.draw(canvas);
|
||||
|
||||
final int restoreCount = canvas.save();
|
||||
canvas.translate(getScrollX(), getScrollY());
|
||||
|
||||
// Draw top indicator
|
||||
if (needShowTopIndicator()) {
|
||||
fillTopIndicatorDrawRect();
|
||||
canvas.drawRect(mTemp, mPaint);
|
||||
}
|
||||
// Draw bottom indicator
|
||||
if (needShowBottomIndicator()) {
|
||||
fillBottomIndicatorDrawRect();
|
||||
canvas.drawRect(mTemp, mPaint);
|
||||
}
|
||||
|
||||
canvas.restoreToCount(restoreCount);
|
||||
}
|
||||
}
|
||||
@@ -51,6 +51,7 @@ public class SimpleImageView extends View implements Drawable.Callback {
|
||||
setWillNotCacheDrawing(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setDrawable(@DrawableRes int resId) {
|
||||
setDrawable(getContext().getResources().getDrawable(resId));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
* 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 com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
public class SolidLinearLayout extends LinearLayout {
|
||||
|
||||
public SolidLinearLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public SolidLinearLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public SolidLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -166,6 +166,7 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
*/
|
||||
int mSelectionBottomPadding = 0;
|
||||
|
||||
private OnDrawSelectorListener mOnDrawSelectorListener;
|
||||
|
||||
public EasyRecyclerView(Context context) {
|
||||
super(context);
|
||||
@@ -278,14 +279,20 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
mGroupFlags &= ~CLIP_TO_PADDING_MASK;
|
||||
}
|
||||
|
||||
// TODO disable selector drawable state change when need not to draw selector
|
||||
boolean drawSelector = mOnDrawSelectorListener == null ||
|
||||
mSelectorPosition < 0 ||
|
||||
mSelectorPosition >= mAdapter.getItemCount() ||
|
||||
mOnDrawSelectorListener.beforeDrawSelector(mSelectorPosition);
|
||||
final boolean drawSelectorOnTop = mDrawSelectorOnTop;
|
||||
if (!drawSelectorOnTop) {
|
||||
|
||||
if (drawSelector && !drawSelectorOnTop) {
|
||||
drawSelector(canvas);
|
||||
}
|
||||
|
||||
super.dispatchDraw(canvas);
|
||||
|
||||
if (drawSelectorOnTop) {
|
||||
if (drawSelector && drawSelectorOnTop) {
|
||||
drawSelector(canvas);
|
||||
}
|
||||
|
||||
@@ -314,6 +321,10 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnDrawSelectorListener(OnDrawSelectorListener listener) {
|
||||
mOnDrawSelectorListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether the selection highlight drawable should be drawn on top of the item or
|
||||
* behind it.
|
||||
@@ -351,6 +362,14 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
return mSelector;
|
||||
}
|
||||
|
||||
private void cancelDrawingSelector() {
|
||||
Rect rect = mSelectorRect;
|
||||
rect.left = 0;
|
||||
rect.top = 0;
|
||||
rect.right = 0;
|
||||
rect.bottom = 0;
|
||||
}
|
||||
|
||||
void updateSelectorState() {
|
||||
if (mSelector != null) {
|
||||
if (shouldShowSelector()) {
|
||||
@@ -656,6 +675,14 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
}
|
||||
}
|
||||
|
||||
public float getTouchStartX() {
|
||||
return mStartX;
|
||||
}
|
||||
|
||||
public float getTouchStartY() {
|
||||
return mStartY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent ev) {
|
||||
if (!isEnabled()) {
|
||||
@@ -733,6 +760,7 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
setPressed(false);
|
||||
}
|
||||
updateSelectorState();
|
||||
cancelDrawingSelector();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1215,6 +1243,19 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
boolean onItemLongClick(EasyRecyclerView parent, View view, int position, long id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when draw selector.
|
||||
*/
|
||||
public interface OnDrawSelectorListener {
|
||||
/**
|
||||
* Callback method to be invoked before selector draw.
|
||||
*
|
||||
* @param position The EasyRecyclerView where the click happened
|
||||
* @return true if need draw selector, false otherwise
|
||||
*/
|
||||
boolean beforeDrawSelector(int position);
|
||||
}
|
||||
|
||||
/**
|
||||
* A MultiChoiceModeListener receives events for {@link android.widget.AbsListView#CHOICE_MODE_MULTIPLE_MODAL}.
|
||||
* It acts as the {@link android.support.v7.view.ActionMode.Callback} for the selection mode and also receives
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Hippo Seven
|
||||
*
|
||||
* 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
|
||||
* 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 com.hippo.widget.recyclerview;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
public class SimpleHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
public SimpleHolder(View itemView) {
|
||||
super(itemView);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user