From b1bd5cbd72a908bf2a42f454b41f3da864f788e9 Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Sun, 25 Sep 2016 07:01:18 +0200 Subject: [PATCH 1/4] Fix of NPE in button by moving method implementations. Added tint ability for floating as workaround. Added warning logs. --- .../com/gc/materialdesign/views/Button.java | 18 +++------- .../gc/materialdesign/views/ButtonFlat.java | 14 +++++--- .../gc/materialdesign/views/ButtonFloat.java | 34 ++++++++++++++++--- .../materialdesign/views/ButtonRectangle.java | 20 +++++++++++ 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Button.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Button.java index db24638..a3171b2 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Button.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Button.java @@ -30,7 +30,7 @@ public abstract class Button extends CustomView { OnClickListener onClickListener; boolean clickAfterRipple = true; int backgroundColor = Color.parseColor("#1E88E5"); - TextView textButton; + public Button(Context context, AttributeSet attrs) { super(context, attrs); @@ -181,19 +181,11 @@ public float getRippleSpeed() { return this.rippleSpeed; } - public void setText(String text) { - textButton.setText(text); - } + public abstract void setText(String text); - public void setTextColor(int color) { - textButton.setTextColor(color); - } + public abstract void setTextColor(int color); - public TextView getTextView() { - return textButton; - } + public abstract TextView getTextView(); - public String getText() { - return textButton.getText().toString(); - } + public abstract String getText(); } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java index b1664c9..de89d26 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFlat.java @@ -96,10 +96,7 @@ protected int makePressColor(){ return Color.parseColor("#88DDDDDD"); } - public void setText(String text){ - textButton.setText(text.toUpperCase()); - } - + // Set color of background public void setBackgroundColor(int color){ backgroundColor = color; @@ -117,4 +114,13 @@ public String getText(){ return textButton.getText().toString(); } + public void setText(String text){ + textButton.setText(text.toUpperCase()); + } + + @Override + public void setTextColor(int color) { + textButton.setTextColor(color); + } + } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFloat.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFloat.java index b4970b9..5d4299f 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFloat.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFloat.java @@ -11,6 +11,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.PorterDuff; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; @@ -18,7 +19,10 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.LayerDrawable; +import android.support.annotation.ColorInt; +import android.support.v4.view.TintableBackgroundView; import android.util.AttributeSet; +import android.util.Log; import android.view.animation.BounceInterpolator; import android.widget.ImageView; import android.widget.ImageView.ScaleType; @@ -175,11 +179,6 @@ public Bitmap cropCircle(Bitmap bitmap) { return output; } - @Override - public TextView getTextView() { - return null; - } - public void setRippleColor(int rippleColor) { this.rippleColor = rippleColor; } @@ -205,5 +204,30 @@ public void hide(){ public boolean isShow(){ return isShow; } + + @Override + public TextView getTextView() { + Log.e("ButtonFloat", "getTextView() - no text view on float button"); + return null; + } + + @Override + public String getText() { + Log.e("ButtonFloat", "getText() - no text view on float button"); + return null; + } + + @Override + public void setText(String text) { + Log.e("ButtonFloat", "ButtonFloat does not have a text"); + } + + @Override + public void setTextColor(int color) { + if (drawableIcon != null){ + Log.w("ButtonFloat", "ButtonFloat does not have a text, will try to tint image, but make sure this is what you want"); + drawableIcon.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); + } + } } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java index e261c7d..b61eb66 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonRectangle.java @@ -146,5 +146,25 @@ protected void onDraw(Canvas canvas) { invalidate(); } } + + @Override + public void setText(String text) { + textButton.setText(text); + } + + @Override + public void setTextColor(int color) { + textButton.setTextColor(color); + } + + @Override + public TextView getTextView() { + return textButton; + } + + @Override + public String getText() { + return textButton.getText().toString(); + } } From 030d9486820c83b738705309f22246d55bccf522 Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Sun, 25 Sep 2016 07:01:33 +0200 Subject: [PATCH 2/4] Simple test of tint ability --- .../java/com/gc/materialdesigndemo/ui/ButtonsActivity.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java index 617d194..14be7c4 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java @@ -6,6 +6,7 @@ import android.os.Bundle; import android.view.Window; +import com.gc.materialdesign.views.ButtonFloat; import com.gc.materialdesigndemo.R; @@ -26,6 +27,10 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.buttonFloatSmall).setBackgroundColor(color); findViewById(R.id.buttonIcon).setBackgroundColor(color); findViewById(R.id.buttonFloat).setBackgroundColor(color); + + // Quick test of tint + ButtonFloat buttonFloat = (ButtonFloat) findViewById(R.id.buttonFloat); + buttonFloat.setTextColor(Color.RED); } From d3920a5a24e9ebbaf7ac6d14b8d236fdcc0f07df Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Sun, 25 Sep 2016 07:02:48 +0200 Subject: [PATCH 3/4] Removal of tint test --- .../java/com/gc/materialdesigndemo/ui/ButtonsActivity.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java index 14be7c4..617d194 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ButtonsActivity.java @@ -6,7 +6,6 @@ import android.os.Bundle; import android.view.Window; -import com.gc.materialdesign.views.ButtonFloat; import com.gc.materialdesigndemo.R; @@ -27,10 +26,6 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.buttonFloatSmall).setBackgroundColor(color); findViewById(R.id.buttonIcon).setBackgroundColor(color); findViewById(R.id.buttonFloat).setBackgroundColor(color); - - // Quick test of tint - ButtonFloat buttonFloat = (ButtonFloat) findViewById(R.id.buttonFloat); - buttonFloat.setTextColor(Color.RED); } From 0a6b8aec88211f6f3f39843562ca35666b09adcd Mon Sep 17 00:00:00 2001 From: Christian Ruppert Date: Sun, 25 Sep 2016 13:29:02 +0200 Subject: [PATCH 4/4] Gradle update --- MaterialDesignLibrary/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MaterialDesignLibrary/build.gradle b/MaterialDesignLibrary/build.gradle index 7a979d7..a09d8fa 100644 --- a/MaterialDesignLibrary/build.gradle +++ b/MaterialDesignLibrary/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.+' + classpath 'com.android.tools.build:gradle:2.2.0' // COMMENT TO DEVELOPER MODE / UNCOMMENT TO UPLOAD TO BINTARRAY // classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5' // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' diff --git a/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties b/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties index 707f4c9..c859f42 100644 --- a/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties +++ b/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Aug 22 18:02:59 CEST 2015 +#Sun Sep 25 06:58:35 CEST 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip