ScrollableNumberPicker


Source link: https://github.com/michaelmuenzer/ScrollableNumberPicker

ScrollableNumberPicker

This view provides an user-friendly numerical input interface. It can easily be customized and is built to be used on Android-TV as well.

How does it look like?

Getting started

The library is available on jcenter(). Just add these lines in your build.gradle:

dependencies {

  compile 'com.michaelmuenzer.android:ScrollableNumberPicker:0.2.2' 
}

Alternatively you can use jitpack.io

Usage

Just include ScrollableNumberPicker inside our xml-layout. There are samples available for mobile and tv applications inside this repository.

<com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker
  android:id="@+id/number_picker_horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>

If you want to change the value by scrolling on the view, you can enable and control speed like this:

<com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker
  [...]
  app:snp_scrollEnabled="true"
  app:snp_updateInterval="25"
  />

You can make use of various other custom attributes to define how the increment and decrement interactions should behave:

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

 <com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker

[...]

app:snp_maxValue="1000"

app:snp_minValue="10"

app:snp_stepSize="5"

app:snp_updateInterval="100"

app:snp_value="10"

/> </Linearlayout>

There exist further attributes which let you customize the general appearance of the view:

<com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker

[...]

app:snp_buttonIconLeft="@drawable/btn_left_selector_main"

app:snp_buttonIconRight="@drawable/btn_right_selector_main"

app:snp_buttonBackgroundTintSelector="@color/white"

app:snp_buttonTouchScaleFactor="0.8"

app:snp_orientation="horizontal"

app:snp_valueMarginEnd="5dp"

app:snp_valueMarginStart="5dp"

app:snp_value_text_color="@color/colorPrimary"

app:snp_value_text_size="16sp"

app:snp_value_text_appearance="?android:attr/textAppearanceMedium"

app:snp_buttonPaddingBottom="8dp"

app:snp_buttonPaddingLeft="8dp"

app:snp_buttonPaddingRight="8dp"

app:snp_buttonPaddingTop="8dp"

/>

You can essentially make the element look exactly like you want by using the android:background attribute:

<com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker

[...]

android:background="@drawable/number_picker_bg_color"

/>

number_picker_bg_color.xml:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"

  android:shape="rectangle">

<solid android:color="@color/green"/>

<corners android:radius="24dp"/>

<size

android:width="24dp"

android:height="24dp"/> </shape>

You can use ScrollableNumberPickerListener to build further processing logic around the selected number:

numberPicker.setListener(new ScrollableNumberPickerListener() {

  @Override
  public void onNumberPicked(int value) {

// Do some magic
  
}
 
}
);

If you use it on Android TV, please include the following to allow D-pad support.

<com.michaelmuenzer.android.scrollablennumberpicker.ScrollableNumberPicker
  android:id="@+id/number_picker_horizontal"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:focusable="true"
  android:nextFocusUp="@+id/number_picker_vertical"/>
@Override public boolean onKeyDown(int keyCode, KeyEvent event) {

  return onKey(keyCode, event);
 
}
  @Override public boolean onKeyUp(int keyCode, KeyEvent event) {

  return onKey(keyCode, event);
 
}
  private boolean onKey(int keyCode, KeyEvent event) {

  if (horizontalNumberPicker.isFocused()) {

return horizontalNumberPicker.handleKeyEvent(keyCode, event);

  
}

return false; 
}

Questions?

If you have any questions feel free to open a github issue with a 'question' label

License

Licensed under the MIT license. See LICENSE.

Resources

Android Wrapper for the Microsoft Project Oxford Emotion API.

A library to make classic bluetooth or BLE easier to use in Android.

Android annotation based SharedPreferences wrapper with fluent interface.

This is a project designed to help controlling Android MediaPlayer class. It makes it easier to use MediaPlayer ListView and RecyclerView. Also it tracks the most visible item in scrolling list. When new item in the list become the most visible, this library gives and API to track it.

Android Timeline is a custom view created to showcase the images against the time photo was taken.

This custom view enables you to simply create a beautiful looking timeline by just including this custom view in your XML file.

An extension of the Floating Action Button to keep track of the user's progress.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes