├── .gitignore
├── LICENSE.txt
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── thunderpunch
│ │ └── spherelayout
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── thunderpunch
│ │ │ └── sample
│ │ │ ├── SampleActivity.java
│ │ │ └── view
│ │ │ └── ElectricView.java
│ └── res
│ │ ├── drawable
│ │ ├── ic_back.png
│ │ ├── ic_electric.png
│ │ ├── ic_pmb.png
│ │ ├── ic_rotate.xml
│ │ ├── pm025.png
│ │ └── shape_oval_w.xml
│ │ ├── layout
│ │ └── activity_sample.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── attrs.xml
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── thunderpunch
│ └── spherelayout
│ └── ExampleUnitTest.java
├── build.gradle
├── gif
├── i.gif
└── ii.gif
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── lib
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── thunderpunch
│ │ └── spherelayoutlib
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── thunderpunch
│ │ │ └── spherelayoutlib
│ │ │ └── layout
│ │ │ ├── SLTouchListener.java
│ │ │ └── SphereLayout.java
│ └── res
│ │ └── values
│ │ ├── attrs.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── thunderpunch
│ └── spherelayoutlib
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 thunderpunch
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SphereLayout
2 |
3 | a layout which supports 3d rotate and enable its childview has z-depth for android
4 |
5 | the effect is shown as below
6 |
7 | |I|II|
8 | |:---:|:---:|
9 | |||
10 |
11 | ## Usage
12 |
13 | **XML**
14 |
15 | 1. 在布局中配置SphereLayout, 设置半径"radius"和对齐方向"snapOrientation" (属性说明见XML attributes);
16 |
17 | 2. 添加childview, SphereLayout可以包含任意个childview ,每个childview都需要设置"***layout_depth***"属性,取值范围在 SphereLayout的"radius"正负范围内[ -radius , radius ] , 布局未旋转时,depth越大的childview视觉上越接近用户, depth 为负的childview一开始处于背面.
18 |
19 | 3. childview默认位于SphereLayout在x,y轴构建的平面上的中间位置,可添加margin使它相对中间位置进行偏移.
20 |
21 | ```xml
22 |
23 |
29 |
30 |
37 |
38 |
44 |
45 |
56 |
57 |
58 |
59 | ```
60 |
61 | **Code**
62 |
63 | 4. 使SphereLayout朝某个方向旋转一定的角度
64 |
65 | ```java
66 | SphereLayout sl = (SphereLayout) findViewById(R.id.sl);
67 | sl.rotate(-40, 30);//朝x轴正方向逆时针旋转40度的方向,向内翻转30度
68 | ```
69 |
70 | 5. 反转 SphereLayout
71 |
72 | ```java
73 | sl.reverse(true);
74 | ```
75 |
76 |
77 |
78 | ## XML attributes
79 |
80 | - SphereLayout自身属性
81 |
82 | ```xml
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | ```
96 |
97 | - SphereLayout 直系子视图的布局参数
98 |
99 | ```xml
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | ```
108 |
109 |
110 |
111 | ## Extras
112 |
113 | - 使SphereLayout和用户进行手势交互
114 |
115 | ```java
116 | SphereLayout sl = (SphereLayout) findViewById(R.id.sl);
117 | sl.setOnTouchListener(new SLTouchListener(sl));
118 | ```
119 |
120 | - 使SphereLayout依附于另一个SphereLayout的中心进行翻转 (待完善)
121 |
122 | ```java
123 | /**
124 | * @param sphereLayout 翻转依赖
125 | */
126 | public void rotateDependsOn(SphereLayout sphereLayout) {
127 | mDependency = sphereLayout;
128 | mCheckedDependencyOffset = false;
129 | mDependency.mRotateListener = new OnRotateListener() {
130 | @Override
131 | public void onRotate(int direction, int degree) {
132 | rotate(direction, degree);
133 | }
134 | };
135 | }
136 | ```
137 |
138 |
139 |
140 | ## License
141 |
142 | ```
143 | MIT License
144 |
145 | Copyright (c) 2017 thunderpunch
146 |
147 | Permission is hereby granted, free of charge, to any person obtaining a copy
148 | of this software and associated documentation files (the "Software"), to deal
149 | in the Software without restriction, including without limitation the rights
150 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
151 | copies of the Software, and to permit persons to whom the Software is
152 | furnished to do so, subject to the following conditions:
153 |
154 | The above copyright notice and this permission notice shall be included in all
155 | copies or substantial portions of the Software.
156 |
157 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
159 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
160 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
161 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
162 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
163 | SOFTWARE.
164 | ```
165 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.thunderpunch.spherelayout"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | vectorDrawables.useSupportLibrary = true
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(include: ['*.jar'], dir: 'libs')
25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | compile 'com.android.support:appcompat-v7:25.1.1'
29 | compile 'com.android.support:design:25.1.1'
30 | testCompile 'junit:junit:4.12'
31 | compile project(':lib')
32 | }
33 |
--------------------------------------------------------------------------------
/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 D:\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/thunderpunch/spherelayout/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.spherelayout;
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.thunderpunch.spherelayout", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/thunderpunch/sample/SampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.sample;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ValueAnimator;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v4.view.ViewCompat;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.AppCompatCheckBox;
10 | import android.view.View;
11 | import android.view.animation.OvershootInterpolator;
12 | import android.widget.CompoundButton;
13 |
14 | import com.thunderpunch.sample.view.ElectricView;
15 | import com.thunderpunch.spherelayout.R;
16 | import com.thunderpunch.spherelayoutlib.layout.SLTouchListener;
17 | import com.thunderpunch.spherelayoutlib.layout.SphereLayout;
18 |
19 |
20 | /**
21 | * Created by thunderpunch on 2017/4/6
22 | * Description:
23 | */
24 |
25 | public class SampleActivity extends AppCompatActivity {
26 | private SphereLayout sl;
27 | private View fabFront, fabBack;
28 | private ValueAnimator animator = new ValueAnimator();
29 | private ElectricView evL, evR;
30 |
31 | @Override
32 | protected void onCreate(@Nullable Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_sample);
35 | sl = (SphereLayout) findViewById(R.id.sl0);
36 | sl.setOnTouchListener(new SLTouchListener(sl));
37 | sl.rotate(-30, 30);//静态示例
38 |
39 | fabFront = findViewById(R.id.fab_front);
40 | fabBack = findViewById(R.id.fab_back);
41 |
42 | configReverseAnimator();//配置反转动画
43 |
44 | final View.OnClickListener clickListener = new View.OnClickListener() {
45 | @Override
46 | public void onClick(View v) {
47 | if (!animator.isRunning()) {
48 | animator.start();
49 | }
50 | }
51 | };
52 | fabFront.setOnClickListener(clickListener);
53 | fabBack.setOnClickListener(clickListener);
54 |
55 | ViewCompat.setScaleX(fabBack, 0);
56 | ViewCompat.setScaleY(fabBack, 0);
57 |
58 |
59 | ((AppCompatCheckBox) findViewById(R.id.cb_hideBack)).setOnCheckedChangeListener(
60 | new CompoundButton.OnCheckedChangeListener() {
61 | @Override
62 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
63 | sl.hideBack(isChecked);
64 | }
65 | });
66 |
67 | evR = (ElectricView) findViewById(R.id.electric_r);
68 | evL = (ElectricView) findViewById(R.id.electric_l);
69 | evR.setOnClickListener(new View.OnClickListener() {
70 | @Override
71 | public void onClick(View v) {
72 | evR.shock();
73 | evL.shock();
74 | }
75 | });
76 |
77 | evL.setOnClickListener(new View.OnClickListener() {
78 | @Override
79 | public void onClick(View v) {
80 | evR.shock();
81 | evL.shock();
82 | }
83 | });
84 | }
85 |
86 | private void configReverseAnimator() {
87 | animator = ValueAnimator.ofInt(0, 180);
88 | animator.setInterpolator(new OvershootInterpolator(2));
89 | animator.setDuration(1400);
90 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
91 | @Override
92 | public void onAnimationUpdate(ValueAnimator animation) {
93 | sl.rotate(0, (Integer) animation.getAnimatedValue());
94 | float fraction = animation.getAnimatedFraction();
95 | if (fraction > 0.5) {
96 | ViewCompat.setScaleX(sl.isReverse() ? fabFront : fabBack, (fraction - 0.5f) / 0.5f);
97 | ViewCompat.setScaleY(sl.isReverse() ? fabFront : fabBack, (fraction - 0.5f) / 0.5f);
98 | } else {
99 | fraction = Math.min(fraction, 0.4f);
100 | ViewCompat.setScaleX(sl.isReverse() ? fabBack : fabFront, 1 - fraction / 0.4f);
101 | ViewCompat.setScaleY(sl.isReverse() ? fabBack : fabFront, 1 - fraction / 0.4f);
102 | }
103 | }
104 | });
105 | animator.addListener(new Animator.AnimatorListener() {
106 | @Override
107 | public void onAnimationStart(Animator animation) {
108 | sl.setEnabled(false);
109 | }
110 |
111 | @Override
112 | public void onAnimationEnd(Animator animation) {
113 | sl.reverse(!sl.isReverse());//在动画结束后设置状态为反转
114 | sl.setEnabled(true);
115 | final boolean isReverse = sl.isReverse();
116 | fabFront.setEnabled(!isReverse);
117 | fabBack.setEnabled(isReverse);
118 | evL.setEnabled(!isReverse);
119 | evR.setEnabled(!isReverse);
120 | }
121 |
122 | @Override
123 | public void onAnimationCancel(Animator animation) {
124 |
125 | }
126 |
127 | @Override
128 | public void onAnimationRepeat(Animator animation) {
129 |
130 | }
131 | });
132 | }
133 |
134 | }
135 |
--------------------------------------------------------------------------------
/app/src/main/java/com/thunderpunch/sample/view/ElectricView.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.sample.view;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.Paint;
7 | import android.graphics.Path;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.util.TypedValue;
11 | import android.view.View;
12 | import android.view.animation.AccelerateInterpolator;
13 | import android.view.animation.DecelerateInterpolator;
14 | import android.view.animation.Interpolator;
15 |
16 | import com.thunderpunch.spherelayout.R;
17 |
18 | import java.util.Random;
19 |
20 | /**
21 | * Created by thunderpunch on 2017/4/11
22 | * Description:
23 | */
24 |
25 | public class ElectricView extends View {
26 | private int mDegree;
27 | private int mDegreeOffset = 30;
28 | private int mStartMargin;
29 | private Random mRandom;
30 | private Path mPath;
31 | private int mMaxOffset;
32 | private Paint mPaint;
33 | private int mRemainCount, mElectricCount;
34 | private Interpolator mInterpolator = new AccelerateInterpolator();
35 | private boolean mStartFromRight = true;
36 |
37 | public ElectricView(Context context) {
38 | this(context, null);
39 | }
40 |
41 | public ElectricView(Context context, @Nullable AttributeSet attrs) {
42 | this(context, attrs, 0);
43 | }
44 |
45 | public ElectricView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
46 | super(context, attrs, defStyleAttr);
47 | mPath = new Path();
48 | mRandom = new Random();
49 | mPaint = new Paint();
50 | mPaint.setColor(0xffffff8e);
51 | mPaint.setStrokeWidth(3);
52 | mPaint.setStyle(Paint.Style.STROKE);
53 | mMaxOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
54 | getContext().getResources().getDisplayMetrics());
55 | mStartMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
56 | getContext().getResources().getDisplayMetrics());
57 |
58 | TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ElectricView);
59 | mElectricCount = typedArray.getInt(R.styleable.ElectricView_electricCount, 1);
60 | mStartFromRight = typedArray.getInt(R.styleable.ElectricView_startFrom, 0) == 1;
61 | mDegree = typedArray.getInt(R.styleable.ElectricView_degree, 0);
62 | typedArray.recycle();
63 | }
64 |
65 |
66 | @Override
67 | protected void onDraw(Canvas canvas) {
68 | if (mRemainCount == 0) {
69 | super.onDraw(canvas);
70 | return;
71 | }
72 | canvas.save();
73 |
74 | final int w = getWidth();
75 | final int h = getHeight();
76 | if (mStartFromRight) {
77 | canvas.rotate(180);
78 | canvas.translate(-w, -h);
79 | }
80 |
81 | canvas.translate(0, (h >> 1) - mStartMargin);
82 | final float percent = mInterpolator.getInterpolation(mRemainCount / 5);
83 | int degreeOffset = (int) (mDegreeOffset * percent);
84 | canvas.rotate(mDegree - degreeOffset);
85 | for (int i = 0; i < mElectricCount; i++) {
86 | int currentX = 5 + mRemainCount;
87 | mPath.rewind();
88 | int j = 0;
89 | while (currentX < w * 0.4 + w * 0.6 * percent || (j <= 1)) {
90 | currentX += mRandom.nextDouble() * 0.5 * w;
91 | mPath.lineTo(currentX, (float) ((mRandom.nextDouble() * 2 - 1) * mMaxOffset));
92 | j++;
93 | }
94 | canvas.drawPath(mPath, mPaint);
95 | if (i != mElectricCount - 1) {
96 | canvas.translate(0, 2 * mStartMargin / (mElectricCount - 1));
97 | canvas.rotate(2 * degreeOffset / (mElectricCount - 1));
98 | }
99 | }
100 | mRemainCount--;
101 | canvas.restore();
102 | postInvalidateDelayed(70);
103 | }
104 |
105 | public void shock() {
106 | mRemainCount = 5;
107 | postInvalidate();
108 | }
109 |
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/drawable/ic_back.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_electric.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/drawable/ic_electric.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_pmb.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/drawable/ic_pmb.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_rotate.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/pm025.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/drawable/pm025.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_oval_w.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
23 |
24 |
33 |
34 |
41 |
42 |
49 |
50 |
63 |
64 |
72 |
73 |
78 |
79 |
80 |
86 |
87 |
99 |
100 |
112 |
113 |
123 |
124 |
134 |
135 |
136 |
142 |
143 |
148 |
149 |
150 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/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 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SphereLayout
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/thunderpunch/spherelayout/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.spherelayout;
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 | }
--------------------------------------------------------------------------------
/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.0'
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 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gif/i.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/gif/i.gif
--------------------------------------------------------------------------------
/gif/ii.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/gif/ii.gif
--------------------------------------------------------------------------------
/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/thunderpunch/SphereLayout/e37e4e65e76524abdb744740087634d381d7ec6e/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 05 23:29:00 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 |
--------------------------------------------------------------------------------
/lib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/lib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:25.1.1'
30 | testCompile 'junit:junit:4.12'
31 | }
32 |
--------------------------------------------------------------------------------
/lib/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 D:\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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/lib/src/androidTest/java/com/thunderpunch/spherelayoutlib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.spherelayoutlib;
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.thunderpunch.spherelayoutlib.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/lib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/thunderpunch/spherelayoutlib/layout/SLTouchListener.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.spherelayoutlib.layout;
2 |
3 | import android.animation.AnimatorSet;
4 | import android.animation.ValueAnimator;
5 | import android.view.MotionEvent;
6 | import android.view.View;
7 | import android.view.ViewConfiguration;
8 | import android.view.animation.DecelerateInterpolator;
9 | import android.view.animation.Interpolator;
10 |
11 | /**
12 | * Created by thunderpunch on 2017/2/23
13 | * Description:
14 | */
15 |
16 | public class SLTouchListener implements View.OnTouchListener {
17 | private static final int MAX_ROTATE_DEGREE = 50;
18 | private static final int DURATION = 1800;
19 | private SphereLayout mSphereLayout;
20 | private AnimatorSet mAnimatorSet;
21 | private int mDownX, mDownY;
22 | private boolean mShouldRunAnimation;
23 | private ValueAnimator mFixAnimator;
24 | private ValueAnimator mRotateAnimator;
25 | private int mTouchSlop;
26 | private SpringInterpolator mInterpolator;
27 | private RotateState mState;
28 |
29 | public SLTouchListener(SphereLayout sphereLayout) {
30 | mSphereLayout = sphereLayout;
31 | mTouchSlop = ViewConfiguration.get(mSphereLayout.getContext()).getScaledTouchSlop();
32 | mInterpolator = new SpringInterpolator();
33 | mState = new RotateState();
34 |
35 | mRotateAnimator = new ValueAnimator();
36 | mRotateAnimator.setInterpolator(mInterpolator);
37 | mRotateAnimator.setIntValues(MAX_ROTATE_DEGREE, 0);
38 | mRotateAnimator.setDuration(DURATION);
39 |
40 | mRotateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
41 | @Override
42 | public void onAnimationUpdate(ValueAnimator animation) {
43 | mState.rotateDegree = (Integer) animation.getAnimatedValue();
44 | mSphereLayout.rotate(mState.direction, mState.rotateDegree);
45 | }
46 | });
47 |
48 | mFixAnimator = new ValueAnimator();
49 | mFixAnimator.setInterpolator(new DecelerateInterpolator());
50 | }
51 |
52 | @Override
53 | public boolean onTouch(View v, final MotionEvent event) {
54 | boolean result = false;
55 | switch (event.getAction()) {
56 | case MotionEvent.ACTION_DOWN:
57 | mDownX = (int) event.getX();
58 | mDownY = (int) event.getY();
59 | mShouldRunAnimation = true;
60 | result = true;
61 | break;
62 | case MotionEvent.ACTION_MOVE:
63 | if (Math.abs(event.getX() - mDownX) >= mTouchSlop || Math.abs(event.getY() - mDownY) >= mTouchSlop) {
64 | mShouldRunAnimation = false;
65 | } else {
66 | result = true;
67 | }
68 | break;
69 | case MotionEvent.ACTION_UP:
70 | if (mShouldRunAnimation) {
71 | final int upX = (int) event.getX();
72 | final int upY = (int) event.getY();
73 | if (mAnimatorSet != null && mAnimatorSet.isRunning()) {
74 | mAnimatorSet.cancel();
75 | }
76 | configFixAnimator(calculateDirection(upX, upY));
77 | mAnimatorSet = new AnimatorSet();
78 | mAnimatorSet.play(mRotateAnimator).after(mFixAnimator);
79 | mAnimatorSet.start();
80 | }
81 | result = true;
82 | break;
83 | }
84 | return result;
85 | }
86 |
87 | /**
88 | * @param toDirection 手指按下的方向
89 | */
90 | private void configFixAnimator(int toDirection) {
91 | final int radius = mSphereLayout.getRadius();
92 | int currentDegree, currentDirection;
93 | mState.direction = mSphereLayout.makeDirectionWithinRange(mState.direction);
94 | //取当前翻转角度较大的那个方向
95 | if (mState.rotateDegree >= 0) {
96 | currentDegree = mState.rotateDegree;
97 | currentDirection = mState.direction;
98 | } else {
99 | currentDegree = -mState.rotateDegree;
100 | currentDirection = mState.direction + (mState.direction > 0 ? -180 : 180);
101 | }
102 |
103 | //获取当前翻转角度较大的方向和手指按下方向的差值
104 | int directionDiff = currentDirection - toDirection;
105 |
106 | //获取当前距离点击位置最近的圆边缘点的Z轴距离
107 | int distZ = (int) Math.abs(Math.sin(Math.toRadians(currentDegree))
108 | * Math.cos(Math.toRadians(directionDiff)) * radius);
109 |
110 | //获取当前点击位置的旋转角度
111 | int degree = (int) Math.toDegrees(Math.asin(distZ * 1.0f / radius))
112 | * (directionDiff > 90 || directionDiff < -90 ? -1 : 1);
113 |
114 | //根据旋转角度获取和总周期得出点击位置移动到最大角度的动画所需要的时间
115 | int fixAnimDuration = (int) ((MAX_ROTATE_DEGREE - degree) * 1.0f / MAX_ROTATE_DEGREE
116 | * DURATION / (1.0f / mInterpolator.factor) / 4);
117 |
118 | mFixAnimator.setIntValues(degree, MAX_ROTATE_DEGREE);
119 | mFixAnimator.setDuration(fixAnimDuration);
120 | mFixAnimator.addUpdateListener(new FixAnimatorUpdateListener(currentDegree, degree, currentDirection, toDirection));
121 | }
122 |
123 | /**
124 | * @param x 相对于自身左上角的x轴偏移量
125 | * @param y 相对于自身左上角的y轴偏移量
126 | * @return
127 | */
128 | private int calculateDirection(int x, int y) {
129 | y -= mSphereLayout.getCenterY();
130 | x -= mSphereLayout.getCenterX();
131 | return (int) Math.toDegrees(Math.atan2(y, x));
132 | }
133 |
134 | /**
135 | * 持有翻转状态
136 | */
137 | private class RotateState {
138 | private int direction;
139 | private int rotateDegree;
140 | }
141 |
142 |
143 | private class FixAnimatorUpdateListener implements ValueAnimator.AnimatorUpdateListener {
144 | static final int DIRECTION_ACCEPTABLE_OFFSET = 5;//方向偏移量
145 | int fromDegree;//起始角度
146 | int fromDirection;//起始方向
147 | int directionDiff;
148 |
149 | FixAnimatorUpdateListener(int fromDegree, int toDegree, int fromDirection, int toDirection) {
150 | directionDiff = toDirection - fromDirection;
151 |
152 | /* if (fromDegree < 10) {
153 | this.fromDegree = toDegree;
154 | this.fromDirection = toDirection;
155 | directionDiff = 0;
156 | } else {*/
157 | //确保差值在[-180,180)
158 | if (directionDiff < -180) {
159 | directionDiff += 360;
160 | }
161 | if (directionDiff >= 180) {
162 | directionDiff -= 360;
163 | }
164 |
165 | final int absDirDiff = Math.abs(directionDiff);
166 |
167 | //如果在方向偏移量范围内,那么不进行fixDirection动画
168 | if (absDirDiff >= 180 - DIRECTION_ACCEPTABLE_OFFSET
169 | || absDirDiff <= DIRECTION_ACCEPTABLE_OFFSET) {
170 | this.fromDegree = toDegree;
171 | this.fromDirection = toDirection;
172 | directionDiff = 0;
173 | } else {
174 | this.fromDegree = fromDegree;
175 | this.fromDirection = fromDirection;
176 | }
177 | // }
178 | }
179 |
180 | @Override
181 | public void onAnimationUpdate(ValueAnimator animation) {
182 | final float fraction = animation.getAnimatedFraction();
183 | final int direction = (int) (fromDirection + directionDiff * fraction);
184 | final int rotateDegree = (int) (fromDegree + (MAX_ROTATE_DEGREE - fromDegree) * fraction);
185 | mSphereLayout.rotate(direction, rotateDegree);
186 | mState.direction = direction;
187 | mState.rotateDegree = rotateDegree;
188 | }
189 | }
190 |
191 | /**
192 | * reference: http://inloop.github.io/interpolator/
193 | */
194 | private class SpringInterpolator implements Interpolator {
195 | public static final float factor = 0.4f;
196 |
197 | @Override
198 | public float getInterpolation(float input) {
199 |
200 | if (input >= 0.7) return 1;//避免振幅过小导致的卡顿感
201 |
202 | return (float) (Math.pow(2, -10 * input) * Math.sin((input - factor / 4) * (2 * Math.PI) / factor) + 1);
203 | }
204 | }
205 | }
206 |
--------------------------------------------------------------------------------
/lib/src/main/java/com/thunderpunch/spherelayoutlib/layout/SphereLayout.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.spherelayoutlib.layout;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Camera;
6 | import android.graphics.Canvas;
7 | import android.graphics.Matrix;
8 | import android.graphics.Point;
9 | import android.os.Parcel;
10 | import android.os.Parcelable;
11 | import android.util.AttributeSet;
12 | import android.util.TypedValue;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 |
16 |
17 | import com.thunderpunch.spherelayoutlib.R;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.Comparator;
22 | import java.util.List;
23 |
24 | /**
25 | * Created by thunderpunch on 2017/2/20
26 | */
27 |
28 | public class SphereLayout extends ViewGroup {
29 | public static final int HORIZONTAL = 0;
30 | public static final int VERTICAL = 1;
31 | private int mRadius;
32 | private Point mCenter;
33 | private Camera mCamera;
34 | private Matrix mMatrix;
35 | private float mDensity;
36 | private int mRotateDegree;
37 | private int mDirection;
38 | private float[] mValues = new float[9];
39 |
40 | private boolean mReverse;
41 | private boolean mHideBack;
42 | private ArrayList mPositiveChildren, mNegativeChildren;
43 | private int mOrientation;
44 |
45 | private OnRotateListener mRotateListener;
46 |
47 | /**
48 | * @see #rotateDependsOn(SphereLayout)
49 | */
50 | private SphereLayout mDependency;
51 | /**
52 | * 自身翻转中心到依赖视图的翻转中心的偏移量
53 | *
54 | * @see #rotateDependsOn(SphereLayout)
55 | */
56 | private int[] mDependencyOffset;
57 | private boolean mCheckedDependencyOffset;
58 |
59 | public SphereLayout(Context context) {
60 | this(context, null);
61 | }
62 |
63 |
64 | public SphereLayout(Context context, AttributeSet attrs) {
65 | this(context, attrs, 0);
66 | }
67 |
68 | public SphereLayout(Context context, AttributeSet attrs, int defStyleAttr) {
69 | super(context, attrs, defStyleAttr);
70 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SphereLayout);
71 | mRadius = a.getDimensionPixelSize(R.styleable.SphereLayout_radius, 0);//球体半径
72 | mOrientation = a.getInt(R.styleable.SphereLayout_snapOrientation, HORIZONTAL);//标记位于背面的视图是以Y轴水平翻转到达正面 或是以X轴竖直翻转可到达正面
73 | mHideBack = a.getBoolean(R.styleable.SphereLayout_hideBack, false);//是否隐藏处在背面的布局
74 | a.recycle();
75 | mCenter = new Point();
76 | mCamera = new Camera();
77 | mDependencyOffset = new int[2];
78 | //mCamera.setLocation(0, 0, -20);
79 | mMatrix = new Matrix();
80 | mPositiveChildren = new ArrayList<>();//depth为正的childview集合
81 | mNegativeChildren = new ArrayList<>();//depth为负的childview集合
82 | mDensity = getResources().getDisplayMetrics().density;
83 | }
84 |
85 | /**
86 | * @param hideBack 是否隐藏背面
87 | */
88 | public void hideBack(boolean hideBack) {
89 | if (mHideBack != hideBack) {
90 | mHideBack = hideBack;
91 | postInvalidate();
92 | }
93 | }
94 |
95 | /**
96 | * @param radius 球体半径
97 | */
98 | public void setRadius(int radius) {
99 | mRadius = radius;
100 | requestLayout();
101 | }
102 |
103 | public int getRadius() {
104 | return mRadius;
105 | }
106 |
107 | /**
108 | * @param isReverse 是否翻转
109 | */
110 | public void reverse(boolean isReverse) {
111 | if (isReverse != mReverse) {
112 | mReverse = isReverse;
113 | mRotateDegree = 0;
114 | invalidate();
115 | }
116 | }
117 |
118 | public boolean isReverse() {
119 | return mReverse;
120 | }
121 |
122 | public int getCenterX() {
123 | return mCenter.x;
124 | }
125 |
126 | public int getCenterY() {
127 | return mCenter.y;
128 | }
129 |
130 | /**
131 | * @param direction 翻转方向 (-180,180] 以布局中心为原点,向量与x轴正方向的夹角,顺加逆减
132 | * @param rotateDegree 翻转角度 (-180,180]
133 | */
134 | public void rotate(int direction, int rotateDegree) {
135 | mDirection = makeDirectionWithinRange(direction);
136 | mRotateDegree = makeRoatateDegreeWithinRange(rotateDegree);
137 | postInvalidate();
138 | if (mRotateListener != null) {
139 | mRotateListener.onRotate(direction, rotateDegree);
140 | }
141 | }
142 |
143 | /**
144 | * @param sphereLayout 翻转依赖
145 | */
146 |
147 | public void rotateDependsOn(SphereLayout sphereLayout) {
148 | mDependency = sphereLayout;
149 | mCheckedDependencyOffset = false;
150 | mDependency.mRotateListener = new OnRotateListener() {
151 | @Override
152 | public void onRotate(int direction, int degree) {
153 | rotate(direction, degree);
154 | }
155 | };
156 | }
157 |
158 | @Override
159 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
160 | if (mRadius == 0) {
161 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
162 | return;
163 | }
164 | if (MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY) {
165 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(mRadius << 1, MeasureSpec.EXACTLY);
166 | }
167 | if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
168 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(mRadius << 1, MeasureSpec.EXACTLY);
169 | }
170 | setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec)
171 | , MeasureSpec.getSize(heightMeasureSpec));
172 | final int count = getChildCount();
173 | for (int i = 0; i < count; i++) {
174 | final View child = getChildAt(i);
175 | if (child.getVisibility() != GONE) {
176 | LayoutParams lp = (LayoutParams) child.getLayoutParams();
177 | if (lp.fitBounds) {
178 | lp.depth = Math.max(Math.min(lp.depth, mRadius), -mRadius);
179 | lp.bottomMargin = lp.leftMargin = lp.rightMargin = lp.topMargin = 0;
180 | final int boundsSize = (int) Math.max(getMinimumBoundsSize(),
181 | 2 * Math.sqrt(mRadius * mRadius - lp.depth * lp.depth));
182 | child.measure(MeasureSpec.makeMeasureSpec(boundsSize, MeasureSpec.EXACTLY),
183 | MeasureSpec.makeMeasureSpec(boundsSize, MeasureSpec.EXACTLY));
184 | } else {
185 | measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
186 | }
187 | }
188 | }
189 | }
190 |
191 | @Override
192 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
193 | super.onSizeChanged(w, h, oldw, oldh);
194 | mCenter.x = w >> 1;
195 | mCenter.y = h >> 1;
196 | }
197 |
198 | @Override
199 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
200 | mPositiveChildren.clear();
201 | mNegativeChildren.clear();
202 | final int count = getChildCount();
203 | for (int i = 0; i < count; i++) {
204 | final View child = getChildAt(i);
205 | if (child.getVisibility() != GONE) {
206 | final LayoutParams lp = (LayoutParams) child.getLayoutParams();
207 | final int width = child.getMeasuredWidth();
208 | final int height = child.getMeasuredHeight();
209 | int childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
210 | int childTop = (b - t - height) / 2 + lp.topMargin - lp.bottomMargin;
211 | child.layout(childLeft, childTop, childLeft + width, childTop + height);
212 | if (lp.depth >= 0) {
213 | mPositiveChildren.add(child);
214 | } else {
215 | mNegativeChildren.add(child);
216 | }
217 | }
218 | }
219 | final Comparator comparator = new Comparator() {
220 | @Override
221 | public int compare(View o1, View o2) {
222 | Integer d0 = Math.abs(((LayoutParams) o1.getLayoutParams()).depth);
223 | Integer d1 = Math.abs(((LayoutParams) o2.getLayoutParams()).depth);
224 | return d0.compareTo(d1);
225 | }
226 | };
227 | //按照depth绝对值排列绘制顺序
228 | Collections.sort(mPositiveChildren, comparator);
229 | Collections.sort(mNegativeChildren, comparator);
230 | }
231 |
232 | @Override
233 | protected void dispatchDraw(Canvas canvas) {
234 | if (mRadius == 0) {
235 | super.dispatchDraw(canvas);
236 | return;
237 | }
238 | if (mDependency != null && !mCheckedDependencyOffset) {
239 | int[] location = new int[2];
240 | int[] dependencyLocation = new int[2];
241 | getLocationOnScreen(location);
242 | mDependency.getLocationOnScreen(dependencyLocation);
243 | mDependencyOffset[0] = dependencyLocation[0] + mDependency.getCenterX() -
244 | (location[0] + getCenterX());
245 | mDependencyOffset[1] = dependencyLocation[1] + mDependency.getCenterY() -
246 | (location[1] + getCenterY());
247 | mCheckedDependencyOffset = true;
248 | }
249 | if (!mReverse) {
250 | if (mRotateDegree > 90 || mRotateDegree <= -90) {
251 | drawChildren(canvas, mNegativeChildren, mPositiveChildren);
252 | } else {
253 | drawChildren(canvas, mPositiveChildren, mNegativeChildren);
254 | }
255 | } else {
256 | if (mRotateDegree >= 90 || mRotateDegree < -90) {
257 | drawChildren(canvas, mPositiveChildren, mNegativeChildren);
258 | } else {
259 | drawChildren(canvas, mNegativeChildren, mPositiveChildren);
260 | }
261 | }
262 | }
263 |
264 | private void drawChildren(Canvas canvas, List frontChildren, List backChildren) {
265 | if (!mHideBack) {
266 | final int c0 = backChildren.size();
267 | for (int i = c0 - 1; i >= 0; i--) {
268 | drawChild(canvas, backChildren.get(i));
269 | }
270 | }
271 | final int c1 = frontChildren.size();
272 | for (int i = 0; i < c1; i++) {
273 | drawChild(canvas, frontChildren.get(i));
274 | }
275 | }
276 |
277 | private void drawChild(Canvas canvas, View child) {
278 | final long drawingTime = getDrawingTime();
279 | final LayoutParams p = (LayoutParams) child.getLayoutParams();
280 | final int depth = mReverse ? -p.depth : p.depth;
281 | mCamera.save();
282 | mCamera.rotateY(mRotateDegree);
283 | mCamera.translate(0, 0, -depth);
284 | mCamera.getMatrix(mMatrix);
285 | mCamera.restore();
286 |
287 | //fix camera bug
288 | mMatrix.getValues(mValues);
289 | mValues[6] = mValues[6] / mDensity;
290 | mValues[7] = mValues[7] / mDensity;
291 |
292 | mMatrix.setValues(mValues);
293 | mMatrix.postRotate(mDirection, 0, 0);
294 | mMatrix.postTranslate(mCenter.x + mDependencyOffset[0], mCenter.y + mDependencyOffset[1]);
295 | mMatrix.preRotate(-mDirection, 0, 0);
296 | mMatrix.preTranslate(-mCenter.x - mDependencyOffset[0], -mCenter.y - mDependencyOffset[1]);
297 | if (depth < 0) {
298 | if (mOrientation == HORIZONTAL) {
299 | mMatrix.preScale(-1, 1, mCenter.x, mCenter.y);
300 | } else if (mOrientation == VERTICAL) {
301 | mMatrix.preScale(1, -1, mCenter.x, mCenter.y);
302 | }
303 | }
304 | canvas.save();
305 | canvas.concat(mMatrix);
306 | drawChild(canvas, child, drawingTime);
307 | canvas.restore();
308 | }
309 |
310 |
311 | public int makeRoatateDegreeWithinRange(int degree) {
312 | while (degree <= -180) {
313 | degree += 360;
314 | }
315 | while (degree > 180) {
316 | degree -= 360;
317 | }
318 | return degree;
319 | }
320 |
321 | public int makeDirectionWithinRange(int direction) {
322 | while (direction <= -180) {
323 | direction += 360;
324 | }
325 | while (direction > 180) {
326 | direction -= 360;
327 | }
328 | return direction;
329 | }
330 |
331 | /**
332 | * @return 当fitBounds为true时, 该childview的最小宽高
333 | */
334 | public int getMinimumBoundsSize() {
335 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
336 | getContext().getResources().getDisplayMetrics());
337 | }
338 |
339 | @Override
340 | protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
341 | return p instanceof LayoutParams;
342 | }
343 |
344 | @Override
345 | protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
346 | if (p instanceof LayoutParams) {
347 | return new LayoutParams((LayoutParams) p);
348 | } else if (p instanceof MarginLayoutParams) {
349 | return new LayoutParams((MarginLayoutParams) p);
350 | }
351 | return new LayoutParams(p);
352 | }
353 |
354 | @Override
355 | public LayoutParams generateLayoutParams(AttributeSet attrs) {
356 | return new LayoutParams(getContext(), attrs);
357 | }
358 |
359 | @Override
360 | protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
361 | return new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
362 | ViewGroup.LayoutParams.MATCH_PARENT);
363 | }
364 |
365 | public static class LayoutParams extends MarginLayoutParams {
366 | /**
367 | * 视图在z轴的位置
368 | * 该z轴以指向观察者的方向为正方向,与{@link Camera}的z轴方向相反
369 | * {@link SphereLayout}的直系子视图必须设置depth属性
370 | */
371 | public int depth;
372 | /**
373 | * 为true时,子视图会宽高适配当前所处{@link #depth}层级的圆的直径且无视自身margin属性
374 | */
375 | public boolean fitBounds;
376 |
377 |
378 | public LayoutParams(Context c, AttributeSet attrs) {
379 | super(c, attrs);
380 | TypedArray a =
381 | c.obtainStyledAttributes(attrs, R.styleable.SphereLayout_Layout);
382 | depth = a.getLayoutDimension(R.styleable.SphereLayout_Layout_layout_depth, "layout_depth");
383 | fitBounds = a.getBoolean(R.styleable.SphereLayout_Layout_layout_fitBounds, false);
384 | a.recycle();
385 | }
386 |
387 | public LayoutParams(int width, int height) {
388 | super(width, height);
389 | }
390 |
391 | public LayoutParams(LayoutParams p) {
392 | super(p);
393 | depth = p.depth;
394 | fitBounds = p.fitBounds;
395 | }
396 |
397 | public LayoutParams(MarginLayoutParams p) {
398 | super(p);
399 | }
400 |
401 | public LayoutParams(ViewGroup.LayoutParams p) {
402 | super(p);
403 | }
404 | }
405 |
406 | @Override
407 | public Parcelable onSaveInstanceState() {
408 | Parcelable superState = super.onSaveInstanceState();
409 | SphereSavedState ss = new SphereSavedState(superState);
410 | ss.radius = mRadius;
411 | ss.orientation = mOrientation;
412 | ss.hideBack = mHideBack;
413 | return ss;
414 | }
415 |
416 | @Override
417 | public void onRestoreInstanceState(Parcelable state) {
418 | SphereSavedState ss = (SphereSavedState) state;
419 | mRadius = ss.radius;
420 | mOrientation = ss.orientation;
421 | mHideBack = ss.hideBack;
422 | super.onRestoreInstanceState(ss.getSuperState());
423 | }
424 |
425 | static class SphereSavedState extends BaseSavedState {
426 | int radius;
427 | int orientation;
428 | boolean hideBack;
429 |
430 | SphereSavedState(Parcelable superState) {
431 | super(superState);
432 | }
433 |
434 | /**
435 | * Constructor called from {@link #CREATOR}
436 | */
437 | private SphereSavedState(Parcel in) {
438 | super(in);
439 | radius = in.readInt();
440 | orientation = in.readInt();
441 | hideBack = in.readInt() == 0 ? false : true;
442 | }
443 |
444 | @Override
445 | public void writeToParcel(Parcel out, int flags) {
446 | super.writeToParcel(out, flags);
447 | out.writeInt(radius);
448 | out.writeInt(orientation);
449 | out.writeInt(hideBack ? 1 : 0);
450 | }
451 |
452 | public static final Creator CREATOR
453 | = new Creator() {
454 | public SphereSavedState createFromParcel(Parcel in) {
455 | return new SphereSavedState(in);
456 | }
457 |
458 | public SphereSavedState[] newArray(int size) {
459 | return new SphereSavedState[size];
460 | }
461 | };
462 | }
463 |
464 | private interface OnRotateListener {
465 | void onRotate(int direction, int degree);
466 | }
467 | }
468 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/lib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SphereLayoutLib
3 |
4 |
--------------------------------------------------------------------------------
/lib/src/test/java/com/thunderpunch/spherelayoutlib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.thunderpunch.spherelayoutlib;
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 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':lib'
2 |
--------------------------------------------------------------------------------