├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zyw
│ │ └── horrarndoo
│ │ └── gooview
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zyw
│ │ │ └── horrarndoo
│ │ │ └── gooview
│ │ │ ├── MainActivity.java
│ │ │ ├── utils
│ │ │ ├── GeometryUtils.java
│ │ │ └── Utils.java
│ │ │ └── view
│ │ │ ├── BubbleLayout.java
│ │ │ ├── GooView.java
│ │ │ ├── GooViewAapter.java
│ │ │ └── GooViewListener.java
│ └── res
│ │ ├── drawable-xhdpi
│ │ └── red_bg.9.png
│ │ ├── drawable
│ │ └── anim_bubble_pop.xml
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── list_item_goo.xml
│ │ ├── mipmap-hdpi
│ │ ├── head.png
│ │ ├── ic_launcher.png
│ │ ├── pop1.png
│ │ ├── pop2.png
│ │ ├── pop3.png
│ │ ├── pop4.png
│ │ └── pop5.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── zyw
│ └── horrarndoo
│ └── gooview
│ └── ExampleUnitTest.java
├── assets
└── demo.gif
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## GooView
2 | 实现类QQ未读消息拖拽效果
3 |
4 | 博客链接:[Android自定义控件:类QQ未读消息拖拽效果](http://blog.csdn.net/oQinYou/article/details/65444808)
5 |
6 | 
7 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.zyw.horrarndoo.gooview"
7 | minSdkVersion 15
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
24 | exclude group: 'com.android.support', module: 'support-annotations'
25 | })
26 | implementation 'com.android.support:appcompat-v7:27.1.1'
27 | testImplementation 'junit:junit:4.12'
28 | }
29 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zyw/horrarndoo/gooview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zyw.horrarndoo.gooview", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/gooview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.ListView;
6 |
7 | import com.zyw.horrarndoo.gooview.view.GooViewAapter;
8 |
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 | private GooViewAapter adapter;
14 | private List list = new ArrayList();
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 | init();
20 | }
21 |
22 | private void init(){
23 | for (int i = 0; i < 120; i++){
24 | list.add("content - " + i);
25 | }
26 | adapter = new GooViewAapter(MainActivity.this, list);
27 | ListView listView= (ListView) findViewById(R.id.list);
28 | listView.setAdapter(adapter);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/gooview/utils/GeometryUtils.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview.utils;
2 |
3 | import android.graphics.PointF;
4 |
5 | /**
6 | * GeometryUtils
7 | * Created by Horrarndoo on 2017/3/20.
8 | * 几何图形工具
9 | */
10 |
11 | public class GeometryUtils {
12 | /**
13 | * As meaning of method name.
14 | * 获得两点之间的距离
15 | * @param p0
16 | * @param p1
17 | * @return
18 | */
19 | public static float getDistanceBetween2Points(PointF p0, PointF p1) {
20 | float distance = (float) Math.sqrt(Math.pow(p0.y - p1.y, 2) + Math.pow(p0.x - p1.x, 2));
21 | return distance;
22 | }
23 |
24 | /**
25 | * Get middle point between p1 and p2.
26 | * 获得两点连线的中点
27 | * @param p1
28 | * @param p2
29 | * @return
30 | */
31 | public static PointF getMiddlePoint(PointF p1, PointF p2) {
32 | return new PointF((p1.x + p2.x) / 2.0f, (p1.y + p2.y) / 2.0f);
33 | }
34 |
35 | /**
36 | * Get point between p1 and p2 by percent.
37 | * 根据百分比获取两点之间的某个点坐标
38 | * @param p1
39 | * @param p2
40 | * @param percent
41 | * @return
42 | */
43 | public static PointF getPointByPercent(PointF p1, PointF p2, float percent) {
44 | return new PointF(evaluateValue(percent, p1.x , p2.x), evaluateValue(percent, p1.y , p2.y));
45 | }
46 |
47 | /**
48 | * 根据分度值,计算从start到end中,fraction位置的值。fraction范围为0 -> 1
49 | * @param fraction
50 | * @param start
51 | * @param end
52 | * @return
53 | */
54 | public static float evaluateValue(float fraction, Number start, Number end){
55 | return start.floatValue() + (end.floatValue() - start.floatValue()) * fraction;
56 | }
57 |
58 |
59 | /**
60 | * Get the point of intersection between circle and line.
61 | * 获取 通过指定圆心,斜率为lineK的直线与圆的交点。
62 | *
63 | * @param pMiddle The circle center point.
64 | * @param radius The circle radius.
65 | * @param lineK The slope of line which cross the pMiddle.
66 | * @return
67 | */
68 | public static PointF[] getIntersectionPoints(PointF pMiddle, float radius, Double lineK) {
69 | PointF[] points = new PointF[2];
70 |
71 | float radian, xOffset = 0, yOffset = 0;
72 | if(lineK != null){
73 | radian= (float) Math.atan(lineK);
74 | xOffset = (float) (Math.sin(radian) * radius);
75 | yOffset = (float) (Math.cos(radian) * radius);
76 | }else {
77 | xOffset = radius;
78 | yOffset = 0;
79 | }
80 | points[0] = new PointF(pMiddle.x + xOffset, pMiddle.y - yOffset);
81 | points[1] = new PointF(pMiddle.x - xOffset, pMiddle.y + yOffset);
82 |
83 | return points;
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/gooview/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview.utils;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.util.DisplayMetrics;
6 | import android.util.TypedValue;
7 | import android.view.View;
8 | import android.widget.Toast;
9 |
10 | /**
11 | * Utils
12 | * Created by Horrarndoo on 2017/3/20.
13 | */
14 |
15 | public class Utils {
16 | public static Toast mToast;
17 |
18 | public static void showToast(Context mContext, String msg) {
19 | if (mToast == null) {
20 | synchronized (Utils.class){
21 | if(mToast == null){
22 | mToast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
23 | }
24 | }
25 | }
26 | mToast.setText(msg);
27 | mToast.show();
28 | }
29 |
30 | /**
31 | * dip 转换成 px
32 | * @param dip
33 | * @param context
34 | * @return
35 | */
36 | public static float dip2Dimension(float dip, Context context) {
37 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
38 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, displayMetrics);
39 | }
40 |
41 | /** 获取状态栏高度
42 | * @param v
43 | * @return
44 | */
45 | public static int getStatusBarHeight(View v) {
46 | if (v == null) {
47 | return 0;
48 | }
49 | Rect frame = new Rect();
50 | v.getWindowVisibleDisplayFrame(frame);
51 | return frame.top;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/gooview/view/BubbleLayout.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview.view;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.widget.FrameLayout;
6 |
7 | /**
8 | * Created by Horrarndoo on 2017/3/20.
9 | * 播放爆炸动画的layout
10 | */
11 |
12 | public class BubbleLayout extends FrameLayout {
13 | Context context;
14 |
15 | public BubbleLayout(Context context) {
16 | super(context);
17 | this.context = context;
18 | }
19 |
20 | private int mCenterX, mCenterY;
21 |
22 | public void setCenter(int x, int y) {
23 | mCenterX = x;
24 | mCenterY = y;
25 | requestLayout();
26 | }
27 |
28 | @Override
29 | protected void onLayout(boolean changed, int left, int top, int right,
30 | int bottom) {
31 | View child = getChildAt(0);
32 | // 设置View到指定位置
33 | if (child != null && child.getVisibility() != GONE) {
34 | final int width = child.getMeasuredWidth();
35 | final int height = child.getMeasuredHeight();
36 | child.layout((int) (mCenterX - width / 2.0f), (int) (mCenterY - height / 2.0f)
37 | , (int) (mCenterX + width / 2.0f), (int) (mCenterY + height / 2.0f));
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/gooview/view/GooView.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview.view;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.animation.ValueAnimator.AnimatorUpdateListener;
7 | import android.content.Context;
8 | import android.graphics.Canvas;
9 | import android.graphics.Color;
10 | import android.graphics.Paint;
11 | import android.graphics.Path;
12 | import android.graphics.PointF;
13 | import android.support.v4.view.MotionEventCompat;
14 | import android.util.AttributeSet;
15 | import android.view.MotionEvent;
16 | import android.view.View;
17 | import android.view.animation.OvershootInterpolator;
18 |
19 | import com.zyw.horrarndoo.gooview.utils.GeometryUtils;
20 | import com.zyw.horrarndoo.gooview.utils.Utils;
21 |
22 | /**
23 | * GooView
24 | * Created by Administrator on 2017/3/20.
25 | */
26 |
27 | public class GooView extends View {
28 | protected static final String TAG = "GooView";
29 |
30 | private PointF mDragCenter;
31 | private PointF mStickCenter;
32 | float dragCircleRadius = 0;
33 | float stickCircleRadius = 0;
34 | float stickCircleMinRadius = 0;
35 | float stickCircleTempRadius = stickCircleRadius;
36 |
37 | String mNumberText = "";
38 |
39 | private Paint mPaintRed;
40 | private Paint mTextPaint;
41 | private ValueAnimator mAnim;
42 | private boolean isOutOfRange = false;
43 |
44 | private OnDisappearListener mListener;
45 | private int mStatusBarHeight;
46 |
47 | /**
48 | * dragPoint拖出mMaxDistance范围后,重置dragPoint范围,超出消失,否则重置
49 | */
50 | private float mResetDistance;
51 | /**
52 | * 绘制连接线最大范围,超出不绘制贝塞尔曲线部分以及stickPoint
53 | */
54 | private float mMaxDistance = 0;
55 |
56 | public GooView(Context context) {
57 | this(context, null);
58 | }
59 |
60 | public GooView(Context context, AttributeSet attrs) {
61 | this(context, attrs, 0);
62 | }
63 |
64 | public GooView(Context context, AttributeSet attrs, int defStyleAttr) {
65 | super(context, attrs, defStyleAttr);
66 | init(context);
67 | }
68 |
69 | private void init(Context context) {
70 | stickCircleRadius = Utils.dip2Dimension(10.0f, context);
71 | dragCircleRadius = Utils.dip2Dimension(10.0f, context);
72 | stickCircleMinRadius = Utils.dip2Dimension(3.0f, context);
73 | mMaxDistance = Utils.dip2Dimension(70.0f, context);
74 | mResetDistance = Utils.dip2Dimension(40.0f, getContext());
75 |
76 | mPaintRed = new Paint(Paint.ANTI_ALIAS_FLAG);
77 | mPaintRed.setColor(Color.RED);
78 |
79 | mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
80 | mTextPaint.setTextAlign(Paint.Align.CENTER);
81 | mTextPaint.setColor(Color.WHITE);
82 | mTextPaint.setTextSize(dragCircleRadius * 1.2f);
83 | }
84 |
85 | /**
86 | * 设置拖拽圆的半径
87 | *
88 | * @param r
89 | */
90 | public void setDargCircleRadius(float r) {
91 | dragCircleRadius = r;
92 | invalidate();
93 | }
94 |
95 | /**
96 | * 设置固定圆的半径
97 | *
98 | * @param r
99 | */
100 | public void setStickCircleRadius(float r) {
101 | stickCircleRadius = r;
102 | invalidate();
103 | }
104 |
105 | /**
106 | * 设置数字
107 | *
108 | * @param num
109 | */
110 | public void setNumber(int num) {
111 | mNumberText = String.valueOf(num);
112 | }
113 |
114 | /**
115 | * 初始化圆的圆心坐标
116 | *
117 | * @param x
118 | * @param y
119 | */
120 | public void initCenter(float x, float y) {
121 | initDragCenter(x, y);
122 | initStickCenter(x, y);
123 | invalidate();
124 | }
125 |
126 | public void initDragCenter(float x, float y) {
127 | mDragCenter = new PointF(x, y);
128 | }
129 |
130 | public void initStickCenter(float x, float y) {
131 | mStickCenter = new PointF(x, y);
132 | }
133 |
134 | /**
135 | * 更新拖拽圆的圆心坐标,重绘View
136 | *
137 | * @param x
138 | * @param y
139 | */
140 | private void updateDragPointCenter(float x, float y) {
141 | this.mDragCenter.x = x;
142 | this.mDragCenter.y = y;
143 | invalidate();
144 | }
145 |
146 | /**
147 | * 根据距离获得当前固定圆的半径
148 | *
149 | * @param distance
150 | * @return
151 | */
152 | private float getCurrentRadius(float distance) {
153 | distance = Math.min(distance, mMaxDistance);
154 | //20%-80%
155 | float fraction = 0.2f + 0.8f * distance / mMaxDistance;
156 |
157 | // Distance -> mMaxDistance
158 | // stickCircleRadius -> stickCircleMinRadius
159 | float evaluateValue = (float) GeometryUtils.evaluateValue(fraction, stickCircleRadius, stickCircleMinRadius);
160 | return evaluateValue;
161 | }
162 |
163 | @Override
164 | public boolean dispatchTouchEvent(MotionEvent event) {
165 | if (isAnimRunning()) {
166 | return false;
167 | }
168 | return super.dispatchTouchEvent(event);
169 | }
170 |
171 | @Override
172 | public boolean onTouchEvent(MotionEvent event) {
173 | switch (MotionEventCompat.getActionMasked(event)) {
174 | case MotionEvent.ACTION_DOWN: {
175 | isOutOfRange = false;
176 | updateDragPointCenter(event.getRawX(), event.getRawY());
177 | break;
178 | }
179 | case MotionEvent.ACTION_MOVE: {
180 | //如果两圆间距大于最大距离mMaxDistance,执行拖拽结束动画
181 | PointF p0 = new PointF(mDragCenter.x, mDragCenter.y);
182 | PointF p1 = new PointF(mStickCenter.x, mStickCenter.y);
183 | if (GeometryUtils.getDistanceBetween2Points(p0, p1) > mMaxDistance) {
184 | isOutOfRange = true;
185 | updateDragPointCenter(event.getRawX(), event.getRawY());
186 | return false;
187 | }
188 | updateDragPointCenter(event.getRawX(), event.getRawY());
189 | break;
190 | }
191 | case MotionEvent.ACTION_UP: {
192 | handleActionUp();
193 | break;
194 | }
195 | default: {
196 | isOutOfRange = false;
197 | break;
198 | }
199 | }
200 | return true;
201 | }
202 |
203 | /**
204 | * 判断动画是否正在执行
205 | *
206 | * @return
207 | */
208 | private boolean isAnimRunning() {
209 | if (mAnim != null && mAnim.isRunning()) {
210 | return true;
211 | }
212 | return false;
213 | }
214 |
215 | /**
216 | * 清除小红点
217 | */
218 | private void disappeared() {
219 | invalidate();
220 |
221 | if (mListener != null) {
222 | mListener.onDisappear(mDragCenter);
223 | }
224 | }
225 |
226 | /**
227 | * 手势抬起动作
228 | */
229 | private void handleActionUp() {
230 | if (isOutOfRange) {
231 | // 当拖动dragPoint范围已经超出mMaxDistance,然后又将dragPoint拖回mResetDistance范围内时
232 | if (GeometryUtils.getDistanceBetween2Points(mDragCenter, mStickCenter) < mResetDistance) {
233 | if (mListener != null)
234 | mListener.onReset(isOutOfRange);
235 | return;
236 | }
237 | // dragPoint > mResetDistance,删除这个点
238 | disappeared();
239 | } else {
240 | //手指抬起时,弹回动画
241 | mAnim = ValueAnimator.ofFloat(1.0f);
242 | mAnim.setInterpolator(new OvershootInterpolator(5.0f));
243 |
244 | final PointF startPoint = new PointF(mDragCenter.x, mDragCenter.y);
245 | final PointF endPoint = new PointF(mStickCenter.x, mStickCenter.y);
246 | mAnim.addUpdateListener(new AnimatorUpdateListener() {
247 | @Override
248 | public void onAnimationUpdate(ValueAnimator animation) {
249 | float fraction = animation.getAnimatedFraction();
250 | PointF pointByPercent = GeometryUtils.getPointByPercent(startPoint, endPoint, fraction);
251 | updateDragPointCenter((float) pointByPercent.x, (float) pointByPercent.y);
252 | }
253 | });
254 | mAnim.addListener(new AnimatorListenerAdapter() {
255 | @Override
256 | public void onAnimationEnd(Animator animation) {
257 | if (mListener != null)
258 | mListener.onReset(isOutOfRange);
259 | }
260 | });
261 |
262 | if (GeometryUtils.getDistanceBetween2Points(startPoint, endPoint) < 10) {
263 | mAnim.setDuration(100);
264 | } else {
265 | mAnim.setDuration(300);
266 | }
267 | mAnim.start();
268 | }
269 | }
270 |
271 | @Override
272 | protected void onDraw(Canvas canvas) {
273 | canvas.save();
274 | //去除状态栏高度偏差
275 | canvas.translate(0, -mStatusBarHeight);
276 | if (!isOutOfRange) {
277 | drawGooPath(canvas);
278 | }
279 | // 画拖拽圆
280 | canvas.drawCircle(mDragCenter.x, mDragCenter.y, dragCircleRadius, mPaintRed);
281 | // 画数字
282 | canvas.drawText(mNumberText, mDragCenter.x, mDragCenter.y + dragCircleRadius / 2f, mTextPaint);
283 | canvas.restore();
284 | }
285 |
286 | /**
287 | * 绘制贝塞尔曲线部分以及固定圆
288 | *
289 | * @param canvas
290 | */
291 | private void drawGooPath(Canvas canvas) {
292 | Path path = new Path();
293 | //1. 根据当前两圆圆心的距离计算出固定圆的半径
294 | float distance = (float) GeometryUtils.getDistanceBetween2Points(mDragCenter, mStickCenter);
295 | stickCircleTempRadius = getCurrentRadius(distance);
296 |
297 | //2. 计算出经过两圆圆心连线的垂线的dragLineK(对边比临边)。求出四个交点坐标
298 | float xDiff = mStickCenter.x - mDragCenter.x;
299 | Double dragLineK = null;
300 | if (xDiff != 0) {
301 | dragLineK = (double) ((mStickCenter.y - mDragCenter.y) / xDiff);
302 | }
303 |
304 | //分别获得经过两圆圆心连线的垂线与圆的交点(两条垂线平行,所以dragLineK相等)。
305 | PointF[] dragPoints = GeometryUtils.getIntersectionPoints(mDragCenter, dragCircleRadius, dragLineK);
306 | PointF[] stickPoints = GeometryUtils.getIntersectionPoints(mStickCenter, stickCircleTempRadius, dragLineK);
307 |
308 | //3. 以两圆连线的0.618处作为 贝塞尔曲线 的控制点。(选一个中间点附近的控制点)
309 | PointF pointByPercent = GeometryUtils.getPointByPercent(mDragCenter, mStickCenter, 0.618f);
310 |
311 | // 绘制两圆连接闭合
312 | path.moveTo((float) stickPoints[0].x, (float) stickPoints[0].y);
313 | path.quadTo((float) pointByPercent.x, (float) pointByPercent.y,
314 | (float) dragPoints[0].x, (float) dragPoints[0].y);
315 | path.lineTo((float) dragPoints[1].x, (float) dragPoints[1].y);
316 | path.quadTo((float) pointByPercent.x, (float) pointByPercent.y,
317 | (float) stickPoints[1].x, (float) stickPoints[1].y);
318 | canvas.drawPath(path, mPaintRed);
319 | // 画固定圆
320 | canvas.drawCircle(mStickCenter.x, mStickCenter.y, stickCircleTempRadius, mPaintRed);
321 | }
322 |
323 | public OnDisappearListener getOnDisappearListener() {
324 | return mListener;
325 | }
326 |
327 | public void setOnDisappearListener(OnDisappearListener mListener) {
328 | this.mListener = mListener;
329 | }
330 |
331 | public void setStatusBarHeight(int statusBarHeight) {
332 | this.mStatusBarHeight = statusBarHeight;
333 | }
334 |
335 | interface OnDisappearListener {
336 | /**
337 | * GooView Disapper
338 | *
339 | * @param mDragCenter
340 | */
341 | void onDisappear(PointF mDragCenter);
342 |
343 | /**
344 | * GooView onReset
345 | *
346 | * @param isOutOfRange
347 | */
348 | void onReset(boolean isOutOfRange);
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/gooview/view/GooViewAapter.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.PointF;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.LinearLayout;
10 | import android.widget.TextView;
11 |
12 | import com.zyw.horrarndoo.gooview.R;
13 | import com.zyw.horrarndoo.gooview.utils.Utils;
14 |
15 | import java.util.ArrayList;
16 | import java.util.HashSet;
17 | import java.util.List;
18 |
19 | /**
20 | * Created by Horrarndoo on 2017/3/20.
21 | */
22 | public class GooViewAapter extends BaseAdapter {
23 | private Context mContext;
24 | //记录已经remove的position
25 | private HashSet mRemoved = new HashSet();
26 | private List list = new ArrayList();
27 |
28 | public GooViewAapter(Context mContext, List list) {
29 | super();
30 | this.mContext = mContext;
31 | this.list = list;
32 | }
33 |
34 | @Override
35 | public int getCount() {
36 | return list.size();
37 | }
38 |
39 | @Override
40 | public Object getItem(int position) {
41 | return list.get(position);
42 | }
43 |
44 | @Override
45 | public long getItemId(int position) {
46 | return position;
47 | }
48 |
49 | @Override
50 | public View getView(final int position, View convertView, ViewGroup parent) {
51 | if (convertView == null) {
52 | convertView = View.inflate(mContext, R.layout.list_item_goo, null);
53 | }
54 | ViewHolder holder = ViewHolder.getHolder(convertView);
55 | holder.mContent.setText(list.get(position));
56 | //item固定小红点layout
57 | LinearLayout pointLayout = holder.mPointLayout;
58 | //item固定小红点
59 | final TextView point = holder.mPoint;
60 |
61 | boolean visiable = !mRemoved.contains(position);
62 | pointLayout.setVisibility(visiable ? View.VISIBLE : View.GONE);
63 | if (visiable) {
64 | point.setText(String.valueOf(position));
65 | pointLayout.setTag(position);
66 | GooViewListener mGooListener = new GooViewListener(mContext, pointLayout) {
67 | @Override
68 | public void onDisappear(PointF mDragCenter) {
69 | super.onDisappear(mDragCenter);
70 | mRemoved.add(position);
71 | notifyDataSetChanged();
72 | Utils.showToast(mContext, "position " + position + " disappear.");
73 | }
74 |
75 | @Override
76 | public void onReset(boolean isOutOfRange) {
77 | super.onReset(isOutOfRange);
78 | notifyDataSetChanged();//刷新ListView
79 | Utils.showToast(mContext, "position " + position + " reset.");
80 | }
81 | };
82 | //在point父布局内的触碰事件都进行监听
83 | pointLayout.setOnTouchListener(mGooListener);
84 | }
85 | return convertView;
86 | }
87 |
88 | static class ViewHolder {
89 |
90 | public ImageView mImage;
91 | public TextView mPoint;
92 | public LinearLayout mPointLayout;
93 | public TextView mContent;
94 |
95 | public ViewHolder(View convertView) {
96 | mImage = (ImageView) convertView.findViewById(R.id.iv_head);
97 | mPoint = (TextView) convertView.findViewById(R.id.point);
98 | mPointLayout = (LinearLayout) convertView.findViewById(R.id.ll_point);
99 | mContent = (TextView) convertView.findViewById(R.id.tv_content);
100 | }
101 |
102 | public static ViewHolder getHolder(View convertView) {
103 | ViewHolder holder = (ViewHolder) convertView.getTag();
104 | if (holder == null) {
105 | holder = new ViewHolder(convertView);
106 | convertView.setTag(holder);
107 | }
108 | return holder;
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zyw/horrarndoo/gooview/view/GooViewListener.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.PixelFormat;
5 | import android.graphics.PointF;
6 | import android.graphics.drawable.AnimationDrawable;
7 | import android.os.Build;
8 | import android.os.Handler;
9 | import android.support.v4.view.MotionEventCompat;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.View.OnTouchListener;
13 | import android.view.ViewParent;
14 | import android.view.WindowManager;
15 | import android.widget.FrameLayout;
16 | import android.widget.ImageView;
17 |
18 | import com.zyw.horrarndoo.gooview.R;
19 | import com.zyw.horrarndoo.gooview.utils.Utils;
20 | import com.zyw.horrarndoo.gooview.view.GooView.OnDisappearListener;
21 |
22 | /**
23 | * Created by Horrarndoo on 2017/3/20.
24 | */
25 |
26 | public class GooViewListener implements OnTouchListener, OnDisappearListener {
27 |
28 | private WindowManager mWm;
29 | private WindowManager.LayoutParams mParams;
30 | private GooView mGooView;
31 | private View pointLayout;
32 | private int number;
33 | private final Context mContext;
34 |
35 | private Handler mHandler;
36 |
37 | public GooViewListener(Context mContext, View pointLayout) {
38 | this.mContext = mContext;
39 | this.pointLayout = pointLayout;
40 | this.number = (Integer) pointLayout.getTag();
41 |
42 | mGooView = new GooView(mContext);
43 |
44 | mWm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
45 | mParams = new WindowManager.LayoutParams();
46 | mParams.format = PixelFormat.TRANSLUCENT;//使窗口支持透明度
47 |
48 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
49 | mParams.flags = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
50 | }
51 |
52 | mHandler = new Handler(mContext.getMainLooper());
53 | }
54 |
55 | @Override
56 | public boolean onTouch(View v, MotionEvent event) {
57 | int action = MotionEventCompat.getActionMasked(event);
58 | // 当按下时,将自定义View添加到WindowManager中
59 | if (action == MotionEvent.ACTION_DOWN) {
60 | ViewParent parent = v.getParent();
61 | // 请求其父级View不拦截Touch事件
62 | parent.requestDisallowInterceptTouchEvent(true);
63 |
64 | int[] points = new int[2];
65 | //获取pointLayout在屏幕中的位置(layout的左上角坐标)
66 | pointLayout.getLocationInWindow(points);
67 | //获取初始小红点中心坐标
68 | int x = points[0] + pointLayout.getWidth() / 2;
69 | int y = points[1] + pointLayout.getHeight() / 2;
70 | // 初始化当前点击的item的信息,数字及坐标
71 | mGooView.setStatusBarHeight(Utils.getStatusBarHeight(v));
72 | mGooView.setNumber(number);
73 | mGooView.initCenter(x, y);
74 | //设置当前GooView消失监听
75 | mGooView.setOnDisappearListener(this);
76 | // 添加当前GooView到WindowManager
77 | mWm.addView(mGooView, mParams);
78 | pointLayout.setVisibility(View.INVISIBLE);
79 | }
80 | // 将所有touch事件转交给GooView处理
81 | mGooView.onTouchEvent(event);
82 | return true;
83 | }
84 |
85 | @Override
86 | public void onDisappear(PointF mDragCenter) {
87 | if (mWm != null && mGooView.getParent() != null) {
88 | mWm.removeView(mGooView);
89 |
90 | //播放气泡爆炸动画
91 | ImageView imageView = new ImageView(mContext);
92 | imageView.setImageResource(R.drawable.anim_bubble_pop);
93 | AnimationDrawable mAnimDrawable = (AnimationDrawable) imageView
94 | .getDrawable();
95 |
96 | final BubbleLayout bubbleLayout = new BubbleLayout(mContext);
97 | bubbleLayout.setCenter((int) mDragCenter.x, (int) mDragCenter.y - Utils.getStatusBarHeight(mGooView));
98 |
99 | bubbleLayout.addView(imageView, new FrameLayout.LayoutParams(
100 | android.widget.FrameLayout.LayoutParams.WRAP_CONTENT,
101 | android.widget.FrameLayout.LayoutParams.WRAP_CONTENT));
102 |
103 | mWm.addView(bubbleLayout, mParams);
104 |
105 | mAnimDrawable.start();
106 |
107 | // 播放结束后,删除该bubbleLayout
108 | mHandler.postDelayed(new Runnable() {
109 | @Override
110 | public void run() {
111 | mWm.removeView(bubbleLayout);
112 | }
113 | }, 501);
114 | }
115 |
116 | }
117 |
118 | @Override
119 | public void onReset(boolean isOutOfRange) {
120 | // 当dragPoint弹回时,去除该View,等下次ACTION_DOWN的时候再添加
121 | if (mWm != null && mGooView.getParent() != null) {
122 | mWm.removeView(mGooView);
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/red_bg.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/drawable-xhdpi/red_bg.9.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/anim_bubble_pop.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
11 |
14 |
17 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/list_item_goo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
25 |
26 |
34 |
35 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/head.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-hdpi/head.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/pop1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-hdpi/pop1.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/pop2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-hdpi/pop2.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/pop3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-hdpi/pop3.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/pop4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-hdpi/pop4.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/pop5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-hdpi/pop5.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 20dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GooView
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zyw/horrarndoo/gooview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zyw.horrarndoo.gooview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/assets/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/assets/demo.gif
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.3.2'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Horrarndoo/GooView/5d9267cbd2a74e8b65e63bd7b92d832810622565/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Mar 28 22:23:56 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------