Improve ChekTextView
This commit is contained in:
1 parent
9495b026b6
commit
d3bfd987b0
3 files changed
+98
-32
No files matched your search
@@ -15,9 +15,7 @@
|
||||
|
||||
package com.hippo.ehviewer.ui.fragment;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -37,7 +35,6 @@ import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.data.GalleryListUrlBuilder;
|
||||
import com.hippo.ehviewer.widget.AdvanceSearchTable;
|
||||
import com.hippo.ehviewer.widget.CategoryTable;
|
||||
import com.hippo.util.Log;
|
||||
import com.hippo.util.UiUtils;
|
||||
import com.hippo.util.ViewUtils;
|
||||
import com.hippo.widget.PrefixEditText;
|
||||
@@ -79,19 +76,20 @@ public class SearchFragment extends Fragment implements CompoundButton.OnChecked
|
||||
private LinearLayoutManager mLayoutManager;
|
||||
private SearchAdapter mAdapter;
|
||||
|
||||
SparseArray<Parcelable> mSavedStates;
|
||||
|
||||
public void setOnSearchListener(OnSearchListener listener) {
|
||||
mOnSearchListener = listener;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
public void onViewStateRestored(Bundle savedInstanceState) {
|
||||
super.onViewStateRestored(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null && mRootView != null) {
|
||||
SparseArray<Parcelable> savedStates = savedInstanceState.getSparseParcelableArray(VIEW_STATE_TAG);
|
||||
if (savedStates != null) {
|
||||
mRootView.restoreHierarchyState(savedStates);
|
||||
mSavedStates = savedInstanceState.getSparseParcelableArray(VIEW_STATE_TAG);
|
||||
if (mSavedStates != null) {
|
||||
mRootView.restoreHierarchyState(mSavedStates);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,6 +116,7 @@ public class SearchFragment extends Fragment implements CompoundButton.OnChecked
|
||||
super.onDestroyView();
|
||||
|
||||
mRootView = null;
|
||||
mSavedStates = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -181,9 +180,6 @@ public class SearchFragment extends Fragment implements CompoundButton.OnChecked
|
||||
|
||||
@Override
|
||||
public SearchHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
Log.d("TAG", "sdsd", new Exception("onCreateViewHolder"));
|
||||
|
||||
View view = mInflater.inflate(R.layout.search_category, parent, false);
|
||||
|
||||
ViewCompat.setElevation(view, UiUtils.dp2pix(4)); // TODO
|
||||
@@ -209,6 +205,10 @@ public class SearchFragment extends Fragment implements CompoundButton.OnChecked
|
||||
}
|
||||
}
|
||||
|
||||
if (mSavedStates != null) {
|
||||
holder.itemView.restoreHierarchyState(mSavedStates);
|
||||
}
|
||||
|
||||
return holder;
|
||||
}
|
||||
|
||||
|
||||
@@ -71,16 +71,16 @@ public class CategoryTable extends TableLayout {
|
||||
* @param category
|
||||
*/
|
||||
public void setCategory(int category) {
|
||||
mDoujinshi.setChecked(!Utils.int2boolean(category & EhUtils.DOUJINSHI));
|
||||
mManga.setChecked(!Utils.int2boolean(category & EhUtils.MANGA));
|
||||
mArtistCG.setChecked(!Utils.int2boolean(category & EhUtils.ARTIST_CG));
|
||||
mGameCG.setChecked(!Utils.int2boolean(category & EhUtils.GAME_CG));
|
||||
mWestern.setChecked(!Utils.int2boolean(category & EhUtils.WESTERN));
|
||||
mNonH.setChecked(!Utils.int2boolean(category & EhUtils.NON_H));
|
||||
mImageSets.setChecked(!Utils.int2boolean(category & EhUtils.IMAGE_SET));
|
||||
mCosplay.setChecked(!Utils.int2boolean(category & EhUtils.COSPLAY));
|
||||
mAsianPorn.setChecked(!Utils.int2boolean(category & EhUtils.ASIAN_PORN));
|
||||
mMisc.setChecked(!Utils.int2boolean(category & EhUtils.MISC));
|
||||
mDoujinshi.setChecked(!Utils.int2boolean(category & EhUtils.DOUJINSHI), false);
|
||||
mManga.setChecked(!Utils.int2boolean(category & EhUtils.MANGA), false);
|
||||
mArtistCG.setChecked(!Utils.int2boolean(category & EhUtils.ARTIST_CG), false);
|
||||
mGameCG.setChecked(!Utils.int2boolean(category & EhUtils.GAME_CG), false);
|
||||
mWestern.setChecked(!Utils.int2boolean(category & EhUtils.WESTERN), false);
|
||||
mNonH.setChecked(!Utils.int2boolean(category & EhUtils.NON_H), false);
|
||||
mImageSets.setChecked(!Utils.int2boolean(category & EhUtils.IMAGE_SET), false);
|
||||
mCosplay.setChecked(!Utils.int2boolean(category & EhUtils.COSPLAY), false);
|
||||
mAsianPorn.setChecked(!Utils.int2boolean(category & EhUtils.ASIAN_PORN), false);
|
||||
mMisc.setChecked(!Utils.int2boolean(category & EhUtils.MISC), false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.view.View.OnClickListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hippo.util.MathUtils;
|
||||
import com.nineoldandroids.animation.Animator;
|
||||
import com.nineoldandroids.animation.ObjectAnimator;
|
||||
|
||||
public class CheckTextView extends TextView implements OnClickListener, Hotspotable {
|
||||
@@ -37,6 +38,7 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
|
||||
private static final long ANIMATION_DURATION = 150;
|
||||
|
||||
private boolean mChecked = false;
|
||||
private boolean mAimating = false;
|
||||
|
||||
private float mX;
|
||||
private float mY;
|
||||
@@ -45,6 +47,8 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
|
||||
|
||||
private Paint mPaint;
|
||||
|
||||
private Animator mCurrentAnimator;
|
||||
|
||||
public CheckTextView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
@@ -84,10 +88,32 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
|
||||
return mRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mChecked = !mChecked;
|
||||
private Animator.AnimatorListener mAnimatorListener = new Animator.AnimatorListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mAimating = true;
|
||||
mCurrentAnimator = animation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAimating = false;
|
||||
mCurrentAnimator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
mAimating = false;
|
||||
mCurrentAnimator = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
// Empty
|
||||
}
|
||||
};
|
||||
|
||||
private void startAnimator() {
|
||||
ObjectAnimator radiusAnim;
|
||||
if (mChecked) {
|
||||
radiusAnim = ObjectAnimator.ofFloat(this, "radius",
|
||||
@@ -98,24 +124,64 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
|
||||
}
|
||||
radiusAnim.setAutoCancel(true);
|
||||
radiusAnim.setDuration(ANIMATION_DURATION); // TODO decide duration according to mMaxRadius
|
||||
radiusAnim.addListener(mAnimatorListener);
|
||||
radiusAnim.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
mChecked = !mChecked;
|
||||
startAnimator();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
float radius = mRadius;
|
||||
if (radius > 0f) {
|
||||
canvas.drawCircle(mX, mY, radius, mPaint);
|
||||
if (mAimating) {
|
||||
float radius = mRadius;
|
||||
if (radius > 0f) {
|
||||
canvas.drawCircle(mX, mY, radius, mPaint);
|
||||
}
|
||||
} else {
|
||||
if (mChecked) {
|
||||
canvas.drawColor(MASK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setChecked(boolean checked) {
|
||||
mChecked = checked;
|
||||
invalidate();
|
||||
/**
|
||||
* Changes the checked state of this CheckTextView.
|
||||
*
|
||||
* @param checked checked true to check the CheckTextView, false to uncheck it
|
||||
* @param animation true for show animation
|
||||
*/
|
||||
public void setChecked(boolean checked, boolean animation) {
|
||||
if (mChecked != checked) {
|
||||
mChecked = checked;
|
||||
|
||||
if (animation) {
|
||||
int w = getWidth();
|
||||
int h = getHeight();
|
||||
mX = w / 2;
|
||||
mY = h / 2;
|
||||
mMaxRadius = (float) Math.hypot(mX, mY);
|
||||
|
||||
startAnimator();
|
||||
} else {
|
||||
if (mCurrentAnimator != null) {
|
||||
mCurrentAnimator.cancel();
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the checked state of it.
|
||||
*
|
||||
* @return true is it is checked
|
||||
*/
|
||||
public boolean isChecked() {
|
||||
return mChecked;
|
||||
}
|
||||
@@ -133,7 +199,7 @@ public class CheckTextView extends TextView implements OnClickListener, Hotspota
|
||||
if (state instanceof Bundle) {
|
||||
final Bundle savedState = (Bundle) state;
|
||||
super.onRestoreInstanceState(savedState.getParcelable(STATE_KEY_SUPER));
|
||||
mChecked = savedState.getBoolean(STATE_KEY_CHECKED);
|
||||
setChecked(savedState.getBoolean(STATE_KEY_CHECKED), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user