├── .gitignore
├── .idea
└── copyright
│ └── profiles_settings.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── sample
│ │ └── dagang
│ │ └── gradientbutton
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── sample
│ │ │ └── dagang
│ │ │ └── gradientbutton
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── sample
│ └── dagang
│ └── gradientbutton
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── imgs
└── device-2017-10-21-161009.png
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── dagang
│ │ └── library
│ │ └── GradientButton.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /.idea
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GradientButton
2 |
3 | A Button that supports gradient ramp for background, the Angle of the circular, shadow.
4 | You can also customize it use hardcode.
5 |
6 | # Preview
7 |
8 |

9 |
10 | # Getting Started
11 |
12 | In your `build.gradle:`
13 |
14 | ```java
15 | dependencies {
16 | compile 'com.dagang:gradient-button:1.0.1'
17 | }
18 | ```
19 |
20 | # Usage
21 |
22 |
23 | ```java
24 |
41 | ```
42 | ### or use java code
43 | ```java
44 | GradientButton gradientButton = (GradientButton) findViewById(R.id.magic_button);
45 | TextView textView = gradientButton.getButton();
46 | textView.setText("Custom Button");
47 | textView.setTextColor(Color.BLUE);
48 | gradientButton.setButtonRadius(20);
49 | gradientButton.setShadowRadius(10);
50 | gradientButton.setShadowColor(Color.RED);
51 | gradientButton.setButtonStartColor(Color.parseColor("#EEE5DE"));
52 | gradientButton.setButtonEndColor(Color.parseColor("#9370DB"));
53 | gradientButton.setButtonPressStartColor(Color.BLACK);
54 | gradientButton.setButtonPressEndColor(Color.BLACK);
55 | gradientButton.setButtonGradientOrientation(GradientButton.LEFT_RIGHT);
56 | gradientButton.getButton().setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | Toast.makeText(MainActivity.this, "onClick", Toast.LENGTH_LONG).show();
60 | }
61 | });
62 | ```
63 |
64 | # Thanks
65 |
66 | [ShadowLayout](https://github.com/Devlight/ShadowLayout)
67 | # Contact me
68 | Email: [dagangxx@gmail.com](dagangxx@gmail.com)
69 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /.idea
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 | defaultConfig {
7 | applicationId "sample.dagang.gradientbutton"
8 | minSdkVersion 14
9 | targetSdkVersion 26
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile project(':library')
28 | // compile 'com.dagang:gradient-button:1.0.0'
29 | compile 'com.android.support:appcompat-v7:26.+'
30 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/duweigang/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/sample/dagang/gradientbutton/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package sample.dagang.gradientbutton;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("sample.dagang.gradientbutton", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/sample/dagang/gradientbutton/MainActivity.java:
--------------------------------------------------------------------------------
1 | package sample.dagang.gradientbutton;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.View;
7 | import android.widget.TextView;
8 | import android.widget.Toast;
9 |
10 | import com.dagang.library.GradientButton;
11 |
12 | public class MainActivity extends AppCompatActivity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 | setContentView(R.layout.activity_main);
18 | GradientButton gradientButton = (GradientButton) findViewById(R.id.magic_button);
19 | TextView textView = gradientButton.getButton();
20 | textView.setText("Custom Button");
21 | textView.setTextColor(Color.BLUE);
22 | gradientButton.setButtonRadius(20);
23 | gradientButton.setShadowRadius(10);
24 | gradientButton.setShadowColor(Color.RED);
25 | gradientButton.setButtonStartColor(Color.parseColor("#EEE5DE"));
26 | gradientButton.setButtonEndColor(Color.parseColor("#9370DB"));
27 | gradientButton.setButtonPressStartColor(Color.BLACK);
28 | gradientButton.setButtonPressEndColor(Color.BLACK);
29 | gradientButton.setButtonGradientOrientation(GradientButton.LEFT_RIGHT);
30 | gradientButton.getButton().setOnClickListener(new View.OnClickListener() {
31 | @Override
32 | public void onClick(View v) {
33 | Toast.makeText(MainActivity.this, "onClick", Toast.LENGTH_LONG).show();
34 | }
35 | });
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
26 |
27 |
44 |
45 |
63 |
64 |
82 |
83 |
101 |
102 |
120 |
121 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | GradientButton
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/sample/dagang/gradientbutton/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package sample.dagang.gradientbutton;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Oct 21 20:08:36 CST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/imgs/device-2017-10-21-161009.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/vangeldu/GradientButton/1216c727b55b1eed2c0ca62b0bd5dab3aac43937/imgs/device-2017-10-21-161009.png
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | /.idea
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.novoda.bintray-release'
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 26
10 | versionCode 3
11 | versionName "1.2"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 |
26 | }
27 | publish {
28 | userOrg = 'dagangxx'
29 | groupId = 'com.dagang'
30 | artifactId = 'gradient-button'
31 | publishVersion = '1.0.1'
32 | website = 'https://github.com/duweigang/GradientButton'
33 | }
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/duweigang/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/java/com/dagang/library/GradientButton.java:
--------------------------------------------------------------------------------
1 | package com.dagang.library;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BlurMaskFilter;
7 | import android.graphics.Canvas;
8 | import android.graphics.Color;
9 | import android.graphics.Paint;
10 | import android.graphics.PorterDuff;
11 | import android.graphics.Rect;
12 | import android.graphics.drawable.GradientDrawable;
13 | import android.graphics.drawable.StateListDrawable;
14 | import android.os.Build;
15 | import android.util.AttributeSet;
16 | import android.view.Gravity;
17 | import android.view.ViewGroup;
18 | import android.widget.FrameLayout;
19 | import android.widget.TextView;
20 |
21 | /**
22 | * Created by duweigang on 2017/10/8.
23 | *
24 | * email : dagangxx@gmail.com
25 | *
26 | * https://github.com/duweigang
27 | */
28 |
29 | public class GradientButton extends FrameLayout {
30 |
31 | public static final int TOP_BOTTOM = 0;
32 | public static final int TR_BL = 1;
33 | public static final int RIGHT_LEFT = 2;
34 | public static final int BR_TL = 3;
35 | public static final int BOTTOM_TOP = 4;
36 | public static final int BL_TR = 5;
37 | public static final int LEFT_RIGHT = 6;
38 | public static final int TL_BR = 7;
39 | private final Paint paint;
40 | private final Canvas canvas;
41 | private final Rect bounds;
42 | private Bitmap bitmap;
43 | private boolean invalidateShadow;
44 | private boolean isShadowed;
45 | private int shadowColor;
46 | private int shadowAlpha;
47 | private float shadowRadius;
48 | private float shadowDistance;
49 | private float shadowAngle;
50 | private float shadowDx;
51 | private float shadowDy;
52 |
53 | private TextView button;
54 |
55 |
56 | private String buttonText;
57 | private float buttonSize;
58 | private int buttonTextColor;
59 |
60 | private int buttonStartColor;
61 | private int buttonEndColor;
62 | private int buttonPressStartColor;
63 | private int buttonPressEndColor;
64 | private int buttonGradientOrientation;
65 | private int buttonRadius;
66 | private Context context;
67 |
68 |
69 | public GradientButton(Context context) {
70 | this(context, null);
71 | }
72 |
73 | public GradientButton(Context context, AttributeSet attrs) {
74 | this(context, attrs, 0);
75 | }
76 |
77 | public GradientButton(Context context, AttributeSet attrs, int defStyleAttr) {
78 | super(context, attrs, defStyleAttr);
79 | this.context = context;
80 | this.paint = new Paint(1) {
81 | {
82 | this.setDither(true);
83 | this.setFilterBitmap(true);
84 | }
85 | };
86 | this.canvas = new Canvas();
87 | this.bounds = new Rect();
88 | this.invalidateShadow = true;
89 | this.setWillNotDraw(false);
90 | this.setLayerType(2, this.paint);
91 |
92 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.GradientButton);
93 |
94 | try {
95 | buttonText = (typedArray.getString(R.styleable.GradientButton_button_text));
96 | buttonSize = (typedArray.getDimension(R.styleable.GradientButton_button_size, 14));
97 | buttonTextColor = (typedArray.getColor(R.styleable.GradientButton_button_text_color, Color.parseColor("#9F79EE")));
98 | buttonStartColor = (typedArray.getColor(R.styleable.GradientButton_button_start_color, Color.parseColor("#EEA9B8")));
99 | buttonEndColor = (typedArray.getColor(R.styleable.GradientButton_button_end_color, Color.parseColor("#EE799F")));
100 | buttonPressStartColor = (typedArray.getColor(R.styleable.GradientButton_button_press_start_color, Color.parseColor("#EEA9B8")));
101 | buttonPressEndColor = (typedArray.getColor(R.styleable.GradientButton_button_press_end_color, Color.parseColor("#EE799F")));
102 | buttonGradientOrientation = (typedArray.getInt(R.styleable.GradientButton_button_gradient_orientation, 6));
103 | buttonRadius = ((int) typedArray.getDimension(R.styleable.GradientButton_button_radius, 10));
104 |
105 | this.setIsShadowed(typedArray.getBoolean(R.styleable.GradientButton_button_is_shadowed, true));
106 | this.setShadowRadius(typedArray.getDimension(R.styleable.GradientButton_button_shadow_radius, 6.0F));
107 | this.setShadowDistance(typedArray.getDimension(R.styleable.GradientButton_button_shadow_distance, 6.0F));
108 | this.setShadowAngle((float) typedArray.getInteger(R.styleable.GradientButton_button_shadow_angle, 45));
109 | this.setShadowColor(typedArray.getColor(R.styleable.GradientButton_button_shadow_color, Color.parseColor("#EEA9B8")));
110 | } finally {
111 | typedArray.recycle();
112 | }
113 | addButtonText();
114 | }
115 |
116 | private void addButtonText() {
117 | button = new TextView(context);
118 | button.setClickable(true);
119 | button.setGravity(Gravity.CENTER);
120 | button.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
121 | button.setText(buttonText);
122 | button.setTextSize(buttonSize);
123 | button.setTextColor(buttonTextColor);
124 | addView(button);
125 | }
126 |
127 | private void setButtonBackground() {
128 |
129 | int[] defaultColors = {buttonStartColor, buttonEndColor};
130 | int[] pressColors = {buttonPressStartColor, buttonPressEndColor};
131 |
132 | GradientDrawable defaultDrawable = getGradientDrawable(defaultColors);
133 | GradientDrawable pressDrawable = getGradientDrawable(pressColors);
134 |
135 | StateListDrawable stateListDrawable = new StateListDrawable();
136 | stateListDrawable.addState(new int[]{android.R.attr.state_pressed}, pressDrawable);
137 | stateListDrawable.addState(new int[]{}, defaultDrawable);
138 |
139 | button.setBackgroundDrawable(stateListDrawable);
140 | }
141 |
142 | private GradientDrawable getGradientDrawable(int[] colors) {
143 |
144 | GradientDrawable backDrawable = new GradientDrawable();
145 | backDrawable.setCornerRadius(buttonRadius);
146 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
147 | backDrawable.setColors(colors);
148 | switch (buttonGradientOrientation) {
149 | case TOP_BOTTOM:
150 | backDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM);
151 | break;
152 | case TR_BL:
153 | backDrawable.setOrientation(GradientDrawable.Orientation.TR_BL);
154 | break;
155 | case RIGHT_LEFT:
156 | backDrawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT);
157 | break;
158 | case BR_TL:
159 | backDrawable.setOrientation(GradientDrawable.Orientation.BR_TL);
160 | break;
161 | case BOTTOM_TOP:
162 | backDrawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP);
163 | break;
164 | case BL_TR:
165 | backDrawable.setOrientation(GradientDrawable.Orientation.BL_TR);
166 | break;
167 | case LEFT_RIGHT:
168 | backDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT);
169 | break;
170 | case TL_BR:
171 | backDrawable.setOrientation(GradientDrawable.Orientation.TL_BR);
172 | break;
173 | }
174 | } else {
175 | backDrawable.setColor(colors[0]);
176 | }
177 | return backDrawable;
178 | }
179 |
180 | protected void onDetachedFromWindow() {
181 | super.onDetachedFromWindow();
182 | if (this.bitmap != null) {
183 | this.bitmap.recycle();
184 | this.bitmap = null;
185 | }
186 |
187 | }
188 |
189 | private void resetShadow() {
190 | this.shadowDx = (float) ((double) this.shadowDistance * Math.cos((double) (this.shadowAngle / 180.0F) * 3.141592653589793D));
191 | this.shadowDy = (float) ((double) this.shadowDistance * Math.sin((double) (this.shadowAngle / 180.0F) * 3.141592653589793D));
192 | int padding = (int) (this.shadowDistance + this.shadowRadius);
193 | this.setPadding(padding, padding, padding, padding);
194 | this.requestLayout();
195 | }
196 |
197 | private int adjustShadowAlpha(boolean adjust) {
198 | return Color.argb(adjust ? 255 : this.shadowAlpha, Color.red(this.shadowColor), Color.green(this.shadowColor), Color.blue(this.shadowColor));
199 | }
200 |
201 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
202 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
203 | this.bounds.set(0, 0, MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
204 | }
205 |
206 | public void requestLayout() {
207 | this.invalidateShadow = true;
208 | super.requestLayout();
209 | }
210 |
211 | @Override
212 | protected void onDraw(Canvas canvas) {
213 | super.onDraw(canvas);
214 | setButtonBackground();
215 |
216 | setButtonShadow(canvas);
217 | }
218 |
219 | private void setButtonShadow(Canvas canvas) {
220 | if (this.isShadowed) {
221 | if (this.invalidateShadow) {
222 | if (this.bounds.width() != 0 && this.bounds.height() != 0) {
223 | this.bitmap = Bitmap.createBitmap(this.bounds.width(), this.bounds.height(), Bitmap.Config.ARGB_8888);
224 | this.canvas.setBitmap(this.bitmap);
225 | this.invalidateShadow = false;
226 | super.dispatchDraw(this.canvas);
227 | Bitmap extractedAlpha = this.bitmap.extractAlpha();
228 | this.canvas.drawColor(0, PorterDuff.Mode.CLEAR);
229 | this.paint.setColor(this.adjustShadowAlpha(false));
230 | this.canvas.drawBitmap(extractedAlpha, this.shadowDx, this.shadowDy, this.paint);
231 | extractedAlpha.recycle();
232 | } else {
233 | this.bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565);
234 | }
235 | }
236 |
237 | this.paint.setColor(this.adjustShadowAlpha(true));
238 | if (this.canvas != null && this.bitmap != null && !this.bitmap.isRecycled()) {
239 | canvas.drawBitmap(this.bitmap, 0.0F, 0.0F, this.paint);
240 | }
241 | }
242 | }
243 |
244 |
245 | public boolean isShadowed() {
246 | return this.isShadowed;
247 | }
248 |
249 | public void setIsShadowed(boolean isShadowed) {
250 | this.isShadowed = isShadowed;
251 | this.postInvalidate();
252 | }
253 |
254 | public float getShadowDistance() {
255 | return this.shadowDistance;
256 | }
257 |
258 | public void setShadowDistance(float shadowDistance) {
259 | this.shadowDistance = shadowDistance;
260 | this.resetShadow();
261 | }
262 |
263 | public float getShadowAngle() {
264 | return this.shadowAngle;
265 | }
266 |
267 | public void setShadowAngle(float shadowAngle) {
268 | this.shadowAngle = Math.max(0.0F, Math.min(shadowAngle, 360.0F));
269 | this.resetShadow();
270 | }
271 |
272 | public float getShadowRadius() {
273 | return this.shadowRadius;
274 | }
275 |
276 | public void setShadowRadius(float shadowRadius) {
277 | this.shadowRadius = Math.max(0.1F, shadowRadius);
278 | if (!this.isInEditMode()) {
279 | this.paint.setMaskFilter(new BlurMaskFilter(this.shadowRadius, BlurMaskFilter.Blur.NORMAL));
280 | this.resetShadow();
281 | }
282 | }
283 |
284 | public int getShadowColor() {
285 | return this.shadowColor;
286 | }
287 |
288 | public void setShadowColor(int shadowColor) {
289 | this.shadowColor = shadowColor;
290 | this.shadowAlpha = Color.alpha(shadowColor);
291 | this.resetShadow();
292 | }
293 |
294 | public float getShadowDx() {
295 | return this.shadowDx;
296 | }
297 |
298 | public float getShadowDy() {
299 | return this.shadowDy;
300 | }
301 |
302 | public TextView getButton() {
303 | return button;
304 | }
305 |
306 | public void setButton(TextView mButton) {
307 | this.button = mButton;
308 | }
309 |
310 | public int getButtonStartColor() {
311 | return buttonStartColor;
312 | }
313 |
314 | public void setButtonStartColor(int buttonStartColor) {
315 | this.buttonStartColor = buttonStartColor;
316 | requestLayout();
317 | }
318 |
319 | public int getButtonEndColor() {
320 | return buttonEndColor;
321 | }
322 |
323 | public void setButtonEndColor(int buttonEndColor) {
324 | this.buttonEndColor = buttonEndColor;
325 | requestLayout();
326 | }
327 |
328 | public int getButtonPressStartColor() {
329 | return buttonPressStartColor;
330 | }
331 |
332 | public void setButtonPressStartColor(int buttonPressStartColor) {
333 | this.buttonPressStartColor = buttonPressStartColor;
334 | requestLayout();
335 | }
336 |
337 | public int getButtonPressEndColor() {
338 | return buttonPressEndColor;
339 | }
340 |
341 | public void setButtonPressEndColor(int buttonPressEndColor) {
342 | this.buttonPressEndColor = buttonPressEndColor;
343 | requestLayout();
344 | }
345 |
346 | public int getButtonGradientOrientation() {
347 | return buttonGradientOrientation;
348 | }
349 |
350 | public void setButtonGradientOrientation(int buttonGradientOrientation) {
351 | this.buttonGradientOrientation = buttonGradientOrientation;
352 | requestLayout();
353 | }
354 |
355 | public int getButtonRadius() {
356 | return buttonRadius;
357 | }
358 |
359 | public void setButtonRadius(int buttonRadius) {
360 | this.buttonRadius = buttonRadius;
361 | requestLayout();
362 | }
363 | }
364 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | library
3 |
4 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':library'
2 |
--------------------------------------------------------------------------------