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 @@ - + 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..e9823d0 --- /dev/null +++ b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/utils/AttributesUtils.java @@ -0,0 +1,285 @@ +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, + 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 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 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"; + + + + 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){ + 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(xml, name, -1); + if (bacgroundColor != -1) + return bacgroundColor; + else if(typedArray != null){ + bacgroundColor = typedArray.getResourceId(position,-1); + if(bacgroundColor != -1) { + return (resources.getColor(bacgroundColor)); + }else { + // Color by hexadecimal + // Color by hexadecimal + bacgroundColor = typedArray.getInt(position, -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(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(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(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(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); + } + } + 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 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(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, + 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, 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, boolean defaaultValue){ + return getBoolean(resources, attrs, style, ML_ANIMATED, ANIMATED, defaaultValue); + } + + 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, int defaultValue){ + return getInt(resources,attrs, style, ML_MAX, MAX,defaultValue); + } + + 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, int defaultValue){ + return getInt(resources,attrs, style, ML_VALUE, VALUE,defaultValue); + } + + 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, boolean defaultValue){ + return getBoolean(resources, attrs, style, ML_CHECKED, CHECKED,defaultValue); + } + + 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 defaultValue){ + boolean bool = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, + name, defaultValue); + return style.getBoolean(position,bool); + } + + public static int getInt(Resources resources, AttributeSet attrs, TypedArray style, String name, int position, int defaultValue){ + int integer = attrs.getAttributeIntValue(MATERIALDESIGNXML, + name, defaultValue); + if(integer != defaultValue){ + return integer; + }else if(style != null){ + integer = style.getInt(position, defaultValue); + } + 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 _float; + } + + + +} 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..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 @@ -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; @@ -35,11 +37,17 @@ public abstract class Button extends CustomView { public Button(Context context, AttributeSet attrs) { super(context, attrs); setDefaultProperties(); - clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - "animate", true); - setAttributes(attrs); + 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(); } @@ -53,7 +61,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 ### @@ -165,7 +173,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) { @@ -173,10 +181,21 @@ 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; } + 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 b1664c9..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,30 +1,37 @@ 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.Paint; import android.graphics.Typeface; import android.util.AttributeSet; +import android.view.Gravity; import android.widget.RelativeLayout; 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())); @@ -32,89 +39,96 @@ protected void setDefaultProperties(){ } @Override - protected void setAttributes(AttributeSet attrs) { - // 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.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); - } + protected void setAttributes(AttributeSet attrs, TypedArray typedArray) { - @Override - public TextView getTextView() { - return textButton; - } - - public String getText(){ - return textButton.getText().toString(); - } + //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 + textButton = new TextView(getContext()); + 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); + + } + + + @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(); + } + + } + + public void setTextSize(float size){ + if (getTextView() != null) + getTextView().setTextSize(size); + } + + /** + * 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/ButtonFloat.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/ButtonFloat.java index b4970b9..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,12 +1,14 @@ 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; 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,38 +74,16 @@ 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 - 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 e261c7d..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 @@ -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,115 +11,73 @@ import android.graphics.Rect; import android.graphics.Typeface; import android.util.AttributeSet; +import android.view.Gravity; import android.widget.RelativeLayout; 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); -// 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())); - } - + + 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, TypedArray typedArray) { + + //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 + textButton = new TextView(getContext()); + 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); + + } + + + public void setTextSize(float size){ + if (getTextView() != null) + getTextView().setTextSize(size); + } // /** // * Center text in button // */ @@ -131,20 +90,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/Card.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/Card.java index 74bc4ef..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 @@ -62,7 +59,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 27b41de..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); - final boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - "check", 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, @@ -106,6 +100,7 @@ public void run() { @Override public void invalidate() { + if (checkView != null) checkView.invalidate(); super.invalidate(); } @@ -119,7 +114,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; @@ -157,7 +153,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); } @@ -192,9 +188,9 @@ public void setChecked(boolean check) { android.R.color.transparent)); if (check) { step = 0; - } - if (check) checkView.changeBackground(); + } + } @@ -222,7 +218,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/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/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java b/MaterialDesignLibrary/MaterialDesign/src/main/java/com/gc/materialdesign/views/LayoutRipple.java index bc27f3b..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, - "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()); - } - - rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, - "rippleSpeed", 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 8001191..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; @@ -14,124 +16,119 @@ 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); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); + } + + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs, TypedArray style){ + + 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 = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); + + 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())); + + 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_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 9fc435b..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,26 +21,28 @@ 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; 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); - setAttributes(attrs); + TypedArray typedArray = context.obtainStyledAttributes(attrs.getStyleAttribute(), AttributesUtils.attrs); + setAttributes(attrs, typedArray); } public int getMax() { @@ -74,7 +77,7 @@ public int getValue() { } public void setValue(final int value) { - if (placedBall == false) + if (!placedBall) post(new Runnable() { @Override @@ -84,9 +87,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(); } @@ -94,7 +98,8 @@ public void run() { @Override public void invalidate() { - ball.invalidate(); + if (ball != null) + ball.invalidate(); super.invalidate(); } @@ -112,6 +117,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 @@ -249,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); @@ -259,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); - } + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); - showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, - "showNumberIndicator", false); - min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0); - max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0); - value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min); + 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, @@ -318,7 +316,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); @@ -331,17 +329,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 +393,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..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; @@ -25,16 +27,18 @@ 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; 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 @@ -48,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); @@ -58,198 +62,201 @@ 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); - } - - 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) { + int bacgroundColor = AttributesUtils.getBackgroundColor(getResources(),attrs,style); + if (bacgroundColor != -1) + setBackgroundColor(bacgroundColor); + + check = AttributesUtils.getChecked(getResources(), attrs, style, 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 (onCheckListener != null) + onCheckListener.onCheck(Switch.this, check); + 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_background); + 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..62890de 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 @@ -38,6 +43,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 +53,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; } @@ -93,6 +100,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 +142,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 +161,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 +211,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 +237,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/drawable-xxxhdpi/sprite_check.png b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable-xxxhdpi/sprite_check.png new file mode 100644 index 0000000..483004d Binary files /dev/null and b/MaterialDesignLibrary/MaterialDesign/src/main/res/drawable-xxxhdpi/sprite_check.png differ 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/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/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 @@ - + - + - + - + - + - + - - + + - - - + - - - + - + - + - + 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); } 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/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); + } + }); + } } 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..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 @@ -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; @@ -10,70 +11,119 @@ 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; 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.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; + } + }; } diff --git a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_buttons.xml index 9215203..51ab0d7 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,14 +69,14 @@ + android:layout_height="wrap_content" > @@ -108,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" /> @@ -141,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" /> @@ -173,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="3000" + materialdesign:MLmin="150" + 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..12edcc1 100644 --- a/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml +++ b/MaterialDesignLibrary/MaterialDesignDemo/src/main/res/layout/activity_widgets.xml @@ -98,6 +98,42 @@ android:layout_centerInParent="true" android:text="Show Color Selector" /> + + + + + + + + + + + + + + \ No newline at end of file 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 @@ + + diff --git a/MaterialDesignLibrary/build.gradle b/MaterialDesignLibrary/build.gradle index 7a979d7..3129176 100644 --- a/MaterialDesignLibrary/build.gradle +++ b/MaterialDesignLibrary/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.+' + classpath 'com.android.tools.build:gradle:2.2.2' // COMMENT TO DEVELOPER MODE / UNCOMMENT TO UPLOAD TO BINTARRAY // classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5' // classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' diff --git a/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties b/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties index 707f4c9..3422c2c 100644 --- a/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties +++ b/MaterialDesignLibrary/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat Aug 22 18:02:59 CEST 2015 +#Mon Nov 07 19:27:37 CET 2016 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip