From 2f1061ec154f5f28094902b2a8b3098e5ac0c503 Mon Sep 17 00:00:00 2001 From: Dennis Murage Date: Fri, 29 Mar 2019 10:14:52 +0300 Subject: [PATCH] Add text style to buttons Separate size attributes for the textview and +/- buttons --- .gitignore | 8 + .idea/compiler.xml | 22 - .idea/copyright/profiles_settings.xml | 3 - .idea/gradle.xml | 19 - .idea/misc.xml | 46 - .idea/modules.xml | 10 - .idea/runConfigurations.xml | 12 - README.md | 24 +- .../view/ElegantNumberButton.java | 39 +- lib/src/main/res/layout/layout.xml | 9 +- lib/src/main/res/values/attrs.xml | 7 + projectFilesBackup/.idea/workspace.xml | 3190 ----------------- 12 files changed, 74 insertions(+), 3315 deletions(-) delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations.xml delete mode 100644 projectFilesBackup/.idea/workspace.xml diff --git a/.gitignore b/.gitignore index cd58028..b44e2ca 100644 --- a/.gitignore +++ b/.gitignore @@ -256,3 +256,11 @@ gradle-app.setting .DS_Store /build /captures +.idea/ + +## VScode files +.project +.settings/ + +### +projectFilesBackup/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 5d6f65c..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 5d19981..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 1a270ac..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index a0a6757..6b44356 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Grab the latest version on gradle using ```groovy -compile 'com.cepheuen.elegant-number-button:lib:1.0.2' +implementation 'com.cepheuen.elegant-number-button:lib:1.0.2' ``` or on maven @@ -62,17 +62,31 @@ For Working implementation of this library check ElegantNumberButtonSample App ## Customization -`backgroundColor` : Set button Background color +`backgroundColor` : Set the view Background color. + +`minusBackgroundColor` : Set the `-` control Background color. + +`plusBackgroundColor` : Set the `+` control Background color. `initialNumber`: Set initial number for the button. `finalNumber` : Set final number range for button. -`textColor`: Modify the text color of the button. +`textColor`: Modify the text color of the counter. + +`minusTextColor`: Modify the text color of the `-` control. + +`plusTextColor`: Modify the text color of the `+` control. + +`textStyle`: Modify the text style of the counter to one of [Bold, Italic, Normal]. + +`buttonTextStyle`: Modify the text style of both controls to one of [Bold, Italic, Normal]. + +`textSize`: Change text size of the counter. -`textSize`: Change text size of the button. +`buttonTextSize`: Change text size of both the controls. -`backgroundDrawable`: Add drawable background for the button. +`backgroundDrawable`: Add drawable background for the view. ## Methods diff --git a/lib/src/main/java/com/cepheuen/elegantnumberbutton/view/ElegantNumberButton.java b/lib/src/main/java/com/cepheuen/elegantnumberbutton/view/ElegantNumberButton.java index 17a2117..b590e31 100644 --- a/lib/src/main/java/com/cepheuen/elegantnumberbutton/view/ElegantNumberButton.java +++ b/lib/src/main/java/com/cepheuen/elegantnumberbutton/view/ElegantNumberButton.java @@ -5,10 +5,13 @@ import android.content.res.TypedArray; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.Build; +import android.support.v4.view.GravityCompat; import android.util.AttributeSet; import android.util.Log; +import android.view.Gravity; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; @@ -19,6 +22,7 @@ /** * Created by Ashik Vetrivelu on 10/08/16. + * Modified by Dennis Murage on 24/03/2019 */ public class ElegantNumberButton extends RelativeLayout { private Context context; @@ -31,7 +35,6 @@ public class ElegantNumberButton extends RelativeLayout { private int finalNumber; private TextView textView; private Button addBtn, subtractBtn; - private View view; private OnValueChangeListener mOnValueChangeListener; public ElegantNumberButton(Context context) { @@ -56,7 +59,6 @@ public ElegantNumberButton(Context context, AttributeSet attrs, int defStyleAttr } private void initView() { - this.view = this; inflate(context, R.layout.layout, this); final Resources res = getResources(); final int defaultColor = res.getColor(R.color.colorPrimary); @@ -68,8 +70,17 @@ private void initView() { initialNumber = a.getInt(R.styleable.ElegantNumberButton_initialNumber, 0); finalNumber = a.getInt(R.styleable.ElegantNumberButton_finalNumber, Integer.MAX_VALUE); float textSize = a.getDimension(R.styleable.ElegantNumberButton_textSize, 13); + float buttonTextSize = a.getDimension(R.styleable.ElegantNumberButton_buttonTextSize, 13); + String textStyle = "normal"; + textStyle = a.getString(R.styleable.ElegantNumberButton_textStyle); + String buttonTextStyle = "normal"; + buttonTextStyle = a.getString(R.styleable.ElegantNumberButton_buttonTextStyle); int color = a.getColor(R.styleable.ElegantNumberButton_backGroundColor, defaultColor); + int minusBackgroundColor = a.getColor(R.styleable.ElegantNumberButton_minusBackgroundColor, defaultColor); + int plusBackgroundColor = a.getColor(R.styleable.ElegantNumberButton_plusBackgroundColor, defaultColor); int textColor = a.getColor(R.styleable.ElegantNumberButton_textColor, defaultTextColor); + int minusTextColor = a.getColor(R.styleable.ElegantNumberButton_minusTextColor, defaultTextColor); + int plusTextColor = a.getColor(R.styleable.ElegantNumberButton_plusTextColor, defaultTextColor); Drawable drawable = a.getDrawable(R.styleable.ElegantNumberButton_backgroundDrawable); subtractBtn = (Button) findViewById(R.id.subtract_btn); @@ -77,13 +88,29 @@ private void initView() { textView = (TextView) findViewById(R.id.number_counter); LinearLayout mLayout = (LinearLayout) findViewById(R.id.layout); - subtractBtn.setTextColor(textColor); - addBtn.setTextColor(textColor); + subtractBtn.setTextColor(minusTextColor); + addBtn.setTextColor(plusTextColor); textView.setTextColor(textColor); - subtractBtn.setTextSize(textSize); - addBtn.setTextSize(textSize); + + subtractBtn.setBackgroundColor(minusBackgroundColor); + addBtn.setBackgroundColor(plusBackgroundColor); + mLayout.setBackgroundColor(color); + + subtractBtn.setTextSize(buttonTextSize); + addBtn.setTextSize(buttonTextSize); textView.setTextSize(textSize); + int mButtonStyle = buttonTextStyle.equals("bold") ? Typeface.BOLD : + buttonTextStyle.equals("italic") ? Typeface.ITALIC : Typeface.NORMAL; + + int mTextStyle = textStyle.equals("bold") ? Typeface.BOLD : + textStyle.equals("italic") ? Typeface.ITALIC : Typeface.NORMAL; + + addBtn.setTypeface(addBtn.getTypeface(), mButtonStyle); + subtractBtn.setTypeface(subtractBtn.getTypeface(), mButtonStyle); + + textView.setTypeface(textView.getTypeface(), mTextStyle); + if (drawable == null) { drawable = defaultDrawable; } diff --git a/lib/src/main/res/layout/layout.xml b/lib/src/main/res/layout/layout.xml index 62e834f..b5215b0 100644 --- a/lib/src/main/res/layout/layout.xml +++ b/lib/src/main/res/layout/layout.xml @@ -2,7 +2,7 @@