Skip to content

Commit 196e304

Browse files
author
ivan.navas
committed
Fix some issues
- Change icon attribute to avoid problems with actionbarSherlock Library - Getter and Setter Ripple Speed for Buttons -- Getter and Setter Ripple Check for CheckBox and Switch — Some updates for SnackBar
1 parent f670f86 commit 196e304

File tree

8 files changed

+52
-31
lines changed

8 files changed

+52
-31
lines changed

MaterialDesign/res/values/attributes.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<!-- in switche's view indicate state of view -->
1515
<attr name="check" format="boolean" />
1616
<!-- in float button indicate icon resource -->
17-
<attr name="icon" format="integer" />
17+
<attr name="iconFloat" format="integer" />
1818
<!-- in float button indicate if must start with animation -->
1919
<attr name="animate" format="boolean" />
2020
</declare-styleable>

MaterialDesign/src/com/gc/materialdesign/views/Button.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,12 @@ public void setBackgroundColor(int color){
148148
}
149149

150150
abstract public TextView getTextView();
151+
152+
public void setRippleSpeed(float rippleSpeed){
153+
this.rippleSpeed = rippleSpeed;
154+
}
155+
156+
public float getRippleSpeed(){
157+
return this.rippleSpeed;
158+
}
151159
}

MaterialDesign/src/com/gc/materialdesign/views/ButtonFloat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected void setAttributes(AttributeSet attrs){
7676
setBackgroundColor(Color.parseColor(background));
7777
}
7878
// Icon of button
79-
int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"icon",-1);
79+
int iconResource = attrs.getAttributeResourceValue(MATERIALDESIGNXML,"iconFloat",-1);
8080
if(iconResource != -1)
8181
drawableIcon = getResources().getDrawable(iconResource);
8282
boolean animate = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"animate", false);

MaterialDesign/src/com/gc/materialdesign/views/CheckBox.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ public void setChecked(boolean check){
149149
checkView.changeBackground();
150150

151151
}
152+
153+
public boolean isCheck(){
154+
return check;
155+
}
152156

153157

154158

MaterialDesign/src/com/gc/materialdesign/views/Switch.java

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import com.gc.materialdesign.R;
44
import com.gc.materialdesign.utils.Utils;
5-
import com.nineoldandroids.animation.Animator;
6-
import com.nineoldandroids.animation.AnimatorListenerAdapter;
5+
import com.gc.materialdesign.views.CheckBox.OnCheckListener;
76
import com.nineoldandroids.animation.ObjectAnimator;
87
import com.nineoldandroids.view.ViewHelper;
98

@@ -84,7 +83,6 @@ protected void setAttributes(AttributeSet attrs){
8483
public boolean onTouchEvent(MotionEvent event) {
8584
isLastTouch = true;
8685
if (event.getAction() == MotionEvent.ACTION_DOWN) {
87-
startRedraw();
8886
press = true;
8987
}else if(event.getAction() == MotionEvent.ACTION_MOVE) {
9088
float x = event.getX();
@@ -114,8 +112,6 @@ else if (event.getAction() == MotionEvent.ACTION_UP) {
114112
if((event.getX()<= getWidth() && event.getX() >= 0) &&
115113
(event.getY()<= getHeight() && event.getY() >= 0)){
116114
ball.animateCheck();
117-
}else{
118-
stopRedraw();
119115
}
120116
}
121117
return true;
@@ -147,23 +143,11 @@ protected void onDraw(Canvas canvas) {
147143
paint.setColor((check)?makePressColor():Color.parseColor("#446D6D6D"));
148144
canvas.drawCircle(ViewHelper.getX(ball)+ball.getWidth()/2, getHeight()/2, getHeight()/2, paint);
149145
}
150-
if (canRedraw) {
151-
invalidate();
152-
}
146+
invalidate();
153147

154148
}
155149

156-
boolean canRedraw = false;
157150

158-
private void startRedraw() {
159-
canRedraw = true;
160-
invalidate();
161-
}
162-
163-
private void stopRedraw() {
164-
canRedraw = false;
165-
invalidate();
166-
}
167151

168152
/**
169153
* Make a dark color to press effect
@@ -202,6 +186,10 @@ public void setChecked(boolean check){
202186
ball.animateCheck();
203187
}
204188

189+
public boolean isCheck(){
190+
return check;
191+
}
192+
205193
class Ball extends View{
206194

207195
float xIni, xFin, xCen;
@@ -232,7 +220,6 @@ public void animateCheck(){
232220
}else{
233221
objectAnimator = ObjectAnimator.ofFloat(this, "x", ball.xIni);
234222
}
235-
objectAnimator.addListener(animatorListener);
236223
objectAnimator.setDuration(300);
237224
objectAnimator.start();
238225
}
@@ -241,12 +228,6 @@ public void animateCheck(){
241228

242229
}
243230

244-
private AnimatorListenerAdapter animatorListener = new AnimatorListenerAdapter() {
245-
public void onAnimationEnd(Animator animation) {
246-
stopRedraw();
247-
};
248-
};
249-
250231
public void setOncheckListener(OnCheckListener onCheckListener){
251232
this.onCheckListener = onCheckListener;
252233
}

MaterialDesign/src/com/gc/materialdesign/widgets/SnackBar.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import android.app.Activity;
77
import android.app.Dialog;
8+
import android.graphics.Color;
89
import android.os.Bundle;
910
import android.os.Handler;
1011
import android.os.Message;
@@ -23,6 +24,10 @@ public class SnackBar extends Dialog{
2324
View.OnClickListener onClickListener;
2425
Activity activity;
2526
View view;
27+
ButtonFlat button;
28+
29+
int backgroundSnackBar = Color.parseColor("#333");
30+
int backgroundButton = Color.parseColor("#1E88E5");
2631

2732
// Timer
2833
private boolean mIndeterminate = false;
@@ -51,12 +56,14 @@ protected void onCreate(Bundle savedInstanceState) {
5156
setContentView(R.layout.snackbar);
5257
setCanceledOnTouchOutside(false);
5358
((TextView)findViewById(R.id.text)).setText(text);
54-
ButtonFlat button = (ButtonFlat) findViewById(R.id.buttonflat);
59+
button = (ButtonFlat) findViewById(R.id.buttonflat);
5560
if(text == null || onClickListener == null){
5661
button.setVisibility(View.GONE);
5762
}else{
5863
button.setText(buttonText);
5964

65+
button.setBackgroundColor(backgroundButton);
66+
6067
button.setOnClickListener(new View.OnClickListener() {
6168

6269
@Override
@@ -67,6 +74,7 @@ public void onClick(View v) {
6774
});
6875
}
6976
view = findViewById(R.id.snackbar);
77+
view.setBackgroundColor(backgroundSnackBar);
7078
}
7179

7280
@Override
@@ -148,4 +156,24 @@ public void setDismissTimer(int time) {
148156
public int getDismissTimer() {
149157
return mTimer;
150158
}
159+
160+
/**
161+
* Change background color of SnackBar
162+
* @param color
163+
*/
164+
public void setBackgroundSnackBar(int color){
165+
backgroundSnackBar = color;
166+
if(view != null)
167+
view.setBackgroundColor(color);
168+
}
169+
170+
/**
171+
* Chage color of FlatButton in Snackbar
172+
* @param color
173+
*/
174+
public void setColorButton(int color){
175+
backgroundButton = color;
176+
if(button != null)
177+
button.setBackgroundColor(color);
178+
}
151179
}

MaterialDesignDemo/res/layout/activity_buttons.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
android:layout_height="wrap_content"
105105
android:layout_centerInParent="true"
106106
android:background="#1E88E5"
107-
materialdesign:icon="@drawable/ic_action_new" />
107+
materialdesign:iconFloat="@drawable/ic_action_new" />
108108
</RelativeLayout>
109109

110110
<!-- SMALL FLOAT BUTTON -->
@@ -136,6 +136,6 @@
136136
android:layout_marginRight="24dp"
137137
android:background="#1E88E5"
138138
materialdesign:animate="true"
139-
materialdesign:icon="@drawable/ic_action_new" />
139+
materialdesign:iconFloat="@drawable/ic_action_new" />
140140

141141
</RelativeLayout>

MaterialDesignDemo/res/layout/activity_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
android:layout_marginLeft="32dp"
4040
android:layout_marginTop="108dp"
4141
android:background="#1E88E5"
42-
materialdesign:icon="@drawable/icn_select_color" />
42+
materialdesign:iconFloat="@drawable/icn_select_color" />
4343
</RelativeLayout>
4444

4545
<RelativeLayout

0 commit comments

Comments
 (0)