-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from navasmdc/develop
Fix some bug and performance improvement
- Loading branch information
Showing
34 changed files
with
1,350 additions
and
1,311 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
.settings/gradle/org.springsource.ide.eclipse.gradle.core.import.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
4 changes: 4 additions & 0 deletions
4
.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=.. |
9 changes: 9 additions & 0 deletions
9
MaterialDesign/.settings/gradle/org.springsource.ide.eclipse.gradle.refresh.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 144 additions & 39 deletions
183
MaterialDesign/src/com/gc/materialdesign/views/Button.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Oops, something went wrong.