├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── attr.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── wanglu1209
│ │ │ └── pikerview
│ │ │ ├── MainActivity.java
│ │ │ └── PickerView.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── github
│ │ │ └── wanglu1209
│ │ │ └── pikerview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── github
│ │ └── wanglu1209
│ │ └── pikerview
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── gradlew
└── README.md
/.idea/.name:
--------------------------------------------------------------------------------
1 | PikerView
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PikerView
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanglu1209/PickerView/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanglu1209/PickerView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanglu1209/PickerView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanglu1209/PickerView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanglu1209/PickerView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wanglu1209/PickerView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 28 17:14:56 CST 2016
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/github/wanglu1209/pikerview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wanglu1209.pikerview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/github/wanglu1209/pikerview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.github.wanglu1209.pikerview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/WangLu/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.github.wanglu1209.pikerview"
9 | minSdkVersion 21
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:24.1.1'
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | <<<<<<< HEAD
2 | *.iml
3 | .gradle
4 | /local.properties
5 | /.idea/workspace.xml
6 | /.idea/libraries
7 | .DS_Store
8 | /build
9 | /captures
10 | =======
11 | # Built application files
12 | *.apk
13 | *.ap_
14 |
15 | # Files for the ART/Dalvik VM
16 | *.dex
17 |
18 | # Java class files
19 | *.class
20 |
21 | # Generated files
22 | bin/
23 | gen/
24 | out/
25 |
26 | # Gradle files
27 | .gradle/
28 | build/
29 |
30 | # Local configuration file (sdk path, etc)
31 | local.properties
32 |
33 | # Proguard folder generated by Eclipse
34 | proguard/
35 |
36 | # Log Files
37 | *.log
38 |
39 | # Android Studio Navigation editor temp files
40 | .navigation/
41 |
42 | # Android Studio captures folder
43 | captures/
44 |
45 | # Intellij
46 | *.iml
47 | .idea/workspace.xml
48 |
49 | # Keystore files
50 | *.jks
51 | >>>>>>> 32befb93ff50cc974e90477bd7ae20c9476d169b
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/gradle.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 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/java/com/github/wanglu1209/pikerview/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.wanglu1209.pikerview;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.Toast;
7 |
8 | import java.util.ArrayList;
9 | import java.util.List;
10 |
11 | public class MainActivity extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_main);
17 |
18 | List data = new ArrayList<>();
19 | data.add("Android");
20 | data.add("Python");
21 | data.add("C#");
22 | data.add("Java");
23 | data.add("C++");
24 | data.add("Go");
25 | data.add("Object-C");
26 | data.add("JavaScript");
27 | data.add("C");
28 | final PickerView pv = (PickerView) findViewById(R.id.pv);
29 | pv.setData(data);
30 |
31 | findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
32 | @Override
33 | public void onClick(View view) {
34 | Toast.makeText(MainActivity.this, "" + pv.getPosition(), Toast.LENGTH_SHORT).show();
35 | }
36 | });
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/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 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PickerView
2 |
3 | 前段时间在公司总是有需求『滚动的选择器』,那时候总是用别人写好的来用,感觉心里不是很舒服,最近有时间了自己来写一写,上图:
4 |
5 | 
6 |
7 | 首先分析一下需求:
8 |
9 | 1. 可以滑动
10 | 2. 滑到两条线里的数据变色
11 | 3. 滑动完成后必须要把选中的数据放到中间
12 |
13 |
14 | ### 滑动
15 |
16 | 首先说到滑动而且还是自定义的View,我们就会想到各种『scrollBy/scrollTo』等,但是这里有个更简单的方法就是**继承自ScrollView**,这样就简单了不少,并且还有滚动的监听『只不过少了一个停止滑动的状态』,然而对于这个需求,我们只需要创建一个ViewGroup来放入数据(也就是很多TextView),然后addView()就OK,代码如下:
17 |
18 | /**
19 | * 初始化数据,首先添加Group
20 | */
21 | mTextGroup = new LinearLayout(context);
22 | mTextGroup.setOrientation(LinearLayout.VERTICAL);
23 | mTextGroup.setGravity(Gravity.CENTER);
24 | addView(mTextGroup);
25 |
26 |
27 | /**
28 | * 由于我们需要给自身的数据在选中的框里显示
29 | * 所以这里需要添加前面和后面的空数据
30 | */
31 | mTextGroup.addView(createTextView(""));
32 | for (int i = 0; i < mData.size(); i++) {
33 | mTextGroup.addView(createTextView("" + mData.get(i)));
34 | }
35 | mTextGroup.addView(createTextView(""));
36 |
37 | ------------------------------------------------------------
38 |
39 | /**
40 | * 动态创建TextView
41 | */
42 | private TextView createTextView(String s) {
43 | TextView tv = new TextView(context);
44 | tv.setText(s);
45 | tv.setTextColor(getResources().getColor(android.R.color.darker_gray));
46 | tv.setTextSize(mTextSize);
47 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, mTextHeight);
48 |
49 | params.bottomMargin = mTextHeight / 2;
50 | params.topMargin = mTextHeight / 2;
51 | tv.setLayoutParams(params);
52 | return tv;
53 | }
54 |
55 |
56 | 可以看到我们在数据的前后都加了两条空数据,因为这里需要在滑动到底部或者顶部的时候确保第一条或者最后一条数据是在我们的两条线之内,这样运行一下程序就会发现我们的数据已经可以滑动了,只不过这个时候还没有中间的两条线。这里需要思考一下,如果我们添加两条线上去的话,滑动的时候线也会跟着滑动,所以这个时候就想到了背景,我们自己来画一个背景。代码如下:
57 |
58 | /**
59 | * 设置背景,这里选择画一个,两条线
60 | */
61 | setBackground(new Drawable() {
62 | @Override
63 | public void draw(Canvas canvas) {
64 | /**
65 | * 这里把两条线之间的距离设置为了两个TextView的高度
66 | */
67 | canvas.drawLine(
68 | mWidth * 0.1f,
69 | mHeight / 2 - mTextHeight,
70 | mWidth * 0.9f,
71 | mHeight / 2 - mTextHeight,
72 | mLinePaint
73 | );
74 | canvas.drawLine(
75 | mWidth * 0.1f,
76 | mHeight / 2 + mTextHeight,
77 | mWidth * 0.9f,
78 | mHeight / 2 + mTextHeight,
79 | mLinePaint
80 | );
81 | }
82 |
83 | @Override
84 | public void setAlpha(int i) {
85 |
86 | }
87 |
88 | @Override
89 | public void setColorFilter(ColorFilter colorFilter) {
90 |
91 | }
92 |
93 | @Override
94 | public int getOpacity() {
95 | return 0;
96 | }
97 | });
98 |
99 |
100 | 这时候我们的背景和数据都弄好了
101 |
102 |
103 | ### 在线内的数据变颜色
104 |
105 | 先考虑一下,因为我们使用的是TextView,所以我们直接就可以设置TextView的字体颜色。很简单,我们在onScrollChanged()方法中用小学除法来算一下当前滚动到了哪个TextView『也就是position』,我们就把哪个改变颜色,代码如下:
106 |
107 | /**
108 | * ScrollView的滑动事件监听
109 | */
110 | @Override
111 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
112 | super.onScrollChanged(l, t, oldl, oldt);
113 |
114 | /**
115 | * 计算出当前在两条线里的position
116 | */
117 | position = (t + mTextHeight) / (mTextHeight * 2);
118 | /**
119 | * 因为此方法会在滑动的时候不停的调用,所以这里设置一个临时的变量来控制
120 | */
121 | if (tempPosition != position) {
122 | int size = mTextGroup.getChildCount();
123 | for (int i = 0; i < size; i++) {
124 | TextView tv = (TextView) mTextGroup.getChildAt(i);
125 | /**
126 | * 因为我们在数据开头添加了一个空的数据,所以这里position要+1
127 | */
128 | if (position + 1 == i) {
129 | tv.setTextColor(getResources().
130 | getColor(android.R.color.holo_blue_dark));
131 | } else {
132 | tv.setTextColor(getResources().
133 | getColor(android.R.color.darker_gray));
134 | }
135 | }
136 | }
137 | tempPosition = position;
138 | }
139 |
140 | ### 滑动结束后把当前数据放在中间(其实我不知道怎么表达了)
141 |
142 |
143 | ScrollView没有滑动结束的监听,所以我们只好取巧来弄一个。我们在手指离开屏幕的30ms后来判断当前的scrollY和离开屏幕时候的scrollY是否一样,一样则认定是滑动结束了,如果不一样,我们强行给弄成一样的来结束滑动
144 |
145 | @Override
146 | public boolean onTouchEvent(MotionEvent ev) {
147 | /**
148 | * 因为ScrollView没有停止滑动的监听,所以这里取巧
149 | * 在手指离开屏幕的30ms后判断是否和原来的scrollY一样
150 | * 如果一样则进入,如果不一样则设置为一样
151 | */
152 | if (ev.getAction() == MotionEvent.ACTION_UP) {
153 | scrollY = getScrollY();
154 | postDelayed(new Runnable() {
155 | @Override
156 | public void run() {
157 | if (scrollY == getScrollY()) {
158 | /**
159 | * 获得每次松手后scrollY相对于TextView高度的偏移量
160 | */
161 | int offset = scrollY % (mTextHeight * 2);
162 |
163 | /**
164 | * 如果偏移量大于TextView高度的一半
165 | * 则进入到下一个
166 | */
167 | if (offset > mTextHeight) {
168 | smoothScrollTo(0, scrollY - offset + (mTextHeight * 2));
169 | } else {
170 | smoothScrollTo(0, scrollY - offset);
171 | }
172 | } else {
173 | scrollY = getScrollY();
174 | post(this);
175 | }
176 | }
177 | }, 30);
178 | }
179 | return super.onTouchEvent(ev);
180 | }
181 |
182 |
183 | 到这里就结束了,其实还是蛮简单的,只不过功能甚少,只能实现基本的选择数据,所以我起名为PickerView,当然以后还会对这个项目进行维护,欢迎大家来star或者提bug
184 |
185 | ---
186 |
187 | #### 感谢
188 |
189 | 感谢wangjiegulu的WheelView给的启发,放上地址
190 |
191 | [WheelView](https://github.com/wangjiegulu/WheelView)
192 |
193 | ---
194 |
195 | ## 最后
196 |
197 | 爱生活,爱小丽,爱Android
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/wanglu1209/pikerview/PickerView.java:
--------------------------------------------------------------------------------
1 | package com.github.wanglu1209.pikerview;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Canvas;
6 | import android.graphics.ColorFilter;
7 | import android.graphics.Paint;
8 | import android.graphics.drawable.Drawable;
9 | import android.util.AttributeSet;
10 | import android.view.Gravity;
11 | import android.view.MotionEvent;
12 | import android.view.ViewGroup;
13 | import android.widget.LinearLayout;
14 | import android.widget.ScrollView;
15 | import android.widget.TextView;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * Created by WangLu on 16/8/24.
21 | */
22 | public class PickerView extends ScrollView {
23 |
24 | private Context context;
25 | /**
26 | * 数据源
27 | */
28 | private List mData;
29 | /**
30 | * 两条线的画笔
31 | */
32 | private Paint mLinePaint;
33 | /**
34 | * 宽,高,还有显示的TextView的高度(注意:这里只是TextView的高度,不算margin)
35 | */
36 | private int mWidth, mHeight, mTextHeight;
37 | /**
38 | * TextView的父容器
39 | */
40 | private LinearLayout mTextGroup;
41 | /**
42 | * 获取屏幕的密度
43 | */
44 | private float mDensity;
45 | /**
46 | * 字体的大小
47 | */
48 | private float mTextSize;
49 | /**
50 | * 根据字体大小来控制整个控件的高度
51 | */
52 | private float mWrapContentHeight;
53 | /**
54 | * 当前选中的position
55 | */
56 | private int position, tempPosition = -1;
57 | private int scrollY;
58 |
59 | public PickerView(Context context) {
60 | this(context, null);
61 | }
62 |
63 | public PickerView(Context context, AttributeSet attrs) {
64 | this(context, attrs, 0);
65 | }
66 |
67 | public PickerView(Context context, AttributeSet attrs, int defStyleAttr) {
68 | super(context, attrs, defStyleAttr);
69 | this.context = context;
70 | /**
71 | * 这句话设置ScrollView滑动到极限的时候不显示提示(就是那个阴影)
72 | */
73 | setOverScrollMode(OVER_SCROLL_NEVER);
74 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PickerView, defStyleAttr, 0);
75 | try {
76 | /**
77 | * 获取到用户设置的字体大小,默认25
78 | */
79 | mTextSize = a.getDimension(R.styleable.PickerView_textSize, 25);
80 | /**
81 | * 获取到屏幕的密度来设置TextView的高度
82 | */
83 | mDensity = getResources().getDisplayMetrics().density;
84 | mTextHeight = (int) ((mDensity + 0.5) * mTextSize);
85 | /**
86 | * 整个控件的高度为6个TextView的高度
87 | */
88 | mWrapContentHeight = mTextHeight * 6;
89 | } finally {
90 | a.recycle();
91 | }
92 | }
93 |
94 |
95 | private void init() {
96 |
97 | /**
98 | * 初始化数据,首先添加Group
99 | */
100 | mTextGroup = new LinearLayout(context);
101 | mTextGroup.setOrientation(LinearLayout.VERTICAL);
102 | mTextGroup.setGravity(Gravity.CENTER);
103 | addView(mTextGroup);
104 |
105 |
106 | /**
107 | * 由于我们需要给自身的数据在选中的框里显示
108 | * 所以这里需要添加前面和后面的空数据
109 | */
110 | mTextGroup.addView(createTextView(""));
111 | for (int i = 0; i < mData.size(); i++) {
112 | mTextGroup.addView(createTextView("" + mData.get(i)));
113 | }
114 | mTextGroup.addView(createTextView(""));
115 |
116 | /**
117 | * 设置背景,这里选择画一个,两条线
118 | */
119 | setBackground(new Drawable() {
120 | @Override
121 | public void draw(Canvas canvas) {
122 | /**
123 | * 这里把两条线之间的距离设置为了两个TextView的高度
124 | */
125 | canvas.drawLine(
126 | mWidth * 0.1f,
127 | mHeight / 2 - mTextHeight,
128 | mWidth * 0.9f,
129 | mHeight / 2 - mTextHeight,
130 | mLinePaint
131 | );
132 | canvas.drawLine(
133 | mWidth * 0.1f,
134 | mHeight / 2 + mTextHeight,
135 | mWidth * 0.9f,
136 | mHeight / 2 + mTextHeight,
137 | mLinePaint
138 | );
139 | }
140 |
141 | @Override
142 | public void setAlpha(int i) {
143 |
144 | }
145 |
146 | @Override
147 | public void setColorFilter(ColorFilter colorFilter) {
148 |
149 | }
150 |
151 | @Override
152 | public int getOpacity() {
153 | return 0;
154 | }
155 | });
156 |
157 | mLinePaint = new Paint();
158 | mLinePaint.setAntiAlias(true);
159 | mLinePaint.setStrokeWidth(1);
160 | mLinePaint.setColor(getResources().getColor(android.R.color.holo_blue_dark));
161 | setPosition(0);
162 |
163 | }
164 |
165 | /**
166 | * 动态创建TextView
167 | */
168 | private TextView createTextView(String s) {
169 | TextView tv = new TextView(context);
170 | tv.setText(s);
171 | tv.setTextColor(getResources().getColor(android.R.color.darker_gray));
172 | tv.setTextSize(mTextSize);
173 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, mTextHeight);
174 |
175 | params.bottomMargin = mTextHeight / 2;
176 | params.topMargin = mTextHeight / 2;
177 | tv.setLayoutParams(params);
178 | return tv;
179 | }
180 |
181 |
182 | @Override
183 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
184 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
185 | /**
186 | * 更改测量方法
187 | * 指定高度为mWrapContentHeight
188 | */
189 | mWidth = measureWidth(widthMeasureSpec);
190 | mHeight = (int) mWrapContentHeight;
191 | setMeasuredDimension(mWidth, (int) mWrapContentHeight);
192 | }
193 |
194 |
195 | private int measureWidth(int size) {
196 | int mode = MeasureSpec.getMode(size);
197 | switch (mode) {
198 | case MeasureSpec.UNSPECIFIED:
199 | case MeasureSpec.AT_MOST:
200 | return (int) mWrapContentHeight;
201 | case MeasureSpec.EXACTLY:
202 | default:
203 | return MeasureSpec.getSize(size);
204 | }
205 | }
206 |
207 | /**
208 | * ScrollView的滑动事件监听
209 | */
210 | @Override
211 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
212 | super.onScrollChanged(l, t, oldl, oldt);
213 |
214 | /**
215 | * 计算出当前在两条线里的position
216 | */
217 | position = (t + mTextHeight) / (mTextHeight * 2);
218 | /**
219 | * 因为此方法会在滑动的时候不停的调用,所以这里设置一个临时的变量来控制
220 | */
221 | if (tempPosition != position) {
222 | int size = mTextGroup.getChildCount();
223 | for (int i = 0; i < size; i++) {
224 | TextView tv = (TextView) mTextGroup.getChildAt(i);
225 | /**
226 | * 因为我们在数据开头添加了一个空的数据,所以这里position要+1
227 | */
228 | if (position + 1 == i) {
229 | tv.setTextColor(getResources().getColor(android.R.color.holo_blue_dark));
230 | } else {
231 | tv.setTextColor(getResources().getColor(android.R.color.darker_gray));
232 | }
233 | }
234 | }
235 | tempPosition = position;
236 |
237 | }
238 |
239 | @Override
240 | public boolean onTouchEvent(MotionEvent ev) {
241 | /**
242 | * 因为ScrollView没有停止滑动的监听,所以这里取巧
243 | * 在手指离开屏幕的30ms后判断是否和原来的scrollY一样
244 | * 如果一样则进入,如果不一样则设置为一样
245 | */
246 | if (ev.getAction() == MotionEvent.ACTION_UP) {
247 | scrollY = getScrollY();
248 | postDelayed(new Runnable() {
249 | @Override
250 | public void run() {
251 | if (scrollY == getScrollY()) {
252 | /**
253 | * 获得每次松手后scrollY相对于TextView高度的偏移量
254 | */
255 | int offset = scrollY % (mTextHeight * 2);
256 |
257 | /**
258 | * 如果偏移量大于TextView高度的一半
259 | * 则进入到下一个
260 | */
261 | if (offset > mTextHeight) {
262 | smoothScrollTo(0, scrollY - offset + (mTextHeight * 2));
263 | } else {
264 | smoothScrollTo(0, scrollY - offset);
265 | }
266 | } else {
267 | scrollY = getScrollY();
268 | post(this);
269 | }
270 | }
271 | }, 30);
272 | }
273 | return super.onTouchEvent(ev);
274 | }
275 |
276 |
277 | /**
278 | * 设置fling的速度为原来的1/3
279 | */
280 | @Override
281 | public void fling(int velocityY) {
282 | super.fling(velocityY / 3);
283 | }
284 |
285 | /**
286 | * 设置数据源
287 | */
288 | public void setData(List data) {
289 | mData = data;
290 | init();
291 | }
292 |
293 | /**
294 | * 设置position
295 | */
296 | public void setPosition(int position) {
297 | this.position = position;
298 | if (position == 0) {
299 | post(new Runnable() {
300 | @Override
301 | public void run() {
302 | scrollTo(0, 1);
303 | }
304 | });
305 | return;
306 | }
307 | post(new Runnable() {
308 | @Override
309 | public void run() {
310 | scrollTo(0, PickerView.this.position * (mTextHeight * 2));
311 | }
312 | });
313 | }
314 |
315 | /**
316 | * 获取position
317 | * @return
318 | */
319 | public int getPosition() {
320 | return position;
321 | }
322 | }
323 |
--------------------------------------------------------------------------------