├── .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 │ │ └── edu │ │ └── counterview │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── edu │ │ │ └── counterview │ │ │ ├── CounterListner.java │ │ │ └── CounterView.java │ └── res │ │ ├── layout │ │ └── item_counter.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── edu │ └── counterview │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshot.gif └── settings.gradle /.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 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | Android 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 63 | 64 | 65 | 66 | 1.8 67 | 68 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CounterView 2 | This is an Android library for UI which can be used as a counter view as in Flipkart, Shopclues, Myntra etc. This is highly customizable and is very simple to integrate. 3 | 4 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-CounterView-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/6532) 5 | 6 | ## Preview 7 | 8 | ![Sample](/screenshot.gif?raw=true "Preview") 9 | 10 | ## Installation 11 | ### Gradle 12 | Add below code in build.gradle 13 | ``` 14 | allprojects { 15 | repositories { 16 | maven { url 'https://jitpack.io' } 17 | } 18 | } 19 | ``` 20 | Add a dependency 21 | ``` 22 | dependencies { 23 | compile 'com.github.AnkitKiet:CounterView:1.4' 24 | } 25 | ``` 26 | 27 | ### Maven 28 | Add below code for Maven installation 29 | ``` 30 | 31 | 32 | jitpack.io 33 | https://jitpack.io 34 | 35 | 36 | ``` 37 | Add a dependency 38 | ``` 39 | 40 | com.github.AnkitKiet 41 | CounterView 42 | 1.4 43 | 44 | ``` 45 | 46 | ## How To Use 47 | 48 | paste below code in java file 49 | 50 | ``` 51 |       CounterView cv = (CounterView) findViewById(R.id.cv); 52 | cv.setStartCounterValue("1"); 53 | cv.setColor(R.color.colorPrimaryDark, R.color.colorPrimary, R.color.colorAccent); 54 | cv.setCounterListener(new CounterListner() { 55 | @Override 56 | public void onIncClick(String s) { 57 | 58 | Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show(); 59 | // Perform Anything 60 | } 61 | 62 | @Override 63 | public void onDecClick(String s) { 64 | Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show(); 65 | //Perform Anything 66 | } 67 | }); 68 | 69 | ``` 70 | paste below code in layout xml file. 71 | ``` 72 | 76 | ``` 77 | 78 | ### Want to Contribute? 79 | Fork this repo and contribute by making a making a Pull Request. Enjoy Coding :) 80 | 81 | ## License 82 | ``` 83 | Copyright 2017 Ankit Maurya 84 | 85 | Licensed under the Apache License, Version 2.0 (the "License"); 86 | you may not use this file except in compliance with the License. 87 | You may obtain a copy of the License at 88 | 89 | http://www.apache.org/licenses/LICENSE-2.0 90 | 91 | Unless required by applicable law or agreed to in writing, software 92 | distributed under the License is distributed on an "AS IS" BASIS, 93 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 94 | See the License for the specific language governing permissions and 95 | limitations under the License. 96 | ``` 97 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'com.github.dcendents.android-maven' 3 | group='com.github.AnkitKiet' 4 | 5 | android { 6 | compileSdkVersion 25 7 | buildToolsVersion "25.0.3" 8 | defaultConfig { 9 | minSdkVersion 10 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(dir: 'libs', include: ['*.jar']) 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile 'com.android.support:appcompat-v7:25.+' 29 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 30 | testCompile 'junit:junit:4.12' 31 | } 32 | -------------------------------------------------------------------------------- /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/Ankit/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/edu/counterview/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package edu.counterview; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("edu.counterview", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/edu/counterview/CounterListner.java: -------------------------------------------------------------------------------- 1 | package edu.counterview; 2 | 3 | /** 4 | * Created by Ankit on 06/12/17. 5 | */ 6 | 7 | 8 | 9 | public interface CounterListner { 10 | void onIncClick(String value); 11 | 12 | void onDecClick(String value); 13 | } -------------------------------------------------------------------------------- /app/src/main/java/edu/counterview/CounterView.java: -------------------------------------------------------------------------------- 1 | package edu.counterview; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.ColorRes; 5 | import android.support.annotation.StringRes; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.LinearLayout; 10 | import android.widget.TextView; 11 | 12 | public class CounterView extends LinearLayout implements View.OnClickListener { 13 | 14 | 15 | public static final String TAG = CounterView.class.getSimpleName(); 16 | private TextView itemCounterValue; 17 | private Button incButton; 18 | private Button decButton; 19 | private LinearLayout rootView; 20 | private CounterListner listener; 21 | 22 | 23 | public CounterView(Context context) { 24 | super(context); 25 | init(context, null, 0); 26 | 27 | } 28 | 29 | public CounterView(Context context, AttributeSet attrs) { 30 | super(context, attrs); 31 | init(context, attrs, 0); 32 | } 33 | 34 | public CounterView(Context context, AttributeSet attrs, int defStyleAttr) { 35 | super(context, attrs, defStyleAttr); 36 | init(context, attrs, defStyleAttr); 37 | 38 | } 39 | 40 | private void init(Context context, AttributeSet attrs, int defStyle) { 41 | inflate(context, R.layout.item_counter, this); 42 | this.rootView = (LinearLayout) findViewById(R.id.root_view); 43 | this.itemCounterValue = (TextView) findViewById(R.id.item_counter_value); 44 | this.incButton = (Button) findViewById(R.id.inc_button); 45 | this.decButton = (Button) findViewById(R.id.dec_button); 46 | this.incButton.setOnClickListener(this); 47 | this.decButton.setOnClickListener(this); 48 | 49 | } 50 | 51 | 52 | public CounterView setStartCounterValue(String startValue) { 53 | if (this.itemCounterValue != null) 54 | this.itemCounterValue.setText(startValue); 55 | return this; 56 | } 57 | 58 | public CounterView setStartCounterValue(@StringRes int startValue) { 59 | if (this.itemCounterValue != null) 60 | this.itemCounterValue.setText(getString(startValue)); 61 | return this; 62 | } 63 | 64 | public CounterView setCounterListener(CounterListner counterListener) { 65 | listener = counterListener; 66 | return this; 67 | } 68 | 69 | public String getCounterValue() { 70 | String text = ""; 71 | if (this.itemCounterValue != null) 72 | text = this.itemCounterValue.getText().toString(); 73 | return text; 74 | } 75 | 76 | private String getString(@StringRes int textResourceValue) { 77 | return getContext().getString(textResourceValue); 78 | } 79 | 80 | public CounterView setColor(@ColorRes int left, @ColorRes int right, @ColorRes int text) { 81 | 82 | this.incButton.setBackgroundColor(getColor(right)); 83 | this.decButton.setBackgroundColor(getColor(left)); 84 | this.itemCounterValue.setTextColor(getColor(text)); 85 | return this; 86 | } 87 | 88 | private int getColor(@ColorRes int colorRes) { 89 | return getContext().getResources().getColor(colorRes); 90 | } 91 | 92 | @Override 93 | public void onClick(View view) { 94 | int value = 0; 95 | value = Integer.parseInt(this.itemCounterValue.getText().toString()); 96 | int i = view.getId(); 97 | if (i == R.id.inc_button) { 98 | value++; 99 | this.itemCounterValue.setText(String.valueOf(value)); 100 | if (this.listener != null) 101 | this.listener.onIncClick(this.itemCounterValue.getText().toString()); 102 | } else if (i == R.id.dec_button) { 103 | value--; 104 | if (value < 1) { 105 | value = 1; 106 | } 107 | this.itemCounterValue.setText(String.valueOf(value)); 108 | if (this.listener != null) 109 | this.listener.onDecClick(this.itemCounterValue.getText().toString()); 110 | } 111 | } 112 | 113 | 114 | } 115 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_counter.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |