Skip to content

Commit 3af7fb7

Browse files
author
Kaler
committed
add new view——ButtonImage
1 parent 5266fee commit 3af7fb7

37 files changed

+178
-99
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.6
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.6

MaterialDesign/AndroidManifest.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
android:versionCode="1"
44
android:versionName="1.0" >
55

6-
<uses-sdk
7-
android:minSdkVersion="8"
8-
android:targetSdkVersion="19" />
6+
<uses-sdk android:minSdkVersion="8" />
97

10-
<application
11-
android:allowBackup="true"
12-
android:label="@string/app_name" >
13-
14-
</application>
8+
<application android:allowBackup="true" />
159

16-
</manifest>
10+
</manifest>

MaterialDesign/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
1212

1313
# Project target.
14-
target=android-19
14+
target=android-8
1515
android.library=true

MaterialDesign/res/layout/text.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

MaterialDesign/res/values/attributes.xml

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<resources>
3-
4-
<declare-styleable name="CustomAttributes">
5-
6-
<!-- Speed of ripple animation -->
7-
<attr name="rippleSpeed" format="float" />
8-
<!-- in float button indicate if must start with animation -->
9-
<attr name="rippleColor" format="color|reference" />
10-
<!-- indicate if the slider must show number indicator -->
11-
<attr name="showNumberIndicator" format="boolean" />
12-
<!-- in progress view indicate max value of progress -->
13-
<attr name="max" format="integer" />
14-
<!-- in progress view indicate min value of progress -->
15-
<attr name="min" format="integer" />
16-
<!-- in progress view indicate value of progress -->
17-
<attr name="value" format="integer" />
18-
<!-- in progress view indicate value of progress -->
19-
<attr name="progress" format="integer" />
20-
<attr name="ringWidth" format="dimension"/>
21-
<!-- in switche's view indicate state of view -->
22-
<attr name="checked" format="boolean" />
23-
<attr name="checkBoxSize" format="dimension" />
24-
<attr name="thumbSize" format="dimension" />
25-
<!-- in float button indicate icon resource -->
26-
<attr name="iconDrawable" format="integer" />
27-
<!-- in float button indicate icon resource -->
28-
<attr name="iconSize" format="dimension" />
29-
<!-- in float button indicate if must start with animation -->
30-
<attr name="animate" format="boolean" />
31-
<attr name="rippleBorderRadius" format="float" />
32-
<attr name="clickAfterRipple" format="boolean"/>
33-
</declare-styleable>
34-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<declare-styleable name="CustomAttributes">
4+
5+
<!-- Color of ripple animation -->
6+
<attr name="rippleColor" format="color|reference" />
7+
<!-- Speed of ripple animation -->
8+
<attr name="rippleSpeed" format="float" />
9+
<!-- indicate if the slider must show number indicator -->
10+
<attr name="showNumberIndicator" format="boolean" />
11+
<!-- in progress view indicate max value of progress -->
12+
<attr name="max" format="integer" />
13+
<!-- in progress view indicate min value of progress -->
14+
<attr name="min" format="integer" />
15+
<!-- in progress view indicate value of progress -->
16+
<attr name="value" format="integer" />
17+
<!-- in progress view indicate value of progress -->
18+
<attr name="progress" format="integer" />
19+
<attr name="ringWidth" format="dimension" />
20+
<!-- in switche's view indicate state of view -->
21+
<attr name="checked" format="boolean" />
22+
<attr name="checkBoxSize" format="dimension" />
23+
<attr name="thumbSize" format="dimension" />
24+
<!-- in float button indicate icon resource -->
25+
<attr name="iconDrawable" format="integer" />
26+
<!-- in button whitch contains drawable indicate icon resource -->
27+
<attr name="iconSize" format="dimension" />
28+
<!-- in float button indicate if must start with animation -->
29+
<attr name="animate" format="boolean" />
30+
<!-- set the border of the ripple frame -->
31+
<attr name="rippleBorderRadius" format="float" />
32+
<!-- if true, delays calls to OnClickListeners until ripple effect ends -->
33+
<attr name="clickAfterRipple" format="boolean" />
34+
</declare-styleable>
35+
3536
</resources>

MaterialDesign/res/values/strings.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

MaterialDesign/src/com/gc/materialdesign/utils/Utils.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.res.Resources;
44
import android.util.TypedValue;
55
import android.view.View;
6+
import android.view.ViewGroup;
67

78
public class Utils {
89

@@ -31,12 +32,20 @@ public static float dipOrDpToFloat(String value) {
3132
}
3233

3334

35+
/**
36+
* 这里看似是得到控件相对的坐标,但是如果这个滑动条在可以上下滚动的布局中就会出现问题。
37+
* 因为这里的坐标都是死的,在上下滚动的view中父控件的top仍旧不变,但实际上是应该获得动态数值的。
38+
* @error
39+
* @param myView
40+
* @return
41+
*/
3442
public static int getRelativeTop(View myView) {
3543
// if (myView.getParent() == myView.getRootView())
44+
myView.getParent().requestLayout();
3645
if(myView.getId() == android.R.id.content)
3746
return myView.getTop();
3847
else
39-
return myView.getTop() + getRelativeTop((View) myView.getParent());
48+
return myView.getTop() + getRelativeTop((View)myView.getParent());
4049
}
4150

4251
public static int getRelativeLeft(View myView) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public Button(Context context, AttributeSet attrs) {
2121

2222
@Override
2323
protected void onInitDefaultValues() {
24-
backgroundColor = Color.parseColor("#1E88E5");// 默认的背景色,蓝色
24+
backgroundColor = Color.parseColor("#2196f3");// 默认的背景色,蓝色
2525
///beforeBackground = backgroundColor;// error
2626
}
2727

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected void onDraw(Canvas canvas) {
4646
x = -1;
4747
y = -1;
4848
radius = getHeight()/rippleSize;
49-
if (clickAfterRipple == true && onClickListener != null) {
49+
if (isEnabled() && clickAfterRipple == true && onClickListener != null) {
5050
onClickListener.onClick(this);
5151
}
5252
}
@@ -58,9 +58,9 @@ protected void onDraw(Canvas canvas) {
5858
public void setBackgroundColor(int color) {
5959
super.setBackgroundColor(color);
6060
if (!settedRippleColor) {
61+
// 如果之前没有设置过涟漪颜色,那么就用默认的
6162
rippleColor = Color.parseColor("#88DDDDDD");
6263
}
63-
//textButton.setTextColor(color);
6464
}
6565

6666

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ public Bitmap cropCircle(Bitmap bitmap) {
138138

139139
// GET AND SET
140140

141+
/* @Override
142+
public void setEnabled(boolean enabled) {
143+
// TODO 自动生成的方法存根
144+
super.setEnabled(enabled);
145+
icon.setEnabled(enabled);
146+
if (enabled) {
147+
getBackground().setAlpha(255);
148+
}else {
149+
getBackground().setAlpha(25);
150+
}
151+
}*/
152+
141153
public void isAnimate(boolean isAnimate) {
142154
if (isAnimate) {
143155
playAnimation();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected void onDraw(Canvas canvas) {
4646
x = -1;
4747
y = -1;
4848
radius = getHeight()/rippleSize;
49-
if(clickAfterRipple == true && onClickListener != null)
49+
if(isEnabled() && clickAfterRipple == true && onClickListener != null)
5050
onClickListener.onClick(this);
5151
}
5252
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.gc.materialdesign.views;
2+
3+
import android.content.Context;
4+
import android.graphics.Canvas;
5+
import android.graphics.Rect;
6+
import android.util.AttributeSet;
7+
8+
import com.gc.materialdesign.R;
9+
import com.gc.materialdesign.utils.Utils;
10+
11+
public class ButtonImage extends ButtonFloat {
12+
13+
public ButtonImage(Context context, AttributeSet attrs) {
14+
super(context, attrs);
15+
// TODO 自动生成的构造函数存根
16+
}
17+
18+
@Override
19+
protected void onInitDefaultValues() {
20+
super.onInitDefaultValues();
21+
iconSize = 24;
22+
sizeRadius = 28;
23+
rippleSpeed = 8;
24+
rippleSize = 5;
25+
minWidth = 20;
26+
minHeight = 20;
27+
backgroundResId = R.drawable.background_button_rectangle;
28+
}
29+
30+
@Override
31+
protected void onDraw(Canvas canvas) {
32+
//super.onDraw(canvas);
33+
if (x != -1) {
34+
Rect src = new Rect(0, 0, getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources()));
35+
Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()), getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources()));
36+
canvas.drawBitmap(makeCircle(), src, dst, null);
37+
}
38+
invalidate();
39+
}
40+
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ protected void onDraw(Canvas canvas) {
110110

111111
// GET AND SET
112112

113+
/* @Override
114+
public void setEnabled(boolean enabled) {
115+
// TODO 自动生成的方法存根
116+
super.setEnabled(enabled);
117+
textButton.setEnabled(enabled);
118+
if (enabled) {
119+
getBackground().setAlpha(255);
120+
}else {
121+
getBackground().setAlpha(25);
122+
}
123+
124+
}*/
125+
113126
public void setText(final String text){
114127
textButton.setText(text);
115128
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public LayoutRipple(Context context, AttributeSet attrs) {
2626
protected void onInitDefaultValues() {
2727
minWidth = 20;
2828
minHeight = 20;
29-
backgroundColor = 0x00ffffff;
29+
backgroundColor = 0x00ffffff;// alpha = 0
3030
rippleSpeed = 20f;// default speed
3131
}
3232

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ protected void setRippleAttributes(AttributeSet attrs) {
5757
rippleSpeed = attrs.getAttributeFloatValue(MATERIALDESIGNXML, "rippleSpeed", rippleSpeed);
5858

5959
/**
60-
* 设定涟漪的相应时间
60+
* 设定涟漪的响应时间
6161
*/
6262
clickAfterRipple = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "clickAfterRipple", clickAfterRipple);
6363
}
@@ -125,7 +125,7 @@ public Bitmap makeCircleFromBitmap(Bitmap output) {
125125
x = -1;
126126
y = -1;
127127
radius = getHeight() / rippleSize;
128-
if(clickAfterRipple == true && onClickListener != null)
128+
if(isEnabled() && clickAfterRipple == true && onClickListener != null)
129129
onClickListener.onClick(this);
130130
}
131131
return output;
@@ -176,7 +176,7 @@ public float getRippleSpeed() {
176176
}
177177

178178
/**
179-
* 设置什么时候响应点击事件,是手指按上去就相应,还是等涟漪扩散完再响应
179+
* 设置什么时候响应点击事件,是手指按上去就响应,还是等涟漪扩散完再响应
180180
* @param clickAfterRipple
181181
*/
182182
public void setClickAfterRipple(boolean clickAfterRipple) {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import android.graphics.Paint;
1313
import android.graphics.PorterDuff;
1414
import android.graphics.PorterDuffXfermode;
15-
import android.graphics.drawable.Drawable;
1615
import android.graphics.drawable.GradientDrawable;
1716
import android.graphics.drawable.LayerDrawable;
1817
import android.os.Bundle;
@@ -59,6 +58,9 @@ protected void onInitDefaultValues() {
5958
@Override
6059
protected void setAttributes(AttributeSet attrs) {
6160
super.setAttributes(attrs);
61+
if (!isInEditMode()) {
62+
getBackground().setAlpha(0);
63+
}
6264
showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,"showNumberIndicator", false);
6365
min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
6466
max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 100);// max > min
@@ -145,7 +147,7 @@ public boolean onTouchEvent(MotionEvent event) {
145147
if (isEnabled()) {
146148
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
147149
if (numberIndicator != null && numberIndicator.isShowing() == false)
148-
numberIndicator.show();
150+
numberIndicator.show();// 只要一按下就会冒出指示器
149151
if ((event.getX() <= getWidth() && event.getX() >= 0)) {
150152
press = true;
151153
// calculate value
@@ -174,8 +176,8 @@ public boolean onTouchEvent(MotionEvent event) {
174176
if (numberIndicator != null) {
175177
// move number indicator
176178
numberIndicator.indicator.x = x;
177-
numberIndicator.indicator.finalY = Utils.getRelativeTop(this)
178-
- getHeight() / 2;
179+
// 指示器起始的y坐标是当前控件的顶部Y坐标-当前控件高度的一半,就等于从空间的垂直中心开始。
180+
numberIndicator.indicator.finalY = Utils.getRelativeTop(this) - getHeight() / 2;
179181
numberIndicator.indicator.finalSize = getHeight() / 2;
180182
numberIndicator.numberIndicator.setText("");
181183
}
@@ -370,6 +372,7 @@ public void dismiss() {
370372

371373
@Override
372374
public void onBackPressed() {
375+
373376
}
374377

375378
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ protected void onInitDefaultValues() {
4545
@Override
4646
protected void setAttributes(AttributeSet attrs) {
4747
super.setAttributes(attrs);
48+
getBackground().setAlpha(0);
4849
iSchecked = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "checked", false);
4950
eventCheck = iSchecked;
5051
setOnClickListener(new OnClickListener() {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public boolean onTouchEvent(MotionEvent event) {
8686

8787
@Override
8888
public void onBackPressed() {
89+
8990
}
9091

9192
@Override
@@ -187,6 +188,10 @@ public void setBackgroundSnackBar(int color){
187188
view.setBackgroundColor(color);
188189
}
189190

191+
public ButtonFlat getButton() {
192+
return button;
193+
}
194+
190195
/**
191196
* Chage color of FlatButton in Snackbar
192197
* @param color
-233 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)