├── .gitignore
├── LICENSE
├── README.md
├── build.gradle
├── gooview-app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── example
│ │ └── gooview
│ │ ├── MainActivity.java
│ │ ├── util
│ │ ├── EvaluateUtil.java
│ │ ├── GeometryUtil.java
│ │ └── Utils.java
│ │ └── view
│ │ └── GooView.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.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
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── website
└── static
└── screenshot.gif
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Eclipse project files
24 | .classpath
25 | .project
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # log files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # Intellij project files
40 | *.iml
41 | *.ipr
42 | *.iws
43 | .idea/
44 |
45 | # keystore files
46 | *.jks
47 |
48 | # External native build folder generated in Android Studio 2.2 and later
49 | .externalNativeBuild
50 |
51 | # Google Services (e.g. APIs or Firebase)
52 | google-services.json
53 |
54 | # Freeline
55 | freeline.py
56 | freeline/
57 | freeline_project_description.json
58 |
59 | .DS_Store
60 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Gooview
2 |
3 | 一个自定义粘性控件,拖动GooView,在一定的范围内具有粘性效果,当超出范围时,GooView消失。
4 |
5 | # Sample usage
6 |
7 | A sample project which provides runnable code examples that demonstrate uses of the classes in this project is available in the gooview-app/ folder.
8 |
9 | # Preview
10 |
11 | 
12 |
--------------------------------------------------------------------------------
/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 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | mavenCentral()
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/gooview-app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/gooview-app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.example.gooview"
9 | minSdkVersion 15
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:25.3.1'
25 | testCompile 'junit:junit:4.12'
26 |
27 | compile 'com.nineoldandroids:library:2.4.0'
28 | }
29 |
--------------------------------------------------------------------------------
/gooview-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 /Users/macmini/Library/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 |
--------------------------------------------------------------------------------
/gooview-app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gooview-app/src/main/java/com/example/gooview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.gooview;
2 |
3 | import com.example.gooview.view.GooView;
4 | import com.example.gooview.view.GooView.OnReleaseListener;
5 |
6 | import android.app.Activity;
7 | import android.os.Bundle;
8 | import android.widget.Toast;
9 |
10 | public class MainActivity extends Activity {
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | GooView gooView = new GooView(this);
15 | gooView.setOnReleaseListener(new OnReleaseListener() {
16 | @Override
17 | public void onReset(boolean isOutOfRange) {
18 | Toast.makeText(getApplicationContext(), "返回原地.." + isOutOfRange, Toast.LENGTH_SHORT).show();
19 | }
20 | @Override
21 | public void onDisappear() {
22 | Toast.makeText(getApplicationContext(), "消失了..", Toast.LENGTH_SHORT).show();
23 | }
24 | });
25 | setContentView(gooView);
26 | }
27 | }
--------------------------------------------------------------------------------
/gooview-app/src/main/java/com/example/gooview/util/EvaluateUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.gooview.util;
2 |
3 | import android.graphics.Rect;
4 |
5 | public class EvaluateUtil {
6 | /**
7 | * Integer 估值器
8 | *
9 | * @param fraction
10 | * @param startValue
11 | * @param endValue
12 | * @return
13 | */
14 | public static Integer evaluateInt(float fraction, Integer startValue, Integer endValue) {
15 | int startInt = startValue;
16 | return (int) (startInt + fraction * (endValue - startInt));
17 | }
18 |
19 | /**
20 | * Float 估值器
21 | *
22 | * @param fraction
23 | * @param startValue
24 | * @param endValue
25 | * @return
26 | */
27 | public static Float evaluateFloat(float fraction, Number startValue, Number endValue) {
28 | float startFloat = startValue.floatValue();
29 | return startFloat + fraction * (endValue.floatValue() - startFloat);
30 | }
31 |
32 | /**
33 | * Argb 估值器
34 | *
35 | * @param fraction
36 | * @param startValue
37 | * @param endValue
38 | * @return
39 | */
40 | public static Object evaluateArgb(float fraction, Object startValue, Object endValue) {
41 | int startInt = (Integer) startValue;
42 | int startA = (startInt >> 24) & 0xff;
43 | int startR = (startInt >> 16) & 0xff;
44 | int startG = (startInt >> 8) & 0xff;
45 | int startB = startInt & 0xff;
46 |
47 | int endInt = (Integer) endValue;
48 | int endA = (endInt >> 24) & 0xff;
49 | int endR = (endInt >> 16) & 0xff;
50 | int endG = (endInt >> 8) & 0xff;
51 | int endB = endInt & 0xff;
52 |
53 | return (int) ((startA + (int) (fraction * (endA - startA))) << 24)
54 | | (int) ((startR + (int) (fraction * (endR - startR))) << 16)
55 | | (int) ((startG + (int) (fraction * (endG - startG))) << 8)
56 | | (int) ((startB + (int) (fraction * (endB - startB))));
57 | }
58 |
59 | /**
60 | * Rect 估值器
61 | * @param fraction
62 | * @param startValue
63 | * @param endValue
64 | * @return
65 | */
66 | public static Rect evaluateRect(float fraction, Rect startValue, Rect endValue) {
67 | return new Rect(startValue.left + (int)((endValue.left - startValue.left) * fraction),
68 | startValue.top + (int)((endValue.top - startValue.top) * fraction),
69 | startValue.right + (int)((endValue.right - startValue.right) * fraction),
70 | startValue.bottom + (int)((endValue.bottom - startValue.bottom) * fraction));
71 | }
72 | }
--------------------------------------------------------------------------------
/gooview-app/src/main/java/com/example/gooview/util/GeometryUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.gooview.util;
2 |
3 | import android.graphics.PointF;
4 |
5 | /**
6 | * 几何图形工具
7 | */
8 | public class GeometryUtil {
9 |
10 | /**
11 | * As meaning of method name.
12 | * 获得两点之间的距离
13 | * @param p0
14 | * @param p1
15 | * @return
16 | */
17 | public static float getDistanceBetween2Points(PointF p0, PointF p1) {
18 | float distance = (float) Math.sqrt(Math.pow(p0.y - p1.y, 2) + Math.pow(p0.x - p1.x, 2));
19 | return distance;
20 | }
21 |
22 | /**
23 | * Get middle point between p1 and p2.
24 | * 获得两点连线的中点
25 | * @param p1
26 | * @param p2
27 | * @return
28 | */
29 | public static PointF getMiddlePoint(PointF p1, PointF p2) {
30 | return new PointF((p1.x + p2.x) / 2.0f, (p1.y + p2.y) / 2.0f);
31 | }
32 |
33 | /**
34 | * Get point between p1 and p2 by percent.
35 | * 根据百分比获取两点之间的某个点坐标
36 | * @param p1
37 | * @param p2
38 | * @param percent
39 | * @return
40 | */
41 | public static PointF getPointByPercent(PointF p1, PointF p2, float percent) {
42 | return new PointF(evaluateValue(percent, p1.x , p2.x), evaluateValue(percent, p1.y , p2.y));
43 | }
44 |
45 | /**
46 | * 根据分度值,计算从start到end中,fraction位置的值。fraction范围为0 -> 1
47 | * @param fraction
48 | * @param start
49 | * @param end
50 | * @return
51 | */
52 | public static float evaluateValue(float fraction, Number start, Number end){
53 | return start.floatValue() + (end.floatValue() - start.floatValue()) * fraction;
54 | }
55 |
56 | /**
57 | * Get the point of intersection between circle and line.
58 | * 获取 通过指定圆心,斜率为lineK的直线与圆的交点。
59 | *
60 | * @param pMiddle The circle center point.
61 | * @param radius The circle radius.
62 | * @param lineK The slope of line which cross the pMiddle.
63 | * @return
64 | */
65 | public static PointF[] getIntersectionPoints(PointF pMiddle, float radius, Double lineK) {
66 | PointF[] points = new PointF[2];
67 |
68 | float radian, xOffset = 0, yOffset = 0;
69 | if(lineK != null){
70 |
71 | radian= (float) Math.atan(lineK);
72 | xOffset = (float) (Math.cos(radian) * radius);
73 | yOffset = (float) (Math.sin(radian) * radius);
74 | }else {
75 | xOffset = radius;
76 | yOffset = 0;
77 | }
78 | points[0] = new PointF(pMiddle.x + xOffset, pMiddle.y + yOffset);
79 | points[1] = new PointF(pMiddle.x - xOffset, pMiddle.y - yOffset);
80 |
81 | return points;
82 | }
83 |
84 | // /**
85 | // * Get the point of intersection between circle and line.
86 | // * 获取 通过指定圆心,斜率为lineK的直线与圆的交点。
87 | // *
88 | // * @param pMiddle The circle center point.
89 | // * @param radius The circle radius.
90 | // * @param lineK The slope of line which cross the pMiddle.
91 | // * @return
92 | // */
93 | // public static PointF[] getIntersectionPoints(PointF pMiddle, float radius, Double lineK) {
94 | // PointF[] points = new PointF[2];
95 | //
96 | // float radian, xOffset = 0, yOffset = 0;
97 | // if(lineK != null){
98 | // radian= (float) Math.atan(lineK);
99 | // xOffset = (float) (Math.sin(radian) * radius);
100 | // yOffset = (float) (Math.cos(radian) * radius);
101 | // }else {
102 | // xOffset = radius;
103 | // yOffset = 0;
104 | // }
105 | // points[0] = new PointF(pMiddle.x + xOffset, pMiddle.y - yOffset);
106 | // points[1] = new PointF(pMiddle.x - xOffset, pMiddle.y + yOffset);
107 | //
108 | // return points;
109 | // }
110 | }
--------------------------------------------------------------------------------
/gooview-app/src/main/java/com/example/gooview/util/Utils.java:
--------------------------------------------------------------------------------
1 | package com.example.gooview.util;
2 |
3 | import android.content.Context;
4 | import android.graphics.Rect;
5 | import android.support.v4.view.MotionEventCompat;
6 | import android.util.DisplayMetrics;
7 | import android.util.TypedValue;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.widget.Toast;
11 |
12 | public class Utils {
13 |
14 | private static Toast mToast;
15 |
16 | public static void showToast(Context mContext, String msg) {
17 | if (mToast == null) {
18 | mToast = Toast.makeText(mContext, "", Toast.LENGTH_SHORT);
19 | }
20 | mToast.setText(msg);
21 | mToast.show();
22 | }
23 |
24 | /**
25 | * dip 转换成 px
26 | * @param dip
27 | * @param context
28 | * @return
29 | */
30 | public static float dip2Dimension(float dip, Context context) {
31 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
32 | return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, displayMetrics);
33 | }
34 | /**
35 | * @param dip
36 | * @param context
37 | * @param complexUnit {@link TypedValue#COMPLEX_UNIT_DIP} {@link TypedValue#COMPLEX_UNIT_SP}}
38 | * @return
39 | */
40 | public static float toDimension(float dip, Context context, int complexUnit) {
41 | DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
42 | return TypedValue.applyDimension(complexUnit, dip, displayMetrics);
43 | }
44 |
45 | /** 获取状态栏高度
46 | * @param v
47 | * @return
48 | */
49 | public static int getStatusBarHeight(View v) {
50 | if (v == null) {
51 | return 0;
52 | }
53 | Rect frame = new Rect();
54 | v.getWindowVisibleDisplayFrame(frame);
55 | return frame.top;
56 | }
57 |
58 | public static String getActionName(MotionEvent event) {
59 | String action = "unknow";
60 | switch (MotionEventCompat.getActionMasked(event)) {
61 | case MotionEvent.ACTION_DOWN:
62 | action = "ACTION_DOWN";
63 | break;
64 | case MotionEvent.ACTION_MOVE:
65 | action = "ACTION_MOVE";
66 | break;
67 | case MotionEvent.ACTION_UP:
68 | action = "ACTION_UP";
69 | break;
70 | case MotionEvent.ACTION_CANCEL:
71 | action = "ACTION_CANCEL";
72 | break;
73 | case MotionEvent.ACTION_SCROLL:
74 | action = "ACTION_SCROLL";
75 | break;
76 | case MotionEvent.ACTION_OUTSIDE:
77 | action = "ACTION_SCROLL";
78 | break;
79 | default:
80 | break;
81 | }
82 | return action;
83 | }
84 | }
--------------------------------------------------------------------------------
/gooview-app/src/main/java/com/example/gooview/view/GooView.java:
--------------------------------------------------------------------------------
1 | package com.example.gooview.view;
2 |
3 | import android.content.Context;
4 | import android.graphics.Canvas;
5 | import android.graphics.Color;
6 | import android.graphics.Paint;
7 | import android.graphics.Paint.Style;
8 | import android.graphics.Path;
9 | import android.graphics.PointF;
10 | import android.util.AttributeSet;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import android.view.animation.OvershootInterpolator;
14 |
15 | import com.example.gooview.util.EvaluateUtil;
16 | import com.example.gooview.util.GeometryUtil;
17 | import com.example.gooview.util.Utils;
18 | import com.nineoldandroids.animation.Animator;
19 | import com.nineoldandroids.animation.AnimatorListenerAdapter;
20 | import com.nineoldandroids.animation.ValueAnimator;
21 | import com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener;
22 |
23 | public class GooView extends View {
24 |
25 | private Paint mPaint;
26 |
27 | public GooView(Context context) {
28 | this(context, null);
29 | }
30 |
31 | public GooView(Context context, AttributeSet attrs) {
32 | this(context, attrs, 0);
33 | }
34 |
35 | public GooView(Context context, AttributeSet attrs, int defStyleAttr) {
36 | super(context, attrs, defStyleAttr);
37 | init();
38 | }
39 |
40 | private void init() {
41 | mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
42 | // mPaint.setAntiAlias(true);
43 | mPaint.setColor(Color.RED);
44 | mPath = new Path();
45 | }
46 |
47 | PointF mDragCenter = new PointF(300f, 300f); //拖拽小球圆心的初始位置
48 | float mDragRadius = 20f; //拖拽小球半径
49 | PointF[] mDragPoints = new PointF[] { new PointF(50f, 250f), new PointF(50f, 350f) };
50 | PointF[] mStickPoints = new PointF[] { new PointF(250f, 250f), new PointF(250f, 350f) };
51 | PointF mControlPoint = new PointF(150f, 300f);
52 | PointF mStickCenter = new PointF(300f, 300f); //外圆圆心位置
53 | float mStickRadius = 15f;
54 | private Path mPath;
55 | private int mStatusBarHeight;
56 | private int mFarthestDistance = 200; //外圆半径
57 | private boolean mIsOutOfRange;
58 | private boolean mIsDisappear;
59 | public interface OnReleaseListener {
60 | void onDisappear();
61 | void onReset(boolean isOutOfRange);
62 | }
63 | private OnReleaseListener mOnReleaseListener;
64 |
65 | public OnReleaseListener getOnReleaseListener() {
66 | return mOnReleaseListener;
67 | }
68 |
69 | public void setOnReleaseListener(OnReleaseListener onReleaseListener) {
70 | mOnReleaseListener = onReleaseListener;
71 | }
72 |
73 | @Override
74 | protected void onDraw(Canvas canvas) {
75 | super.onDraw(canvas);
76 | // 保存画布状态
77 | canvas.save();
78 | // 移动画布
79 | canvas.translate(0, -mStatusBarHeight);
80 | if (!mIsDisappear) {
81 | if (!mIsOutOfRange) {
82 | float tempStickRadius = updateStickRadius();
83 | // 画连接部分
84 | float dy = mStickCenter.y - mDragCenter.y;
85 | float dx = mStickCenter.x - mDragCenter.x;
86 | Double lineK = null;
87 | if (dx != 0f) {
88 | // 圆心连线斜率
89 | lineK = (double) (dy / dx);
90 | }
91 | Double lineK2 = null;
92 | // 计算与圆心连线垂直的直线的斜率
93 | if (lineK == null) {
94 | lineK2 = 0.0;
95 | } else if (lineK == 0.0) {
96 | lineK2 = null;
97 | } else {
98 | lineK2 = -1.0 / lineK;
99 | }
100 | mStickPoints = GeometryUtil.getIntersectionPoints(mStickCenter, tempStickRadius,
101 | lineK2);
102 | mDragPoints = GeometryUtil.getIntersectionPoints(mDragCenter, mDragRadius, lineK2);
103 | mControlPoint = GeometryUtil.getMiddlePoint(mDragCenter, mStickCenter);
104 | // Path表示一条路径
105 | // 重置路径
106 | mPath.reset();
107 | // 移动到某个点
108 | mPath.moveTo(mStickPoints[0].x, mStickPoints[0].y);
109 | // 画二阶贝塞尔曲线
110 | mPath.quadTo(mControlPoint.x, mControlPoint.y, mDragPoints[0].x, mDragPoints[0].y);
111 | // 画线段
112 | mPath.lineTo(mDragPoints[1].x, mDragPoints[1].y);
113 | mPath.quadTo(mControlPoint.x, mControlPoint.y, mStickPoints[1].x, mStickPoints[1].y);
114 | // 封闭曲线
115 | mPath.close();
116 | canvas.drawPath(mPath, mPaint);
117 | // 画固定圆
118 |
119 | canvas.drawCircle(mStickCenter.x, mStickCenter.y, tempStickRadius, mPaint);
120 | }
121 | // 画拖拽圆
122 | canvas.drawCircle(mDragCenter.x, mDragCenter.y, mDragRadius, mPaint);
123 | }
124 |
125 | mPaint.setStyle(Style.STROKE);
126 | canvas.drawCircle(mStickCenter.x, mStickCenter.y, mFarthestDistance, mPaint);
127 | mPaint.setStyle(Style.FILL);
128 | // 恢复画布
129 | canvas.restore();
130 | }
131 |
132 | private float updateStickRadius() {
133 | // 14f, 8f
134 | float distance = GeometryUtil.getDistanceBetween2Points(mDragCenter, mStickCenter);
135 | distance = Math.min(distance, mFarthestDistance);
136 | float percent = distance * 1.0f / mFarthestDistance;
137 | return EvaluateUtil.evaluateFloat(percent, 14f, 8f);
138 | }
139 |
140 | @Override
141 | public boolean onTouchEvent(MotionEvent event) {
142 | float rawX;
143 | float rawY;
144 | switch (event.getAction()) {
145 | case MotionEvent.ACTION_DOWN:
146 | mIsOutOfRange = false;
147 | mIsDisappear = false;
148 | rawX = event.getRawX();
149 | rawY = event.getRawY();
150 | updateDragCenter(rawX, rawY);
151 | break;
152 | case MotionEvent.ACTION_MOVE:
153 | rawX = event.getRawX();
154 | rawY = event.getRawY();
155 | float distance = GeometryUtil.getDistanceBetween2Points(mDragCenter, mStickCenter);
156 | if (distance > mFarthestDistance) {
157 | // 断开
158 | mIsOutOfRange = true;
159 | invalidate();
160 | }
161 | updateDragCenter(rawX, rawY);
162 | break;
163 | case MotionEvent.ACTION_UP:
164 | if (mIsOutOfRange) {
165 | // 拖拽过程超出范围
166 | float distanceUp = GeometryUtil
167 | .getDistanceBetween2Points(mDragCenter, mStickCenter);
168 | if (distanceUp > mFarthestDistance) {
169 | // 消失
170 | mIsDisappear = true;
171 | invalidate();
172 | if(mOnReleaseListener != null) {
173 | mOnReleaseListener.onDisappear();
174 | }
175 | } else {
176 | updateDragCenter(mStickCenter.x, mStickCenter.y);
177 | if(mOnReleaseListener != null) {
178 | mOnReleaseListener.onReset(mIsOutOfRange);
179 | }
180 | }
181 | } else {
182 | // 拖拽过程没超出范围
183 | final PointF startPoint = new PointF(mDragCenter.x, mDragCenter.y);
184 | ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
185 | animator.addUpdateListener(new AnimatorUpdateListener() {
186 | @Override
187 | public void onAnimationUpdate(ValueAnimator animator) {
188 | float percent = animator.getAnimatedFraction();
189 | PointF pointByPercent = GeometryUtil.getPointByPercent(startPoint,
190 | mStickCenter, percent);
191 | updateDragCenter(pointByPercent.x, pointByPercent.y);
192 | }
193 | });
194 | // BaseXxx, SimpleXxx
195 | animator.addListener(new AnimatorListenerAdapter() {
196 | @Override
197 | public void onAnimationEnd(Animator animation) {
198 | super.onAnimationEnd(animation);
199 | if(mOnReleaseListener != null) {
200 | mOnReleaseListener.onReset(mIsOutOfRange);
201 | }
202 | }
203 | });
204 | animator.setDuration(500);
205 | animator.setInterpolator(new OvershootInterpolator(4.0f));
206 | animator.start();
207 |
208 | }
209 | break;
210 | default:
211 | break;
212 | }
213 | return true;
214 | }
215 |
216 | private void updateDragCenter(float x, float y) {
217 | mDragCenter.set(x, y);
218 | invalidate();
219 | }
220 |
221 | @Override
222 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
223 | super.onSizeChanged(w, h, oldw, oldh);
224 | mStatusBarHeight = Utils.getStatusBarHeight(this);
225 | }
226 | }
--------------------------------------------------------------------------------
/gooview-app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/gooview-app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jopengroup/android-gooview/0b73f9b3b66d1001454b036bfa1b1f474641d6d7/gooview-app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gooview-app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jopengroup/android-gooview/0b73f9b3b66d1001454b036bfa1b1f474641d6d7/gooview-app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gooview-app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jopengroup/android-gooview/0b73f9b3b66d1001454b036bfa1b1f474641d6d7/gooview-app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gooview-app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jopengroup/android-gooview/0b73f9b3b66d1001454b036bfa1b1f474641d6d7/gooview-app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gooview-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jopengroup/android-gooview/0b73f9b3b66d1001454b036bfa1b1f474641d6d7/gooview-app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/gooview-app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/gooview-app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gooview-app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 40dp
4 | 40dp
5 |
6 |
--------------------------------------------------------------------------------
/gooview-app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | gooview
3 |
4 |
--------------------------------------------------------------------------------
/gooview-app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jopengroup/android-gooview/0b73f9b3b66d1001454b036bfa1b1f474641d6d7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Mar 13 10:32:12 CST 2017
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-3.3-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 ':gooview-app'
2 |
--------------------------------------------------------------------------------
/website/static/screenshot.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jopengroup/android-gooview/0b73f9b3b66d1001454b036bfa1b1f474641d6d7/website/static/screenshot.gif
--------------------------------------------------------------------------------