项目作者: radeshf

项目描述 :
Two side chooser for accept and ignore situation
高级语言: Kotlin
项目地址: git://github.com/radeshf/TwoSideChooser.git
创建时间: 2019-02-04T14:10:10Z
项目社区:https://github.com/radeshf/TwoSideChooser

开源协议:Apache License 2.0

下载


Two Side Chooser

Two side chooser for accept and ignore situation

API

License

Dependency

Add this into your root build.gradle file (not your module build.gradle file):

  1. allprojects {
  2. repositories {
  3. ...
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

Then, add the library to your project build.gradle

  1. dependencies {
  2. implementation 'com.github.radeshf:TwoSideChooser:1.0.7'
  3. }
Example 1

  • XML :
  1. <radesh.twosidechooser.Chooser
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:id="@+id/chooser"
  5. app:acceptDrawable="@drawable/ic_accept_ex1"
  6. app:acceptDrawableSize="50dp"
  7. app:acceptBackgroundColor="#ffca05"
  8. app:ignoreDrawable="@drawable/ic_ignore_ex1"
  9. app:ignoreDrawableSize="50dp"
  10. app:ignoreBackgroundColor="#ffca05"
  11. app:arrowsDrawable="@drawable/ic_arrows_ex1"
  12. app:arrowsDrawableRotation="180"
  13. app:chooserBackgroundColor="#124743"
  14. app:drawablesPadding="5dp"
  15. app:thumbDrawable="@drawable/ic_candidate"
  16. ></radesh.twosidechooser.Chooser>
Example 2

  • XML :
  1. <radesh.twosidechooser.Chooser
  2. android:layout_width="wrap_content"
  3. android:layout_height="wrap_content"
  4. android:id="@+id/chooser"
  5. app:enableSelectWithClick="false"
  6. app:enableNearbyAnimation="true"
  7. app:enableReturnToCenter="true"
  8. app:acceptDrawable="@drawable/ic_call"
  9. app:acceptBackgroundColor="#15AE15"
  10. app:acceptDrawableSize="55dp"
  11. app:ignoreDrawable="@drawable/ic_call"
  12. app:ignoreBackgroundColor="#D91A1A"
  13. app:ignoreDrawableSize="55dp"
  14. app:ignoreDrawableRotation="135"
  15. app:chooserBackgroundColor="#00ffffff"
  16. app:drawablesPadding="10dp"
  17. app:acceptValue="90"
  18. app:ignoreValue="10"
  19. app:thumbDrawable="@drawable/ic_fingerprint_ex2"
  20. ></radesh.twosidechooser.Chooser>
  • Kotlin :

For listening user swipe to accept or ignore

  1. chooser.setOnSwipeEndListener(object : onSwipeEndListener{
  2. override fun onAccept() {
  3. Log.i(tag,"Accepted")
  4. //return to center with animation
  5. chooser.smoothReturnToCenter()
  6. }
  7. override fun onIgnore() {
  8. Log.i(tag,"Ignored")
  9. //return to center promptly
  10. chooser.returnToCenter()
  11. }
  12. })

Use this if you want to be approved promptly

  1. //approved promptly when you swipe to end or start
  2. chooser.enableDoWithoutStopTracking(true)
  3. //sets acceptValue to 100 and calculate ignore value (ignoreValue = 0)
  4. chooser.setAcceptFinalValue(100,true)

Some Other functions

  1. //sets acceptValue to 80 and calculate ignore value (ignoreValue = 20)
  2. chooser.setAcceptValue(80,true)
  3. // when enter this value animation will be start (when arrive above 60 and below 40)
  4. chooser.setAcceptAnimationValue(60,true)
  5. // change animation when arrive animation value(set above)
  6. chooser.setMovementAnimation(customAnimation)
  7. //if you want hide arrows use 0f
  8. chooser.setArrowsImagesAlpha(0.8f)
  9. //set drawable padding to look better
  10. chooser.setDrawablePadding(resources.getDimensionPixelOffset(R.dimen.padding))
  11. //set chooser background
  12. chooser.setChooserBackgroundColor(resources.getColor(R.color.colorAccent))
  • Configure using xml attributes or setters in code:

























































































































    Attribute Name Default Value Description
    app:acceptValue=”10” 85 when arrives to this value fire onAccept()\n must be in 55 to 100
    app:ignoreValue=”90” 15 when arrives to this value fire onIgnore() \n must be in 0 to 45
    app:acceptAnimationValue=”70” 60 after this value will played animation for accept button \n must be in 55 to 100
    app:ignoreAnimationValue=”20” 30 after this value will played animation for ignore button \n must be in 0 to 45
    app:centerProgress=”50” 50 thumb return to this progress
    app:enableNearbyAnimation=”false” true enable/disable animation when thumb close to buttons
    app:enableReturnToCenter=”false” true return to center when thumb release and not in accept/ignore value if true
    app:enableSelectWithClick=”true” false prevent to accept with single tap on buttons (swipe not necessary if true)
    app:acceptDrawable=”@drawable/ic_accept” ic_accept sets accept drawable
    app:ignoreDrawable=”@drawable/ic_ignore” ic_accept sets ignore drawable
    app:acceptBackgroundDrawable=”@drawable/accept_bg” border_accept sets accept background drawable
    app:ignoreBackgroundDrawable=”@drawable/ignore_bg” chooser_border_ignore sets ignore background drawable
    app:acceptBackgroundColor=”@color/accept_color” @color/colorAccent sets accept background drawable color
    app:ignoreBackgroundColor=”@color/ignore_color” @color/colorAccent sets ignore background drawable color
    app:arrowsDrawable=”@drawable/ic_arrows” ic_arrows sets arrows drawable together
    app:arrowsDrawableRotation=”180” 0 rotate both arrows
    app:acceptDrawableRotation=”90” 0 rotate accept drawable
    app:ignoreDrawableRotation=”135” 0 rotate ignore drawable
    app:thumbDrawable=”@drawable/ic_thumb” ic_thumb sets thumb drawable
    app:drawablesPadding=”0dp” 0 sets accept/ignore drawables padding
    app:acceptDrawableSize=”50dp” 40dp sets accept drawable size
    app:ignoreDrawableSize=”50dp” 40dp sets ignore drawable size
    app:chooserBackgroundColor=”@color/chooser_color” @color/colorPrimary sets chooser background color

License

Copyright 2019 Radesh Farokh Manesh

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

  1. 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.