1717package com .bvapp .arcmenulibrary ;
1818
1919import android .content .Context ;
20- import android .content .res .ColorStateList ;
2120import android .content .res .Resources ;
2221import android .graphics .Rect ;
23- import android .graphics .Typeface ;
24- import android .os .Build ;
25- import android .support .annotation .ColorInt ;
26- import android .support .annotation .DimenRes ;
27- import android .support .design .widget .CoordinatorLayout ;
2822import android .util .AttributeSet ;
29- import android .util .DisplayMetrics ;
30- import android .util .Log ;
31- import android .view .Gravity ;
3223import android .view .View ;
3324import android .view .animation .AccelerateInterpolator ;
3425import android .view .animation .AlphaAnimation ;
4031import android .view .animation .LinearInterpolator ;
4132import android .view .animation .OvershootInterpolator ;
4233import android .view .animation .RotateAnimation ;
43- import android .widget .FrameLayout ;
4434import android .widget .RelativeLayout ;
4535
4636import java .util .ArrayList ;
@@ -79,6 +69,11 @@ public interface OnMenuItemOpenClose{
7969
8070 private static final int MIN_RADIUS = 100 ;
8171
72+ public static final int TOOLTIP_UP = 0xF20 ;
73+ public static final int TOOLTIP_DOWN = 0xF21 ;
74+ public static final int TOOLTIP_RIGHT = 0xF22 ;
75+ public static final int TOOLTIP_LEFT = 0xF23 ;
76+
8277 private Context mContext ;
8378 private int mLayoutCenterX ;
8479 private int mLayoutCenterY ;
@@ -104,17 +99,20 @@ public interface OnMenuItemOpenClose{
10499 private float tPerDeg = DEFAULT_TO_DEGREES ;
105100
106101 /* the distance between the layout's center and any child's center */
107- private int mRadius ;
102+ private int mRadius = 0 ;
108103 private int mMinRadius = MIN_RADIUS ;
109104 private boolean mExpanded = false ;
110105 private boolean mExpandDone ;
111106 private boolean mAnimDone = true ;
107+ private boolean mRaiusCtrl ;
112108
113109 /* */
114110 private ArrayList <TextStructure > textStructure = new ArrayList <>();
115111 private boolean menuItemRotatationInClosing ;
116112 private boolean checkCenterGravity ;
117113 private boolean toolTipCtrl ;
114+ private int mToolTipSide ;
115+ private int mPreChildOffset ;
118116
119117 /**
120118 *
@@ -217,9 +215,10 @@ private static double computeOffsetX(final int offset, final float degrees) {
217215 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
218216 //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
219217
220- final int radius = mRadius = computeRadius (
218+ int radius = mRadius = computeRadius (
221219 Math .abs (mToDegrees - mFromDegrees ), getChildCount ()/2 ,
222220 mChildSize , mChildPadding , mMinRadius );
221+
223222 final int size = radius * 3 + mChildSize + mChildPadding
224223 + mLayoutPadding * 2 + mMenuSize + 4 * mDefaultShift + mViewWidth ;
225224
@@ -382,12 +381,26 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
382381 if (toolTipCtrl ){
383382 tStructure = textStructure .get (j );
384383 j ++;
385- int shift = getShift ( mFromDegrees , mToDegrees , tDeg , tStructure . w ) ;
386-
387- frame = computeChildFrame (centerX , centerY , mExpanded ? mRadius : 0 , mChildSize , shift , tDeg ,
384+ int l1 , r1 , t1 , b1 ;
385+ l1 = r1 = t1 = b1 = 0 ;
386+ frame = computeChildFrame (centerX , centerY , mExpanded ? mRadius : 0 , 0 , 0 , degrees ,
388387 getChildAt (childAt ).getMeasuredHeight (), getChildAt (childAt ).getMeasuredWidth ());
388+ if (mToolTipSide == TOOLTIP_UP ){
389+ t1 = getFrameOffsetY (tStructure .h );
390+ }else if (mToolTipSide == TOOLTIP_DOWN ){
391+ b1 = getFrameOffsetY (tStructure .h );
392+ }else if (mToolTipSide == TOOLTIP_RIGHT ){
393+ r1 = getFrameOffsetX (tStructure .w );
394+ }else if (mToolTipSide == TOOLTIP_LEFT ){
395+ l1 = getFrameOffsetX (tStructure .w );
396+ }else {
397+ int shiftX = getShift (mFromDegrees , mToDegrees , tDeg , tStructure .w );
398+ int shiftY = mChildSize ;
399+ frame = computeChildFrame (centerX , centerY , mExpanded ? mRadius : 0 , shiftY , shiftX , tDeg ,
400+ getChildAt (childAt ).getMeasuredHeight (), getChildAt (childAt ).getMeasuredWidth ());
401+ }
389402
390- getChildAt (childAt ).layout (frame .left , frame .top , frame .right , frame .bottom );
403+ getChildAt (childAt ).layout (frame .left - l1 + r1 , frame .top - t1 + b1 , frame .right - l1 + r1 , frame .bottom - t1 + b1 );
391404 getChildAt (childAt ).setVisibility (mExpanded ? VISIBLE :INVISIBLE );
392405 }else {
393406 getChildAt (childAt ).setVisibility (INVISIBLE );
@@ -399,6 +412,22 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
399412 }
400413 }
401414
415+ private int getFrameOffsetX (int w ){
416+ /*
417+ mPreChildOffset = w;
418+ for(TextStructure str: textStructure){
419+ if(str.w > mPreChildOffset){
420+ mPreChildOffset = str.w;
421+ }
422+ }
423+ return (mPreChildOffset + mChildSize + (int) dpToPx(4))/2;
424+ */
425+ return (w + mChildSize + (int ) dpToPx (4 ))/2 ;
426+ }
427+
428+ private int getFrameOffsetY (int h ){
429+ return h > mChildSize ? h : mChildSize ;
430+ }
402431 /**
403432 *
404433 * @param fDeg
@@ -486,9 +515,27 @@ private void bindChildAnimation(final View child, final int index, final int ord
486515 final float perDegrees = (mToDegrees - mFromDegrees ) / (childCount - 1 );
487516 Rect frame ;
488517 if (order % 2 != 0 ){
489- int shift = getShift (mFromDegrees , mToDegrees , tDeg + index * tPerDeg , child .getMeasuredWidth ());
490- frame = computeChildFrame (centerX , centerY , mExpanded ? 0 : mRadius , mChildSize , shift ,tDeg
491- + index * tPerDeg , child .getMeasuredHeight (), child .getMeasuredWidth ());
518+ frame = computeChildFrame (centerX , centerY , mExpanded ? 0 : mRadius , 0 , 0 ,mFromDegrees
519+ + index * perDegrees , child .getMeasuredHeight (), child .getMeasuredWidth ());
520+ int offsetX = getFrameOffsetX (child .getMeasuredWidth ());
521+ int offsetY = getFrameOffsetY (child .getMeasuredHeight ());
522+ if (mToolTipSide == TOOLTIP_UP ){
523+ frame .top -= offsetY ;
524+ frame .bottom -= offsetY ;
525+ }else if (mToolTipSide == TOOLTIP_DOWN ){
526+ frame .top += offsetY ;
527+ frame .bottom += offsetY ;
528+ }else if (mToolTipSide == TOOLTIP_RIGHT ){
529+ frame .left += offsetX ;
530+ frame .right += offsetX ;
531+ }else if (mToolTipSide == TOOLTIP_LEFT ){
532+ frame .left -= offsetX ;
533+ frame .right -= offsetX ;
534+ }else {
535+ int shift = getShift (mFromDegrees , mToDegrees , tDeg + index * tPerDeg , child .getMeasuredWidth ());
536+ frame = computeChildFrame (centerX , centerY , mExpanded ? 0 : mRadius , mChildSize , shift ,tDeg
537+ + index * tPerDeg , child .getMeasuredHeight (), child .getMeasuredWidth ());
538+ }
492539 }else {
493540 frame = computeChildFrame (centerX , centerY , radius , mFromDegrees
494541 + index * perDegrees , mChildSize );
@@ -752,6 +799,10 @@ public void setArc(float fromDegrees, float toDegrees) {
752799 requestLayout ();
753800 }
754801
802+ public void setToolTipSide (int mToolTipSide ) {
803+ this .mToolTipSide = mToolTipSide ;
804+ }
805+
755806 /**
756807 *
757808 * @param left
@@ -862,6 +913,12 @@ public int getRadius() {
862913 return mRadius ;
863914 }
864915
916+ public void setRadius (int mRadius ) {
917+ this .mRadius = mRadius ;
918+ mRaiusCtrl = true ;
919+ requestLayout ();
920+ }
921+
865922 /**
866923 *
867924 * @param l
0 commit comments