null
.
534 | */
535 | public void setColors(int[] colors) {
536 | mColors = colors;
537 | // if colors are reset, make sure to reset the color index as well
538 | setColorIndex(0);
539 | }
540 |
541 | /**
542 | * @param index Index into the color array of the color to display in
543 | * the progress spinner.
544 | */
545 | public void setColorIndex(int index) {
546 | mColorIndex = index;
547 | }
548 |
549 | /**
550 | * Proceed to the next available ring color. This will automatically
551 | * wrap back to the beginning of colors.
552 | */
553 | public void goToNextColor() {
554 | mColorIndex = (mColorIndex + 1) % (mColors.length);
555 | }
556 |
557 | public void setColorFilter(ColorFilter filter) {
558 | mArcPaint.setColorFilter(filter);
559 | invalidateSelf();
560 | }
561 |
562 | /**
563 | * @return Current alpha of the progress spinner and arrowhead.
564 | */
565 | public int getAlpha() {
566 | return mAlpha;
567 | }
568 |
569 | /**
570 | * @param alpha Set the alpha of the progress spinner and associated arrowhead.
571 | */
572 | public void setAlpha(int alpha) {
573 | mAlpha = alpha;
574 | }
575 |
576 | @SuppressWarnings("unused")
577 | public float getStrokeWidth() {
578 | return mStrokeWidth;
579 | }
580 |
581 | /**
582 | * @param strokeWidth Set the stroke width of the progress spinner in pixels.
583 | */
584 | public void setStrokeWidth(float strokeWidth) {
585 | mStrokeWidth = strokeWidth;
586 | mArcPaint.setStrokeWidth(strokeWidth);
587 | invalidateSelf();
588 | }
589 |
590 | @SuppressWarnings("unused")
591 | public float getStartTrim() {
592 | return mStartTrim;
593 | }
594 |
595 | @SuppressWarnings("unused")
596 | public void setStartTrim(float startTrim) {
597 | mStartTrim = startTrim;
598 | invalidateSelf();
599 | }
600 |
601 | public float getStartingStartTrim() {
602 | return mStartingStartTrim;
603 | }
604 |
605 | public float getStartingEndTrim() {
606 | return mStartingEndTrim;
607 | }
608 |
609 | @SuppressWarnings("unused")
610 | public float getEndTrim() {
611 | return mEndTrim;
612 | }
613 |
614 | @SuppressWarnings("unused")
615 | public void setEndTrim(float endTrim) {
616 | mEndTrim = endTrim;
617 | invalidateSelf();
618 | }
619 |
620 | @SuppressWarnings("unused")
621 | public float getRotation() {
622 | return mRotation;
623 | }
624 |
625 | @SuppressWarnings("unused")
626 | public void setRotation(float rotation) {
627 | mRotation = rotation;
628 | invalidateSelf();
629 | }
630 |
631 | public void setInsets(int width, int height) {
632 | final float minEdge = (float) Math.min(width, height);
633 | float insets;
634 | if (mRingCenterRadius <= 0 || minEdge < 0) {
635 | insets = (float) Math.ceil(mStrokeWidth / 2.0f);
636 | } else {
637 | insets = (float) (minEdge / 2.0f - mRingCenterRadius);
638 | }
639 | mStrokeInset = insets;
640 | }
641 |
642 | @SuppressWarnings("unused")
643 | public float getInsets() {
644 | return mStrokeInset;
645 | }
646 |
647 | public double getCenterRadius() {
648 | return mRingCenterRadius;
649 | }
650 |
651 | /**
652 | * @param centerRadius Inner radius in px of the circle the progress
653 | * spinner arc traces.
654 | */
655 | public void setCenterRadius(double centerRadius) {
656 | mRingCenterRadius = centerRadius;
657 | }
658 |
659 | /**
660 | * @param show Set to true to show the arrow head on the progress spinner.
661 | */
662 | public void setShowArrow(boolean show) {
663 | if (mShowArrow != show) {
664 | mShowArrow = show;
665 | invalidateSelf();
666 | }
667 | }
668 |
669 | /**
670 | * @param scale Set the scale of the arrowhead for the spinner.
671 | */
672 | public void setArrowScale(float scale) {
673 | if (scale != mArrowScale) {
674 | mArrowScale = scale;
675 | invalidateSelf();
676 | }
677 | }
678 |
679 | /**
680 | * @return The amount the progress spinner is currently rotated, between [0..1].
681 | */
682 | public float getStartingRotation() {
683 | return mStartingRotation;
684 | }
685 |
686 | /**
687 | * If the start / end trim are offset to begin with, store them so that
688 | * animation starts from that offset.
689 | */
690 | public void storeOriginals() {
691 | mStartingStartTrim = mStartTrim;
692 | mStartingEndTrim = mEndTrim;
693 | mStartingRotation = mRotation;
694 | }
695 |
696 | /**
697 | * Reset the progress spinner to default rotation, start and end angles.
698 | */
699 | public void resetOriginals() {
700 | mStartingStartTrim = 0;
701 | mStartingEndTrim = 0;
702 | mStartingRotation = 0;
703 | setStartTrim(0);
704 | setEndTrim(0);
705 | setRotation(0);
706 | }
707 |
708 | private void invalidateSelf() {
709 | mRingCallback.invalidateDrawable(null);
710 | }
711 | }
712 |
713 | /**
714 | * Squishes the interpolation curve into the second half of the animation.
715 | */
716 | private static class EndCurveInterpolator extends AccelerateDecelerateInterpolator {
717 | @Override
718 | public float getInterpolation(float input) {
719 | return super.getInterpolation(Math.max(0, (input - 0.5f) * 2.0f));
720 | }
721 | }
722 |
723 | /**
724 | * Squishes the interpolation curve into the first half of the animation.
725 | */
726 | private static class StartCurveInterpolator extends AccelerateDecelerateInterpolator {
727 | @Override
728 | public float getInterpolation(float input) {
729 | return super.getInterpolation(Math.min(1, input * 2.0f));
730 | }
731 | }
732 |
733 | /**
734 | * Taken from {@link package android.support.v4.widget}
735 | */
736 | private class OvalShadow extends OvalShape {
737 | private RadialGradient mRadialGradient;
738 | private int mShadowRadius;
739 | private Paint mShadowPaint;
740 | private int mCircleDiameter;
741 |
742 | public OvalShadow(int shadowRadius, int circleDiameter) {
743 | super();
744 | mShadowPaint = new Paint();
745 | mShadowRadius = shadowRadius;
746 | mCircleDiameter = circleDiameter;
747 | mRadialGradient = new RadialGradient(mCircleDiameter / 2, mCircleDiameter / 2,
748 | mShadowRadius, new int[]{
749 | FILL_SHADOW_COLOR, Color.TRANSPARENT
750 | }, null, Shader.TileMode.CLAMP);
751 | mShadowPaint.setShader(mRadialGradient);
752 | }
753 |
754 | @Override
755 | public void draw(Canvas canvas, Paint paint) {
756 | final int viewWidth = getBounds().width();
757 | final int viewHeight = getBounds().height();
758 | canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2 + mShadowRadius),
759 | mShadowPaint);
760 | canvas.drawCircle(viewWidth / 2, viewHeight / 2, (mCircleDiameter / 2), paint);
761 | }
762 | }
763 | }
764 |
--------------------------------------------------------------------------------
/app/src/main/java/com/android/weexlist/widgets/WeexPtrDefaultHandler.java:
--------------------------------------------------------------------------------
1 | package com.android.weexlist.widgets;
2 |
3 | import android.support.v4.view.ViewCompat;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.AbsListView;
7 | import android.widget.FrameLayout;
8 |
9 | import com.taobao.weex.RenderContainer;
10 | import com.taobao.weex.ui.view.WXFrameLayout;
11 | import com.taobao.weex.ui.view.refresh.wrapper.BounceRecyclerView;
12 |
13 | import in.srain.cube.views.ptr.PtrDefaultHandler;
14 |
15 | /**
16 | * Created by liuzhao on 17/3/23.
17 | */
18 |
19 | public abstract class WeexPtrDefaultHandler extends PtrDefaultHandler {
20 | public static boolean canChildScrollUp(View view) {
21 | View realView = view;
22 | if (view instanceof ViewGroup) {
23 | FrameLayout frameLayout = (FrameLayout) view;
24 | RenderContainer renderContainer = (RenderContainer) frameLayout.getChildAt(0);
25 | realView = ((BounceRecyclerView) ((WXFrameLayout) renderContainer.getChildAt(0)).getChildAt(0)).getInnerView();
26 | }
27 | if (android.os.Build.VERSION.SDK_INT < 14) {
28 | if (realView instanceof AbsListView) {
29 | final AbsListView absListView = (AbsListView) realView;
30 | return absListView.getChildCount() > 0
31 | && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
32 | .getTop() < absListView.getPaddingTop());
33 | } else {
34 | return realView.getScrollY() > 0;
35 | }
36 | } else {
37 | return ViewCompat.canScrollVertically(realView, -1);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |