├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── a.jpg
│ │ │ │ ├── b.jpg
│ │ │ │ ├── c.jpg
│ │ │ │ ├── d.jpg
│ │ │ │ └── e.jpg
│ │ │ ├── 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
│ │ │ └── layout
│ │ │ │ ├── demo.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── vp.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── bannerdot
│ │ │ ├── MainActivity.java
│ │ │ ├── DemoActivity.java
│ │ │ ├── VpActivity.java
│ │ │ └── BezierBannerDotDemo.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── bannerdot
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── bannerdot
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── dotlibrary
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── attr.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── dotlibrary
│ │ │ └── BezierBannerDot.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── dotlibrary
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── dotlibrary
│ │ └── ExampleInstrumentedTest.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── checkstyle-idea.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
├── misc.xml
└── markdown-navigator.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── screenshots
└── ezgif.com-resize (2).gif
├── .gitignore
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/dotlibrary/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':dotlibrary'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | bannerdot
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/dotlibrary/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DotLibrary
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/a.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/drawable-xxhdpi/a.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/b.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/drawable-xxhdpi/b.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/c.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/drawable-xxhdpi/c.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/d.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/drawable-xxhdpi/d.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/e.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/drawable-xxhdpi/e.jpg
--------------------------------------------------------------------------------
/screenshots/ezgif.com-resize (2).gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/screenshots/ezgif.com-resize (2).gif
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/yanyiqun001/bannerDot/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 22 17:53:51 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 |
--------------------------------------------------------------------------------
/.idea/checkstyle-idea.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/dotlibrary/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/dotlibrary/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/bannerdot/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bannerdot;
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 | }
--------------------------------------------------------------------------------
/dotlibrary/src/test/java/com/dotlibrary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dotlibrary;
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 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
14 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/bannerdot/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.bannerdot;
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.bannerdot", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/dotlibrary/src/androidTest/java/com/dotlibrary/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.dotlibrary;
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.dotlibrary.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/dotlibrary/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.yanyiqun001'
4 | android {
5 | compileSdkVersion 26
6 | buildToolsVersion "26.0.2"
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:26.+'
31 | testCompile 'junit:junit:4.12'
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
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 |
--------------------------------------------------------------------------------
/dotlibrary/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\Administrator\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
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/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.bannerdot"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
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 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.3.1'
28 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
29 | testCompile 'junit:junit:4.12'
30 | //compile project(':dotlibrary')
31 | compile 'com.github.yanyiqun001:bannerDot:1.0'
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bannerdot/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.bannerdot;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.Button;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 | Button button1;
11 | Button button2;
12 | @Override
13 | protected void onCreate(Bundle savedInstanceState) {
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_main);
16 | button1= (Button) findViewById(R.id.btn1);
17 | button2= (Button) findViewById(R.id.btn2);
18 | button1.setOnClickListener(new View.OnClickListener() {
19 | @Override
20 | public void onClick(View v) {
21 | startActivity(new Intent(MainActivity.this,VpActivity.class));
22 | }
23 | });
24 | button2.setOnClickListener(new View.OnClickListener() {
25 | @Override
26 | public void onClick(View v) {
27 | startActivity(new Intent(MainActivity.this,DemoActivity.class));
28 | }
29 | });
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # bannerDot
2 | 贝塞尔圆点指示器
3 |
4 | .gif?raw=true)
5 |
6 | ### Usage
7 |
8 | Add the JitPack repository to your build file
9 |
10 | ```
11 | allprojects {
12 | repositories {
13 | ...
14 | maven { url "https://jitpack.io" }
15 | }
16 | }
17 | ```
18 | Add the dependency
19 | ```
20 |
21 | dependencies{
22 | compile 'com.github.yanyiqun001:bannerDot:1.0'
23 | }
24 |
25 | ```
26 |
27 |
28 | ##### xml:
29 | ```
30 |
42 | ```
43 |
44 | selectedRaduis:起始圆半径
45 |
46 | unSelectedRaduis:背景圆半径
47 |
48 | selectedColor:起始圆颜色
49 |
50 | unSelectedColor:背景圆颜色
51 |
52 | spacing:间距
53 |
54 | ##### Attach to viewpager
55 | ```
56 | bezierBannerDot.attachToViewpager(viewPager)
57 | ```
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/vp.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
21 |
22 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bannerdot/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.bannerdot;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.MotionEvent;
7 | import android.view.View;
8 |
9 |
10 |
11 | /**
12 | * Created by Administrator on 2017/7/3 0003.
13 | */
14 |
15 | public class DemoActivity extends AppCompatActivity {
16 | BezierBannerDotDemo bd;
17 | float mStartX;
18 | int TOUCH_MOVE_MAX = 700;
19 | float progress;
20 | //向右滑 向左滚动
21 | public static int DIRECTION_LEFT = 1;
22 | //向左滑 向右滚动
23 | public static int DIRECTION_RIGHT = 2;
24 | @Override
25 | protected void onCreate(@Nullable Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.demo);
28 | bd = (BezierBannerDotDemo) this.findViewById(R.id.bd);
29 | findViewById(R.id.container).setOnTouchListener(new View.OnTouchListener() {
30 | @Override
31 | public boolean onTouch(View v, MotionEvent event) {
32 |
33 | switch (event.getActionMasked()) {
34 | case MotionEvent.ACTION_DOWN:
35 | mStartX = event.getX();
36 | return true;
37 | case MotionEvent.ACTION_MOVE:
38 | float x = event.getX();
39 | if (x - mStartX > 0) {
40 | progress = x - mStartX >= TOUCH_MOVE_MAX ? 1 : (x - mStartX) / (TOUCH_MOVE_MAX);
41 | bd.setDirection(DIRECTION_RIGHT);
42 | bd.setProgress(progress);
43 | } else if (x - mStartX < 0) {
44 | progress = mStartX - x >= TOUCH_MOVE_MAX ? 1 : (mStartX - x) / (TOUCH_MOVE_MAX);
45 | bd.setDirection(DIRECTION_LEFT);
46 | bd.setProgress(progress);
47 | }
48 | return true;
49 | case MotionEvent.ACTION_UP:
50 | if (progress >= 1.0f) {
51 | bd.resetProgress();
52 | return true;
53 | }
54 | return true;
55 | }
56 | return false;
57 | }
58 | });
59 | }
60 |
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bannerdot/VpActivity.java:
--------------------------------------------------------------------------------
1 | package com.bannerdot;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.view.PagerAdapter;
5 | import android.support.v4.view.ViewPager;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.ImageView;
10 |
11 | import com.dotlibrary.BezierBannerDot;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import static com.bannerdot.R.id.bd;
17 |
18 | /**
19 | * Created by Administrator on 2017/7/3 0003.
20 | */
21 |
22 | public class VpActivity extends AppCompatActivity {
23 | BezierBannerDot bezierBannerDot;
24 | private ViewPager viewPager;
25 | private MyPagerAdapter pagerAdapter;
26 | private int[] resource={R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d,R.drawable.e};
27 | private List viewlist=new ArrayList<>();
28 |
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.vp);
33 | viewPager = (ViewPager) this.findViewById(R.id.vp);
34 | bezierBannerDot = (BezierBannerDot) this.findViewById(bd);
35 | for (int i = 0; i < resource.length ; i++) {
36 | ImageView imageView=new ImageView(VpActivity.this);
37 | imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
38 | viewlist.add(imageView) ;
39 | }
40 | pagerAdapter=new MyPagerAdapter();
41 | viewPager.setAdapter(pagerAdapter);
42 | bezierBannerDot.attachToViewpager(viewPager);
43 | }
44 |
45 | private class MyPagerAdapter extends PagerAdapter {
46 | @Override
47 | public int getCount() {
48 | return resource.length;
49 | }
50 |
51 | @Override
52 | public boolean isViewFromObject(View view, Object object) {
53 | return view == object;
54 | }
55 |
56 | @Override
57 | public void destroyItem(ViewGroup container, int position, Object object) {
58 | container.removeView(viewlist.get(position));
59 | }
60 | @Override
61 | public Object instantiateItem(ViewGroup container, int position) {
62 | ImageView v = viewlist.get(position);
63 | v.setImageResource(resource[position]);
64 | container.addView(v);
65 | return v;
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | C:\Users\Administrator\AppData\Roaming\Subversion
48 |
49 |
50 |
51 |
52 |
53 | 1.8
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bannerdot/BezierBannerDotDemo.java:
--------------------------------------------------------------------------------
1 | package com.bannerdot;
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.Path;
8 | import android.support.annotation.Nullable;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 | import android.view.animation.AccelerateDecelerateInterpolator;
12 | import android.view.animation.Interpolator;
13 |
14 | /**
15 | * Created by Administrator on 2017/6/26 0026.
16 | */
17 |
18 | public class BezierBannerDotDemo extends View {
19 | private Paint mCirclePaint;
20 | private Paint mPointPaint;
21 | private Path mPath = new Path();
22 | private Path mPath2 = new Path();
23 | //间隔距离
24 | private float distance = 80;
25 | //起始圆初始半径
26 | private float mRadius = 50;
27 | //起始圆变化半径
28 | private float mChangeRadius;
29 | //辅助圆变化半径
30 | private float mSupportChangeRadius;
31 | //起始圆圆心左边
32 | float mCenterPointX;
33 | float mCenterPointY;
34 | //辅助圆圆心坐标
35 | float mSupportCircleX;
36 | float mSupportCircleY;
37 | //第一阶段运动进度
38 | private float mProgress = 0;
39 | //第二阶段运动进度
40 | private float mProgress2 = 0;
41 | //整体运动进度 也是原始进度
42 | private float mOriginProgress;
43 | //第一阶段运动
44 | private int MOVE_STEP_ONE=1;
45 | //第二阶段运动
46 | private int MOVE_STEP_TWO=2;
47 | float controlPointX;
48 | float controlPointY;
49 | float mStartX;
50 | float mStartY;
51 | float endPointX ;
52 | float endPointY;
53 | private int mDrection;
54 | //向右滑 向左滚动
55 | public static int DIRECTION_LEFT = 1;
56 | //向左滑 向右滚动
57 | public static int DIRECTION_RIGHT = 2;
58 |
59 | Interpolator accelerateinterpolator = new AccelerateDecelerateInterpolator();
60 |
61 |
62 | public BezierBannerDotDemo(Context context) {
63 | this(context, null);
64 | }
65 |
66 | public BezierBannerDotDemo(Context context, @Nullable AttributeSet attrs) {
67 | this(context, attrs, 0);
68 | }
69 |
70 | public BezierBannerDotDemo(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
71 | super(context, attrs, defStyleAttr);
72 | initPaint();
73 | moveToNext();
74 | }
75 |
76 | private void initPaint() {
77 | Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
78 | p.setColor(Color.RED);
79 | p.setStyle(Paint.Style.FILL);
80 | p.setAntiAlias(true);
81 | p.setDither(true);
82 | mCirclePaint = p;
83 |
84 |
85 | Paint p2 = new Paint(Paint.ANTI_ALIAS_FLAG);
86 | p2.setColor(0xFF000000);
87 | p2.setStyle(Paint.Style.FILL);
88 | p2.setAntiAlias(true);
89 | p2.setDither(true);
90 | mPointPaint = p2;
91 | }
92 |
93 | @Override
94 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
95 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
96 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
97 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
98 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
99 |
100 | int width = (int) (mRadius * 2 * 2 + distance + getPaddingLeft() + getPaddingRight());
101 | int height = (int) (2 * mRadius + getPaddingTop() + getPaddingBottom());
102 |
103 | int mHeight, mWidth;
104 |
105 | if (widthMode == MeasureSpec.EXACTLY) {
106 | mWidth = widthSize;
107 | } else if (widthMode == MeasureSpec.AT_MOST) {
108 | mWidth = Math.min(widthSize, width);
109 | } else {
110 | mWidth = widthSize;
111 | }
112 |
113 | if (heightMode == MeasureSpec.EXACTLY) {
114 | mHeight = heightSize;
115 | } else if (heightMode == MeasureSpec.AT_MOST) {
116 | mHeight = Math.min(heightSize, height);
117 | } else {
118 | mHeight = heightSize;
119 | }
120 |
121 | setMeasuredDimension(mWidth, mHeight);
122 |
123 | }
124 |
125 | @Override
126 | protected void onDraw(Canvas canvas) {
127 | super.onDraw(canvas);
128 | canvas.save();
129 | canvas.translate(getPaddingLeft(), getPaddingTop());
130 | canvas.drawCircle(mSupportCircleX, mSupportCircleY, mSupportChangeRadius, mCirclePaint);
131 | canvas.drawCircle(mCenterPointX, mCenterPointY, mChangeRadius, mCirclePaint);
132 | canvas.drawPath(mPath, mCirclePaint);
133 | //标出贝塞尔点
134 | canvas.drawCircle(controlPointX,controlPointY,5,mPointPaint);
135 | canvas.drawCircle(mStartX,mStartY,5,mPointPaint);
136 | canvas.drawCircle(endPointX,endPointY,5,mPointPaint);
137 | canvas.restore();
138 |
139 | }
140 |
141 | public void setProgress(float progress) {
142 | mOriginProgress=progress;
143 | if(progress<=0.5){
144 | mProgress = progress/0.5f;
145 | mProgress2=0;
146 | }else{
147 | mProgress2=(progress-0.5f)/0.5f;
148 | mProgress=1;
149 | }
150 | if(mDrection==DIRECTION_RIGHT) {
151 | moveToNext();
152 | }else{
153 | moveToPrivious();
154 | }
155 |
156 | invalidate();
157 | }
158 |
159 | /**
160 | * 向右移动
161 | */
162 | private void moveToNext() {
163 | mPath.reset();
164 | mPath2.reset();
165 | float mRadiusProgress = accelerateinterpolator.getInterpolation(mOriginProgress);
166 | //起始圆圆心
167 | mCenterPointX = getValue(getCenterPointAt(1),getCenterPointAt(2)-mRadius,MOVE_STEP_TWO);
168 | mCenterPointY = mRadius;
169 | //起始圆半径
170 | mChangeRadius = getValue(mRadius,0,mRadiusProgress);
171 | //起点与起始圆圆心间的角度
172 | double radian = Math.toRadians(getValue(45, 0,MOVE_STEP_ONE));
173 | //X轴距离圆心距离
174 | float mX = (float) (Math.sin(radian) * mChangeRadius);
175 | //Y轴距离圆心距离
176 | float mY = (float) (Math.cos(radian) * mChangeRadius);
177 |
178 | //辅助圆圆心
179 | mSupportCircleX = getValue(getCenterPointAt(1)+mRadius, getCenterPointAt(2),MOVE_STEP_ONE);
180 | mSupportCircleY = mRadius;
181 | //辅助圆半径
182 | mSupportChangeRadius = getValue(0, mRadius, mRadiusProgress);
183 | //终点与辅助圆圆心间的角度
184 | double supportradian = Math.toRadians(getValue(0, 45,MOVE_STEP_TWO));
185 | //X轴距离圆心距离
186 | float msupportradianX = (float) (Math.sin(supportradian) * mSupportChangeRadius);
187 | //Y轴距离圆心距离
188 | float msupportradianY = (float) (Math.cos(supportradian) * mSupportChangeRadius);
189 | //起点
190 | mStartX = mCenterPointX + mX;
191 | mStartY = mCenterPointY - mY;
192 |
193 | //终点
194 | endPointX = mSupportCircleX-msupportradianX;
195 | endPointY = mRadius - msupportradianY;
196 | //控制点
197 | controlPointX = getValueForAll(2 * mRadius, getCenterPointAt(2)-mRadius);
198 | controlPointY = mRadius;
199 | //移动至起点
200 | mPath.moveTo(mStartX, mStartY);
201 | //形成闭合区域
202 | mPath.quadTo(controlPointX, controlPointY, endPointX, endPointY);
203 | mPath.lineTo(endPointX, mRadius + msupportradianY);
204 | mPath.quadTo(controlPointX, mRadius , mStartX, mStartY + 2 * mY);
205 | mPath.lineTo(mStartX, mStartY);
206 |
207 | }
208 | /**
209 | * 向左移动(与向右过程大致相同)
210 | */
211 | private void moveToPrivious() {
212 | mPath.reset();
213 | mPath2.reset();
214 | float mRadiusProgress = accelerateinterpolator.getInterpolation(mOriginProgress);
215 | //起始圆
216 | mCenterPointX = getValue(getCenterPointAt(2),getCenterPointAt(1)+mRadius,MOVE_STEP_TWO);
217 | mCenterPointY = mRadius;
218 | mChangeRadius = getValue(mRadius,0,mRadiusProgress);
219 |
220 | double radian = Math.toRadians(getValue(45, 0,MOVE_STEP_ONE));
221 | float mX = (float) (Math.sin(radian) * mChangeRadius);
222 | float mY = (float) (Math.cos(radian) * mChangeRadius);
223 |
224 | //辅助圆
225 | mSupportCircleX = getValue(getCenterPointAt(2)-mRadius, getCenterPointAt(1),MOVE_STEP_ONE);
226 | mSupportCircleY = mRadius;
227 | mSupportChangeRadius = getValue(0, mRadius, mRadiusProgress);
228 |
229 | double supportradian = Math.toRadians(getValue(0, 45,MOVE_STEP_TWO));
230 | float msupportradianX = (float) (Math.sin(supportradian) * mSupportChangeRadius);
231 | float msupportradianY = (float) (Math.cos(supportradian) * mSupportChangeRadius);
232 |
233 | mStartX = mCenterPointX - mX;
234 | mStartY = mCenterPointY - mY;
235 |
236 | endPointX = mSupportCircleX+msupportradianX;
237 | endPointY = mRadius - msupportradianY;
238 |
239 | controlPointX = getValueForAll(getCenterPointAt(2)-mRadius, getCenterPointAt(1)+mRadius);
240 | controlPointY = mRadius;
241 |
242 | mPath.moveTo(mStartX, mStartY);
243 | mPath.quadTo(controlPointX, controlPointY, endPointX, endPointY);
244 | mPath.lineTo(endPointX, mRadius + msupportradianY);
245 | mPath.quadTo(controlPointX, mRadius , mStartX, mStartY + 2 * mY);
246 | mPath.lineTo(mStartX, mStartY);
247 | }
248 |
249 | /**
250 | * 获取当前值(适用分阶段变化的值)
251 | * @param start 初始值
252 | * @param end 终值
253 | * @param step 第几活动阶段
254 | * @return
255 | */
256 | public float getValue(float start, float end, int step) {
257 | if(step==MOVE_STEP_ONE) {
258 | return start + (end - start) * mProgress;
259 | }else{
260 |
261 | return start + (end - start) * mProgress2;
262 | }
263 | }
264 | /**
265 | * 获取当前值(适用全过程变化的值)
266 | * @param start 初始值
267 | * @param end 终值
268 | * @return
269 | */
270 | public float getValueForAll(float start, float end){
271 | return start + (end - start) * mOriginProgress;
272 | }
273 |
274 | /**
275 | * 通过进度获取当前值
276 | * @param start 初始值
277 | * @param end 终值
278 | * @param progress 当前进度
279 | * @return
280 | */
281 | public float getValue(float start, float end, float progress) {
282 | return start + (end - start) * progress;
283 | }
284 |
285 | /**
286 | * 获取圆心X坐标
287 | * @param index 第几个圆
288 | * @return
289 | */
290 | private float getCenterPointAt(int index) {
291 | if (index == 1) {
292 | return mRadius;
293 | }
294 | return mRadius*3+distance;
295 | }
296 | /**
297 | * 设置当前方向
298 | */
299 | public void setDirection(int direction) {
300 | mDrection = direction;
301 | }
302 | /**
303 | * 重置进度
304 | */
305 | public void resetProgress() {
306 | mProgress = 0;
307 | mProgress2 = 0;
308 | mOriginProgress = 0;
309 | }
310 | }
311 |
--------------------------------------------------------------------------------
/dotlibrary/src/main/java/com/dotlibrary/BezierBannerDot.java:
--------------------------------------------------------------------------------
1 | package com.dotlibrary;
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.support.v4.view.ViewPager;
10 | import android.util.AttributeSet;
11 | import android.util.Log;
12 | import android.view.View;
13 | import android.view.animation.AccelerateDecelerateInterpolator;
14 | import android.view.animation.Interpolator;
15 |
16 | /**
17 | * Created by Administrator on 2017/6/26 0026.
18 | */
19 |
20 | public class BezierBannerDot extends View implements ViewPager.OnPageChangeListener {
21 | //选中画笔
22 | private Paint mCirclePaint;
23 | //背景画笔
24 | private Paint mCirclePaint2;
25 | //选中路径
26 | private Path mPath = new Path();
27 | //背景路径
28 | private Path mPath2 = new Path();
29 | //选中颜色
30 | private int mSelectedColor;
31 | //未选中颜色
32 | private int mUnSelectedColor;
33 | //圆点之间距离
34 | private float distance = 80;
35 | //起始圆初始半径
36 | private float mRadius = 30;
37 | //起始圆变化半径
38 | private float mChangeRadius;
39 | //背景圆初始半径
40 | private float mNomarlRadius = 20;
41 | //背景圆变化半径 背景圆都用这个
42 | private float mChangeBgRadius;
43 | //起始圆辅助圆变化半径
44 | private float mSupportChangeRadius;
45 | //将要到达位置的背景圆的辅助圆变化半径
46 | private float mSupport_Next_ChangeRadius;
47 | //起始圆圆心坐标
48 | float mCenterPointX;
49 | float mCenterPointY;
50 | //起始圆辅助圆圆心坐标
51 | float mSupportCircleX;
52 | float mSupportCircleY;
53 | //当前背景圆圆心坐标
54 | float mSupport_next_centerX;
55 | float mSupport_next_centerY;
56 | //将要到达位置的背景圆圆心坐标
57 | float mbgNextPointX;
58 | float mbgNextPointY;
59 |
60 | //是否进入自动移动状态
61 | private boolean autoMove = false;
62 | //第一阶段运动进度
63 | private float mProgress = 0;
64 | //第二阶段运动进度
65 | private float mProgress2 = 0;
66 | //整体运动进度 也是原始进度
67 | private float mOriginProgress;
68 |
69 | //当前选中的位置
70 | private int mSelectedIndex = 0;
71 | private int count;
72 |
73 | //第一阶段运动
74 | private int MOVE_STEP_ONE = 1;
75 | //第二阶段运动
76 | private int MOVE_STEP_TWO = 2;
77 | //控制点坐标
78 | float controlPointX;
79 | float controlPointY;
80 | //起点坐标
81 | float mStartX;
82 | float mStartY;
83 | //终点坐标
84 | float endPointX;
85 | float endPointY;
86 | private int mDrection;
87 | //向右滑 向左滚动
88 | public static int DIRECTION_LEFT = 1;
89 | //向左滑 向右滚动
90 | public static int DIRECTION_RIGHT = 2;
91 | private static final String TAG="tag";
92 |
93 | Interpolator accelerateinterpolator = new AccelerateDecelerateInterpolator();
94 |
95 |
96 | public BezierBannerDot(Context context) {
97 | this(context, null);
98 | }
99 |
100 | public BezierBannerDot(Context context, @Nullable AttributeSet attrs) {
101 | this(context, attrs, 0);
102 | }
103 |
104 | public BezierBannerDot(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
105 | super(context, attrs, defStyleAttr);
106 | initattrs(attrs);
107 | initPaint();
108 | }
109 |
110 |
111 | private void initPaint() {
112 | Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
113 | p.setColor(mSelectedColor);
114 | p.setStyle(Paint.Style.FILL);
115 | p.setAntiAlias(true);
116 | p.setDither(true);
117 | mCirclePaint = p;
118 |
119 | Paint p1 = new Paint(Paint.ANTI_ALIAS_FLAG);
120 | p1.setColor(mUnSelectedColor);
121 | p1.setStyle(Paint.Style.FILL);
122 | p1.setAntiAlias(true);
123 | p1.setDither(true);
124 | mCirclePaint2 = p1;
125 |
126 | }
127 |
128 | private void initattrs(AttributeSet attrs) {
129 | TypedArray typedArray=getContext().obtainStyledAttributes(attrs,R.styleable.BezierBannerDot);
130 | mSelectedColor=typedArray.getColor(R.styleable.BezierBannerDot_selectedColor,0xFFFFFFFF);
131 | mUnSelectedColor=typedArray.getColor(R.styleable.BezierBannerDot_unSelectedColor,0xFFAAAAAA);
132 | mRadius=typedArray.getDimension(R.styleable.BezierBannerDot_selectedRaduis,mRadius);
133 | mNomarlRadius=typedArray.getDimension(R.styleable.BezierBannerDot_unSelectedRaduis,mNomarlRadius);
134 | distance=typedArray.getDimension(R.styleable.BezierBannerDot_spacing,distance);
135 | typedArray.recycle();
136 | }
137 |
138 | @Override
139 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
140 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
141 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
142 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
143 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
144 | //宽度等于所有圆点宽度+之间的间隔+padding;要留出当左右两个是大圆点的左右边距
145 | int width = (int) (mNomarlRadius * 2 * count + (mRadius - mNomarlRadius) * 2 + (count - 1) * distance + getPaddingLeft() + getPaddingRight());
146 | int height = (int) (2 * mRadius + getPaddingTop() + getPaddingBottom());
147 |
148 | int mHeight, mWidth;
149 |
150 | if (widthMode == MeasureSpec.EXACTLY) {
151 | mWidth = widthSize;
152 | } else if (widthMode == MeasureSpec.AT_MOST) {
153 | mWidth = Math.min(widthSize, width);
154 | } else {
155 | mWidth = widthSize;
156 | }
157 |
158 | if (heightMode == MeasureSpec.EXACTLY) {
159 | mHeight = heightSize;
160 | } else if (heightMode == MeasureSpec.AT_MOST) {
161 | mHeight = Math.min(heightSize, height);
162 | } else {
163 | mHeight = heightSize;
164 | }
165 |
166 | setMeasuredDimension(mWidth, mHeight);
167 |
168 | }
169 |
170 | @Override
171 | protected void onDraw(Canvas canvas) {
172 | super.onDraw(canvas);
173 |
174 | canvas.save();
175 | canvas.translate(getPaddingLeft(), getPaddingTop());
176 |
177 | //画暂不活动的背景圆
178 | for (int i = 0; i < count; i++) {
179 | if (mDrection == DIRECTION_RIGHT) {
180 | if (i == mSelectedIndex || i == mSelectedIndex + 1) {
181 | //活动的就不用画了
182 | } else {
183 | canvas.drawCircle(getCenterPointAt(i), mRadius, mNomarlRadius, mCirclePaint2);
184 | }
185 |
186 | } else if (mDrection == DIRECTION_LEFT) {
187 | if (i == mSelectedIndex || i == mSelectedIndex - 1) {
188 | //活动的就不用画了
189 | } else {
190 | canvas.drawCircle(getCenterPointAt(i), mRadius, mNomarlRadius, mCirclePaint2);
191 | }
192 | }
193 | }
194 |
195 | //画活动背景圆
196 | canvas.drawCircle(mSupport_next_centerX, mSupport_next_centerY, mSupport_Next_ChangeRadius, mCirclePaint2);
197 | canvas.drawCircle(mbgNextPointX, mbgNextPointY, mChangeBgRadius, mCirclePaint2);
198 | canvas.drawPath(mPath2, mCirclePaint2);
199 | //画选中圆
200 | canvas.drawCircle(mSupportCircleX, mSupportCircleY, mSupportChangeRadius, mCirclePaint);
201 | canvas.drawCircle(mCenterPointX, mCenterPointY, mChangeRadius, mCirclePaint);
202 | canvas.drawPath(mPath, mCirclePaint);
203 |
204 | canvas.restore();
205 |
206 | }
207 |
208 | /**
209 | * 转化整体进度值使两个阶段的运动进度都是0-1
210 | * @param progress 当前整体进度
211 | */
212 | public void setProgress(float progress) {
213 | //viewpager滑动完毕返回的0不需要,拦截掉
214 | if (progress == 0) {
215 | Log.d(TAG, "拦截");
216 | return;
217 | }
218 | mOriginProgress = progress;
219 | if (progress <= 0.5) {
220 | mProgress = progress / 0.5f;
221 | mProgress2 = 0;
222 | } else {
223 | mProgress2 = (progress - 0.5f) / 0.5f;
224 | mProgress = 1;
225 |
226 | }
227 | if (mDrection == DIRECTION_RIGHT) {
228 | moveToNext();
229 | } else {
230 | moveToPrivous();
231 | }
232 | invalidate();
233 | Log.d(TAG, "刷新");
234 |
235 |
236 | }
237 |
238 | /**
239 | * 向右移动
240 | */
241 | private void moveToNext() {
242 | //重置路径
243 | mPath.reset();
244 | mPath2.reset();
245 | //使用一个插值器使圆的大小变化两边慢中间快
246 | float mRadiusProgress = accelerateinterpolator.getInterpolation(mOriginProgress);
247 | //----------------------选中圆--------------------------------
248 | //起始圆圆心
249 | mCenterPointX = getValue(getCenterPointAt(mSelectedIndex), getCenterPointAt(mSelectedIndex + 1) - mRadius, MOVE_STEP_TWO);
250 | mCenterPointY = mRadius;
251 | //起始圆半径
252 | mChangeRadius = getValue(mRadius, 0, mRadiusProgress);
253 |
254 | //起点与起始圆圆心间的角度
255 | double radian = Math.toRadians(getValue(45, 0, MOVE_STEP_ONE));
256 | //X轴距离圆心距离
257 | float mX = (float) (Math.sin(radian) * mChangeRadius);
258 | //Y轴距离圆心距离
259 | float mY = (float) (Math.cos(radian) * mChangeRadius);
260 |
261 | //辅助圆
262 | mSupportCircleX = getValue(getCenterPointAt(mSelectedIndex) + mRadius, getCenterPointAt(mSelectedIndex + 1), MOVE_STEP_ONE);
263 | mSupportCircleY = mRadius;
264 | mSupportChangeRadius = getValue(0, mRadius, mRadiusProgress);
265 |
266 | //终点与辅助圆圆心间的角度
267 | double supportradian = Math.toRadians(getValue(0, 45, MOVE_STEP_TWO));
268 | //X轴距离圆心距离
269 | float msupportradianX = (float) (Math.sin(supportradian) * mSupportChangeRadius);
270 | //Y轴距离圆心距离
271 | float msupportradianY = (float) (Math.cos(supportradian) * mSupportChangeRadius);
272 |
273 | //起点
274 | mStartX = mCenterPointX + mX;
275 | mStartY = mCenterPointY - mY;
276 |
277 | //终点
278 | endPointX = mSupportCircleX - msupportradianX;
279 | endPointY = mRadius - msupportradianY;
280 |
281 | //控制点
282 | controlPointX = getValueForAll(getCenterPointAt(mSelectedIndex) + mRadius, getCenterPointAt(mSelectedIndex + 1) - mRadius);
283 | controlPointY = mRadius;
284 |
285 | //移动到起点
286 | mPath.moveTo(mStartX, mStartY);
287 |
288 | //形成闭合区域
289 | mPath.quadTo(controlPointX, controlPointY, endPointX, endPointY);
290 | mPath.lineTo(endPointX, mRadius + msupportradianY);
291 | mPath.quadTo(controlPointX, mRadius, mStartX, mStartY + 2 * mY);
292 | mPath.lineTo(mStartX, mStartY);
293 |
294 | //----------------------背景圆反方向移动--------------------------------
295 | //起始圆圆心
296 | mbgNextPointX = getValue(getCenterPointAt(mSelectedIndex + 1), getCenterPointAt(mSelectedIndex) + mNomarlRadius, MOVE_STEP_TWO);
297 | mbgNextPointY = mRadius;
298 | //起始圆半径
299 | mChangeBgRadius = getValue(mNomarlRadius, 0, mRadiusProgress);
300 |
301 | //起点与起始圆圆心间的角度
302 | double m_Next_radian = Math.toRadians(getValue(45, 0, MOVE_STEP_ONE));
303 | float mX_next = (float) (Math.sin(m_Next_radian) * mChangeBgRadius);
304 | float mY_next = (float) (Math.cos(m_Next_radian) * mChangeBgRadius);
305 | //辅助圆圆心
306 | mSupport_next_centerX = getValue(getCenterPointAt(mSelectedIndex + 1) - mNomarlRadius, getCenterPointAt(mSelectedIndex), MOVE_STEP_ONE);
307 | mSupport_next_centerY = mRadius;
308 | //辅助圆半径
309 | mSupport_Next_ChangeRadius = getValue(0, mNomarlRadius, mRadiusProgress);
310 |
311 | //终点与辅助圆圆心间的角度
312 | double mSupport_Next_radian = Math.toRadians(getValue(0, 45, MOVE_STEP_TWO));
313 | float mSupport_Next_radianX = (float) (Math.sin(mSupport_Next_radian) * mSupport_Next_ChangeRadius);
314 | float mSupport_Next_radianY = (float) (Math.cos(mSupport_Next_radian) * mSupport_Next_ChangeRadius);
315 |
316 | //起点
317 | float startPoint_support_nextX = mbgNextPointX - mX_next;
318 | float startPoint_support_nextY = mbgNextPointY - mY_next;
319 |
320 | //终点
321 | float endPoint_support_nextX = mSupport_next_centerX + mSupport_Next_radianX;
322 | float endPoint_support_nextY = mSupport_next_centerY - mSupport_Next_radianY;
323 |
324 | //控制点
325 | float controlPointX_Next = getValueForAll(getCenterPointAt(mSelectedIndex + 1) - mNomarlRadius, getCenterPointAt(mSelectedIndex) + mNomarlRadius);
326 | float controlPointY_Next = mRadius;
327 |
328 | //移动到起点
329 | mPath2.moveTo(startPoint_support_nextX, startPoint_support_nextY);
330 | //形成闭合区域
331 | mPath2.quadTo(controlPointX_Next, controlPointY_Next, endPoint_support_nextX, endPoint_support_nextY);
332 | mPath2.lineTo(endPoint_support_nextX, mRadius + mSupport_Next_radianY);
333 | mPath2.quadTo(controlPointX_Next, controlPointY_Next, startPoint_support_nextX, startPoint_support_nextY + 2 * mY_next);
334 | mPath2.lineTo(startPoint_support_nextX, startPoint_support_nextY);
335 |
336 | }
337 |
338 |
339 | /**
340 | * 向左移动(与向右过程大致相同)
341 | */
342 | private void moveToPrivous() {
343 | mPath.reset();
344 | mPath2.reset();
345 |
346 | float mRadiusProgress = accelerateinterpolator.getInterpolation(mOriginProgress);
347 |
348 | //----------------------选中圆--------------------------------
349 | mCenterPointX = getValue(getCenterPointAt(mSelectedIndex), getCenterPointAt(mSelectedIndex - 1) + mRadius, MOVE_STEP_TWO);
350 | mCenterPointY = mRadius;
351 | mChangeRadius = getValue(mRadius, 0, mRadiusProgress);
352 | //起点与起始圆圆心间的角度
353 | double radian = Math.toRadians(getValue(45, 0, MOVE_STEP_ONE));
354 | //X轴距离圆心距离
355 | float mX = (float) (Math.sin(radian) * mChangeRadius);
356 | //Y轴距离圆心距离
357 | float mY = (float) (Math.cos(radian) * mChangeRadius);
358 |
359 | //辅助圆
360 | mSupportCircleX = getValue(getCenterPointAt(mSelectedIndex) - mRadius, getCenterPointAt(mSelectedIndex - 1), MOVE_STEP_ONE);
361 | mSupportCircleY = mRadius;
362 | mSupportChangeRadius = getValue(0, mRadius, mRadiusProgress);
363 |
364 |
365 | //终点与辅助圆圆心间的角度
366 | double supportradian = Math.toRadians(getValue(0, 45, MOVE_STEP_TWO));
367 | //X轴距离圆心距离
368 | float msupportradianX = (float) (Math.sin(supportradian) * mSupportChangeRadius);
369 | //Y轴距离圆心距离
370 | float msupportradianY = (float) (Math.cos(supportradian) * mSupportChangeRadius);
371 |
372 | mStartX = mCenterPointX - mX;
373 | mStartY = mCenterPointY - mY;
374 |
375 | endPointX = mSupportCircleX + msupportradianX;
376 | endPointY = mRadius - msupportradianY;
377 |
378 | controlPointX = getValueForAll(getCenterPointAt(mSelectedIndex) - mRadius, getCenterPointAt(mSelectedIndex - 1) + mRadius);
379 | controlPointY = mRadius;
380 |
381 | mPath.moveTo(mStartX, mStartY);
382 | mPath.quadTo(controlPointX, controlPointY, endPointX, endPointY);
383 | mPath.lineTo(endPointX, mRadius + msupportradianY);
384 | mPath.quadTo(controlPointX, mRadius, mStartX, mStartY + 2 * mY);
385 | mPath.lineTo(mStartX, mStartY);
386 |
387 |
388 | //----------------------背景圆反方向移动--------------------------------
389 | mbgNextPointX = getValue(getCenterPointAt(mSelectedIndex - 1), getCenterPointAt(mSelectedIndex) - mNomarlRadius, MOVE_STEP_TWO);
390 | mbgNextPointY = mRadius;
391 | mChangeBgRadius = getValue(mNomarlRadius, 0, mRadiusProgress);
392 | //起点与起始圆圆心间的角度
393 | double m_Next_radian = Math.toRadians(getValue(45, 0, MOVE_STEP_ONE));
394 | //X轴距离圆心距离
395 | float mX_next = (float) (Math.sin(m_Next_radian) * mChangeBgRadius);
396 | //Y轴距离圆心距离
397 | float mY_next = (float) (Math.cos(m_Next_radian) * mChangeBgRadius);
398 |
399 | mSupport_next_centerX = getValue(getCenterPointAt(mSelectedIndex - 1) + mNomarlRadius, getCenterPointAt(mSelectedIndex), MOVE_STEP_ONE);
400 | mSupport_next_centerY = mRadius;
401 | mSupport_Next_ChangeRadius = getValue(0, mNomarlRadius, mRadiusProgress);
402 |
403 | //终点与辅助圆圆心间的角度
404 | double mSupport_Next_radian = Math.toRadians(getValue(0, 45, MOVE_STEP_TWO));
405 | //X轴距离圆心距离
406 | float mSupport_Next_radianX = (float) (Math.sin(mSupport_Next_radian) * mSupport_Next_ChangeRadius);
407 | //Y轴距离圆心距离
408 | float mSupport_Next_radianY = (float) (Math.cos(mSupport_Next_radian) * mSupport_Next_ChangeRadius);
409 |
410 | float startPoint_support_nextX = mbgNextPointX + mX_next;
411 | float startPoint_support_nextY = mbgNextPointY - mY_next;
412 |
413 | float endPoint_support_nextX = mSupport_next_centerX - mSupport_Next_radianX;
414 | float endPoint_support_nextY = mSupport_next_centerY - mSupport_Next_radianY;
415 |
416 | float controlPointX_Next = getValueForAll(getCenterPointAt(mSelectedIndex - 1) + mNomarlRadius, getCenterPointAt(mSelectedIndex) - mNomarlRadius);
417 | float controlPointY_Next = mRadius;
418 |
419 | mPath2.moveTo(startPoint_support_nextX, startPoint_support_nextY);
420 | mPath2.quadTo(controlPointX_Next, controlPointY_Next, endPoint_support_nextX, endPoint_support_nextY);
421 | mPath2.lineTo(endPoint_support_nextX, mRadius + mSupport_Next_radianY);
422 | mPath2.quadTo(controlPointX_Next, controlPointY_Next, startPoint_support_nextX, startPoint_support_nextY + 2 * mY_next);
423 | mPath2.lineTo(startPoint_support_nextX, startPoint_support_nextY);
424 |
425 | }
426 |
427 |
428 | /**
429 | * 获取当前值(适用分阶段变化的值)
430 | * @param start 初始值
431 | * @param end 终值
432 | * @param step 第几活动阶段
433 | * @return
434 | */
435 | public float getValue(float start, float end, int step) {
436 | if (step == MOVE_STEP_ONE) {
437 | return start + (end - start) * mProgress;
438 | } else {
439 | return start + (end - start) * mProgress2;
440 | }
441 | }
442 | /**
443 | * 获取当前值(适用全过程变化的值)
444 | * @param start 初始值
445 | * @param end 终值
446 | * @return
447 | */
448 | public float getValueForAll(float start, float end) {
449 | return start + (end - start) * mOriginProgress;
450 | }
451 |
452 | /**
453 | * 通过进度获取当前值
454 | * @param start 初始值
455 | * @param end 终值
456 | * @param progress 当前进度
457 | * @return
458 | */
459 | public float getValue(float start, float end, float progress) {
460 | return start + (end - start) * progress;
461 | }
462 |
463 | /**
464 | * 获取圆心X坐标
465 | * @param index 第几个圆
466 | * @return
467 | */
468 | private float getCenterPointAt(int index) {
469 | if (index == 0) {
470 | return mRadius;
471 | }
472 | return index * (distance + 2 * mNomarlRadius) + mNomarlRadius + (mRadius - mNomarlRadius);
473 | }
474 |
475 |
476 | public void setDirection(int direction) {
477 | mDrection = direction;
478 | }
479 |
480 | /**
481 | * 重置进度
482 | */
483 | public void resetProgress() {
484 | mProgress = 0;
485 | mProgress2 = 0;
486 | mOriginProgress = 0;
487 | }
488 |
489 | /**
490 | * 绑定viewpager
491 | */
492 | public void attachToViewpager(ViewPager viewPager) {
493 | viewPager.addOnPageChangeListener(this);
494 | count = viewPager.getAdapter().getCount();
495 | moveToNext();
496 | mDrection=DIRECTION_RIGHT;
497 | invalidate();
498 | }
499 |
500 |
501 | @Override
502 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
503 | //偏移量为0 说明运动停止
504 | if (positionOffset == 0) {
505 | mSelectedIndex = position;
506 | Log.d("tag", "到达");
507 | resetProgress();
508 | }
509 | //向左滑,指示器向右移动
510 | if (position + positionOffset - mSelectedIndex > 0) {
511 | mDrection = DIRECTION_RIGHT;
512 | //向左快速滑动 偏移量不归0 但是position发生了改变 需要更新当前索引
513 | if (mDrection == DIRECTION_RIGHT && position + positionOffset > mSelectedIndex + 1) {
514 | mSelectedIndex = position;
515 | Log.d(TAG, "向左快速滑动");
516 | } else {
517 | setProgress(positionOffset);
518 | }
519 | } else if (position + positionOffset - mSelectedIndex < 0) { //向右滑,指示器向左移动
520 | mDrection = DIRECTION_LEFT;
521 | //向右快速滑动
522 | if (mDrection == DIRECTION_LEFT && position + positionOffset < mSelectedIndex - 1) {
523 | mSelectedIndex = position;
524 | Log.d(TAG, "向右快速滑动");
525 | } else {
526 | setProgress(1 - positionOffset);
527 | }
528 | }
529 |
530 | }
531 |
532 | @Override
533 | public void onPageSelected(int position) {
534 |
535 | }
536 |
537 | @Override
538 | public void onPageScrollStateChanged(int state) {
539 |
540 | }
541 |
542 | }
543 |
--------------------------------------------------------------------------------