Git Product home page Git Product logo

materialnumberpicker's Introduction

MaterialNumberPicker

Release Build Status API Android Arsenal GitHub license

This library takes over the repository that I originally created and passed on but seems no longer maintained. It was ported in Kotlin to provide clearer and more optimized code, and includes various features that are still pending in the previous library. It also provides optionals and nullables with a custom constructor so that you can customize your picker the way you want without using a verbose builder pattern.

Native NumberPicker MaterialNumberPicker (default) MaterialNumberPicker (custom)
Default picker Simple picker Custom picker

Gradle Dependency

Add this in your root build.gradle file:

allprojects {
    repositories {
	maven { url "https://jitpack.io" }
    }
}

Then add the dependencies that you need in your project.

dependencies {
    compile "com.github.StephenVinouze:MaterialNumberPicker:{latest_version}"
}

Usage

Both XML and programmatic instanciations are supported :

<com.github.stephenvinouze.materialnumberpickercore.MaterialNumberPicker
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:mnpMaxValue="50"
    app:mnpMinValue="1"
    app:mnpEditable="false"
    app:mnpFontname="Hand.ttf"
    app:mnpSeparatorColor="@color/colorAccent"
    app:mnpTextColor="@color/colorPrimary"
    app:mnpTextSize="16sp"
    app:mnpTextStyle="bold"
    app:mnpValue="10"
    app:mnpWrapped="false" />
val numberPicker = MaterialNumberPicker(
    context = this,
    minValue = 1,
    maxValue = 50,
    value = 10,
    separatorColor = ContextCompat.getColor(this, R.color.colorAccent),
    textColor = ContextCompat.getColor(this, R.color.colorPrimary),
    textSize = resources.getDimensionPixelSize(R.dimen.numberpicker_textsize),
    textStyle = Typeface.BOLD_ITALIC,
    editable = false,
    wrapped = false,
    fontName = "Hand.ttf",
    formatter = NumberPicker.Formatter {
        return@Formatter "Value $it"
    }
)

For Java users, I have overloaded the constructor so that it generates all possible constructors.

MaterialNumberPicker numberPicker = new MaterialNumberPicker(
    this,
    1,
    50,
    10,
    ContextCompat.getColor(this, R.color.colorAccent),
    ContextCompat.getColor(this, R.color.colorPrimary),
    getResources().getDimensionPixelSize(R.dimen.numberpicker_textsize),
    Typeface.BOLD_ITALIC,
    false,
    false,
    "Hand.ttf",
    new NumberPicker.Formatter() {
        @Override
        public String format(int i) {
            return "Value " + i;
        }
    }
);

I have arranged the parameters in priority order but it is not as ideal as with Koltin because you can't name the attributes nor change their orders. However, all attributes are exposed with getter/setters so you can easily set the desired attributes after instanciating the picker with the default constructor.

MaterialNumberPicker numberPicker = new MaterialNumberPicker(this);
numberPicker.setTextColor(ContextCompat.getColor(this, R.color.colorPrimary));

Once you have your number picker, you can present it by itself, or within an alert dialog :

AlertDialog.Builder(this)
    .setTitle(title)
    .setView(numberPicker)
    .setNegativeButton(getString(android.R.string.cancel), null)
    .setPositiveButton(getString(android.R.string.ok), { _, _ ->
        Toast.makeText(this, getString(R.string.picker_value, numberPicker.value), Toast.LENGTH_LONG).show()
    })
    .show()

The only attribute that cannot be defined through XML is the formatter that is natively included in the NumberPicker. It can be directly assigned from the custom constructor when instanciating programmaticaly. Note that all attributes have their own getter/setters and can be upcated anytime durnig your view's lifecycle.

We also provide a way to define either your text style within the picker or a custom font. Be aware though that once you define a custom font, the text style will be overriden by the custom font and won't be interpreted.

Pull requests

I welcome and encourage all pull requests. I might not be able to respond as fast as I would want to but I endeavor to be as responsive as possible.

All PR must:

  1. Be written in Kotlin
  2. Maintain code style
  3. Indicate whether it is a enhancement, bug fix or anything else
  4. Provide a clear description of what your PR brings
  5. Enjoy coding in Kotlin :)

materialnumberpicker's People

Contributors

jahirfiquitiva avatar stephenvinouze 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

materialnumberpicker's Issues

Font

i can't find Constructor that have fontName and any thing related to font in this what is the problem?

Picker stopped showing when upgrading to api 29

it actually still functions, but nothing is displayed, meaning, if I click on the right place on the screen, a number will be picked, but I don't see any numbers or dividers.
any idea why?

Suggestions for readme

  • screenshots
  • usage explanation
  • list all attributes, parameters,...
  • add license info

Thanks for maintaining this lib.

How do I set a range

like a minimum range of 5. So the next values will be 5, 10,15,20,25,30,35 in the number picker.

Issue with font size

I'm using fontsize as 32sp. On a oneplus 6. Android Q. Stable. But the font size is not changing at all. I tried app:mnpTextSize="32sp" and also materialNumberPicker.setTextSize(32); but no luck. Can you please check it? thanks!

Java

I'm not using Kotlin right now. How could I use this lib with Java?

Change the separator width margin

Is there any way to change the separator width's margin from match_parent to say have margin of 20 dp to start and end..

Basically, I want the separator to have some offset from the edges of the screen. It would look a lot pretty that way.

Two NumberPicker in one Alert

Hello!

First of all, thank you for this library!
I'm trying to make an picker alert but with two numberPickers (for exemple to choose the weight with the kilos and the grammes after), but can't find the way to do it.
I've tried to change the function presentPickerInAlert with two NumberPickers but cound't find how to set 2 views.
Can you help me with that?
Thank you

Some interesting info.

Please Note: THIS IS NOT AN ISSUE. Just some cool facts.

I'm going through a few apps that I've been assigned to dissemble and reverse engineer, and I found that a company called PetSafe, seems to be using this script in their source code. Not sure if you know, thought it would be nice to know. I've never had anyone ever use my code, which is understandable. I'm not the greatest, tho I've been trying for 7 years now.

Reverse Engineering Version of app: 1.4.0 build 43
App name: My PetSafe

Screenshot 2024-03-18 at 7 11 10 PM

Separator color always black

Not sure if it's onli API29, but that's my target. Separator color is always black no matter what color I set it, however, it appears right on the layout editor - just not on the actual build. I'm setting color in xml.

Constructor default for wrapped is DEFAULT_EDITABLE

As per title, the default for the wrapped constructor argument is DEFAULT_EDITABLE instead of DEFAULT_WRAPPED. Just a minor bug, since actually they're both false and the default behavior is eventually working as intended.

Show more than 3 values

Hello,
Thanks for putting out such a great work. I'd like to display about 10 items (instead of 3) at once on the picker. Please kindly advise on how to implement that. I am using Java. Thank you.

Which version is it?

implementation 'com.github.StephenVinouze:MaterialNumberPicker:1.1.0'

I managed to find this working version, but I'm not sure if it's the last one available...
could you specify the current version in the README file?

or maybe I'm missing something? I'm not an expert on android studio, especially with dependencies, so maybe it just flew over my head...

Attributes not apply on Adroid 10

Tried Android 9 and Android 10
Android 9 is good, but for 10 attributes not apply
I use material components lib (may be this help)

crashing when custom font is set

maybe I'm doing this totally wrong. But I have a custom font and I need to set it. I tried passing just the string of the font. which i have in res/font/montessara_light_black as "montessara_light_black" in the setFont. It just crashed.
Can you show how to do that?

Request: Increase density of numbers shown on picker

Hello!

I would like to be able to have the option to set a density of the number of items displayed in the picker. The AOSP default NumberPicker also shows three at a time, but this feels too loose or sparse for some UI preferences.

I believe this is also what #7 was asking for as well.

screen shot 2018-07-12 at 1 10 01 pm
The above image shows the iOS analogy to Android's NumberPicker.

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.