|
@@ -24,19 +24,29 @@ import java.util.List;
|
|
|
*/
|
|
*/
|
|
|
@SuppressLint("NewApi")
|
|
@SuppressLint("NewApi")
|
|
|
public class FunnelView extends View implements ValueAnimator.AnimatorUpdateListener {
|
|
public class FunnelView extends View implements ValueAnimator.AnimatorUpdateListener {
|
|
|
|
|
+
|
|
|
public static final float ANGLE_SCALE = 2.0f;
|
|
public static final float ANGLE_SCALE = 2.0f;
|
|
|
- private List<Integer> mMoneys = new ArrayList<>();
|
|
|
|
|
private int maxMoney;
|
|
private int maxMoney;
|
|
|
private float phaseX = 1f;
|
|
private float phaseX = 1f;
|
|
|
private int textAlpha = 255;
|
|
private int textAlpha = 255;
|
|
|
- private ArrayList<Paint> mPaints = new ArrayList<>();
|
|
|
|
|
- private ArrayList<String> colors = new ArrayList<>();
|
|
|
|
|
|
|
+ private float mLastX;
|
|
|
|
|
+ private float mLastY;
|
|
|
|
|
+ private float mLastWidth;
|
|
|
|
|
+ private int maxHight;
|
|
|
|
|
+
|
|
|
private Paint mPaintLine;
|
|
private Paint mPaintLine;
|
|
|
private Paint mPaintText;
|
|
private Paint mPaintText;
|
|
|
- private float mTotalHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics());
|
|
|
|
|
|
|
+ private ObjectAnimator xAnimator;
|
|
|
|
|
+ private ObjectAnimator alphaAnimator;
|
|
|
|
|
+ private List<Integer> mMoneys = new ArrayList<>();
|
|
|
|
|
+ private ArrayList<Paint> mPaints = new ArrayList<>();
|
|
|
|
|
+ private ArrayList<String> colors = new ArrayList<>();
|
|
|
|
|
+
|
|
|
private ArrayList<Float> mPathHeights = new ArrayList<>();
|
|
private ArrayList<Float> mPathHeights = new ArrayList<>();
|
|
|
private ArrayList<Float> mPathAngleWidths = new ArrayList<>();
|
|
private ArrayList<Float> mPathAngleWidths = new ArrayList<>();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ private float mTotalHeight =
|
|
|
|
|
+ TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 250, getResources().getDisplayMetrics());
|
|
|
private float maxWidth =
|
|
private float maxWidth =
|
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 330, getResources().getDisplayMetrics());
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 330, getResources().getDisplayMetrics());
|
|
|
private float maxLineH =
|
|
private float maxLineH =
|
|
@@ -53,12 +63,7 @@ public class FunnelView extends View implements ValueAnimator.AnimatorUpdateList
|
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
|
|
|
private float textStartOffsetX =
|
|
private float textStartOffsetX =
|
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7, getResources().getDisplayMetrics());
|
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7, getResources().getDisplayMetrics());
|
|
|
-
|
|
|
|
|
- private float mLastX;
|
|
|
|
|
- private float mLastY;
|
|
|
|
|
- private float mLastWidth;
|
|
|
|
|
- private int maxHight;
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
public FunnelView(Context context) {
|
|
public FunnelView(Context context) {
|
|
|
this(context, null);
|
|
this(context, null);
|
|
|
}
|
|
}
|
|
@@ -72,7 +77,6 @@ public class FunnelView extends View implements ValueAnimator.AnimatorUpdateList
|
|
|
init();
|
|
init();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
public void setData(List<Integer> moneys, int maxMoney,ArrayList<String> colors) {
|
|
public void setData(List<Integer> moneys, int maxMoney,ArrayList<String> colors) {
|
|
|
this.mMoneys = moneys;
|
|
this.mMoneys = moneys;
|
|
|
this.maxMoney = maxMoney;
|
|
this.maxMoney = maxMoney;
|
|
@@ -166,8 +170,7 @@ public class FunnelView extends View implements ValueAnimator.AnimatorUpdateList
|
|
|
draw2(canvas, mPaints.get(i), mPathAngleWidths.get(i), mPathHeights.get(i),i);
|
|
draw2(canvas, mPaints.get(i), mPathAngleWidths.get(i), mPathHeights.get(i),i);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- ObjectAnimator xAnimator;
|
|
|
|
|
- ObjectAnimator alphaAnimator;
|
|
|
|
|
|
|
+
|
|
|
public void animateY() {
|
|
public void animateY() {
|
|
|
xAnimator = ObjectAnimator.ofFloat(this, "phaseX", 0, 1);
|
|
xAnimator = ObjectAnimator.ofFloat(this, "phaseX", 0, 1);
|
|
|
xAnimator.setDuration(2000);
|
|
xAnimator.setDuration(2000);
|
|
@@ -197,8 +200,7 @@ public class FunnelView extends View implements ValueAnimator.AnimatorUpdateList
|
|
|
setMeasuredDimension(getMeasuredLength(widthMeasureSpec, true),
|
|
setMeasuredDimension(getMeasuredLength(widthMeasureSpec, true),
|
|
|
getMeasuredLength(heightMeasureSpec, false));
|
|
getMeasuredLength(heightMeasureSpec, false));
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
private int getMeasuredLength(int length, boolean isWidth) {
|
|
private int getMeasuredLength(int length, boolean isWidth) {
|
|
|
int specMode = MeasureSpec.getMode(length);
|
|
int specMode = MeasureSpec.getMode(length);
|
|
|
int specSize = MeasureSpec.getSize(length);
|
|
int specSize = MeasureSpec.getSize(length);
|
|
@@ -228,31 +230,16 @@ public class FunnelView extends View implements ValueAnimator.AnimatorUpdateList
|
|
|
this.textAlpha = textAlpha;
|
|
this.textAlpha = textAlpha;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onAnimationUpdate(ValueAnimator animation) {
|
|
public void onAnimationUpdate(ValueAnimator animation) {
|
|
|
Log.i("Animation", "onAnimationUpdate:动画更新...." );
|
|
Log.i("Animation", "onAnimationUpdate:动画更新...." );
|
|
|
calculate();
|
|
calculate();
|
|
|
postInvalidate();
|
|
postInvalidate();
|
|
|
-
|
|
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onAnimationEnd() {
|
|
protected void onAnimationEnd() {
|
|
|
super.onAnimationEnd();
|
|
super.onAnimationEnd();
|
|
|
Log.i("Animation", "onAnimationUpdate:动画结束....");
|
|
Log.i("Animation", "onAnimationUpdate:动画结束....");
|
|
|
maxHight=0;
|
|
maxHight=0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- /* private void drawText9(Canvas canvas) {
|
|
|
|
|
- Paint.FontMetrics fontMetrics = mPaintText.getFontMetrics();
|
|
|
|
|
- float fontTotalHeight = fontMetrics.bottom - fontMetrics.top;
|
|
|
|
|
- float offY = fontTotalHeight / 2 - fontMetrics.bottom;
|
|
|
|
|
- canvas.drawText("销售漏斗", mLastX + mLastWidth - mPathAngleWidths.get(mPathAngleWidths.size()-1) + 3 * textStartOffsetX, mLastY -
|
|
|
|
|
- mPathHeights.get(mPathHeights.size()-1) / 2 + offY, mPaintText);
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-}
|
|
|
|
|
|
|
+}
|