Skip to content

Latest commit

 

History

History
215 lines (182 loc) · 8.39 KB

README-ZH.md

File metadata and controls

215 lines (182 loc) · 8.39 KB

FaceOffToggleButton

WoWoViewPager BoomMenu CoCoin BlurLockView LeeCo GithubWidget JellyToggleButton FaceOffToggleButton

笑脸苦脸表示开关状态的开关按钮。

FaceOffToggleButton

最近在写一个可爱的果冻动效开关按钮。之后无意中看到一个用笑脸和苦脸表示开关状态的按钮(IOSDribbble)。因为都是开关按钮,所以顺手写了一个。这篇文档许多相关功能和之前提到的开关按钮类似,更多信息可以去JellyToggleButton看看。

Guide

  1. English Version
  2. Gradle
  3. Demo
  4. Usage Guide
    1. Background Color
    2. Left & Right Background Color
    3. Left & Right Face Color
    4. Left & Right Eye Color
    5. Left & Right Mouth Color
    6. Set Checked and Toggle
    7. Listener
    8. Duration
    9. Draggable
    10. Color Change Type
    11. Dimension
    12. Other Method
  5. Todo
  6. Versions
  7. License

Gradle

dependencies {
    compile 'com.nightonke:faceofftogglebutton:1.0.0'
}

Demo

Demo在此:

  1. On Github
  2. On Fir

QR Code

Usage Guide

Background Color

这里的背景颜色和View的背景颜色略有不同,可以试着定义背景颜色或者阅读源码来查看其不同之处。

setBackgroundColor(int mBackgroundColor)
app:foBackgroundColor="@color/white"

Left & Right Background Color

脸运动到左边的背景颜色和运动到右边的背景颜色。

setLeftBackgroundColor(int mLeftBackgroundColor)
setRightBackgroundColor(int mRightBackgroundColor)
app:foLeftBackgroundColor="@color/gray"
app:foRightBackgroundColor="@color/blue"

Left & Right Face Color

左脸颜色和右脸颜色。

setLeftFaceColor(int mLeftFaceColor)
setRightFaceColor(int mRightFaceColor)
app:foLeftFaceColor="@color/white"
app:foRightFaceColor="@color/white"

Left & Right Eye Color

左脸的眼睛颜色和右脸的眼睛颜色。

setLeftEyeColor(int mLeftEyeColor)
setRightEyeColor(int mRightEyeColor)
app:foLeftEyeColor="@color/gray"
app:foRightEyeColor="@color/blue"

Left & Right Mouth Color

setLeftMouthColor(int mLeftMouthColor)
setRightMouthColor(int mRightMouthColor)
app:foLeftMouthColor="@color/gray"
app:foRightMouthColor="@color/blue"

Set Checked and Toggle

方法 是否有动画 是否有监听器
setChecked(boolean checked) Y Y
setChecked(boolean checked, boolean callListener) Y Y/N
setCheckedImmediately(boolean checked) N Y
setCheckedImmediately(boolean checked, boolean callListener) N Y/N
toggle() Y Y
toggle(boolean callListener) Y Y/N
toggleImmediately() N Y
toggleImmediately(boolean callListener) N Y/N

Listener

fotb0.setOnStateChangeListener(new FaceOffToggleButton.OnStateChangeListener() {
    @Override
    public void onStateChange(float process, State state, FaceOffToggleButton fotb) {
        // process - current process of JTB, between [0, 1]
        // state   - current state of JTB, it is one of State.LEFT, State.LEFT_TO_RIGHT, State.RIGHT and State.RIGHT_TO_LEFT
        // fotb     - the FOTB
    }
});

Duration

setDuration(int duration)
app:foDuration="1000"

Draggable

setDraggable(boolean draggable)
app:foDraggable="false"

Color Change Type

更多相关信息,请查阅

setColorChangeType(ColorChangeType mColorChangeType)
app:foColorChangeType="hsv"

Dimension

// 脸的半径,单位像素
setFaceRadius(float mFaceRadius)

// 控件宽度与脸半径的比值,单位浮点数
setWidthRadiusRatio(float mWidthRadiusRatio)

// 脸和背景的间距,单位像素
setFaceMargin(float mFaceMargin)
app:foFaceRadius="15dp"
app:foWidthRadiusRatio="2.5"
app:foFaceMargin="1dp"

Other Method

手指拖动的距离和脸移动的距离。

setTouchMoveRatioValue(float ratio)
app:foTouchMoveRatioValue="2"

当脸运动到与上次相同的状态是否调用监听器。

setMoveToSameStateCallListener(boolean callListener)
app:foMoveToSameStateCallListener="false"

Todo

  1. 眼睛和嘴巴运动到终点的缓冲动效。
  2. 更多表情。

Version

第一版本。

License

Copyright 2016 Nightonke

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.
See the License for the specific language governing permissions and
limitations under the License.