Update
This commit is contained in:
1 parent
a0d5cb9937
commit
9b7ebdff61
16 files changed
+668
-61
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.Button;
|
||||
@@ -67,12 +68,12 @@ public class CardButton extends Button implements CardViewDelegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCardBackgroundColor(int color) {
|
||||
public void setCardBackgroundColor(ColorStateList color) {
|
||||
mCardHelper.setCardBackgroundColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardBackgroundColor() {
|
||||
public ColorStateList getCardBackgroundColor() {
|
||||
return mCardHelper.getCardBackgroundColor();
|
||||
}
|
||||
|
||||
@@ -87,12 +88,12 @@ public class CardButton extends Button implements CardViewDelegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCardBoundColor(int color) {
|
||||
public void setCardBoundColor(ColorStateList color) {
|
||||
mCardHelper.setCardBoundColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardBoundColor() {
|
||||
public ColorStateList getCardBoundColor() {
|
||||
return mCardHelper.getCardBoundColor();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.hippo.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
@@ -67,12 +68,12 @@ public class CardLinearLayout extends LinearLayout implements CardViewDelegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCardBackgroundColor(int color) {
|
||||
public void setCardBackgroundColor(ColorStateList color) {
|
||||
mCardHelper.setCardBackgroundColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardBackgroundColor() {
|
||||
public ColorStateList getCardBackgroundColor() {
|
||||
return mCardHelper.getCardBackgroundColor();
|
||||
}
|
||||
|
||||
@@ -87,12 +88,12 @@ public class CardLinearLayout extends LinearLayout implements CardViewDelegate {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCardBoundColor(int color) {
|
||||
public void setCardBoundColor(ColorStateList color) {
|
||||
mCardHelper.setCardBoundColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardBoundColor() {
|
||||
public ColorStateList getCardBoundColor() {
|
||||
return mCardHelper.getCardBoundColor();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,11 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
*/
|
||||
public static final int CHOICE_MODE_MULTIPLE_MODAL = 3;
|
||||
|
||||
/**
|
||||
* The list allows multiple choices in custom action
|
||||
*/
|
||||
public static final int CHOICE_MODE_MULTIPLE_CUSTOM = 4;
|
||||
|
||||
/**
|
||||
* Controls if/how the user may choose/check items in the list
|
||||
*/
|
||||
@@ -94,6 +99,17 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
*/
|
||||
MultiChoiceModeWrapper mMultiChoiceModeCallback;
|
||||
|
||||
/**
|
||||
* Listener for custom multiple choices
|
||||
*/
|
||||
private CustomChoiceListener mCustomChoiceListener;
|
||||
|
||||
private boolean mCustomChoice = false;
|
||||
|
||||
private SparseBooleanArray mTempCheckStates;
|
||||
|
||||
private FixCheckedHelper mFixCheckedHelper;
|
||||
|
||||
/**
|
||||
* Running count of how many items are currently checked
|
||||
*/
|
||||
@@ -491,6 +507,38 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
return ids;
|
||||
}
|
||||
|
||||
public boolean inCustomChoice() {
|
||||
return mCustomChoice;
|
||||
}
|
||||
|
||||
public void intoCustomChoiceMode() {
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE_CUSTOM && !mCustomChoice) {
|
||||
mCustomChoice = true;
|
||||
|
||||
mCustomChoiceListener.onIntoCustomChoice(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void outOfCustomChoiceMode() {
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE_CUSTOM && mCustomChoice) {
|
||||
|
||||
// Copy mCheckStates
|
||||
mTempCheckStates.clear();
|
||||
for (int i = 0, n = mCheckStates.size(); i < n; i++) {
|
||||
mTempCheckStates.put(mCheckStates.keyAt(i), mCheckStates.valueAt(i));
|
||||
}
|
||||
// Uncheck remain checked items
|
||||
for (int i = 0, n = mTempCheckStates.size(); i < n; i++) {
|
||||
if (mTempCheckStates.valueAt(i)) {
|
||||
setItemChecked(mTempCheckStates.keyAt(i), false);
|
||||
}
|
||||
}
|
||||
|
||||
mCustomChoice = false;
|
||||
mCustomChoiceListener.onOutOfCustomChoice(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear any choices previously set
|
||||
*/
|
||||
@@ -505,6 +553,12 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
updateOnScreenCheckedViews();
|
||||
}
|
||||
|
||||
public void toggleItemChecked(int position) {
|
||||
if (mCheckStates != null) {
|
||||
setItemChecked(position, !mCheckStates.get(position));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the checked state of the specified position. The is only valid if
|
||||
* the choice mode has been set to {@link #CHOICE_MODE_SINGLE} or
|
||||
@@ -518,6 +572,11 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check is intoCheckMode
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE_CUSTOM && !mCustomChoice) {
|
||||
throw new IllegalStateException("Call intoCheckMode first");
|
||||
}
|
||||
|
||||
// Start selection mode if needed. We don't need to if we're unchecking something.
|
||||
if (value && mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode == null) {
|
||||
if (mMultiChoiceModeCallback == null ||
|
||||
@@ -529,7 +588,7 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
mChoiceActionMode = startActionMode(mMultiChoiceModeCallback);
|
||||
}
|
||||
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE || mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE || mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL || mChoiceMode == CHOICE_MODE_MULTIPLE_CUSTOM) {
|
||||
boolean oldValue = mCheckStates.get(position);
|
||||
mCheckStates.put(position, value);
|
||||
if (mCheckedIdStates != null && mAdapter.hasStableIds()) {
|
||||
@@ -551,6 +610,10 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
mMultiChoiceModeCallback.onItemCheckedStateChanged(mChoiceActionMode,
|
||||
position, id, value);
|
||||
}
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE_CUSTOM) {
|
||||
final long id = mAdapter.getItemId(position);
|
||||
mCustomChoiceListener.onItemCheckedStateChanged(this, position, id, value);
|
||||
}
|
||||
} else {
|
||||
boolean updateIds = mCheckedIdStates != null && mAdapter.hasStableIds();
|
||||
// Clear all values if we're checking something, or unchecking the currently
|
||||
@@ -608,10 +671,19 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
if (mCheckedIdStates == null && mAdapter != null && mAdapter.hasStableIds()) {
|
||||
mCheckedIdStates = new LongSparseArray<>(0);
|
||||
}
|
||||
if (mFixCheckedHelper == null) {
|
||||
mFixCheckedHelper = new FixCheckedHelper();
|
||||
addOnChildAttachStateChangeListener(mFixCheckedHelper);
|
||||
}
|
||||
// Modal multi-choice mode only has choices when the mode is active. Clear them.
|
||||
if (mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL) {
|
||||
clearChoices();
|
||||
setLongClickable(true);
|
||||
} else if (mChoiceMode == CHOICE_MODE_MULTIPLE_CUSTOM) {
|
||||
if (mTempCheckStates == null) {
|
||||
mTempCheckStates = new SparseBooleanArray(0);
|
||||
}
|
||||
clearChoices();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -632,6 +704,14 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
mMultiChoiceModeCallback.setWrapped(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
public void setCustomCheckedListener(CustomChoiceListener listener) {
|
||||
mCustomChoiceListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a quick, in-place update of the checked or activated state
|
||||
* on all visible item views. This should only be called when a valid
|
||||
@@ -850,7 +930,7 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
boolean handled = false;
|
||||
boolean dispatchItemClick = true;
|
||||
|
||||
if (mChoiceMode != CHOICE_MODE_NONE) {
|
||||
if (mChoiceMode != CHOICE_MODE_NONE && mChoiceMode != CHOICE_MODE_MULTIPLE_CUSTOM) {
|
||||
handled = true;
|
||||
boolean checkedStateChanged = false;
|
||||
|
||||
@@ -952,13 +1032,6 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
mOnItemLongClickListener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* If choice mode is set, call it in {@link Adapter#onBindViewHolder}
|
||||
*/
|
||||
public void checkItemCheckedState(View view, int position) {
|
||||
setViewChecked(view, isItemChecked(position));
|
||||
}
|
||||
|
||||
/**
|
||||
* This saved state class is a Parcelable and should not extend
|
||||
* {@link android.view.View.BaseSavedState} nor {@link android.view.AbsSavedState}
|
||||
@@ -1274,6 +1347,22 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
boolean beforeDrawSelector(int position);
|
||||
}
|
||||
|
||||
public class FixCheckedHelper implements OnChildAttachStateChangeListener {
|
||||
|
||||
@Override
|
||||
public void onChildViewAttachedToWindow(View view) {
|
||||
int position = getChildAdapterPosition(view);
|
||||
if (position >= 0) {
|
||||
setViewChecked(view, mCheckStates.get(position));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChildViewDetachedFromWindow(View view) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -1349,4 +1438,16 @@ public class EasyRecyclerView extends RecyclerView {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom checked
|
||||
*/
|
||||
public interface CustomChoiceListener {
|
||||
|
||||
void onIntoCustomChoice(EasyRecyclerView view);
|
||||
|
||||
void onOutOfCustomChoice(EasyRecyclerView view);
|
||||
|
||||
void onItemCheckedStateChanged(EasyRecyclerView view, int position, long id, boolean checked);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user