From f92458588b44ac7379a8a58142eede7d02325a88 Mon Sep 17 00:00:00 2001 From: Ankit Maurya Date: Wed, 6 Dec 2017 17:25:22 +0530 Subject: [PATCH] Initial commit --- .gitignore | 9 + .idea/compiler.xml | 22 +++ .idea/copyright/profiles_settings.xml | 3 + .idea/encodings.xml | 6 + .idea/gradle.xml | 18 ++ .idea/misc.xml | 78 +++++++++ .idea/modules.xml | 9 + .idea/runConfigurations.xml | 12 ++ app/.gitignore | 1 + app/build.gradle | 31 ++++ app/proguard-rules.pro | 25 +++ .../counterview/ExampleInstrumentedTest.java | 26 +++ app/src/main/AndroidManifest.xml | 10 ++ .../java/edu/counterview/CounterListner.java | 13 ++ .../java/edu/counterview/CounterView.java | 114 +++++++++++++ app/src/main/res/layout/activity_main.xml | 39 +++++ app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 ++ .../java/edu/counterview/ExampleUnitTest.java | 17 ++ build.gradle | 25 +++ gradle.properties | 17 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 160 ++++++++++++++++++ gradlew.bat | 90 ++++++++++ settings.gradle | 1 + 27 files changed, 752 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/edu/counterview/ExampleInstrumentedTest.java create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/edu/counterview/CounterListner.java create mode 100644 app/src/main/java/edu/counterview/CounterView.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/edu/counterview/ExampleUnitTest.java create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..085136f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + Android + + + + + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..94a99da --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..2674b16 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.library' +apply plugin: 'com.github.dcendents.android-maven' +group='com.github.AnkitKiet' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.3" + defaultConfig { + minSdkVersion 22 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:25.+' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..86bb423 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/Ankit/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/edu/counterview/ExampleInstrumentedTest.java b/app/src/androidTest/java/edu/counterview/ExampleInstrumentedTest.java new file mode 100644 index 0000000..0ebd763 --- /dev/null +++ b/app/src/androidTest/java/edu/counterview/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package edu.counterview; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("edu.counterview", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..abd5e3b --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/edu/counterview/CounterListner.java b/app/src/main/java/edu/counterview/CounterListner.java new file mode 100644 index 0000000..0ba17ab --- /dev/null +++ b/app/src/main/java/edu/counterview/CounterListner.java @@ -0,0 +1,13 @@ +package edu.counterview; + +/** + * Created by Ankit on 06/12/17. + */ + + + +public interface CounterListner { + void onIncClick(String value); + + void onDecClick(String value); +} \ No newline at end of file diff --git a/app/src/main/java/edu/counterview/CounterView.java b/app/src/main/java/edu/counterview/CounterView.java new file mode 100644 index 0000000..cf42333 --- /dev/null +++ b/app/src/main/java/edu/counterview/CounterView.java @@ -0,0 +1,114 @@ +package edu.counterview; + +import android.content.Context; +import android.support.annotation.ColorRes; +import android.support.annotation.StringRes; +import android.util.AttributeSet; +import android.view.View; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + +public class CounterView extends LinearLayout implements View.OnClickListener { + + + public static final String TAG = CounterView.class.getSimpleName(); + private TextView itemCounterValue; + private Button incButton; + private Button decButton; + private LinearLayout rootView; + private CounterListner listener; + + + public CounterView(Context context) { + super(context); + init(context, null, 0); + + } + + public CounterView(Context context, AttributeSet attrs) { + super(context, attrs); + init(context, attrs, 0); + } + + public CounterView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context, attrs, defStyleAttr); + + } + + private void init(Context context, AttributeSet attrs, int defStyle) { + inflate(context, R.layout.activity_main, this); + this.rootView = (LinearLayout) findViewById(R.id.root_view); + this.itemCounterValue = (TextView) findViewById(R.id.item_counter_value); + this.incButton = (Button) findViewById(R.id.inc_button); + this.decButton = (Button) findViewById(R.id.dec_button); + this.incButton.setOnClickListener(this); + this.decButton.setOnClickListener(this); + + } + + + public CounterView setStartCounterValue(String startValue) { + if (this.itemCounterValue != null) + this.itemCounterValue.setText(startValue); + return this; + } + + public CounterView setStartCounterValue(@StringRes int startValue) { + if (this.itemCounterValue != null) + this.itemCounterValue.setText(getString(startValue)); + return this; + } + + public CounterView setCounterListener(CounterListner counterListener) { + listener = counterListener; + return this; + } + + public String getCounterValue() { + String text = ""; + if (this.itemCounterValue != null) + text = this.itemCounterValue.getText().toString(); + return text; + } + + private String getString(@StringRes int textResourceValue) { + return getContext().getString(textResourceValue); + } + + private CounterView setColor(@ColorRes int left, @ColorRes int right, @ColorRes int text) { + + this.incButton.setBackgroundColor(getColor(right)); + this.decButton.setBackgroundColor(getColor(right)); + this.itemCounterValue.setBackgroundColor(getColor(text)); + return this; + } + + private int getColor(@ColorRes int colorRes) { + return getContext().getResources().getColor(colorRes); + } + + @Override + public void onClick(View view) { + int value = 0; + value = Integer.parseInt(this.itemCounterValue.getText().toString()); + int i = view.getId(); + if (i == R.id.inc_button) { + value++; + this.itemCounterValue.setText(String.valueOf(value)); + if (this.listener != null) + this.listener.onIncClick(this.itemCounterValue.getText().toString()); + } else if (i == R.id.dec_button) { + value--; + if (value < 1) { + value = 1; + } + this.itemCounterValue.setText(String.valueOf(value)); + if (this.listener != null) + this.listener.onDecClick(this.itemCounterValue.getText().toString()); + } + } + + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..bde6a8f --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,39 @@ + + + +