diff --git a/.settings/gradle/org.springsource.ide.eclipse.gradle.core.import.prefs b/.settings/gradle/org.springsource.ide.eclipse.gradle.core.import.prefs new file mode 100644 index 0000000..692e075 --- /dev/null +++ b/.settings/gradle/org.springsource.ide.eclipse.gradle.core.import.prefs @@ -0,0 +1,10 @@ +#org.springsource.ide.eclipse.gradle.core.preferences.GradleImportPreferences +#Sun Jan 11 18:49:20 CET 2015 +addResourceFilters=true +afterTasks=afterEclipseImport; +beforeTasks=cleanEclipse;eclipse; +enableAfterTasks=true +enableBeforeTasks=true +enableDSLD=false +enableDependendencyManagement=true +projects=MaterialDesign; diff --git a/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs b/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs new file mode 100644 index 0000000..a59d3b8 --- /dev/null +++ b/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs @@ -0,0 +1,4 @@ +#org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences +#Sun Jan 11 18:49:02 CET 2015 +build.family.org.gradle.tooling.model.eclipse.HierarchicalEclipseProject=;MaterialDesign;MaterialDesignDemo; +org.springsource.ide.eclipse.gradle.rootprojectloc= diff --git a/MaterialDesign/.classpath b/MaterialDesign/.classpath index 5444437..efc76ed 100644 --- a/MaterialDesign/.classpath +++ b/MaterialDesign/.classpath @@ -1,9 +1,9 @@ + - - + diff --git a/MaterialDesign/.project b/MaterialDesign/.project index e49dea6..e945e83 100644 --- a/MaterialDesign/.project +++ b/MaterialDesign/.project @@ -27,7 +27,8 @@ - com.android.ide.eclipse.adt.AndroidNature + org.springsource.ide.eclipse.gradle.core.nature org.eclipse.jdt.core.javanature + com.android.ide.eclipse.adt.AndroidNature diff --git a/MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs b/MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs new file mode 100644 index 0000000..0787811 --- /dev/null +++ b/MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs @@ -0,0 +1,4 @@ +#org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences +#Sun Jan 11 18:49:24 CET 2015 +org.springsource.ide.eclipse.gradle.linkedresources= +org.springsource.ide.eclipse.gradle.rootprojectloc=.. diff --git a/MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs b/MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs new file mode 100644 index 0000000..ea4c4ff --- /dev/null +++ b/MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs @@ -0,0 +1,9 @@ +#org.springsource.ide.eclipse.gradle.core.actions.GradleRefreshPreferences +#Sun Jan 11 18:49:23 CET 2015 +addResourceFilters=true +afterTasks=afterEclipseImport; +beforeTasks=cleanEclipse;eclipse; +enableAfterTasks=true +enableBeforeTasks=true +enableDSLD=false +useHierarchicalNames=false diff --git a/MaterialDesign/build.gradle b/MaterialDesign/build.gradle index 2c02db9..8db9cee 100644 --- a/MaterialDesign/build.gradle +++ b/MaterialDesign/build.gradle @@ -25,8 +25,8 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 21 - versionCode 1 - versionName '1.0' + versionCode 2 + versionName '1.1' } } @@ -35,8 +35,8 @@ ext.issueUrl = 'https://github.com/navasmdc/MaterialDesignLibrary/issues' ext.gitUrl = 'https://github.com/navasmdc/MaterialDesignLibrary.git' bintray { - user = hasProperty('BINTRAY_USER') ? BINTRAY_USER : "_" - key = hasProperty('BINTRAY_KEY') ? BINTRAY_PASSWORD : "_" + user = hasProperty('BINTRAY_USER') ? BINTRAY_USER : "" + key = hasProperty('BINTRAY_KEY') ? BINTRAY_PASSWORD : "" configurations = ["archives"] pkg { diff --git a/MaterialDesign/project.properties b/MaterialDesign/project.properties index db721fd..91d2b02 100644 --- a/MaterialDesign/project.properties +++ b/MaterialDesign/project.properties @@ -11,5 +11,5 @@ #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt # Project target. -target=android-8 +target=android-19 android.library=true diff --git a/MaterialDesign/src/com/gc/materialdesign/utils/Utils.java b/MaterialDesign/src/com/gc/materialdesign/utils/Utils.java index 7340a16..b496f75 100644 --- a/MaterialDesign/src/com/gc/materialdesign/utils/Utils.java +++ b/MaterialDesign/src/com/gc/materialdesign/utils/Utils.java @@ -1,7 +1,6 @@ package com.gc.materialdesign.utils; import android.content.res.Resources; -import android.graphics.Rect; import android.util.TypedValue; import android.view.View; @@ -10,38 +9,18 @@ public class Utils { /** * Convert Dp to Pixel - * 将dp转换为pixel */ public static int dpToPx(float dp, Resources resources){ float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, resources.getDisplayMetrics()); return (int) px; } - /** - * @param value - * @return 将dip或者dp转为float - */ - public static float dipOrDpToFloat(String value) { - if (value.indexOf("dp") != -1) { - value = value.replace("dp", ""); - } - else { - value = value.replace("dip", ""); - } - return Float.parseFloat(value); - } - - - /** - * 这里看似是得到控件相对的坐标,但是如果这个滑动条在可以上下滚动的布局中就会出现问题。 - * 因为这里的坐标都是死的,在上下滚动的view中父控件的top仍旧不变,但实际上是应该获得动态数值的。 - * @param myView - * @return - */ public static int getRelativeTop(View myView) { - Rect bounds = new Rect(); - myView.getGlobalVisibleRect(bounds); - return bounds.top; +// if (myView.getParent() == myView.getRootView()) + if(myView.getId() == android.R.id.content) + return myView.getTop(); + else + return myView.getTop() + getRelativeTop((View) myView.getParent()); } public static int getRelativeLeft(View myView) { diff --git a/MaterialDesign/src/com/gc/materialdesign/views/Button.java b/MaterialDesign/src/com/gc/materialdesign/views/Button.java index 257f3e0..c4f7c48 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/Button.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/Button.java @@ -1,74 +1,179 @@ package com.gc.materialdesign.views; +import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.Utils; + import android.content.Context; import android.graphics.Bitmap; -import android.graphics.Bitmap.Config; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.Bitmap.Config; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.LayerDrawable; import android.util.AttributeSet; +import android.view.MotionEvent; import android.widget.TextView; -import com.gc.materialdesign.R; -import com.gc.materialdesign.utils.Utils; +public abstract class Button extends CustomView { -public abstract class Button extends RippleView { + final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; + + // Complete in child class + int minWidth; + int minHeight; + int background; + float rippleSpeed = 10f; + int rippleSize = 3; + Integer rippleColor; + OnClickListener onClickListener; + int backgroundColor = Color.parseColor("#1E88E5"); public Button(Context context, AttributeSet attrs) { super(context, attrs); - onInitAttributes(attrs); + setDefaultProperties(); + setAttributes(attrs); + beforeBackground = backgroundColor; + if(rippleColor==null) + rippleColor = makePressColor(); + } + + protected void setDefaultProperties() { + // Min size + setMinimumHeight(Utils.dpToPx(minHeight, getResources())); + setMinimumWidth(Utils.dpToPx(minWidth, getResources())); + // Background shape + setBackgroundResource(background); + setBackgroundColor(backgroundColor); } + + // Set atributtes of XML to View + abstract protected void setAttributes(AttributeSet attrs); + + // ### RIPPLE EFFECT ### + + float x = -1, y = -1; + float radius = -1; + @Override - protected void onInitDefaultValues() { - backgroundColor = Color.parseColor("#2196f3");// 默认的背景色,蓝色 - ///beforeBackground = backgroundColor;// error + 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; + } + }else if (event.getAction() == MotionEvent.ACTION_CANCEL) { + isLastTouch = false; + x = -1; + y = -1; + } + } + return true; } - - protected void onInitAttributes(AttributeSet attrs) { - setAttributes(attrs); + + @Override + protected void onFocusChanged(boolean gainFocus, int direction, + Rect previouslyFocusedRect) { + if (!gainFocus) { + x = -1; + y = -1; + } } - - // ### RIPPLE EFFECT ### - - /** - * @return 涟漪的bitmap - */ + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + // super.onInterceptTouchEvent(ev); + return true; + } + public Bitmap makeCircle() { - // 画涟漪时要考虑到按钮的边界区域,不要把按钮的阴影边界也填满了 Bitmap output = Bitmap.createBitmap( - getWidth() - Utils.dpToPx(6, getResources()), - getHeight() - Utils.dpToPx(7, getResources()), Config.ARGB_8888); - return makeCircleFromBitmap(output); + getWidth() - Utils.dpToPx(6, getResources()), getHeight() + - Utils.dpToPx(7, getResources()), Config.ARGB_8888); + Canvas canvas = new Canvas(output); + canvas.drawARGB(0, 0, 0, 0); + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(rippleColor); + 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; } - - // Set color of background + + /** + * 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; + } + + // Set color of background public void setBackgroundColor(int color) { - backgroundColor = color; - if (isEnabled()) { + this.backgroundColor = color; + if (isEnabled()) beforeBackground = backgroundColor; - } try { LayerDrawable layer = (LayerDrawable) getBackground(); - // 每个按钮的框架都是由drawable中的xml文件制定的,xml文件中都有一个item的id叫:shape_bacground - GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); - /** - * 给这个图片设置背景色,因为图片的主体是透明的所以可以直接显示背景色 - * 效果就是一个透明但有阴影的框架下有了背景色,这样的方式可以方便的设置不同颜色的按钮,让按钮看起来还是浑然一体 - */ + GradientDrawable shape = (GradientDrawable) layer + .findDrawableByLayerId(R.id.shape_bacground); shape.setColor(backgroundColor); - /** - * 当重新设定背景色后,要检查涟漪颜色。如果已经设定了涟漪颜色,那么就用之前的。如果没设定就重新生成 - */ - if (!settedRippleColor) { - rippleColor = makePressColor(255); - } + rippleColor = makePressColor(); } catch (Exception ex) { // Without bacground } } abstract public TextView getTextView(); - + + public void setRippleSpeed(float rippleSpeed) { + this.rippleSpeed = rippleSpeed; + } + + public float getRippleSpeed() { + return this.rippleSpeed; + } } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ButtonFlat.java b/MaterialDesign/src/com/gc/materialdesign/views/ButtonFlat.java index e0a9166..11dbd0a 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ButtonFlat.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ButtonFlat.java @@ -1,44 +1,77 @@ package com.gc.materialdesign.views; +import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.Utils; + import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Typeface; import android.util.AttributeSet; +import android.widget.RelativeLayout; import android.widget.TextView; -import com.gc.materialdesign.R; - -public class ButtonFlat extends ButtonRectangle { +public class ButtonFlat extends Button { + TextView textButton; + public ButtonFlat(Context context, AttributeSet attrs) { super(context, attrs); + } - @Override - protected void onInitDefaultValues(){ - textButton = new TextView(getContext()); + protected void setDefaultProperties(){ minHeight = 36; minWidth = 88; - rippleSpeed = 6f; - defaultTextColor = Color.parseColor("#1E88E5"); - backgroundResId = R.drawable.background_transparent; - rippleColor = Color.parseColor("#88DDDDDD"); - //setBackgroundResource(R.drawable.background_transparent); + rippleSize = 3; + // Min size + setMinimumHeight(Utils.dpToPx(minHeight, getResources())); + setMinimumWidth(Utils.dpToPx(minWidth, getResources())); + setBackgroundResource(R.drawable.background_transparent); + } + + @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);//不调用父类的onDraw()方法。因为这会用ButtonRectangle的onDraw() + super.onDraw(canvas); if (x != -1) { Paint paint = new Paint(); paint.setAntiAlias(true); - if (rippleColor == null) { - paint.setColor(Color.parseColor("#88DDDDDD")); - }else { - paint.setColor(rippleColor); - } + paint.setColor(makePressColor()); canvas.drawCircle(x, y, radius, paint); if(radius > getHeight()/rippleSize) radius += rippleSpeed; @@ -46,22 +79,42 @@ protected void onDraw(Canvas canvas) { x = -1; y = -1; radius = getHeight()/rippleSize; - if (isEnabled() && clickAfterRipple == true && onClickListener != null) { + if(onClickListener != null) onClickListener.onClick(this); - } } + invalidate(); } - invalidate(); + } + /** + * Make a dark color to ripple effect + * @return + */ @Override - public void setBackgroundColor(int color) { - super.setBackgroundColor(color); - if (!settedRippleColor) { - // 如果之前没有设置过涟漪颜色,那么就用默认的 - rippleColor = Color.parseColor("#88DDDDDD"); - } + 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/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloat.java b/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloat.java index acfe228..19f5236 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloat.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloat.java @@ -5,9 +5,11 @@ import com.nineoldandroids.animation.ObjectAnimator; import com.nineoldandroids.view.ViewHelper; +import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; @@ -17,180 +19,167 @@ import android.util.AttributeSet; import android.view.animation.BounceInterpolator; import android.widget.ImageView; +import android.widget.ImageView.ScaleType; import android.widget.RelativeLayout; import android.widget.TextView; -/** - * @author:Jack Tony - * @tips :正常的圆形悬浮按钮,默认sizeIcon = 24;sizeRadius = 28; - * @date :2014-11-1 - */ -public class ButtonFloat extends Button { - - protected int iconSize;// 内部图片大小 - protected int sizeRadius;// 图标半径 - - ImageView icon; // 按钮中的ImageView - Drawable iconDrawable;// imageView中的drawable +public class ButtonFloat extends Button{ + + int sizeIcon = 24; + int sizeRadius = 28; + + + ImageView icon; // Icon of float button + Drawable drawableIcon; + + + public ButtonFloat(Context context, AttributeSet attrs) { super(context, attrs); - } - - @Override - protected void onInitDefaultValues() { - super.onInitDefaultValues(); - icon = new ImageView(getContext()); - iconSize = 24; + setBackgroundResource(R.drawable.background_button_float); sizeRadius = 28; - rippleSpeed = 3; - rippleSize = 5; - minWidth = sizeRadius * 2;// 56dp - minHeight = sizeRadius * 2;// 56dp - backgroundResId = R.drawable.background_button_float; - } - - @Override - protected void onInitAttributes(AttributeSet attrs) { - super.onInitAttributes(attrs); - // 设置按钮中的图标 - int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconDrawable",-1); - if (iconResource != -1) { - iconDrawable = getResources().getDrawable(iconResource); - } - - // animation - boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "animate", false); - if (animate) { - playAnimation(); - } - - if (iconDrawable != null) { - icon.setBackgroundDrawable(iconDrawable); + setDefaultProperties(); + icon = new ImageView(context); + icon.setAdjustViewBounds(true); + icon.setScaleType(ScaleType.CENTER_CROP); + if(drawableIcon != null) { + icon.setImageDrawable(drawableIcon); +// try { +// icon.setBackground(drawableIcon); +// } catch (NoSuchMethodError e) { +// icon.setBackgroundDrawable(drawableIcon); +// } } - // 设置按钮中图标的大小 - String size = attrs.getAttributeValue(MATERIALDESIGNXML, "iconSize"); - if (size != null) { - iconSize = (int) Utils.dipOrDpToFloat(size); - } - setIconParams(); - addView(icon); - } - - private void setIconParams() { - // TODO 自动生成的方法存根 - RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( - Utils.dpToPx(iconSize, getResources()), Utils.dpToPx(iconSize, getResources())); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Utils.dpToPx(sizeIcon, getResources()),Utils.dpToPx(sizeIcon, getResources())); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); icon.setLayoutParams(params); + addView(icon); + } - /** - * float的动画 - */ - private void playAnimation() { - post(new Runnable() { - @Override - public void run() { - float originalY = ViewHelper.getY(ButtonFloat.this) - Utils.dpToPx(24, getResources()); - ViewHelper.setY(ButtonFloat.this, - ViewHelper.getY(ButtonFloat.this) + getHeight() * 3); - ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", originalY); - animator.setInterpolator(new BounceInterpolator()); - animator.setDuration(1500);// 动画持续时间 - animator.start(); - } - }); + protected void setDefaultProperties(){ + rippleSpeed = Utils.dpToPx(2, getResources()); + rippleSize = Utils.dpToPx(5, getResources()); + setMinimumWidth(Utils.dpToPx(sizeRadius*2, getResources())); + setMinimumHeight(Utils.dpToPx(sizeRadius*2, getResources())); + super.background = R.drawable.background_button_float; +// super.setDefaultProperties(); } - + + + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs){ + //Set background Color + // Color by resource + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); + if(bacgroundColor != -1){ + setBackgroundColor(getResources().getColor(bacgroundColor)); + }else{ + // Color by hexadecimal + background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + } + + // Set Ripple Color + // Color by resource + int rippleColor = attrs.getAttributeResourceValue(MATERIALDESIGNXML, + "rippleColor", -1); + if (rippleColor != -1) { + setRippleColor(getResources().getColor(rippleColor)); + } else { + // Color by hexadecimal + int background = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1); + if (background != -1) + setRippleColor(background); + else + setRippleColor(makePressColor()); + } + // Icon of button + int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconFloat",-1); + if(iconResource != -1) + drawableIcon = getResources().getDrawable(iconResource); + boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"animate", false); + if(animate){ + post(new Runnable() { + + @Override + public void run() { + float originalY = ViewHelper.getY(ButtonFloat.this)-Utils.dpToPx(24, getResources()); + ViewHelper.setY(ButtonFloat.this,ViewHelper.getY(ButtonFloat.this)+getHeight()*3); + ObjectAnimator animator = ObjectAnimator.ofFloat(ButtonFloat.this, "y", originalY); + animator.setInterpolator(new BounceInterpolator()); + animator.setDuration(1500); + animator.start(); + } + }); + } + + } + + Integer height; + Integer width; @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (x != -1) { Rect src = new Rect(0, 0, getWidth(), getHeight()); - Rect dst = new Rect(Utils.dpToPx(1, getResources()), - Utils.dpToPx(2, getResources()), - getWidth() - Utils.dpToPx(1, getResources()), - getHeight() - Utils.dpToPx(2, getResources())); + Rect dst = new Rect(Utils.dpToPx(1, getResources()), Utils.dpToPx(2, getResources()), getWidth()-Utils.dpToPx(1, getResources()), getHeight()-Utils.dpToPx(2, getResources())); canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null); + invalidate(); } - invalidate(); - } - - // 主要用于将涟漪的范围限制在圆圈内 - public Bitmap cropCircle(Bitmap bitmap) { - Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888); - Canvas canvas = new Canvas(output); - - final int color = 0xff424242; - final Paint paint = new Paint(); - final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); - - paint.setAntiAlias(true); - canvas.drawARGB(0, 0, 0, 0); - paint.setColor(color); - canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, - bitmap.getWidth() / 2, paint); - paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); - canvas.drawBitmap(bitmap, rect, rect, paint); - return output; } - - // GET AND SET -/* @Override - public void setEnabled(boolean enabled) { - // TODO 自动生成的方法存根 - super.setEnabled(enabled); - icon.setEnabled(enabled); - if (enabled) { - getBackground().setAlpha(255); - }else { - getBackground().setAlpha(25); - } - }*/ - public void isAnimate(boolean isAnimate) { - if (isAnimate) { - playAnimation(); - } - } + public ImageView getIcon() { return icon; } - - public Drawable getIconDrawable() { - return iconDrawable; + + public void setIcon(ImageView icon) { + this.icon = icon; } - public void setIconDrawable(Drawable drawableIcon) { - this.iconDrawable = drawableIcon; - icon.setImageDrawable(drawableIcon); + public Drawable getDrawableIcon() { + return drawableIcon; } - /** - * 设置button中图片的大小,默认是居中显示的。 - * 如果图片大小超过了按钮的大小,那么按钮会根据图片进行放大,直到能包含内部图片为止 - * @param size - */ - public void setIconSize(int size) { - iconSize = size; - setIconParams(); + public void setDrawableIcon(Drawable drawableIcon) { + this.drawableIcon = drawableIcon; + try { + icon.setBackground(drawableIcon); + } catch (NoSuchMethodError e) { + icon.setBackgroundDrawable(drawableIcon); + } } - /** - * @return 按钮中心图片的大小 - */ - public int getIconSize() { - return iconSize; + public Bitmap cropCircle(Bitmap bitmap) { + Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), + bitmap.getHeight(), Config.ARGB_8888); + Canvas canvas = new Canvas(output); + + final int color = 0xff424242; + final Paint paint = new Paint(); + final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); + + paint.setAntiAlias(true); + canvas.drawARGB(0, 0, 0, 0); + paint.setColor(color); + canvas.drawCircle(bitmap.getWidth() / 2, bitmap.getHeight() / 2, + bitmap.getWidth()/2, paint); + paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); + canvas.drawBitmap(bitmap, rect, rect, paint); + return output; } @Override - @Deprecated public TextView getTextView() { - // 无效方法 return null; } - + + public void setRippleColor(int rippleColor) { + this.rippleColor = rippleColor; + } } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloatSmall.java b/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloatSmall.java index f92b7ca..d85681d 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloatSmall.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ButtonFloatSmall.java @@ -1,31 +1,33 @@ package com.gc.materialdesign.views; +import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.Utils; + import android.content.Context; import android.util.AttributeSet; +import android.widget.RelativeLayout; - -/** - * @tips :很小的圆形按钮,上面可以添加图片 - * @date :2014-11-1 - */ public class ButtonFloatSmall extends ButtonFloat { - + public ButtonFloatSmall(Context context, AttributeSet attrs) { super(context, attrs); + sizeRadius = 20; + sizeIcon = 20; + setDefaultProperties(); + RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(Utils.dpToPx(sizeIcon, getResources()),Utils.dpToPx(sizeIcon, getResources())); + params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); + icon.setLayoutParams(params); } - @Override - protected void onInitDefaultValues() { - super.onInitDefaultValues(); - /** - * 其实这里里面很多值在父控件中已经设置过了,这里可以不用super语句。 - * 但为了方便理解和避免错误。用了super语句,super后将需要自定义的值又重新设置了一遍。 - */ - sizeRadius = 20; - rippleSize = 8; - minWidth = sizeRadius * 2;// 40dp - minHeight = sizeRadius * 2;// 40dp + protected void setDefaultProperties(){ + rippleSpeed = Utils.dpToPx(2, getResources()); + rippleSize = 10; + // Min size + setMinimumHeight(Utils.dpToPx(sizeRadius*2, getResources())); + setMinimumWidth(Utils.dpToPx(sizeRadius*2, getResources())); + // Background shape + setBackgroundResource(R.drawable.background_button_float); +// setBackgroundColor(backgroundColor); } - } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ButtonIcon.java b/MaterialDesign/src/com/gc/materialdesign/views/ButtonIcon.java index 21f9807..0637b2f 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ButtonIcon.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ButtonIcon.java @@ -1,8 +1,12 @@ package com.gc.materialdesign.views; +import com.gc.materialdesign.utils.Utils; + +import android.R; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; +import android.graphics.Rect; import android.graphics.drawable.ColorDrawable; import android.util.AttributeSet; import android.view.MotionEvent; @@ -11,16 +15,9 @@ public class ButtonIcon extends ButtonFloat { public ButtonIcon(Context context, AttributeSet attrs) { super(context, attrs); - } - - @Override - protected void onInitDefaultValues() { - super.onInitDefaultValues(); - rippleSpeed = 2; - rippleSize = 5; - backgroundResId = -1; - // Background shape - setBackgroundDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent))); + setBackground(new ColorDrawable(getResources().getColor(android.R.color.transparent))); + rippleSpeed = Utils.dpToPx(2, getResources()); + rippleSize = Utils.dpToPx(5, getResources()); } @Override @@ -38,7 +35,7 @@ protected void onDraw(Canvas canvas) { if (x != -1) { Paint paint = new Paint(); paint.setAntiAlias(true); - paint.setColor(backgroundColor); + paint.setColor(makePressColor()); canvas.drawCircle(x, y, radius, paint); if(radius > getHeight()/rippleSize) radius += rippleSpeed; @@ -46,11 +43,16 @@ protected void onDraw(Canvas canvas) { x = -1; y = -1; radius = getHeight()/rippleSize; - if(isEnabled() && clickAfterRipple == true && onClickListener != null) + if(onClickListener != null) onClickListener.onClick(this); } + invalidate(); } - invalidate(); + } + + @Override + protected int makePressColor() { + return backgroundColor; } } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ButtonImage.java b/MaterialDesign/src/com/gc/materialdesign/views/ButtonImage.java deleted file mode 100644 index 94f6131..0000000 --- a/MaterialDesign/src/com/gc/materialdesign/views/ButtonImage.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.gc.materialdesign.views; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.util.AttributeSet; - -import com.gc.materialdesign.R; -import com.gc.materialdesign.utils.Utils; - -public class ButtonImage extends ButtonFloat { - - public ButtonImage(Context context, AttributeSet attrs) { - super(context, attrs); - // TODO 自动生成的构造函数存根 - } - - @Override - protected void onInitDefaultValues() { - super.onInitDefaultValues(); - iconSize = 24; - sizeRadius = 28; - rippleSpeed = 8; - rippleSize = 5; - minWidth = 20; - minHeight = 20; - backgroundResId = R.drawable.background_button_rectangle; - } - - @Override - protected void onDraw(Canvas canvas) { - //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/MaterialDesign/src/com/gc/materialdesign/views/ButtonRectangle.java b/MaterialDesign/src/com/gc/materialdesign/views/ButtonRectangle.java index 1e83dd9..b60ad8a 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ButtonRectangle.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ButtonRectangle.java @@ -1,7 +1,9 @@ package com.gc.materialdesign.views; +import com.gc.materialdesign.R; +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.Rect; @@ -10,137 +12,138 @@ import android.widget.RelativeLayout; import android.widget.TextView; -import com.gc.materialdesign.R; -import com.gc.materialdesign.utils.Utils; - -/** - * @tips :矩形按钮 - * @date :2014-11-1 - */ public class ButtonRectangle extends Button { - protected TextView textButton; - protected int defaultTextColor; + TextView textButton; + + int paddingTop,paddingBottom, paddingLeft, paddingRight; + public ButtonRectangle(Context context, AttributeSet attrs) { super(context, attrs); + setDefaultProperties(); } - @Override - protected void onInitDefaultValues(){ - super.onInitDefaultValues(); - textButton = new TextView(getContext()); - defaultTextColor = Color.WHITE; - rippleSpeed = 5.5f; - minWidth = 80; - minHeight = 36; - backgroundResId = R.drawable.background_button_rectangle; + 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(); } - @Override - protected void onInitAttributes(AttributeSet attrs) { - super.onInitAttributes(attrs); - if (isInEditMode()) { - // 为了在编译器中预览时不报空指针,在这里产生一个textView对象。实际中不会产生的。 - textButton = new TextView(getContext()); + + // 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{ - //如果没有文字资源,也就是@String/xx,那么就设置文字 text = attrs.getAttributeValue(ANDROIDXML,"text"); } - - /** - * 当文字不为空的时候,TextView设置文字,否则不设置文字 - */ if(text != null){ + textButton = new TextView(getContext()); textButton.setText(text); + textButton.setTextColor(Color.WHITE); + 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); + 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); + } - /** - * 设置textSize - */ - String textSize = attrs.getAttributeValue(ANDROIDXML,"textSize"); - if (text != null && textSize != null) { - textSize = textSize.substring(0, textSize.length() - 2);//12sp->12 - textButton.setTextSize(Float.parseFloat(textSize)); - } - - /** - * 设置textColor - */ - int textColor = attrs.getAttributeResourceValue(ANDROIDXML,"textColor",-1); - if(text != null && textColor != -1){ - textButton.setTextColor(getResources().getColor(textColor)); - } - else if(text != null ){ - // 16进制的color - String color = attrs.getAttributeValue(ANDROIDXML,"textColor"); - if(color != null && !isInEditMode()) { - textButton.setTextColor(Color.parseColor(color)); - }else { - textButton.setTextColor(defaultTextColor); - } - } - textButton.setTypeface(null, Typeface.BOLD); - //textButton.setPadding(5, 5, 5, 5); - RelativeLayout.LayoutParams params = new RelativeLayout.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); - + rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, + "rippleSpeed", Utils.dpToPx(6, getResources())); } +// /** +// * Center text in button +// */ +// boolean txtCenter = false; +// private void centrarTexto(){ +// if((textButton.getWidth()+paddingLeft+paddingRight)>Utils.dpToPx(80, getResources())) +// setMinimumWidth(textButton.getWidth()+paddingLeft+paddingRight); +// setMinimumHeight(textButton.getHeight()+paddingBottom+paddingTop); +// textButton.setX(getWidth()/2-textButton.getWidth()/2 - paddingTop + paddingBottom); +// textButton.setY(getHeight()/2-textButton.getHeight()/2 - paddingLeft + paddingRight); +// txtCenter = true; +// } + + 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(); } - invalidate(); } - // GET AND SET - -/* @Override - public void setEnabled(boolean enabled) { - // TODO 自动生成的方法存根 - super.setEnabled(enabled); - textButton.setEnabled(enabled); - if (enabled) { - getBackground().setAlpha(255); - }else { - getBackground().setAlpha(25); - } - - }*/ - - public void setText(final String text){ - textButton.setText(text); + public void setText(String text){ + textButton.setText(text); } - // Set color of text public void setTextColor(int color){ textButton.setTextColor(color); } - - public void setTextSize(float size) { - textButton.setTextSize(size); - } - @Override public TextView getTextView() { return textButton; } + public String getText(){ + return textButton.getText().toString(); + } + } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/Card.java b/MaterialDesign/src/com/gc/materialdesign/views/Card.java index 2c71ae9..74bc4ef 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/Card.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/Card.java @@ -1,47 +1,69 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.Utils; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Bitmap.Config; +import android.graphics.Canvas; import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; +import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.LayerDrawable; import android.util.AttributeSet; +import android.util.Log; +import android.view.Gravity; +import android.view.MotionEvent; +import android.widget.FrameLayout; +import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; +import android.widget.RelativeLayout.LayoutParams; public class Card extends CustomView { - private TextView textButton; + TextView textButton; - private int paddingTop,paddingBottom, paddingLeft, paddingRight; + int paddingTop,paddingBottom, paddingLeft, paddingRight; + int backgroundColor = Color.parseColor("#FFFFFF"); public Card(Context context, AttributeSet attrs) { super(context, attrs); setAttributes(attrs); } - @Override - protected void onInitDefaultValues() { - // TODO 自动生成的方法存根 - minWidth = 20; - minHeight = 20; - backgroundColor = Color.parseColor("#FFFFFF"); - backgroundResId = R.drawable.background_button_rectangle; + + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs){ + + setBackgroundResource(R.drawable.background_button_rectangle); + //Set background Color + // Color by resource + int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); + 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 public void setBackgroundColor(int color){ this.backgroundColor = color; - if(isEnabled()) { + if(isEnabled()) beforeBackground = backgroundColor; - } - GradientDrawable shape = null; - if (!isInEditMode()) { - LayerDrawable layer = (LayerDrawable) getBackground(); - shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); - shape.setColor(backgroundColor); - } - + LayerDrawable layer = (LayerDrawable) getBackground(); + GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); + shape.setColor(backgroundColor); } } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/CheckBox.java b/MaterialDesign/src/com/gc/materialdesign/views/CheckBox.java index 4cf49ac..6b10ee3 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/CheckBox.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/CheckBox.java @@ -1,5 +1,8 @@ package com.gc.materialdesign.views; +import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.Utils; + import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; @@ -14,85 +17,99 @@ import android.view.View; import android.widget.RelativeLayout; -import com.gc.materialdesign.R; -import com.gc.materialdesign.utils.Utils; - public class CheckBox extends CustomView { - private Check checkView; + int backgroundColor = Color.parseColor("#4CAF50"); + + Check checkView; - private boolean idPressed = false; - private boolean isChecked = false; + boolean press = false; + boolean check = false; - private OnCheckListener onCheckListener; + OnCheckListener onCheckListener; public CheckBox(Context context, AttributeSet attrs) { super(context, attrs); setAttributes(attrs); } - @Override - protected void onInitDefaultValues() { - minWidth = 48; - minHeight = 48; - backgroundColor = Color.parseColor("#4CAF50");// default color - backgroundResId = R.drawable.background_checkbox; - } - - @Override + // Set atributtes of XML to View protected void setAttributes(AttributeSet attrs) { - super.setAttributes(attrs); - boolean isChecked = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "checked", false); - if (isChecked) { + + setBackgroundResource(R.drawable.background_checkbox); + + // Set size of view + setMinimumHeight(Utils.dpToPx(48, getResources())); + setMinimumWidth(Utils.dpToPx(48, 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 + // Color by hexadecimal + int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); + if (background != -1) + setBackgroundColor(background); + } + + boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, + "check", false); + if (check) { post(new Runnable() { @Override public void run() { setChecked(true); setPressed(false); - changeBackgroundColor(getResources().getColor(android.R.color.transparent)); + changeBackgroundColor(getResources().getColor( + android.R.color.transparent)); } }); } - float size = 20; - String checkBoxSize = attrs.getAttributeValue(MATERIALDESIGNXML, "checkBoxSize"); - if (checkBoxSize != null) { - size = Utils.dipOrDpToFloat(checkBoxSize); - } checkView = new Check(getContext()); - setCheckBoxParams(size); - addView(checkView); - } - - private void setCheckBoxParams(float size) { - RelativeLayout.LayoutParams params = new LayoutParams( - Utils.dpToPx(size, getResources()), Utils.dpToPx(size, getResources())); + RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20, + getResources()), Utils.dpToPx(20, getResources())); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); checkView.setLayoutParams(params); + addView(checkView); + } + @Override + public void invalidate() { + checkView.invalidate(); + super.invalidate(); + } + + @Override public boolean onTouchEvent(MotionEvent event) { + invalidate(); if (isEnabled()) { isLastTouch = true; if (event.getAction() == MotionEvent.ACTION_DOWN) { - changeBackgroundColor((isChecked) ? makePressColor(70) : Color.parseColor("#446D6D6D")); + changeBackgroundColor((check) ? makePressColor() : Color + .parseColor("#446D6D6D")); } else if (event.getAction() == MotionEvent.ACTION_UP) { - changeBackgroundColor(getResources().getColor(android.R.color.transparent)); - idPressed = false; + changeBackgroundColor(getResources().getColor( + android.R.color.transparent)); + press = false; if ((event.getX() <= getWidth() && event.getX() >= 0) && (event.getY() <= getHeight() && event.getY() >= 0)) { isLastTouch = false; - isChecked = !isChecked; + check = !check; if (onCheckListener != null) - onCheckListener.onCheck(isChecked); - if (isChecked) { + onCheckListener.onCheck(check); + if (check) { step = 0; } - if (isChecked) { + if (check) checkView.changeBackground(); - } } } } @@ -102,41 +119,88 @@ public boolean onTouchEvent(MotionEvent event) { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (idPressed) { + if (press) { Paint paint = new Paint(); paint.setAntiAlias(true); - paint.setColor((isChecked) ? makePressColor(70) : Color.parseColor("#446D6D6D")); - canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, paint); + paint.setColor((check) ? makePressColor() : Color + .parseColor("#446D6D6D")); + canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, + paint); + invalidate(); } - invalidate(); } - + + private void changeBackgroundColor(int color) { + LayerDrawable layer = (LayerDrawable) getBackground(); + GradientDrawable shape = (GradientDrawable) layer + .findDrawableByLayerId(R.id.shape_bacground); + shape.setColor(color); + } + + /** + * 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); + } + + @Override + public void setBackgroundColor(int color) { + backgroundColor = color; + if (isEnabled()) + beforeBackground = backgroundColor; + changeBackgroundColor(color); + } + + public void setChecked(boolean check) { + this.check = check; + setPressed(false); + changeBackgroundColor(getResources().getColor( + android.R.color.transparent)); + if (check) { + step = 0; + } + if (check) + checkView.changeBackground(); + + } + + public boolean isCheck() { + return check; + } + // Indicate step in check animation - private int step = 0; + int step = 0; // View that contains checkbox - private class Check extends View { + class Check extends View { - private Bitmap sprite; + Bitmap sprite; public Check(Context context) { super(context); - if (!isInEditMode()) { - setBackgroundResource(R.drawable.background_checkbox_uncheck); - } - sprite = BitmapFactory.decodeResource(context.getResources(), R.drawable.sprite_check); + setBackgroundResource(R.drawable.background_checkbox_uncheck); + sprite = BitmapFactory.decodeResource(context.getResources(), + R.drawable.sprite_check); } public void changeBackground() { - if (isChecked) { + if (check) { setBackgroundResource(R.drawable.background_checkbox_check); LayerDrawable layer = (LayerDrawable) getBackground(); - GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); + GradientDrawable shape = (GradientDrawable) layer + .findDrawableByLayerId(R.id.shape_bacground); shape.setColor(backgroundColor); } else { - if (!isInEditMode()) { - setBackgroundResource(R.drawable.background_checkbox_uncheck); - } + setBackgroundResource(R.drawable.background_checkbox_uncheck); } } @@ -144,62 +208,27 @@ public void changeBackground() { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (isChecked) { - if (step < 11) + if (check) { + if (step < 11){ step++; + invalidate(); + } } else { - if (step >= 0) + if (step >= 0){ step--; - if (step == -1) + invalidate(); + } + if (step == -1){ + invalidate(); changeBackground(); + } } Rect src = new Rect(40 * step, 0, (40 * step) + 40, 40); Rect dst = new Rect(0, 0, this.getWidth() - 2, this.getHeight()); - if (!isInEditMode()) { - canvas.drawBitmap(sprite, src, dst, null); - } - invalidate(); - - } + canvas.drawBitmap(sprite, src, dst, null); - } - - private void changeBackgroundColor(int color) { - if (!isInEditMode()) { - LayerDrawable layer = (LayerDrawable) getBackground(); - GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); - shape.setColor(color); - } - } - - @Override - public void setBackgroundColor(int color) { - backgroundColor = color; - if (isEnabled()) { - beforeBackground = backgroundColor; } - changeBackgroundColor(getResources().getColor(android.R.color.transparent)); -// changeBackgroundColor(color); - } - - public void setChecked(boolean checked) { - this.isChecked = checked; - setPressed(false); - changeBackgroundColor(getResources().getColor(android.R.color.transparent)); - if (checked) { - step = 0; - } - if (checked) { - checkView.changeBackground(); - } - } - public boolean isChecked() { - return isChecked; - } - - public void setCheckBoxSize(float size) { - setCheckBoxParams(size); } public void setOncheckListener(OnCheckListener onCheckListener) { @@ -207,7 +236,7 @@ public void setOncheckListener(OnCheckListener onCheckListener) { } public interface OnCheckListener { - public void onCheck(boolean isChecked); + public void onCheck(boolean check); } } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/CustomView.java b/MaterialDesign/src/com/gc/materialdesign/views/CustomView.java index ff57e6c..e8ea2da 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/CustomView.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/CustomView.java @@ -5,73 +5,29 @@ import android.util.AttributeSet; import android.widget.RelativeLayout; -import com.gc.materialdesign.utils.Utils; - -public abstract class CustomView extends RelativeLayout{ +public class CustomView extends RelativeLayout{ - protected final static String MATERIALDESIGNXML = "http://schemas.android.com/apk/res-auto"; - protected final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; - protected int minWidth; - protected int minHeight; + final static String MATERIALDESIGNXML = "http://schemas.android.com/apk/res-auto"; + final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; - protected int backgroundColor; - protected int beforeBackground; - protected int backgroundResId = -1;// view背景的形状资源 + final int disabledBackgroundColor = Color.parseColor("#E2E2E2"); + int beforeBackground; // Indicate if user touched this view the last time public boolean isLastTouch = false; - + public CustomView(Context context, AttributeSet attrs) { super(context, attrs); - onInitDefaultValues(); - //onInitAttributes(attrs); - } - - protected abstract void onInitDefaultValues(); - - // Set atributtes of XML to View - protected void setAttributes(AttributeSet attrs) { - setMinimumHeight(Utils.dpToPx(minHeight, getResources())); - setMinimumWidth(Utils.dpToPx(minWidth, getResources())); - if (backgroundResId != -1 && !isInEditMode()) { - setBackgroundResource(backgroundResId); - } - setBackgroundAttributes(attrs); } - /** - * 设置背景色 - * Set background Color - */ - protected void setBackgroundAttributes(AttributeSet attrs) { - int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,"background",-1); - if(bacgroundColor != -1){ - setBackgroundColor(getResources().getColor(bacgroundColor)); - }else{ - // Color by hexadecimal - int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1); - if(background != -1 && !isInEditMode()) { - setBackgroundColor(background); - }else { - setBackgroundColor(backgroundColor);// 如果没有设置,就用这个颜色 - } - } + @Override + public void setEnabled(boolean enabled) { + super.setEnabled(enabled); + if(enabled) + setBackgroundColor(beforeBackground); + else + setBackgroundColor(disabledBackgroundColor); + invalidate(); } - - - /** - * Make a dark color to press effect - * @return - */ - protected int makePressColor(int alpha) { - int r = (backgroundColor >> 16) & 0xFF; - int g = (backgroundColor >> 8) & 0xFF; - int b = (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(alpha, r, g, b); - } - } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/LayoutRipple.java b/MaterialDesign/src/com/gc/materialdesign/views/LayoutRipple.java index 431b280..bc27f3b 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/LayoutRipple.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/LayoutRipple.java @@ -3,88 +3,195 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; -import android.graphics.PorterDuff.Mode; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; -import android.graphics.PorterDuffXfermode; import android.graphics.Rect; -import android.graphics.RectF; import android.util.AttributeSet; +import android.view.MotionEvent; -public class LayoutRipple extends RippleView { +public class LayoutRipple extends CustomView { + + int background; + float rippleSpeed = 10f; + int rippleSize = 3; + + OnClickListener onClickListener; + int backgroundColor = Color.parseColor("#FFFFFF"); + + Integer rippleColor; + Float xRippleOrigin; + Float yRippleOrigin; - private Float xRippleOrigin; - private Float yRippleOrigin; - float rippleBorderRadius = 0;// radius - 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 - protected void onInitDefaultValues() { - minWidth = 20; - minHeight = 20; - backgroundColor = 0x00ffffff;// alpha = 0 - rippleSpeed = 20f;// default speed + 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 setAttributes(AttributeSet attrs) { - super.setAttributes(attrs); - //设定涟漪最外层的边界弧度,是圆角矩形,如果不设置,则是普通矩形 - rippleBorderRadius = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleBorderRadius", 0); + protected void onFocusChanged(boolean gainFocus, int direction, + Rect previouslyFocusedRect) { + if (!gainFocus) { + x = -1; + y = -1; + } } - - // ### RIPPLE EFFECT ### - + + @Override + public boolean onInterceptTouchEvent(MotionEvent ev) { + // super.onInterceptTouchEvent(ev); + return true; + } + public Bitmap makeCircle() { - Bitmap output = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_8888); + 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; - return makeCircleFromBitmap(output); + 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; } - - @Override + 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(cropRoundRect(makeCircle()), src, dst, null); + canvas.drawBitmap(makeCircle(), src, dst, null); + invalidate(); } - invalidate(); } - + /** - * @param bitmap - * @return 设置涟漪的边界,涟漪在这个区域里面可见。这里可以设置四角的弧度数 + * Make a dark color to ripple effect + * + * @return */ - public Bitmap cropRoundRect(Bitmap bitmap) { - Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), - bitmap.getHeight(), Config.ARGB_8888); - Canvas canvas = new Canvas(output); - - final int color = 0xff424242; - final Paint paint = new Paint(); - final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); - - paint.setAntiAlias(true); - canvas.drawARGB(0, 0, 0, 0); - paint.setColor(color); - RectF rectF = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()); - canvas.drawRoundRect(rectF, rippleBorderRadius, rippleBorderRadius, paint); - - paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); - canvas.drawBitmap(bitmap, rect, rect, paint); - return output; + 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; } - - - // SETTERS - public void setxRippleOrigin(Float xRippleOrigin) { this.xRippleOrigin = xRippleOrigin; } @@ -92,25 +199,5 @@ public void setxRippleOrigin(Float xRippleOrigin) { public void setyRippleOrigin(Float yRippleOrigin) { this.yRippleOrigin = yRippleOrigin; } - - /** - * set the layoutRipple border radius - * @param size - */ - public void setRippleBorderRadius(float size) { - rippleBorderRadius = size; - } - - // Set color of background - public void setBackgroundColor(int color){ - backgroundColor = color; - /** - * 当重新设定背景色后,要检查涟漪颜色。如果已经设定了涟漪颜色,那么就用之前的。如果没设定就重新生成 - */ - if (!settedRippleColor) { - rippleColor = makePressColor(255); - } - super.setBackgroundColor(color); - } - + } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java index ad70a49..391d4f2 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarCircularIndeterminate.java @@ -13,153 +13,159 @@ import android.util.AttributeSet; public class ProgressBarCircularIndeterminate extends CustomView { + + + final static String ANDROIDXML = "http://schemas.android.com/apk/res/android"; + + int backgroundColor = Color.parseColor("#1E88E5"); + public ProgressBarCircularIndeterminate(Context context, AttributeSet attrs) { super(context, attrs); setAttributes(attrs); - } - - @Override - protected void onInitDefaultValues() { - // TODO 自动生成的方法存根 - minWidth = 32; - minHeight = 32; - backgroundColor = Color.parseColor("#1E88E5"); + } - @Override - protected void setAttributes(AttributeSet attrs) { - // TODO 自动生成的方法存根 - super.setAttributes(attrs); - float size = 4;// default ring width - String width = attrs.getAttributeValue(MATERIALDESIGNXML, "ringWidth"); - if (width != null) { - size = Utils.dipOrDpToFloat(width); + // 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")); + } + + setMinimumHeight(Utils.dpToPx(3, getResources())); + + } - ringWidth = size; - } - + /** * Make a dark color to ripple effect - * * @return */ - protected int makePressColor() { + protected int makePressColor(){ int r = (this.backgroundColor >> 16) & 0xFF; int g = (this.backgroundColor >> 8) & 0xFF; int b = (this.backgroundColor >> 0) & 0xFF; - // r = (r+90 > 245) ? 245 : r+90; - // g = (g+90 > 245) ? 245 : g+90; - // b = (b+90 > 245) ? 245 : b+90; - return Color.argb(128, r, g, b); +// r = (r+90 > 245) ? 245 : r+90; +// g = (g+90 > 245) ? 245 : g+90; +// b = (b+90 > 245) ? 245 : b+90; + return Color.argb(128,r, g, b); } - + + @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (firstAnimationOver == false) - drawFirstAnimation(canvas);// 从无到有慢慢扩大的动画 - if (cont > 0) - drawSecondAnimation(canvas);// 一直旋转的动画 + if(firstAnimationOver == false) + drawFirstAnimation(canvas); + if(cont > 0) + drawSecondAnimation(canvas); invalidate(); + } - - private float radius1 = 0; - private float radius2 = 0; - private int cont = 0; - private boolean firstAnimationOver = false; - private float ringWidth = 4; - + + float radius1 = 0; + float radius2 = 0; + int cont = 0; + boolean firstAnimationOver = false; /** * Draw first animation of view - * * @param canvas */ - private void drawFirstAnimation(Canvas canvas) { - if (radius1 < getWidth() / 2) { + private void drawFirstAnimation(Canvas canvas){ + if(radius1 < getWidth()/2){ Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(makePressColor()); - radius1 = (radius1 >= getWidth() / 2) ? (float) getWidth() / 2 : radius1 + 1; - canvas.drawCircle(getWidth() / 2, getHeight() / 2, radius1, paint); - } else { + radius1 = (radius1 >= getWidth()/2)? (float)getWidth()/2 : radius1+1; + canvas.drawCircle(getWidth()/2, getHeight()/2, radius1, paint); + }else{ Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); - Canvas temp = new Canvas(bitmap); - Paint paint = new Paint(); + Canvas temp = new Canvas(bitmap); + Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(makePressColor()); - temp.drawCircle(getWidth() / 2, 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)); - if (cont >= 50) { - radius2 = (radius2 >= getWidth() / 2) ? (float) getWidth() / 2 : radius2 + 1; - } else { - radius2 = (radius2 >= getWidth() / 2 - Utils.dpToPx(ringWidth, getResources())) ? - (float) getWidth() / 2 - Utils.dpToPx(ringWidth, getResources()) : radius2 + 1; - } - temp.drawCircle(getWidth() / 2, getHeight() / 2, radius2, transparentPaint); - canvas.drawBitmap(bitmap, 0, 0, new Paint()); - if (radius2 >= getWidth() / 2 - Utils.dpToPx(ringWidth, getResources())) - cont++; - if (radius2 >= getWidth() / 2) - firstAnimationOver = true; + temp.drawCircle(getWidth()/2, 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)); + if(cont >= 50){ + radius2 = (radius2 >= getWidth()/2)? (float)getWidth()/2 : radius2+1; + }else{ + radius2 = (radius2 >= getWidth()/2-Utils.dpToPx(4, getResources()))? (float)getWidth()/2-Utils.dpToPx(4, getResources()) : radius2+1; + } + temp.drawCircle(getWidth()/2, getHeight()/2, radius2, transparentPaint); + canvas.drawBitmap(bitmap, 0, 0, new Paint()); + if(radius2 >= getWidth()/2-Utils.dpToPx(4, getResources())) + cont++; + if(radius2 >= getWidth()/2) + firstAnimationOver = true; } } - - private int arcD = 1; - private int arcO = 0; - private float rotateAngle = 0; - private int limite = 0; - + + int arcD = 1; + int arcO = 0; + float rotateAngle = 0; + int limite = 0; /** * Draw second animation of view - * * @param canvas */ - private void drawSecondAnimation(Canvas canvas) { - if (arcO == limite) - arcD += 6; - if (arcD >= 290 || arcO > limite) { - arcO += 6; - arcD -= 6; + private void drawSecondAnimation(Canvas canvas){ + if(arcO == limite) + arcD+=6; + if(arcD >= 290 || arcO > limite){ + arcO+=6; + arcD-=6; } - if (arcO > limite + 290) { + if(arcO > limite + 290){ limite = arcO; arcO = limite; arcD = 1; } rotateAngle += 4; - canvas.rotate(rotateAngle, getWidth() / 2, getHeight() / 2); - - Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); - Canvas temp = new Canvas(bitmap); - Paint paint = new Paint(); + canvas.rotate(rotateAngle,getWidth()/2, getHeight()/2); + + 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(backgroundColor); - // temp.drawARGB(0, 0, 0, 255); +// temp.drawARGB(0, 0, 0, 255); temp.drawArc(new RectF(0, 0, getWidth(), getHeight()), arcO, arcD, true, 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(getWidth() / 2, getHeight() / 2, (getWidth() / 2) - Utils.dpToPx(ringWidth, getResources()), transparentPaint); + Paint transparentPaint = new Paint(); + transparentPaint.setAntiAlias(true); + transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); + transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + temp.drawCircle(getWidth()/2, getHeight()/2, (getWidth()/2)-Utils.dpToPx(4, getResources()), transparentPaint); - canvas.drawBitmap(bitmap, 0, 0, new Paint()); + canvas.drawBitmap(bitmap, 0, 0, new Paint()); } - + + + + + // Set color of background - public void setBackgroundColor(int color) { + public void setBackgroundColor(int color){ super.setBackgroundColor(getResources().getColor(android.R.color.transparent)); - if (isEnabled()) { + if(isEnabled()) beforeBackground = backgroundColor; - } this.backgroundColor = color; } - - public void setRingWidth(float width) { - ringWidth = width; - } } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarDeterminate.java b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarDeterminate.java index 103256f..c227426 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarDeterminate.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarDeterminate.java @@ -1,6 +1,7 @@ package com.gc.materialdesign.views; import com.gc.materialdesign.R; +import com.gc.materialdesign.utils.Utils; import android.content.Context; import android.graphics.Canvas; @@ -10,94 +11,106 @@ import android.util.AttributeSet; import android.view.View; import android.widget.RelativeLayout; +import android.widget.RelativeLayout.LayoutParams; public class ProgressBarDeterminate extends CustomView { - - private int max = 100; - private int min = 0; - private int progress = 0; - - protected View progressView; + + + 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); } - - @Override - protected void onInitDefaultValues() { - minWidth = 40; - minHeight = 3; - backgroundColor = Color.parseColor("#1E88E5"); - } - + // Set atributtes of XML to View - @Override - protected void setAttributes(AttributeSet attrs) { - progressView = new View(getContext()); - RelativeLayout.LayoutParams params = new LayoutParams(1, 1); - progressView.setLayoutParams(params); - if (!isInEditMode()) { + protected void setAttributes(AttributeSet attrs){ + + progressView = new View(getContext()); + RelativeLayout.LayoutParams params = new LayoutParams(1,1); + progressView.setLayoutParams(params); progressView.setBackgroundResource(R.drawable.background_progress); - } - addView(progressView); - //super必须放在view初始化后,英文setAttr会执行设置背景的方法,如果view还没产生就设置背景会报null - super.setAttributes(attrs); - min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0); - max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 100); - progress = attrs.getAttributeIntValue(MATERIALDESIGNXML, "progress", min); - - post(new Runnable() { - @Override - public void run() { - RelativeLayout.LayoutParams params = (LayoutParams) progressView.getLayoutParams(); - params.height = getHeight(); - progressView.setLayoutParams(params); - //setProgress(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() { + RelativeLayout.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) + if(pendindProgress!=-1) setProgress(pendindProgress); } - - public void setMax(int max) { + + public void setMax(int max){ this.max = max; } - - public int getMax() { - return max; - } - public void setMin(int min) { + public void setMin(int min){ this.min = min; } - public int getMin() { - return min; - } - - private int pendindProgress = -1; - - public void setProgress(int progress) { - this.progress = progress; - if (getWidth() == 0) { + int pendindProgress = -1; + public void setProgress(int progress){ + if(getWidth() == 0){ pendindProgress = progress; - } else { - //this.progress = progress; - if (progress > max) + }else{ + this.progress = progress; + if(progress > max) progress = max; - if (progress < min) + if(progress < min) progress = min; - int totalWidth = max - min; - double progressPercent = (double) progress / (double) totalWidth; - int progressWidth = (int) (getWidth() * progressPercent); + int totalWidth = max-min; + double progressPercent = (double)progress/(double)totalWidth; + int progressWidth =(int) (getWidth()*progressPercent); RelativeLayout.LayoutParams params = (LayoutParams) progressView.getLayoutParams(); params.width = progressWidth; params.height = getHeight(); @@ -105,35 +118,20 @@ public void setProgress(int progress) { pendindProgress = -1; } } - - public int getProgress() { + + public int getProgress(){ return progress; } - - // Set color of background - public void setBackgroundColor(int color) { - backgroundColor = color; - if (!isInEditMode()) { - if (isEnabled()) { - beforeBackground = backgroundColor; - } - LayerDrawable layer = (LayerDrawable) progressView.getBackground(); - GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); - shape.setColor(color); - } - super.setBackgroundColor(makePressColor(128)); - } - /** - * Make a dark color to ripple effect - * @return - */ - @Override - protected int makePressColor(int alpha){ - int r = (this.backgroundColor >> 16) & 0xFF; - int g = (this.backgroundColor >> 8) & 0xFF; - int b = (this.backgroundColor >> 0) & 0xFF; - return Color.argb(alpha,r, g, b); + // Set color of background + public void setBackgroundColor(int color){ + this.backgroundColor = color; + if(isEnabled()) + beforeBackground = backgroundColor; + LayerDrawable layer = (LayerDrawable) progressView.getBackground(); + GradientDrawable shape = (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground); + shape.setColor(color); + super.setBackgroundColor(makePressColor()); } } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminate.java b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminate.java index 5d6b135..693126e 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminate.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminate.java @@ -2,7 +2,7 @@ import com.gc.materialdesign.R; import com.nineoldandroids.animation.Animator; -import com.nineoldandroids.animation.AnimatorListenerAdapter; +import com.nineoldandroids.animation.Animator.AnimatorListener; import com.nineoldandroids.animation.ObjectAnimator; import com.nineoldandroids.view.ViewHelper; @@ -20,12 +20,13 @@ public ProgressBarIndeterminate(Context context, AttributeSet attrs) { @Override public void run() { // Make progress animation + setProgress(60); Animation anim = AnimationUtils.loadAnimation(getContext(), R.anim.progress_indeterminate_animation); progressView.startAnimation(anim); final ObjectAnimator anim2 = ObjectAnimator.ofFloat(progressView, "x", getWidth()); anim2.setDuration(1200); - anim2.addListener(new AnimatorListenerAdapter() { + anim2.addListener(new AnimatorListener() { int cont = 1; int suma = 1; @@ -36,13 +37,18 @@ public void onAnimationEnd(Animator arg0) { ViewHelper.setX(progressView,-progressView.getWidth()/2); cont += suma; ObjectAnimator anim2Repeat = ObjectAnimator.ofFloat(progressView, "x", getWidth()); - anim2Repeat.setDuration(duration / cont); + anim2Repeat.setDuration(duration/cont); anim2Repeat.addListener(this); anim2Repeat.start(); if(cont == 3 || cont == 1) suma *=-1; } + + public void onAnimationStart(Animator arg0) {} + public void onAnimationRepeat(Animator arg0) {} + public void onAnimationCancel(Animator arg0) {} }); + anim2.start(); } }); diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminateDeterminate.java b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminateDeterminate.java index 4a54207..b607815 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminateDeterminate.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ProgressBarIndeterminateDeterminate.java @@ -1,7 +1,7 @@ package com.gc.materialdesign.views; import com.nineoldandroids.animation.Animator; -import com.nineoldandroids.animation.AnimatorListenerAdapter; +import com.nineoldandroids.animation.Animator.AnimatorListener; import com.nineoldandroids.animation.ObjectAnimator; import com.nineoldandroids.view.ViewHelper; @@ -14,6 +14,8 @@ public class ProgressBarIndeterminateDeterminate extends ProgressBarDeterminate boolean runAnimation = true; ObjectAnimator animation; + + public ProgressBarIndeterminateDeterminate(Context context, AttributeSet attrs) { super(context, attrs); post(new Runnable() { @@ -26,7 +28,8 @@ public void run() { ViewHelper.setX(progressView,getWidth()+progressView.getWidth()/2); animation = ObjectAnimator.ofFloat(progressView, "x", -progressView.getWidth()/2); animation.setDuration(1200); - animation.addListener(new AnimatorListenerAdapter() { + animation.addListener(new AnimatorListener() { + int cont = 1; int suma = 1; int duration = 1200; @@ -34,17 +37,20 @@ public void run() { public void onAnimationEnd(Animator arg0) { // Repeat animation if(runAnimation){ - ViewHelper.setX(progressView, getWidth() + progressView.getWidth() / 2); - cont += suma; - animation = ObjectAnimator.ofFloat(progressView, "x", -progressView.getWidth() / 2); - animation.setDuration(duration / cont); - animation.addListener(this); - animation.start(); - if(cont == 3 || cont == 1) { - suma *= -1; - } + ViewHelper.setX(progressView,getWidth()+progressView.getWidth()/2); + cont += suma; + animation = ObjectAnimator.ofFloat(progressView, "x", -progressView.getWidth()/2); + animation.setDuration(duration/cont); + animation.addListener(this); + animation.start(); + if(cont == 3 || cont == 1) suma *=-1; } + } + + public void onAnimationStart(Animator arg0) {} + public void onAnimationRepeat(Animator arg0) {} + public void onAnimationCancel(Animator arg0) {} }); animation.start(); } diff --git a/MaterialDesign/src/com/gc/materialdesign/views/RippleView.java b/MaterialDesign/src/com/gc/materialdesign/views/RippleView.java deleted file mode 100644 index a086584..0000000 --- a/MaterialDesign/src/com/gc/materialdesign/views/RippleView.java +++ /dev/null @@ -1,190 +0,0 @@ -package com.gc.materialdesign.views; - -import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.util.AttributeSet; -import android.view.MotionEvent; - -public abstract class RippleView extends CustomView{ - - protected boolean settedRippleColor = false; - - protected int rippleSize = 3;//手指按在控件上,产生的圆形涟漪的大小 - protected Integer rippleColor = null;//the color of ripple - protected float rippleSpeed;//the speed of ripple translate - - protected OnClickListener onClickListener; - protected boolean clickAfterRipple = true;//view is click until the ripple is end - - public RippleView(Context context, AttributeSet attrs) { - super(context, attrs); - setAttributes(attrs); - } - - // Set atributtes of XML to View - @Override - protected void setAttributes(AttributeSet attrs) { - super.setAttributes(attrs); - setRippleAttributes(attrs); - } - - protected void setRippleAttributes(AttributeSet attrs) { - /** - * 初始化按压时涟漪的颜色 - * Set Ripple Color - * Color by resource - */ - int color = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"rippleColor",-1); - if(color != -1){ - rippleColor = getResources().getColor(color); - settedRippleColor = true; - }else{ - // Color by hexadecimal - int rColor = attrs.getAttributeIntValue(MATERIALDESIGNXML, "rippleColor", -1);// 16进制的颜色 - if(rColor != -1 && !isInEditMode()) { - rippleColor = rColor; - settedRippleColor = true; - } - } - - /** - * 初始化涟漪扩展的速度 - * init Ripple speed - */ - rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", rippleSpeed); - - /** - * 设定涟漪的响应时间 - */ - clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "clickAfterRipple", clickAfterRipple); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - // super.onInterceptTouchEvent(ev); - return true; - } - - // ripple position - protected float x = -1; - protected float y = -1; - protected float radius = -1; - - @Override - public boolean onTouchEvent(MotionEvent event) { - 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 (clickAfterRipple == false && onClickListener != null) { - onClickListener.onClick(this); - } - } - } - return true; - } - - public Bitmap makeCircleFromBitmap(Bitmap output) { - Canvas canvas = new Canvas(output); - canvas.drawARGB(0, 0, 0, 0); - Paint paint = new Paint(); - paint.setAntiAlias(true); - if (rippleColor == null) { - paint.setColor(makePressColor(255)); - }else { - paint.setColor(rippleColor); - } - canvas.drawCircle(x, y, radius, paint); - if (radius > getHeight() / rippleSize) - radius += rippleSpeed; - if (radius >= getWidth()) { - x = -1; - y = -1; - radius = getHeight() / rippleSize; - if(isEnabled() && clickAfterRipple == true && onClickListener != null) - onClickListener.onClick(this); - } - return output; - } - - @Override - protected void onFocusChanged(boolean gainFocus, int direction, - Rect previouslyFocusedRect) { - if (!gainFocus) { - x = -1; - y = -1; - } - } - - - @Override - public void setOnClickListener(OnClickListener l) { - onClickListener = l; - } - - /** - * set and get ripple color - * @param color - */ - public void setRippleColor(int color) { - rippleColor = color; - settedRippleColor = true; - } - - public int getRippleColor() { - if (rippleColor != null) { - return rippleColor; - }else { - return makePressColor(255); - } - } - - /** - * set and get ripple speed - * @param speed - */ - public void setRippleSpeed(float speed) { - rippleSpeed = speed; - } - - public float getRippleSpeed() { - return rippleSpeed; - } - - /** - * 设置什么时候响应点击事件,是手指按上去就响应,还是等涟漪扩散完再响应 - * @param clickAfterRipple - */ - public void setClickAfterRipple(boolean clickAfterRipple) { - this.clickAfterRipple = clickAfterRipple; - } - - public boolean getClickAfterRipple() { - return clickAfterRipple; - } - -} diff --git a/MaterialDesign/src/com/gc/materialdesign/views/ScrollView.java b/MaterialDesign/src/com/gc/materialdesign/views/ScrollView.java index e52779b..0f9ae0f 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/ScrollView.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/ScrollView.java @@ -3,6 +3,7 @@ import android.content.Context; import android.util.AttributeSet; import android.view.MotionEvent; +import android.view.View; import android.view.ViewGroup; @@ -11,7 +12,6 @@ public class ScrollView extends android.widget.ScrollView { /* * This class avoid problems in scrollviews with elements in library * Use it if you want use a ScrollView in your App - * 当你想要在scrollView中放置有涟漪效果的item时,用这个来代替传统的ScrollView */ public ScrollView(Context context, AttributeSet attrs) { diff --git a/MaterialDesign/src/com/gc/materialdesign/views/Slider.java b/MaterialDesign/src/com/gc/materialdesign/views/Slider.java index 9932dc3..edfc31a 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/Slider.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/Slider.java @@ -24,14 +24,16 @@ import android.widget.TextView; public class Slider extends CustomView { - + // Event when slider change value public interface OnValueChangedListener { public void onValueChanged(int value); } - - private Ball ball; - public NumberIndicator numberIndicator; + + int backgroundColor = Color.parseColor("#4CAF50"); + + Ball ball; + NumberIndicator numberIndicator; boolean showNumberIndicator = false; boolean press = false; @@ -40,76 +42,85 @@ public interface OnValueChangedListener { int max = 100; int min = 0; - private OnValueChangedListener onValueChangedListener; + OnValueChangedListener onValueChangedListener; public Slider(Context context, AttributeSet attrs) { super(context, attrs); setAttributes(attrs); } - @Override - protected void onInitDefaultValues() { - minWidth = 80;// size of view - minHeight = 48; - backgroundColor = Color.parseColor("#4CAF50"); - backgroundResId = R.drawable.background_transparent; - } - - @Override + // Set atributtes of XML to View protected void setAttributes(AttributeSet attrs) { - super.setAttributes(attrs); - if (!isInEditMode()) { - getBackground().setAlpha(0); + + setBackgroundResource(R.drawable.background_transparent); + + // Set size of view + setMinimumHeight(Utils.dpToPx(48, getResources())); + setMinimumWidth(Utils.dpToPx(80, 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); } - showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"showNumberIndicator", false); + + showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, + "showNumberIndicator", false); min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0); - max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 100);// max > min + max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0); value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min); - float size = 20; - String thumbSize = attrs.getAttributeValue(MATERIALDESIGNXML, "thumbSize"); - if (thumbSize != null) { - size = Utils.dipOrDpToFloat(thumbSize); - } - ball = new Ball(getContext()); - setBallParams(size); + 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); // Set if slider content number indicator + // TODO if (showNumberIndicator) { - if (!isInEditMode()) { - numberIndicator = new NumberIndicator(getContext()); - } + numberIndicator = new NumberIndicator(getContext()); } + } - private void setBallParams(float size) { - RelativeLayout.LayoutParams params = new LayoutParams( - Utils.dpToPx(size, getResources()), Utils.dpToPx(size, getResources())); - params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); - ball.setLayoutParams(params); + @Override + public void invalidate() { + ball.invalidate(); + super.invalidate(); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (!placedBall) { + if (!placedBall) placeBall(); - } + if (value == min) { // Crop line to transparent effect - Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); + Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), + canvas.getHeight(), Bitmap.Config.ARGB_8888); Canvas temp = new Canvas(bitmap); Paint paint = new Paint(); paint.setColor(Color.parseColor("#B0B0B0")); paint.setStrokeWidth(Utils.dpToPx(2, getResources())); - temp.drawLine(getHeight() / 2, getHeight() / 2, getWidth() - getHeight() / 2, getHeight() / 2, paint); + temp.drawLine(getHeight() / 2, getHeight() / 2, getWidth() + - getHeight() / 2, getHeight() / 2, paint); Paint transparentPaint = new Paint(); - transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); - transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + 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, + ViewHelper.getY(ball) + ball.getHeight() / 2, ball.getWidth() / 2, transparentPaint); canvas.drawBitmap(bitmap, 0, 0, new Paint()); @@ -117,42 +128,41 @@ protected void onDraw(Canvas canvas) { Paint paint = new Paint(); paint.setColor(Color.parseColor("#B0B0B0")); paint.setStrokeWidth(Utils.dpToPx(2, getResources())); - canvas.drawLine(getHeight() / 2, getHeight() / 2, getWidth() - getHeight() / 2, getHeight() / 2, paint); + canvas.drawLine(getHeight() / 2, getHeight() / 2, getWidth() + - getHeight() / 2, getHeight() / 2, paint); paint.setColor(backgroundColor); - float division = (ball.xFin - ball.xIni) / (max - min); + float division = (ball.xFin - ball.xIni) / (max-min); int value = this.value - min; - canvas.drawLine(getHeight() / 2, getHeight() / 2, value * division + getHeight() / 2, getHeight() / 2, paint); - // init ball's X - ViewHelper.setX(ball, value * division + getHeight() / 2 - ball.getWidth() / 2); - ball.changeBackground(); + canvas.drawLine(getHeight() / 2, getHeight() / 2, value * division + + getHeight() / 2, getHeight() / 2, paint); + } + if (press && !showNumberIndicator) { - /** - * 如果按住,在不显示指示器的状态下,会将ball大小扩大来给用户反馈。 - * 最后一个参数:getHeight() / x,表示的是按下去后显示的圆球的半径 - * 如果x=2,那么按下后圆球的直径就是这个view的高 - * 如果x=3,按下后显示圆球的半径就是这个view高的三分之一 - */ Paint paint = new Paint(); paint.setColor(backgroundColor); paint.setAntiAlias(true); - canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, getHeight() / 2, getHeight() / 3, paint); + canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, + getHeight() / 2, getHeight() / 3, paint); } invalidate(); + } @Override public boolean onTouchEvent(MotionEvent event) { isLastTouch = true; if (isEnabled()) { - if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) { - if (numberIndicator != null && numberIndicator.isShowing() == false) - numberIndicator.show();// 只要一按下就会冒出指示器 + if (event.getAction() == MotionEvent.ACTION_DOWN + || event.getAction() == MotionEvent.ACTION_MOVE) { + if (numberIndicator != null + && numberIndicator.isShowing() == false) + numberIndicator.show(); if ((event.getX() <= getWidth() && event.getX() >= 0)) { press = true; // calculate value int newValue = 0; - float division = (ball.xFin - ball.xIni) / (max - min); + float division = (ball.xFin - ball.xIni) / (max-min); if (event.getX() > ball.xFin) { newValue = max; } else if (event.getX() < ball.xIni) { @@ -176,8 +186,8 @@ public boolean onTouchEvent(MotionEvent event) { if (numberIndicator != null) { // move number indicator numberIndicator.indicator.x = x; - // 指示器起始的y坐标是当前控件的顶部Y坐标-当前控件高度的一半,就等于从空间的垂直中心开始。 - numberIndicator.indicator.finalY = Utils.getRelativeTop(this) - getHeight() ; + numberIndicator.indicator.finalY = Utils + .getRelativeTop(this) - getHeight() / 2; numberIndicator.indicator.finalSize = getHeight() / 2; numberIndicator.numberIndicator.setText(""); } @@ -190,19 +200,32 @@ public boolean onTouchEvent(MotionEvent event) { } - } else if (event.getAction() == MotionEvent.ACTION_UP) { + } else if (event.getAction() == MotionEvent.ACTION_UP || + event.getAction() == MotionEvent.ACTION_CANCEL) { if (numberIndicator != null) numberIndicator.dismiss(); isLastTouch = false; press = false; - if ((event.getX() <= getWidth() && event.getX() >= 0)) { - - } } } return true; } + /** + * 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); + } + private void placeBall() { ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2); ball.xIni = ViewHelper.getX(ball); @@ -221,49 +244,30 @@ public void setOnValueChangedListener( OnValueChangedListener onValueChangedListener) { this.onValueChangedListener = onValueChangedListener; } - - public void setThumbSize(float size) { - setBallParams(size); - } public int getValue() { return value; } - public void setValue(int value) { - setValue(value, false); - } - /** - * @param value - * @param inRunnable 如果为true表示在runnable中跟新进度,否则在主线程中更新 - */ - public void setValue(int value,boolean inRunnable) { - if (value <= min) { - value = min; - } - if (value >= max) { - value = max; - } - setValueInRunnable(value,inRunnable); - } - - - private void setValueInRunnable(final int value,final boolean inRunnable) { - if(placedBall == false && inRunnable == true) + public void setValue(final int value) { + if (placedBall == false) post(new Runnable() { + @Override public void run() { - setValue(value,inRunnable); + setValue(value); } }); - else{ + else { this.value = value; float division = (ball.xFin - ball.xIni) / max; - ViewHelper.setX(ball,value*division + getHeight()/2 - ball.getWidth()/2); + ViewHelper.setX(ball, + value * division + getHeight() / 2 - ball.getWidth() / 2); ball.changeBackground(); } + } - + public int getMax() { return max; } @@ -284,47 +288,39 @@ public boolean isShowNumberIndicator() { return showNumberIndicator; } - public void showNumberIndicator(boolean showNumberIndicator) { + public void setShowNumberIndicator(boolean showNumberIndicator) { this.showNumberIndicator = showNumberIndicator; - if (!isInEditMode()) { - numberIndicator = (showNumberIndicator) ? new NumberIndicator(getContext()) : null; - } + numberIndicator = (showNumberIndicator) ? new NumberIndicator( + getContext()) : null; } - + @Override public void setBackgroundColor(int color) { backgroundColor = color; - if (isEnabled()) { + if (isEnabled()) beforeBackground = backgroundColor; - } } - private boolean placedBall = false; + boolean placedBall = false; - private class Ball extends View { + class Ball extends View { - private float xIni, xFin, xCen; + float xIni, xFin, xCen; public Ball(Context context) { super(context); - if (!isInEditMode()) { - setBackgroundResource(R.drawable.background_switch_ball_uncheck); - } else { - setBackgroundResource(android.R.drawable.radiobutton_off_background); - } + setBackgroundResource(R.drawable.background_switch_ball_uncheck); } public void changeBackground() { - if (!isInEditMode()) { - if (value != min) { - 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); - } + if (value != min) { + 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); } } @@ -332,10 +328,10 @@ public void changeBackground() { // Slider Number Indicator - public class NumberIndicator extends Dialog { + class NumberIndicator extends Dialog { - private Indicator indicator; - private TextView numberIndicator; + Indicator indicator; + TextView numberIndicator; public NumberIndicator(Context context) { super(context, android.R.style.Theme_Translucent); @@ -348,7 +344,8 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.number_indicator_spinner); setCanceledOnTouchOutside(false); - RelativeLayout content = (RelativeLayout) this.findViewById(R.id.number_indicator_spinner_content); + RelativeLayout content = (RelativeLayout) this + .findViewById(R.id.number_indicator_spinner_content); indicator = new Indicator(this.getContext()); content.addView(indicator); @@ -358,8 +355,8 @@ protected void onCreate(Bundle savedInstanceState) { content.addView(numberIndicator); indicator.setLayoutParams(new RelativeLayout.LayoutParams( - RelativeLayout.LayoutParams.MATCH_PARENT, - RelativeLayout.LayoutParams.MATCH_PARENT)); + RelativeLayout.LayoutParams.FILL_PARENT, + RelativeLayout.LayoutParams.FILL_PARENT)); } @Override @@ -372,31 +369,31 @@ public void dismiss() { @Override public void onBackPressed() { - } } - private class Indicator extends RelativeLayout { + class Indicator extends RelativeLayout { // Position of number indicator - private float x = 0; - private float y = 0; + float x = 0; + float y = 0; // Size of number indicator - private float size = 0; + float size = 0; // Final y position after animation - private float finalY = 0; + float finalY = 0; // Final size after animation - private float finalSize = 0; + float finalSize = 0; - private boolean animate = true; + boolean animate = true; - private boolean numberIndicatorResize = false; + boolean numberIndicatorResize = false; public Indicator(Context context) { super(context); - setBackgroundColor(getResources().getColor(android.R.color.transparent)); + setBackgroundColor(getResources().getColor( + android.R.color.transparent)); } @Override @@ -404,8 +401,8 @@ protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (numberIndicatorResize == false) { - RelativeLayout.LayoutParams params = (LayoutParams) numberIndicator. - numberIndicator.getLayoutParams(); + RelativeLayout.LayoutParams params = (LayoutParams) numberIndicator.numberIndicator + .getLayoutParams(); params.height = (int) finalSize * 2; params.width = (int) finalSize * 2; numberIndicator.numberIndicator.setLayoutParams(params); @@ -421,19 +418,25 @@ protected void onDraw(Canvas canvas) { size += Utils.dpToPx(2, getResources()); } canvas.drawCircle( - ViewHelper.getX(ball) + Utils.getRelativeLeft((View) ball.getParent()) + ViewHelper.getX(ball) + + Utils.getRelativeLeft((View) ball.getParent()) + ball.getWidth() / 2, y, size, paint); if (animate && size >= finalSize) animate = false; if (animate == false) { - ViewHelper.setX(numberIndicator.numberIndicator, - (ViewHelper.getX(ball) + Utils.getRelativeLeft((View) ball.getParent()) + ball.getWidth() / 2) - size); + ViewHelper + .setX(numberIndicator.numberIndicator, + (ViewHelper.getX(ball) + + Utils.getRelativeLeft((View) ball + .getParent()) + ball.getWidth() / 2) + - size); ViewHelper.setY(numberIndicator.numberIndicator, y - size); numberIndicator.numberIndicator.setText(value + ""); } + invalidate(); } } -} \ No newline at end of file +} diff --git a/MaterialDesign/src/com/gc/materialdesign/views/Switch.java b/MaterialDesign/src/com/gc/materialdesign/views/Switch.java index ca29193..9bb4090 100644 --- a/MaterialDesign/src/com/gc/materialdesign/views/Switch.java +++ b/MaterialDesign/src/com/gc/materialdesign/views/Switch.java @@ -21,69 +21,65 @@ public class Switch extends CustomView { - private Ball ball; + int backgroundColor = Color.parseColor("#4CAF50"); - private boolean iSchecked = false; - private boolean eventCheck = false; - private boolean press = false; + Ball ball; - private OnCheckListener onCheckListener; + boolean check = false; + boolean eventCheck = false; + boolean press = false; + + OnCheckListener onCheckListener; public Switch(Context context, AttributeSet attrs) { super(context, attrs); setAttributes(attrs); - } - - @Override - protected void onInitDefaultValues() { - minWidth = 80;// size of view - minHeight = 48; - backgroundColor = Color.parseColor("#4CAF50");// default color - backgroundResId = R.drawable.background_transparent; - } - - @Override - protected void setAttributes(AttributeSet attrs) { - super.setAttributes(attrs); - if (!isInEditMode()) { - getBackground().setAlpha(0); - } - iSchecked = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "checked", false); - eventCheck = iSchecked; - //添加监听器,如果点击了这个控件(不包括ball的区域),这个控件就开始判断是否是开启状态。 setOnClickListener(new OnClickListener() { + @Override public void onClick(View arg0) { - setChecked(iSchecked ? false : true); - } - }); - - float size = 20; - String thumbSize = attrs.getAttributeValue(MATERIALDESIGNXML, "thumbSize"); - if (thumbSize != null) { - size = Utils.dipOrDpToFloat(thumbSize); - } - ball = new Ball(getContext()); - setThumbParams(size); - addView(ball); - // 给圆球添加监听器,点击圆球后就开始判断是否进入开启状态 - ball.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - // TODO 自动生成的方法存根 - setChecked(iSchecked ? false : true); + if (check) + setChecked(false); + else + setChecked(true); } }); } - private void setThumbParams(float size) { - RelativeLayout.LayoutParams params = new LayoutParams( - Utils.dpToPx(size, getResources()), Utils.dpToPx(size, getResources())); + // Set atributtes of XML to View + protected void setAttributes(AttributeSet attrs) { + + setBackgroundResource(R.drawable.background_transparent); + + // Set size of view + setMinimumHeight(Utils.dpToPx(48, getResources())); + setMinimumWidth(Utils.dpToPx(80, 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); + } + + 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()) { @@ -91,45 +87,37 @@ public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { press = true; } else if (event.getAction() == MotionEvent.ACTION_MOVE) { - requestDisallowInterceptTouchEvent(true); float x = event.getX(); x = (x < ball.xIni) ? ball.xIni : x; x = (x > ball.xFin) ? ball.xFin : x; if (x > ball.xCen) { - iSchecked = true; + check = true; } else { - iSchecked = false; + check = false; } ViewHelper.setX(ball, x); ball.changeBackground(); - if (event.getX() <= getWidth() && event.getX() >= 0) { + if ((event.getX() <= getWidth() && event.getX() >= 0)) { isLastTouch = false; press = false; } - } else if (event.getAction() == MotionEvent.ACTION_UP - || event.getAction() == MotionEvent.ACTION_CANCEL) { - requestDisallowInterceptTouchEvent(false); + } else if (event.getAction() == MotionEvent.ACTION_UP || + event.getAction() == MotionEvent.ACTION_CANCEL) { press = false; isLastTouch = false; - if (eventCheck != iSchecked) { - eventCheck = iSchecked; + if (eventCheck != check) { + eventCheck = check; if (onCheckListener != null) - onCheckListener.onCheck(iSchecked); + onCheckListener.onCheck(check); } - if (event.getX() <= getWidth() && event.getX() >= 0) { + if ((event.getX() <= getWidth() && event.getX() >= 0)) { ball.animateCheck(); - } + } } } return true; } - -/* @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - //return super.onInterceptTouchEvent(ev); - return false; - } -*/ + @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); @@ -142,26 +130,49 @@ protected void onDraw(Canvas canvas) { Canvas temp = new Canvas(bitmap); Paint paint = new Paint(); paint.setAntiAlias(true); - paint.setColor((iSchecked) ? backgroundColor : Color.parseColor("#B0B0B0")); + paint.setColor((check) ? backgroundColor : Color.parseColor("#B0B0B0")); paint.setStrokeWidth(Utils.dpToPx(2, getResources())); - temp.drawLine(getHeight() / 2, getHeight() / 2, getWidth() - getHeight() / 2, getHeight() / 2, paint); + 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)); + 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); + ViewHelper.getY(ball) + ball.getHeight() / 2, + ball.getWidth() / 2, transparentPaint); + canvas.drawBitmap(bitmap, 0, 0, new Paint()); if (press) { - paint.setColor((iSchecked) ? makePressColor(70) : Color.parseColor("#446D6D6D")); - canvas.drawCircle(ViewHelper.getX(ball) + ball.getWidth() / 2, getHeight() / 2, getHeight() / 2, paint); + 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 - private boolean placedBall = false; + boolean placedBall = false; private void placeBall() { ViewHelper.setX(ball, getHeight() / 2 - ball.getWidth() / 2); @@ -172,62 +183,50 @@ private void placeBall() { ball.animateCheck(); } - // SETTERS AND GETTERS - + // SETTERS + @Override public void setBackgroundColor(int color) { backgroundColor = color; - if (isEnabled()) { + if (isEnabled()) beforeBackground = backgroundColor; - } + } - + public void setChecked(boolean check) { - iSchecked = check; + this.check = check; ball.animateCheck(); } - - public boolean isChecked() { - return iSchecked; - } - public void setThumbSize(float size) { - setThumbParams(size); + public boolean isCheck() { + return check; } - - private class Ball extends View { + class Ball extends View { - private float xIni, xFin, xCen; + float xIni, xFin, xCen; public Ball(Context context) { super(context); - if (!isInEditMode()) { - setBackgroundResource(R.drawable.background_switch_ball_uncheck); - } + setBackgroundResource(R.drawable.background_switch_ball_uncheck); } public void changeBackground() { - if (iSchecked) { - if (!isInEditMode()) { - setBackgroundResource(R.drawable.background_checkbox); - LayerDrawable layer = (LayerDrawable) getBackground(); - GradientDrawable shape = (GradientDrawable) layer - .findDrawableByLayerId(R.id.shape_bacground); - shape.setColor(backgroundColor); - } - + if (check) { + setBackgroundResource(R.drawable.background_checkbox); + LayerDrawable layer = (LayerDrawable) getBackground(); + GradientDrawable shape = (GradientDrawable) layer + .findDrawableByLayerId(R.id.shape_bacground); + shape.setColor(backgroundColor); } else { - if (!isInEditMode()) { - setBackgroundResource(R.drawable.background_switch_ball_uncheck); - } + setBackgroundResource(R.drawable.background_switch_ball_uncheck); } } public void animateCheck() { changeBackground(); ObjectAnimator objectAnimator; - if (iSchecked) { + if (check) { objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xFin); } else { @@ -238,13 +237,13 @@ public void animateCheck() { } } - + public void setOncheckListener(OnCheckListener onCheckListener) { this.onCheckListener = onCheckListener; } public interface OnCheckListener { - public void onCheck(boolean isChecked); + public void onCheck(boolean check); } } diff --git a/MaterialDesign/src/com/gc/materialdesign/widgets/ColorSelector.java b/MaterialDesign/src/com/gc/materialdesign/widgets/ColorSelector.java index 892729d..dd15571 100644 --- a/MaterialDesign/src/com/gc/materialdesign/widgets/ColorSelector.java +++ b/MaterialDesign/src/com/gc/materialdesign/widgets/ColorSelector.java @@ -91,9 +91,9 @@ public void run() { int g = (this.color >> 8) & 0xFF; int b = (this.color >> 0) & 0xFF; - red.setValue(r, true); - green.setValue(g, true); - blue.setValue(b, true); + red.setValue(r); + green.setValue(g); + blue.setValue(b); red.setOnValueChangedListener(this); green.setOnValueChangedListener(this); @@ -121,7 +121,6 @@ public interface OnColorSelectedListener{ @Override public void dismiss() { - Animation anim = AnimationUtils.loadAnimation(context, R.anim.dialog_main_hide_amination); anim.setAnimationListener(new AnimationListener() { diff --git a/MaterialDesign/src/com/gc/materialdesign/widgets/SnackBar.java b/MaterialDesign/src/com/gc/materialdesign/widgets/SnackBar.java index c9fdec9..242abff 100644 --- a/MaterialDesign/src/com/gc/materialdesign/widgets/SnackBar.java +++ b/MaterialDesign/src/com/gc/materialdesign/widgets/SnackBar.java @@ -20,15 +20,15 @@ public class SnackBar extends Dialog{ - private String text; - private float textSize = 14;//Roboto Regular 14sp - private String buttonText; - private View.OnClickListener onClickListener; - private Activity activity; - private View view; - private ButtonFlat button; - private int backgroundSnackBar = Color.parseColor("#333333"); - private int buttonTextColor = Color.parseColor("#1E88E5"); + String text; + float textSize = 14;//Roboto Regular 14sp + String buttonText; + View.OnClickListener onClickListener; + Activity activity; + View view; + ButtonFlat button; + int backgroundSnackBar = Color.parseColor("#333333"); + int backgroundButton = Color.parseColor("#1E88E5"); OnHideListener onHideListener; // Timer @@ -64,7 +64,7 @@ protected void onCreate(Bundle savedInstanceState) { button.setVisibility(View.GONE); }else{ button.setText(buttonText); - button.setTextColor(buttonTextColor); + button.setBackgroundColor(backgroundButton); button.setOnClickListener(new View.OnClickListener() { @@ -86,7 +86,6 @@ public boolean onTouchEvent(MotionEvent event) { @Override public void onBackPressed() { - } @Override @@ -188,16 +187,12 @@ public void setBackgroundSnackBar(int color){ view.setBackgroundColor(color); } - public ButtonFlat getButton() { - return button; - } - /** * Chage color of FlatButton in Snackbar * @param color */ public void setColorButton(int color){ - buttonTextColor = color; + backgroundButton = color; if(button != null) button.setBackgroundColor(color); } diff --git a/MaterialDesignDemo/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs b/MaterialDesignDemo/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs new file mode 100644 index 0000000..333bf0c --- /dev/null +++ b/MaterialDesignDemo/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs @@ -0,0 +1,3 @@ +#org.springsource.ide.eclipse.gradle.core.preferences.GradleProjectPreferences +#Sun Jan 11 18:49:02 CET 2015 +org.springsource.ide.eclipse.gradle.rootprojectloc=.. diff --git a/build.gradle b/build.gradle index 2ff167c..95fa62e 100644 --- a/build.gradle +++ b/build.gradle @@ -19,6 +19,6 @@ allprojects { } group = "com.github.navasmdc" - version = "1.0" + version = "1.1" } diff --git a/gradle.properties b/gradle.properties index e47cb03..bb261e8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,8 +17,8 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=1.0 -VERSION_CODE=1 +VERSION_NAME=1.1 +VERSION_CODE=2 GROUP=com.github.navasmdc diff --git a/settings.gradle b/settings.gradle index a046698..fd4bab1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1 @@ include ':MaterialDesign' -include ':MaterialDesignDemo'