Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/zero at decrease nominal #2

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
.idea/**/workspace.xml
.idea/**/gradle.xml
.idea/**/libraries
.gradle/
build/
local.properties
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
.idea/caches
.idea/codeStyles
.idea/misc.xml
15 changes: 1 addition & 14 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ apply plugin: 'com.github.dcendents.android-maven'
group='com.github.AnkitKiet'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
minSdkVersion 11
targetSdkVersion 27
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -21,11 +21,11 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation('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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@



public interface CounterListner {
public interface CounterListener {
void onIncClick(String value);

void onDecClick(String value);
Expand Down
33 changes: 15 additions & 18 deletions app/src/main/java/edu/counterview/CounterView.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@

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;
private CounterListener listener;

private boolean isMinusSupported;

public CounterView(Context context) {
super(context);
init(context, null, 0);

}

public CounterView(Context context, AttributeSet attrs) {
Expand All @@ -34,21 +33,18 @@ public CounterView(Context context, AttributeSet attrs) {
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.item_counter, 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.rootView = findViewById(R.id.root_view);
this.itemCounterValue = findViewById(R.id.item_counter_value);
this.incButton = findViewById(R.id.inc_button);
this.decButton = 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);
Expand All @@ -61,7 +57,7 @@ public CounterView setStartCounterValue(@StringRes int startValue) {
return this;
}

public CounterView setCounterListener(CounterListner counterListener) {
public CounterView setCounterListener(CounterListener counterListener) {
listener = counterListener;
return this;
}
Expand All @@ -78,7 +74,6 @@ private String getString(@StringRes int textResourceValue) {
}

public CounterView setColor(@ColorRes int left, @ColorRes int right, @ColorRes int text) {

this.incButton.setBackgroundColor(getColor(right));
this.decButton.setBackgroundColor(getColor(left));
this.itemCounterValue.setTextColor(getColor(text));
Expand All @@ -89,10 +84,14 @@ private int getColor(@ColorRes int colorRes) {
return getContext().getResources().getColor(colorRes);
}

public CounterView setMinus(boolean isSupported) {
this.isMinusSupported = isSupported;
return this;
}

@Override
public void onClick(View view) {
int value = 0;
value = Integer.parseInt(this.itemCounterValue.getText().toString());
int value = Integer.parseInt(this.itemCounterValue.getText().toString());
int i = view.getId();
if (i == R.id.inc_button) {
value++;
Expand All @@ -101,14 +100,12 @@ public void onClick(View view) {
this.listener.onIncClick(this.itemCounterValue.getText().toString());
} else if (i == R.id.dec_button) {
value--;
if (value < 1) {
value = 1;
if (value < 0 && !isMinusSupported) {
value = 0;
}
this.itemCounterValue.setText(String.valueOf(value));
if (this.listener != null)
this.listener.onDecClick(this.itemCounterValue.getText().toString());
}
}


}
14 changes: 10 additions & 4 deletions app/src/main/res/layout/item_counter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@
android:layout_height="25dp"
android:layout_weight="0.5"
android:background="@color/colorPrimary"
android:text="-"
android:text="@string/decrement"
android:textColor="#ffffff" />

<TextView
android:id="@+id/item_counter_value"
android:layout_width="25dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_weight="0.5"
android:text="1"
android:gravity="center"
android:minWidth="32dp"
android:text="@string/default_value"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
Expand All @@ -32,7 +38,7 @@
android:layout_height="25dp"
android:layout_weight="0.5"
android:background="@color/colorPrimaryDark"
android:text="+"
android:text="@string/increment"
android:textColor="#ffffff" />


Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<resources>
<string name="app_name">CounterView</string>
<string name="increment">+</string>
<string name="decrement">-</string>
<string name="default_value">0</string>
</resources>
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip