GithubHelp home page GithubHelp logo

roughike / swipeselector Goto Github PK

View Code? Open in Web Editor NEW
1.1K 40.0 161.0 9.48 MB

A nicer-looking, more intuitive and highly customizable alternative for radio buttons and dropdowns for Android.

License: Apache License 2.0

Java 100.00%

swipeselector's Introduction

SwipeSelector

Codacy Badge

Undergoing for some API changes for a 2.0 major version, see example usage in the sample module!

Get it on Google Play

What and why?

Bored of dull looking radio buttons and dropdowns? Me too. I started looking for a more sophisticated way of offering user a choice, and came up with this beautiful dribble.

Unfortunately, there were no ready-made solutions to achieve this, so I spent a good day working on this very thing I call SwipeSelector.

minSDK Version

SwipeSelector supports API levels all the way down to 8 (Android Froyo).

Installation

Gradle:

compile 'com.roughike:swipe-selector:1.0.6'

Maven:

<dependency>
  <groupId>com.roughike</groupId>
  <artifactId>swipe-selector</artifactId>
  <version>1.0.6</version>
  <type>pom</type>
</dependency>

How do I use it?

The usage is really simple.

First add SwipeSelector to your layout file:

<com.roughike.swipeselector.SwipeSelector
    android:value="@+value/swipeSelector"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Then get a hold of it and give it a set of SwipeItem objects with values, titles and descriptions:

SwipeSelector swipeSelector = (SwipeSelector) findViewById(R.value.swipeSelector);
swipeSelector.setItems(
  // The first argument is the value for that item, and should in most cases be unique for the
  // current SwipeSelector, just as you would assign values to radio buttons.
  // You can use the value later on to check what the selected item was.
  // The value can be any Object, here we're using ints.
  new SwipeItem(0, "Slide one", "Description for slide one."),
  new SwipeItem(1, "Slide two", "Description for slide two."),
  new SwipeItem(2, "Slide three", "Description for slide three.")
);

Whenever you need to know what is the currently showing SwipeItem:

SwipeItem selectedItem = swipeSelector.getSelectedItem();

// The value is the first argument provided when creating the SwipeItem.
int value = (Integer) selectedItem.value;

// for example
if (value == 0) {
  // The user selected slide number one.
}

For an example project using multiple SwipeSelectors, refer to the sample app.

Customization

<com.roughike.swipeselector.SwipeSelector
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:value="@+value/conditionSelector"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:swipe_indicatorSize="10dp"
    app:swipe_indicatorMargin="12dp"
    app:swipe_indicatorInActiveColor="#DDDDDD"
    app:swipe_indicatorActiveColor="#FF00FF"
    app:swipe_leftButtonResource="@drawable/leftButtonResource"
    app:swipe_rightButtonResource="@drawable/rightButtonResource"
    app:swipe_customFontPath="fonts/MySuperDuperFont.ttf"
    app:swipe_titleTextAppearance="@style/MyTitleTextApperance"
    app:swipe_descriptionTextAppearance="@style/MyDescriptionTextApperance"
    app:swipe_descriptionGravity="center" />
swipe_indicatorSize
the size for the circle indicators.
swipe_indicatorMargin
how far the indicators are from each other.
swipe_indicatorInActiveColor
the color for normal unselected indicators.
swipe_indicatorActiveColor
the color for selected indicator.
swipe_leftButtonResource and swipe_rightButtonResource
custom Drawable resources for the left and right buttons. The margins for the content are calculated automatically, so even a bigger custom image won't overlap the content.
swipe_customFontPath
path for your custom font file, such as fonts/MySuperDuperFont.ttf. In that case your font path would look like src/main/assets/fonts/MySuperDuperFont.ttf, but you only need to provide fonts/MySuperDuperFont.ttf, as the asset folder will be auto-filled for you.
swipe_titleTextAppearance and swipe_descriptionTextAppearance
custom TextAppearance for the title and description TextViews for modifying the font sizes and colors and what not.
swipe_descriptionGravity
custom horizontal gravity (in other words alignment) for the description text. Can be either left, center or right. Default should be fine in most cases, but sometimes you might need to modify this.

Apps using SwipeSelector

Send me a pull request with modified README.md to get a shoutout!

Contributions

Feel free to create issues / pull requests.

License

SwipeSelector library for Android
Copyright (c) 2016 Iiro Krankka (http://github.com/roughike).

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.

swipeselector's People

Contributors

emmanuelmess avatar neustaterasa avatar ravidsrk avatar roughike avatar stephanebg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swipeselector's Issues

Add option to hide the description

When we have nothing to add in the desciption, we simply put noting in the filed "desciption" :

swipeSelector.setItems(
                new SwipeItem(0, "1", ""),
                new SwipeItem(1, "2", ""),
                new SwipeItem(2, "3", "")
);

but it's not an optimal solution, the ui is badly affected

setEnabled functionality

Hey,

I'm using your superb library but i'm missing 1 feature, after i press submit/order button i need to lock the selectors, i read the methods you already made and there was no such a thing. I also tried setEnabled(false) and it didn't work.

Is there a way that i can do that ? Thanks.

Dynamically add SwipeItems

Suppose we have 10 elements in the array. So is there any way to add 10 SwipeItems with the Java code i.e
to dynamically add 10 swipeitems ??

Title doesn't update in View after using setItems() twice

Hi!

I first set the items on create (5 items) and then later set them again using setItems() (to 2 items). They update the actual objects (Adapter and Viewpager just fine with 2 items and correct values) with the view having 2 items but the Title values in the View are not updated and show the values from the initial set (5 items).

For example if the view has title values of: "1" , "2". "3", "4", "5" on the first setItems() call, on the second setItems() call (with only values "4" and "5"), the title will have the values of "1" and "2", not the expected "4" and "5".

Please advise on how to update the view to show the updated item values?

Custom font

Hi!

Is there some opportunity to change font for my custom?

Thanks for reply!

Swipe items from SQLite ?

i already implement your library into my project and it looks marvelous. but sorry for ask, is there any clue how to set of SwipeItem objects using SQLite ? thanks.

firing initial values

I wanted to fire an initial value after populating data in adapter. It invokes only after swiping or clicking next and prev button.
selectItemWithValue or selectItemAt doesnot seems to fulfill it.

Support RTL

Hi,
thanks for the lib. I used it in my project but unfortunately it doesn't support RTL.
Chevrons are not correctly reflected. Maye be it can be done easily with autoMirrored attribute.

No resource identifier found for attribute... error

Hi,

Android 7.1.1. api25 I am unable to set any of the custom attributes, as I get "no resource found.." as per the example below:
No resource identifier found for attribute 'swipe_unselectedItemTitle' in package '...'

My root attribute has:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"

and all other custom attributes work fine.

I also tried
xmlns:app="http://schemas.android.com/apk/lib/com.roughike.swipeselector"

Using your library

Hey,
couldn't find another way to tell ya, but thanks for the awesome library:) I just wanted to say that i'm using it now and already included it's name in my app. In case you want to add it to the README, Here is the link to mine

Cheers mate!

No button option

The option to have no right/left buttons, it seems to me that some devs might want to use this.

Not found lib in maven central

I only use this if only add the jcenter to settings.gradle. Please help us to move the repo to maven central. Thanks a lot

Setting for endless scrolling (overscroll)

I like this view very much. I'm just missing one feature, namely, endless scrolling. I would like to be able to swipe right on the last item of a list to reach the first item again.

What do you think about that idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.