|
| 1 | +# ProSwipeButton |
| 2 | +A swipe button for Android with a circular progress bar for async operations |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +# Gradle |
| 7 | +``` |
| 8 | +dependencies { |
| 9 | + ... |
| 10 | + compile 'in.shadowfax:proswipebutton:1.0.1' |
| 11 | +} |
| 12 | +``` |
| 13 | + |
| 14 | +# Usage |
| 15 | +1. In your XML layout file, add this custom view |
| 16 | +```xml |
| 17 | +<in.shadowfax.proswipebutton.ProSwipeButton |
| 18 | + android:id="@+id/awesome_btn" |
| 19 | + android:layout_width="match_parent" |
| 20 | + android:layout_height="wrap_content" |
| 21 | + android:layout_margin="8dp" |
| 22 | + app:bg_color="@android:color/holo_blue_dark" |
| 23 | + app:btn_text="Place Order" /> |
| 24 | +``` |
| 25 | + |
| 26 | +2. React to successful swipe on the button by adding a swipe listener |
| 27 | +```java |
| 28 | +ProSwipeButton proSwipeBtn = (ProSwipeButton) findViewById(R.id.awesome_btn); |
| 29 | +proSwipeBtn.setOnSwipeListener(new ProSwipeButton.OnSwipeListener() { |
| 30 | + @Override |
| 31 | + public void onSwipeConfirm() { |
| 32 | + // user has swiped the btn. Perform your async operation now |
| 33 | + new Handler().postDelayed(new Runnable() { |
| 34 | + @Override |
| 35 | + public void run() { |
| 36 | + // task success! show TICK icon in ProSwipeButton |
| 37 | + proSwipeBtn.showResultIcon(true); // false if task failed |
| 38 | + } |
| 39 | + }, 2000); |
| 40 | + } |
| 41 | + }); |
| 42 | +``` |
| 43 | + |
| 44 | +3. After the async task is completed, tell the ProSwipeButton to show a result icon. |
| 45 | +Either a tick for a successful async operation or cross for a failed async operation. |
| 46 | + |
| 47 | +```java |
| 48 | +proSwipeBtn.showResultIcon(true); //if task succeeds |
| 49 | +proSwipeBtn.showResultIcon(false); //if task fails |
| 50 | +``` |
| 51 | + |
| 52 | +# Customizations |
| 53 | + |
| 54 | +You can customize the button via XML or programatically. |
| 55 | + |
| 56 | +```XML |
| 57 | +<in.shadowfax.proswipebutton.ProSwipeButton |
| 58 | + android:id="@+id/proswipebutton_main_error" |
| 59 | + android:layout_width="match_parent" |
| 60 | + android:layout_height="wrap_content" |
| 61 | + android:layout_margin="8dp" |
| 62 | + app:arrow_color="#33FFFFFF" |
| 63 | + app:bg_color="@android:color/holo_blue_dark" |
| 64 | + app:btn_radius="2dp" |
| 65 | + app:btn_text="Place Order" |
| 66 | + app:text_color="@android:color/white" |
| 67 | + app:text_size="12sp" /> |
| 68 | +``` |
| 69 | +Feel free to raise feature requests via the issue tracker for more customizations or just send in a PR :) |
| 70 | + |
| 71 | +# Sample |
| 72 | +Clone the repository and check out the `app` module. |
| 73 | + |
| 74 | +# License |
| 75 | + |
| 76 | +``` |
| 77 | +MIT License |
| 78 | +
|
| 79 | +Copyright (c) 2017 Shadowfax Technologies |
| 80 | +
|
| 81 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 82 | +of this software and associated documentation files (the "Software"), to deal |
| 83 | +in the Software without restriction, including without limitation the rights |
| 84 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 85 | +copies of the Software, and to permit persons to whom the Software is |
| 86 | +furnished to do so, subject to the following conditions: |
| 87 | +
|
| 88 | +The above copyright notice and this permission notice shall be included in all |
| 89 | +copies or substantial portions of the Software. |
| 90 | +
|
| 91 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 92 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 93 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 94 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 95 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 96 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 97 | +SOFTWARE. |
| 98 | +``` |
0 commit comments