Two side chooser for accept and ignore situation
Two side chooser for accept and ignore situation
Add this into your root build.gradle
file (not your module build.gradle
file):
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Then, add the library to your project build.gradle
dependencies {
implementation 'com.github.radeshf:TwoSideChooser:1.0.7'
}
<radesh.twosidechooser.Chooser
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chooser"
app:acceptDrawable="@drawable/ic_accept_ex1"
app:acceptDrawableSize="50dp"
app:acceptBackgroundColor="#ffca05"
app:ignoreDrawable="@drawable/ic_ignore_ex1"
app:ignoreDrawableSize="50dp"
app:ignoreBackgroundColor="#ffca05"
app:arrowsDrawable="@drawable/ic_arrows_ex1"
app:arrowsDrawableRotation="180"
app:chooserBackgroundColor="#124743"
app:drawablesPadding="5dp"
app:thumbDrawable="@drawable/ic_candidate"
></radesh.twosidechooser.Chooser>
<radesh.twosidechooser.Chooser
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chooser"
app:enableSelectWithClick="false"
app:enableNearbyAnimation="true"
app:enableReturnToCenter="true"
app:acceptDrawable="@drawable/ic_call"
app:acceptBackgroundColor="#15AE15"
app:acceptDrawableSize="55dp"
app:ignoreDrawable="@drawable/ic_call"
app:ignoreBackgroundColor="#D91A1A"
app:ignoreDrawableSize="55dp"
app:ignoreDrawableRotation="135"
app:chooserBackgroundColor="#00ffffff"
app:drawablesPadding="10dp"
app:acceptValue="90"
app:ignoreValue="10"
app:thumbDrawable="@drawable/ic_fingerprint_ex2"
></radesh.twosidechooser.Chooser>
For listening user swipe to accept or ignore
chooser.setOnSwipeEndListener(object : onSwipeEndListener{
override fun onAccept() {
Log.i(tag,"Accepted")
//return to center with animation
chooser.smoothReturnToCenter()
}
override fun onIgnore() {
Log.i(tag,"Ignored")
//return to center promptly
chooser.returnToCenter()
}
})
Use this if you want to be approved promptly
//approved promptly when you swipe to end or start
chooser.enableDoWithoutStopTracking(true)
//sets acceptValue to 100 and calculate ignore value (ignoreValue = 0)
chooser.setAcceptFinalValue(100,true)
Some Other functions
//sets acceptValue to 80 and calculate ignore value (ignoreValue = 20)
chooser.setAcceptValue(80,true)
// when enter this value animation will be start (when arrive above 60 and below 40)
chooser.setAcceptAnimationValue(60,true)
// change animation when arrive animation value(set above)
chooser.setMovementAnimation(customAnimation)
//if you want hide arrows use 0f
chooser.setArrowsImagesAlpha(0.8f)
//set drawable padding to look better
chooser.setDrawablePadding(resources.getDimensionPixelOffset(R.dimen.padding))
//set chooser background
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 |
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
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.