├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ └── sample │ │ └── kingja │ │ └── supershapeview │ │ └── MainActivity.java │ └── res │ ├── drawable │ ├── bubble_background.xml │ ├── circle_gradient.xml │ └── sweep_gradient.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── car.jpg │ ├── close.png │ ├── hill.jpg │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ ├── ic_launcher_round.png │ ├── jason.jpg │ ├── send.png │ └── taylor.jpg │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ ├── ic_launcher_foreground.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── ic_launcher_background.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── imgs ├── qcode_1.2.0.png └── super_shape_view.png ├── settings.gradle └── supershapeview ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── ic_launcher-web.png ├── java └── com │ └── kingja │ └── supershapeview │ ├── core │ ├── ISuperShape.java │ ├── SuperConfig.java │ └── SuperManager.java │ ├── shape │ ├── CommonShape.java │ ├── IBuilder.java │ └── ImageShape.java │ └── view │ ├── SuperShapeEditText.java │ ├── SuperShapeFrameLayout.java │ ├── SuperShapeImageView.java │ ├── SuperShapeLinearLayout.java │ ├── SuperShapeRelativeLayout.java │ └── SuperShapeTextView.java └── res └── values ├── attr.xml ├── ic_launcher_background.xml └── strings.xml /.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 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperShapeView 2 | A smart custom view support shapes for TextView ,EditView ,ImageView and so on,instead of shape.xml. CLICK THE ***STAR*** if it's useful for you. 3 | 4 | ## Preview 5 |
6 | 7 | ## Custom attribute 8 | | attribute | format | example | 9 | | :------------- |:-------------| :-----| 10 | | super_cornerRadius | dimension | app:super_cornerRadius="5dp" | 11 | | super_strokeWidth | dimension | app:super_strokeWidth="1dp" | 12 | | super_strokeColor | color/reference | app:super_strokeColor="#bebebe" | 13 | | super_solidColor | color/reference | app:super_solidColor="@color/red" | 14 | | super_dashWidth | dimension | app:super_dashWidth="2dp" | 15 | | super_dashGap | dimension | app:super_dashGap="2dp" | 16 | | super_topLeftRadius | dimension | app:super_topLeftRadius="2dp" | 17 | | super_topRightRadius | dimension | app:super_topRightRadius="2dp" | 18 | | super_bottomLeftRadius | dimension | app:super_bottomLeftRadius="2dp" | 19 | | super_bottomRightRadius | dimension | app:super_bottomRightRadius="2dp" | 20 | 21 | ## Gradle 22 | ```java 23 | compile 'com.kingja.supershapeview:supershapeview:1.2.0' 24 | ``` 25 | 26 | ## Usage 27 | ##### Build in xml 28 | * `Image Shape` 29 | ```xml 30 | 42 | ``` 43 | * `Others` 44 | ```xml 45 | 57 | ``` 58 | 59 | ##### Modify attrs dynamically 60 | ```java 61 | SuperShapeTextView superShapeTextView = (SuperShapeTextView) view; 62 | SuperManager superManager = superShapeTextView.getSuperManager(); 63 | superManager.setSolidColor(0xff303F9F); 64 | superManager.setStrokeColor(getResources().getColor(R.color.colorAccent)); 65 | superManager.setCorner(20);//DP 66 | superManager.setStrokeWidth(2);//DP 67 | superManager.setDashGap(2);//DP 68 | superManager.setDashWidth(2);//DP 69 | superManager.setCorner(10,6,10,6); 70 | ... 71 | ``` 72 | 73 | ## Download Demo 74 | ![](imgs/qcode_1.2.0.png) 75 | 76 | 77 | ## Changelog 78 | **v1.2.0** 79 | - provide API for setting attrs 80 | - provide Shape for ImageView (SuperShapeImageView) 81 | 82 | **v1.1.1** 83 | - Initial release 84 | 85 | ## Contact me 86 | Any questions:Welcome to contact me. 87 | * Email:kingjavip@gmail.com 88 | 89 | ## License 90 | 91 | Copyright 2017 KingJA 92 | 93 | Licensed under the Apache License, Version 2.0 (the "License"); 94 | you may not use this file except in compliance with the License. 95 | You may obtain a copy of the License at 96 | 97 | http://www.apache.org/licenses/LICENSE-2.0 98 | 99 | Unless required by applicable law or agreed to in writing, software 100 | distributed under the License is distributed on an "AS IS" BASIS, 101 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 102 | See the License for the specific language governing permissions and 103 | limitations under the License. 104 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /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.kingja.supershapeview" 8 | minSdkVersion 16 9 | targetSdkVersion 26 10 | versionCode 20180314 11 | versionName "1.2.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | compileOptions { 20 | sourceCompatibility JavaVersion.VERSION_1_8 21 | targetCompatibility JavaVersion.VERSION_1_8 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | implementation 'com.android.support:appcompat-v7:26.1.0' 28 | implementation project(':supershapeview') 29 | } 30 | -------------------------------------------------------------------------------- /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 D:\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/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /app/src/main/java/sample/kingja/supershapeview/MainActivity.java: -------------------------------------------------------------------------------- 1 | package sample.kingja.supershapeview; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.view.View; 6 | 7 | import com.kingja.supershapeview.core.SuperManager; 8 | import com.kingja.supershapeview.view.SuperShapeEditText; 9 | import com.kingja.supershapeview.view.SuperShapeImageView; 10 | import com.kingja.supershapeview.view.SuperShapeTextView; 11 | 12 | import java.util.Random; 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_main); 20 | } 21 | 22 | public void changeIvStyle(View view) { 23 | SuperShapeImageView superShapeImageView = (SuperShapeImageView) view; 24 | SuperManager superManager = superShapeImageView.getSuperManager(); 25 | superManager.setStrokeColor(getResources().getColor(R.color.colorAccent)); 26 | superManager.setStrokeWidth(new Random().nextInt(6)); 27 | superManager.setDashGap(new Random().nextInt(6)); 28 | superManager.setDashWidth(new Random().nextInt(6)); 29 | superManager.setCorner(new Random().nextInt(10), new Random().nextInt(20), new Random().nextInt(30), new 30 | Random().nextInt(50)); 31 | // superManager.setCorner(new Random().nextInt(20)); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bubble_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/circle_gradient.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/sweep_gradient.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 19 | 20 | 27 | 28 | 42 | 43 | 53 | 54 | 55 | 56 | 61 | 62 | 72 | 73 | 77 | 78 | 79 | 80 | 95 | 96 | 104 | 105 | 111 | 112 | 119 | 120 | 125 | 126 | 127 | 128 | 129 | 130 | 141 | 142 | 143 | 154 | 155 | 168 | 169 | 183 | 184 | 185 | 197 | 198 | 213 | 214 | 222 | 223 | 227 | 228 | 229 | 230 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/car.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/car.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/close.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/hill.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/hill.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/jason.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/jason.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/send.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/send.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/taylor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxhdpi/taylor.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/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/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3489FF 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SuperShapeView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.0.0' 11 | 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | } 22 | } 23 | 24 | task clean(type: Delete) { 25 | delete rootProject.buildDir 26 | } 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Oct 26 22:07:46 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-4.1-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/qcode_1.2.0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/imgs/qcode_1.2.0.png -------------------------------------------------------------------------------- /imgs/super_shape_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/imgs/super_shape_view.png -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':supershapeview' 2 | -------------------------------------------------------------------------------- /supershapeview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /supershapeview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion '26.0.2' 6 | 7 | defaultConfig { 8 | minSdkVersion 16 9 | targetSdkVersion 26 10 | versionCode 20180314 11 | versionName "1.2.0" 12 | } 13 | buildTypes { 14 | release { 15 | minifyEnabled false 16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 17 | } 18 | } 19 | compileOptions { 20 | sourceCompatibility JavaVersion.VERSION_1_8 21 | targetCompatibility JavaVersion.VERSION_1_8 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(include: ['*.jar'], dir: 'libs') 27 | implementation 'com.android.support:appcompat-v7:26.1.0' 28 | } 29 | -------------------------------------------------------------------------------- /supershapeview/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 D:\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 | -------------------------------------------------------------------------------- /supershapeview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /supershapeview/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KingJA/SuperShapeView/3bed2fb4726c3133c830772b9bac9f50987c116a/supershapeview/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/core/ISuperShape.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.core; 2 | 3 | /** 4 | * Description:TODO 5 | * Create Time:2018/3/11 11:54 6 | * Author:KingJA 7 | * Email:kingjavip@gmail.com 8 | */ 9 | public interface ISuperShape { 10 | 11 | public void setSolidColor(int solidColor); 12 | 13 | public void setStrokeColor(int strokeColor); 14 | 15 | public void setStrokeWidth(int strokeWidth); 16 | 17 | public void setCorner(float corner); 18 | 19 | public void setDashWidth(float dashWidth); 20 | 21 | public void setDashGap(float dashGap); 22 | 23 | public void setCorner(int leftTopCorner, int rightTopCorner, int rightBottomCorner, int leftBottomCorner); 24 | } 25 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/core/SuperConfig.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.core; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Description:TODO 7 | * Create Time:2018/3/11 17:37 8 | * Author:KingJA 9 | * Email:kingjavip@gmail.com 10 | */ 11 | public class SuperConfig implements Serializable { 12 | public static final float DEFAULT_CORNER_RADIUS = 0f; 13 | public static final float DEFAULT_STROKE_WIDTH = 0f; 14 | public static final int DEFAULT_STROKE_COLOR = 0; 15 | public static final int DEFAULT_SOLID_COLOR = 0; 16 | public static final float DEFAULT_DASHWIDTH = 0f; 17 | public static final float DEFAULT_DASHGAP = 0f; 18 | public static final float DEFAULT_TOP_LEFT_RADIUS = 0f; 19 | public static final float DEFAULT_TOP_RIGHT_RADIUS = 0f; 20 | public static final float DEFAULT_BOTTOM_LEFT_RADIUS = 0f; 21 | public static final float DEFAULT_BOTTOM_IGHT_RADIUS = 0f; 22 | 23 | private float cornerRadius; 24 | private int strokeColor; 25 | private int solidColor; 26 | private int strokeWidth; 27 | private float dashWidth; 28 | private float dashGap; 29 | private float topLeftRadius; 30 | private float topRightRadius; 31 | private float bottomLeftRadius; 32 | private float bottomRightRadius; 33 | 34 | public float getCornerRadius() { 35 | return cornerRadius; 36 | } 37 | 38 | public void setCornerRadius(float cornerRadius) { 39 | this.cornerRadius = cornerRadius; 40 | } 41 | 42 | public int getStrokeColor() { 43 | return strokeColor; 44 | } 45 | 46 | public void setStrokeColor(int strokeColor) { 47 | this.strokeColor = strokeColor; 48 | } 49 | 50 | public int getSolidColor() { 51 | return solidColor; 52 | } 53 | 54 | public void setSolidColor(int solidColor) { 55 | this.solidColor = solidColor; 56 | } 57 | 58 | public int getStrokeWidth() { 59 | return strokeWidth; 60 | } 61 | 62 | public void setStrokeWidth(int strokeWidth) { 63 | this.strokeWidth = strokeWidth; 64 | } 65 | 66 | public float getDashWidth() { 67 | return dashWidth; 68 | } 69 | 70 | public void setDashWidth(float dashWidth) { 71 | this.dashWidth = dashWidth; 72 | } 73 | 74 | public float getDashGap() { 75 | return dashGap; 76 | } 77 | 78 | public void setDashGap(float dashGap) { 79 | this.dashGap = dashGap; 80 | } 81 | 82 | public float getTopLeftRadius() { 83 | return topLeftRadius; 84 | } 85 | 86 | public void setTopLeftRadius(float topLeftRadius) { 87 | this.topLeftRadius = topLeftRadius; 88 | } 89 | 90 | public float getTopRightRadius() { 91 | return topRightRadius; 92 | } 93 | 94 | public void setTopRightRadius(float topRightRadius) { 95 | this.topRightRadius = topRightRadius; 96 | } 97 | 98 | public float getBottomLeftRadius() { 99 | return bottomLeftRadius; 100 | } 101 | 102 | public void setBottomLeftRadius(float bottomLeftRadius) { 103 | this.bottomLeftRadius = bottomLeftRadius; 104 | } 105 | 106 | public float getBottomRightRadius() { 107 | return bottomRightRadius; 108 | } 109 | 110 | public void setBottomRightRadius(float bottomRightRadius) { 111 | this.bottomRightRadius = bottomRightRadius; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/core/SuperManager.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.core; 2 | 3 | import android.content.res.TypedArray; 4 | import android.graphics.Canvas; 5 | import android.os.Parcel; 6 | import android.os.Parcelable; 7 | import android.util.AttributeSet; 8 | import android.util.TypedValue; 9 | import android.view.View; 10 | 11 | import com.kingja.supershapeview.R; 12 | import com.kingja.supershapeview.shape.CommonShape; 13 | import com.kingja.supershapeview.shape.IBuilder; 14 | import com.kingja.supershapeview.shape.ImageShape; 15 | 16 | /** 17 | * Description:TODO 18 | * Create Time:2017/7/7 15:49 19 | * Author:KingJA 20 | * Email:kingjavip@gmail.com 21 | */ 22 | public class SuperManager implements ISuperShape { 23 | private View view; 24 | private SuperConfig superConfig; 25 | private IBuilder builder; 26 | 27 | public SuperManager(AttributeSet attrs, View view) { 28 | this.view = view; 29 | obtainAttrs(attrs); 30 | } 31 | 32 | public void beSuperView() { 33 | builder = new CommonShape(view); 34 | setSuperConfig(superConfig); 35 | } 36 | 37 | public void beSuperImageView() { 38 | builder = new ImageShape(view); 39 | setSuperConfig(superConfig); 40 | } 41 | 42 | private void obtainAttrs(AttributeSet attrs) { 43 | TypedArray typedArray = view.getContext().obtainStyledAttributes(attrs, R.styleable.SuperShapeView); 44 | superConfig = new SuperConfig(); 45 | superConfig.setCornerRadius(typedArray.getDimension(R.styleable.SuperShapeView_super_cornerRadius, 46 | SuperConfig.DEFAULT_CORNER_RADIUS)); 47 | superConfig.setStrokeColor(typedArray.getColor(R.styleable.SuperShapeView_super_strokeColor, 48 | SuperConfig.DEFAULT_STROKE_COLOR)); 49 | superConfig.setSolidColor(typedArray.getColor(R.styleable.SuperShapeView_super_solidColor, 50 | SuperConfig.DEFAULT_SOLID_COLOR)); 51 | superConfig.setStrokeWidth((int) typedArray.getDimension(R.styleable.SuperShapeView_super_strokeWidth, 52 | SuperConfig.DEFAULT_STROKE_WIDTH)); 53 | superConfig.setDashWidth(typedArray.getDimension(R.styleable.SuperShapeView_super_dashWidth, 54 | SuperConfig.DEFAULT_DASHWIDTH)); 55 | superConfig.setDashGap(typedArray.getDimension(R.styleable.SuperShapeView_super_dashGap, SuperConfig 56 | .DEFAULT_DASHGAP)); 57 | superConfig.setTopLeftRadius(typedArray.getDimension(R.styleable.SuperShapeView_super_topLeftRadius, 58 | SuperConfig.DEFAULT_TOP_LEFT_RADIUS)); 59 | superConfig.setTopRightRadius(typedArray.getDimension(R.styleable.SuperShapeView_super_topRightRadius, 60 | SuperConfig.DEFAULT_TOP_RIGHT_RADIUS)); 61 | superConfig.setBottomLeftRadius(typedArray.getDimension(R.styleable.SuperShapeView_super_bottomLeftRadius, 62 | SuperConfig.DEFAULT_BOTTOM_LEFT_RADIUS)); 63 | superConfig.setBottomRightRadius(typedArray.getDimension(R.styleable.SuperShapeView_super_bottomRightRadius, 64 | SuperConfig.DEFAULT_BOTTOM_IGHT_RADIUS)); 65 | typedArray.recycle(); 66 | } 67 | 68 | 69 | private int dp2px(float dp) { 70 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, view.getContext().getResources() 71 | .getDisplayMetrics()); 72 | } 73 | 74 | @Override 75 | public void setSolidColor(int solidColor) { 76 | superConfig.setSolidColor(solidColor); 77 | builder.modifyAttr(); 78 | } 79 | 80 | @Override 81 | public void setStrokeColor(int strokeColor) { 82 | superConfig.setStrokeColor(strokeColor); 83 | builder.modifyAttr(); 84 | } 85 | 86 | @Override 87 | public void setStrokeWidth(int strokeWidth) { 88 | superConfig.setStrokeWidth(dp2px(strokeWidth)); 89 | builder.modifyAttr(); 90 | } 91 | 92 | @Override 93 | public void setCorner(float corner) { 94 | superConfig.setCornerRadius(dp2px(corner)); 95 | builder.modifyAttr(); 96 | } 97 | 98 | @Override 99 | public void setDashWidth(float dashWidth) { 100 | superConfig.setDashWidth(dp2px(dashWidth)); 101 | builder.modifyAttr(); 102 | } 103 | 104 | @Override 105 | public void setDashGap(float dashGap) { 106 | superConfig.setDashGap(dp2px(dashGap)); 107 | builder.modifyAttr(); 108 | } 109 | 110 | @Override 111 | public void setCorner(int topLeftRadius, int topRightRadius, int bottomRightRadius, int bottomLeftRadius) { 112 | if (topLeftRadius != SuperConfig.DEFAULT_CORNER_RADIUS || topRightRadius != SuperConfig.DEFAULT_CORNER_RADIUS 113 | || bottomRightRadius != SuperConfig.DEFAULT_CORNER_RADIUS || bottomLeftRadius != SuperConfig 114 | .DEFAULT_CORNER_RADIUS) { 115 | superConfig.setCornerRadius(0); 116 | } 117 | superConfig.setTopLeftRadius(topLeftRadius); 118 | superConfig.setTopRightRadius(topRightRadius); 119 | superConfig.setBottomLeftRadius(bottomLeftRadius); 120 | superConfig.setBottomRightRadius(bottomRightRadius); 121 | builder.modifyAttr(); 122 | } 123 | 124 | private void restore(SuperConfig superConfig) { 125 | this.superConfig = superConfig; 126 | setSuperConfig(superConfig); 127 | } 128 | 129 | public Parcelable onSaveInstanceState(Parcelable superState) { 130 | SavedState ss = new SavedState(superState); 131 | ss.superConfig = superConfig; 132 | return ss; 133 | } 134 | 135 | public Parcelable onRestoreInstanceState(Parcelable state) { 136 | SavedState ss = (SavedState) state; 137 | restore(ss.superConfig); 138 | return ss.getSuperState(); 139 | } 140 | 141 | public void buildShape(Canvas canvas) { 142 | builder.buildShape(canvas); 143 | } 144 | 145 | public void setSuperConfig(SuperConfig superConfig) { 146 | builder.setSuperConfig(superConfig); 147 | } 148 | 149 | static class SavedState extends View.BaseSavedState { 150 | SuperConfig superConfig; 151 | 152 | SavedState(Parcelable superState) { 153 | super(superState); 154 | } 155 | 156 | private SavedState(Parcel in) { 157 | super(in); 158 | superConfig = (SuperConfig) in.readSerializable(); 159 | } 160 | 161 | @Override 162 | public void writeToParcel(Parcel out, int flags) { 163 | super.writeToParcel(out, flags); 164 | out.writeSerializable(superConfig); 165 | } 166 | 167 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 168 | @Override 169 | public SavedState createFromParcel(Parcel in) { 170 | return new SavedState(in); 171 | } 172 | 173 | @Override 174 | public SavedState[] newArray(int size) { 175 | return new SavedState[size]; 176 | } 177 | }; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/shape/CommonShape.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.shape; 2 | 3 | import android.graphics.Canvas; 4 | import android.graphics.drawable.GradientDrawable; 5 | import android.view.View; 6 | 7 | import com.kingja.supershapeview.core.SuperConfig; 8 | 9 | /** 10 | * Description:TODO 11 | * Create Time:2018/3/12 16:08 12 | * Author:KingJA 13 | * Email:kingjavip@gmail.com 14 | */ 15 | public class CommonShape implements IBuilder { 16 | private View view; 17 | private SuperConfig superConfig; 18 | 19 | public CommonShape(View view) { 20 | this.view = view; 21 | } 22 | 23 | @Override 24 | public void buildShape(Canvas canvas) { 25 | GradientDrawable mGradientDrawable = new GradientDrawable(); 26 | mGradientDrawable.setColor(superConfig.getSolidColor()); 27 | mGradientDrawable.setStroke(superConfig.getStrokeWidth(), superConfig.getStrokeColor(), superConfig 28 | .getDashWidth(), superConfig.getDashGap()); 29 | float[] radius = {superConfig.getTopLeftRadius(), superConfig.getTopLeftRadius(), superConfig 30 | .getTopRightRadius(), superConfig.getTopRightRadius(), superConfig.getBottomRightRadius(), 31 | superConfig.getBottomRightRadius(), superConfig.getBottomLeftRadius(), superConfig 32 | .getBottomLeftRadius()}; 33 | if (superConfig.getCornerRadius() == SuperConfig.DEFAULT_CORNER_RADIUS) { 34 | mGradientDrawable.setCornerRadii(radius); 35 | } else { 36 | mGradientDrawable.setCornerRadius(superConfig.getCornerRadius()); 37 | } 38 | view.setBackground(mGradientDrawable); 39 | } 40 | 41 | @Override 42 | public void setSuperConfig(SuperConfig superConfig) { 43 | this.superConfig = superConfig; 44 | } 45 | 46 | @Override 47 | public void modifyAttr() { 48 | buildShape(null); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/shape/IBuilder.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.shape; 2 | 3 | import android.graphics.Canvas; 4 | 5 | import com.kingja.supershapeview.core.SuperConfig; 6 | 7 | /** 8 | * Description:TODO 9 | * Create Time:2018/3/12 15:50 10 | * Author:KingJA 11 | * Email:kingjavip@gmail.com 12 | */ 13 | public interface IBuilder { 14 | public void buildShape( Canvas canvas); 15 | 16 | public void setSuperConfig(SuperConfig superConfig); 17 | 18 | public void modifyAttr(); 19 | } 20 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/shape/ImageShape.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.shape; 2 | 3 | import android.graphics.Bitmap; 4 | import android.graphics.BitmapShader; 5 | import android.graphics.Canvas; 6 | import android.graphics.DashPathEffect; 7 | import android.graphics.Paint; 8 | import android.graphics.Path; 9 | import android.graphics.PathEffect; 10 | import android.graphics.RectF; 11 | import android.graphics.Shader; 12 | import android.graphics.drawable.BitmapDrawable; 13 | import android.graphics.drawable.ColorDrawable; 14 | import android.graphics.drawable.Drawable; 15 | import android.view.View; 16 | import android.widget.ImageView; 17 | 18 | import com.kingja.supershapeview.core.SuperConfig; 19 | 20 | /** 21 | * Description:TODO 22 | * Create Time:2018/3/12 15:49 23 | * Author:KingJA 24 | * Email:kingjavip@gmail.com 25 | */ 26 | public class ImageShape implements IBuilder { 27 | private final ImageView imageView; 28 | private SuperConfig superConfig; 29 | 30 | @Override 31 | public void setSuperConfig(SuperConfig superConfig) { 32 | this.superConfig = superConfig; 33 | } 34 | 35 | @Override 36 | public void modifyAttr() { 37 | imageView.invalidate(); 38 | } 39 | 40 | public ImageShape(View view) { 41 | this.imageView = (ImageView) view; 42 | } 43 | 44 | private Paint getStrokePaint() { 45 | Paint strokePaint = new Paint(Paint.ANTI_ALIAS_FLAG); 46 | strokePaint.setStyle(Paint.Style.STROKE); 47 | strokePaint.setColor(superConfig.getStrokeColor()); 48 | strokePaint.setStrokeWidth(superConfig.getStrokeWidth()); 49 | PathEffect effects = new DashPathEffect(new float[]{superConfig.getDashWidth(), superConfig.getDashGap(), 50 | superConfig.getDashWidth(), superConfig.getDashGap()}, 0); 51 | strokePaint.setPathEffect(effects); 52 | return strokePaint; 53 | } 54 | 55 | private RectF getRectF() { 56 | int borderOffset = (int) (superConfig.getStrokeWidth() * 0.5f); 57 | RectF rectF = new RectF(); 58 | rectF.set(borderOffset, borderOffset, imageView.getMeasuredWidth() - borderOffset, imageView 59 | .getMeasuredHeight() - borderOffset); 60 | return rectF; 61 | } 62 | 63 | private Paint getShaderPaint() { 64 | Bitmap mBitmap = drawableToBitmap(imageView.getDrawable()); 65 | BitmapShader mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); 66 | Paint mBitmapPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 67 | mBitmapShader.setLocalMatrix(imageView.getImageMatrix()); 68 | mBitmapPaint.setShader(mBitmapShader); 69 | return mBitmapPaint; 70 | } 71 | 72 | private Bitmap drawableToBitmap(Drawable drawable) { 73 | if (drawable instanceof BitmapDrawable) { 74 | return ((BitmapDrawable) drawable).getBitmap(); 75 | } 76 | Bitmap bitmap; 77 | try { 78 | if (drawable instanceof ColorDrawable) { 79 | bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888); 80 | } else { 81 | int width = drawable.getIntrinsicWidth(); 82 | int height = drawable.getIntrinsicHeight(); 83 | bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 84 | } 85 | Canvas canvas = new Canvas(bitmap); 86 | drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); 87 | drawable.draw(canvas); 88 | } catch (Exception e) { 89 | e.printStackTrace(); 90 | bitmap = null; 91 | } 92 | return bitmap; 93 | } 94 | 95 | private Path getPath() { 96 | Path path = new Path(); 97 | float[] radius = {superConfig.getTopLeftRadius(), superConfig.getTopLeftRadius(), superConfig 98 | .getTopRightRadius(), superConfig.getTopRightRadius(), superConfig.getBottomRightRadius(), 99 | superConfig.getBottomRightRadius(), superConfig.getBottomLeftRadius(), superConfig 100 | .getBottomLeftRadius()}; 101 | if (superConfig.getCornerRadius() == SuperConfig.DEFAULT_CORNER_RADIUS) { 102 | path.addRoundRect(getRectF(), radius, Path.Direction.CW); 103 | } else { 104 | path.addRoundRect(getRectF(), superConfig.getCornerRadius(), superConfig.getCornerRadius(), Path 105 | .Direction.CW); 106 | } 107 | return path; 108 | } 109 | 110 | @Override 111 | public void buildShape(Canvas canvas) { 112 | canvas.drawPath(getPath(), getShaderPaint()); 113 | if (superConfig.getStrokeWidth() > 0) { 114 | canvas.drawPath(getPath(), getStrokePaint()); 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/view/SuperShapeEditText.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.view; 2 | 3 | import android.content.Context; 4 | import android.os.Parcelable; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.widget.AppCompatEditText; 7 | import android.util.AttributeSet; 8 | 9 | import com.kingja.supershapeview.core.SuperManager; 10 | 11 | /** 12 | * Description:TODO 13 | * Create Time:2017/6/26 10:32 14 | * Author:KingJA 15 | * Email:kingjavip@gmail.com 16 | */ 17 | public class SuperShapeEditText extends AppCompatEditText { 18 | 19 | private SuperManager superManager; 20 | 21 | public SuperManager getSuperManager() { 22 | return superManager; 23 | } 24 | public SuperShapeEditText(Context context) { 25 | super(context); 26 | } 27 | 28 | public SuperShapeEditText(Context context, @Nullable AttributeSet attrs) { 29 | super(context, attrs); 30 | initSuperShapeView(attrs); 31 | } 32 | 33 | public SuperShapeEditText(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | initSuperShapeView(attrs); 36 | } 37 | 38 | private void initSuperShapeView(AttributeSet attrs) { 39 | superManager = new SuperManager(attrs, this); 40 | superManager.beSuperView(); 41 | } 42 | @Override 43 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 44 | super.onSizeChanged(w, h, oldw, oldh); 45 | superManager.buildShape(null); 46 | } 47 | 48 | @Override 49 | public Parcelable onSaveInstanceState() { 50 | return superManager.onSaveInstanceState(super.onSaveInstanceState()); 51 | } 52 | 53 | @Override 54 | public void onRestoreInstanceState(Parcelable state) { 55 | super.onRestoreInstanceState(superManager.onRestoreInstanceState(state)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/view/SuperShapeFrameLayout.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.view; 2 | 3 | import android.content.Context; 4 | import android.os.Parcelable; 5 | import android.support.annotation.Nullable; 6 | import android.util.AttributeSet; 7 | import android.widget.FrameLayout; 8 | 9 | import com.kingja.supershapeview.core.SuperManager; 10 | 11 | /** 12 | * Description:TODO 13 | * Create Time:2017/6/26 10:32 14 | * Author:KingJA 15 | * Email:kingjavip@gmail.com 16 | */ 17 | public class SuperShapeFrameLayout extends FrameLayout { 18 | private SuperManager superManager; 19 | 20 | public SuperManager getSuperManager() { 21 | return superManager; 22 | } 23 | 24 | public SuperShapeFrameLayout(Context context) { 25 | super(context); 26 | } 27 | 28 | public SuperShapeFrameLayout(Context context, @Nullable AttributeSet attrs) { 29 | super(context, attrs); 30 | initSuperShapeView(attrs); 31 | } 32 | 33 | public SuperShapeFrameLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | initSuperShapeView(attrs); 36 | } 37 | 38 | private void initSuperShapeView(AttributeSet attrs) { 39 | superManager = new SuperManager(attrs, this); 40 | superManager.beSuperView(); 41 | } 42 | 43 | @Override 44 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 45 | super.onSizeChanged(w, h, oldw, oldh); 46 | superManager.buildShape(null); 47 | } 48 | 49 | @Override 50 | public Parcelable onSaveInstanceState() { 51 | return superManager.onSaveInstanceState(super.onSaveInstanceState()); 52 | } 53 | 54 | @Override 55 | public void onRestoreInstanceState(Parcelable state) { 56 | super.onRestoreInstanceState(superManager.onRestoreInstanceState(state)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/view/SuperShapeImageView.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.view; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.os.Parcelable; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.widget.AppCompatImageView; 8 | import android.util.AttributeSet; 9 | import android.util.Log; 10 | 11 | import com.kingja.supershapeview.core.SuperManager; 12 | 13 | /** 14 | * Description:TODO 15 | * Create Time:2017/6/26 10:32 16 | * Author:KingJA 17 | * Email:kingjavip@gmail.com 18 | */ 19 | public class SuperShapeImageView extends AppCompatImageView { 20 | 21 | private SuperManager superManager; 22 | 23 | public SuperShapeImageView(Context context) { 24 | super(context); 25 | } 26 | 27 | public SuperShapeImageView(Context context, @Nullable AttributeSet attrs) { 28 | super(context, attrs); 29 | initSuperShapeView(attrs); 30 | } 31 | 32 | public SuperShapeImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 33 | super(context, attrs, defStyleAttr); 34 | initSuperShapeView(attrs); 35 | } 36 | 37 | private void initSuperShapeView(AttributeSet attrs) { 38 | superManager = new SuperManager(attrs, this); 39 | superManager.beSuperImageView(); 40 | 41 | } 42 | 43 | @Override 44 | protected void onDraw(Canvas canvas) { 45 | superManager.buildShape(canvas); 46 | } 47 | 48 | public SuperManager getSuperManager() { 49 | return superManager; 50 | } 51 | 52 | @Override 53 | public Parcelable onSaveInstanceState() { 54 | return superManager.onSaveInstanceState(super.onSaveInstanceState()); 55 | } 56 | 57 | @Override 58 | public void onRestoreInstanceState(Parcelable state) { 59 | super.onRestoreInstanceState(superManager.onRestoreInstanceState(state)); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/view/SuperShapeLinearLayout.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.view; 2 | 3 | import android.content.Context; 4 | import android.os.Parcelable; 5 | import android.support.annotation.Nullable; 6 | import android.util.AttributeSet; 7 | import android.widget.LinearLayout; 8 | 9 | import com.kingja.supershapeview.core.SuperManager; 10 | 11 | /** 12 | * Description:TODO 13 | * Create Time:2017/6/26 10:32 14 | * Author:KingJA 15 | * Email:kingjavip@gmail.com 16 | */ 17 | public class SuperShapeLinearLayout extends LinearLayout { 18 | private SuperManager superManager; 19 | 20 | public SuperManager getSuperManager() { 21 | return superManager; 22 | } 23 | 24 | public SuperShapeLinearLayout(Context context) { 25 | super(context); 26 | } 27 | 28 | public SuperShapeLinearLayout(Context context, @Nullable AttributeSet attrs) { 29 | super(context, attrs); 30 | initSuperShapeView(attrs); 31 | } 32 | 33 | public SuperShapeLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | initSuperShapeView(attrs); 36 | } 37 | 38 | private void initSuperShapeView(AttributeSet attrs) { 39 | superManager = new SuperManager(attrs, this); 40 | superManager.beSuperView(); 41 | } 42 | 43 | @Override 44 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 45 | super.onSizeChanged(w, h, oldw, oldh); 46 | superManager.buildShape(null); 47 | } 48 | 49 | @Override 50 | public Parcelable onSaveInstanceState() { 51 | return superManager.onSaveInstanceState(super.onSaveInstanceState()); 52 | } 53 | 54 | @Override 55 | public void onRestoreInstanceState(Parcelable state) { 56 | super.onRestoreInstanceState(superManager.onRestoreInstanceState(state)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/view/SuperShapeRelativeLayout.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.view; 2 | 3 | import android.content.Context; 4 | import android.os.Parcelable; 5 | import android.support.annotation.Nullable; 6 | import android.util.AttributeSet; 7 | import android.widget.RelativeLayout; 8 | 9 | import com.kingja.supershapeview.core.SuperManager; 10 | 11 | /** 12 | * Description:TODO 13 | * Create Time:2017/6/26 10:32 14 | * Author:KingJA 15 | * Email:kingjavip@gmail.com 16 | */ 17 | public class SuperShapeRelativeLayout extends RelativeLayout { 18 | private SuperManager superManager; 19 | 20 | public SuperManager getSuperManager() { 21 | return superManager; 22 | } 23 | 24 | public SuperShapeRelativeLayout(Context context) { 25 | super(context); 26 | } 27 | 28 | public SuperShapeRelativeLayout(Context context, @Nullable AttributeSet attrs) { 29 | super(context, attrs); 30 | initSuperShapeView(attrs); 31 | } 32 | 33 | public SuperShapeRelativeLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | initSuperShapeView(attrs); 36 | } 37 | 38 | private void initSuperShapeView(AttributeSet attrs) { 39 | superManager = new SuperManager(attrs, this); 40 | superManager.beSuperView(); 41 | } 42 | 43 | @Override 44 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 45 | super.onSizeChanged(w, h, oldw, oldh); 46 | superManager.buildShape(null); 47 | } 48 | 49 | @Override 50 | public Parcelable onSaveInstanceState() { 51 | return superManager.onSaveInstanceState(super.onSaveInstanceState()); 52 | } 53 | 54 | @Override 55 | public void onRestoreInstanceState(Parcelable state) { 56 | super.onRestoreInstanceState(superManager.onRestoreInstanceState(state)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /supershapeview/src/main/java/com/kingja/supershapeview/view/SuperShapeTextView.java: -------------------------------------------------------------------------------- 1 | package com.kingja.supershapeview.view; 2 | 3 | import android.content.Context; 4 | import android.os.Parcelable; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.widget.AppCompatTextView; 7 | import android.util.AttributeSet; 8 | 9 | import com.kingja.supershapeview.core.SuperManager; 10 | 11 | /** 12 | * Description:TODO 13 | * Create Time:2017/6/26 10:32 14 | * Author:KingJA 15 | * Email:kingjavip@gmail.com 16 | */ 17 | public class SuperShapeTextView extends AppCompatTextView { 18 | 19 | private SuperManager superManager; 20 | 21 | public SuperManager getSuperManager() { 22 | return superManager; 23 | } 24 | 25 | public SuperShapeTextView(Context context) { 26 | super(context); 27 | } 28 | 29 | public SuperShapeTextView(Context context, @Nullable AttributeSet attrs) { 30 | super(context, attrs); 31 | initSuperShapeView(attrs); 32 | } 33 | 34 | public SuperShapeTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 35 | super(context, attrs, defStyleAttr); 36 | initSuperShapeView(attrs); 37 | } 38 | 39 | private void initSuperShapeView(AttributeSet attrs) { 40 | superManager = new SuperManager(attrs, this); 41 | superManager.beSuperView(); 42 | } 43 | 44 | @Override 45 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 46 | super.onSizeChanged(w, h, oldw, oldh); 47 | superManager.buildShape(null); 48 | } 49 | 50 | @Override 51 | public Parcelable onSaveInstanceState() { 52 | return superManager.onSaveInstanceState(super.onSaveInstanceState()); 53 | } 54 | 55 | @Override 56 | public void onRestoreInstanceState(Parcelable state) { 57 | super.onRestoreInstanceState(superManager.onRestoreInstanceState(state)); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /supershapeview/src/main/res/values/attr.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /supershapeview/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3489FF 4 | -------------------------------------------------------------------------------- /supershapeview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SuperShapeView 3 | 4 | --------------------------------------------------------------------------------