diff --git a/.gitignore b/.gitignore index b0fce84..7654e9d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,3 @@ hs_err_pid* bin/ gen/ .DS_Store - -SwitchButton/gradle.properties diff --git a/CHANGELOG.md b/CHANGELOG.md index ee5632a..18a269c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,112 @@ + Change Log ============ [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SwitchButton-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1119) -**To get a quick preview, you can find the Demo in [Google Play](https://play.google.com/store/apps/details?id=com.kyleduo.switchbutton.demo) or [My Blog](http://kyleduo.com/project/switchbutton/switchbutton_demo_140.apk).** +**To get a quick preview, you can find Demo apk in [Google Play](https://play.google.com/store/apps/details?id=com.kyleduo.switchbutton.demo) or [Directly download](./demo/switchbutton_demo_141.apk).** This project provides you a convenient way to use and customise a SwitchButton widget in Android. With just resources changed and attrs set, you can create a lifelike SwitchButton of Android 5.0+, iOS, MIUI, or Flyme and so on. Now we get the biggest movement since SwitchButton published. v1.3.0 comes with totally reconsitution and more convenient API. A wholly new demo can give you a tour in it. - *** -update 1.4.0 (Latest) + +## 2.1.0 (Latest) + +**ENG** + +1. Migrate to maven central + + +**CHN** + +1. 迁移到 maven central + +## 2.0.3 + +**ENG** + +1. Fix [#103](https://github.com/kyleduo/SwitchButton/issues/103). Determin whether state change is triggered manully using `isPressed` in OnCheckedChangeListener is supported. +2. Remove targetSdkVersion declaration. +3. Upgrate compileSdkVersion to 29. + +**CHN** + +1. 修复 [#103](https://github.com/kyleduo/SwitchButton/issues/103)。支持在OnCheckedChangeListener中使用`isPressed`判断是否是手动触发。 +2. 移除targetSdkVersion声明 +3. 更新compileSdkVersion到29 + +## 2.0.2 + +**ENG** + +1. Fix [#122](https://github.com/kyleduo/SwitchButton/issues/122). Support sub-class extending from SwitchButton. +2. Fix bug which move faster than expected while touch and move vertically. +3. Remove dependency of AppCompat library. + + +**CHN** + +1. 修复 [#122](https://github.com/kyleduo/SwitchButton/issues/122)。支持从SwitchButton集成子类。 +2. 修复纵向滑动导致移动过快的Bug。 +3. 移除对AppCompat库的依赖。 + + +## 2.0.0 + +**ENG** + +1. Re-clarify the meaning of some params. +2. Update the measurement of SwitchButton and the logic becomes more clear, especially the text part. +3. Support config SwitchButton's size by setting a exact width and height. There are now TWO mainly method to control it's size. + + +**CHN** + +1. 重新明确了参数的含义。 +2. 更新了SwitchButton的测量机制,逻辑更加清晰;尤其是文字部分。 +3. 支持设置确定的宽高,来确定SwitchButton的View大小。现在有两种方式可以控制SwitchButton的大小了。 + + + +## 1.4.6 + +- Fixed [#89](https://github.com/kyleduo/SwitchButton/issues/89) . + +## 1.4.5 + +- Fixed [#75](https://github.com/kyleduo/SwitchButton/issues/75) [#78](https://github.com/kyleduo/SwitchButton/issues/78) [#85](https://github.com/kyleduo/SwitchButton/issues/85). + + + +1.4.4 +--- + +* Fixed [#65](https://github.com/kyleduo/SwitchButton/issues/65). +* Update text layout, tests looks like center. + + +1.4.3 +--- + +* Fixed [#64](https://github.com/kyleduo/SwitchButton/issues/64). Respect to clickable and focusable attributes. + + +1.4.2 +--- + +* Support [#49](https://github.com/kyleduo/SwitchButton/issues/60). By default SwitchButton found accentColor of your theme for tintColor. (**accentColor** is used for controls according to [Material Design guideline](https://material.google.com/style/color.html#color-color-schemes). ) + + +1.4.1 +--- + +* fixed [#49](https://github.com/kyleduo/SwitchButton/issues/49). +* Support operation without onCheckedChanged callback. + + +1.4.0 --- * Add text feature. You can set text for either checked or unchecked status with __kswTextOn__ and __kswTextOff__ attrs. And you can set the margin of text in horizontal direction using __kswTextMarginH__ attr. @@ -19,91 +114,103 @@ update 1.4.0 (Latest) * Thanks [@lpmfilho](https://github.com/lpmfilho) *** -update 1.3.4 + +1.3.4 --- * Fix [#40](https://github.com/kyleduo/SwitchButton/issues/40) *** -update 1.3.3 + +1.3.3 --- * Fix SwitchButtonMD style bug in RecyclerView and add page for test. -* Fix bug in setCheckedImmediately() in onCheckedChanged() method. **(setChecked in onChecked)** + *Fix bug in setCheckedImmediately() in onCheckedChanged() method. **(setChecked in onChecked)** *** -update 1.3.2 + +1.3.2 --- * **setClickable(boolean)** support. -* Bug fix. + * Bug fix. *** -update 1.3.1 + +1.3.1 --- * Remove shadow of MD style to support under 5.0. *** -update 1.3.0 + +1.3.0 --- * Reconstructe the whole library. -* More convenient customization way by __tintColor__. -* New design demo. All APIs in ONE. -* Fix issue [#23](https://github.com/kyleduo/SwitchButton/issues/23) [#25](https://github.com/kyleduo/SwitchButton/issues/25) [#26](https://github.com/kyleduo/SwitchButton/issues/26) -* Just exciting!!! + * More convenient customization way by __tintColor__. + * New design demo. All APIs in ONE. + *Fix issue [#23](https://github.com/kyleduo/SwitchButton/issues/23) [#25](https://github.com/kyleduo/SwitchButton/issues/25) [#26](https://github.com/kyleduo/SwitchButton/issues/26) + *Just exciting!!! *** -update 1.2.10 + +1.2.10 --- * Fix issue [#22](https://github.com/kyleduo/SwitchButton/issues/22) by change the attributes' name to prevent conflict; *** -update 1.2.9 +1.2.9 --- * Fix issue [#19](https://github.com/kyleduo/SwitchButton/issues/19). *** -update 1.2.8 + +1.2.8 --- * Fix stretch bug while using higher API. -* Add Gradle support. -* Built in Android Studio. + *Add Gradle support. + *Built in Android Studio. *** -update 1.2.7 + +1.2.7 --- * Fix rendering bug on some devices. -* Fix states bug. + *Fix states bug. *** -update 1.2.6 + +1.2.6 --- * With calling the method ___setChecked(boolean, false);___, you can change the status without invoking the listener. *** -update 1.2.5 + +1.2.5 --- * Fix shrink bug in Android 5.0 (the problem is same like it is in Android 4.4, which has been fixed in 1.2.4). -* More available to setup Material Design style SwitchButton using ___@style/MD___ in xml layout. -* Fix Demo Project bug + *More available to setup Material Design style SwitchButton using ___@style/MD___ in xml layout. + *Fix Demo Project bug *** -update 1.2.4 + +1.2.4 --- * fix shrink bug(that will cause the content out of bounds not disapper, on Android 4.4) * upload .pad resource, whitch I forgot to upload before.(My fault.) *** -update 1.2.3 + +1.2.3 --- * bug fix * upgrade demo apk @@ -121,7 +228,8 @@ When toggle, call ___toggle();___ with change the status immediately and ___togg ![easy_to_use](https://raw.githubusercontent.com/kyleduo/SwitchButton/master/preview/easy_to_use_128.png) *** -update 1.2 + +1.2 --- (11/08/2014) @@ -142,7 +250,8 @@ To use shrink feature, you can easily add these attributes in your xml file. It *** -update 1.1 + +1.1 --- (10/08/2014) @@ -161,6 +270,7 @@ new default style and demo apk looks like this: *** -Update 1.0 + +1.0 --- -Add an attr of radius, now you can change the radius when configure the button's face! \ No newline at end of file +Add an attr of radius, now you can change the radius when configure the button's face! diff --git a/README.md b/README.md index 98f3a7f..a55840a 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,113 @@ + SwitchButton ============ [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-SwitchButton-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1119) -**To get a quick preview, you can find the Demo in [Google Play](https://play.google.com/store/apps/details?id=com.kyleduo.switchbutton.demo) or [My Blog](http://kyleduo.com/project/switchbutton/switchbutton_demo_140.apk).** - -This project provides you a convenient way to use and customise a SwitchButton widget in Android. With just resources changed and attrs set, you can create a lifelike SwitchButton of Android 5.0+, iOS, MIUI, or Flyme and so on. +**To get a quick preview, you can get Demo apk in [Google Play](https://play.google.com/store/apps/details?id=com.kyleduo.switchbutton.demo) or [Directly download](./demo/switchbutton_demo_200.apk).** -Now we get the biggest movement since SwitchButton published. v1.3.0 comes with totally reconsitution and more convenient API. A wholly new demo can give you a tour in it. +This project provides you a convenient way to use and customise a SwitchButton widget in Android. *** + + Change Log --- -[Change Log 1.4.0](https://github.com/kyleduo/SwitchButton/blob/master/CHANGELOG.md) + +[All Change Log](./CHANGELOG.md) + +**Some attributes are changed in 2.0.0 and you need to update them to the new ones, since the measurement logic has been totally changed. (Default behavior and style does not change.)** + +**因为2.0.0测量逻辑的改变,部分属性已经做了修改,请更新到新的属性。(默认行为和样式并没有变化)** + +> 1. Re-clarify the meaning of some params. +> 2. Update the measurement of SwitchButton and the logic becomes more clear, especially the text part. +> 3. Support config SwitchButton's size by setting a exact width and height. There are now TWO mainly method to control it's size. +> 4. When use SwitchButon in a scrollable view, SwitchButton consume scroll gestures only horizontal. This means the when you want to scroll the scrollable view vertically and start your touch on a SwitchButton, it will not stop you now. +> 5. Bug fix. + +>1. 重新明确了参数的含义。 +>2. 更新了SwitchButton的测量机制,逻辑更加清晰;尤其是文字部分。 +>3. 支持设置确定的宽高,来确定SwitchButton的View大小。现在有两种方式可以控制SwitchButton的大小了。 +>4. 可滚动的View中的SwitchButton只会消费横向滚动事件。这意味着你可以从SwitchButton开始按下并纵向滚动可滚动View,SwitchButton现在不会阻止你滚动了。 +>5. Bug 修复。 + Using SwitchButton in your application --- -~~ADT~~ - No more support - -__Gradle__ - +**In Gradle** +​ Add dependencies in build.gradle of your module - dependencies { - compile 'com.kyleduo.switchbutton:library:1.4.0' - } +```groovy +dependencies { + implementation 'com.kyleduo.switchbutton:library:2.1.0' +} +``` + +> Version 2.1.0 can be pulled from `mavenCentral()` + +#### Migrate to 2.0.0 (迁移到2.0.0) + +**ENG** + +**There is a big diagram below to show how SwitchButton measure it self in 2.0.0. It is strongly recommended that you should check it out.** + +1. **kswBackMeasureRatio** has been removed from SwitchButton attributes since it has an ambiguous meaning. I've add the new **kswThumbRangeRatio** attribute to represent how much multiple the scroll range of thumb than the width of thumb. +2. **kswTextMarginH** and **kswAutoAdjustTextPosition** have been removed from SwitchButton attributes since I updated the measurement logic of text part. And these two attributes do not represent the back meaning well. **kswTextThumbInset**, **kswTextExtra** and **kswTextAdjust** was introduced to represent "how much the text go under thumb", "how much extra space do you want around the text" and "how much to move the text from the center of text area to adjust the text's position". There are all shown on the diagram. +3. Setters and getters are also changed due to the change of attributes. + +**CHN** + +下面有一张图表来解释SwitchButton在2.0.0版本中是如何进行测量的,非常建议你看一看。 + +1. **kswBackMeasureRatio** 属性被移除了,因为名称有歧义。新增加的 **kswThumbRangeRatio** 属性表示thumb移动区域和thumb宽度的比值。 +2. **kswTextMarginH** 和 **kswAutoAdjustTextPosition** 属性被移除了,因为我更新了对文字的测量逻辑,而且这两个属性名称表意不明确。我增加了**kswTextThumbInset**, **kswTextExtra** 和 **kswTextAdjust** 这三个新属性来分别表示“文字在thumb下面的距离”,“额外文字空间”和”文字调节距离“。这些都在图表中有所体现。 +3. setter和getter都跟随属性名称的改变而进行了改变。 + +### Diagram: How SwitchButton Measure + +This diagram shows how SwitchButton measure itself and what does those nouns mean. To measure width is much complex than the height, so if you know how to measure width, you know how to measure height. And text measurement and location increase the complexity. + +![demo_preview](./images/how_switchbutton_measure.png) + *** + + Demo --- I create a new demo apk to show you how to style the cute widget and use it. There's some screenshots of the new demo. -![demo_preview](./preview/demo_140.jpg) +![demo_preview](./images/demo_preview.png) *** + + Usage --- -The usage of SwitchButton is just like CheckBox. Since SwitchButton has addition animation when checked status changed, there are two addition methods for disable animation for single operation. +The usage of SwitchButton is just like CheckBox. The basic control APIs of SwitchButton. + +* __setChecked(boolean)__ +* __toggle()__ -* __setCheckedImmediatelay(boolean)__: like setChecked but NO animation. +Since SwitchButton has addition animation when checked status changed, there are two addition methods for disable animation for single operation. + +* __setCheckedImmediately(boolean)__: like setChecked but NO animation. * __toggleImmediately()__: like toggle but NO animation. +From **version 1.4.1** on, SwitchButton support operation without onCheckedChanged callback. It makes changing state in code more convenient. Using these methods to achieve that feature. + + +* __setCheckedNoEvent(boolean)__ +* __setCheckedImmediatelyNoEvent(boolean)__ +* __toggleNoEvent()__ +* __toggleImmediatelyNoEvent()__ + *** + + Style --- @@ -65,16 +129,21 @@ In __xml__ layout file, you can configure the face of switch button using these * __kswBackDrawable__: drawable for background * __kswBackColor__: color for background * __kswFadeBack__: fade background color/drawable when drag or animate between on/off status or not -* __kswBackMeasureRatio__: decide width of background from thumb's, this is the ratio * __kswAnimationDuration__: duration of animation between 2 status * __kswTintColor__: change SwitchButton's style just by __one__ property, all relevant color will be generate automatically. Do not support `SwitchButtonMD` or other style created by xml resources. * __kswTextOn__: text for checked status. * __kswTextOff__: text for unchecked status. -* __kswTextMarginH__: horizontal margin of text. +* __kswTextThumbInset (since 2.0.0)__: length of the part of text under the thumb. +* __kswTextExtra (since 2.0.0)__: extra space needed by background besides the actual text width. +* __kswTextAdjust (since 2.0.0)__: move the text after position text on the center of text area. +* **kswThumbRangeRatio (since 2.0.0)**: (thumb move range width / thumb's width). float value. *see measure diagram* +* ~~__kswBackMeasureRatio__: (background's width / thumb's width). float value.~~ *Removed since 2.0.0* +* ~~**kswTextMarginH**: horizontal margin of text.~~ *Removed since 2.0.0* +* ~~__kswAutoAdjustTextPosition__: **(since 1.4.4)** whether auto adjust text position to make them looks centered (NOT really centered) when there are round corners. You should set this to false when you don't need this feature.~~ *Removed since 2.0.0* You can alse change the configuration of SwitchButton ___in code___. You can find the api from Demo apk. There's a glance. -``` +```java private String[] opts = new String[]{ "setThumbColorRes/setThumbColor", "setThumbDrawableRes/setThumbDrawable", @@ -93,15 +162,28 @@ private String[] opts = new String[]{ }; ``` + +Beautiful Apps +--- + +If you're using SwitchButton in your app, wish you can email me these infomation of your app and I'll create a list here. And that should be an utmost encouragement to me. :-) [kyleduo@gmail.com](mailto:kyleduo@gmail.com) + +| App | Name | Description | Markets | Developer | +| ---------------------------------------- | ----------------------- | ---------------------------------------- | ---------------------------------------- | ---------------------------------------- | +| ![headlines.png](https://static.kyleduo.com/headlines.png?imageView/2/w/80/) | Headlines | Headlines is a news dashboard for your smart TV. | [![market_logo_google_play.png](https://static.kyleduo.com/market_logo_google_play.png?imageView/2/w/80)](https://play.google.com/store/apps/details?id=com.mystraldesign.headlines)[![amazon-underground-app-us-black.png](https://static.kyleduo.com/amazon-underground-app-us-black.png?imageView/2/w/80)](https://www.amazon.com/Headlines-news-your-big-screen/dp/B01G93GRGC/ref=sr_1_1?ie=UTF8&qid=1487843182&sr=8-1&keywords=mystral+design) | [MYSTRAL](http://www.mystraldesign.com/) | +| ![lantouzi.png](https://static.kyleduo.com/lantouzi.png?imageView/2/w/80) | 懒投资 | 专业安全的投资理财平台 | [官方网站](https://lantouzi.com/mobile/download) | [懒投资 lantouzi.com](https://lantouzi.com) | +| ![notifications_in_bubble.png](https://static.kyleduo.com/project/switchbutton/apps/logo/notifications_in_bubble.png) | Notifications in bubble | Access all notifications from a floating bubble. | [![market_logo_google_play.png](https://static.kyleduo.com/market_logo_google_play.png?imageView/2/w/80)](https://play.google.com/store/apps/details?id=com.ram.chocolate.nm.premium) | [BestAppzz](https://play.google.com/store/apps/developer?id=BestAppzz) | + + License --- Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/SwitchButton/build.gradle b/SwitchButton/build.gradle index e69203f..b3fed8f 100644 --- a/SwitchButton/build.gradle +++ b/SwitchButton/build.gradle @@ -2,20 +2,18 @@ buildscript { repositories { - jcenter() + google() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.1.2' - classpath 'com.github.dcendents:android-maven-plugin:1.2' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0' - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files + classpath 'com.android.tools.build:gradle:8.0.0' + classpath "com.vanniktech:gradle-maven-publish-plugin:0.25.3" } } allprojects { repositories { - jcenter() + google() + mavenCentral() } } diff --git a/SwitchButton/demo/build.gradle b/SwitchButton/demo/build.gradle index 93d0ab4..e3f1192 100644 --- a/SwitchButton/demo/build.gradle +++ b/SwitchButton/demo/build.gradle @@ -1,16 +1,20 @@ -apply plugin: 'com.android.application' +plugins { + id('com.android.application') +} android { - compileSdkVersion 23 - buildToolsVersion "22.0.1" + compileSdk 33 + + namespace "com.kyleduo.switchbutton.demo" defaultConfig { applicationId "com.kyleduo.switchbutton.demo" - minSdkVersion 11 - targetSdkVersion 21 - versionCode 18 - versionName "1.4.0" + minSdkVersion 14 + targetSdk 33 + versionCode Integer.parseInt(VERSION_CODE) + versionName VERSION_NAME } + buildTypes { release { minifyEnabled true @@ -20,8 +24,9 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:23.1.1' - compile 'com.android.support:recyclerview-v7:23.1.1' - compile project(':library') + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation("androidx.appcompat:appcompat:1.6.1") + implementation("androidx.recyclerview:recyclerview:1.3.2") + implementation project(':library') +// implementation 'com.kyleduo.switchbutton:library:2.0.3' } diff --git a/SwitchButton/demo/demo-release.apk b/SwitchButton/demo/demo-release.apk deleted file mode 100644 index 49d5e7e..0000000 Binary files a/SwitchButton/demo/demo-release.apk and /dev/null differ diff --git a/SwitchButton/demo/src/main/AndroidManifest.xml b/SwitchButton/demo/src/main/AndroidManifest.xml index 970e2f2..7801699 100644 --- a/SwitchButton/demo/src/main/AndroidManifest.xml +++ b/SwitchButton/demo/src/main/AndroidManifest.xml @@ -1,59 +1,55 @@ - + - - - - + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + diff --git a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/MainActivity.java b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/MainActivity.java index 29c4487..6a3f330 100644 --- a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/MainActivity.java +++ b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/MainActivity.java @@ -3,13 +3,14 @@ import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; +import androidx.appcompat.app.AppCompatActivity; + public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { @@ -32,17 +33,14 @@ public boolean onCreateOptionsMenu(Menu menu) { public boolean onOptionsItemSelected(MenuItem item) { Intent intent = new Intent(Intent.ACTION_VIEW); int id = item.getItemId(); - switch (id) { - case R.id.action_github: - intent.setData(Uri.parse("https://github.com/kyleduo/SwitchButton")); - startActivity(intent); - return true; - case R.id.action_blog: - intent.setData(Uri.parse("http://kyleduo.com")); - startActivity(intent); - return true; - default: - break; + if (id == R.id.action_github) { + intent.setData(Uri.parse("https://github.com/kyleduo/SwitchButton")); + startActivity(intent); + return true; + } else if (id == R.id.action_blog) { + intent.setData(Uri.parse("https://kyleduo.com")); + startActivity(intent); + return true; } return super.onOptionsItemSelected(item); } @@ -63,15 +61,15 @@ private void jumpToRecycler() { startActivity(new Intent(this, RecyclerActivity.class)); } - private void gotoWeibo() { + private void gotoBlog() { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("http://kyleduo.com")); + intent.setData(Uri.parse("https://kyleduo.com")); startActivity(intent); } private void gotoLicense() { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("http://www.apache.org/licenses/LICENSE-2.0")); + intent.setData(Uri.parse("https://www.apache.org/licenses/LICENSE-2.0")); startActivity(intent); } @@ -92,7 +90,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) jumpToRecycler(); break; case 4: - gotoWeibo(); + gotoBlog(); break; case 5: gotoLicense(); diff --git a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/RecyclerActivity.java b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/RecyclerActivity.java index 556f99a..ce73170 100644 --- a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/RecyclerActivity.java +++ b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/RecyclerActivity.java @@ -1,9 +1,6 @@ package com.kyleduo.switchbutton.demo; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -15,6 +12,10 @@ import java.util.ArrayList; import java.util.List; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + /** * Created by kyle on 16/1/8. */ diff --git a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleActivity.java b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleActivity.java index cec8722..37b91ce 100644 --- a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleActivity.java +++ b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleActivity.java @@ -1,37 +1,54 @@ package com.kyleduo.switchbutton.demo; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.widget.CompoundButton; import com.kyleduo.switchbutton.SwitchButton; -public class StyleActivity extends ActionBarActivity { - - private SwitchButton mFlymeSb, mMiuiSb, mCustomSb, mDefaultSb, mSB; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_style); - - SwitchButton disableSb = (SwitchButton) findViewById(R.id.sb_disable_control); - mFlymeSb = (SwitchButton) findViewById(R.id.sb_custom_flyme); - mMiuiSb = (SwitchButton) findViewById(R.id.sb_custom_miui); - mCustomSb = (SwitchButton) findViewById(R.id.sb_custom); - mDefaultSb = (SwitchButton) findViewById(R.id.sb_default); - mSB = (SwitchButton) findViewById(R.id.sb_ios); - - disableSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mFlymeSb.setEnabled(isChecked); - mMiuiSb.setEnabled(isChecked); - mCustomSb.setEnabled(isChecked); - mDefaultSb.setEnabled(isChecked); - mSB.setEnabled(isChecked); - } - }); - } +import androidx.appcompat.app.AppCompatActivity; + +public class StyleActivity extends AppCompatActivity { + + private SwitchButton mFlymeSb, mMIUISb, mCustomSb, mDefaultSb, mSB; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_style); + + SwitchButton disableSb = (SwitchButton) findViewById(R.id.sb_disable_control); + SwitchButton disableNoEventSb = (SwitchButton) findViewById(R.id.sb_disable_control_no_event); + mFlymeSb = (SwitchButton) findViewById(R.id.sb_custom_flyme); + mMIUISb = (SwitchButton) findViewById(R.id.sb_custom_miui); + mCustomSb = (SwitchButton) findViewById(R.id.sb_custom); + mDefaultSb = (SwitchButton) findViewById(R.id.sb_default); + mSB = (SwitchButton) findViewById(R.id.sb_ios); + + if (disableSb != null) { + disableSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mFlymeSb.setEnabled(isChecked); + mMIUISb.setEnabled(isChecked); + mCustomSb.setEnabled(isChecked); + mDefaultSb.setEnabled(isChecked); + mSB.setEnabled(isChecked); + } + }); + } + if (disableNoEventSb != null) { + disableNoEventSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mFlymeSb.setEnabled(isChecked); + mMIUISb.setEnabled(isChecked); + mCustomSb.setEnabled(isChecked); + mDefaultSb.setEnabled(isChecked); + mSB.setEnabled(isChecked); + } + }); + disableNoEventSb.setCheckedImmediatelyNoEvent(false); + } + } } diff --git a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleInCodeActivity.java b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleInCodeActivity.java index c498899..ab2ce83 100644 --- a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleInCodeActivity.java +++ b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/StyleInCodeActivity.java @@ -1,13 +1,10 @@ package com.kyleduo.switchbutton.demo; -import android.graphics.PointF; import android.graphics.RectF; -import android.graphics.drawable.Drawable; import android.os.Bundle; -import android.support.v7.app.ActionBarActivity; import android.text.Spannable; import android.text.SpannableString; -import android.text.SpannableStringBuilder; +import android.text.TextUtils; import android.text.style.ImageSpan; import android.view.View; import android.widget.AdapterView; @@ -16,109 +13,114 @@ import com.kyleduo.switchbutton.SwitchButton; -public class StyleInCodeActivity extends ActionBarActivity implements AdapterView.OnItemClickListener { +import androidx.appcompat.app.AppCompatActivity; - private SwitchButton mChangeSb; - private boolean mThumbMarginFlag, mThumbSizeFlag, mThumbRadiusFlag, mBackRadiusFlag, mBackMeasureRatioFlag, mAnimationDurationFlag; - private String[] opts = new String[]{ - "setThumbColorRes/setThumbColor", - "setThumbDrawableRes/setThumbDrawable", - "setBackColorRes/setBackColor", - "setBackDrawableRes/setBackDrawable", - "setTintColor", - "setThumbMargin", - "setThumbSize", - "setThumbRadius (color-mode only)", - "setBackRadius (color-mode only)", - "setFadeBack", - "setBackMeasureRatio", - "setAnimationDuration", - "setText", - "setDrawDebugRect", - }; +public class StyleInCodeActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_style_in_code); + private SwitchButton mChangeSb; + private boolean mThumbMarginFlag, mThumbSizeFlag, mThumbRadiusFlag, mBackRadiusFlag, mBackMeasureRatioFlag, mAnimationDurationFlag; + private String[] opts = new String[]{ + "setThumbColorRes/setThumbColor", + "setThumbDrawableRes/setThumbDrawable", + "setBackColorRes/setBackColor", + "setBackDrawableRes/setBackDrawable", + "setTintColor", + "setThumbMargin", + "setThumbSize", + "setThumbRadius (color-mode only)", + "setBackRadius (color-mode only)", + "setFadeBack", + "setThumbRangeRatio", + "setAnimationDuration", + "setText", + "setDrawDebugRect", + }; - mChangeSb = (SwitchButton) findViewById(R.id.sb_code); - ListView optLv = (ListView) findViewById(R.id.opt_lv); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_style_in_code); - optLv.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, opts)); - optLv.setOnItemClickListener(this); - } + mChangeSb = (SwitchButton) findViewById(R.id.sb_code); + ListView optLv = (ListView) findViewById(R.id.opt_lv); - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - switch (position) { - case 0: - mChangeSb.setThumbColorRes(R.color.custom_thumb_color); - break; - case 1: - mChangeSb.setThumbDrawableRes(R.drawable.miui_thumb_drawable); - break; - case 2: - mChangeSb.setBackColorRes(R.color.custom_back_color); - break; - case 3: - mChangeSb.setBackDrawableRes(R.drawable.miui_back_drawable); - break; - case 4: - mChangeSb.setTintColor(0x9F6C66); - break; - case 5: { - float margin = 10 * getResources().getDisplayMetrics().density; - float defaultMargin = SwitchButton.DEFAULT_THUMB_MARGIN_DP * getResources().getDisplayMetrics().density; - mChangeSb.setThumbMargin(mThumbMarginFlag ? new RectF(defaultMargin, defaultMargin, defaultMargin, defaultMargin) : new RectF(margin, margin, margin, margin)); - mThumbMarginFlag = !mThumbMarginFlag; - } - break; - case 6: { - float size = 30 * getResources().getDisplayMetrics().density; - mChangeSb.setThumbSize(mThumbSizeFlag ? null : new PointF(size, size)); - mThumbSizeFlag = !mThumbSizeFlag; - } - break; - case 7: { - float r = 2 * getResources().getDisplayMetrics().density; - mChangeSb.setThumbRadius(mThumbRadiusFlag ? Math.min(mChangeSb.getThumbSizeF().x, mChangeSb.getThumbSizeF().y) / 2f : r); - mThumbRadiusFlag = !mThumbRadiusFlag; - } - break; - case 8: { - float r = 2 * getResources().getDisplayMetrics().density; - mChangeSb.setBackRadius(mBackRadiusFlag ? Math.min(mChangeSb.getBackSizeF().x, mChangeSb.getBackSizeF().y) / 2f : r); - mBackRadiusFlag = !mBackRadiusFlag; - } - break; - case 9: - mChangeSb.setFadeBack(!mChangeSb.isFadeBack()); - break; - case 10: - mChangeSb.setBackMeasureRatio(mBackMeasureRatioFlag ? SwitchButton.DEFAULT_BACK_MEASURE_RATIO : 2.4f); - mBackMeasureRatioFlag = !mBackMeasureRatioFlag; - break; - case 11: - mChangeSb.setAnimationDuration(mAnimationDurationFlag ? SwitchButton.DEFAULT_ANIMATION_DURATION : 1000); - mAnimationDurationFlag = !mAnimationDurationFlag; - break; - case 12: { - SpannableString ss = new SpannableString("abc"); - Drawable d = getResources().getDrawable(R.drawable.icon_blog); - if (d != null) { - d.setBounds(0, d.getIntrinsicWidth() / 4, d.getIntrinsicWidth() / 2, d.getIntrinsicHeight() * 3 / 4); - ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE); - ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); - mChangeSb.setText(ss, "OFF"); - } - } - break; - case 13: - mChangeSb.setDrawDebugRect(!mChangeSb.isDrawDebugRect()); - break; - default: - break; - } - } + optLv.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, opts)); + optLv.setOnItemClickListener(this); + } + + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + switch (position) { + case 0: + mChangeSb.setThumbColorRes(R.color.custom_thumb_color); + break; + case 1: + mChangeSb.setThumbDrawableRes(R.drawable.miui_thumb_drawable); + break; + case 2: + mChangeSb.setBackColorRes(R.color.custom_back_color); + break; + case 3: + mChangeSb.setBackDrawableRes(R.drawable.miui_back_drawable); + break; + case 4: + mChangeSb.setTintColor(0x9F6C66); + break; + case 5: { + float margin = 10 * getResources().getDisplayMetrics().density; + float defaultMargin = SwitchButton.DEFAULT_THUMB_MARGIN_DP * getResources().getDisplayMetrics().density; + mChangeSb.setThumbMargin(mThumbMarginFlag ? new RectF(defaultMargin, defaultMargin, defaultMargin, defaultMargin) : new RectF(margin, margin, margin, margin)); + mThumbMarginFlag = !mThumbMarginFlag; + } + break; + case 6: { + int size = (int) (30 * getResources().getDisplayMetrics().density); + mChangeSb.setThumbSize(size, size); + mThumbSizeFlag = !mThumbSizeFlag; + } + break; + case 7: { + float r = 2 * getResources().getDisplayMetrics().density; + mChangeSb.setThumbRadius(mThumbRadiusFlag ? Math.min(mChangeSb.getThumbWidth(), mChangeSb.getThumbHeight()) / 2f : r); + mThumbRadiusFlag = !mThumbRadiusFlag; + } + break; + case 8: { + float r = 2 * getResources().getDisplayMetrics().density; + mChangeSb.setBackRadius(mBackRadiusFlag ? Math.min(mChangeSb.getBackSizeF().x, mChangeSb.getBackSizeF().y) / 2f : r); + mBackRadiusFlag = !mBackRadiusFlag; + } + break; + case 9: + mChangeSb.setFadeBack(!mChangeSb.isFadeBack()); + break; + case 10: + mChangeSb.setThumbRangeRatio(mBackMeasureRatioFlag ? SwitchButton.DEFAULT_THUMB_RANGE_RATIO : 4f); + mBackMeasureRatioFlag = !mBackMeasureRatioFlag; + break; + case 11: + mChangeSb.setAnimationDuration(mAnimationDurationFlag ? SwitchButton.DEFAULT_ANIMATION_DURATION : 1000); + mAnimationDurationFlag = !mAnimationDurationFlag; + break; + case 12: { + CharSequence on = mChangeSb.getTextOn(); + CharSequence off = mChangeSb.getTextOff(); + if (TextUtils.isEmpty(on) || TextUtils.isEmpty(off)) { + SpannableString ss = new SpannableString("[icon]"); + ImageSpan span = new ImageSpan(this, R.drawable.icon_blog_small, ImageSpan.ALIGN_BOTTOM); + ss.setSpan(span, 0, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + mChangeSb.setText(ss, "OFF"); + mChangeSb.setTextExtra((int) (getResources().getDisplayMetrics().density * 4)); + } else { + mChangeSb.setText("", ""); + } + } + break; + case 13: + mChangeSb.setDrawDebugRect(!mChangeSb.isDrawDebugRect()); + break; + default: + break; + } + } } diff --git a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/UseActivity.java b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/UseActivity.java index 8534207..fcaf276 100644 --- a/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/UseActivity.java +++ b/SwitchButton/demo/src/main/java/com/kyleduo/switchbutton/demo/UseActivity.java @@ -3,150 +3,186 @@ import android.animation.Animator; import android.animation.ObjectAnimator; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.CompoundButton; +import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import com.kyleduo.switchbutton.SwitchButton; +import androidx.appcompat.app.AppCompatActivity; + public class UseActivity extends AppCompatActivity implements View.OnClickListener { - private SwitchButton mListenerSb, mLongSb, mToggleSb, mCheckedSb, mDelaySb, mForceOpenSb, mForceOpenControlSb; - private ProgressBar mPb; - private Button mStartBt, mToggleAniBt, mToggleNotAniBt, mCheckedAniBt, mCheckNotAniBt; - private TextView mListenerFinish; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_use); - - findView(); - - // work with listener - mListenerSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mListenerFinish.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE); - } - }); - - // work with delay - mDelaySb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - mDelaySb.setEnabled(false); - mDelaySb.postDelayed(new Runnable() { - @Override - public void run() { - mDelaySb.setEnabled(true); - } - }, 1500); - } - }); - - // work with stuff takes long - mStartBt.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View v) { - ObjectAnimator animator = ObjectAnimator.ofInt(mPb, "progress", 0, 1000); - animator.setDuration(1000); - animator.addListener(new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) { - mStartBt.setEnabled(false); - mLongSb.setChecked(false); - } - - @Override - public void onAnimationEnd(Animator animation) { - mStartBt.setEnabled(true); - mLongSb.setChecked(true); - } - - @Override - public void onAnimationCancel(Animator animation) { - mStartBt.setEnabled(true); - } - - @Override - public void onAnimationRepeat(Animator animation) { - - } - }); - animator.start(); - } - }); - - // toggle - mToggleAniBt.setOnClickListener(this); - mToggleNotAniBt.setOnClickListener(this); - - // checked - mCheckedAniBt.setOnClickListener(this); - mCheckNotAniBt.setOnClickListener(this); - - // check in check - mForceOpenSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (mForceOpenControlSb.isChecked()) { - Toast.makeText(UseActivity.this, "Call mForceOpenSb.setChecked(true); in on CheckedChanged", Toast.LENGTH_SHORT).show(); - mForceOpenSb.setChecked(true); - } - } - }); - } - - private void findView() { - mListenerSb = (SwitchButton) findViewById(R.id.sb_use_listener); - mLongSb = (SwitchButton) findViewById(R.id.sb_use_long); - mToggleSb = (SwitchButton) findViewById(R.id.sb_use_toggle); - mCheckedSb = (SwitchButton) findViewById(R.id.sb_use_checked); - mDelaySb = (SwitchButton) findViewById(R.id.sb_use_delay); - - mPb = (ProgressBar) findViewById(R.id.pb); - mPb.setProgress(0); - mPb.setMax(1000); - - mStartBt = (Button) findViewById(R.id.long_start); - mToggleAniBt = (Button) findViewById(R.id.toggle_ani); - mToggleNotAniBt = (Button) findViewById(R.id.toggle_not_ani); - mCheckedAniBt = (Button) findViewById(R.id.checked_ani); - mCheckNotAniBt = (Button) findViewById(R.id.checked_not_ani); - - mListenerFinish = (TextView) findViewById(R.id.listener_finish); - mListenerFinish.setVisibility(mListenerSb.isChecked() ? View.VISIBLE : View.INVISIBLE); - - mForceOpenSb = (SwitchButton) findViewById(R.id.use_focus_open); - mForceOpenControlSb = (SwitchButton) findViewById(R.id.use_focus_open_control); - } - - @Override - public void onClick(View v) { - int id = v.getId(); - switch (id) { - case R.id.toggle_ani: - mToggleSb.toggle(); - break; - case R.id.toggle_not_ani: - mToggleSb.toggleImmediately(); - break; - case R.id.checked_ani: - mCheckedSb.setChecked(!mCheckedSb.isChecked()); - break; - case R.id.checked_not_ani: - mCheckedSb.setCheckedImmediately(!mCheckedSb.isChecked()); - break; - - default: - break; - } - } + private SwitchButton mListenerSb, mListenerDistinguishSb, mLongSb, mToggleSb, mCheckedSb, mDelaySb, mForceOpenSb, mForceOpenControlSb; + private ProgressBar mPb; + private Button mStartBt; + private TextView mListenerFinish; + private TextView mTriggerTv; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_use); + + findView(); + + LinearLayout toggleWrapper = (LinearLayout) findViewById(R.id.toggle_wrapper); + for (int i = 0; i < toggleWrapper.getChildCount(); i++) { + toggleWrapper.getChildAt(i).setOnClickListener(this); + } + + LinearLayout checkWrapper = (LinearLayout) findViewById(R.id.check_wrapper); + for (int i = 0; i < checkWrapper.getChildCount(); i++) { + checkWrapper.getChildAt(i).setOnClickListener(this); + } + + + // work with listener + mListenerSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mListenerFinish.setVisibility(isChecked ? View.VISIBLE : View.INVISIBLE); + if (mListenerDistinguishSb.isChecked() != isChecked) { + mListenerDistinguishSb.setChecked(isChecked); + } + } + }); + + // listener with distinguish + mListenerDistinguishSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mTriggerTv.setVisibility(isChecked ? View.VISIBLE : View.GONE); + if (isChecked) { + mTriggerTv.setText(buttonView.isPressed() ? R.string.use_trigger_manually : R.string.use_trigger_by_code); + } + } + }); + + // work with delay + mDelaySb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + mDelaySb.setEnabled(false); + mDelaySb.postDelayed(new Runnable() { + @Override + public void run() { + mDelaySb.setEnabled(true); + } + }, 1500); + } + }); + + // work with stuff takes long + mStartBt.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + ObjectAnimator animator = ObjectAnimator.ofInt(mPb, "progress", 0, 1000); + animator.setDuration(1000); + animator.addListener(new Animator.AnimatorListener() { + @Override + public void onAnimationStart(Animator animation) { + mStartBt.setEnabled(false); + mLongSb.setChecked(false); + } + + @Override + public void onAnimationEnd(Animator animation) { + mStartBt.setEnabled(true); + mLongSb.setChecked(true); + } + + @Override + public void onAnimationCancel(Animator animation) { + mStartBt.setEnabled(true); + } + + @Override + public void onAnimationRepeat(Animator animation) { + + } + }); + animator.start(); + } + }); + + // check in check + mForceOpenSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + if (mForceOpenControlSb.isChecked()) { + toast("Call mForceOpenSb.setChecked(true); in on CheckedChanged"); + mForceOpenSb.setChecked(true); + } + } + }); + } + + private void findView() { + mListenerSb = (SwitchButton) findViewById(R.id.sb_use_listener); + mListenerDistinguishSb = (SwitchButton) findViewById(R.id.sb_listener_distinguish); + mLongSb = (SwitchButton) findViewById(R.id.sb_use_long); + mToggleSb = (SwitchButton) findViewById(R.id.sb_use_toggle); + mCheckedSb = (SwitchButton) findViewById(R.id.sb_use_checked); + mDelaySb = (SwitchButton) findViewById(R.id.sb_use_delay); + + mPb = (ProgressBar) findViewById(R.id.pb); + mPb.setProgress(0); + mPb.setMax(1000); + + mStartBt = (Button) findViewById(R.id.long_start); + + mListenerFinish = (TextView) findViewById(R.id.listener_finish); + mListenerFinish.setVisibility(mListenerSb.isChecked() ? View.VISIBLE : View.INVISIBLE); + mTriggerTv = (TextView) findViewById(R.id.listener_trigger); + + mForceOpenSb = (SwitchButton) findViewById(R.id.use_focus_open); + mForceOpenControlSb = (SwitchButton) findViewById(R.id.use_focus_open_control); + + mToggleSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + toast("Toggle SwitchButton new check state: " + (isChecked ? "Checked" : "Unchecked")); + } + }); + + mCheckedSb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + toast("Check SwitchButton new check state: " + (isChecked ? "Checked" : "Unchecked")); + } + }); + } + + @Override + public void onClick(View v) { + int id = v.getId(); + if (id == R.id.toggle_ani) { + mToggleSb.toggle(); + } else if (id == R.id.toggle_ani_no_event) { + mToggleSb.toggleNoEvent(); + } else if (id == R.id.toggle_not_ani) { + mToggleSb.toggleImmediately(); + } else if (id == R.id.toggle_not_ani_no_event) { + mToggleSb.toggleImmediatelyNoEvent(); + } else if (id == R.id.checked_ani) { + mCheckedSb.setChecked(!mCheckedSb.isChecked()); + } else if (id == R.id.checked_ani_no_event) { + mCheckedSb.setCheckedNoEvent(!mCheckedSb.isChecked()); + } else if (id == R.id.checked_not_ani) { + mCheckedSb.setCheckedImmediately(!mCheckedSb.isChecked()); + } else if (id == R.id.checked_not_ani_no_event) { + mCheckedSb.setCheckedImmediatelyNoEvent(!mCheckedSb.isChecked()); + } + } + + private void toast(String text) { + Toast.makeText(UseActivity.this, text, Toast.LENGTH_SHORT).show(); + } } diff --git a/SwitchButton/demo/src/main/res/color/custom_text_state_color.xml b/SwitchButton/demo/src/main/res/color/custom_text_state_color.xml index efe0446..5b14586 100644 --- a/SwitchButton/demo/src/main/res/color/custom_text_state_color.xml +++ b/SwitchButton/demo/src/main/res/color/custom_text_state_color.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/SwitchButton/demo/src/main/res/drawable-xxhdpi/icon_blog_small.png b/SwitchButton/demo/src/main/res/drawable-xxhdpi/icon_blog_small.png new file mode 100644 index 0000000..0d0fa2f Binary files /dev/null and b/SwitchButton/demo/src/main/res/drawable-xxhdpi/icon_blog_small.png differ diff --git a/SwitchButton/demo/src/main/res/layout/activity_recycler.xml b/SwitchButton/demo/src/main/res/layout/activity_recycler.xml index 79f7f53..af4a141 100644 --- a/SwitchButton/demo/src/main/res/layout/activity_recycler.xml +++ b/SwitchButton/demo/src/main/res/layout/activity_recycler.xml @@ -1,8 +1,8 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/SwitchButton/demo/src/main/res/layout/activity_style.xml b/SwitchButton/demo/src/main/res/layout/activity_style.xml index 7efc46f..8a0d55c 100644 --- a/SwitchButton/demo/src/main/res/layout/activity_style.xml +++ b/SwitchButton/demo/src/main/res/layout/activity_style.xml @@ -26,6 +26,128 @@ android:layout_height="wrap_content" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -55,6 +179,8 @@ android:layout_height="wrap_content" android:textColor="@color/custom_text_state_color" android:textSize="16dp" + app:kswTextAdjust="-2dp" + app:kswTextExtra="8dp" app:kswTextOff="Off" app:kswTextOn="On" /> @@ -111,9 +237,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - app:kswBackMeasureRatio="2.2" app:kswBackRadius="2dp" app:kswThumbRadius="2dp" + app:kswThumbRangeRatio="2.2" app:kswTintColor="#49416E" /> @@ -124,9 +250,9 @@ android:layout_height="wrap_content" android:layout_gravity="center" app:kswBackDrawable="@drawable/flyme_back_drawable" - app:kswBackMeasureRatio="2.2" app:kswThumbDrawable="@drawable/flyme_thumb_drawable" app:kswThumbHeight="16dp" + app:kswThumbRangeRatio="2.2" app:kswThumbWidth="16dp" /> @@ -137,9 +263,9 @@ android:layout_height="wrap_content" android:layout_gravity="center" app:kswBackDrawable="@drawable/miui_back_drawable" - app:kswBackMeasureRatio="2" app:kswThumbDrawable="@drawable/miui_thumb_drawable" app:kswThumbHeight="18dp" + app:kswThumbRangeRatio="2" app:kswThumbWidth="18dp" /> @@ -208,12 +334,12 @@ android:layout_height="wrap_content" app:kswAnimationDuration="300" app:kswBackDrawable="@drawable/ios_back_drawable" - app:kswBackMeasureRatio="1.4" app:kswThumbDrawable="@drawable/ios_thumb_selector" app:kswThumbMarginBottom="-8dp" app:kswThumbMarginLeft="-5dp" app:kswThumbMarginRight="-5dp" - app:kswThumbMarginTop="-2.5dp"/> + app:kswThumbMarginTop="-2.5dp" + app:kswThumbRangeRatio="1.4"/> - + android:orientation="horizontal"> + + + + + + \ No newline at end of file diff --git a/SwitchButton/demo/src/main/res/layout/activity_use.xml b/SwitchButton/demo/src/main/res/layout/activity_use.xml index c2169e2..a9619c0 100644 --- a/SwitchButton/demo/src/main/res/layout/activity_use.xml +++ b/SwitchButton/demo/src/main/res/layout/activity_use.xml @@ -41,6 +41,49 @@ android:text="@string/use_listener_finish"/> + + + + + + + + + + + + + +