├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.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
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── net
│ │ │ │ └── vrgsoft
│ │ │ │ └── slider
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── net
│ │ │ └── vrgsoft
│ │ │ └── slider
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── net
│ │ └── vrgsoft
│ │ └── slider
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── attrs.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── net
│ │ │ └── vrgsoft
│ │ │ └── library
│ │ │ ├── SliderBgLine.java
│ │ │ ├── SliderPoint.java
│ │ │ └── Slider.java
│ ├── test
│ │ └── java
│ │ │ └── net
│ │ │ └── vrgsoft
│ │ │ └── library
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── net
│ │ └── vrgsoft
│ │ └── library
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── video.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── caches
│ └── build_file_checksums.ser
├── vcs.xml
├── runConfigurations.xml
├── gradle.xml
├── modules.xml
├── codeStyles
│ └── Project.xml
└── misc.xml
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------
/video.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/video.gif
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Slider
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/caches/build_file_checksums.ser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/.idea/caches/build_file_checksums.ser
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/VRGsoftUA/Slider-indicator/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/VRGsoftUA/Slider-indicator/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/VRGsoftUA/Slider-indicator/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/VRGsoftUA/Slider-indicator/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/VRGsoftUA/Slider-indicator/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/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 50dp
4 | 12.5dp
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat May 12 14:39:46 EEST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #f76d74
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffffff
4 | #ffffff
5 | #7aba2e
6 | #ffffff
7 | #4dffffff
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/net/vrgsoft/slider/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.slider;
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 | }
--------------------------------------------------------------------------------
/library/src/test/java/net/vrgsoft/library/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.library;
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/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/net/vrgsoft/slider/MainActivity.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.slider;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 |
7 | public class MainActivity extends AppCompatActivity {
8 | private static final String LOG_TAG = MainActivity.class.getSimpleName();
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | }
15 |
16 | public void onPointClick(int position){
17 | Log.d(LOG_TAG, String.valueOf(position));
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/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=-Xmx2048m
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/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/net/vrgsoft/slider/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.slider;
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 | * Instrumented 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("net.vrgsoft.slider", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/net/vrgsoft/library/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.library;
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 | * Instrumented 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("net.vrgsoft.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 |
6 |
7 |
8 | defaultConfig {
9 | minSdkVersion 16
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 |
29 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
30 | implementation 'com.android.support:appcompat-v7:27.1.1'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
33 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
34 | }
35 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "net.vrgsoft.slider"
7 | minSdkVersion 16
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.0'
25 | implementation project(":library")
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation ('com.android.support.test:runner:1.0.2')
28 | androidTestImplementation ('com.android.support.test.espresso:espresso-core:3.0.2')
29 | }
30 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/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 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #### [HIRE US](http://vrgsoft.net/)
2 |
3 | # SliderIndicator
4 | Custom view for view pager with customization
5 |
6 |
7 |
8 | # Usage
9 |
10 | *For a working implementation, Have a look at the Sample Project - app*
11 |
12 | 1. Include the library as local library project.
13 | ```gradle
14 | allprojects {
15 | repositories {
16 | maven { url 'https://jitpack.io' }
17 | }
18 | }
19 |
20 | dependencies {
21 | compile 'com.github.VRGsoftUA:Slider-indicator:1.0'
22 | }
23 | ```
24 | 2. Include Slider class in your xml layout. For Example:
25 | ```
26 |
43 | ```
44 |
45 | # Customization
46 | | Attribute | Description |
47 | | ------------- | ------------- |
48 | | app:lineOuterColor | Direction line outer color |
49 | | app:lineInnerColor | Direction line inner color |
50 | | app:pointPulseColor | Point pulse color |
51 | | app:pointInnerColor | Point inner circle color |
52 | | app:pointOuterColor | Point outer circle color |
53 | | app:pointsCount | The number of points to be drawn (from 2 to 8) |
54 | | app:animationDuration | Duration for all animations |
55 | | app:pointSize | The size of one point |
56 | | app:lineStrokeWidth | Direction line width |
57 | | app:onPointClick | Convinience attribute for receiving callbacks to activity or data binding |
58 | | android:orientation | Sets the orientation of the view |
59 |
60 | | Method | Description |
61 | | ------------- | ------------- |
62 | | setPointSize(int pointSize) | Sets the size of one point |
63 | | setLineStrokeWidth(int lineStrokeWidth) | Sets the line stroke width of one point |
64 | | setOrientation(int orientation) | Sets the orientation of the view |
65 | | setDuration(long duration) | Sets the aniamtion duration |
66 | | setOuterLineColor(int outerLineColor) | Sets the outer line color |
67 | | setInnerLineColor(int innerLineColor) | Sets the inner line color |
68 | | setPointPulseColor(int pulseColor) | Sets the point pulse circle color |
69 | | setPointOuterColor(int pulseColor) | Sets the point outer circle color |
70 | | setPointInnerColor(int innerColor) | Sets the point inner circle color |
71 |
72 | #### Contributing
73 | * Contributions are always welcome
74 | * If you want a feature and can code, feel free to fork and add the change yourself and make a pull request
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
27 |
28 |
44 |
45 |
61 |
62 |
78 |
79 |
--------------------------------------------------------------------------------
/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/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/library/src/main/java/net/vrgsoft/library/SliderBgLine.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.library;
2 |
3 | import android.animation.ValueAnimator;
4 | import android.annotation.SuppressLint;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.graphics.Canvas;
8 | import android.graphics.Paint;
9 | import android.support.annotation.ColorInt;
10 | import android.support.annotation.IntRange;
11 | import android.support.annotation.Nullable;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 | import android.view.animation.LinearInterpolator;
15 | import android.widget.LinearLayout;
16 |
17 | import static net.vrgsoft.library.Slider.DEFAULT_ANIMATION_DURATION;
18 |
19 |
20 | class SliderBgLine extends View {
21 | private Paint paint;
22 | private int outerLineColor;
23 | private int innerLineColor;
24 | private long duration;
25 | private float directionLineWidth;
26 | private float innerLineWidth;
27 | private float outerLineWidth;
28 | private float[] positions;
29 | private int pointsCount;
30 | private float currentPosition;
31 | private ValueAnimator animator;
32 | private int mOrientation;
33 |
34 | public SliderBgLine(Context context) {
35 | this(context, null);
36 | }
37 |
38 | public SliderBgLine(Context context, @Nullable AttributeSet attrs) {
39 | this(context, attrs, 0);
40 | }
41 |
42 | public SliderBgLine(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
43 | super(context, attrs, defStyleAttr);
44 | init(context, attrs);
45 | }
46 |
47 | private void init(Context context, AttributeSet attrs) {
48 | initDefaultValues(context);
49 | initAttrs(context, attrs);
50 | }
51 |
52 | private void initDefaultValues(Context context) {
53 | paint = new Paint();
54 | paint.setAntiAlias(true);
55 | paint.setStyle(Paint.Style.STROKE);
56 | duration = DEFAULT_ANIMATION_DURATION;
57 | mOrientation = LinearLayout.HORIZONTAL;
58 |
59 | outerLineColor = context.getResources().getColor(R.color.defaultOuterLineColor);
60 | innerLineColor = context.getResources().getColor(R.color.defaultInnerLineColor);
61 | }
62 |
63 | @SuppressLint("CustomViewStyleable")
64 | private void initAttrs(Context context, AttributeSet attrs) {
65 | if (attrs != null) {
66 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider);
67 |
68 | outerLineColor = a.getColor(R.styleable.Slider_lineOuterColor, outerLineColor);
69 | innerLineColor = a.getColor(R.styleable.Slider_lineInnerColor, outerLineColor);
70 | mOrientation = a.getInt(R.styleable.Slider_android_orientation, mOrientation);
71 | duration = a.getInt(R.styleable.Slider_animationDuration, (int) duration);
72 |
73 | a.recycle();
74 | }
75 | }
76 |
77 | @Override
78 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
79 | int pointGap;
80 | if (mOrientation == LinearLayout.HORIZONTAL) {
81 | directionLineWidth = h * 0.187f;
82 | innerLineWidth = h * 0.35f;
83 | outerLineWidth = h;
84 | pointGap = w / (pointsCount - 1);
85 | } else {
86 | directionLineWidth = w * 0.187f;
87 | innerLineWidth = w * 0.35f;
88 | outerLineWidth = w;
89 | pointGap = h / (pointsCount - 1);
90 | }
91 |
92 | positions = new float[pointsCount];
93 | for (int i = 0; i < pointsCount; ++i) {
94 | positions[i] = pointGap * i;
95 | }
96 | }
97 |
98 | @Override
99 | protected void onDraw(Canvas canvas) {
100 | paint.setColor(innerLineColor);
101 | paint.setStrokeWidth(directionLineWidth);
102 | if (mOrientation == LinearLayout.HORIZONTAL) {
103 | canvas.drawLine(0, getHeight() * 0.5f, getWidth(), getHeight() * 0.5f, paint);
104 | } else {
105 | canvas.drawLine(getWidth() * 0.5f, 0, getWidth() * 0.5f, getHeight(), paint);
106 | }
107 |
108 |
109 | paint.setColor(outerLineColor);
110 | paint.setStrokeWidth(outerLineWidth);
111 | if (mOrientation == LinearLayout.HORIZONTAL) {
112 | canvas.drawLine(0, getHeight() * 0.5f, currentPosition, getHeight() * 0.5f, paint);
113 | } else {
114 | canvas.drawLine(getWidth() * 0.5f, 0, getWidth() * 0.5f, currentPosition, paint);
115 | }
116 |
117 | paint.setColor(innerLineColor);
118 | paint.setStrokeWidth(innerLineWidth);
119 | if (mOrientation == LinearLayout.HORIZONTAL) {
120 | canvas.drawLine(0, getHeight() * 0.5f, currentPosition, getHeight() * 0.5f, paint);
121 | } else {
122 | canvas.drawLine(getWidth() * 0.5f, 0, getWidth() * 0.5f, currentPosition, paint);
123 | }
124 | }
125 |
126 | void setPointsCount(int pointsCount) {
127 | this.pointsCount = pointsCount;
128 | }
129 |
130 | void startAnimation(int position) {
131 | if (animator != null && animator.isRunning()) {
132 | animator.cancel();
133 | }
134 | animator = ValueAnimator.ofFloat(currentPosition, positions[position]);
135 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
136 | @Override
137 | public void onAnimationUpdate(ValueAnimator animation) {
138 | currentPosition = (Float) animation.getAnimatedValue();
139 | SliderBgLine.this.invalidate();
140 | }
141 | });
142 | animator.setInterpolator(new LinearInterpolator());
143 | animator.setDuration(duration);
144 | animator.start();
145 | }
146 |
147 | /**
148 | * @param outerLineColor color to be set
149 | */
150 | public void setOuterLineColor(@ColorInt int outerLineColor) {
151 | this.outerLineColor = outerLineColor;
152 | invalidate();
153 | }
154 |
155 | /**
156 | * @param innerLineColor color to be set
157 | */
158 | public void setInnerLineColor(@ColorInt int innerLineColor) {
159 | this.innerLineColor = innerLineColor;
160 | invalidate();
161 | }
162 |
163 | /**
164 | * @param duration duration to be set
165 | */
166 | public void setDuration(long duration) {
167 | this.duration = duration;
168 | }
169 |
170 | /**
171 | * @param orientation orientation to be set
172 | */
173 | public void setOrientation(@IntRange(from = LinearLayout.HORIZONTAL, to = LinearLayout.VERTICAL) int orientation) {
174 | mOrientation = orientation;
175 | }
176 | }
177 |
--------------------------------------------------------------------------------
/library/src/main/java/net/vrgsoft/library/SliderPoint.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.library;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.ValueAnimator;
6 | import android.annotation.SuppressLint;
7 | import android.content.Context;
8 | import android.content.res.TypedArray;
9 | import android.graphics.Canvas;
10 | import android.graphics.Paint;
11 | import android.support.annotation.Nullable;
12 | import android.util.AttributeSet;
13 | import android.view.View;
14 | import android.view.animation.AccelerateInterpolator;
15 | import android.view.animation.DecelerateInterpolator;
16 | import android.view.animation.LinearInterpolator;
17 |
18 | import static net.vrgsoft.library.Slider.DEFAULT_ANIMATION_DURATION;
19 |
20 | class SliderPoint extends View {
21 | private static final int PULSE_INITIAL_ALPHA = 0x80;
22 | private static final int PULSE_INITIAL_RADIUS = 0;
23 |
24 | private Paint paint;
25 |
26 | private float endPulseRadius;
27 | private float endOuterRadius;
28 | private float endInnerRadius;
29 | private float startPulseRadius;
30 | private float startOuterRadius;
31 | private float startInnerRadius;
32 | private float middleInnerRadius;
33 |
34 | private float currentPulseRadius;
35 | private float currentOuterRadius;
36 | private float currentInnerRadius;
37 |
38 | private int centerX;
39 | private int centerY;
40 |
41 | private int pulseColor;
42 | private int outerColor;
43 | private int innerColor;
44 |
45 | private int pulseAlpha;
46 |
47 | private ValueAnimator mainAnimator;
48 | private ValueAnimator innerCircleSecondHalfAnimator;
49 | private ValueAnimator innerCircleFirstHalfAnimator;
50 | private ValueAnimator transitAnimator;
51 |
52 | private long duration;
53 |
54 | public SliderPoint(Context context) {
55 | this(context, null);
56 | }
57 |
58 | public SliderPoint(Context context, @Nullable AttributeSet attrs) {
59 | this(context, attrs, 0);
60 | }
61 |
62 | public SliderPoint(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
63 | super(context, attrs, defStyleAttr);
64 | init(context, attrs);
65 | }
66 |
67 | private void init(Context context, AttributeSet attrs) {
68 | initDefaultValues(context);
69 | initAttrs(context, attrs);
70 | }
71 |
72 | private void initDefaultValues(Context context) {
73 | paint = new Paint();
74 | paint.setAntiAlias(true);
75 | paint.setStyle(Paint.Style.FILL);
76 | duration = DEFAULT_ANIMATION_DURATION;
77 |
78 | pulseColor = context.getResources().getColor(R.color.defaultPointPulseColor);
79 | outerColor = context.getResources().getColor(R.color.defaultPointOuterColor);
80 | innerColor = context.getResources().getColor(R.color.defaultPointInnerColor);
81 | }
82 |
83 | @SuppressLint("CustomViewStyleable")
84 | private void initAttrs(Context context, AttributeSet attrs) {
85 | if (attrs != null) {
86 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider);
87 |
88 | pulseColor = a.getColor(R.styleable.Slider_pointPulseColor, pulseColor);
89 | outerColor = a.getColor(R.styleable.Slider_pointOuterColor, outerColor);
90 | innerColor = a.getColor(R.styleable.Slider_pointInnerColor, innerColor);
91 | duration = a.getInt(R.styleable.Slider_animationDuration, (int) duration);
92 |
93 | a.recycle();
94 | }
95 | }
96 |
97 | @Override
98 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
99 | int baseValue = w > h ? h : w;
100 |
101 | centerX = w / 2;
102 | centerY = h / 2;
103 |
104 | endPulseRadius = baseValue * 0.44f;
105 | endOuterRadius = baseValue * 0.26f;
106 | endInnerRadius = baseValue * 0.11f;
107 |
108 | startPulseRadius = endOuterRadius / 2;
109 | startOuterRadius = endOuterRadius / 2;
110 | startInnerRadius = endInnerRadius / 2;
111 | middleInnerRadius = endOuterRadius * 0.85f;
112 |
113 | initDefaultState();
114 | }
115 |
116 | @Override
117 | protected void onDraw(Canvas canvas) {
118 | paint.setColor(pulseColor);
119 | paint.setAlpha(pulseAlpha);
120 | canvas.drawCircle(centerX, centerY, currentPulseRadius, paint);
121 |
122 | paint.setColor(outerColor);
123 | paint.setAlpha(0xFF);
124 | canvas.drawCircle(centerX, centerY, currentOuterRadius, paint);
125 |
126 | paint.setColor(innerColor);
127 | canvas.drawCircle(centerX, centerY, currentInnerRadius, paint);
128 | }
129 |
130 | public void startTransitAnimation(long startDelay) {
131 | transitAnimator = ValueAnimator.ofFloat(0, 1);
132 | transitAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
133 | @Override
134 | public void onAnimationUpdate(ValueAnimator animation) {
135 | float value = (Float) animation.getAnimatedValue();
136 | pulseAlpha = (int) ((1 - value) * 255);
137 |
138 | currentPulseRadius = endOuterRadius + value * (endPulseRadius - endOuterRadius);
139 | SliderPoint.this.invalidate();
140 | }
141 | });
142 | transitAnimator.addListener(new AnimatorListenerAdapter() {
143 | @Override
144 | public void onAnimationCancel(Animator animation) {
145 | initDefaultState();
146 | }
147 |
148 | @Override
149 | public void onAnimationEnd(Animator animation) {
150 | initDefaultState();
151 | }
152 | });
153 | transitAnimator.setStartDelay(startDelay);
154 | transitAnimator.setInterpolator(new DecelerateInterpolator());
155 | transitAnimator.setDuration(duration);
156 | transitAnimator.start();
157 | }
158 |
159 | public void startSelectAnimation() {
160 | cancelAllAnimations();
161 | startMainAnimation();
162 | startInnerCircleAnimation();
163 | }
164 |
165 | private void startMainAnimation() {
166 | mainAnimator = ValueAnimator.ofFloat(0, 1);
167 | mainAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
168 | @Override
169 | public void onAnimationUpdate(ValueAnimator animation) {
170 | float value = (Float) animation.getAnimatedValue();
171 | currentPulseRadius = startPulseRadius + value * (endPulseRadius - startPulseRadius);
172 | currentOuterRadius = startOuterRadius + value * (endOuterRadius - startOuterRadius);
173 | SliderPoint.this.invalidate();
174 | }
175 | });
176 | mainAnimator.setInterpolator(new LinearInterpolator());
177 | mainAnimator.setDuration(duration);
178 | mainAnimator.start();
179 | }
180 |
181 | private void startInnerCircleAnimation() {
182 | innerCircleFirstHalfAnimator = ValueAnimator.ofFloat(startInnerRadius, middleInnerRadius);
183 | innerCircleFirstHalfAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
184 | @Override
185 | public void onAnimationUpdate(ValueAnimator animation) {
186 | currentInnerRadius = (Float) animation.getAnimatedValue();
187 | SliderPoint.this.invalidate();
188 | }
189 | });
190 | innerCircleFirstHalfAnimator.setDuration(duration);
191 | innerCircleFirstHalfAnimator.setInterpolator(new AccelerateInterpolator(1.2f));
192 | innerCircleFirstHalfAnimator.start();
193 |
194 | innerCircleSecondHalfAnimator = ValueAnimator.ofFloat(middleInnerRadius, endInnerRadius);
195 | innerCircleSecondHalfAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
196 | @Override
197 | public void onAnimationUpdate(ValueAnimator animation) {
198 | currentInnerRadius = (Float) animation.getAnimatedValue();
199 | SliderPoint.this.invalidate();
200 | }
201 | });
202 | innerCircleSecondHalfAnimator.setInterpolator(new DecelerateInterpolator(2f));
203 | innerCircleSecondHalfAnimator.setDuration(duration);
204 | innerCircleSecondHalfAnimator.setStartDelay(duration);
205 | innerCircleSecondHalfAnimator.start();
206 | }
207 |
208 | public void cancelAllAnimations() {
209 | if (mainAnimator != null && mainAnimator.isRunning()) {
210 | mainAnimator.cancel();
211 | }
212 | if (innerCircleFirstHalfAnimator != null && innerCircleFirstHalfAnimator.isRunning()) {
213 | innerCircleFirstHalfAnimator.cancel();
214 | }
215 | if (innerCircleSecondHalfAnimator != null) {
216 | innerCircleSecondHalfAnimator.cancel();
217 | }
218 | if (transitAnimator != null && transitAnimator.isRunning()) {
219 | transitAnimator.cancel();
220 | }
221 | }
222 |
223 | public void initDefaultState() {
224 | pulseAlpha = PULSE_INITIAL_ALPHA;
225 | currentPulseRadius = PULSE_INITIAL_RADIUS;
226 | currentOuterRadius = endOuterRadius;
227 | currentInnerRadius = endInnerRadius;
228 | invalidate();
229 | }
230 |
231 | public void setDuration(long duration) {
232 | this.duration = duration;
233 | }
234 |
235 | public void setPulseColor(int pulseColor) {
236 | this.pulseColor = pulseColor;
237 | invalidate();
238 | }
239 |
240 | public void setOuterColor(int outerColor) {
241 | this.outerColor = outerColor;
242 | invalidate();
243 | }
244 |
245 | public void setInnerColor(int innerColor) {
246 | this.innerColor = innerColor;
247 | invalidate();
248 | }
249 | }
250 |
--------------------------------------------------------------------------------
/library/src/main/java/net/vrgsoft/library/Slider.java:
--------------------------------------------------------------------------------
1 | package net.vrgsoft.library;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.ContextWrapper;
6 | import android.content.res.TypedArray;
7 | import android.os.Parcel;
8 | import android.os.Parcelable;
9 | import android.support.annotation.ColorInt;
10 | import android.support.annotation.IntRange;
11 | import android.support.annotation.NonNull;
12 | import android.support.annotation.Nullable;
13 | import android.support.constraint.ConstraintLayout;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.LinearLayout;
18 |
19 | import java.lang.reflect.InvocationTargetException;
20 | import java.lang.reflect.Method;
21 | import java.util.LinkedHashMap;
22 |
23 | import static android.support.constraint.ConstraintLayout.LayoutParams.HORIZONTAL;
24 | import static android.support.constraint.ConstraintLayout.LayoutParams.PARENT_ID;
25 |
26 | public class Slider extends ConstraintLayout {
27 | static final long DEFAULT_ANIMATION_DURATION = 500;
28 |
29 | private static final int START_INDEX = 1000;
30 | private static final int DEFAULT_POINT_COUNT = 3;
31 | private static final int MIN_POINT_COUNT = 2;
32 | private static final int MAX_POINT_COUNT = 8;
33 |
34 | private int mPointsCount;
35 | private int mCurrentPosition;
36 | private int mPreviousPosition;
37 | private int mPointSize;
38 | private int mLineStrokeWidth;
39 | private int mOrientation;
40 | private long mDuration;
41 |
42 | private OnPointClickListener mPointClickListener;
43 | private ClickHandler mClickHandler;
44 | private LinkedHashMap mPoints;
45 | private SliderBgLine mBgLine;
46 |
47 | public Slider(Context context) {
48 | this(context, null);
49 | }
50 |
51 | public Slider(Context context, AttributeSet attrs) {
52 | this(context, attrs, 0);
53 | }
54 |
55 | public Slider(Context context, AttributeSet attrs, int defStyleAttr) {
56 | super(context, attrs, defStyleAttr);
57 | init(context, attrs);
58 | }
59 |
60 | private void init(Context context, AttributeSet attrs) {
61 | initDefaultValues(context);
62 | initAttrs(context, attrs);
63 | initBgLine(context, attrs);
64 | initPoints(context, attrs);
65 | initClickListeners();
66 | setCurrentPosition(mCurrentPosition);
67 | }
68 |
69 | private void initDefaultValues(Context context) {
70 | mPointsCount = DEFAULT_POINT_COUNT;
71 | mDuration = DEFAULT_ANIMATION_DURATION;
72 | mOrientation = LinearLayout.HORIZONTAL;
73 | mPoints = new LinkedHashMap<>();
74 | mClickHandler = new ClickHandler();
75 | mPointSize = context.getResources().getDimensionPixelSize(R.dimen.defaultPointSize);
76 | mLineStrokeWidth = context.getResources().getDimensionPixelSize(R.dimen.defaultLineHeight);
77 | }
78 |
79 | private void initAttrs(Context context, AttributeSet attrs) {
80 | if (attrs != null) {
81 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider);
82 |
83 | mPointsCount = a.getInteger(R.styleable.Slider_pointsCount, mPointsCount);
84 | if (mPointsCount > MAX_POINT_COUNT || mPointsCount < MIN_POINT_COUNT) {
85 | throw new IllegalArgumentException("Sms length should be in range from 1 to 8");
86 | }
87 |
88 | mPointSize = a.getDimensionPixelSize(R.styleable.Slider_pointSize, mPointSize);
89 | mLineStrokeWidth = a.getDimensionPixelSize(R.styleable.Slider_lineStrokeWidth, mLineStrokeWidth);
90 | mOrientation = a.getInt(R.styleable.Slider_android_orientation, mOrientation);
91 | mDuration = a.getInt(R.styleable.Slider_animationDuration, (int) mDuration);
92 |
93 | final String handlerName = a.getString(R.styleable.Slider_onPointClick);
94 | if (handlerName != null) {
95 | setPointClickListener(new DeclaredPointClickListener(this, handlerName));
96 | }
97 |
98 | a.recycle();
99 | }
100 | }
101 |
102 | @Override
103 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
104 | super.onLayout(changed, left, top, right, bottom);
105 | }
106 |
107 | private void initBgLine(Context context, AttributeSet attrs) {
108 | mBgLine = new SliderBgLine(context, attrs);
109 | mBgLine.setPointsCount(mPointsCount);
110 | mBgLine.setId(START_INDEX - 1);
111 | initLineLayoutParams();
112 | addView(mBgLine);
113 | }
114 |
115 | private void initPointsLayoutParams() {
116 | float bias = 1.0f / (mPointsCount - 1);
117 | float currentBias = 0;
118 |
119 | if (mOrientation == HORIZONTAL) {
120 | for (int i = START_INDEX; i < START_INDEX + mPointsCount; ++i) {
121 | SliderPoint point = mPoints.get(i);
122 |
123 | ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(mPointSize, mPointSize);
124 | params.topToTop = PARENT_ID;
125 | params.bottomToBottom = PARENT_ID;
126 | params.startToStart = PARENT_ID;
127 | params.endToEnd = PARENT_ID;
128 | params.horizontalBias = currentBias;
129 |
130 | point.setLayoutParams(params);
131 | currentBias += bias;
132 | }
133 | } else {
134 | for (int i = START_INDEX; i < START_INDEX + mPointsCount; ++i) {
135 | SliderPoint point = mPoints.get(i);
136 |
137 | ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(mPointSize, mPointSize);
138 | params.startToStart = PARENT_ID;
139 | params.endToEnd = PARENT_ID;
140 | params.startToStart = PARENT_ID;
141 | params.endToEnd = PARENT_ID;
142 | params.verticalBias = currentBias;
143 |
144 | point.setLayoutParams(params);
145 | currentBias += bias;
146 | }
147 | }
148 | }
149 |
150 | private void initLineLayoutParams() {
151 | ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mLineStrokeWidth);
152 | params.topToTop = PARENT_ID;
153 | params.bottomToBottom = PARENT_ID;
154 | params.endToEnd = PARENT_ID;
155 | params.startToStart = PARENT_ID;
156 | if (mOrientation == HORIZONTAL) {
157 | params.width = ViewGroup.LayoutParams.MATCH_PARENT;
158 | params.height = mLineStrokeWidth;
159 | params.leftMargin = mPointSize / 2;
160 | params.rightMargin = mPointSize / 2;
161 | } else {
162 | params.height = ViewGroup.LayoutParams.MATCH_PARENT;
163 | params.width = mLineStrokeWidth;
164 | params.topMargin = mPointSize / 2;
165 | params.bottomMargin = mPointSize / 2;
166 | }
167 | mBgLine.setLayoutParams(params);
168 | }
169 |
170 | private void initPoints(Context context, AttributeSet attrs) {
171 | for (int i = START_INDEX; i < START_INDEX + mPointsCount; i++) {
172 | SliderPoint point = new SliderPoint(context, attrs);
173 | point.setId(i);
174 | mPoints.put(i, point);
175 | addView(point);
176 | }
177 | initPointsLayoutParams();
178 | }
179 |
180 | private void initClickListeners() {
181 | for (SliderPoint point : mPoints.values()) {
182 | point.setOnClickListener(mClickHandler);
183 | }
184 | }
185 |
186 | public void setCurrentPosition(int position) {
187 | if (mCurrentPosition == position) return;
188 | mPreviousPosition = mCurrentPosition;
189 | mCurrentPosition = position;
190 | post(new Runnable() {
191 | @Override
192 | public void run() {
193 | Slider.this.startAnimation();
194 | }
195 | });
196 | if (mPointClickListener != null) {
197 | mPointClickListener.onPointClick(mCurrentPosition);
198 | }
199 | }
200 |
201 | private void startAnimation() {
202 | cancelAllAnimations();
203 | initDefaultState();
204 |
205 | handleTransitAnimation();
206 |
207 | mPoints.get(mCurrentPosition + 1000).startSelectAnimation();
208 | mBgLine.startAnimation(mCurrentPosition);
209 | }
210 |
211 | private void handleTransitAnimation() {
212 | int transitPointsCount = Math.abs(mCurrentPosition - mPreviousPosition) - 1;
213 | if (transitPointsCount > 0) {
214 | long onePointTime = mDuration / (transitPointsCount + 2);
215 | long startDelay = 0;
216 | if (mCurrentPosition - mPreviousPosition > 1) {
217 | for (int i = 1; i < transitPointsCount + 1; ++i) {
218 | startDelay += onePointTime;
219 | mPoints.get(START_INDEX + mPreviousPosition + i).startTransitAnimation(startDelay);
220 | }
221 | } else {
222 | for (int i = 1; i < transitPointsCount + 1; ++i) {
223 | startDelay += onePointTime;
224 | mPoints.get(START_INDEX + mPreviousPosition - i).startTransitAnimation(startDelay);
225 | }
226 | }
227 | }
228 | }
229 |
230 | private void initDefaultState() {
231 | for (SliderPoint point : mPoints.values()) {
232 | point.initDefaultState();
233 | }
234 | }
235 |
236 | private void cancelAllAnimations() {
237 | for (SliderPoint point : mPoints.values()) {
238 | point.cancelAllAnimations();
239 | }
240 | }
241 |
242 | public void setPointClickListener(OnPointClickListener pointClickListener) {
243 | mPointClickListener = pointClickListener;
244 | }
245 |
246 | public interface OnPointClickListener {
247 | void onPointClick(int position);
248 | }
249 |
250 | @SuppressLint("ResourceType")
251 | private class ClickHandler implements OnClickListener {
252 | @Override
253 | public void onClick(View v) {
254 | if (v.getId() - START_INDEX == mCurrentPosition) return;
255 | setCurrentPosition(v.getId() - START_INDEX);
256 | if (mPointClickListener != null) {
257 | mPointClickListener.onPointClick(mCurrentPosition);
258 | }
259 | }
260 | }
261 |
262 | private static class DeclaredPointClickListener implements OnPointClickListener {
263 | private final View mHostView;
264 | private final String mMethodName;
265 |
266 | private Method mResolvedMethod;
267 | private Context mResolvedContext;
268 |
269 | DeclaredPointClickListener(@NonNull View hostView, @NonNull String methodName) {
270 | mHostView = hostView;
271 | mMethodName = methodName;
272 | }
273 |
274 | @Override
275 | public void onPointClick(int position) {
276 | if (mResolvedMethod == null) {
277 | resolveMethod(mHostView.getContext());
278 | }
279 |
280 | try {
281 | mResolvedMethod.invoke(mResolvedContext, position);
282 | } catch (IllegalAccessException e) {
283 | throw new IllegalStateException(
284 | "Could not execute non-public method for onSubmit", e);
285 | } catch (InvocationTargetException e) {
286 | throw new IllegalStateException(
287 | "Could not execute method for onSubmit", e);
288 | }
289 | }
290 |
291 | private void resolveMethod(@Nullable Context context) {
292 | while (context != null) {
293 | try {
294 | if (!context.isRestricted()) {
295 | final Method method = context.getClass().getMethod(mMethodName, int.class);
296 | if (method != null) {
297 | mResolvedMethod = method;
298 | mResolvedContext = context;
299 | return;
300 | }
301 | }
302 | } catch (NoSuchMethodException e) {
303 | // Failed to find method, keep searching up the hierarchy.
304 | }
305 |
306 | if (context instanceof ContextWrapper) {
307 | context = ((ContextWrapper) context).getBaseContext();
308 | } else {
309 | // Can't search up the hierarchy, null out and fail.
310 | context = null;
311 | }
312 | }
313 |
314 | final int id = mHostView.getId();
315 | final String idText = id == NO_ID ? "" : " with id '"
316 | + mHostView.getContext().getResources().getResourceEntryName(id) + "'";
317 | throw new IllegalStateException("Could not find method " + mMethodName
318 | + "(View) in a parent or ancestor Context for onSubmit "
319 | + "attribute defined on view " + mHostView.getClass() + idText);
320 | }
321 | }
322 |
323 | @Override
324 | public Parcelable onSaveInstanceState() {
325 | Parcelable superState = super.onSaveInstanceState();
326 | SavedState ss = new SavedState(superState);
327 | ss.setPosition(mCurrentPosition);
328 | return ss;
329 | }
330 |
331 | @Override
332 | public void onRestoreInstanceState(Parcelable state) {
333 | SavedState ss = (SavedState) state;
334 | setCurrentPosition(ss.getPosition());
335 | super.onRestoreInstanceState(ss.getSuperState());
336 | }
337 |
338 | /**
339 | * @param pointSize point width and height
340 | */
341 | public void setPointSize(int pointSize) {
342 | mPointSize = pointSize;
343 | initPointsLayoutParams();
344 | }
345 |
346 | /**
347 | * @param lineStrokeWidth guide line stroke width
348 | */
349 | public void setLineStrokeWidth(int lineStrokeWidth) {
350 | mLineStrokeWidth = lineStrokeWidth;
351 | initLineLayoutParams();
352 | }
353 |
354 | /**
355 | * @param orientation LinearLayout.HORIZONTAL or LinearLayout.VERTICAL
356 | */
357 | public void setOrientation(@IntRange(from = LinearLayout.HORIZONTAL, to = LinearLayout.VERTICAL) int orientation) {
358 | mOrientation = orientation;
359 | mBgLine.setOrientation(orientation);
360 | initLineLayoutParams();
361 | initPointsLayoutParams();
362 | }
363 |
364 | /**
365 | * @param duration animation duration in ms
366 | */
367 | public void setDuration(long duration) {
368 | mDuration = duration;
369 | mBgLine.setDuration(duration);
370 | for(SliderPoint point : mPoints.values()){
371 | point.setDuration(duration);
372 | }
373 | }
374 |
375 | /**
376 | * @param outerLineColor color to be set
377 | */
378 | public void setOuterLineColor(@ColorInt int outerLineColor) {
379 | mBgLine.setOuterLineColor(outerLineColor);
380 | }
381 |
382 | /**
383 | * @param innerLineColor color to be set
384 | */
385 | public void setInnerLineColor(@ColorInt int innerLineColor) {
386 | mBgLine.setInnerLineColor(innerLineColor);
387 | }
388 |
389 | /**
390 | * @param pulseColor color to be set
391 | */
392 | public void setPointPulseColor(int pulseColor) {
393 | for(SliderPoint point : mPoints.values()){
394 | point.setPulseColor(pulseColor);
395 | }
396 | }
397 |
398 | /**
399 | * @param outerColor color to be set
400 | */
401 | public void setPointOuterColor(int outerColor) {
402 | for(SliderPoint point : mPoints.values()){
403 | point.setOuterColor(outerColor);
404 | }
405 | }
406 |
407 | /**
408 | * @param innerColor color to be set
409 | */
410 | public void setPointInnerColor(int innerColor) {
411 | for(SliderPoint point : mPoints.values()){
412 | point.setInnerColor(innerColor);
413 | }
414 | }
415 |
416 | private static final class SavedState extends BaseSavedState {
417 | private int mPosition;
418 |
419 | SavedState(Parcelable superState) {
420 | super(superState);
421 | }
422 |
423 | private SavedState(Parcel in) {
424 | super(in);
425 | mPosition = in.readInt();
426 | }
427 |
428 | @Override
429 | public void writeToParcel(Parcel out, int flags) {
430 | super.writeToParcel(out, flags);
431 | out.writeInt(mPosition);
432 | }
433 |
434 | public static final Parcelable.Creator CREATOR
435 | = new Parcelable.Creator() {
436 | @Override
437 | public SavedState createFromParcel(Parcel in) {
438 | return new SavedState(in);
439 | }
440 |
441 | @Override
442 | public SavedState[] newArray(int size) {
443 | return new SavedState[size];
444 | }
445 | };
446 |
447 | public int getPosition() {
448 | return mPosition;
449 | }
450 |
451 | public void setPosition(int position) {
452 | mPosition = position;
453 | }
454 |
455 | }
456 | }
457 |
--------------------------------------------------------------------------------