Android library that allows applications to add dialog-based slider widgets to their settings

Overview

Android Slider Preference Library

A dialog-based preference that provides slider widget functionality. Useful for settings where the range of values are not discrete and fall along a continuum. This preference will store a float between 0.0 and 1.0 in the SharedPreferences.

Overview

  • Slider represents a float between 0.0 and 1.0
  • Supports multiple summaries (e.g. "Low", "Medium", "High") and selects one based on the slider's position
    • Java: SliderPreference.setSummary(CharSequence[] summaries)
    • XML: android:summary="@array/string_array_of_summaries"
    • A single String still works too
  • Subclass of DialogPreference
    • Supports all dialog-specific attributes such as android:dialogMessage
    • Visually-consistent with Android's built-in preferences
    • Less error-prone than displaying the slider directly on the settings screen
  • MIT License

How To Use

Android Studio

Using Gradle

  1. Step: Add JitPack to your root build.gradle:
allprojects {
	repositories {
		// [...]
		maven { url 'https://jitpack.io' }
	}
}
  1. Step: Add the library as a dependency to your project build.gradle:
dependencies {
    // [...]
    compile 'com.github.jayschwa:AndroidSliderPreference:v1.0.1'
}

Using a Module

  1. Paste or clone this library into the /libs folder, in the root directory of your project. Create a new folder: /libs if not already present. (This step is not required - only for keeping cleaner project structure)

  2. Edit settings.gradle by adding the library. You also have to define a project directory for the library. Your settings.gradle should look like below:

    include ':app', ':SliderPreference'
    project(':SliderPreference').projectDir = new File('libs/AndroidSliderPreference')
    
  3. In app/build.gradle add the SliderPreference library as a dependency:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:21.0.3'
        compile project(":SliderPreference")
    }
    
  4. Sync project, clean and build. You can use the SliderPreference as part of your project now.

Eclipse

Before you can add a SliderPreference to your application, you must first add a library reference:

  1. Clone or download a copy of the library
  2. Import the library into Eclipse: File menu -> Import -> Existing Project into Workspace
  3. Open your application's project properties and add a library reference to "SliderPreference"

Add a slider to your application

<!-- preferences.xml -->
<net.jayschwa.android.preference.SliderPreference
    android:key="my_slider"
    android:title="@string/slider_title"
    android:summary="@array/slider_summaries"
    android:defaultValue="@string/slider_default"
    android:dialogMessage="@string/slider_message" />
<!-- strings.xml -->
<string name="slider_title">Temperature</string>
<string-array name="slider_summaries">
    <!-- You can define as many summaries as you'd like -->
    <!-- The active summary will reflect the preference's current value -->
    <item>Freezing</item> <!-- 0.00 to 0.25 -->
    <item>Chilly</item>   <!-- 0.25 to 0.50 -->
    <item>Warm</item>     <!-- 0.50 to 0.75 -->
    <item>Boiling</item>  <!-- 0.75 to 1.00 -->
</string-array>
<item name="slider_default" format="float" type="string">0.5</item>
<string name="slider_message">Optional message displayed in the dialog above the slider</string>

It is possible to define the default value directly in the attribute. The summary can also be a regular string, instead of a string array:

<net.jayschwa.android.preference.SliderPreference
    android:summary="This summary is static and boring"
    android:defaultValue="0.5" />

Background

Sliders are recommended by Android's official design documentation for specific types of settings:

Use this pattern for a setting where the range of values are not discrete and fall along a continuum.

Slider design pattern example

Despite this recommendation, the Android SDK does not actually provide a Preference with slider functionality. Various custom implementations can be found around the web, but many have issues such as:

  • The slider is displayed directly on the settings screen
    • Higher chance of accidental clicks
    • No way to confirm or cancel potential changes
  • Discrete values are displayed to the user
    • Not ideal for this design pattern

This library aims to be as consistent as possible with the design pattern and Android's built-in Preference implementations.

License

This library is licensed under the MIT License. A copy of the license is provided in LICENSE.txt:

Copyright 2012 Jay Weisskopf

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Add Logarithmic Scaling Option

    Add Logarithmic Scaling Option

    Adds a subclass of SliderPreference that maps its value to a logarithmic scale when it saves.

    The current implementation is great for settings used an additive manner, but less so for settings used in a multiplicative manner1, as perceived effects will vary by value2. Typically, sliders avoid this by applying a logarithmic scale to their output, but no such option currently exists for the Android Slider Preference library.

    This pull request adds the aforementioned functionality with the following edits:

    • In SliderPreference, the setValue function has been broken into several different functions, to allow subclasses to hook persistence calls correctly. Externally, the class functions exactly the same as it did previously, and the amount of internal change is kept as minimal as possible.
    • A new class LogarithmicSliderPreference has been added to the package net.jayschwa.android.preference. It is a subclass of SliderPreference, and has behavior identical to its parent, with the exception of functions that export or import slider values. These functions contain additional logic which maps the internal linear scale to an external logarithmic one, with float values between 0.0 and 10.0.
    • Documentation has been updated to reference the new implementation.

    1: Volume, for example. 2: One can observe this by considering 0.5 to be the default value, and calculating the effective multipliers created by high and low values. 1.0 only doubles the default, but 0.1 decreases it by a factor of 5.

    opened by rarcher 6
  • Metadata Automation

    Metadata Automation

    This update simplifies the build process by eliminating redundant copies of several metadata constants, replacing them instead with Gradle code that distributes their values automatically.

    More specifically:

    • The target SDK version now exists only in the project.properties file, and is read via a Properties object.
    • The version code is set equal to the number of tags currently in the Git repository, with each tag representing a single release.
    • The version name is set to the name of the most recent Git tag, with some additional descriptive text added if the current HEAD does not point directly to a tagged commit (it's actually just Git's describe command).

    Changes have been tested, and seem to work without any problems.

    opened by rarcher 5
  • Update for Android Plugin Compatibility

    Update for Android Plugin Compatibility

    The latest Android plugin is not compatible with the build tools version requested by the library, and Gradle will forcibly update the latter if you attempt to use the two together. The build tools version that Gradle suggests seems to work without any problems, so please make it the official version of the library.

    opened by rarcher 2
  • Cleanup of Android API Settings

    Cleanup of Android API Settings

    Eclipse's insistence on having Android 17 installed was annoying, so I cleaned up the API settings a bit.

    More specifically:

    • Updated Eclipse's project.properties file to match the manifest.
    • Removed the minimum and target API settings from the build.gradle file. These are only needed if you want to overwrite the corresponding values in the manifest, and since they are identical to those in the manifest, they are redundant.

    Changes have been tested, and seem to work without any problems.

    opened by rarcher 2
  • Add Range Constants

    Add Range Constants

    As a follow-up to #7, could I convince you to accept a smaller update as a compromise? This just makes the slider's maximum and minimum values available as public constants, so they don't have to be duplicated in client code when doing scaling.

    opened by rarcher 2
  • Feature/maven jitpack

    Feature/maven jitpack

    "Fixing" issue #4 by providing a source on maven using JitPack.

    Please make sure that you put a tag called "1.0" on 97f28cf. When that is done I will trigger the building process and it will be available as described in the README.md

    Edit: The hash for the commit was wrong! It should be the latest commit: 97f28cf

    Edit2: Btw: I needed to add the classpath/repo to make it remotely buildable

    opened by meierjan 2
  • Updated and made project Android Studio compatible

    Updated and made project Android Studio compatible

    1. Added a build.gradle file
    2. Updated AndroidManifest.xml for Lollipop Compatibility
    3. Updated Readme.md with instructions for AS
    4. Tested and used code up to Lollipop (API 21)
    opened by JudeRosario 2
  • wrong gradle documentation

    wrong gradle documentation

    The documentation should be rewrite with :

    allprojects {
        repositories {
            maven { url "https://jitpack.io" }
        }
    }
    
    dependencies {
        
        compile 'com.github.jayschwa:AndroidSliderPreference:v1.0.0'
    }
    

    compile 'com.github.jayschwa:AndroidSliderPreference:1.0' doesn't exist

    opened by dragouf 1
  • Cannot resolve library tag in maven repo

    Cannot resolve library tag in maven repo

    Hi,

    Please create 1.0 tag, because now it is not possible to download the library from the maven. I know I can specify commit or branch, but we have tags so please use it.

    dependencies { // [...] compile 'com.github.jayschwa:AndroidSliderPreference:1.0' }

    opened by pzienowicz 1
  • sliderpreference error

    sliderpreference error

    setSummary(getContext().getResources().getStringArray(summaryResId));

    Android studio say Error:(93) Error: Expected resource of type array [ResourceType]

    can you take a look. its in sliderPreference class. i turned off lint but then it says indexoutofbounds error.

    opened by j2emanue 1
  • Misleading setup for

    Misleading setup for "Using a Module"

    Document says that you should clone the repository into your libs folder. This will create a folder called AndroidSliderPreference.

    The document goes on to tell you to all the following to your settings.gradle.

    project(':SliderPreference').projectDir = new File('libs/SliderPreference')

    This causes an error during gradle sync as there is no SliderPreference folder.

    I propose updating the documentation to:

    project(':SliderPreference').projectDir = new File('libs/AndroidSliderPreference')

    opened by liquidvapour 1
Releases(v1.0.1)
Owner
Jay Petacat
Jay Petacat
Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but with this dialog you can do all thats with only one dialog.

# Media Recorder Dialog ![](https://img.shields.io/badge/Platform-Android-brightgreen.svg) ![](https://img.shields.io/badge/Android-CustomView-blue.sv

Abdullah Alhazmy 73 Nov 29, 2022
ionalert 1.3 1.6 Java Sweetalert, Dialog, Alert Dialog

ionalert - Android Alert Dialog A beautiful design Android Alert Dialog, alternative of Sweet Alert Dialog based on KAlertDialog using MaterialCompone

Excel Dwi Oktavianto 23 Sep 17, 2022
Alert Dialog - You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment.

We show a warning message (Alert Dialog) to the user in many parts of our applications. You can use this extension instead of creating a separate Alert Dialog for each Activity or Fragment. Thanks to this extension, you can create a Dialog and call it in the Activity or Fragment you want and customize the component you want.

Gökmen Bayram 0 Jan 9, 2022
Extremely useful library to validate EditText inputs whether by using just the validator for your custom view or using library's extremely resizable & customisable dialog

Extremely useful library for validating EditText inputs whether by using just the validator (OtpinVerification) for your custom view or using library's extremely resizable & customisable dialog (OtpinDialogCreator)

Ehma Ugbogo 17 Oct 25, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
An Android library for displaying a dialog where it presents new features in the app.

WhatIsNewDialog What is new dialog for Android is used for presenting new features in the the app. It can be used in the activity starts, from menu or

NonZeroApps 22 Aug 23, 2022
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

Keisuke Kobayashi 553 Nov 23, 2022
A simple library to show custom dialog with animation in android

SmartDialog A simple library to show custom dialog in android Step 1. Add the JitPack repository to your build file allprojects { repositories {

claudysoft 9 Aug 18, 2022
An beautiful and easy to use dialog library for Android

An beautiful and easy to use dialog library for Android

ShouHeng 22 Nov 8, 2022
CuteDialog- Android Custom Material Dialog Library

A Custom Material Design Dialog Library for Android Purpose CuteDialog is a Highly Customizable Material Design Android Library. CuteDialog allows dev

CuteLibs - Smart & Beautiful Android Libraries 7 Dec 7, 2022
AlertDialog for Android, a beautiful and material alert dialog to use in your android app.

AlertDialog for Android, a beautiful and material alert dialog to use in your android app. Older verion of this library has been removed

Akshay Masram 124 Dec 28, 2022
Advanced dialog solution for android

DialogPlus Simple and advanced dialog solution. Uses normal view as dialog Provides expandable option Multiple positioning Built-in options for easy i

Orhan Obut 5k Dec 29, 2022
SweetAlert for Android, a beautiful and clever alert dialog

Sweet Alert Dialog SweetAlert for Android, a beautiful and clever alert dialog 中文版 Inspired by JavaScript SweetAlert Demo Download ScreenShot Setup Th

书呆子 7.3k Dec 30, 2022
An Android Dialog Lib simplify customization.

FlycoDialog-Master 中文版 An Android Dialog Lib simplify customization. Supprot 2.2+. Features [Built-in Dialog, convenient to use](#Built-in Dialog) [Ab

Flyco 2.3k Dec 8, 2022
[Deprecated] This project can make it easy to theme and custom Android's dialog. Also provides Holo and Material themes for old devices.

Deprecated Please use android.support.v7.app.AlertDialog of support-v7. AlertDialogPro Why AlertDialogPro? Theming Android's AlertDialog is not an eas

Feng Dai 468 Nov 10, 2022
A simple file/ directory picker dialog for android

FileListerDialog FileListerDialog helps you to list and pick file/directory. Library is built for Android Getting Started Installing To use this libra

Yogesh S 446 Jan 7, 2023
a quick custom android dialog project

QustomDialog Qustom helps you make quick custom dialogs for Android. All this is, for the time being, is a way to make it easy to achieve the Holo loo

Daniel Smith 183 Nov 20, 2022
AlertDialog - Explain about Alert Dialog in Android

AndroidTemplate I got a problem to create Android project with Java 11 and anoth

Monthira Chayabanjonglerd 1 Feb 13, 2022
An easy to use, yet very customizable search dialog

search-dialog An awesome and customizable search dialog with built-in search options. Usage First add jitpack to your projects build.gradle file allpr

Mad Mirrajabi 518 Dec 15, 2022