├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── bigkoo
│ │ └── snappingstepperdemo
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── bigkoo
│ │ │ └── snappingstepperdemo
│ │ │ ├── MainActivity.java
│ │ │ └── listviewdemo
│ │ │ ├── ListDemoActivity.java
│ │ │ └── ListDemoAdapter.java
│ └── res
│ │ ├── drawable
│ │ ├── ic_stepper_left.png
│ │ ├── ic_stepper_right.png
│ │ └── sl_steppercustom_button_bg.xml
│ │ ├── layout
│ │ ├── activity_listdemo.xml
│ │ ├── activity_main.xml
│ │ └── adapter_listdemo.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── bigkoo
│ └── snappingstepperdemo
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── snappingstepper
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
├── androidTest
└── java
│ └── com
│ └── bigkoo
│ └── snappingstepper
│ └── ApplicationTest.java
├── main
├── AndroidManifest.xml
├── java
│ └── com
│ │ └── bigkoo
│ │ └── snappingstepper
│ │ ├── SnappingStepper.java
│ │ └── listener
│ │ └── SnappingStepperValueChangeListener.java
└── res
│ ├── drawable-xxhdpi
│ ├── ic_snappingstepper_minus.png
│ └── ic_snappingstepper_plus.png
│ ├── drawable
│ └── sl_snappingstepper_button.xml
│ ├── layout
│ └── view_snappingstepper.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ └── strings.xml
└── test
└── java
└── com
└── bigkoo
└── snappingstepper
└── ExampleUnitTest.java
/.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/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
20 |
--------------------------------------------------------------------------------
/.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 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Android-ShoppingCartAddSubtract
3 | 一种漂亮的UI控件,能更灵活的控制数字的增减。
4 |
5 | 项目地址:[https://github.com/open-android/ShoppingCartAddSubtract](https://github.com/open-android/ShoppingCartAddSubtract "购物车加减控件")
6 |
7 |
8 | 简书:[http://www.jianshu.com/p/be3d0f763c5a](http://www.jianshu.com/p/be3d0f763c5a "购物车加减控件")
9 | # 运行效果
10 |
11 | 
12 |
13 | * 爱生活,爱学习,更爱做代码的搬运工,分类查找更方便请下载黑马助手app
14 |
15 |
16 | 
17 |
18 | ## 使用步骤
19 | ### 1. 在project的build.gradle添加如下代码(如下图)
20 |
21 | allprojects {
22 | repositories {
23 | ...
24 | maven { url "https://jitpack.io" }
25 | }
26 | }
27 |
28 | 
29 |
30 | ### 2. 在Module的build.gradle添加依赖
31 |
32 | compile 'com.github.open-android:ShoppingCartAddSubtract:0.1.0'
33 |
34 |
35 | ### 3. 在XML添加如下代码
36 |
37 |
43 |
44 |
48 |
49 |
54 |
55 |
56 | ### 4. 在java类中添加如下代码
57 |
58 | tvValue = (TextView) findViewById(R.id.tvValue);
59 | stepper = (SnappingStepper) findViewById(R.id.stepper);
60 | tvValue.setText(String.valueOf(stepper.getValue()));
61 | stepper.setOnValueChangeListener(this);
62 | @Override
63 | public void onValueChange(View view ,int value) {
64 | switch (view.getId()){
65 | case R.id.stepper:
66 | tvValue.setText(String.valueOf(value));
67 | break;
68 | }
69 | }
70 |
71 |
72 |
73 |
74 |
75 |
76 | ---
77 |
78 | * 注意细节
79 |
80 | > 支持更多的自定义属性XML表示
81 |
82 |
99 |
100 | > 支持更多的自定义属性java代码表示
101 |
102 | stepperCustom.setBackgroundColor(getResources().getColor(R.color.colorStepperButtonNormal));
103 | stepperCustom.setButtonBackGround(R.drawable.sl_steppercustom_button_bg);
104 | stepperCustom.setContentBackground(R.color.colorStepperContentBg);
105 | stepperCustom.setContentTextColor(R.color.colorStepperText);
106 | stepperCustom.setContentTextSize(18);
107 | stepperCustom.setLeftButtonResources(R.drawable.ic_stepper_left);
108 | stepperCustom.setRightButtonResources(R.drawable.ic_stepper_right);
109 |
110 | * 详细的使用方法在DEMO里面都演示啦,如果你觉得这个库还不错,请赏我一颗star吧~~~
111 |
112 |
113 | * 欢迎关注微信公众号
114 |
115 | 
116 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.bigkoo.snappingstepperdemo"
9 | minSdkVersion 16
10 | targetSdkVersion 23
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(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:appcompat-v7:23.1.0'
25 | // compile 'com.bigkoo:snappingstepper:1.0.2'
26 | compile project(':snappingstepper')
27 | }
28 |
--------------------------------------------------------------------------------
/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/Sai/Documents/software/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/src/androidTest/java/com/bigkoo/snappingstepperdemo/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepperdemo;
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 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bigkoo/snappingstepperdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepperdemo;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.TextView;
8 |
9 | import com.bigkoo.snappingstepper.SnappingStepper;
10 | import com.bigkoo.snappingstepper.listener.SnappingStepperValueChangeListener;
11 | import com.bigkoo.snappingstepperdemo.listviewdemo.ListDemoActivity;
12 |
13 | public class MainActivity extends AppCompatActivity implements SnappingStepperValueChangeListener {
14 |
15 | private TextView tvValue;
16 | private SnappingStepper stepper;
17 | private TextView tvValueCustom;
18 | private SnappingStepper stepperCustom;
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 | tvValue = (TextView) findViewById(R.id.tvValue);
24 | stepper = (SnappingStepper) findViewById(R.id.stepper);
25 | tvValueCustom = (TextView) findViewById(R.id.tvValueCustom);
26 | stepperCustom = (SnappingStepper) findViewById(R.id.stepperCustom);
27 |
28 | tvValue.setText(String.valueOf(stepper.getValue()));
29 | tvValueCustom.setText(String.valueOf(stepperCustom.getValue()));
30 | stepper.setOnValueChangeListener(this);
31 | stepperCustom.setOnValueChangeListener(this);
32 |
33 | stepperCustom.setBackgroundColor(getResources().getColor(R.color.colorStepperButtonNormal));
34 | stepperCustom.setButtonBackGround(R.drawable.sl_steppercustom_button_bg);
35 | stepperCustom.setContentBackground(R.color.colorStepperContentBg);
36 | stepperCustom.setContentTextColor(R.color.colorStepperText);
37 | stepperCustom.setContentTextSize(18);
38 | stepperCustom.setLeftButtonResources(R.drawable.ic_stepper_left);
39 | stepperCustom.setRightButtonResources(R.drawable.ic_stepper_right);
40 | }
41 |
42 | @Override
43 | public void onValueChange(View view ,int value) {
44 | switch (view.getId()){
45 | case R.id.stepper:
46 | tvValue.setText(String.valueOf(value));
47 | break;
48 | case R.id.stepperCustom:
49 | tvValueCustom.setText(String.valueOf(value));
50 | break;
51 | }
52 | }
53 | public void openListView(View v){
54 | startActivity(new Intent(this, ListDemoActivity.class));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bigkoo/snappingstepperdemo/listviewdemo/ListDemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepperdemo.listviewdemo;
2 |
3 | import android.app.Activity;
4 | import android.os.Bundle;
5 | import android.view.View;
6 | import android.widget.AdapterView;
7 | import android.widget.ListView;
8 |
9 | import com.bigkoo.snappingstepperdemo.R;
10 |
11 | /**
12 | * Created by Sai on 16/2/18.
13 | */
14 | public class ListDemoActivity extends Activity implements AdapterView.OnItemClickListener {
15 | ListView listView;
16 | @Override
17 | protected void onCreate(Bundle savedInstanceState) {
18 | super.onCreate(savedInstanceState);
19 | setContentView(R.layout.activity_listdemo);
20 | listView = (ListView) findViewById(R.id.listView);
21 |
22 | listView.setAdapter(new ListDemoAdapter(this));
23 | listView.setOnItemClickListener(this);
24 | }
25 |
26 | @Override
27 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
28 | System.out.println("点击了列表=======");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/app/src/main/java/com/bigkoo/snappingstepperdemo/listviewdemo/ListDemoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepperdemo.listviewdemo;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 |
9 | import com.bigkoo.snappingstepper.SnappingStepper;
10 | import com.bigkoo.snappingstepperdemo.R;
11 |
12 | /**
13 | * Created by Sai on 16/2/18.
14 | */
15 | public class ListDemoAdapter extends BaseAdapter {
16 |
17 | private Context context;
18 |
19 | public ListDemoAdapter(Context context) {
20 | this.context = context;
21 | }
22 |
23 | @Override
24 | public int getCount() {
25 | return 100;
26 | }
27 |
28 | @Override
29 | public Object getItem(int position) {
30 | return "";
31 | }
32 |
33 | @Override
34 | public long getItemId(int position) {
35 | return position;
36 | }
37 |
38 | @Override
39 | public View getView(int position, View convertView, ViewGroup parent) {
40 | ViewHolder holder = null;
41 | if (convertView == null) {
42 | convertView = LayoutInflater.from(context).inflate(
43 | R.layout.adapter_listdemo, null);
44 | holder = new ViewHolder();
45 | holder.stepperCustom = (SnappingStepper) convertView.findViewById(R.id.stepperCustom);
46 | convertView.setTag(holder);
47 | } else {
48 | holder = (ViewHolder) convertView.getTag();
49 | }
50 |
51 | if(position == 5){
52 | holder.stepperCustom.setMinValue(0);
53 | holder.stepperCustom.setValue(10);
54 | }
55 | return convertView;
56 | }
57 |
58 | private class ViewHolder {
59 | SnappingStepper stepperCustom;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_stepper_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/app/src/main/res/drawable/ic_stepper_left.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_stepper_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/app/src/main/res/drawable/ic_stepper_right.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sl_steppercustom_button_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_listdemo.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
17 |
18 |
22 |
23 |
28 |
29 |
35 |
36 |
47 |
48 |
53 |
54 |
55 |
72 |
73 |
74 |
79 |
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/adapter_listdemo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #cc482c
7 | #92011d
8 | #f95b3a
9 | #ffffff
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SnappingStepperDemo
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/bigkoo/snappingstepperdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepperdemo;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' // Add this line
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':snappingstepper'
2 |
--------------------------------------------------------------------------------
/snappingstepper/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/snappingstepper/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | //apply plugin: 'com.github.dcendents.android-maven'
3 | //apply plugin: 'com.jfrog.bintray'
4 | apply plugin: 'com.github.dcendents.android-maven'//固定不变
5 | group='com.github.open-android'//itcastsh:github账号
6 | version = "1.0.2"
7 |
8 |
9 | android {
10 | compileSdkVersion 25
11 | buildToolsVersion "25.0.0"
12 |
13 | defaultConfig {
14 | minSdkVersion 16
15 | targetSdkVersion 25
16 | versionCode 1
17 | versionName "1.0"
18 | }
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | compile 'com.nineoldandroids:library:2.4.0'
30 | }
31 |
32 | def siteUrl = 'https://github.com/saiwu-bigkoo/Android-SnappingStepper' // #CONFIG# // project homepage
33 | def gitUrl = 'https://github.com/saiwu-bigkoo/Android-SnappingStepper.git' // #CONFIG# // project git
34 | group = "com.bigkoo"
35 |
36 | //install {
37 | // repositories.mavenInstaller {
38 | // // This generates POM.xml with proper parameters
39 | // pom {
40 | // project {
41 | // packaging 'aar'
42 | // name 'SnappingStepper For Android' // #CONFIG# // project title
43 | // url siteUrl
44 | // // Set your license
45 | // licenses {
46 | // license {
47 | // name 'The Apache Software License, Version 2.0'
48 | // url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
49 | // }
50 | // }
51 | // developers {
52 | // developer {
53 | // id 'sai' // #CONFIG# // your user id (you can write your nickname)
54 | // name 'sai.wu' // #CONFIG# // your user name
55 | // email 'sai.wu@bigkoo.com' // #CONFIG# // your email
56 | // }
57 | // }
58 | // scm {
59 | // connection gitUrl
60 | // developerConnection gitUrl
61 | // url siteUrl
62 | // }
63 | // }
64 | // }
65 | // }
66 | //}
67 |
68 | task sourcesJar(type: Jar) {
69 | from android.sourceSets.main.java.srcDirs
70 | classifier = 'sources'
71 | }
72 |
73 | task javadoc(type: Javadoc) {
74 | source = android.sourceSets.main.java.srcDirs
75 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
76 | }
77 |
78 | task javadocJar(type: Jar, dependsOn: javadoc) {
79 | classifier = 'javadoc'
80 | from javadoc.destinationDir
81 | }
82 |
83 | artifacts {
84 | archives javadocJar
85 | archives sourcesJar
86 | }
87 |
88 | Properties properties = new Properties()
89 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
90 | //bintray {
91 | // user = properties.getProperty("bintray.user")
92 | // key = properties.getProperty("bintray.apikey")
93 | // configurations = ['archives']
94 | // pkg {
95 | // repo = "maven"
96 | // name = "SnappingStepper" // #CONFIG# project name in jcenter
97 | // websiteUrl = siteUrl
98 | // vcsUrl = gitUrl
99 | // licenses = ["Apache-2.0"]
100 | // publish = true
101 | // }
102 | //}
--------------------------------------------------------------------------------
/snappingstepper/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/Sai/Documents/software/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 |
--------------------------------------------------------------------------------
/snappingstepper/src/androidTest/java/com/bigkoo/snappingstepper/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepper;
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 | }
--------------------------------------------------------------------------------
/snappingstepper/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/java/com/bigkoo/snappingstepper/SnappingStepper.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepper;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.drawable.Drawable;
6 | import android.util.AttributeSet;
7 | import android.view.LayoutInflater;
8 | import android.view.MotionEvent;
9 | import android.view.View;
10 | import android.view.ViewConfiguration;
11 | import android.view.animation.AccelerateInterpolator;
12 | import android.widget.ImageView;
13 | import android.widget.RelativeLayout;
14 | import android.widget.TextView;
15 |
16 | import com.bigkoo.snappingstepper.listener.SnappingStepperValueChangeListener;
17 | import com.nineoldandroids.animation.Animator;
18 | import com.nineoldandroids.animation.ValueAnimator;
19 |
20 | import java.lang.ref.WeakReference;
21 |
22 | /**
23 | * Created by Sai on 16/1/15.
24 | */
25 | public class SnappingStepper extends RelativeLayout implements View.OnTouchListener, ValueAnimator.AnimatorListener, ValueAnimator.AnimatorUpdateListener {
26 | private SnappingStepperValueChangeListener listener;
27 | private TextView tvStepperContent;
28 | private ImageView ivStepperMinus, ivStepperPlus;
29 | public static int ANIMATIONDURATION = 300;//恢复动画时间
30 | public boolean animationing = false;//动画中,不能进行滑动
31 | private UpdateRunnable updateRunnable;
32 | private boolean stepTouch = false;//是否按着,判断是否还要继续更新数值和界面
33 |
34 | //按下后多少间隔触发快速改变模式
35 | private static final long STEPSPEEDCHANGEDURATION = 1000;
36 | private static long UPDATEDURATIONSLOW = 300;//数值更新频率-慢
37 | private static long UPDATEDURATIONFAST = 100;//数值更新频率-快
38 | private int valueSlowStep = 1;//慢速递增值 步长
39 |
40 | //按下的初始x值
41 | private float startX = 0;
42 | private float startStepperContentLeft = 0;
43 | private boolean hasStepperContentLeft = false;
44 | //按下时间
45 | private long startTime = 0;
46 |
47 |
48 | //当前状态
49 | private int status = STATUS_NORMAL;
50 | private static final int STATUS_MIMNUS = -1;
51 | private static final int STATUS_PLUS = 1;
52 | private static final int STATUS_NORMAL = 0;
53 | //当前模式
54 | private Mode mode = Mode.AUTO;
55 |
56 | public enum Mode {
57 | AUTO(0), CUSTOM(1);
58 | private final int value;
59 |
60 | Mode(int value) {
61 | this.value = value;
62 | }
63 |
64 | public int getValue() {
65 | return value;
66 | }
67 |
68 | public static Mode valueOf(int value) { // 手写的从int到enum的转换函数
69 | switch (value) {
70 | case 0:
71 | return AUTO;
72 | case 1:
73 | return CUSTOM;
74 | }
75 | return AUTO;
76 | }
77 | }
78 |
79 | private int value = 0;
80 | private int minValue = 0;
81 | private int maxValue = 100;
82 |
83 | public SnappingStepper(Context context) {
84 | this(context, null);
85 | }
86 |
87 | public SnappingStepper(Context context, AttributeSet attrs) {
88 | super(context, attrs);
89 | initViews(attrs);
90 | }
91 |
92 | private void initViews(AttributeSet attrs) {
93 |
94 |
95 | LayoutInflater.from(getContext()).inflate(R.layout.view_snappingstepper, this, true);
96 | tvStepperContent = (TextView) findViewById(R.id.tvStepperContent);
97 | ivStepperMinus = (ImageView) findViewById(R.id.ivStepperMinus);
98 | ivStepperPlus = (ImageView) findViewById(R.id.ivStepperPlus);
99 |
100 | String text = "";
101 | Drawable background = null;
102 | Drawable contentBackground = null;
103 | Drawable leftButtonResources = null;
104 | Drawable rightButtonResources = null;
105 | Drawable leftButtonBackground = null;
106 | Drawable rightButtonBackground = null;
107 | int contentTextColor = getResources().getColor(R.color.cl_snappingstepper_text);
108 | float contentTextSize = 0;
109 | if (attrs != null) {
110 | TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SnappingStepper);
111 | int modeValue = a.getInt(R.styleable.SnappingStepper_mode, Mode.AUTO.getValue());
112 | mode = Mode.valueOf(modeValue);
113 | minValue = a.getInt(R.styleable.SnappingStepper_min, minValue);
114 | maxValue = a.getInt(R.styleable.SnappingStepper_max, maxValue);
115 | value = valueRangeCheck(a.getInt(R.styleable.SnappingStepper_value, value));
116 | valueSlowStep = a.getInt(R.styleable.SnappingStepper_step, valueSlowStep);
117 | if (valueSlowStep <= 0) valueSlowStep = 1;
118 | text = a.getString(R.styleable.SnappingStepper_text);
119 |
120 | background = a.getDrawable(R.styleable.SnappingStepper_stepper_background);
121 | contentBackground = a.getDrawable(R.styleable.SnappingStepper_stepper_contentBackground);
122 | leftButtonResources = a.getDrawable(R.styleable.SnappingStepper_stepper_leftButtonResources);
123 | rightButtonResources = a.getDrawable(R.styleable.SnappingStepper_stepper_rightButtonResources);
124 | leftButtonBackground = a.getDrawable(R.styleable.SnappingStepper_stepper_leftButtonBackground);
125 | rightButtonBackground = a.getDrawable(R.styleable.SnappingStepper_stepper_rightButtonBackground);
126 |
127 | contentTextColor = a.getColor(R.styleable.SnappingStepper_stepper_contentTextColor, contentTextColor);
128 |
129 | contentTextSize = a.getFloat(R.styleable.SnappingStepper_stepper_contentTextSize, 0);
130 | a.recycle();
131 | }
132 |
133 | if (background != null) {
134 | setBackgroundDrawable(background);
135 | } else {
136 | setBackgroundResource(R.color.cl_snappingstepper_button_press);
137 | }
138 |
139 |
140 | if (contentBackground != null) {
141 | setContentBackground(contentBackground);
142 | }
143 | tvStepperContent.setTextColor(contentTextColor);
144 | if (contentTextSize > 0)
145 | setContentTextSize(contentTextSize);
146 |
147 | if (leftButtonBackground != null) {
148 | ivStepperMinus.setBackgroundDrawable(leftButtonBackground);
149 | }
150 | if (rightButtonBackground != null) {
151 | ivStepperPlus.setBackgroundDrawable(rightButtonBackground);
152 | }
153 |
154 | if (leftButtonResources != null) {
155 | setLeftButtonResources(leftButtonResources);
156 | }
157 | if (rightButtonResources != null) {
158 | setRightButtonResources(rightButtonResources);
159 | }
160 |
161 | if (mode == Mode.AUTO)//AUTO模式,写数值到滑动条上
162 | tvStepperContent.setText(String.valueOf(value));
163 | else
164 | tvStepperContent.setText(text);
165 |
166 | //设置后onclick产生的点击状态会失效
167 | ivStepperMinus.setOnTouchListener(this);
168 | ivStepperPlus.setOnTouchListener(this);
169 | setOnTouchListener(this);
170 |
171 | updateRunnable = new UpdateRunnable(this);
172 | }
173 |
174 |
175 | @Override
176 | public boolean onTouch(View v, MotionEvent event) {
177 | switch (event.getAction()) {
178 | case MotionEvent.ACTION_DOWN:
179 | stepTouch = true;
180 | postDelayed(updateRunnable, UPDATEDURATIONSLOW);
181 | //非按钮则记录位置
182 | startX = event.getX();
183 | initStartStepperContentLeft();
184 | startTime = System.currentTimeMillis();
185 | //如果是两边的按钮,分别设置为点击状态
186 | if (v == ivStepperMinus) {
187 | ivStepperMinus.setPressed(true);
188 | status = STATUS_MIMNUS;
189 | break;
190 | } else if (v == ivStepperPlus) {
191 | ivStepperPlus.setPressed(true);
192 | status = STATUS_PLUS;
193 | break;
194 | }
195 | break;
196 | case MotionEvent.ACTION_MOVE:
197 | //是按钮则不能移动,恢复位置的动画中也不能移动
198 | if (v == ivStepperMinus || v == ivStepperPlus || animationing) break;
199 | //非按钮则进行移动
200 | float moveX = event.getX() - startX;
201 | float x = moveX + startStepperContentLeft;
202 | moveStepperContent(x);
203 | moveEffectStatus(moveX);
204 | break;
205 | case MotionEvent.ACTION_UP:
206 | case MotionEvent.ACTION_CANCEL:
207 | stepTouch = false;
208 | //如果是两边的按钮,分别设置为点击状态
209 | if (v == ivStepperMinus) {
210 | ivStepperMinus.setPressed(false);
211 | break;
212 | } else if (v == ivStepperPlus) {
213 | ivStepperPlus.setPressed(false);
214 | break;
215 | }
216 | restoreStepperContent();
217 | break;
218 | }
219 | return true;
220 | }
221 |
222 | private void initStartStepperContentLeft() {
223 | if (hasStepperContentLeft) return;
224 | hasStepperContentLeft = true;
225 | startStepperContentLeft = tvStepperContent.getLeft();
226 | }
227 |
228 | /**
229 | * 中间滑条恢复原位置
230 | */
231 | private void restoreStepperContent() {
232 | if (animationing) return;
233 | animationing = true;
234 | ValueAnimator restoreTranslateAnimation = ValueAnimator.ofFloat(tvStepperContent.getLeft(), (int) startStepperContentLeft);
235 | restoreTranslateAnimation.setDuration(ANIMATIONDURATION);
236 | restoreTranslateAnimation.addListener(this);
237 | restoreTranslateAnimation.addUpdateListener(this);
238 | restoreTranslateAnimation.setInterpolator(new AccelerateInterpolator());
239 | restoreTranslateAnimation.start();
240 | }
241 |
242 | /**
243 | * 移动位置
244 | *
245 | * @param x
246 | */
247 | private void moveStepperContent(float x) {
248 | RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
249 | params.leftMargin = (int) x;
250 | //限制子控件移动必须在视图范围内
251 | if (params.leftMargin < 0 || (params.leftMargin + tvStepperContent.getWidth()) > getWidth())
252 | return;
253 | params.topMargin = 0;
254 | params.width = tvStepperContent.getWidth();
255 | params.height = tvStepperContent.getHeight();
256 |
257 | tvStepperContent.setLayoutParams(params);
258 | }
259 |
260 | @Override
261 | public void onAnimationUpdate(ValueAnimator animation) {
262 | Float value = (Float) animation.getAnimatedValue();
263 | moveStepperContent(value);
264 | }
265 |
266 | private void moveEffectStatus(float x) {
267 | int scaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
268 | if (x > scaledTouchSlop) {
269 | status = STATUS_PLUS;
270 | } else if (x < -scaledTouchSlop) {
271 | status = STATUS_MIMNUS;
272 | } else {
273 | status = STATUS_NORMAL;
274 | }
275 | }
276 |
277 | private int getNextValue() {
278 | switch (status) {
279 | case STATUS_MIMNUS:
280 | return value - valueSlowStep;
281 | case STATUS_PLUS:
282 | return value + valueSlowStep;
283 | case STATUS_NORMAL:
284 | return value;
285 | }
286 | return value;
287 | }
288 |
289 | private void updateUI() {
290 | int nextValue = getNextValue();
291 | //判断是否在范围之内
292 | if (nextValue < minValue) {
293 | nextValue = minValue;
294 | }
295 | if (nextValue > maxValue) {
296 | nextValue = maxValue;
297 | }
298 | value = nextValue;
299 | if (mode == Mode.AUTO)//AUTO模式,写数值到滑动条上
300 | tvStepperContent.setText(String.valueOf(value));
301 | if (listener != null)
302 | listener.onValueChange(this, value);
303 | if (stepTouch)
304 | postDelayed(updateRunnable, (System.currentTimeMillis() - startTime > STEPSPEEDCHANGEDURATION) ? UPDATEDURATIONFAST : UPDATEDURATIONSLOW);
305 | }
306 |
307 | @Override
308 | public void onAnimationStart(Animator animation) {
309 |
310 | }
311 |
312 | @Override
313 | public void onAnimationEnd(Animator animation) {
314 | animationing = false;
315 | }
316 |
317 | @Override
318 | public void onAnimationCancel(Animator animation) {
319 |
320 | }
321 |
322 | @Override
323 | public void onAnimationRepeat(Animator animation) {
324 |
325 | }
326 |
327 |
328 | static class UpdateRunnable implements Runnable {
329 | private WeakReference view;
330 |
331 | public UpdateRunnable(SnappingStepper view) {
332 | this.view = new WeakReference(view);
333 | }
334 |
335 | public void run() {
336 | SnappingStepper stepper = view.get();
337 | if (stepper != null) {
338 | stepper.updateUI();
339 | }
340 | }
341 | }
342 |
343 | public void setOnValueChangeListener(SnappingStepperValueChangeListener listener) {
344 | this.listener = listener;
345 | }
346 |
347 | /**
348 | * 返回当前模式类型
349 | *
350 | * @return
351 | */
352 | public Mode getMode() {
353 | return mode;
354 | }
355 |
356 | /**
357 | * 模式设置 AUTO(0) 数值写到滑动条, CUSTOM(1) 自定义文字;
358 | *
359 | * @param mode
360 | */
361 | public void setMode(Mode mode) {
362 | this.mode = mode;
363 | }
364 |
365 | /**
366 | * 获取当前值
367 | *
368 | * @return
369 | */
370 | public int getValue() {
371 | return value;
372 | }
373 |
374 | /**
375 | * 设置当前值
376 | *
377 | * @param value
378 | */
379 | public void setValue(int value) {
380 | this.value = valueRangeCheck(value);
381 | if (mode == Mode.AUTO)//AUTO模式,写数值到滑动条上
382 | tvStepperContent.setText(String.valueOf(value));
383 | }
384 |
385 | public int valueRangeCheck(int value) {
386 | if (value > maxValue) value = maxValue;
387 | else if (value < minValue) value = minValue;
388 | return value;
389 | }
390 |
391 | /**
392 | * 获取最小值
393 | *
394 | * @return
395 | */
396 | public int getMinValue() {
397 | return minValue;
398 | }
399 |
400 | /**
401 | * 设置最小值
402 | *
403 | * @return
404 | */
405 | public void setMinValue(int minValue) {
406 | this.minValue = minValue;
407 | }
408 |
409 | /**
410 | * 获取最大值
411 | *
412 | * @return
413 | */
414 | public int getMaxValue() {
415 | return maxValue;
416 | }
417 |
418 | /**
419 | * 设置最大值
420 | *
421 | * @return
422 | */
423 | public void setMaxValue(int maxValue) {
424 | this.maxValue = maxValue;
425 | }
426 |
427 | /**
428 | * 获取步长
429 | *
430 | * @return
431 | */
432 | public int getValueSlowStep() {
433 | return valueSlowStep;
434 | }
435 |
436 | /**
437 | * 设置步长
438 | *
439 | * @return
440 | */
441 | public void setValueSlowStep(int valueSlowStep) {
442 | this.valueSlowStep = valueSlowStep;
443 | }
444 |
445 | /**
446 | * 设置中间内容滑条颜色
447 | *
448 | * @param resId
449 | */
450 | public void setContentBackground(int resId) {
451 | tvStepperContent.setBackgroundResource(resId);
452 | }
453 |
454 | public void setContentBackground(Drawable drawable) {
455 | tvStepperContent.setBackgroundDrawable(drawable);
456 | }
457 |
458 | /**
459 | * 设置中间内容文字颜色
460 | *
461 | * @param resId
462 | */
463 | public void setContentTextColor(int resId) {
464 | tvStepperContent.setTextColor(getResources().getColor(resId));
465 | }
466 |
467 | /**
468 | * 设置中间内容文字,mode需为Custom才支持
469 | *
470 | * @param text
471 | */
472 | public void setText(String text) {
473 | tvStepperContent.setText(text);
474 | }
475 |
476 | /**
477 | * 设置中间内容文字大小
478 | *
479 | * @param size
480 | */
481 | public void setContentTextSize(float size) {
482 | tvStepperContent.setTextSize(size);
483 | }
484 |
485 | /**
486 | * 设置按钮背景
487 | *
488 | * @param resId
489 | */
490 | public void setButtonBackGround(int resId) {
491 | ivStepperMinus.setBackgroundResource(resId);
492 | ivStepperPlus.setBackgroundResource(resId);
493 | }
494 |
495 | /**
496 | * 设置按钮资源
497 | *
498 | * @param resId
499 | */
500 | public void setLeftButtonResources(int resId) {
501 | ivStepperMinus.setImageResource(resId);
502 | }
503 |
504 | /**
505 | * 设置按钮资源
506 | *
507 | * @param drawable
508 | */
509 | public void setLeftButtonResources(Drawable drawable) {
510 | ivStepperMinus.setImageDrawable(drawable);
511 | }
512 |
513 | /**
514 | * 设置按钮资源
515 | *
516 | * @param resId
517 | */
518 | public void setRightButtonResources(int resId) {
519 | ivStepperPlus.setImageResource(resId);
520 | }
521 |
522 | /**
523 | * 设置按钮资源
524 | *
525 | * @param drawable
526 | */
527 | public void setRightButtonResources(Drawable drawable) {
528 | ivStepperPlus.setImageDrawable(drawable);
529 | }
530 | }
531 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/java/com/bigkoo/snappingstepper/listener/SnappingStepperValueChangeListener.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepper.listener;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by Sai on 16/1/15.
7 | */
8 | public interface SnappingStepperValueChangeListener {
9 | public void onValueChange(View view ,int value);
10 | }
11 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/drawable-xxhdpi/ic_snappingstepper_minus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/snappingstepper/src/main/res/drawable-xxhdpi/ic_snappingstepper_minus.png
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/drawable-xxhdpi/ic_snappingstepper_plus.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/open-android/ShoppingCartAddSubtract/6c654fc0a3c2713372f29b60ca7d8a8fd38fa759/snappingstepper/src/main/res/drawable-xxhdpi/ic_snappingstepper_plus.png
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/drawable/sl_snappingstepper_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/layout/view_snappingstepper.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
28 |
29 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #237bb6
4 | #1f567b
5 | #2b8ccd
6 | #000000
7 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 30dp
4 | 10dp
5 | 15sp
6 |
--------------------------------------------------------------------------------
/snappingstepper/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | SnappingStepper
3 |
4 |
--------------------------------------------------------------------------------
/snappingstepper/src/test/java/com/bigkoo/snappingstepper/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.bigkoo.snappingstepper;
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 | }
--------------------------------------------------------------------------------