├── .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 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 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 | 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 | ![]( http://upload-images.jianshu.io/upload_images/4037105-ad779cfe6a715668.gif?imageMogr2/auto-orient/strip) 12 | 13 | * 爱生活,爱学习,更爱做代码的搬运工,分类查找更方便请下载黑马助手app 14 | 15 | 16 | ![黑马助手.png](http://upload-images.jianshu.io/upload_images/4037105-f777f1214328dcc4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 17 | 18 | ## 使用步骤 19 | ### 1. 在project的build.gradle添加如下代码(如下图) 20 | 21 | allprojects { 22 | repositories { 23 | ... 24 | maven { url "https://jitpack.io" } 25 | } 26 | } 27 | 28 | ![](http://oi5nqn6ce.bkt.clouddn.com/itheima/booster/code/jitpack.png) 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 | ![](http://oi5nqn6ce.bkt.clouddn.com/itheima/booster/code/qrcode.png) 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 |