From d09e6eacbc9b1069a01c016135d1867496d56916 Mon Sep 17 00:00:00 2001 From: Ivan Navas Date: Mon, 7 Nov 2016 20:31:43 +0100 Subject: [PATCH 01/13] Fix #15 issue --- .../gc/materialdesign/widgets/SnackBar.java | 64 +++++++++++++++---- .../src/main/res/layout/snackbar.xml | 6 +- .../materialdesigndemo/ui/WidgetActivity.java | 2 +- .../src/main/res/layout/activity_widgets.xml | 11 ++++ 4 files changed, 67 insertions(+), 16 deletions(-) diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java index 242abff..f8356c6 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java @@ -16,7 +16,10 @@ import android.widget.TextView; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.Utils; import com.gc.materialdesign.views.ButtonFlat; +import com.nineoldandroids.view.ViewHelper; +import com.nineoldandroids.view.ViewPropertyAnimator; public class SnackBar extends Dialog{ @@ -29,6 +32,8 @@ public class SnackBar extends Dialog{ ButtonFlat button; int backgroundSnackBar = Color.parseColor("#333333"); int backgroundButton = Color.parseColor("#1E88E5"); + + View pushUpView; OnHideListener onHideListener; // Timer @@ -93,6 +98,17 @@ public void show() { super.show(); view.setVisibility(View.VISIBLE); view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.snackbar_show_animation)); + view.post(new Runnable() { + @Override + public void run() { + if(pushUpView != null) + ViewPropertyAnimator.animate(pushUpView).y( + ViewHelper.getY(pushUpView) - view.getHeight()) + .setDuration(300) + .start(); + } + }); + if (!mIndeterminate) { dismissTimer.start(); } @@ -124,9 +140,6 @@ public boolean handleMessage(Message msg) { } }); - /** - * @author Jack Tony - */ @Override public void dismiss() { Animation anim = AnimationUtils.loadAnimation(activity, R.anim.snackbar_hide_animation); @@ -146,31 +159,46 @@ public void onAnimationEnd(Animation animation) { } }); view.startAnimation(anim); + if(pushUpView != null) + ViewPropertyAnimator.animate(pushUpView).y( + ViewHelper.getY(pushUpView) + view.getHeight()) + .setDuration(300) + .start(); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - // TODO 自动生成的方法存根 if (keyCode == KeyEvent.KEYCODE_BACK ) { dismiss(); } return super.onKeyDown(keyCode, event); } - public void setMessageTextSize(float size) { + public SnackBar setMessageTextSize(float size) { textSize = size; + return this; } - - public void setIndeterminate(boolean indeterminate) { - mIndeterminate = indeterminate; + + /** + * Set true to avoid hide the snackbar + * @param indeterminate + */ + public SnackBar setIndeterminate(boolean indeterminate) { + mIndeterminate = indeterminate; + return this; } public boolean isIndeterminate() { return mIndeterminate; } - public void setDismissTimer(int time) { + /** + * Sets the time to dismiss the snackbar + * @param time + */ + public SnackBar setDismissTimer(int time) { mTimer = time; + return this; } public int getDismissTimer() { @@ -181,20 +209,22 @@ public int getDismissTimer() { * Change background color of SnackBar * @param color */ - public void setBackgroundSnackBar(int color){ + public SnackBar setBackgroundSnackBar(int color){ backgroundSnackBar = color; if(view != null) view.setBackgroundColor(color); + return this; } /** * Chage color of FlatButton in Snackbar * @param color */ - public void setColorButton(int color){ + public SnackBar setColorButton(int color){ backgroundButton = color; if(button != null) button.setBackgroundColor(color); + return this; } /** @@ -205,8 +235,18 @@ public void setColorButton(int color){ public interface OnHideListener{ public void onHide(); } + + /** + * Sets the view to push up when the snackbar will show + * @param pushUpView + */ + public SnackBar setPushUpView(View pushUpView){ + this.pushUpView = pushUpView; + return this; + } - public void setOnhideListener(OnHideListener onHideListener){ + public SnackBar setOnhideListener(OnHideListener onHideListener){ this.onHideListener = onHideListener; + return this; } } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/snackbar.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/snackbar.xml index 0a1ce20..7d91b4f 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/snackbar.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/snackbar.xml @@ -6,7 +6,7 @@ + + \ No newline at end of file From 5583f693cd7c6b07607f697436abf02061b1f50d Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Mon, 7 Nov 2016 21:09:09 +0100 Subject: [PATCH 02/13] fixed issues: #23 #30 #45 --- .../gc/materialdesign/views/ButtonFlat.java | 29 ++- .../materialdesign/views/ButtonRectangle.java | 230 +++++++++--------- .../com/gc/materialdesign/views/CheckBox.java | 3 +- .../src/main/res/layout/activity_buttons.xml | 3 +- MaterialDesignLibrary/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 4 +- 6 files changed, 151 insertions(+), 120 deletions(-) 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..0d63559 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 @@ -16,6 +16,8 @@ public class ButtonFlat extends Button { TextView textButton; + int paddingTop, paddingBottom, paddingLeft, paddingRight; + public ButtonFlat(Context context, AttributeSet attrs) { super(context, attrs); @@ -25,6 +27,10 @@ protected void setDefaultProperties(){ minHeight = 36; minWidth = 88; rippleSize = 3; + paddingBottom = Utils.dpToPx(16, getResources()); + paddingLeft = Utils.dpToPx(16, getResources()); + paddingRight = Utils.dpToPx(16, getResources()); + paddingTop = Utils.dpToPx(16, getResources()); // Min size setMinimumHeight(Utils.dpToPx(minHeight, getResources())); setMinimumWidth(Utils.dpToPx(minWidth, getResources())); @@ -33,6 +39,27 @@ protected void setDefaultProperties(){ @Override protected void setAttributes(AttributeSet attrs) { + + // Set Padding + String value = attrs.getAttributeValue(ANDROIDXML, "padding"); + if (value != null) { + float padding = Float.parseFloat(value.replace("dip", "")); + paddingBottom = Utils.dpToPx(padding, getResources()); + paddingLeft = Utils.dpToPx(padding, getResources()); + paddingRight = Utils.dpToPx(padding, getResources()); + paddingTop = Utils.dpToPx(padding, getResources()); + } else { + value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); + paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); + paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); + paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); + paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); + } + setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + // Set text button String text = null; int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1); @@ -41,8 +68,8 @@ protected void setAttributes(AttributeSet attrs) { }else{ text = attrs.getAttributeValue(ANDROIDXML,"text"); } + textButton = new TextView(getContext()); if(text != null){ - textButton = new TextView(getContext()); textButton.setText(text.toUpperCase()); textButton.setTextColor(backgroundColor); textButton.setTypeface(null, Typeface.BOLD); 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..d5e5175 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 @@ -14,111 +14,112 @@ import android.widget.TextView; public class ButtonRectangle extends Button { - - TextView textButton; - - int paddingTop,paddingBottom, paddingLeft, paddingRight; - - - public ButtonRectangle(Context context, AttributeSet attrs) { - super(context, attrs); - setDefaultProperties(); - } - @Override - protected void setDefaultProperties(){ -// paddingBottom = Utils.dpToPx(16, getResources()); -// paddingLeft = Utils.dpToPx(16, getResources()); -// paddingRight = Utils.dpToPx(16, getResources()); -// paddingTop = Utils.dpToPx(16, getResources()); - super.minWidth = 80; - super.minHeight = 36; - super.background = R.drawable.background_button_rectangle; - super.setDefaultProperties(); - } - - - // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs){ - - //Set background Color - // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } - - // Set Padding - String value = attrs.getAttributeValue(ANDROIDXML,"padding"); -// if(value != null){ -// float padding = Float.parseFloat(value.replace("dip", "")); -// paddingBottom = Utils.dpToPx(padding, getResources()); -// paddingLeft = Utils.dpToPx(padding, getResources()); -// paddingRight = Utils.dpToPx(padding, getResources()); -// paddingTop = Utils.dpToPx(padding, getResources()); -// }else{ -// value = attrs.getAttributeValue(ANDROIDXML,"paddingLeft"); -// paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); -// value = attrs.getAttributeValue(ANDROIDXML,"paddingTop"); -// paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); -// value = attrs.getAttributeValue(ANDROIDXML,"paddingRight"); -// paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); -// value = attrs.getAttributeValue(ANDROIDXML,"paddingBottom"); -// paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); -// } - - - // Set text button - String text = null; - int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1); - if(textResource != -1){ - text = getResources().getString(textResource); - }else{ - text = attrs.getAttributeValue(ANDROIDXML,"text"); - } - if(text != null){ - textButton = new TextView(getContext()); - textButton.setText(text); - textButton.setTextColor(Color.WHITE); - textButton.setTypeface(null, Typeface.BOLD); - LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); - params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); - params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); - textButton.setLayoutParams(params); - addView(textButton); + + TextView textButton; + + int paddingTop, paddingBottom, paddingLeft, paddingRight; + + + public ButtonRectangle(Context context, AttributeSet attrs) { + super(context, attrs); + setDefaultProperties(); + } + + @Override + protected void setDefaultProperties() { + paddingBottom = Utils.dpToPx(16, getResources()); + paddingLeft = Utils.dpToPx(16, getResources()); + paddingRight = Utils.dpToPx(16, getResources()); + paddingTop = Utils.dpToPx(16, getResources()); + super.minWidth = 80; + super.minHeight = 36; + super.background = R.drawable.background_button_rectangle; + super.setDefaultProperties(); + } + + + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs) { + + //Set background Color + // Color by resource + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); + if (bacgroundColor != -1) { + setBackgroundColor(getResources().getColor(bacgroundColor)); + } else { + // Color by hexadecimal + // Color by hexadecimal + background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + } + + // Set Padding + String value = attrs.getAttributeValue(ANDROIDXML, "padding"); + if (value != null) { + float padding = Float.parseFloat(value.replace("dip", "")); + paddingBottom = Utils.dpToPx(padding, getResources()); + paddingLeft = Utils.dpToPx(padding, getResources()); + paddingRight = Utils.dpToPx(padding, getResources()); + paddingTop = Utils.dpToPx(padding, getResources()); + } else { + value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); + paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); + paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); + paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); + paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); + } + setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + // Set text button + String text = null; + int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1); + if (textResource != -1) { + text = getResources().getString(textResource); + } else { + text = attrs.getAttributeValue(ANDROIDXML, "text"); + } + + textButton = new TextView(getContext()); + if (text != null) { + textButton.setText(text); + textButton.setTextColor(Color.WHITE); + textButton.setTypeface(null, Typeface.BOLD); + LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); + params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); + textButton.setLayoutParams(params); + addView(textButton); // FrameLayout.LayoutParams params = (LayoutParams) textView.getLayoutParams(); // params.width = getWidth(); // params.gravity = Gravity.CENTER_HORIZONTAL; //// params.setMargins(paddingLeft, paddingTop, paddingRight, paddingRight); // textView.setLayoutParams(params);textColor - int textColor = attrs.getAttributeResourceValue(ANDROIDXML,"textColor",-1); - if(textColor != -1){ - textButton.setTextColor(textColor); - }else{ - // Color by hexadecimal - // Color by hexadecimal - textColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1); - if (textColor != -1) - textButton.setTextColor(textColor); - } - int[] array = {android.R.attr.textSize}; - TypedArray values = getContext().obtainStyledAttributes(attrs, array); - float textSize = values.getDimension(0, -1); - values.recycle(); - if(textSize != -1) - textButton.setTextSize(textSize); - - } - - rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - "rippleSpeed", Utils.dpToPx(6, getResources())); - } - + int textColor = attrs.getAttributeResourceValue(ANDROIDXML, "textColor", -1); + if (textColor != -1) { + textButton.setTextColor(textColor); + } else { + // Color by hexadecimal + // Color by hexadecimal + textColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1); + if (textColor != -1) + textButton.setTextColor(textColor); + } + int[] array = {android.R.attr.textSize}; + TypedArray values = getContext().obtainStyledAttributes(attrs, array); + float textSize = values.getDimension(0, -1); + values.recycle(); + if (textSize != -1) + textButton.setTextSize(textSize); + + } + + rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, + "rippleSpeed", Utils.dpToPx(6, getResources())); + } + // /** // * Center text in button // */ @@ -131,20 +132,21 @@ protected void setAttributes(AttributeSet attrs){ // textButton.setY(getHeight()/2-textButton.getHeight()/2 - paddingLeft + paddingRight); // txtCenter = true; // } - - Integer height; - Integer width; - @Override - protected void onDraw(Canvas canvas) { + + Integer height; + Integer width; + + @Override + protected void onDraw(Canvas canvas) { // if(!txtCenter) // centrarTexto(); - super.onDraw(canvas); - if (x != -1) { - Rect src = new Rect(0, 0, getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources())); - Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()), getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources())); - canvas.drawBitmap(makeCircle(), src, dst, null); - invalidate(); - } - } - + super.onDraw(canvas); + if (x != -1) { + Rect src = new Rect(0, 0, getWidth() - Utils.dpToPx(6, getResources()), getHeight() - Utils.dpToPx(7, getResources())); + Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()), getWidth() - Utils.dpToPx(6, getResources()), getHeight() - Utils.dpToPx(7, getResources())); + canvas.drawBitmap(makeCircle(), src, dst, null); + invalidate(); + } + } + } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java index 27b41de..89d5718 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java @@ -119,7 +119,8 @@ public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { changeBackgroundColor((check) ? makePressColor() : Color .parseColor("#446D6D6D")); - } else if (event.getAction() == MotionEvent.ACTION_UP) { + } else if ((event.getAction() == MotionEvent.ACTION_UP) + | (event.getAction() == MotionEvent.ACTION_CANCEL)){ changeBackgroundColor(getResources().getColor( android.R.color.transparent)); press = false; diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml index 9215203..d7ae500 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml @@ -43,6 +43,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" + android:textColor="#ffffff" android:text="Button" /> @@ -68,7 +69,7 @@ + android:layout_height="wrap_content" > Date: Tue, 8 Nov 2016 00:01:39 +0100 Subject: [PATCH 03/13] fixed issues: #81 #102 #107 #114 #118 #124 #125 #127 #128 #162 --- .../gc/materialdesign/views/ButtonFlat.java | 261 ++++++------ .../materialdesign/views/ButtonRectangle.java | 2 + .../com/gc/materialdesign/views/CheckBox.java | 7 +- .../com/gc/materialdesign/views/Slider.java | 28 +- .../com/gc/materialdesign/views/Switch.java | 382 +++++++++--------- .../materialdesign/widgets/ColorSelector.java | 1 + .../com/gc/materialdesign/widgets/Dialog.java | 1 + .../widgets/ProgressDialog.java | 1 + .../gc/materialdesign/widgets/SnackBar.java | 3 +- .../materialdesigndemo/ui/SwitchActivity.java | 13 +- 10 files changed, 364 insertions(+), 335 deletions(-) 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 0d63559..0668ea6 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 @@ -13,135 +13,136 @@ import android.widget.TextView; public class ButtonFlat extends Button { - - TextView textButton; - - int paddingTop, paddingBottom, paddingLeft, paddingRight; - - public ButtonFlat(Context context, AttributeSet attrs) { - super(context, attrs); - - } - - protected void setDefaultProperties(){ - minHeight = 36; - minWidth = 88; - rippleSize = 3; - paddingBottom = Utils.dpToPx(16, getResources()); - paddingLeft = Utils.dpToPx(16, getResources()); - paddingRight = Utils.dpToPx(16, getResources()); - paddingTop = Utils.dpToPx(16, getResources()); - // Min size - setMinimumHeight(Utils.dpToPx(minHeight, getResources())); - setMinimumWidth(Utils.dpToPx(minWidth, getResources())); - setBackgroundResource(R.drawable.background_transparent); - } - - @Override - protected void setAttributes(AttributeSet attrs) { - - // Set Padding - String value = attrs.getAttributeValue(ANDROIDXML, "padding"); - if (value != null) { - float padding = Float.parseFloat(value.replace("dip", "")); - paddingBottom = Utils.dpToPx(padding, getResources()); - paddingLeft = Utils.dpToPx(padding, getResources()); - paddingRight = Utils.dpToPx(padding, getResources()); - paddingTop = Utils.dpToPx(padding, getResources()); - } else { - value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); - paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); - paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); - paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); - paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); - } - setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); - - // Set text button - String text = null; - int textResource = attrs.getAttributeResourceValue(ANDROIDXML,"text",-1); - if(textResource != -1){ - text = getResources().getString(textResource); - }else{ - text = attrs.getAttributeValue(ANDROIDXML,"text"); - } - textButton = new TextView(getContext()); - if(text != null){ - textButton.setText(text.toUpperCase()); - textButton.setTextColor(backgroundColor); - textButton.setTypeface(null, Typeface.BOLD); - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); - params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); - textButton.setLayoutParams(params); - addView(textButton); - } - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } - } - - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (x != -1) { - - Paint paint = new Paint(); - paint.setAntiAlias(true); - paint.setColor(makePressColor()); - canvas.drawCircle(x, y, radius, paint); - if(radius > getHeight()/rippleSize) - radius += rippleSpeed; - if(radius >= getWidth()){ - x = -1; - y = -1; - radius = getHeight()/rippleSize; - if(onClickListener != null&& clickAfterRipple) - onClickListener.onClick(this); - } - invalidate(); - } - - } - - /** - * Make a dark color to ripple effect - * @return - */ - @Override - 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; - if(isEnabled()) - beforeBackground = backgroundColor; - textButton.setTextColor(color); - } - - @Override - public TextView getTextView() { - return textButton; - } - - public String getText(){ - return textButton.getText().toString(); - } + + int paddingTop, paddingBottom, paddingLeft, paddingRight; + + public ButtonFlat(Context context, AttributeSet attrs) { + super(context, attrs); + + } + + protected void setDefaultProperties() { + minHeight = 36; + minWidth = 88; + rippleSize = 3; + paddingBottom = Utils.dpToPx(16, getResources()); + paddingLeft = Utils.dpToPx(16, getResources()); + paddingRight = Utils.dpToPx(16, getResources()); + paddingTop = Utils.dpToPx(16, getResources()); + // Min size + setMinimumHeight(Utils.dpToPx(minHeight, getResources())); + setMinimumWidth(Utils.dpToPx(minWidth, getResources())); + setBackgroundResource(R.drawable.background_transparent); + } + + @Override + protected void setAttributes(AttributeSet attrs) { + + // Set Padding + String value = attrs.getAttributeValue(ANDROIDXML, "padding"); + if (value != null) { + float padding = Float.parseFloat(value.replace("dip", "")); + paddingBottom = Utils.dpToPx(padding, getResources()); + paddingLeft = Utils.dpToPx(padding, getResources()); + paddingRight = Utils.dpToPx(padding, getResources()); + paddingTop = Utils.dpToPx(padding, getResources()); + } else { + value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); + paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); + paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); + paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); + value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); + paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); + } + setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + + // Set text button + String text = null; + int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1); + if (textResource != -1) { + text = getResources().getString(textResource); + } else { + text = attrs.getAttributeValue(ANDROIDXML, "text"); + } + textButton = new TextView(getContext()); + if (text != null) { + textButton.setText(text.toUpperCase()); + textButton.setTextColor(backgroundColor); + textButton.setTypeface(null, Typeface.BOLD); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); + textButton.setLayoutParams(params); + boolean allCaps = attrs.getAttributeBooleanValue(ANDROIDXML, "textAllCaps", false); + textButton.setAllCaps(allCaps); + addView(textButton); + } + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); + if (bacgroundColor != -1) { + setBackgroundColor(getResources().getColor(bacgroundColor)); + } else { + // Color by hexadecimal + // Color by hexadecimal + background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + } + } + + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (x != -1) { + + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(makePressColor()); + canvas.drawCircle(x, y, radius, paint); + if (radius > getHeight() / rippleSize) + radius += rippleSpeed; + if (radius >= getWidth()) { + x = -1; + y = -1; + radius = getHeight() / rippleSize; + if (onClickListener != null && clickAfterRipple) + onClickListener.onClick(this); + } + invalidate(); + } + + } + + /** + * Make a dark color to ripple effect + * + * @return + */ + @Override + 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; + if (isEnabled()) + beforeBackground = backgroundColor; + textButton.setTextColor(color); + } + + @Override + public TextView getTextView() { + return textButton; + } + + public String getText() { + return textButton.getText().toString(); + } } 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 d5e5175..f12b984 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 @@ -91,6 +91,8 @@ protected void setAttributes(AttributeSet attrs) { params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); textButton.setLayoutParams(params); + boolean allCaps = attrs.getAttributeBooleanValue(ANDROIDXML, "textAllCaps", false); + textButton.setAllCaps(allCaps); addView(textButton); // FrameLayout.LayoutParams params = (LayoutParams) textView.getLayoutParams(); // params.width = getWidth(); diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java index 89d5718..f52d6c6 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java @@ -57,7 +57,7 @@ protected void setAttributes(AttributeSet attrs) { setBackgroundColor(background); } - final boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, + check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check", false); post(new Runnable() { @@ -106,6 +106,7 @@ public void run() { @Override public void invalidate() { + if (checkView != null) checkView.invalidate(); super.invalidate(); } @@ -193,9 +194,9 @@ public void setChecked(boolean check) { android.R.color.transparent)); if (check) { step = 0; - } - if (check) checkView.changeBackground(); + } + } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java index 9fc435b..354e446 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java @@ -26,16 +26,16 @@ public class Slider extends CustomView { private int backgroundColor = Color.parseColor("#4CAF50"); - private Ball ball; + private Ball ball; private Bitmap bitmap; private int max = 100; private int min = 0; - private NumberIndicator numberIndicator; + private NumberIndicator numberIndicator; private OnValueChangedListener onValueChangedListener; - private boolean placedBall = false; - private boolean press = false; + private boolean placedBall = false; + private boolean press = false; private boolean showNumberIndicator = false; - private int value = 0; + private int value = 0; public Slider(Context context, AttributeSet attrs) { super(context, attrs); @@ -94,7 +94,8 @@ public void run() { @Override public void invalidate() { - ball.invalidate(); + if (ball != null) + ball.invalidate(); super.invalidate(); } @@ -331,17 +332,17 @@ public void changeBackground() { class Indicator extends RelativeLayout { - boolean animate = true; + boolean animate = true; // Final size after animation - float finalSize = 0; + float finalSize = 0; // Final y position after animation - float finalY = 0; + float finalY = 0; boolean numberIndicatorResize = false; // Size of number indicator - float size = 0; + float size = 0; // Position of number indicator - float x = 0; - float y = 0; + float x = 0; + float y = 0; public Indicator(Context context) { super(context); @@ -395,10 +396,11 @@ protected void onDraw(Canvas canvas) { class NumberIndicator extends Dialog { Indicator indicator; - TextView numberIndicator; + TextView numberIndicator; public NumberIndicator(Context context) { super(context, android.R.style.Theme_Translucent); + requestWindowFeature(Window.FEATURE_NO_TITLE); } @Override diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java index fe6be3e..418cac6 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java @@ -25,9 +25,10 @@ public class Switch extends CustomView { private Ball ball; - private boolean check = false; + private boolean check = false; private boolean eventCheck = false; - private boolean press = false; + private boolean press = false; + private boolean moved = false; private OnCheckListener onCheckListener; private Bitmap bitmap; @@ -61,195 +62,204 @@ protected void setAttributes(AttributeSet attrs) { int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } - - check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check", - false); - eventCheck = check; - ball = new Ball(getContext()); - RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20, - getResources()), Utils.dpToPx(20, getResources())); - params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); - ball.setLayoutParams(params); - addView(ball); - - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - if (isEnabled()) { - isLastTouch = true; - if (event.getAction() == MotionEvent.ACTION_DOWN) { - press = true; - } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - float x = event.getX(); - x = (x < ball.xIni) ? ball.xIni : x; - x = (x > ball.xFin) ? ball.xFin : x; - if (x > ball.xCen) { - eventCheck = true; - } else { - eventCheck = false; - } - ViewHelper.setX(ball, x); - ball.changeBackground(); - if ((event.getX() <= getWidth() && event.getX() >= 0)) { - isLastTouch = false; - press = false; - } - } else if (event.getAction() == MotionEvent.ACTION_UP || - event.getAction() == MotionEvent.ACTION_CANCEL) { - press = false; - isLastTouch = false; - if (eventCheck != check) { - check = eventCheck; - if (onCheckListener != null) - onCheckListener.onCheck(Switch.this,check); - } - if ((event.getX() <= getWidth() && event.getX() >= 0)) { - ball.animateCheck(); - } - } - } - return true; - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (!placedBall) { + setBackgroundColor(getResources().getColor(bacgroundColor)); + } else { + // Color by hexadecimal + int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + } + + check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check", + false); + eventCheck = check; + ball = new Ball(getContext()); + RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20, + getResources()), Utils.dpToPx(20, getResources())); + params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); + ball.setLayoutParams(params); + addView(ball); + + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (isEnabled()) { + isLastTouch = true; + if (event.getAction() == MotionEvent.ACTION_DOWN) { + press = true; + } else if (event.getAction() == MotionEvent.ACTION_MOVE) { + moved = true; + float x = event.getX(); + x = (x < ball.xIni) ? ball.xIni : x; + x = (x > ball.xFin) ? ball.xFin : x; + if (x > ball.xCen) { + eventCheck = true; + } else { + eventCheck = false; + } + ViewHelper.setX(ball, x); + ball.changeBackground(); + if ((event.getX() <= getWidth() && event.getX() >= 0)) { + isLastTouch = false; + press = false; + } + } else if (event.getAction() == MotionEvent.ACTION_UP || + event.getAction() == MotionEvent.ACTION_CANCEL) { + press = false; + isLastTouch = false; + if (eventCheck != check) { + check = eventCheck; + if (onCheckListener != null) + onCheckListener.onCheck(Switch.this, check); + } else { + if (!moved){ + check = !eventCheck; + setChecked(check); + if (onCheckListener != null) + onCheckListener.onCheck(Switch.this, check); + } + } + if ((event.getX() <= getWidth() && event.getX() >= 0)) { + ball.animateCheck(); + } + moved = false; + } + } + return true; + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (!placedBall) { placeBall(); } - // Crop line to transparent effect - if(null == bitmap) { + // Crop line to transparent effect + if (null == bitmap) { bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); } - Canvas temp = new Canvas(bitmap); - Paint paint = new Paint(); - paint.setAntiAlias(true); - paint.setColor((eventCheck) ? backgroundColor : Color.parseColor("#B0B0B0")); - paint.setStrokeWidth(Utils.dpToPx(2, getResources())); - temp.drawLine(getHeight() / 2, getHeight() / 2, getWidth() - - getHeight() / 2, getHeight() / 2, paint); - Paint transparentPaint = new Paint(); - transparentPaint.setAntiAlias(true); - transparentPaint.setColor(getResources().getColor( - android.R.color.transparent)); - transparentPaint.setXfermode(new PorterDuffXfermode( - PorterDuff.Mode.CLEAR)); - temp.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, - ViewHelper.getY(ball) + ball.getHeight() / 2, - ball.getWidth() / 2, transparentPaint); - - canvas.drawBitmap(bitmap, 0, 0, new Paint()); - - if (press) { - paint.setColor((check) ? makePressColor() : Color - .parseColor("#446D6D6D")); - canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, - getHeight() / 2, getHeight() / 2, paint); - } - invalidate(); - - } - - /** - * Make a dark color to press effect - * - * @return - */ - protected int makePressColor() { - int r = (this.backgroundColor >> 16) & 0xFF; - int g = (this.backgroundColor >> 8) & 0xFF; - int b = (this.backgroundColor >> 0) & 0xFF; - r = (r - 30 < 0) ? 0 : r - 30; - g = (g - 30 < 0) ? 0 : g - 30; - b = (b - 30 < 0) ? 0 : b - 30; - return Color.argb(70, r, g, b); - } - - // Move ball to first position in view - boolean placedBall = false; - - private void placeBall() { - ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2); - ball.xIni = ViewHelper.getX(ball); - ball.xFin = getWidth() - getHeight() / 2 - ball.getWidth() / 2; - ball.xCen = getWidth() / 2 - ball.getWidth() / 2; - placedBall = true; - ball.animateCheck(); - } - - // SETTERS - - @Override - public void setBackgroundColor(int color) { - backgroundColor = color; - if (isEnabled()) - beforeBackground = backgroundColor; - - } - - public void setChecked(boolean check) { - invalidate(); - this.check = check; - this.eventCheck = check; - ball.animateCheck(); - } - - public boolean isCheck() { - return check; - } - - class Ball extends View { - - float xIni, xFin, xCen; - - public Ball(Context context) { - super(context); - setBackgroundResource(R.drawable.background_switch_ball_uncheck); - } - - public void changeBackground() { - if (eventCheck) { - setBackgroundResource(R.drawable.background_checkbox); - LayerDrawable layer = (LayerDrawable) getBackground(); - GradientDrawable shape = (GradientDrawable) layer - .findDrawableByLayerId(R.id.shape_bacground); - shape.setColor(backgroundColor); - } else { - setBackgroundResource(R.drawable.background_switch_ball_uncheck); - } - } - - public void animateCheck() { - changeBackground(); - ObjectAnimator objectAnimator; - if (eventCheck) { - objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xFin); - - } else { - objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xIni); - } - objectAnimator.setDuration(300); - objectAnimator.start(); - } - - } - - public void setOncheckListener(OnCheckListener onCheckListener) { - this.onCheckListener = onCheckListener; - } - - public interface OnCheckListener { - public void onCheck(Switch view, boolean check); - } + Canvas temp = new Canvas(bitmap); + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor((eventCheck) ? backgroundColor : Color.parseColor("#B0B0B0")); + paint.setStrokeWidth(Utils.dpToPx(2, getResources())); + temp.drawLine(getHeight() / 2, getHeight() / 2, getWidth() + - getHeight() / 2, getHeight() / 2, paint); + Paint transparentPaint = new Paint(); + transparentPaint.setAntiAlias(true); + transparentPaint.setColor(getResources().getColor( + android.R.color.transparent)); + transparentPaint.setXfermode(new PorterDuffXfermode( + PorterDuff.Mode.CLEAR)); + temp.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, + ViewHelper.getY(ball) + ball.getHeight() / 2, + ball.getWidth() / 2, transparentPaint); + + canvas.drawBitmap(bitmap, 0, 0, new Paint()); + + if (press) { + paint.setColor((check) ? makePressColor() : Color + .parseColor("#446D6D6D")); + canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, + getHeight() / 2, getHeight() / 2, paint); + } + invalidate(); + + } + + /** + * Make a dark color to press effect + * + * @return + */ + protected int makePressColor() { + int r = (this.backgroundColor >> 16) & 0xFF; + int g = (this.backgroundColor >> 8) & 0xFF; + int b = (this.backgroundColor >> 0) & 0xFF; + r = (r - 30 < 0) ? 0 : r - 30; + g = (g - 30 < 0) ? 0 : g - 30; + b = (b - 30 < 0) ? 0 : b - 30; + return Color.argb(70, r, g, b); + } + + // Move ball to first position in view + boolean placedBall = false; + + private void placeBall() { + ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2); + ball.xIni = ViewHelper.getX(ball); + ball.xFin = getWidth() - getHeight() / 2 - ball.getWidth() / 2; + ball.xCen = getWidth() / 2 - ball.getWidth() / 2; + placedBall = true; + ball.animateCheck(); + } + + // SETTERS + + @Override + public void setBackgroundColor(int color) { + backgroundColor = color; + if (isEnabled()) + beforeBackground = backgroundColor; + + } + + public void setChecked(boolean check) { + invalidate(); + this.check = check; + this.eventCheck = check; + ball.animateCheck(); + } + + public boolean isCheck() { + return check; + } + + class Ball extends View { + + float xIni, xFin, xCen; + + public Ball(Context context) { + super(context); + setBackgroundResource(R.drawable.background_switch_ball_uncheck); + } + + public void changeBackground() { + if (eventCheck) { + setBackgroundResource(R.drawable.background_checkbox); + LayerDrawable layer = (LayerDrawable) getBackground(); + GradientDrawable shape = (GradientDrawable) layer + .findDrawableByLayerId(R.id.shape_bacground); + shape.setColor(backgroundColor); + } else { + setBackgroundResource(R.drawable.background_switch_ball_uncheck); + } + } + + public void animateCheck() { + changeBackground(); + ObjectAnimator objectAnimator; + if (eventCheck) { + objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xFin); + + } else { + objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xIni); + } + objectAnimator.setDuration(300); + objectAnimator.start(); + } + + } + + public void setOncheckListener(OnCheckListener onCheckListener) { + this.onCheckListener = onCheckListener; + } + + public interface OnCheckListener { + public void onCheck(Switch view, boolean check); + } } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ColorSelector.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ColorSelector.java index fbd6c3f..3209fab 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ColorSelector.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ColorSelector.java @@ -32,6 +32,7 @@ public class ColorSelector extends android.app.Dialog implements OnValueChangedL public ColorSelector(Context context,Integer color, OnColorSelectedListener onColorSelectedListener) { super(context, android.R.style.Theme_Translucent); + requestWindowFeature(Window.FEATURE_NO_TITLE); this.context = context; this.onColorSelectedListener = onColorSelectedListener; if(color != null) diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/Dialog.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/Dialog.java index d141899..38a458d 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/Dialog.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/Dialog.java @@ -36,6 +36,7 @@ public class Dialog extends android.app.Dialog{ public Dialog(Context context,String title, String message) { super(context, android.R.style.Theme_Translucent); + requestWindowFeature(Window.FEATURE_NO_TITLE); this.context = context;// init Context this.message = message; this.title = title; diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ProgressDialog.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ProgressDialog.java index e83a6b6..ccc0b27 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ProgressDialog.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/ProgressDialog.java @@ -28,6 +28,7 @@ public class ProgressDialog extends android.app.Dialog{ public ProgressDialog(Context context,String title) { super(context, android.R.style.Theme_Translucent); + requestWindowFeature(Window.FEATURE_NO_TITLE); this.title = title; this.context = context; } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java index 242abff..33de082 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/widgets/SnackBar.java @@ -38,6 +38,7 @@ public class SnackBar extends Dialog{ // With action button public SnackBar(Activity activity, String text, String buttonText, View.OnClickListener onClickListener) { super(activity, android.R.style.Theme_Translucent); + requestWindowFeature(Window.FEATURE_NO_TITLE); this.activity = activity; this.text = text; this.buttonText = buttonText; @@ -47,6 +48,7 @@ public SnackBar(Activity activity, String text, String buttonText, View.OnClickL // Only text public SnackBar(Activity activity, String text) { super(activity, android.R.style.Theme_Translucent); + requestWindowFeature(Window.FEATURE_NO_TITLE); this.activity = activity; this.text = text; } @@ -150,7 +152,6 @@ public void onAnimationEnd(Animation animation) { @Override public boolean onKeyDown(int keyCode, KeyEvent event) { - // TODO 自动生成的方法存根 if (keyCode == KeyEvent.KEYCODE_BACK ) { dismiss(); } diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/SwitchActivity.java b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/SwitchActivity.java index e34c514..bdbfff9 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/SwitchActivity.java +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/SwitchActivity.java @@ -6,6 +6,8 @@ import android.os.Bundle; import android.view.Window; +import com.gc.materialdesign.views.CheckBox; +import com.gc.materialdesign.views.Switch; import com.gc.materialdesigndemo.R; @@ -23,8 +25,15 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_switchs); int color = getIntent().getIntExtra("BACKGROUND", Color.BLACK); findViewById(R.id.checkBox).setBackgroundColor(color); + ((CheckBox)findViewById(R.id.checkBox)).setChecked(false); findViewById(R.id.switchView).setBackgroundColor(color); - } - + + ((Switch)findViewById(R.id.switchView)).setOncheckListener(new Switch.OnCheckListener() { + @Override + public void onCheck(Switch view, boolean check) { + ((CheckBox)findViewById(R.id.checkBox)).setChecked(!check); + } + }); + } } From c9ec8443a13cd6f2dce8077b172252e3faa8b25d Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Tue, 8 Nov 2016 00:20:25 +0100 Subject: [PATCH 04/13] fixed issues: #134 --- .../MaterialDesign/src/main/AndroidManifest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/AndroidManifest.xml b/MaterialDesignLibrary/MaterialDesign/src/main/AndroidManifest.xml index 93820b9..0d18913 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/AndroidManifest.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ - + From 5d21fe1a3f61cbc98d92f66ab8c3ec3039efe3e7 Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Tue, 8 Nov 2016 00:34:35 +0100 Subject: [PATCH 05/13] change attrs with prefix to avoid conflicts --- .../com/gc/materialdesign/views/Button.java | 2 +- .../gc/materialdesign/views/ButtonFloat.java | 356 +++++++++--------- .../gc/materialdesign/views/CustomView.java | 109 +++--- .../src/main/res/values/attributes.xml | 32 +- 4 files changed, 257 insertions(+), 242 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..a471448 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 @@ -36,7 +36,7 @@ public Button(Context context, AttributeSet attrs) { super(context, attrs); setDefaultProperties(); clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - "animate", true); + ML_ANIMATED, true); setAttributes(attrs); beforeBackground = backgroundColor; if (rippleColor == null) 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..e059c60 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 @@ -26,184 +26,182 @@ import android.widget.TextView; -public class ButtonFloat extends Button{ - - int sizeIcon = 24; - int sizeRadius = 28; - - - ImageView icon; // Icon of float button - Drawable drawableIcon; - - public boolean isShow = false; - - float showPosition; - float hidePosition; - - - - public ButtonFloat(Context context, AttributeSet attrs) { - super(context, attrs); - setBackgroundResource(R.drawable.background_button_float); - setBackgroundColor(backgroundColor); - sizeRadius = 28; - setDefaultProperties(); - icon = new ImageView(context); - icon.setAdjustViewBounds(true); - icon.setScaleType(ScaleType.CENTER_CROP); - if(drawableIcon != null) { - icon.setImageDrawable(drawableIcon); - } - LayoutParams params = new LayoutParams(Utils.dpToPx(sizeIcon, getResources()),Utils.dpToPx(sizeIcon, getResources())); - params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); - icon.setLayoutParams(params); - addView(icon); - - } - - protected void setDefaultProperties(){ - rippleSpeed = Utils.dpToPx(2, getResources()); - rippleSize = Utils.dpToPx(5, getResources()); - setMinimumWidth(Utils.dpToPx(sizeRadius*2, getResources())); - setMinimumHeight(Utils.dpToPx(sizeRadius*2, getResources())); - super.background = R.drawable.background_button_float; +public class ButtonFloat extends Button { + + int sizeIcon = 24; + int sizeRadius = 28; + + + ImageView icon; // Icon of float button + Drawable drawableIcon; + + public boolean isShow = false; + + float showPosition; + float hidePosition; + + + public ButtonFloat(Context context, AttributeSet attrs) { + super(context, attrs); + setBackgroundResource(R.drawable.background_button_float); + setBackgroundColor(backgroundColor); + sizeRadius = 28; + setDefaultProperties(); + icon = new ImageView(context); + icon.setAdjustViewBounds(true); + icon.setScaleType(ScaleType.CENTER_CROP); + if (drawableIcon != null) { + icon.setImageDrawable(drawableIcon); + } + LayoutParams params = new LayoutParams(Utils.dpToPx(sizeIcon, getResources()), Utils.dpToPx(sizeIcon, getResources())); + params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); + icon.setLayoutParams(params); + addView(icon); + + } + + protected void setDefaultProperties() { + rippleSpeed = Utils.dpToPx(2, getResources()); + rippleSize = Utils.dpToPx(5, getResources()); + setMinimumWidth(Utils.dpToPx(sizeRadius * 2, getResources())); + setMinimumHeight(Utils.dpToPx(sizeRadius * 2, getResources())); + super.background = R.drawable.background_button_float; // super.setDefaultProperties(); - } - - - // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs){ - //Set background Color - // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } - - // Set Ripple Color - // Color by resource - int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML, - "rippleColor", -1); - if (rippleColor != -1) { - setRippleColor(getResources().getColor(rippleColor)); - } else { - // Color by hexadecimal - int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1); - if (background != -1) - setRippleColor(background); - else - setRippleColor(makePressColor()); - } - // Icon of button - int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconDrawable",-1); - if(iconResource != -1) - drawableIcon = getResources().getDrawable(iconResource); - final boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"animate", false); - post(new Runnable() { - - @Override - public void run() { - showPosition = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources()); - hidePosition = ViewHelper.getY(ButtonFloat.this) + getHeight() * 3; - if(animate){ - ViewHelper.setY(ButtonFloat.this, hidePosition); - show(); - } - } - }); - - } - - Integer height; - Integer width; - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (x != -1) { - Rect src = new Rect(0, 0, getWidth(), getHeight()); - Rect dst = new Rect(Utils.dpToPx(1, getResources()), Utils.dpToPx(2, getResources()), getWidth()-Utils.dpToPx(1, getResources()), getHeight()-Utils.dpToPx(2, getResources())); - canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null); - invalidate(); - } - } - - - - - public ImageView getIcon() { - return icon; - } - - public void setIcon(ImageView icon) { - this.icon = icon; - } - - public Drawable getDrawableIcon() { - return drawableIcon; - } - - public void setDrawableIcon(Drawable drawableIcon) { - this.drawableIcon = drawableIcon; - try { - icon.setBackground(drawableIcon); - } catch (NoSuchMethodError e) { - icon.setBackgroundDrawable(drawableIcon); - } - } - - public Bitmap cropCircle(Bitmap bitmap) { - Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), - bitmap.getHeight(), Config.ARGB_8888); - Canvas canvas = new Canvas(output); - - final int color = 0xff424242; - final Paint paint = new Paint(); - final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); - - paint.setAntiAlias(true); - canvas.drawARGB(0, 0, 0, 0); - paint.setColor(color); - canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, - bitmap.getWidth()/2, paint); - paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); - canvas.drawBitmap(bitmap, rect, rect, paint); - return output; - } - - @Override - public TextView getTextView() { - return null; - } - - public void setRippleColor(int rippleColor) { - this.rippleColor = rippleColor; - } - - public void show(){ - ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", showPosition); - animator.setInterpolator(new BounceInterpolator()); - animator.setDuration(1500); - animator.start(); - isShow = true; - } - - public void hide(){ - - ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", hidePosition); - animator.setInterpolator(new BounceInterpolator()); - animator.setDuration(1500); - animator.start(); - - isShow = false; - } - - public boolean isShow(){ - return isShow; - } - + } + + + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs) { + //Set background Color + // Color by resource + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); + if (bacgroundColor != -1) { + setBackgroundColor(getResources().getColor(bacgroundColor)); + } else { + // Color by hexadecimal + background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + } + + // Set Ripple Color + // Color by resource + int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML, + ML_RIPPLE_COLOR, -1); + if (rippleColor != -1) { + setRippleColor(getResources().getColor(rippleColor)); + } else { + // Color by hexadecimal + int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_RIPPLE_COLOR, -1); + if (background != -1) + setRippleColor(background); + else + setRippleColor(makePressColor()); + } + // Icon of button + int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML, "iconDrawable", -1); + if (iconResource != -1) + drawableIcon = getResources().getDrawable(iconResource); + final boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, ML_ANIMATED, false); + post(new Runnable() { + + @Override + public void run() { + showPosition = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources()); + hidePosition = ViewHelper.getY(ButtonFloat.this) + getHeight() * 3; + if (animate) { + ViewHelper.setY(ButtonFloat.this, hidePosition); + show(); + } + } + }); + + } + + Integer height; + Integer width; + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (x != -1) { + Rect src = new Rect(0, 0, getWidth(), getHeight()); + Rect dst = new Rect(Utils.dpToPx(1, getResources()), Utils.dpToPx(2, getResources()), getWidth() - Utils.dpToPx(1, getResources()), getHeight() - Utils.dpToPx(2, getResources())); + canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null); + invalidate(); + } + } + + + public ImageView getIcon() { + return icon; + } + + public void setIcon(ImageView icon) { + this.icon = icon; + } + + public Drawable getDrawableIcon() { + return drawableIcon; + } + + public void setDrawableIcon(Drawable drawableIcon) { + this.drawableIcon = drawableIcon; + try { + icon.setBackground(drawableIcon); + } catch (NoSuchMethodError e) { + icon.setBackgroundDrawable(drawableIcon); + } + } + + public Bitmap cropCircle(Bitmap bitmap) { + Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), + bitmap.getHeight(), Config.ARGB_8888); + Canvas canvas = new Canvas(output); + + final int color = 0xff424242; + final Paint paint = new Paint(); + final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); + + paint.setAntiAlias(true); + canvas.drawARGB(0, 0, 0, 0); + paint.setColor(color); + canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, + bitmap.getWidth() / 2, paint); + paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); + canvas.drawBitmap(bitmap, rect, rect, paint); + return output; + } + + @Override + public TextView getTextView() { + return null; + } + + public void setRippleColor(int rippleColor) { + this.rippleColor = rippleColor; + } + + public void show() { + ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", showPosition); + animator.setInterpolator(new BounceInterpolator()); + animator.setDuration(1500); + animator.start(); + isShow = true; + } + + public void hide() { + + ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", hidePosition); + animator.setInterpolator(new BounceInterpolator()); + animator.setDuration(1500); + animator.start(); + + isShow = false; + } + + public boolean isShow() { + return isShow; + } + } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java index 7a76e38..4124d33 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java @@ -6,50 +6,67 @@ import android.util.AttributeSet; import android.widget.RelativeLayout; -public class CustomView extends RelativeLayout{ - - - final static String MATERIALDESIGNXML = "http://schemas.android.com/apk/res-auto"; - final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; - - final int disabledBackgroundColor = Color.parseColor("#E2E2E2"); - int beforeBackground; - - // Indicate if user touched this view the last time - public boolean isLastTouch = false; - - public CustomView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - public void setEnabled(boolean enabled) { - super.setEnabled(enabled); - if(enabled) - setBackgroundColor(beforeBackground); - else - setBackgroundColor(disabledBackgroundColor); - invalidate(); - } - - boolean animation = false; - - @Override - protected void onAnimationStart() { - super.onAnimationStart(); - animation = true; - } - - @Override - protected void onAnimationEnd() { - super.onAnimationEnd(); - animation = false; - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if(animation) - invalidate(); - } +public class CustomView extends RelativeLayout { + + + final static String MATERIALDESIGNXML = "http://schemas.android.com/apk/res-auto"; + final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; + + final static String ML_ANIMATED = "MLanimated"; + final static String ML_RIPPLE_COLOR = "MLrippleColor"; + final static String ML_RIPPLE_SPEED = "MLrippleSpeed"; + final static String ML_SHOW_NUMBER_INDICATOR = "MLshowNumberIndicator"; + final static String ML_MAX = "MLmax"; + final static String ML_MIN = "MLmin"; + final static String ML_VALUE = "MLvalue"; + final static String ML_PROGRESS = "MLprogress"; + final static String ML_RING_WIDTH = "MLringWidth"; + final static String ML_CHECKED = "MLchecked"; + final static String ML_CHECKBOX_SIZE = "MLcheckBoxSize"; + final static String ML_THUMB_SIZE = "MLthumbSize"; + final static String ML_ICON_DRAWABLE = "MLiconDrawable"; + final static String ML_ICON_SIZE = "MLiconSize"; + final static String ML_RIPPLE_BORDER_RADIUS = "MLrippleBorderRadius"; + final static String ML_CLICK_AFTER_RIPPLE = "MLclickAfterRipple"; + + final int disabledBackgroundColor = Color.parseColor("#E2E2E2"); + int beforeBackground; + + // Indicate if user touched this view the last time + public boolean isLastTouch = false; + + public CustomView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + if (enabled) + setBackgroundColor(beforeBackground); + else + setBackgroundColor(disabledBackgroundColor); + invalidate(); + } + + boolean animation = false; + + @Override + protected void onAnimationStart() { + super.onAnimationStart(); + animation = true; + } + + @Override + protected void onAnimationEnd() { + super.onAnimationEnd(); + animation = false; + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (animation) + invalidate(); + } } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml index 95a6502..78722a2 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml @@ -4,34 +4,34 @@ - + - + - + - + - + - + - - + + - - - + + + - + - + - + - + - + From c91847dde5caa66e6d077d444cd5dc0c668fda96 Mon Sep 17 00:00:00 2001 From: Ivan Navas Date: Tue, 8 Nov 2016 00:37:37 +0100 Subject: [PATCH 06/13] Pre Merge --- .../materialdesign/utils/AttributesUtils.java | 174 ++++++++++++++++++ .../com/gc/materialdesign/views/Button.java | 8 +- .../gc/materialdesign/views/ButtonFlat.java | 3 +- .../gc/materialdesign/views/ButtonFloat.java | 3 +- .../materialdesign/views/ButtonRectangle.java | 92 +++------ .../gc/materialdesign/views/CustomView.java | 4 + .../ui/ButtonsActivity.java | 10 +- .../src/main/res/layout/activity_buttons.xml | 2 +- .../src/main/res/values/styles.xml | 4 + 9 files changed, 221 insertions(+), 79 deletions(-) create mode 100644 MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java new file mode 100644 index 0000000..0b17f40 --- /dev/null +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java @@ -0,0 +1,174 @@ +package com.gc.materialdesign.utils; + +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.util.AttributeSet; + +import com.gc.materialdesign.R; + +/** + * Created by Navas on 7/11/16. + */ + +public class AttributesUtils { + + public static int[] attrs = { + android.R.attr.background, + android.R.attr.padding, + android.R.attr.paddingLeft, + android.R.attr.paddingTop, + android.R.attr.paddingRight, + android.R.attr.paddingBottom, + android.R.attr.text, + android.R.attr.textColor, + android.R.attr.textSize}; + + public static final int BACKGROUNDCOLOR = 0; + public static final int PADDING = 1; + public static final int PADDINGLEFT = 2; + public static final int PADDINGTOP = 3; + public static final int PADDINGRIGT = 4; + public static final int PADDINGBOTTOM = 5; + public static final int TEXT = 6; + public static final int TEXTCOLOR = 7; + public static final int TEXTSIZE = 8; + + + + final static String MATERIALDESIGNXML = "http://schemas.android.com/apk/res-auto"; + final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; + + public static int getBackgroundColor(Resources resources, AttributeSet attrs, TypedArray typedArray){ + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); + if (bacgroundColor != -1) { + return (resources.getColor(bacgroundColor)); + } else { + // Color by hexadecimal + // Color by hexadecimal + bacgroundColor = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (bacgroundColor != -1) + return bacgroundColor; + else if(typedArray != null){ + bacgroundColor = typedArray.getResourceId(BACKGROUNDCOLOR,-1); + if(bacgroundColor != -1) { + return (resources.getColor(bacgroundColor)); + }else { + // Color by hexadecimal + // Color by hexadecimal + bacgroundColor = typedArray.getInt(BACKGROUNDCOLOR, -1); + if (bacgroundColor != -1) + return bacgroundColor; + } + } + } + return -1; + } + + public static int[] getPadding(Resources resources, AttributeSet attrs, TypedArray typedArray, int[] paddings){ + String value = attrs.getAttributeValue(ANDROIDXML, "padding"); + if (value != null) { + float padding = Float.parseFloat(value.replace("dip", "")); + paddings[0] = Utils.dpToPx(padding, resources); + paddings[1] = paddings[0]; + paddings[2] = paddings[0]; + paddings[3] = paddings[0]; + } else if(typedArray != null){ + value = typedArray.getString(PADDING); + if (value != null) { + float padding = Float.parseFloat(value.replace("dip", "")); + paddings[0] = Utils.dpToPx(padding, resources); + paddings[1] = paddings[0]; + paddings[2] = paddings[0]; + paddings[3] = paddings[0]; + }else { + value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); + if(value == null){ + value = typedArray.getString(PADDINGLEFT); + if(value != null) paddings[0] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + }else paddings[0] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); + if(value == null){ + value = typedArray.getString(PADDINGTOP); + if(value != null) paddings[1] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + }else paddings[1] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); + if(value == null){ + value = typedArray.getString(PADDINGRIGT); + if(value != null) paddings[2] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + }else paddings[2] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); + if(value == null){ + value = typedArray.getString(PADDINGBOTTOM); + if(value != null) paddings[3] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + }else paddings[3] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); + } + } + return paddings; + } + + public static String getText(Resources resources, AttributeSet attrs, TypedArray typedArray){ + String text = null; + int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1); + if (textResource != -1) { + return resources.getString(textResource); + } else if(attrs.getAttributeValue(ANDROIDXML, "text") != null){ + return attrs.getAttributeValue(ANDROIDXML, "text"); + }else if(typedArray != null){ + textResource = typedArray.getResourceId(TEXT,-1); + if (textResource != -1) { + return resources.getString(textResource); + } else if(typedArray.getString(TEXT) != null){ + return typedArray.getString(TEXT); + } + } + return null; + } + + public static int getTextColor(Resources resources, AttributeSet attrs, TypedArray typedArray){ + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "textColor", -1); + if (bacgroundColor != -1) { + return (resources.getColor(bacgroundColor)); + } else { + // Color by hexadecimal + // Color by hexadecimal + bacgroundColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1); + if (bacgroundColor != -1) + return bacgroundColor; + else if(typedArray != null){ + bacgroundColor = typedArray.getResourceId(TEXTCOLOR,-1); + if(bacgroundColor != -1) { + return (resources.getColor(bacgroundColor)); + }else { + // Color by hexadecimal + // Color by hexadecimal + bacgroundColor = typedArray.getInt(TEXTCOLOR, -1); + if (bacgroundColor != -1) + return bacgroundColor; + } + } + } + return -1; + } + + public static float getTextSize(Resources resources, TypedArray attrs, TypedArray style){ + float textSize = attrs.getDimension(0, -1); + attrs.recycle(); + if (textSize != -1) + return textSize; + else if (style != null && style.getDimension(TEXTSIZE,-1) != -1) + return style.getDimension(TEXTSIZE,-1); + return -1; + } + + public static float getRippleSpeed(Resources resources, AttributeSet attrs, TypedArray style){ + float rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, + "rippleSpeed", -1); + if(rippleSpeed != -1){ + return rippleSpeed; + }else if(style != null){ + + } + return rippleSpeed + } + +} 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..9317fcb 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 @@ -1,9 +1,11 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -37,7 +39,9 @@ public Button(Context context, AttributeSet attrs) { setDefaultProperties(); clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "animate", true); - setAttributes(attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs,typedArray); + typedArray.recycle(); beforeBackground = backgroundColor; if (rippleColor == null) rippleColor = makePressColor(); @@ -53,7 +57,7 @@ protected void setDefaultProperties() { } // Set atributtes of XML to View - abstract protected void setAttributes(AttributeSet attrs); + abstract protected void setAttributes(AttributeSet attrs, TypedArray typedArray); // ### RIPPLE EFFECT ### 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 0d63559..14bca1e 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 @@ -4,6 +4,7 @@ import com.gc.materialdesign.utils.Utils; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -38,7 +39,7 @@ protected void setDefaultProperties(){ } @Override - protected void setAttributes(AttributeSet attrs) { + protected void setAttributes(AttributeSet attrs, TypedArray typedArray) { // Set Padding String value = attrs.getAttributeValue(ANDROIDXML, "padding"); 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..e4ca5ee 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 @@ -7,6 +7,7 @@ import android.annotation.SuppressLint; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -72,7 +73,7 @@ protected void setDefaultProperties(){ // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs){ + protected void setAttributes(AttributeSet attrs, TypedArray typedArray){ //Set background Color // Color by resource int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); 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 d5e5175..b513ea9 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 @@ -1,6 +1,7 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import android.content.Context; @@ -39,85 +40,38 @@ protected void setDefaultProperties() { // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs) { + protected void setAttributes(AttributeSet attrs, TypedArray typedArray) { //Set background Color // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); - if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(), attrs, typedArray); + if(bacgroundColor != -1) setBackgroundColor(bacgroundColor); // Set Padding - String value = attrs.getAttributeValue(ANDROIDXML, "padding"); - if (value != null) { - float padding = Float.parseFloat(value.replace("dip", "")); - paddingBottom = Utils.dpToPx(padding, getResources()); - paddingLeft = Utils.dpToPx(padding, getResources()); - paddingRight = Utils.dpToPx(padding, getResources()); - paddingTop = Utils.dpToPx(padding, getResources()); - } else { - value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); - paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); - paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); - paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); - paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); - } - setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + int[] paddings = {paddingLeft,paddingTop,paddingRight,paddingBottom}; + paddings = AttributesUtils.getPadding(getResources(),attrs,typedArray,paddings); + setPadding(paddings[0], paddings[1], paddings[2], paddings[3]); // Set text button - String text = null; - int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1); - if (textResource != -1) { - text = getResources().getString(textResource); - } else { - text = attrs.getAttributeValue(ANDROIDXML, "text"); - } - textButton = new TextView(getContext()); - if (text != null) { - textButton.setText(text); - textButton.setTextColor(Color.WHITE); - textButton.setTypeface(null, Typeface.BOLD); - LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); - params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); - textButton.setLayoutParams(params); - addView(textButton); -// FrameLayout.LayoutParams params = (LayoutParams) textView.getLayoutParams(); -// params.width = getWidth(); -// params.gravity = Gravity.CENTER_HORIZONTAL; -//// params.setMargins(paddingLeft, paddingTop, paddingRight, paddingRight); -// textView.setLayoutParams(params);textColor - int textColor = attrs.getAttributeResourceValue(ANDROIDXML, "textColor", -1); - if (textColor != -1) { - textButton.setTextColor(textColor); - } else { - // Color by hexadecimal - // Color by hexadecimal - textColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1); - if (textColor != -1) - textButton.setTextColor(textColor); - } - int[] array = {android.R.attr.textSize}; - TypedArray values = getContext().obtainStyledAttributes(attrs, array); - float textSize = values.getDimension(0, -1); - values.recycle(); - if (textSize != -1) - textButton.setTextSize(textSize); - - } + String text = AttributesUtils.getText(getResources(), attrs, typedArray); + if(text != null) textButton.setText(text); + int textColor = AttributesUtils.getTextColor(getResources(), attrs, typedArray); + textButton.setTextColor((textColor == -1) ? Color.WHITE : textColor); + textButton.setTypeface(null, Typeface.BOLD); + LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); + params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); + textButton.setLayoutParams(params); + addView(textButton); + int[] array = {android.R.attr.textSize}; + TypedArray values = getContext().obtainStyledAttributes(attrs, array); + float textSize = AttributesUtils.getTextSize(getResources(), values, typedArray); + if (textSize != -1) + textButton.setTextSize(textSize); rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", Utils.dpToPx(6, getResources())); + } // /** diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java index 7a76e38..ff82830 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CustomView.java @@ -21,6 +21,10 @@ public class CustomView extends RelativeLayout{ public CustomView(Context context, AttributeSet attrs) { super(context, attrs); } + + public CustomView(Context context, AttributeSet attrs, int style){ + super(context, attrs, style); + } @Override public void setEnabled(boolean enabled) { 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..39e9e7b 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 @@ -21,11 +21,11 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_buttons); int color = getIntent().getIntExtra("BACKGROUND", Color.BLACK); - findViewById(R.id.buttonflat).setBackgroundColor(color); - findViewById(R.id.button).setBackgroundColor(color); - findViewById(R.id.buttonFloatSmall).setBackgroundColor(color); - findViewById(R.id.buttonIcon).setBackgroundColor(color); - findViewById(R.id.buttonFloat).setBackgroundColor(color); +// findViewById(R.id.buttonflat).setBackgroundColor(color); +// findViewById(R.id.button).setBackgroundColor(color); +// findViewById(R.id.buttonFloatSmall).setBackgroundColor(color); +// findViewById(R.id.buttonIcon).setBackgroundColor(color); +// findViewById(R.id.buttonFloat).setBackgroundColor(color); } diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml index d7ae500..bea1c93 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml @@ -76,7 +76,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" - android:background="#1E88E5" + style="@style/PruebaStyle" android:text="Button" /> diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/values/styles.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/values/styles.xml index 6ce89c7..cc5441a 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/values/styles.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/values/styles.xml @@ -17,4 +17,8 @@ + + From 9acfe9b77dd783ccc6faa02ee0548253f5606683 Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Tue, 8 Nov 2016 00:39:37 +0100 Subject: [PATCH 07/13] change attrs with prefix to avoid conflicts --- .../gc/materialdesign/views/ButtonFloat.java | 2 +- .../materialdesign/views/ButtonRectangle.java | 2 +- .../com/gc/materialdesign/views/CheckBox.java | 2 +- .../gc/materialdesign/views/LayoutRipple.java | 6 +- .../views/ProgressBarDeterminate.java | 240 +++++++++--------- .../com/gc/materialdesign/views/Slider.java | 6 +- .../com/gc/materialdesign/views/Switch.java | 2 +- 7 files changed, 131 insertions(+), 129 deletions(-) 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 e059c60..0592b47 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 @@ -99,7 +99,7 @@ protected void setAttributes(AttributeSet attrs) { setRippleColor(makePressColor()); } // Icon of button - int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML, "iconDrawable", -1); + int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML, ML_ICON_DRAWABLE, -1); if (iconResource != -1) drawableIcon = getResources().getDrawable(iconResource); final boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, ML_ANIMATED, false); 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 f12b984..3ee5e5c 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 @@ -119,7 +119,7 @@ protected void setAttributes(AttributeSet attrs) { } rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - "rippleSpeed", Utils.dpToPx(6, getResources())); + ML_RIPPLE_SPEED, Utils.dpToPx(6, getResources())); } // /** diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java index f52d6c6..b7e5f5c 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java @@ -58,7 +58,7 @@ protected void setAttributes(AttributeSet attrs) { } check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - "check", false); + ML_CHECKED, false); post(new Runnable() { @Override diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java index bc27f3b..c632a5b 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java @@ -48,12 +48,12 @@ protected void setAttributes(AttributeSet attrs) { // Set Ripple Color // Color by resource int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML, - "rippleColor", -1); + ML_RIPPLE_COLOR, -1); if (rippleColor != -1) { setRippleColor(getResources().getColor(rippleColor)); } else { // Color by hexadecimal - int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1); + int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_RIPPLE_COLOR, -1); if (background != -1) setRippleColor(background); else @@ -61,7 +61,7 @@ protected void setAttributes(AttributeSet attrs) { } rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - "rippleSpeed", 20f); + ML_RIPPLE_SPEED, 20f); } // Set color of background diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java index 8001191..284ba8e 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java @@ -14,124 +14,126 @@ import android.widget.RelativeLayout.LayoutParams; public class ProgressBarDeterminate extends CustomView { - - - int max = 100; - int min = 0; - int progress = 0; - - int backgroundColor = Color.parseColor("#1E88E5"); - - View progressView; - - public ProgressBarDeterminate(Context context, AttributeSet attrs) { - super(context, attrs); - setAttributes(attrs); - } - - // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs){ - - progressView = new View(getContext()); - LayoutParams params = new LayoutParams(1,1); - progressView.setLayoutParams(params); - progressView.setBackgroundResource(R.drawable.background_progress); - addView(progressView); - - //Set background Color - // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - else - setBackgroundColor(Color.parseColor("#1E88E5")); - } - - min = attrs.getAttributeIntValue(MATERIALDESIGNXML,"min", 0); - max = attrs.getAttributeIntValue(MATERIALDESIGNXML,"max", 100); - progress = attrs.getAttributeIntValue(MATERIALDESIGNXML,"progress", min); - - setMinimumHeight(Utils.dpToPx(3, getResources())); - - post(new Runnable() { - - @Override - public void run() { - LayoutParams params = (LayoutParams) progressView.getLayoutParams(); - params.height = getHeight(); - progressView.setLayoutParams(params); - } - }); - - } - - /** - * Make a dark color to ripple effect - * @return - */ - protected int makePressColor(){ - int r = (this.backgroundColor >> 16) & 0xFF; - int g = (this.backgroundColor >> 8) & 0xFF; - int b = (this.backgroundColor >> 0) & 0xFF; - return Color.argb(128,r, g, b); - } - - // SETTERS - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if(pendindProgress!=-1) - setProgress(pendindProgress); - } - - public void setMax(int max){ - this.max = max; - } - - public void setMin(int min){ - this.min = min; - } - - int pendindProgress = -1; - public void setProgress(int progress){ - if(getWidth() == 0){ - pendindProgress = progress; - }else{ - this.progress = progress; - if(progress > max) - progress = max; - if(progress < min) - progress = min; - int totalWidth = max-min; - double progressPercent = (double)progress/(double)totalWidth; - int progressWidth =(int) (getWidth()*progressPercent); - LayoutParams params = (LayoutParams) progressView.getLayoutParams(); - params.width = progressWidth; - params.height = getHeight(); - progressView.setLayoutParams(params); - pendindProgress = -1; - } - } - - public int getProgress(){ - return progress; - } - - // Set color of background - public void setBackgroundColor(int color){ - this.backgroundColor = color; - if(isEnabled()) - beforeBackground = backgroundColor; - LayerDrawable layer = (LayerDrawable) progressView.getBackground(); - GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); - shape.setColor(color); - super.setBackgroundColor(makePressColor()); - } + + + int max = 100; + int min = 0; + int progress = 0; + + int backgroundColor = Color.parseColor("#1E88E5"); + + View progressView; + + public ProgressBarDeterminate(Context context, AttributeSet attrs) { + super(context, attrs); + setAttributes(attrs); + } + + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs) { + + progressView = new View(getContext()); + LayoutParams params = new LayoutParams(1, 1); + progressView.setLayoutParams(params); + progressView.setBackgroundResource(R.drawable.background_progress); + addView(progressView); + + //Set background Color + // Color by resource + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); + if (bacgroundColor != -1) { + setBackgroundColor(getResources().getColor(bacgroundColor)); + } else { + // Color by hexadecimal + int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + else + setBackgroundColor(Color.parseColor("#1E88E5")); + } + + min = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MIN, 0); + max = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MAX, 100); + progress = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_PROGRESS, min); + + setMinimumHeight(Utils.dpToPx(3, getResources())); + + post(new Runnable() { + + @Override + public void run() { + LayoutParams params = (LayoutParams) progressView.getLayoutParams(); + params.height = getHeight(); + progressView.setLayoutParams(params); + } + }); + + } + + /** + * Make a dark color to ripple effect + * + * @return + */ + protected int makePressColor() { + int r = (this.backgroundColor >> 16) & 0xFF; + int g = (this.backgroundColor >> 8) & 0xFF; + int b = (this.backgroundColor >> 0) & 0xFF; + return Color.argb(128, r, g, b); + } + + // SETTERS + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + if (pendindProgress != -1) + setProgress(pendindProgress); + } + + public void setMax(int max) { + this.max = max; + } + + public void setMin(int min) { + this.min = min; + } + + int pendindProgress = -1; + + public void setProgress(int progress) { + if (getWidth() == 0) { + pendindProgress = progress; + } else { + this.progress = progress; + if (progress > max) + progress = max; + if (progress < min) + progress = min; + int totalWidth = max - min; + double progressPercent = (double) progress / (double) totalWidth; + int progressWidth = (int) (getWidth() * progressPercent); + LayoutParams params = (LayoutParams) progressView.getLayoutParams(); + params.width = progressWidth; + params.height = getHeight(); + progressView.setLayoutParams(params); + pendindProgress = -1; + } + } + + public int getProgress() { + return progress; + } + + // Set color of background + public void setBackgroundColor(int color) { + this.backgroundColor = color; + if (isEnabled()) + beforeBackground = backgroundColor; + LayerDrawable layer = (LayerDrawable) progressView.getBackground(); + GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); + shape.setColor(color); + super.setBackgroundColor(makePressColor()); + } } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java index 354e446..e94a617 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java @@ -273,9 +273,9 @@ protected void setAttributes(AttributeSet attrs) { showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "showNumberIndicator", false); - min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0); - max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0); - value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min); + min = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MIN, 0); + max = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MAX, 0); + value = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_VALUE, min); ball = new Ball(getContext()); RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20, diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java index 418cac6..f7df293 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java @@ -70,7 +70,7 @@ protected void setAttributes(AttributeSet attrs) { setBackgroundColor(background); } - check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check", + check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, ML_CHECKED, false); eventCheck = check; ball = new Ball(getContext()); From b30fd9808bb6732e6053ea7af5dfefb78db927e5 Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Tue, 8 Nov 2016 01:06:15 +0100 Subject: [PATCH 08/13] changed attr in xml and added progress dialog to demo --- .../src/main/res/layout/color_selector.xml | 18 ++++++------ .../materialdesigndemo/ui/WidgetActivity.java | 13 ++++++++- .../src/main/res/layout/activity_buttons.xml | 8 ++--- .../src/main/res/layout/activity_main.xml | 2 +- .../src/main/res/layout/activity_progress.xml | 10 +++---- .../src/main/res/layout/activity_switchs.xml | 4 +-- .../src/main/res/layout/activity_widgets.xml | 29 +++++++++++++++++++ 7 files changed, 62 insertions(+), 22 deletions(-) diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/color_selector.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/color_selector.xml index 8d1c77e..fe56b00 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/color_selector.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/layout/color_selector.xml @@ -46,9 +46,9 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#4D4D4D" - materialdesign:max="255" - materialdesign:min="0" - materialdesign:showNumberIndicator="true" /> + materialdesign:MLmax="255" + materialdesign:MLmin="0" + materialdesign:MLshowNumberIndicator="true" /> + materialdesign:MLmax="255" + materialdesign:MLmin="0" + materialdesign:MLshowNumberIndicator="true" /> + materialdesign:MLmax="255" + materialdesign:MLmin="0" + materialdesign:MLshowNumberIndicator="true" /> diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java index 65e39f1..91d6a8b 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java @@ -3,6 +3,7 @@ import com.gc.materialdesign.views.ButtonFlat; import com.gc.materialdesign.widgets.ColorSelector; import com.gc.materialdesign.widgets.Dialog; +import com.gc.materialdesign.widgets.ProgressDialog; import com.gc.materialdesign.widgets.SnackBar; import com.gc.materialdesigndemo.R; @@ -25,7 +26,7 @@ protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.activity_widgets); - + // SHOW SNACKBAR findViewById(R.id.buttonSnackBar).setOnClickListener(new OnClickListener() { @@ -66,6 +67,16 @@ public void onClick(View v) { dialog.show(); } }); + + findViewById(R.id.buttonProgressDialog).setOnClickListener(new OnClickListener() { + + @Override + public void onClick(final View flatButton) { + ProgressDialog progressDialog = new ProgressDialog(WidgetActivity.this, "Loading"); + progressDialog.show(); + } + }); + // SHOW COLOR SEECTOR findViewById(R.id.buttonColorSelector).setOnClickListener(new OnClickListener() { diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml index d7ae500..99e10eb 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml @@ -109,7 +109,7 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#1E88E5" - materialdesign:iconDrawable="@drawable/ic_action_new" /> + materialdesign:MLiconDrawable="@drawable/ic_action_new" /> @@ -142,7 +142,7 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#1E88E5" - materialdesign:iconDrawable="@drawable/ic_next" /> + materialdesign:MLiconDrawable="@drawable/ic_next" /> @@ -174,7 +174,7 @@ android:layout_alignParentBottom="true" android:layout_marginRight="24dp" android:background="#1E88E5" - materialdesign:animate="true" - materialdesign:iconDrawable="@drawable/ic_action_new" /> + materialdesign:MLanimated="true" + materialdesign:MLiconDrawable="@drawable/ic_action_new" /> diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_main.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_main.xml index dd07eb1..e0b2afe 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_main.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_main.xml @@ -39,7 +39,7 @@ android:layout_marginLeft="32dp" android:layout_marginTop="108dp" android:background="#1E88E5" - materialdesign:iconDrawable="@drawable/icn_select_color" /> + materialdesign:MLiconDrawable="@drawable/icn_select_color" /> @@ -198,9 +198,9 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#1E88E5" - materialdesign:max="50" - materialdesign:min="0" - materialdesign:showNumberIndicator="true" /> + materialdesign:MLmax="50" + materialdesign:MLmin="0" + materialdesign:MLshowNumberIndicator="true" /> diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_switchs.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_switchs.xml index 3d95ca7..835a502 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_switchs.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_switchs.xml @@ -40,7 +40,7 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#1E88E5" - materialdesign:check="true" /> + materialdesign:MLchecked="true" /> @@ -72,7 +72,7 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#1E88E5" - materialdesign:check="true" /> + materialdesign:MLchecked="true" /> diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml index 47868a4..d2f8db5 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml @@ -98,6 +98,35 @@ android:layout_centerInParent="true" android:text="Show Color Selector" /> + + + + + + + + + + + \ No newline at end of file From 40f21aec6bedb22ab1980c4016e6663ab2f28995 Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Wed, 16 Nov 2016 22:31:04 +0100 Subject: [PATCH 09/13] fixed issues: 151, 154 --- .../com/gc/materialdesign/views/Slider.java | 8 +++--- .../ui/ProgressActivity.java | 3 +++ .../materialdesigndemo/ui/WidgetActivity.java | 27 +++++++++++++++++++ .../src/main/res/layout/activity_progress.xml | 4 +-- .../src/main/res/layout/activity_widgets.xml | 7 +++++ 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java index e94a617..5528da5 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java @@ -74,7 +74,7 @@ public int getValue() { } public void setValue(final int value) { - if (placedBall == false) + if (!placedBall) post(new Runnable() { @Override @@ -84,9 +84,10 @@ public void run() { }); else { this.value = value; - float division = (ball.xFin - ball.xIni) / max; + float division = (ball.xFin - ball.xIni) / (max - min); + int _value = this.value - min; // this line is new, you were using parameter value (thats incorrect, obviously) ViewHelper.setX(ball, - value * division + getHeight() / 2 - ball.getWidth() / 2); + _value * division + getHeight() / 2 - ball.getWidth() / 2); ball.changeBackground(); } @@ -113,6 +114,7 @@ public void setShowNumberIndicator(boolean showNumberIndicator) { public boolean onTouchEvent(MotionEvent event) { isLastTouch = true; if (isEnabled()) { + getParent().requestDisallowInterceptTouchEvent(true); if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { if (numberIndicator != null diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ProgressActivity.java b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ProgressActivity.java index 224efa1..a10db1a 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ProgressActivity.java +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/ProgressActivity.java @@ -10,6 +10,7 @@ import com.gc.materialdesign.views.ProgressBarDeterminate; import com.gc.materialdesign.views.ProgressBarIndeterminateDeterminate; +import com.gc.materialdesign.views.Slider; import com.gc.materialdesigndemo.R; @@ -37,6 +38,8 @@ protected void onCreate(Bundle savedInstanceState) { progressTimer.start(); progressBarIndeterminateDeterminate = (ProgressBarIndeterminateDeterminate) findViewById(R.id.progressBarIndeterminateDeterminate); progressTimer2.start(); + + ((Slider)findViewById(R.id.sliderNumber)).setValue(300); } diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java index 91d6a8b..9ca335c 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java @@ -11,7 +11,11 @@ import android.app.Activity; import android.graphics.Color; import android.os.Bundle; +import android.support.v4.view.PagerAdapter; +import android.support.v4.view.ViewPager; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.View.OnClickListener; import android.widget.Toast; @@ -85,6 +89,29 @@ public void onClick(final View flatButton) { new ColorSelector(WidgetActivity.this, Color.RED, null).show(); } }); + +// ViewPager vp_slider = (ViewPager) findViewById(R.id.vp_slider); +// vp_slider.setAdapter(pagerAdapter); } + + PagerAdapter pagerAdapter = new PagerAdapter() { + @Override + public int getCount() { + return 2; + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + LayoutInflater inflater = LayoutInflater.from(WidgetActivity.this); + ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.activity_progress, container, false); + container.addView(layout); + return layout; + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view == object; + } + }; } diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_progress.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_progress.xml index f668757..bf07953 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_progress.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_progress.xml @@ -198,8 +198,8 @@ android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#1E88E5" - materialdesign:MLmax="50" - materialdesign:MLmin="0" + materialdesign:MLmax="3000" + materialdesign:MLmin="150" materialdesign:MLshowNumberIndicator="true" /> diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml index d2f8db5..12edcc1 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml @@ -127,6 +127,13 @@ android:layout_centerInParent="true" android:text="Show Progress Dialog" /> + + + \ No newline at end of file From 4ed33e41d6d15812806d437d81cfa3eed21a50b6 Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Wed, 16 Nov 2016 22:59:28 +0100 Subject: [PATCH 10/13] fixed issues: 157, 158 --- .../com/gc/materialdesign/views/Button.java | 7 + .../com/gc/materialdesign/views/Switch.java | 2 + .../materialdesigndemo/ui/WidgetActivity.java | 180 ++++++++++-------- 3 files changed, 105 insertions(+), 84 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 a471448..4ddae0b 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 @@ -173,6 +173,13 @@ public void setBackgroundColor(int color) { } } + @Override + public boolean performClick() { + if (onClickListener != null) + onClickListener.onClick(this); + return onClickListener != null; + } + public void setRippleSpeed(float rippleSpeed) { this.rippleSpeed = rippleSpeed; } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java index f7df293..12b2d33 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java @@ -113,6 +113,8 @@ public boolean onTouchEvent(MotionEvent event) { if (onCheckListener != null) onCheckListener.onCheck(Switch.this, check); } else { + if (onCheckListener != null) + onCheckListener.onCheck(Switch.this, check); if (!moved){ check = !eventCheck; setChecked(check); diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java index 9ca335c..4c26727 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/java/com/gc/materialdesigndemo/ui/WidgetActivity.java @@ -22,96 +22,108 @@ public class WidgetActivity extends Activity { - private int backgroundColor = Color.parseColor("#1E88E5"); + private int backgroundColor = Color.parseColor("#1E88E5"); + private SnackBar snackBar; - @SuppressLint("NewApi") - @Override - protected void onCreate(Bundle savedInstanceState) { - requestWindowFeature(Window.FEATURE_NO_TITLE); - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_widgets); + @SuppressLint("NewApi") + @Override + protected void onCreate(Bundle savedInstanceState) { + requestWindowFeature(Window.FEATURE_NO_TITLE); + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_widgets); // SHOW SNACKBAR - findViewById(R.id.buttonSnackBar).setOnClickListener(new OnClickListener() { - - @Override - public void onClick(final View flatButton) { - new SnackBar(WidgetActivity.this, - "Do you want change color of this button to red?", - "yes", new OnClickListener() { - - @Override - public void onClick(View v) { - ButtonFlat btn = (ButtonFlat) findViewById(R.id.buttonSnackBar); - btn.setTextColor(Color.RED); - } - }).show(); - } - }); + findViewById(R.id.buttonSnackBar).setOnClickListener(new OnClickListener() { + + @Override + public void onClick(final View flatButton) { + snackBar = new SnackBar(WidgetActivity.this, + "Do you want change color of this button to red?", + "yes", new OnClickListener() { + + @Override + public void onClick(final View v) { + ButtonFlat btn = (ButtonFlat) findViewById(R.id.buttonSnackBar); + btn.setTextColor(Color.RED); + } + }); + snackBar.show(); + } + }); + // SHOW DiALOG - findViewById(R.id.buttonDialog).setOnClickListener(new OnClickListener() { - - @Override - public void onClick(final View flatButton) { - Dialog dialog = new Dialog(WidgetActivity.this, "Title", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam"); - dialog.setOnAcceptButtonClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - Toast.makeText(WidgetActivity.this, "Click accept button", 1).show(); - } - }); - dialog.setOnCancelButtonClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - Toast.makeText(WidgetActivity.this, "Click cancel button", 1).show(); - } - }); - dialog.show(); - } - }); - - findViewById(R.id.buttonProgressDialog).setOnClickListener(new OnClickListener() { - - @Override - public void onClick(final View flatButton) { - ProgressDialog progressDialog = new ProgressDialog(WidgetActivity.this, "Loading"); - progressDialog.show(); - } - }); + findViewById(R.id.buttonDialog).setOnClickListener(new OnClickListener() { + + @Override + public void onClick(final View flatButton) { + Dialog dialog = new Dialog(WidgetActivity.this, "Title", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam"); + dialog.setOnAcceptButtonClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + Toast.makeText(WidgetActivity.this, "Click accept button", 1).show(); + if (snackBar != null) { + snackBar.dismiss(); + new SnackBar(WidgetActivity.this, "thread problem", "accept", new OnClickListener() { + @Override + public void onClick(View view) { + + } + }).show(); + } + } + }); + dialog.setOnCancelButtonClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + Toast.makeText(WidgetActivity.this, "Click cancel button", 1).show(); + } + }); + dialog.show(); + } + }); + + findViewById(R.id.buttonProgressDialog).setOnClickListener(new OnClickListener() { + + @Override + public void onClick(final View flatButton) { + ProgressDialog progressDialog = new ProgressDialog(WidgetActivity.this, "Loading"); + progressDialog.show(); + } + }); // SHOW COLOR SEECTOR - findViewById(R.id.buttonColorSelector).setOnClickListener(new OnClickListener() { - - @Override - public void onClick(final View flatButton) { - new ColorSelector(WidgetActivity.this, Color.RED, null).show(); - } - }); - + findViewById(R.id.buttonColorSelector).setOnClickListener(new OnClickListener() { + + @Override + public void onClick(final View flatButton) { + new ColorSelector(WidgetActivity.this, Color.RED, null).show(); + } + }); + findViewById(R.id.buttonDialog).performClick(); // ViewPager vp_slider = (ViewPager) findViewById(R.id.vp_slider); // vp_slider.setAdapter(pagerAdapter); - } - - - PagerAdapter pagerAdapter = new PagerAdapter() { - @Override - public int getCount() { - return 2; - } - - @Override - public Object instantiateItem(ViewGroup container, int position) { - LayoutInflater inflater = LayoutInflater.from(WidgetActivity.this); - ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.activity_progress, container, false); - container.addView(layout); - return layout; - } - - @Override - public boolean isViewFromObject(View view, Object object) { - return view == object; - } - }; + } + + + PagerAdapter pagerAdapter = new PagerAdapter() { + @Override + public int getCount() { + return 2; + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + LayoutInflater inflater = LayoutInflater.from(WidgetActivity.this); + ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.activity_progress, container, false); + container.addView(layout); + return layout; + } + + @Override + public boolean isViewFromObject(View view, Object object) { + return view == object; + } + }; } From 3b7d7b61dd7446b92a40893cbbf375a8fd9eadaa Mon Sep 17 00:00:00 2001 From: Sergio Pascual Cabrito Date: Thu, 17 Nov 2016 00:11:53 +0100 Subject: [PATCH 11/13] fixed issues: 164 --- .../src/main/java/com/gc/materialdesign/views/Button.java | 2 +- .../main/java/com/gc/materialdesign/views/ButtonFlat.java | 5 +++++ .../java/com/gc/materialdesign/views/ButtonRectangle.java | 5 +++++ .../src/main/java/com/gc/materialdesign/views/Card.java | 2 +- .../src/main/java/com/gc/materialdesign/views/CheckBox.java | 4 ++-- .../com/gc/materialdesign/views/ProgressBarDeterminate.java | 2 +- .../src/main/java/com/gc/materialdesign/views/Slider.java | 2 +- .../src/main/java/com/gc/materialdesign/views/Switch.java | 2 +- .../src/main/res/drawable/background_button_float.xml | 2 +- .../src/main/res/drawable/background_button_rectangle.xml | 2 +- .../src/main/res/drawable/background_checkbox.xml | 2 +- .../src/main/res/drawable/background_checkbox_check.xml | 2 +- .../src/main/res/drawable/background_checkbox_uncheck.xml | 2 +- .../src/main/res/drawable/background_progress.xml | 2 +- .../src/main/res/drawable/background_switch_ball_uncheck.xml | 2 +- .../src/main/res/drawable/background_transparent.xml | 2 +- .../java/com/gc/materialdesigndemo/ui/ButtonsActivity.java | 3 +++ 17 files changed, 28 insertions(+), 15 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 4ddae0b..e6d6ee0 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 @@ -165,7 +165,7 @@ public void setBackgroundColor(int color) { try { LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer - .findDrawableByLayerId(R.id.shape_bacground); + .findDrawableByLayerId(R.id.shape_background); shape.setColor(backgroundColor); rippleColor = makePressColor(); } catch (Exception ex) { 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 0668ea6..9673c5d 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 @@ -114,6 +114,11 @@ protected void onDraw(Canvas canvas) { } + public void setTextSize(float size){ + if (getTextView() != null) + getTextView().setTextSize(size); + } + /** * Make a dark color to ripple effect * 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 3ee5e5c..ed8f066 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 @@ -122,6 +122,11 @@ protected void setAttributes(AttributeSet attrs) { ML_RIPPLE_SPEED, Utils.dpToPx(6, getResources())); } + + public void setTextSize(float size){ + if (getTextView() != null) + getTextView().setTextSize(size); + } // /** // * Center text in button // */ diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java index 74bc4ef..bdb1726 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java @@ -62,7 +62,7 @@ public void setBackgroundColor(int color){ if(isEnabled()) beforeBackground = backgroundColor; LayerDrawable layer = (LayerDrawable) getBackground(); - GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); + GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_background); shape.setColor(backgroundColor); } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java index b7e5f5c..22e2959 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java @@ -159,7 +159,7 @@ protected void onDraw(Canvas canvas) { private void changeBackgroundColor(int color) { LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer - .findDrawableByLayerId(R.id.shape_bacground); + .findDrawableByLayerId(R.id.shape_background); shape.setColor(color); } @@ -224,7 +224,7 @@ public void changeBackground() { setBackgroundResource(R.drawable.background_checkbox_check); LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer - .findDrawableByLayerId(R.id.shape_bacground); + .findDrawableByLayerId(R.id.shape_background); shape.setColor(backgroundColor); } else { setBackgroundResource(R.drawable.background_checkbox_uncheck); diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java index 284ba8e..d9cba4b 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java @@ -131,7 +131,7 @@ public void setBackgroundColor(int color) { if (isEnabled()) beforeBackground = backgroundColor; LayerDrawable layer = (LayerDrawable) progressView.getBackground(); - GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); + GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_background); shape.setColor(color); super.setBackgroundColor(makePressColor()); } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java index 5528da5..490bbcb 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java @@ -321,7 +321,7 @@ public void changeBackground() { setBackgroundResource(R.drawable.background_checkbox); LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer - .findDrawableByLayerId(R.id.shape_bacground); + .findDrawableByLayerId(R.id.shape_background); shape.setColor(backgroundColor); } else { setBackgroundResource(R.drawable.background_switch_ball_uncheck); diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java index 12b2d33..ad8d8f9 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java @@ -234,7 +234,7 @@ public void changeBackground() { setBackgroundResource(R.drawable.background_checkbox); LayerDrawable layer = (LayerDrawable) getBackground(); GradientDrawable shape = (GradientDrawable) layer - .findDrawableByLayerId(R.id.shape_bacground); + .findDrawableByLayerId(R.id.shape_background); shape.setColor(backgroundColor); } else { setBackgroundResource(R.drawable.background_switch_ball_uncheck); diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_button_float.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_button_float.xml index 7c9f560..908e64b 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_button_float.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_button_float.xml @@ -4,7 +4,7 @@ - + diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox.xml index 1b688d9..aea6617 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox.xml @@ -1,7 +1,7 @@ + android:id="@+id/shape_background"> diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_check.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_check.xml index 482cc18..7045a3a 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_check.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_check.xml @@ -1,7 +1,7 @@ + android:id="@+id/shape_background"> diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_uncheck.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_uncheck.xml index a3919f6..517c807 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_uncheck.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_checkbox_uncheck.xml @@ -1,7 +1,7 @@ + android:id="@+id/shape_background"> diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_progress.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_progress.xml index 8287418..b0ebbf9 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_progress.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_progress.xml @@ -1,6 +1,6 @@ - + diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_switch_ball_uncheck.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_switch_ball_uncheck.xml index 9248293..fbf2a35 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_switch_ball_uncheck.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_switch_ball_uncheck.xml @@ -1,7 +1,7 @@ + android:id="@+id/shape_background"> diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_transparent.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_transparent.xml index b4147b8..157ab77 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_transparent.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable/background_transparent.xml @@ -1,7 +1,7 @@ - + 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..4492c0c 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.ButtonFlat; import com.gc.materialdesigndemo.R; @@ -26,6 +27,8 @@ protected void onCreate(Bundle savedInstanceState) { findViewById(R.id.buttonFloatSmall).setBackgroundColor(color); findViewById(R.id.buttonIcon).setBackgroundColor(color); findViewById(R.id.buttonFloat).setBackgroundColor(color); + + ((ButtonFlat)findViewById(R.id.buttonflat)).getTextView().setTextSize(12f); } From 85ae71fb6f5d4dc70c552e3f682b2130f9a193cc Mon Sep 17 00:00:00 2001 From: Ivan Navas Date: Thu, 17 Nov 2016 00:12:10 +0100 Subject: [PATCH 12/13] Pre Merge --- .../materialdesign/utils/AttributesUtils.java | 205 ++++++++++++++---- .../src/main/res/values/attributes.xml | 4 - 2 files changed, 158 insertions(+), 51 deletions(-) diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java index 0b17f40..3080697 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java @@ -21,17 +21,61 @@ public class AttributesUtils { android.R.attr.paddingBottom, android.R.attr.text, android.R.attr.textColor, - android.R.attr.textSize}; + android.R.attr.textSize, + R.attr.MLrippleSpeed, + R.attr.MLclickAfterRipple, + R.attr.MLrippleColor, + R.attr.MLanimated, + R.attr.MLshowNumberIndicator, + R.attr.MLmax, + R.attr.MLmin, + R.attr.MLvalue, + R.attr.MLprogress, + R.attr.MLringWidth, + R.attr.MLchecked, + R.attr.MLiconDrawable, + R.attr.MLrippleBorderRadius}; public static final int BACKGROUNDCOLOR = 0; public static final int PADDING = 1; - public static final int PADDINGLEFT = 2; - public static final int PADDINGTOP = 3; - public static final int PADDINGRIGT = 4; - public static final int PADDINGBOTTOM = 5; + public static final int PADDING_LEFT = 2; + public static final int PADDING_TOP = 3; + public static final int PADDING_RIGT = 4; + public static final int PADDING_BOTTOM = 5; public static final int TEXT = 6; - public static final int TEXTCOLOR = 7; - public static final int TEXTSIZE = 8; + public static final int TEXT_COLOR = 7; + public static final int TEXT_SIZE = 8; + public static final int RIPPLE_SPEED = 9; + public static final int CLICK_AFTER_RIPPLE = 10; + public static final int RIPPLE_COLOR = 11; + public static final int ANIMATED = 12; + public static final int SHOW_NUMBER_INDICATOR = 13; + public static final int MAX = 14; + public static final int MIN = 15; + public static final int VALUE = 16; + public static final int PROGRESS = 17; + public static final int RING_WIDTH = 18; + public static final int CHECKED = 19; + public static final int ICON_DRAWABLE = 20; + public static final int RIPPLE_BORDER_RADIUS = 21; + + + final static String ML_RIPPLE_SPEED = "MLrippleSpeed"; + final static String ML_CLICK_AFTER_RIPPLE = "MLclickAfterRipple"; + final static String ML_RIPPLE_COLOR = "MLrippleColor"; + final static String ML_ANIMATED = "MLanimated"; + final static String ML_SHOW_NUMBER_INDICATOR = "MLshowNumberIndicator"; + final static String ML_MAX = "MLmax"; + final static String ML_MIN = "MLmin"; + final static String ML_VALUE = "MLvalue"; + final static String ML_PROGRESS = "MLprogress"; + final static String ML_RING_WIDTH = "MLringWidth"; + final static String ML_CHECKED = "MLchecked"; + final static String ML_CHECKBOX_SIZE = "MLcheckBoxSize"; + final static String ML_THUMB_SIZE = "MLthumbSize"; + final static String ML_ICON_DRAWABLE = "MLiconDrawable"; + final static String ML_ICON_SIZE = "MLiconSize"; + final static String ML_RIPPLE_BORDER_RADIUS = "MLrippleBorderRadius"; @@ -39,26 +83,38 @@ public class AttributesUtils { final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; public static int getBackgroundColor(Resources resources, AttributeSet attrs, TypedArray typedArray){ - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); + return getColor(resources, attrs, typedArray, "background", BACKGROUNDCOLOR); + } + + public static int getTextColor(Resources resources, AttributeSet attrs, TypedArray typedArray){ + return getColor(resources, attrs, typedArray, "textColor", TEXT_COLOR); + } + + private static int getColor(Resources resources, AttributeSet attrs, TypedArray typedArray, String name, int position){ + return getColor(resources, attrs, typedArray, ANDROIDXML, name, position); + } + + private static int getColor(Resources resources, AttributeSet attrs, TypedArray typedArray, String xml, String name, int position){ + int bacgroundColor = attrs.getAttributeResourceValue(xml, name, -1); if (bacgroundColor != -1) { return (resources.getColor(bacgroundColor)); } else { // Color by hexadecimal // Color by hexadecimal - bacgroundColor = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + bacgroundColor = attrs.getAttributeIntValue(xml, name, -1); if (bacgroundColor != -1) return bacgroundColor; else if(typedArray != null){ - bacgroundColor = typedArray.getResourceId(BACKGROUNDCOLOR,-1); + bacgroundColor = typedArray.getResourceId(position,-1); if(bacgroundColor != -1) { return (resources.getColor(bacgroundColor)); }else { // Color by hexadecimal // Color by hexadecimal - bacgroundColor = typedArray.getInt(BACKGROUNDCOLOR, -1); + bacgroundColor = typedArray.getInt(position, -1); if (bacgroundColor != -1) return bacgroundColor; - } + } } } return -1; @@ -83,22 +139,22 @@ public static int[] getPadding(Resources resources, AttributeSet attrs, TypedArr }else { value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); if(value == null){ - value = typedArray.getString(PADDINGLEFT); + value = typedArray.getString(PADDING_LEFT); if(value != null) paddings[0] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); }else paddings[0] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); if(value == null){ - value = typedArray.getString(PADDINGTOP); + value = typedArray.getString(PADDING_TOP); if(value != null) paddings[1] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); }else paddings[1] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); if(value == null){ - value = typedArray.getString(PADDINGRIGT); + value = typedArray.getString(PADDING_RIGT); if(value != null) paddings[2] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); }else paddings[2] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); if(value == null){ - value = typedArray.getString(PADDINGBOTTOM); + value = typedArray.getString(PADDING_BOTTOM); if(value != null) paddings[3] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); }else paddings[3] = Utils.dpToPx(Float.parseFloat(value.replace("dip","")), resources); } @@ -112,7 +168,7 @@ public static String getText(Resources resources, AttributeSet attrs, TypedArray if (textResource != -1) { return resources.getString(textResource); } else if(attrs.getAttributeValue(ANDROIDXML, "text") != null){ - return attrs.getAttributeValue(ANDROIDXML, "text"); + return attrs.getAttributeValue(ANDROIDXML, "text"); }else if(typedArray != null){ textResource = typedArray.getResourceId(TEXT,-1); if (textResource != -1) { @@ -124,51 +180,106 @@ public static String getText(Resources resources, AttributeSet attrs, TypedArray return null; } - public static int getTextColor(Resources resources, AttributeSet attrs, TypedArray typedArray){ - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "textColor", -1); - if (bacgroundColor != -1) { - return (resources.getColor(bacgroundColor)); - } else { - // Color by hexadecimal - // Color by hexadecimal - bacgroundColor = attrs.getAttributeIntValue(ANDROIDXML, "textColor", -1); - if (bacgroundColor != -1) - return bacgroundColor; - else if(typedArray != null){ - bacgroundColor = typedArray.getResourceId(TEXTCOLOR,-1); - if(bacgroundColor != -1) { - return (resources.getColor(bacgroundColor)); - }else { - // Color by hexadecimal - // Color by hexadecimal - bacgroundColor = typedArray.getInt(TEXTCOLOR, -1); - if (bacgroundColor != -1) - return bacgroundColor; - } - } - } - return -1; - } - public static float getTextSize(Resources resources, TypedArray attrs, TypedArray style){ float textSize = attrs.getDimension(0, -1); attrs.recycle(); if (textSize != -1) return textSize; - else if (style != null && style.getDimension(TEXTSIZE,-1) != -1) - return style.getDimension(TEXTSIZE,-1); + else if (style != null && style.getDimension(TEXT_SIZE,-1) != -1) + return style.getDimension(TEXT_SIZE,-1); return -1; } public static float getRippleSpeed(Resources resources, AttributeSet attrs, TypedArray style){ float rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - "rippleSpeed", -1); + ML_RIPPLE_SPEED, -1); if(rippleSpeed != -1){ return rippleSpeed; }else if(style != null){ + rippleSpeed = style.getFloat(RIPPLE_SPEED, -1); + } + return rippleSpeed; + } + public static boolean getClickAfterRipple(Resources resources, AttributeSet attrs, TypedArray style){ + return getBoolean(resources, attrs, style, ML_CLICK_AFTER_RIPPLE, CLICK_AFTER_RIPPLE); + } + + public static int getRippleColor(Resources resources, AttributeSet attrs, TypedArray typedArray){ + return getColor(resources, attrs, typedArray,MATERIALDESIGNXML, ML_RIPPLE_COLOR, RIPPLE_COLOR); + } + + public static boolean getAnimated(Resources resources, AttributeSet attrs, TypedArray style){ + return getBoolean(resources, attrs, style, ML_ANIMATED, ANIMATED); + } + + public static boolean getShowNumberIndicator(Resources resources, AttributeSet attrs, TypedArray style){ + return getBoolean(resources, attrs, style, ML_SHOW_NUMBER_INDICATOR, SHOW_NUMBER_INDICATOR); + } + + public static float getRipleBorderRadius(Resources resources, AttributeSet attrs, TypedArray style){ + return getFloat(resources, attrs, style, ML_RIPPLE_BORDER_RADIUS, RIPPLE_BORDER_RADIUS); + } + + public static int getMax(Resources resources, AttributeSet attrs, TypedArray style){ + return getInt(resources,attrs, style, ML_MAX, MAX); + } + + public static int getMin(Resources resources, AttributeSet attrs, TypedArray style){ + return getInt(resources,attrs, style, ML_MIN, MIN); + } + + public static int getValue(Resources resources, AttributeSet attrs, TypedArray style){ + return getInt(resources,attrs, style, ML_VALUE, VALUE); + } + + public static int getProgress(Resources resources, AttributeSet attrs, TypedArray style){ + return getInt(resources,attrs, style, ML_PROGRESS, PROGRESS); + } + + public static boolean getChecked(Resources resources, AttributeSet attrs, TypedArray style){ + return getBoolean(resources, attrs, style, ML_CHECKED, CHECKED); + } + + public static int getIconDrawable(Resources resources, AttributeSet attrs, TypedArray style){ + int iconDrawable = attrs.getAttributeResourceValue(MATERIALDESIGNXML, + ML_ICON_DRAWABLE, -1); + if(iconDrawable != -1){ + return iconDrawable; + }else if(style != null){ + iconDrawable = style.getResourceId(ICON_DRAWABLE, -1); + } + return iconDrawable; + } + + public static boolean getBoolean(Resources resources, AttributeSet attrs, TypedArray style, String name, int position){ + boolean bool = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, + name, false); + return style.getBoolean(position,bool); + } + + public static int getInt(Resources resources, AttributeSet attrs, TypedArray style, String name, int position){ + int integer = attrs.getAttributeIntValue(MATERIALDESIGNXML, + name, -1); + if(integer != -1){ + return integer; + }else if(style != null){ + integer = style.getInt(position, -1); + } + return integer; + } + + public static float getFloat(Resources resources, AttributeSet attrs, TypedArray style, String name, int position){ + float _float = attrs.getAttributeFloatValue(MATERIALDESIGNXML, + name, -1); + if(_float != -1){ + return _float; + }else if(style != null){ + _float = style.getFloat(position, -1); } - return rippleSpeed + return _float; } + + } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml b/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml index 78722a2..99507ba 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml +++ b/MaterialDesignLibrary/MaterialDesign/src/main/res/values/attributes.xml @@ -20,12 +20,8 @@ - - - - From a95ef3051bbcdd273c73cac9c614d15644cece59 Mon Sep 17 00:00:00 2001 From: Ivan Navas Date: Thu, 17 Nov 2016 01:17:40 +0100 Subject: [PATCH 13/13] Enable set attributes by styles --- .../materialdesign/utils/AttributesUtils.java | 44 +-- .../com/gc/materialdesign/views/Button.java | 14 +- .../gc/materialdesign/views/ButtonFlat.java | 74 ++-- .../gc/materialdesign/views/ButtonFloat.java | 31 +- .../materialdesign/views/ButtonRectangle.java | 5 +- .../com/gc/materialdesign/views/Card.java | 21 +- .../com/gc/materialdesign/views/CheckBox.java | 28 +- .../gc/materialdesign/views/LayoutRipple.java | 338 +++++++++--------- .../ProgressBarCircularIndeterminate.java | 36 +- .../views/ProgressBarDeterminate.java | 27 +- .../com/gc/materialdesign/views/Slider.java | 31 +- .../com/gc/materialdesign/views/Switch.java | 23 +- .../res/drawable-xxxhdpi/sprite_check.png | Bin 0 -> 4580 bytes 13 files changed, 309 insertions(+), 363 deletions(-) create mode 100644 MaterialDesignLibrary/MaterialDesign/src/main/res/drawable-xxxhdpi/sprite_check.png diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java index 3080697..e9823d0 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java @@ -201,44 +201,44 @@ public static float getRippleSpeed(Resources resources, AttributeSet attrs, Type return rippleSpeed; } - public static boolean getClickAfterRipple(Resources resources, AttributeSet attrs, TypedArray style){ - return getBoolean(resources, attrs, style, ML_CLICK_AFTER_RIPPLE, CLICK_AFTER_RIPPLE); + public static boolean getClickAfterRipple(Resources resources, AttributeSet attrs, TypedArray style, boolean defaaultValue){ + return getBoolean(resources, attrs, style, ML_CLICK_AFTER_RIPPLE, CLICK_AFTER_RIPPLE, defaaultValue); } public static int getRippleColor(Resources resources, AttributeSet attrs, TypedArray typedArray){ return getColor(resources, attrs, typedArray,MATERIALDESIGNXML, ML_RIPPLE_COLOR, RIPPLE_COLOR); } - public static boolean getAnimated(Resources resources, AttributeSet attrs, TypedArray style){ - return getBoolean(resources, attrs, style, ML_ANIMATED, ANIMATED); + public static boolean getAnimated(Resources resources, AttributeSet attrs, TypedArray style, boolean defaaultValue){ + return getBoolean(resources, attrs, style, ML_ANIMATED, ANIMATED, defaaultValue); } - public static boolean getShowNumberIndicator(Resources resources, AttributeSet attrs, TypedArray style){ - return getBoolean(resources, attrs, style, ML_SHOW_NUMBER_INDICATOR, SHOW_NUMBER_INDICATOR); + public static boolean getShowNumberIndicator(Resources resources, AttributeSet attrs, TypedArray style, boolean defaaultValue){ + return getBoolean(resources, attrs, style, ML_SHOW_NUMBER_INDICATOR, SHOW_NUMBER_INDICATOR, defaaultValue); } public static float getRipleBorderRadius(Resources resources, AttributeSet attrs, TypedArray style){ return getFloat(resources, attrs, style, ML_RIPPLE_BORDER_RADIUS, RIPPLE_BORDER_RADIUS); } - public static int getMax(Resources resources, AttributeSet attrs, TypedArray style){ - return getInt(resources,attrs, style, ML_MAX, MAX); + public static int getMax(Resources resources, AttributeSet attrs, TypedArray style, int defaultValue){ + return getInt(resources,attrs, style, ML_MAX, MAX,defaultValue); } - public static int getMin(Resources resources, AttributeSet attrs, TypedArray style){ - return getInt(resources,attrs, style, ML_MIN, MIN); + public static int getMin(Resources resources, AttributeSet attrs, TypedArray style, int defaultValue){ + return getInt(resources,attrs, style, ML_MIN, MIN,defaultValue); } - public static int getValue(Resources resources, AttributeSet attrs, TypedArray style){ - return getInt(resources,attrs, style, ML_VALUE, VALUE); + public static int getValue(Resources resources, AttributeSet attrs, TypedArray style, int defaultValue){ + return getInt(resources,attrs, style, ML_VALUE, VALUE,defaultValue); } - public static int getProgress(Resources resources, AttributeSet attrs, TypedArray style){ - return getInt(resources,attrs, style, ML_PROGRESS, PROGRESS); + public static int getProgress(Resources resources, AttributeSet attrs, TypedArray style, int defaultValue){ + return getInt(resources,attrs, style, ML_PROGRESS, PROGRESS,defaultValue); } - public static boolean getChecked(Resources resources, AttributeSet attrs, TypedArray style){ - return getBoolean(resources, attrs, style, ML_CHECKED, CHECKED); + public static boolean getChecked(Resources resources, AttributeSet attrs, TypedArray style, boolean defaultValue){ + return getBoolean(resources, attrs, style, ML_CHECKED, CHECKED,defaultValue); } public static int getIconDrawable(Resources resources, AttributeSet attrs, TypedArray style){ @@ -252,19 +252,19 @@ public static int getIconDrawable(Resources resources, AttributeSet attrs, Typed return iconDrawable; } - public static boolean getBoolean(Resources resources, AttributeSet attrs, TypedArray style, String name, int position){ + public static boolean getBoolean(Resources resources, AttributeSet attrs, TypedArray style, String name, int position, boolean defaultValue){ boolean bool = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - name, false); + name, defaultValue); return style.getBoolean(position,bool); } - public static int getInt(Resources resources, AttributeSet attrs, TypedArray style, String name, int position){ + public static int getInt(Resources resources, AttributeSet attrs, TypedArray style, String name, int position, int defaultValue){ int integer = attrs.getAttributeIntValue(MATERIALDESIGNXML, - name, -1); - if(integer != -1){ + name, defaultValue); + if(integer != defaultValue){ return integer; }else if(style != null){ - integer = style.getInt(position, -1); + integer = style.getInt(position, defaultValue); } return integer; } 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 6f0068e..b241172 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 @@ -37,13 +37,17 @@ public abstract class Button extends CustomView { public Button(Context context, AttributeSet attrs) { super(context, attrs); setDefaultProperties(); - clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - ML_ANIMATED, true); TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + clickAfterRipple = AttributesUtils.getClickAfterRipple(getResources(),attrs,typedArray,true); setAttributes(attrs,typedArray); + int rippleColor = AttributesUtils.getRippleColor(getResources(),attrs,typedArray); + if(rippleColor != -1) + this.rippleColor = rippleColor; + rippleSpeed = AttributesUtils.getRippleSpeed(getResources(), attrs, typedArray); + if(rippleSpeed != -1) rippleSpeed = Utils.dpToPx(6, getResources()); typedArray.recycle(); beforeBackground = backgroundColor; - if (rippleColor == null) + if (this.rippleColor == null) rippleColor = makePressColor(); } @@ -188,6 +192,10 @@ public void setRippleSpeed(float rippleSpeed) { this.rippleSpeed = rippleSpeed; } + public void setRippleColor(Integer rippleColor) { + this.rippleColor = rippleColor; + } + public float getRippleSpeed() { return this.rippleSpeed; } 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 8fa61e6..ab8a3f3 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 @@ -1,6 +1,7 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import android.content.Context; @@ -10,6 +11,7 @@ import android.graphics.Paint; import android.graphics.Typeface; import android.util.AttributeSet; +import android.view.Gravity; import android.widget.RelativeLayout; import android.widget.TextView; @@ -39,56 +41,34 @@ protected void setDefaultProperties(){ @Override protected void setAttributes(AttributeSet attrs, TypedArray typedArray) { - // Set Padding - String value = attrs.getAttributeValue(ANDROIDXML, "padding"); - if (value != null) { - float padding = Float.parseFloat(value.replace("dip", "")); - paddingBottom = Utils.dpToPx(padding, getResources()); - paddingLeft = Utils.dpToPx(padding, getResources()); - paddingRight = Utils.dpToPx(padding, getResources()); - paddingTop = Utils.dpToPx(padding, getResources()); - } else { - value = attrs.getAttributeValue(ANDROIDXML, "paddingLeft"); - paddingLeft = (value == null) ? paddingLeft : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingTop"); - paddingTop = (value == null) ? paddingTop : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingRight"); - paddingRight = (value == null) ? paddingRight : (int) Float.parseFloat(value.replace("dip", "")); - value = attrs.getAttributeValue(ANDROIDXML, "paddingBottom"); - paddingBottom = (value == null) ? paddingBottom : (int) Float.parseFloat(value.replace("dip", "")); - } - setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom); + //Set background Color + // Color by resource + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(), attrs, typedArray); + if(bacgroundColor != -1) setBackgroundColor(bacgroundColor); + // Set Padding + int[] paddings = {paddingLeft,paddingTop,paddingRight,paddingBottom}; + paddings = AttributesUtils.getPadding(getResources(),attrs,typedArray,paddings); + setPadding(paddings[0], paddings[1], paddings[2], paddings[3]); // Set text button - String text = null; - int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1); - if (textResource != -1) { - text = getResources().getString(textResource); - } else { - text = attrs.getAttributeValue(ANDROIDXML, "text"); - } textButton = new TextView(getContext()); - if (text != null) { - textButton.setText(text.toUpperCase()); - textButton.setTextColor(backgroundColor); - textButton.setTypeface(null, Typeface.BOLD); - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); - textButton.setLayoutParams(params); - boolean allCaps = attrs.getAttributeBooleanValue(ANDROIDXML, "textAllCaps", false); - textButton.setAllCaps(allCaps); - addView(textButton); - } - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); - if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } + String text = AttributesUtils.getText(getResources(), attrs, typedArray); + if(text != null) textButton.setText(text); + int textColor = AttributesUtils.getTextColor(getResources(), attrs, typedArray); + textButton.setTextColor((textColor == -1) ? Color.WHITE : textColor); + textButton.setTypeface(null, Typeface.BOLD); + LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); + params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); + textButton.setLayoutParams(params); + textButton.setGravity(Gravity.CENTER); + addView(textButton); + int[] array = {android.R.attr.textSize}; + TypedArray values = getContext().obtainStyledAttributes(attrs, array); + float textSize = AttributesUtils.getTextSize(getResources(), values, typedArray); + if (textSize != -1) + textButton.setTextSize(textSize); + } 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 e4ca5ee..b417caa 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 @@ -1,6 +1,7 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import com.nineoldandroids.animation.ObjectAnimator; import com.nineoldandroids.view.ViewHelper; @@ -76,35 +77,13 @@ protected void setDefaultProperties(){ protected void setAttributes(AttributeSet attrs, TypedArray typedArray){ //Set background Color // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } - - // Set Ripple Color - // Color by resource - int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML, - "rippleColor", -1); - if (rippleColor != -1) { - setRippleColor(getResources().getColor(rippleColor)); - } else { - // Color by hexadecimal - int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1); - if (background != -1) - setRippleColor(background); - else - setRippleColor(makePressColor()); - } + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(), attrs, typedArray); + if(bacgroundColor != -1) setBackgroundColor(bacgroundColor); // Icon of button - int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconDrawable",-1); + int iconResource = AttributesUtils.getIconDrawable(getResources(),attrs,typedArray); if(iconResource != -1) drawableIcon = getResources().getDrawable(iconResource); - final boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"animate", false); + final boolean animate = AttributesUtils.getAnimated(getResources(),attrs,typedArray, false); post(new Runnable() { @Override 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 bf40c38..53a4329 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 @@ -11,6 +11,7 @@ import android.graphics.Rect; import android.graphics.Typeface; import android.util.AttributeSet; +import android.view.Gravity; import android.widget.RelativeLayout; import android.widget.TextView; @@ -62,6 +63,7 @@ protected void setAttributes(AttributeSet attrs, TypedArray typedArray) { params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); params.setMargins(Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources()), Utils.dpToPx(5, getResources())); textButton.setLayoutParams(params); + textButton.setGravity(Gravity.CENTER); addView(textButton); int[] array = {android.R.attr.textSize}; TypedArray values = getContext().obtainStyledAttributes(attrs, array); @@ -69,9 +71,6 @@ protected void setAttributes(AttributeSet attrs, TypedArray typedArray) { if (textSize != -1) textButton.setTextSize(textSize); - rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - "rippleSpeed", Utils.dpToPx(6, getResources())); - } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java index bdb1726..25e5611 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java @@ -1,9 +1,11 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; @@ -33,27 +35,22 @@ public class Card extends CustomView { public Card(Context context, AttributeSet attrs) { super(context, attrs); - setAttributes(attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); } // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs){ + protected void setAttributes(AttributeSet attrs, TypedArray style){ + + setBackgroundResource(R.drawable.background_button_rectangle); //Set background Color // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if(bacgroundColor != -1) setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - String background = attrs.getAttributeValue(ANDROIDXML,"background"); - if(background != null) - setBackgroundColor(Color.parseColor(background)); - else - setBackgroundColor(this.backgroundColor); - } } // Set color of background diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java index 22e2959..e5ac309 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/CheckBox.java @@ -1,9 +1,11 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -31,11 +33,12 @@ public class CheckBox extends CustomView { public CheckBox(Context context, AttributeSet attrs) { super(context, attrs); - setAttributes(attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); } // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs) { + protected void setAttributes(AttributeSet attrs, TypedArray style){ setBackgroundResource(R.drawable.background_checkbox); @@ -45,20 +48,11 @@ protected void setAttributes(AttributeSet attrs) { // Set background Color // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, - "background", -1); - if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); - check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - ML_CHECKED, false); + check = AttributesUtils.getChecked(getResources(),attrs,style,false); post(new Runnable() { @Override @@ -71,7 +65,7 @@ public void run() { }); checkView = new Check(getContext()); - checkView.setId(View.generateViewId()); +// checkView.setId(View.generateViewId()); RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20, getResources()), Utils.dpToPx(20, getResources())); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); @@ -89,7 +83,7 @@ public void run() { } if(text != null) { - params.removeRule(RelativeLayout.CENTER_IN_PARENT); +// params.removeRule(RelativeLayout.CENTER_IN_PARENT); params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); TextView textView = new TextView(getContext()); RelativeLayout.LayoutParams textViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java index c632a5b..5ca1792 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java @@ -1,6 +1,7 @@ package com.gc.materialdesign.views; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; @@ -10,7 +11,9 @@ import android.util.AttributeSet; import android.view.MotionEvent; -public class LayoutRipple extends CustomView { +import com.gc.materialdesign.utils.AttributesUtils; + +public class LayoutRipple extends Button { int background; float rippleSpeed = 10f; @@ -19,179 +22,186 @@ public class LayoutRipple extends CustomView { OnClickListener onClickListener; int backgroundColor = Color.parseColor("#FFFFFF"); - Integer rippleColor; Float xRippleOrigin; Float yRippleOrigin; public LayoutRipple(Context context, AttributeSet attrs) { super(context, attrs); - setAttributes(attrs); - } - - // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs) { - - // Set background Color - // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, - "background", -1); - if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - else - setBackgroundColor(this.backgroundColor); - } - // Set Ripple Color - // Color by resource - int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML, - ML_RIPPLE_COLOR, -1); - if (rippleColor != -1) { - setRippleColor(getResources().getColor(rippleColor)); - } else { - // Color by hexadecimal - int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_RIPPLE_COLOR, -1); - if (background != -1) - setRippleColor(background); - else - setRippleColor(makePressColor()); - } - - rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - ML_RIPPLE_SPEED, 20f); - } - - // Set color of background - public void setBackgroundColor(int color) { - this.backgroundColor = color; - if (isEnabled()) - beforeBackground = backgroundColor; - super.setBackgroundColor(color); - } - - public void setRippleSpeed(int rippleSpeed) { - this.rippleSpeed = rippleSpeed; } - // ### RIPPLE EFFECT ### - - float x = -1, y = -1; - float radius = -1; - @Override - public boolean onTouchEvent(MotionEvent event) { - invalidate(); - if (isEnabled()) { - isLastTouch = true; - if (event.getAction() == MotionEvent.ACTION_DOWN) { - radius = getHeight() / rippleSize; - x = event.getX(); - y = event.getY(); - } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - radius = getHeight() / rippleSize; - x = event.getX(); - y = event.getY(); - if (!((event.getX() <= getWidth() && event.getX() >= 0) && (event - .getY() <= getHeight() && event.getY() >= 0))) { - isLastTouch = false; - x = -1; - y = -1; - } - } else if (event.getAction() == MotionEvent.ACTION_UP) { - if ((event.getX() <= getWidth() && event.getX() >= 0) - && (event.getY() <= getHeight() && event.getY() >= 0)) { - radius++; - } else { - isLastTouch = false; - x = -1; - y = -1; - } - }if (event.getAction() == MotionEvent.ACTION_CANCEL) { - isLastTouch = false; - x = -1; - y = -1; - } - } - return true; - } - - @Override - protected void onFocusChanged(boolean gainFocus, int direction, - Rect previouslyFocusedRect) { - if (!gainFocus) { - x = -1; - y = -1; - } - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - // super.onInterceptTouchEvent(ev); - return true; - } - - public Bitmap makeCircle() { - Bitmap output = Bitmap.createBitmap(getWidth(), getHeight(), - Config.ARGB_8888); - Canvas canvas = new Canvas(output); - canvas.drawARGB(0, 0, 0, 0); - Paint paint = new Paint(); - paint.setAntiAlias(true); - if (rippleColor == null) - rippleColor = makePressColor(); - paint.setColor(rippleColor); - x = (xRippleOrigin == null) ? x : xRippleOrigin; - y = (yRippleOrigin == null) ? y : yRippleOrigin; - canvas.drawCircle(x, y, radius, paint); - if (radius > getHeight() / rippleSize) - radius += rippleSpeed; - if (radius >= getWidth()) { - x = -1; - y = -1; - radius = getHeight() / rippleSize; - if (onClickListener != null) - onClickListener.onClick(this); - } - return output; - } - - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - if (x != -1) { - Rect src = new Rect(0, 0, getWidth(), getHeight()); - Rect dst = new Rect(0, 0, getWidth(), getHeight()); - canvas.drawBitmap(makeCircle(), src, dst, null); - invalidate(); - } - } - - /** - * Make a dark color to ripple effect - * - * @return - */ - protected int makePressColor() { - int r = (this.backgroundColor >> 16) & 0xFF; - int g = (this.backgroundColor >> 8) & 0xFF; - int b = (this.backgroundColor >> 0) & 0xFF; - r = (r - 30 < 0) ? 0 : r - 30; - g = (g - 30 < 0) ? 0 : g - 30; - b = (b - 30 < 0) ? 0 : b - 30; - return Color.rgb(r, g, b); - } - - @Override - public void setOnClickListener(OnClickListener l) { - onClickListener = l; - } - - public void setRippleColor(int rippleColor) { - this.rippleColor = rippleColor; + protected void setAttributes(AttributeSet attrs, TypedArray style) { + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); + rippleSpeed = 30f; + clickAfterRipple = false; } +// // Set atributtes of XML to View +// protected void setAttributes(AttributeSet attrs) { +// +// // Set background Color +// // Color by resource +// int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, +// "background", -1); +// if (bacgroundColor != -1) { +// setBackgroundColor(getResources().getColor(bacgroundColor)); +// } else { +// // Color by hexadecimal +// background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); +// if (background != -1) +// setBackgroundColor(background); +// else +// setBackgroundColor(this.backgroundColor); +// } +// // Set Ripple Color +// // Color by resource +// int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML, +// ML_RIPPLE_COLOR, -1); +// if (rippleColor != -1) { +// setRippleColor(getResources().getColor(rippleColor)); +// } else { +// // Color by hexadecimal +// int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_RIPPLE_COLOR, -1); +// if (background != -1) +// setRippleColor(background); +// else +// setRippleColor(makePressColor()); +// } +// +// rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, +// ML_RIPPLE_SPEED, 20f); +// } +// +// // Set color of background +// public void setBackgroundColor(int color) { +// this.backgroundColor = color; +// if (isEnabled()) +// beforeBackground = backgroundColor; +// super.setBackgroundColor(color); +// } +// +// public void setRippleSpeed(int rippleSpeed) { +// this.rippleSpeed = rippleSpeed; +// } +// +// // ### RIPPLE EFFECT ### +// +// float x = -1, y = -1; +// float radius = -1; +// +// @Override +// public boolean onTouchEvent(MotionEvent event) { +// invalidate(); +// if (isEnabled()) { +// isLastTouch = true; +// if (event.getAction() == MotionEvent.ACTION_DOWN) { +// radius = getHeight() / rippleSize; +// x = event.getX(); +// y = event.getY(); +// } else if (event.getAction() == MotionEvent.ACTION_MOVE) { +// radius = getHeight() / rippleSize; +// x = event.getX(); +// y = event.getY(); +// if (!((event.getX() <= getWidth() && event.getX() >= 0) && (event +// .getY() <= getHeight() && event.getY() >= 0))) { +// isLastTouch = false; +// x = -1; +// y = -1; +// } +// } else if (event.getAction() == MotionEvent.ACTION_UP) { +// if ((event.getX() <= getWidth() && event.getX() >= 0) +// && (event.getY() <= getHeight() && event.getY() >= 0)) { +// radius++; +// } else { +// isLastTouch = false; +// x = -1; +// y = -1; +// } +// }if (event.getAction() == MotionEvent.ACTION_CANCEL) { +// isLastTouch = false; +// x = -1; +// y = -1; +// } +// } +// return true; +// } +// +// @Override +// protected void onFocusChanged(boolean gainFocus, int direction, +// Rect previouslyFocusedRect) { +// if (!gainFocus) { +// x = -1; +// y = -1; +// } +// } +// +// @Override +// public boolean onInterceptTouchEvent(MotionEvent ev) { +// // super.onInterceptTouchEvent(ev); +// return true; +// } +// +// public Bitmap makeCircle() { +// Bitmap output = Bitmap.createBitmap(getWidth(), getHeight(), +// Config.ARGB_8888); +// Canvas canvas = new Canvas(output); +// canvas.drawARGB(0, 0, 0, 0); +// Paint paint = new Paint(); +// paint.setAntiAlias(true); +// if (rippleColor == null) +// rippleColor = makePressColor(); +// paint.setColor(rippleColor); +// x = (xRippleOrigin == null) ? x : xRippleOrigin; +// y = (yRippleOrigin == null) ? y : yRippleOrigin; +// canvas.drawCircle(x, y, radius, paint); +// if (radius > getHeight() / rippleSize) +// radius += rippleSpeed; +// if (radius >= getWidth()) { +// x = -1; +// y = -1; +// radius = getHeight() / rippleSize; +// if (onClickListener != null) +// onClickListener.onClick(this); +// } +// return output; +// } +// +// protected void onDraw(Canvas canvas) { +// super.onDraw(canvas); +// if (x != -1) { +// Rect src = new Rect(0, 0, getWidth(), getHeight()); +// Rect dst = new Rect(0, 0, getWidth(), getHeight()); +// canvas.drawBitmap(makeCircle(), src, dst, null); +// invalidate(); +// } +// } +// +// /** +// * Make a dark color to ripple effect +// * +// * @return +// */ +// protected int makePressColor() { +// int r = (this.backgroundColor >> 16) & 0xFF; +// int g = (this.backgroundColor >> 8) & 0xFF; +// int b = (this.backgroundColor >> 0) & 0xFF; +// r = (r - 30 < 0) ? 0 : r - 30; +// g = (g - 30 < 0) ? 0 : g - 30; +// b = (b - 30 < 0) ? 0 : b - 30; +// return Color.rgb(r, g, b); +// } +// +// @Override +// public void setOnClickListener(OnClickListener l) { +// onClickListener = l; +// } +// +// public void setRippleColor(int rippleColor) { +// this.rippleColor = rippleColor; +// } +// public void setxRippleOrigin(Float xRippleOrigin) { this.xRippleOrigin = xRippleOrigin; } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java index 391d4f2..1f31001 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java @@ -1,8 +1,10 @@ package com.gc.materialdesign.views; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -22,31 +24,23 @@ public class ProgressBarCircularIndeterminate extends CustomView { public ProgressBarCircularIndeterminate(Context context, AttributeSet attrs) { super(context, attrs); - setAttributes(attrs); - + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); } // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs){ - - setMinimumHeight(Utils.dpToPx(32, getResources())); - setMinimumWidth(Utils.dpToPx(32, getResources())); - - //Set background Color - // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - else - setBackgroundColor(Color.parseColor("#1E88E5")); - } + protected void setAttributes(AttributeSet attrs, TypedArray style){ - setMinimumHeight(Utils.dpToPx(3, getResources())); + setMinimumHeight(Utils.dpToPx(32, getResources())); + setMinimumWidth(Utils.dpToPx(32, getResources())); + + //Set background Color + // Color by resource + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); + + setMinimumHeight(Utils.dpToPx(3, getResources())); } diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java index d9cba4b..008ce17 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ProgressBarDeterminate.java @@ -1,9 +1,11 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.drawable.GradientDrawable; @@ -26,11 +28,12 @@ public class ProgressBarDeterminate extends CustomView { public ProgressBarDeterminate(Context context, AttributeSet attrs) { super(context, attrs); - setAttributes(attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); } // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs) { + protected void setAttributes(AttributeSet attrs, TypedArray style){ progressView = new View(getContext()); LayoutParams params = new LayoutParams(1, 1); @@ -40,21 +43,13 @@ protected void setAttributes(AttributeSet attrs) { //Set background Color // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, "background", -1); - if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - else - setBackgroundColor(Color.parseColor("#1E88E5")); - } + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); - min = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MIN, 0); - max = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MAX, 100); - progress = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_PROGRESS, min); + min = AttributesUtils.getMin(getResources(),attrs,style,0); + max = AttributesUtils.getMax(getResources(),attrs,style,100); + progress = AttributesUtils.getProgress(getResources(),attrs,style,min); setMinimumHeight(Utils.dpToPx(3, getResources())); diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java index 490bbcb..45cce62 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Slider.java @@ -2,6 +2,7 @@ import android.app.Dialog; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -20,6 +21,7 @@ import android.widget.TextView; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import com.nineoldandroids.view.ViewHelper; @@ -39,7 +41,8 @@ public class Slider extends CustomView { public Slider(Context context, AttributeSet attrs) { super(context, attrs); - setAttributes(attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); } public int getMax() { @@ -252,7 +255,7 @@ protected void onDraw(Canvas canvas) { } // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs) { + protected void setAttributes(AttributeSet attrs, TypedArray style){ setBackgroundResource(R.drawable.background_transparent); @@ -262,22 +265,14 @@ protected void setAttributes(AttributeSet attrs) { // Set background Color // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, - "background", -1); - if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } - - showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - "showNumberIndicator", false); - min = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MIN, 0); - max = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_MAX, 0); - value = attrs.getAttributeIntValue(MATERIALDESIGNXML, ML_VALUE, min); + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); + + showNumberIndicator = AttributesUtils.getShowNumberIndicator(getResources(),attrs,style,false); + min = AttributesUtils.getMin(getResources(),attrs,style,0); + max = AttributesUtils.getMax(getResources(),attrs,style,100); + value = AttributesUtils.getValue(getResources(),attrs,style,min); ball = new Ball(getContext()); RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20, diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java index ad8d8f9..5a54b2f 100644 --- a/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Switch.java @@ -1,6 +1,7 @@ package com.gc.materialdesign.views; import android.content.Context; +import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -15,6 +16,7 @@ import android.widget.RelativeLayout; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.AttributesUtils; import com.gc.materialdesign.utils.Utils; import com.nineoldandroids.animation.ObjectAnimator; import com.nineoldandroids.view.ViewHelper; @@ -35,7 +37,8 @@ public class Switch extends CustomView { public Switch(Context context, AttributeSet attrs) { super(context, attrs); - setAttributes(attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); setOnClickListener(new OnClickListener() { @Override @@ -49,7 +52,7 @@ public void onClick(View arg0) { } // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs) { + protected void setAttributes(AttributeSet attrs, TypedArray style){ setBackgroundResource(R.drawable.background_transparent); @@ -59,19 +62,11 @@ protected void setAttributes(AttributeSet attrs) { // Set background Color // Color by resource - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML, - "background", -1); - if (bacgroundColor != -1) { - setBackgroundColor(getResources().getColor(bacgroundColor)); - } else { - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if (background != -1) - setBackgroundColor(background); - } + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); - check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, ML_CHECKED, - false); + check = AttributesUtils.getChecked(getResources(), attrs, style, false); eventCheck = check; ball = new Ball(getContext()); RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20, diff --git a/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable-xxxhdpi/sprite_check.png b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable-xxxhdpi/sprite_check.png new file mode 100644 index 0000000000000000000000000000000000000000..483004d7aee570526bc8f501beba3caaa9e43cb0 GIT binary patch literal 4580 zcmb7G_d6S0*bZKs8nJ@fvxvQ`R;XE{_ST@PR_&DtVpPzoUAuO@s%p~+RaEU+v$3Pp zrXpxReZTAb1HK>5xt?>b``pjEuKPL9O&{E+rDCT7006Z5dJuB}fN15$7NH=!*@f6d z@c;mo;uCFc(?Ik4T0HtX+6vOj3JMZ3U}*p#te`ME)Z*bhOX3(>5pDX4J~?yzsi!%y z9xYlg9ehWclHQ>EC4f%>V&M-lORuDm5m`Z$X{R^vCC3w)HSGQaf=oa2XX41#cdG+o zKZYNS7msfG5pNwoM5j3SXOslxQq*T;n7jhz+LjZ|4V8y?& zQHuqyOPog>HJ9R@2gI|YJ8tn@T;7>dPw4^tDb8%S<&y@O=BD6|@$(KK)jJ@6 zlfm2;Ipa|&gHb-)SQ)E~z+-Xys9$;Rbjl|($h)ASz|l4L!;K~3^;BiXu9S2a5G#%X z-!9W71dR*QPtfT1+h_nqJx~CMyjlWp1wM51mVmwzk%^U94+pI14LToAO4%k&~2`TS*c&HsXCt2hzQP5wKWi-qAzpeso-QwK6sX~bic-E98_m_(YVm7swy zevPN={arrap8b3Q&oG{CLtMejt^wx)h}>b|p^S7B8$W(1hIDj zXti5Q%sd$h%n{`LQk0cFcJCRyNgG{Elqk}WtUZH=GD_Uw*w*eWf08KreWXcm&I*GK zm3mAS1A?AGF7wC8f8*{ z;8H2iRbOCp5jlOI73KjEWg)wF&cWmzbBXY=OB{nS*bjQIgtTM@3 z&f?U<;osbPo6<1IGrgl4MyEl&=XIaW>?$nEf-HU{Og70_&g&{$C~Jo|2B3~fH}5lv z_a&`qubL%`T#7svfm$Hnnz%n~pAMeZ-Lc(KqScnIBpo+@Qqkn+8P_DroSa-}&}2|# zkoxr*v*_(ojtP?OAEz<|S3)pB)l$OJ#IkEgXhva1>}~zbR&{vw(Tu_L!i?_p_Zr!0 z*!0wNYfWekc1q((?i1wG4X>XQO0`Epw|vruIQI))DJSBVW|8tEa{O}Ep8Hdr;{~&m zv&U0kC*Mx0l$}}RzuPM^SR)>yVA;k1&gfkJyViKcysyUkhB{CZGuq$yCUA$woMsPFv0}=Dq}3W>=Q9hqtK{mC|xVfA(J?A zdzf^qb0kq>oaF(F7K#kTVZ=C+&SNwep`lYnUfho`Jzd{^$HkS! zeJLGrot)^Fo@kgoB1834L47<5L$y@HmFq%OwoYf~du)G3&0VmvRvNxGL=BaN_n+WT z*m0@tJM94uyN(sUG_8G`LW-t2f7cN!%f zbv-lR{tOW6;cK^FQ_ezyk34H51;V7{9tW7}|9?#e(SRiABA=^cX5BFJ+o#Ph=7shZ~a{%ZCbb_8b%hsTk$m zwdYYEI{W12$EFdVAs?J%Uax0A%s3HJR5{lx3Mi8Db7`MHHXaf_hMi!XV(fYxC+th? z-?z8~Rp7o7EXUtg)J9nE)`RWTy88V_Vw#c7Po74LG=aq>quRk9jwb0=6R+PioWXbP zQOwCYeToWg-qnjq3nFt$ZBO+Q5g;!1P?}tmh z$E=2}R%dq?ms)R&ScAtTxfi)UpaaRF_XpE*RC9iQG7`m5N7i}lRW5w%4DYP}c{Dd=Rb^>yckWy7axfBsA&iohB_zXgVak_W3c8BF zqDKfF?fPXkO+R|!tMDH&NhGk5w2={s*Anh^{@5(b-lY)C`yIl9!!fztdt{SLES<{@{9DjCf_}2t>!%No5FS%97Zj-4dawc|2sygn2iWH;Pk}tEStkLyF zoh<%)lV7gVS9i_6`F+=G<3$g4UTj+t>Ts=rzGF+afvm9BjiO0(^5yGu4!GQPgX0d5 z+Pxh$l|z@FI92FUgRr{$pHuk9ZQcvlKIACmgn#k=fDlYrQr!t3cBMa?kyq8HF80Ua za(H7t6cctOBgL#L|J&j8YN|fpxf(O~XL8^DAZYIN+8R{v;gs{yEIM#SV%O(SXKpA^ zw*8>tKukRszJ0-VdbD4aVp0qzIY*vczVP?BbMup=^w+Zu1OUMNe-}|$g?b18K>ko4 zqG=IUuvh4qGHt<@FvfGtk4Iq?ox)a~>G{~xOV(l$ywb_Z5C{+oG3I#$5!~)TvAV3K zvPP5&A$cfbd3eNQV}$}r`#q;UQy7@7;iRc%KxVfnj9Qi9lS+4w2UXa-<#YY6rodZ) zTcvxadm)vDU7G>(^jZ|Wc0k>flP`QN&f~wl6!MBLl7BJ@FGRJ0YXT6EhZNL z@CHI9g`m8Fkg|2(+$9myxcq$|lR4x*xL|KkG0AZh@*l+{4}F*Lqhl2>nJpYIl2sS> zAJCYRxQ<)sn%*ngtJC7s#h^1SCdtt9d<%(`*Mz6Ywp5F!?AdK0p%s(AQGdhM32da>7R1Q&)*#&ifx1Si+NCTZirELT4ZOZCgV zcDw%CGZZ{Sa3_-@<4k_;Egk^B?i&9taC#C4hmViFxO=@Jt9bX%!PU=zbJQoOz*ZIX z->jGm{qC+*_N;Bf{M;cv8=eOpBrGG@3%3{I+4Hw@*t^;Mm4psTMzxkvD#(Zur=E|c z#oVVSWwBV-X&TEKHuRw6f-DO`)E+)$1=VjOGc(wBK z8RMJO10TqS;G&qln7E)xlh7D~&KG=u+O|r{`HK(OAGzL|j(OXJiJQ=QO)-Vl*?_A% zb=WT^+1PX2v3j=dut{E;s22@YMq~pW3tvO1i=9z!-`()d9sGtfg>u(do{uo(%R0Xr zGp9SYCE%i}IAu@uBht%%Eg`1&}OCzleNzBV@j}HDH^9Ejyc)}`{ zre}k6+WTq|7DE^uJvfHs6ztoxv=t-mt3F`!`r*Ho9ePZ(_S1#V4ec=j9bFZ6m|;m* z*O%uaCZ>L_gc#(sXbBhb6xVK;b(Semd4$fp!FI|pL3ZbaFh-VBK**ULXq#U(0 z-+g1H-g>f_%)av)tb?|0QG|LzC@ychB*@k7T)RMWJ=)`z->{nnzj)_-VdEMqQSUsH zsw7n%HTt00dhg;Z`>QJ-X8LfV#mcreABjcSSc~wA!vn}c?e$(ul9^MRPlhCe zFv3guc+qggMW8e&X5co_<>07b`^nSoO+#fo%;)E*@;M1o<)%g8niXMH9QrF9r;I`U zU`=p-(GFz!eUkqkQOR~W#MXoKgAAL%LHxg!3F1wd>FU&4yF)?%Xkahb(I@TfX&^b} zo{C3y$|h?EHse^R|I{6d{m8m<)MUOEs!4Jf*>~ZX8}@cd!DN4>u^4_@=G+BW6GD)R zBWV|I*(PyYZCMO|J&Qh;wInxNZ|+qj=HgflCHJrf?Xpg6{hpluZKT$I#TR?7Jp!S9 z_QE-koK`2%zZuR@%+VRBtf5Yrkc`G~F?WvutY%gI-B6Xj`*9MSGxTo{MxC*w_^_sdJQ2ep^mrSGI>}F% z-%NnZKP)T0dOM+6{0#~aLu9p(iG|BnMnCy0o6GJ$H#sMCMOtmeP92nL?5O==t*%3mMr2XQNAa(;QgN(O z=E7#?49$gdc0NAS;71G@;DpsRS+HrsC9s&5rwQ1^{)B^roAT0NUYG(&jxq|dkF+tb zZxlu6LK>leXYPxY3x6he+V^+2J+lx~0p~)t$X8P7_MeO?`{a8M=p1DYfq03V7M<3T z5H8G++$6bfv8g__E!r%H_OXi3y$9CKLf4O6Z_4$5qNjU#Lp&9y7|&S>p8TcvpAypD isEnTa|93R~ArT{Gssau7p5M$|fWFQH$U7~U*#801{KgUh literal 0 HcmV?d00001