Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hasBottom option #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.14.2'
classpath 'com.android.tools.build:gradle:1.0.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jan 01 15:09:54 EET 2015
#Thu Jan 08 13:08:07 CET 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
26 changes: 24 additions & 2 deletions library/src/main/java/com/dd/processbutton/FlatButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,19 @@ private void initAttributes(Context context, AttributeSet attributeSet) {
}
}

private LayerDrawable createNormalDrawable(TypedArray attr) {
private Drawable createNormalDrawable(TypedArray attr) {
Drawable drawableNormal;
if (attr.getBoolean(R.styleable.FlatButton_pb_hasBottom, true)) {
drawableNormal = createLayeredNormalDrawable(attr);
} else {
drawableNormal = createGradientNormalDrawable(attr);
}
return drawableNormal;
}

private Drawable createLayeredNormalDrawable(TypedArray attr) {
LayerDrawable drawableNormal =
(LayerDrawable) getDrawable(R.drawable.rect_normal).mutate();
(LayerDrawable) getDrawable(R.drawable.rect_normal_with_bottom).mutate();

GradientDrawable drawableTop =
(GradientDrawable) drawableNormal.getDrawable(0).mutate();
Expand All @@ -87,6 +97,18 @@ private LayerDrawable createNormalDrawable(TypedArray attr) {
return drawableNormal;
}

private Drawable createGradientNormalDrawable(TypedArray attr) {
GradientDrawable drawableNormal =
(GradientDrawable) getDrawable(R.drawable.rect_normal).mutate();
drawableNormal.setCornerRadius(getCornerRadius());

int blueNormal = getColor(R.color.blue_normal);
int colorNormal = attr.getColor(R.styleable.FlatButton_pb_colorNormal, blueNormal);
drawableNormal.setColor(colorNormal);

return drawableNormal;
}

private Drawable createPressedDrawable(TypedArray attr) {
GradientDrawable drawablePressed =
(GradientDrawable) getDrawable(R.drawable.rect_pressed).mutate();
Expand Down
20 changes: 5 additions & 15 deletions library/src/main/res/drawable/rect_normal.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="@dimen/corner_radius" />
<solid android:color="@color/blue_pressed" />
</shape>
</item>

<item android:bottom="@dimen/layer_padding">
<shape android:shape="rectangle">
<corners android:radius="@dimen/corner_radius" />
<solid android:color="@color/blue_normal" />
</shape>
</item>
</layer-list>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="@dimen/corner_radius" />
<solid android:color="@color/blue_normal" />
</shape>
17 changes: 17 additions & 0 deletions library/src/main/res/drawable/rect_normal_with_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<corners android:radius="@dimen/corner_radius" />
<solid android:color="@color/blue_pressed" />
</shape>
</item>

<item android:bottom="@dimen/layer_padding">
<shape android:shape="rectangle">
<corners android:radius="@dimen/corner_radius" />
<solid android:color="@color/blue_normal" />
</shape>
</item>
</layer-list>
1 change: 1 addition & 0 deletions library/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
</declare-styleable>

<declare-styleable name="FlatButton">
<attr name="pb_hasBottom" format="boolean" />
<attr name="pb_colorPressed" format="color" />
<attr name="pb_colorNormal" format="color" />
<attr name="pb_cornerRadius" format="dimension" />
Expand Down
8 changes: 5 additions & 3 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ android {
}

applicationVariants.all { variant ->
def oldFile = variant.outputFile
def newPath = "${variant.name}" + "_" + "${variant.versionName}" + "_" + "${variant.versionCode}" + "_" + getDate() + ".apk";
variant.outputFile = new File(oldFile.parentFile, newPath)
variant.outputs.each { output ->
def oldFile = output.outputFile
def newPath = "${variant.name}" + "_" + "${variant.versionName}" + "_" + "${variant.versionCode}" + "_" + getDate() + ".apk";
output.outputFile = new File(oldFile.parentFile, newPath)
}
}
}

Expand Down