Skip to content

Commit

Permalink
fix touch event
Browse files Browse the repository at this point in the history
  • Loading branch information
zcweng committed Dec 24, 2016
1 parent 5f19802 commit c0ed487
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 109 deletions.
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2016 https://github.com/zcweng/SwitchButton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60 changes: 36 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,53 @@
# SwitchButton
具有与IOS开关控件相似样式的Android控件
-------
SwitchButton.具有与IOS开关控件相似样式和行为的Android控件


```
<attr name="sb_shadow_radius" format="reference|dimension"/> 阴影半径
<attr name="sb_shadow_offset" format="reference|dimension"/> 阴影偏移
<attr name="sb_shadow_color" format="reference|color"/> 阴影颜色
<attr name="sb_uncheck_color" format="reference|color"/> 关闭颜色
<attr name="sb_checked_color" format="reference|color"/> 开启颜色
<attr name="sb_border_width" format="reference|dimension"/> 边框宽度
<attr name="sb_checkline_color" format="reference|color"/> 开启指示器颜色
<attr name="sb_checkline_width" format="reference|dimension"/>开启指示器线宽
<attr name="sb_uncheckcircle_color" format="reference|color"/>关闭指示器颜色
<attr name="sb_uncheckcircle_width" format="reference|dimension"/>关闭指示器线宽
<attr name="sb_uncheckcircle_radius" format="reference|dimension"/>关闭指示器半径
<attr name="sb_checked" format="reference|boolean"/> 是否选中
<attr name="sb_shadow_effect" format="reference|boolean"/> 是否启用阴影
<attr name="sb_effect_duration" format="reference|integer"/> 动画时间,默认300ms
<attr name="sb_button_color" format="reference|color"/> 按钮颜色
<attr name="sb_show_indicator" format="reference|boolean"/> 是否显示指示器,默认true:显示
<attr name="sb_background" format="reference|color"/> 背景色,默认白色
<attr name="sb_enable_effect" format="reference|boolean"/> 是否启用特效,默认true
<attr name="sb_shadow_radius" format="reference|dimension"/> 阴影半径
<attr name="sb_shadow_offset" format="reference|dimension"/> 阴影偏移
<attr name="sb_shadow_color" format="reference|color"/> 阴影颜色
<attr name="sb_uncheck_color" format="reference|color"/> 关闭颜色
<attr name="sb_checked_color" format="reference|color"/> 开启颜色
<attr name="sb_border_width" format="reference|dimension"/> 边框宽度
<attr name="sb_checkline_color" format="reference|color"/> 开启指示器颜色
<attr name="sb_checkline_width" format="reference|dimension"/> 开启指示器线宽
<attr name="sb_uncheckcircle_color" format="reference|color"/> 关闭指示器颜色
<attr name="sb_uncheckcircle_width" format="reference|dimension"/> 关闭指示器线宽
<attr name="sb_uncheckcircle_radius" format="reference|dimension"/>关闭指示器半径
<attr name="sb_checked" format="reference|boolean"/> 是否选中
<attr name="sb_shadow_effect" format="reference|boolean"/> 是否启用阴影
<attr name="sb_effect_duration" format="reference|integer"/> 动画时间,默认300ms
<attr name="sb_button_color" format="reference|color"/> 按钮颜色
<attr name="sb_show_indicator" format="reference|boolean"/> 是否显示指示器,默认true:显示
<attr name="sb_background" format="reference|color"/> 背景色,默认白色
<attr name="sb_enable_effect" format="reference|boolean"/> 是否启用特效,默认true
SwitchButton switchButton = (SwitchButton) findViewById(R.id.switch_button);
switchButton.setChecked(true);
switchButton.isChecked();
switchButton.toggle(); //切换开关
switchButton.toggle(false);//无动画切换
//禁用按钮
switchButton.setEnabled(false);
switchButton.setOnCheckedChangeListener(new SwitchButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(SwitchButton view, boolean isChecked) {
//TODO do your job
}
});
//禁用按钮
switchButton.setEnabled(false);
```


<img src="21879.gif" style="max-width:212px;height:182px;" />
<img src="device-capture.png" style="max-width:480px;height:auto;" />




License
-------
MIT, See the <a href="https://github.com/zcweng/SwitchButton/LICENSE">[LICENSE]</a> file for details.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ buildscript {

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// classpath 'com.novoda:bintray-release:0.4.0'
}
}

Expand Down
Binary file modified device-capture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
119 changes: 116 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
//apply plugin: 'com.novoda.bintray-release'

def MODULE_NAME = "SwitchButton"
def VERSION_CODE = 1
def VERSION_NAME = "0.0.1"

android {
compileSdkVersion 23
Expand All @@ -7,15 +14,121 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 23
versionCode VERSION_CODE
versionName VERSION_NAME
}

sourceSets {
main {
}
lintOptions {
abortOnError false
}

}

dependencies{

}


def SITE_URL = "https://github.com/zcweng/SwitchButton"
def GIT_URL = "https://github.com/zcweng/SwitchButton.git"
def ISSUE_URL = "https://github.com/zcweng/SwitchButton/issues"
def LICENSE_URL = "https://github.com/zcweng/SwitchButton/LICENSE"
def DESCRIPTION = "SwitchButton.具有与IOS开关控件相似样式和行为的Android控件"
group = "com.suke.widget"

//Properties properties = new Properties()
//properties.load(project.rootProject.file('local.properties').newDataInputStream())
//publish {
// userOrg = properties.getProperty("bintray.user")
// groupId = group
// artifactId = MODULE_NAME
// publishVersion = VERSION_NAME
// desc = DESCRIPTION
// website = SITE_URL
//}


install {
repositories.mavenInstaller {
pom {
project {
packaging 'aar'
name DESCRIPTION
url SITE_URL
licenses {
license {
name 'The MIT License (MIT)'
url LICENSE_URL
}
}
developers {
developer {
id 'suke'
name 'suke'
email 'zhouchangwen@gmail.com'
}
}
scm {
connection GIT_URL
developerConnection GIT_URL
url SITE_URL
}
}
}
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}


Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def BINTRAY_USER = properties.getProperty("bintray.user")
def BINTRAY_KEY = properties.getProperty("bintray.apikey")

bintray {
user = BINTRAY_USER
key = BINTRAY_KEY
configurations = ['archives']
filesSpec {
from 'build/libs'
into 'standalone_files/level1'
}
dryRun = false
publish = true
override = true
pkg {
repo = "maven"
name = "switch-button"
desc = DESCRIPTION
websiteUrl = SITE_URL
vcsUrl = GIT_URL
userOrg = BINTRAY_USER
issueTrackerUrl = ISSUE_URL
licenses = ["MIT"]
labels = ['android'] //标签
publish = true
publicDownloadNumbers = true
}
version {
name = VERSION_NAME
desc = DESCRIPTION
released = new Date()
vcsTag = VERSION_NAME
attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
}
}
Loading

0 comments on commit c0ed487

Please sign in to comment.