Git Product home page Git Product logo

Comments (19)

Carbs0126 avatar Carbs0126 commented on June 23, 2024

sorry i have not add customizing font function, you can custom font in NumberPickerView by using code:

mPaintText.setTypeFace(...);

when mPaintText is initialized.

i will add this function later

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

Thanks, for fast answer.
I try to edit the file within Android Studio but I can't edit the file. It's locked :(
Any Idea about this?

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

After some search, I manage to import the project as module and was able to edit the file but what I should put in mPaintText.setTypeFace(...); ?
I tried those but didn't work:

mPaintText.setTypeface(Typeface.create("2Toon", Typeface.BOLD)); mPaintText.Typeface.createFromAsset(getContext().getAssets(), "2Toon.ttf"); mPaintText.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"fonts/2Toon"));

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on June 23, 2024

sorry for not replying in time, you can add a method

public void setContentTextTypeface(Typeface typeface){
        mPaintText.setTypeface(typeface);
    }

    public void setHintTextTypeface(Typeface typeface){
        mPaintHint.setTypeface(typeface);
    }

and invoke this method outside in oncreate method , if you want to change typeface dynamicly, using mNumberPickerView.invalidate( ) after using this method

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

No Problem :)
I solved the problem by adding:
mPaintText.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/MyFont.ttf"));
It worked for me. I don't know if it's a good practice to do it in that way though.

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on June 23, 2024

if you have used MyFont.ttf, you can use a static value to refer to this MyFont.ttf, in this way you can avoid memory leak, because every time you use

Typeface.createFromAsset(context.getAssets(),"fonts/MyFont.ttf")

MyFont.ttf will be created again and added into memory.

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

I don't understand what you mean by "...use a static value to refer to this MyFont.ttf".
How can I use a static value to refer to the custom font I want use?

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on June 23, 2024

i mean you can use cache to refer to MyFont.ttf, in this way, if you use MyFont.ttf again, you can get MyFont.ttf from cache,
just like

public static Typeface cache = Typeface.createFromAsset(context.getAssets(),"fonts/MyFont.ttf")

mPaintText.setTypeface(cache);

this will avoid memory leak

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

Ah okay, I got it now. I'll change it.
But compared to [your solution], what are the differences/advantages?(#17 (comment))

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on June 23, 2024

if there are many numberpickerviews in you app( or other views which use MyFont.ttf), there will be many copy of MyFont.ttf, but in fact only one MyFont.ttf is enough

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

Cool, I got it :) Thank you very much.

Off Topic:
Is their a way to display the selected numbers while scrolling?
I tried to put it in the the onScrollStateChange methode but it randomly crash my app.

Like in this gif:
http://i.imgur.com/d3ZMjss.gif

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on June 23, 2024

i have not add this function, if you need this function now, you can add some code into

calculateFirstItemParameterByGlobalY()

and get the index of current selected item by mCurrDrawFirstItemIndex and mCurrDrawFirstItemY, and set this index value to another value such as 'currSelected', and use a 'prevSelected' to store the last selected one in scrolling, if currSelected != prevSelected, then number changed. i will add this function later :)

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on June 23, 2024

i have added a method

    picker.setOnValueChangeListenerInScrolling(...);

you can get changed value while in scrolling

and i have also added two methods for changing typeface of text/hint in NumberPickerView,
just update dependence version of NumberPickerView to 1.1.1

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

Oh, Great,
I just try it , it's working but the scrolling is not smooth. It lags a lot.

`

@Override

public void onValueChangeInScrolling(NumberPickerView picker, int oldVal, int newVal) {
    myChosedNumber.setText(picker.getContentByCurrValue());
 }

`

Is there a better way to make it as smooth as in the gif

from numberpickerview.

Carbs0126 avatar Carbs0126 commented on June 23, 2024

this callback will be invoked once as number value changed for 'one item', and this callback runs in main thread , if you want to do some complicated work in this callback such as play sound, it may make scrolling lag. To make scrolling smoothly you can use handler to send message in this callback ,or make callback tasks run in a new thread, if it still lag, you can send your code to me ,and maybe i can refine this project according to your code

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

Hi, I sent just you the project via email,
I've tried to put the code in a Runnable as well in a AsyncTask but it was still laggy.

I planned to add a scrolling sound but It's not much of a big deal if it may create (lag) problems...

If you need any info, let me know.

from numberpickerview.

4goodapp avatar 4goodapp commented on June 23, 2024

And by the way, I've try the project in that gif on my phone and it was working smoothly, just like in the gif.

I found that project from here, Just in case it may help.

from numberpickerview.

tinsukE avatar tinsukE commented on June 23, 2024

@Carbs0126 Can you update the version in the README file to 1.1.1?

I was trying to branch the repo to add the Typeface functionality, but saw that it was already implemented in this version (which is not refereed to anywhere).

from numberpickerview.

rohankandwal avatar rohankandwal commented on June 23, 2024

I have created a fork of the project which allows custom font loading from xml itself. I will be glad if you can take a look at it.
https://github.com/rohankandwal/NumberPickerView

from numberpickerview.

Related Issues (20)

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.