B4A Library BAJLocale: A holistic approach to internationalization for B4(A/J) application (Part 2)

In that post B4Multilingual I have started to describe a Windows program (B4Multingual) that I have been developing to maintain multilingual B4A and B4J applications. As that post is mainly about the tool itself and is bound to grow bigger as documentation gets gradually added to it, I thought that a different post, which deals exclusively with the localization aspect and the B4(A/J) library was warranted. You may use the library (source code will be released at a later date when comments and source have been tidied up) without the tool, but B4Multingual offers some real advantages.

There are a few excellent implementations of localization developed by fellows BA coders on this forum, in particular:
RiverRaid's AHATranslate class and corwin42's AHLocale library. Warwound offers a library too and a short and concise tutorial you can find here.

You might actually be using one of them and be very happy with it. I was. So why did I create a new library?

I wanted, as part of my toolchain, a solution that would allow me to work on multilingual applications with the following criteria in mind:
  1. It should necessitate little or no coding.
  2. The translations should be easy to maintain.
  3. The text assignments should be as clear and concise as possible
  4. The implementation should be able to cope with ad hoc translations and localization (Java i18n)
  5. The implementation should cope with B4A and B4J applications transparently.
  6. Allow for scaffolding (i.e. to a quickly set up skeleton for an app.)
  7. The code should all be written in BA (no java) and the source available freely.
Points 1 & 2 are taken care of by the Windows tool mentioned at the start of this post. The tool can generate pure B4(A/J) code or a mixture of XML files with B4(A/J) code.

Points 3, 4 & 5 are taken care of by the code generated by the tool and the set of classes (library for now) that wrap some of the Android classes.

Point 6 is yet to be implemented, but the foundations are already in place in the Windows app.

Point 7 will be addressed as I keep developing this post. The no java rule has not been put forward out of dislike for java, but because I find it quite a chore to have to keep switching editors (one for java and one for B4(A/J)) when developing. Not only that, but the hassle of compiling libraries outside the BA editor is a pain. I wished for in-situ java, but I don't see that happening anytime soon. The consequence of this choice is that the BAJLocale library is 99% reflection based.

The BAJLocale library wraps the following Android classes:

AJLocale -> Locale
AJCurrency -> Currency
AJDateFormat -> DateFormat
AJDate -> Date
AJCalendar -> Calendar
AJSimpleDateFormat -> SimpleDateFormat
AJDateFormatSymbols -> DateFormatSymbols
AJSimpleDateFormat -> SimpleDateFormat
And adds 2 helper classes AJResources and AJHelper

It aims at providing localization to B4A and B4J applications.

If you are still reading this post after this long preamble, here's some meatier stuff.

I have attached a BA demo that showcases some of the possibilities of this library. Before running it, you'll need to deploy the library (jar + xml) into your shared library folder. The demo itself is in essence based, with permission, on corwin42's own demo. Though the demo GUI is essentially the same and his, I have added a few views and the code and library are original.

The localization business is encapsulated in the class generated by B4Multingual and the attached BAJLocale library.

First declare an object of type Tr (or whatever you will call the class).
B4X:
Sub Globals
   Private oTr As Tr
   '...
End Sub

Then initialize it and assign values to the relevant views:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   oTr.Initialize
   '...
   Activity.Title = oTr.title
   lbCurrency.Text = oTr.currency
   lbFirstDayOfWeek.Text = oTr.first_week_day
   lbCurrentLanguage.Text = oTr.current_language
   btParameter.Text = oTr.trans_with_var_values
End Sub
As you can tell, it's extremely simple and easy on the eye and the fingers. You can shorten the object name further (T for example) if you wish.

NB: The translations have been generated with Bing Web Service (using B4Multingual) and may not be accurate. Actually, some are definitely wrong, but I decided to leave them in as is, as a reminder that automated translation lacks context and needs to be manually checked.
10fe54g.jpg

If you are dealing with arrays of strings, say planets, the syntax is as concise and easy to follow:
B4X:
  'Fill spinner view with localized planet values
  spPlanets.Clear
  '
  For Each planet In oTr.planets_Map.Values
    spPlanets.Add(planet)
  Next
2uhsujc.jpg

A few comments about the generated class (Tr) which is shown further below. The Class_Globals sub declares a few objects that map the Android java classes as faithfully as possible. These objects are not really used in the class itself, but are there as a convenient way of getting localization related stuff in one class. So for instance, if you wish to display all localized months in a spinner for the current locale say, you could do it this way:
B4X:
  'Fill spinner view with localized month values
  spMonths.Clear

  For Each month In oTr.AJCalendar.GetDisplayNames(oTr.AJCalendar.MONTH, oTr.AJCalendar.LONG, oTr.AJLocale.Locale)
    spMonths.Add(month)
  Next
fbe3iq.jpg

It looks a bit of a mouthful. It's on purpose as I like to know which Android function I am calling from b4(A/J) code. If you don't like this, you can edit the generated code (Tr class) and add a new sub that'll hide the hideous details:
B4X:
Public Sub getLongMonths As List
   Return oAJCalendar.GetDisplayNames(oAJCalendar.MONTH, oAJCalendar.LONG, oAJLocale.Locale)
End Sub

And the call from the activity would look like this:
B4X:
  For Each month In oTr.LongMonths
     spMonths.Add(month)
   Next
Which might be more palatable.

I will (at a later date) add an option in BAJMultilingual to do just that automatically.

Another feature is the presence of multiple Initializers. One of the disadvantages of developing classes in B4(A/J) instead of Java, is the restriction to only one Initializer, as per the documentation and confirmed by Erel's statement. Sure the initializer may accept arguments as well, but at the end, there can be only one initializer per class. Fortunately, there are various ways of lifting that restriction. One is demonstrated in the code below:

Most of the time you'll only want to initialize a Tr object by calling Initialize as it will keep in synch with the device current chosen locale and your chosen default language. The default language is the one which is used when no translations are available. However, you may want to decide to use a different default language, such as French instead of English say. In this particular case you would initialize the object this way:
B4X:
  oTr.Initialize2("fr")
To allow this to happen in a pure BA class you must ensure that your extra initializers call B4A's private method innerInitialize.This is taken care of by the sub InternalInitialize that makes a reflection call to do just that.
B4X:
Private Sub InternalInitialize
   Dim r As Reflector
   r.Target = Me
   r.Runmethod4("innerInitialize", Array As Object(r.GetProcessBA("main")), Array As String("anywheresoftware.b4a.BA"))
End Sub
Therefore by calling InternalInitialize at the beginning of your extra initializers you get the benefit of multiple initializers without having to create your libraries in Java. (It's possible to call your own class Initializer as well and therefore benefit from multiple initializers. I'll describe a method later on.)
B4X:
Public Sub Initialize
   PopulateTranslate
   oAJLocale.InitializeDefault
   SetHelperClasses(oAJLocale.Locale)

   default_language_translation_ = EN
End Sub

Public Sub Initialize2(default_language_translation As String)
   InternalInitialize
   '
   PopulateTranslate
   oAJLocale.Initialize(default_language_translation)
   SetHelperClasses(oAJLocale.Locale)

   default_language_translation_ = default_language_translation
End Sub

In a future post, there will be further commenting on the generated and the the AJLocale class will be described in detail.
Generated code
B4X:
'B4Multingual B4A/B4J Generated Code
Private Sub Class_Globals
   Private translationMap As Map
   Private oAJLocale As AJLocale
   Private oAJDateFormatSymbols As AJDateFormatSymbols
   Private oAJCalendar As AJCalendar
   Private oAJCurrency As AJCurrency
   Private oAJDateFormat As AJDateFormat
   Private default_language_translation_ As String
   '
#Region varSYMBOLS
   Private const clubs_ As Int = 4
   Private const currency_ As Int = 5
   Private const currency_symbol_ As Int = 6
   Private const current_language_ As Int = 7
   Private const diamonds_ As Int = 10
   Private const first_week_day_ As Int = 12
   Private const hearts_ As Int = 13
   Private const planets_ As Int = 23
   Private const select_lang_ As Int = 29
   Private const select_month_ As Int = 30
   Private const select_weekday_ As Int = 31
   Private const spades_ As Int = 39
   Private const suits_ As Int = 42
   Private const title_ As Int = 46
   Private const trans_with_var_values_ As Int = 47
   Private const variable_message_ As Int = 48
   Private const car_ As Int = 49
   Private const planets__ As Int = 51
#End Region varSYMBOLS

#Region varLOCALES
   Private const EN As String = "en" 'English:Default Language
   Private const FR As String = "fr" 'French
   Private const IT As String = "it" 'Italian
#End Region varLOCALES
End Sub

#Region Initialize Methods
Private Sub InternalInitialize
   Dim r As Reflector
   r.Target = Me
   r.Runmethod4("innerInitialize", Array As Object(r.GetProcessBA("main")), Array As String("anywheresoftware.b4a.BA"))
End Sub

Public Sub Initialize
   PopulateTranslate
   oAJLocale.InitializeDefault
   SetHelperClasses(oAJLocale.Locale)

   default_language_translation_ = EN
End Sub

Public Sub Initialize2(default_language_translation As String)
   InternalInitialize
   '
   PopulateTranslate
   oAJLocale.Initialize(default_language_translation)
   SetHelperClasses(oAJLocale.Locale)

   default_language_translation_ = default_language_translation
End Sub

Private Sub SetHelperClasses(Locale As JavaObject)
   oAJDateFormatSymbols.Initialize2(Locale)
   oAJCalendar.GetInstance2(Locale)
   oAJDateFormat.Initialize
   oAJDateFormat.GetDateInstance3(oAJDateFormat.DEFAULT, Locale)
   oAJDateFormat.SetCalendar(oAJCalendar.Calendar)
   Try
     oAJCurrency.GetInstance(Locale)
   Catch
     Log(LastException)
   End Try
End Sub
#End Region Initialize Methods

#Region LOCALES
Public Sub getEnglish As String
   Return EN
End Sub
Public Sub getFrench As String
   Return FR
End Sub
Public Sub getItalian As String
   Return IT
End Sub
#End Region LOCALES

#Region KEYS
Public Sub getclubs As String
   Return Get_(clubs_)
End Sub
Public Sub getcurrency As String
   Return Get_(currency_)
End Sub
Public Sub getcurrency_symbol As String
   Return Get_(currency_symbol_)
End Sub
Public Sub getcurrent_language As String
   Return Get_(current_language_)
End Sub
Public Sub getdiamonds As String
   Return Get_(diamonds_)
End Sub
Public Sub getfirst_week_day As String
   Return Get_(first_week_day_)
End Sub
Public Sub gethearts As String
   Return Get_(hearts_)
End Sub
Public Sub getplanets As String
   Return Get_(planets_)
End Sub
Public Sub getselect_lang As String
   Return Get_(select_lang_)
End Sub
Public Sub getselect_month As String
   Return Get_(select_month_)
End Sub
Public Sub getselect_weekday As String
   Return Get_(select_weekday_)
End Sub
Public Sub getspades As String
   Return Get_(spades_)
End Sub
Public Sub getsuits As String
   Return Get_(suits_)
End Sub
Public Sub gettitle As String
   Return Get_(title_)
End Sub
Public Sub gettrans_with_var_values As String
   Return Get_(trans_with_var_values_)
End Sub
Public Sub getvariable_message As String
   Return Get_(variable_message_)
End Sub
Public Sub getcarMap As Map
   Return GetMap_(car_)
End Sub
Public Sub getplanets_Map As Map
   Return GetMap_(planets__)
End Sub
#End Region KEYS

#Region Public Methods
Public Sub getAJLocale As AJLocale
   Return oAJLocale
End Sub

Public Sub setAJLocale(AJLocale As AJLocale)
   oAJLocale = AJLocale
   SetHelperClasses(oAJLocale.Locale)
End Sub

Public Sub getAJDateFormatSymbols As AJDateFormatSymbols
   Return oAJDateFormatSymbols
End Sub

Public Sub getAJCalendar As AJCalendar
   Return oAJCalendar
End Sub

Public Sub getAJCurrency As AJCurrency
   Return oAJCurrency
End Sub

Public Sub setAJCurrency(AJCurrency As AJCurrency)
   oAJCurrency = AJCurrency
End Sub

Public Sub getAJDateFormat As AJDateFormat
   Return oAJDateFormat
End Sub

Private Sub Get_(symbol As Int) As String
   Return Get(symbol, oAJLocale.GetLanguage)
End Sub

Public Sub Get(symbol As Int, lang As String) As String
   Dim line_map As Map
   line_map = translationMap.Get(symbol)
   Return(line_map.GetDefault(lang, line_map.Get(default_language_translation_)))
End Sub

Private Sub GetMap_(symbol As Int) As Map
   Return GetMap(symbol, oAJLocale.GetLanguage)
End Sub

Public Sub GetMap(symbol As Int, lang As String) As Map
   Dim lines_map As Map
   lines_map = translationMap.Get(symbol)
   Return lines_map.GetDefault(lang, lines_map.Get(default_language_translation_))
End Sub
#End Region Public Methods

Private Sub PopulateTranslate
   Dim line_map As Map
   Dim lines_map As Map
   translationMap.Initialize

   '4: CLUBS
   line_map.Initialize
   line_map.Put(EN,"Clubs")
   line_map.Put(FR,"Trèfle")
   line_map.Put(IT,"Club")
   translationMap.Put(clubs_, line_map)

   '5: CURRENCY
   line_map.Initialize
   line_map.Put(EN,"Currency")
   line_map.Put(FR,"Devise")
   line_map.Put(IT,"Valuta")
   translationMap.Put(currency_, line_map)

   '6: CURRENCY_SYMBOL
   line_map.Initialize
   line_map.Put(EN,"Currency Symbol")
   line_map.Put(FR,"Symbole monétaire")
   line_map.Put(IT,"Simbolo di valuta")
   translationMap.Put(currency_symbol_, line_map)

   '7: CURRENT_LANGUAGE
   line_map.Initialize
   line_map.Put(EN,"Current Language")
   line_map.Put(FR,"Langage courant")
   line_map.Put(IT,"Lingua corrente")
   translationMap.Put(current_language_, line_map)

   '10: DIAMONDS
   line_map.Initialize
   line_map.Put(EN,"Diamonds")
   line_map.Put(FR,"Diamants")
   line_map.Put(IT,"Diamanti")
   translationMap.Put(diamonds_, line_map)

   '12: FIRST_WEEK_DAY
   line_map.Initialize
   line_map.Put(EN,"First day of week")
   line_map.Put(FR,"Premier jour de la semaine")
   line_map.Put(IT,"Primo giorno della settimana")
   translationMap.Put(first_week_day_, line_map)

   '13: HEARTS
   line_map.Initialize
   line_map.Put(EN,"Hearts")
   line_map.Put(FR,"Coeurs")
   line_map.Put(IT,"Cuori")
   translationMap.Put(hearts_, line_map)

   '23: PLANETS
   line_map.Initialize
   line_map.Put(EN,"Planets")
   line_map.Put(FR,"Planètes")
   line_map.Put(IT,"Pianeti")
   translationMap.Put(planets_, line_map)

   '29: SELECT_LANG
   line_map.Initialize
   line_map.Put(EN,"Select Language")
   line_map.Put(FR,"Sélectionner une langue")
   line_map.Put(IT,"Seleziona lingua")
   translationMap.Put(select_lang_, line_map)

   '30: SELECT_MONTH
   line_map.Initialize
   line_map.Put(EN,"Select Month")
   line_map.Put(FR,"Sélectionnez le mois")
   line_map.Put(IT,"Selezionare il mese")
   translationMap.Put(select_month_, line_map)

   '31: SELECT_WEEKDAY
   line_map.Initialize
   line_map.Put(EN,"Select Weekday")
   line_map.Put(FR,"Sélectionnez le jour")
   line_map.Put(IT,"Selezionare il giorno")
   translationMap.Put(select_weekday_, line_map)

   '39: SPADES
   line_map.Initialize
   line_map.Put(EN,"Spades")
   line_map.Put(FR,"Pique")
   line_map.Put(IT,"Picche")
   translationMap.Put(spades_, line_map)

   '42: SUITS
   line_map.Initialize
   line_map.Put(EN,"Pick a Suit:")
   line_map.Put(FR,"Choisir une couleur:")
   line_map.Put(IT,"Scegliere un colore:")
   translationMap.Put(suits_, line_map)

   '46: TITLE
   line_map.Initialize
   line_map.Put(EN,"Title")
   line_map.Put(FR,"Titre")
   line_map.Put(IT,"Titolo")
   translationMap.Put(title_, line_map)

   '47: TRANS_WITH_VAR_VALUES
   line_map.Initialize
   line_map.Put(EN,"Translation with variable values")
   line_map.Put(FR,"Traduction avec les valeurs des variables")
   line_map.Put(IT,"Traduzione con i valori delle variabili")
   translationMap.Put(trans_with_var_values_, line_map)

   '48: VARIABLE_MESSAGE
   line_map.Initialize
   line_map.Put(EN,"You are in %1$s and your Currency is %2$s")
   line_map.Put(FR,"Vous êtes à %1$s et votre monnaie est %2$s")
   line_map.Put(IT,"Sei in %1$s e la valuta è %2$s")
   translationMap.Put(variable_message_, line_map)

   '49: CARDS (string-srray)
   lines_map.Initialize
   line_map.Initialize
   line_map.Put(0, "Ace")
   line_map.Put(1, "King")
   line_map.Put(2, "Queen")
   line_map.Put(3, "Jack")
   lines_map.Put(EN, line_map)

   line_map.Initialize
   line_map.Put(0, "ACE")
   line_map.Put(1, "King")
   line_map.Put(2, "Reine")
   line_map.Put(3, "Jack")
   lines_map.Put(FR, line_map)

   '50: PLANETS_ (string-srray)
   lines_map.Initialize
   line_map.Initialize
   line_map.Put(0, "Mercury")
   line_map.Put(1, "Venus")
   line_map.Put(2, "Earth")
   line_map.Put(3, "Mars")
   line_map.Put(4, "Jupiter")
   line_map.Put(5, "Saturn")
   line_map.Put(6, "Uranus")
   line_map.Put(7, "Neptune")
   lines_map.Put(EN, line_map)

   line_map.Initialize
   line_map.Put(0, "Mercure")
   line_map.Put(1, "Venus")
   line_map.Put(2, "Terre")
   line_map.Put(3, "Mars")
   line_map.Put(4, "Jupiter")
   line_map.Put(5, "Saturn")
   line_map.Put(6, "Uranus")
   line_map.Put(7, "Neptune")
   lines_map.Put(FR, line_map)

   line_map.Initialize
   line_map.Put(0, "Mercurio")
   line_map.Put(1, "Venus")
   line_map.Put(2, "Terra")
   line_map.Put(3, "Marzo")
   line_map.Put(4, "Giove")
   line_map.Put(5, "Saturno")
   line_map.Put(6, "Urano")
   line_map.Put(7, "Nettuno")
   lines_map.Put(IT, line_map)
   translationMap.Put(planets__, lines_map)

   '51: CAR (plurals-array)
   lines_map.Initialize
   line_map.Initialize
   line_map.Put("one", "car")
   line_map.Put("other", "cars")
   lines_map.Put(EN, line_map)

   line_map.Initialize
   line_map.Put("one", "voiture")
   line_map.Put("other", "voitures")
   lines_map.Put(FR, line_map)

   line_map.Initialize
   line_map.Put("one", "auto")
   line_map.Put("other", "Automobili")
   lines_map.Put(IT, line_map)
   translationMap.Put(car_, lines_map)
End Sub
Edit: 7/12/2015
This library is not maintained here anymore. Go there for the latest version.
 
Last edited:

cimperia

Active Member
Licensed User
Longtime User
Here's the documentation and code of the most important class of the library:AJLocale. The prefix AJ means that it'll run on B4(A/J) transparently. The class maps java.util.Locale. It has been written in BA with extensive use of reflection to avoid reverting to java. The trick described in the first post allows for the multiple initializers.

But first, here's the documentation of the code (class) generated by B4Multinlingual:
Dependencies
  • reflection
  • javaobject
  • bajlocale
  • collectionsextra
  • threading
Tr (Class)
Properties:

  • AJCalendar As ajcalendar [read only]
  • AJCurrency As ajcurrency
  • AJDateFormat As ajdateformat [read only]
  • AJDateFormatSymbols As ajdateformatsymbols [read only]
  • AJLocale As ajlocale
  • carMap As Map [read only]
  • clubs As String [read only]
  • currency As String [read only]
  • currency_symbol As String [read only]
  • current_language As String [read only]
  • diamonds As String [read only]
  • English As String [read only]
  • first_week_day As String [read only]
  • French As String [read only]
  • hearts As String [read only]
  • Italian As String [read only]
  • planets As String [read only]
  • planets_Map As Map [read only]
  • select_lang As String [read only]
  • select_month As String [read only]
  • select_weekday As String [read only]
  • ShortMonths As List [read only]
  • spades As String [read only]
  • suits As String [read only]
  • title As String [read only]
  • trans_with_var_values As String [read only]
  • variable_message As String [read only]
Methods:
  • IsInitialized As boolean
    Tests whether the object has been initialized.
  • Get (symbol As int, lang As String) As String
  • GetMap (symbol As int, lang As String) As Map
  • Initialize (ba As BA) As String
  • Initialize2 (default_language_translation As String) As String

Please download the demo in post #1 to see how it is used.

I'll add the other classes as I have finished cleaning them up.

AJLocale Doc:
Dependencies

  • reflection
  • collectionsextra
  • javaobject
  • threading
AJLocale (Class)
Properties:

  • CANADA As JavaObject [read only]
    Locale constant For en_CA.
  • CANADA_FRENCH As JavaObject [read only]
    Locale constant For fr_CA.
  • CHINA As JavaObject [read only]
    Locale constant For zh_CN.
  • CHINESE As JavaObject [read only]
    Locale constant For zh.
  • Default As ajlocale [read only]
    Retrieve the current device's Locale
  • ENGLISH As JavaObject [read only]
    Locale constant For en.
  • FRANCE As JavaObject [read only]
    Locale constant For fr_FR.
  • FRENCH As JavaObject [read only]
    Locale constant For fr.
  • GERMAN As JavaObject [read only]
    Locale constant For de.
  • GERMANY As JavaObject [read only]
    Locale constant For de_DE.
  • ITALIAN As JavaObject [read only]
    Locale constant For it.
  • ITALY As JavaObject [read only]
    Locale constant For it_IT.
  • JAPAN As JavaObject [read only]
    Locale constant For ja_JP.
  • JAPANESE As JavaObject [read only]
    Locale constant For ja.
  • KOREA As JavaObject [read only]
    Locale constant For ko_KR.
  • KOREAN As JavaObject [read only]
    Locale constant For ko.
  • Locale As JavaObject
  • PRC As JavaObject [read only]
    Locale constant For zh_CN.
  • ROOT As JavaObject [read only]
    Locale constant For the root locale.
  • SIMPLIFIED_CHINESE As JavaObject [read only]
    Locale constant For zh_CN.
  • TAIWAN As JavaObject [read only]
    Locale constant For zh_TW.
  • TRADITIONAL_CHINESE As JavaObject [read only]
    Locale constant For zh_TW.
  • UK As JavaObject [read only]
    Locale constant For en_GB.
  • US As JavaObject [read only]
    Locale constant For en_US
Methods:
  • IsInitialized As boolean
    Tests whether the object has been initialized.
  • Equals (pLocale As ajlocale) As boolean
    Returns true if this Locale is equal to another AJLocale.Locale object.
  • GetAvailableLocales (pAll As boolean) As List
    Returns a List of all installed locales.
  • GetCountry As String
    Returns the country/region code for this locale, which should either be:
    the empty string,
    an uppercase ISO 3166 2-letter code,
    or a UN M.49 3-digit code.
  • GetDefaultLanguage As String
  • GetDisplayCountry (pLocale As JavaObject) As String
    This method takes either Null or a Locale as parameter.
    If the argument is Null, it's equivalent to calling
    GetDisplayCountry on the default Locale
    Ex
    Log(oAJLocale.GetDisplayCountry(Null))
    is equivalent to:
    Log(oAJLocale.GetDisplayCountry(oAJLocale.Default.Locale))

    If a locale is used, the method returns the name of this locale's language, localized to locale.
    EX: Log(oAJLocale.GetDisplayCountry(oAJLocale.Locale))
    'Let's try Japanese
    Log(oAJLocale.GetDisplayCountry(oAJLocale.JAPAN))
  • GetDisplayLanguage (pLocale As JavaObject) As String
  • GetDisplayName (pLocale As JavaObject) As String
  • GetDisplayVariant (pLocale As JavaObject) As String
  • GetISO3Country As String
  • GetISO3Language As String
  • GetISOCountries As String[]
  • GetISOLanguages As String[]
  • GetLanguage As String
  • GetVariant As String
  • Initialize (ba As BA, pLanguage As String) As String
    pLanguage: a valid ISO 639 <b>alpha-2 or alpha-3 language code</b>

    Initalize("en") 'English locale
    Initialize("fr") 'French locale

    A <b>Locale</b> object represents a specific geographical, political, or cultural region. An operation that requires a Locale To perform its task Is called locale-sensitive And uses the Locale To tailor information For the user. For example, displaying a number Is a locale-sensitive operation--the number should be formatted according To the customs/conventions of the user's native country, region, or culture.

    Create a Locale object using the constructors in this class:

    1. Initialize -> Locale(String language)
    2. Initialize2 -> Locale(String language, String country)
    3. Initialize3 -> Locale(String language, String country, String variant)
    4. InitializeDefault -> Static Java method java.util.Locale.getDefault()

    The language parameter is a valid ISO 639 <b>alpha-2 or alpha-3 language code, or registered language subtags up to 8 alpha letters</b> (for future enhancements). When a language has both an alpha-2 code and an alpha-3 code, the alpha-2 code must be used. You can find a full list of valid language codes in the IANA Language Subtag Registry (search for "Type: language"). The language field is case insensitive, but Locale always canonicalizes to lower case.
    <a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">Language Codes</a>

    The country must be an <b>ISO 3166 alpha-2 country code Or UN M.49 numeric-3</b> area code. You can find a full list of valid country And region codes in the IANA Language Subtag Registry (search For "Type: region"). The country (region) field Is Case insensitive, but Locale always canonicalizes To upper Case.
    Well-formed country/region values have the form [a-zA-Z]{2} | [0-9]{3}
    Example: "US" (United States), "FR" (France), "029" (Caribbean)

    More info here <a href="http://developer.android.com/reference/java/util/Locale.html">Android Java Locale</a>and here <a href="https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Locale.html">Oracle Java Locale</a>
  • Initialize2 (pLanguage As String, pCountry As String) As String
    Constructs a new Locale using the specified language and country codes.

    Dim baloc as AJLocale
    baloc.Initialize2("fr", "FR")
  • Initialize3 (pLanguage As String, pCountry As String, pVariant As String) As String
    Constructs a new Locale using the specified language, country and variant codes.

    Dim baloc as AJLocale
    baloc.Initialize3("fr", "FR", "FrenchIsGood")
  • InitializeDefault As ajlocale
  • InitializeInternal (pLocale As JavaObject) As String
    @hide
  • Name As String
  • ToString As String

AJLocale
B4X:
'Class module
'Version: 1
'Author: Cimperia
'java.util.Locale
#If B4A OR B4J
'Set to Private to avoid having it called directly!
Private Sub Class_Globals
   Private r As Reflector
   Private const classType As String = "java.util.Locale"
   'Class Locale object
   Private locale_ As JavaObject
   Private this As AJLocale = Me

   'Predefined Java Locals
   Private CONST CANADA_                As String = "CANADA"
   Private CONST CANADA_FRENCH_          As String = "CANADA_FRENCH"
   Private CONST CHINA_                  As String = "CHINA"
   Private CONST CHINESE_                As String = "CHINESE"
   Private CONST ENGLISH_                As String = "ENGLISH"
   Private CONST FRANCE_                As String = "FRANCE"
   Private CONST FRENCH_                As String = "FRENCH"
   Private CONST GERMAN_                As String = "GERMAN"
   Private CONST GERMANY_                As String = "GERMANY"
   Private CONST ITALIAN_                As String = "ITALIAN"
   Private CONST ITALY_                  As String = "ITALY"
   Private CONST JAPAN_                  As String = "JAPAN"
   Private CONST JAPANESE_              As String = "JAPANESE"
   Private CONST KOREA_                  As String = "KOREA"
   Private CONST KOREAN_                As String = "KOREAN"
   Private CONST PRC_                    As String = "PRC"
   Private CONST ROOT_                  As String = "ROOT"
   Private CONST SIMPLIFIED_CHINESE_     As String = "SIMPLIFIED_CHINESE"
   Private CONST TAIWAN_                As String = "TAIWAN"
   Private CONST TRADITIONAL_CHINESE_    As String = "TRADITIONAL_CHINESE"
   Private CONST UK_                    As String = "UK"
   Private CONST US_                    As String = "US"
End Sub

Private Sub InternalInitialize
  Dim r As Reflector
   'Initialize(r.GetProcessBA("main")) ' This will work, but you forfait the right to call Initialize in your own code.
   r.Target = Me
   r.Runmethod4("innerInitialize", Array As Object(r.GetProcessBA("main")), Array As String("anywheresoftware.b4a.BA"))
End Sub

#Region Public Sub Initialize(pLanguage As String)
'pLanguage: a valid ISO 639 <b>alpha-2 or alpha-3 language code</b>
'
'Initalize("en")  'English locale
'Initialize("fr") 'French locale
'
'A <b>Locale</b> object represents a specific geographical, political, or cultural region. An operation that requires a Locale To perform its task Is called locale-sensitive And uses the Locale To tailor information For the user. For example, displaying a number Is a locale-sensitive operation--the number should be formatted according To the customs/conventions of the user's native country, region, or culture.
'
'Create a Locale object using the constructors in this class:
'
'  1. Initialize  -> Locale(String language)
'  2. Initialize2 -> Locale(String language, String country)
'  3. Initialize3 -> Locale(String language, String country, String variant)
'  4. InitializeDefault -> Static Java method java.util.Locale.getDefault()
'
'The language parameter is a valid ISO 639 <b>alpha-2 or alpha-3 language code, or registered language subtags up to 8 alpha letters</b> (for future enhancements). When a language has both an alpha-2 code and an alpha-3 code, the alpha-2 code must be used. You can find a full list of valid language codes in the IANA Language Subtag Registry (search for "Type: language"). The language field is case insensitive, but Locale always canonicalizes to lower case.
'<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">Language Codes</a>
'
'The country must be an <b>ISO 3166 alpha-2 country code Or UN M.49 numeric-3</b> area code. You can find a full list of valid country And region codes in the IANA Language Subtag Registry (search For "Type: region"). The country (region) field Is Case insensitive, but Locale always canonicalizes To upper Case.
'Well-formed country/region values have the form [a-zA-Z]{2} | [0-9]{3}
'Example: "US" (United States), "FR" (France), "029" (Caribbean)
'
'More info here <a href="http://developer.android.com/reference/java/util/Locale.html">Android Java Locale</a>and here <a href="https://docs.oracle.com/javase/8/docs/api/index.html?java/util/Locale.html">Oracle Java Locale</a>
Public Sub Initialize(pLanguage As String)
  Init(r.CreateObject2(this.classType, Array As Object(pLanguage), _
    Array As String("java.lang.String")))
End Sub
#End Region Initialize

#Region Initialize2
'Constructs a new Locale using the specified language and country codes.
'
'Dim baloc as AJLocale
'baloc.Initialize2("fr", "FR")
Public Sub Initialize2(pLanguage As String, pCountry As String)
   InternalInitialize
  '
  Init(r.CreateObject2(this.classType, Array As Object(pLanguage, pCountry), _
    Array As String("java.lang.String","java.lang.String")))
End Sub
#End Region Initialize2

#Region Initialize3
'Constructs a new Locale using the specified language, country and variant codes.
'
'Dim baloc as AJLocale
'baloc.Initialize3("fr", "FR", "FrenchIsGood")
Public Sub Initialize3(pLanguage As String, pCountry As String, pVariant As String)
   InternalInitialize
  '
  Init(r.CreateObject2(this.classType, Array As Object(pLanguage, pCountry, pVariant), _
    Array As String("java.lang.String","java.lang.String","java.lang.String")))
End Sub
#End Region Initialize2

Public Sub InitializeDefault As AJLocale
   Return getDefault
End Sub

'Retrieve the current device's Locale
Public Sub getDefault As AJLocale
   InternalInitialize
   '
   Return Init(getDefault_)
End Sub

'@hide
Public Sub InitializeInternal(pLocale As JavaObject)
     InternalInitialize
     ' 
     Init(pLocale)
End Sub

Public Sub getLocale As JavaObject
   Return locale_
End Sub

Public Sub setLocale(Value As JavaObject)
   locale_ = Value
End Sub

Private Sub Init(pLocale As JavaObject) As JavaObject
   locale_ = pLocale
   Return Me
End Sub

#Region PREDEFINED-LOCALES
'Locale constant For en_CA.
Public Sub getCANADA As JavaObject
   r.Target = locale_
   Return r.GetField(CANADA_)
End Sub

'Locale constant For fr_CA.
Public Sub getCANADA_FRENCH As JavaObject
   r.Target = locale_
   Return r.GetField(CANADA_FRENCH_)
End Sub

'Locale constant For zh_CN.
Public Sub getCHINA As JavaObject
   r.Target = locale_
   Return r.GetField(CHINA_)
End Sub

'Locale constant For zh.
Public Sub getCHINESE As JavaObject
   r.Target = locale_
   Return r.GetField(CHINESE_)
End Sub

'Locale constant For en.
Public Sub getENGLISH As JavaObject
   r.Target = locale_
   Return r.GetField(ENGLISH_)
End Sub

'Locale constant For fr_FR.
Public Sub getFRANCE As JavaObject
   r.Target = locale_
   Return r.GetField(FRANCE_)
End Sub

'Locale constant For fr.
Public Sub getFRENCH As JavaObject
   r.Target = locale_
   Return r.GetField(FRENCH_)
End Sub

'Locale constant For de.
Public Sub getGERMAN As JavaObject
   r.Target = locale_
   Return r.GetField(GERMAN_)
End Sub

'Locale constant For de_DE.
Public Sub getGERMANY As JavaObject
   r.Target = locale_
   Return r.GetField(GERMANY_)
End Sub

'Locale constant For it.
Public Sub getITALIAN As JavaObject
   r.Target = locale_
   Return r.GetField(ITALIAN_)
End Sub

'Locale constant For it_IT.
Public Sub getITALY As JavaObject
   r.Target = locale_
   Return r.GetField(ITALY_)
End Sub

'Locale constant For ja_JP.
Public Sub getJAPAN As JavaObject
   r.Target = locale_
   Return r.GetField(JAPAN_)
End Sub

'Locale constant For ja.
Public Sub getJAPANESE As JavaObject
   r.Target = locale_
   Return r.GetField(JAPANESE_)
End Sub

'Locale constant For ko_KR.
Public Sub getKOREA As JavaObject
   r.Target = locale_
   Return r.GetField(KOREA_)
End Sub

'Locale constant For ko.
Public Sub getKOREAN As JavaObject
   r.Target = locale_
   Return r.GetField(KOREAN_)
End Sub

'Locale constant For zh_CN.
Public Sub getPRC As JavaObject
   r.Target = locale_
   Return r.GetField(PRC_)
End Sub

'Locale constant For the root locale.
Public Sub getROOT As JavaObject
   r.Target = locale_
   Return r.GetField(ROOT_)
End Sub

'Locale constant For zh_CN.
Public Sub getSIMPLIFIED_CHINESE As JavaObject
   r.Target = locale_
   Return r.GetField(SIMPLIFIED_CHINESE_)
End Sub

'Locale constant For zh_TW.
Public Sub getTAIWAN As JavaObject
   r.Target = locale_
   Return r.GetField(TAIWAN_)
End Sub

'Locale constant For zh_TW.
Public Sub getTRADITIONAL_CHINESE As JavaObject
   r.Target = locale_
   Return r.GetField(TRADITIONAL_CHINESE_)
End Sub

'Locale constant For en_GB.
Public Sub getUK As JavaObject
   r.Target = locale_
   Return r.GetField(UK_)
End Sub

'Locale constant For en_US
Public Sub getUS As JavaObject
   r.Target = locale_
   Return r.GetField(US_)
End Sub
#End Region

#Region LOCALE REFLECTIVE-METHODS
#region java.util.Locale
'Returns true if this Locale is equal to another AJLocale.Locale object.
Public Sub Equals (pLocale As AJLocale) As Boolean
   r.Target = locale_
   Return r.RunPublicmethod("equals", Array As Object(pLocale.Locale), Array As String("java.lang.Object"))
End Sub

'Returns a List of all installed locales.
Public Sub GetAvailableLocales(pAll As Boolean) As List
   Dim aList() As Object
   Dim retList As List : retList.Initialize
   Dim language, country As String

   aList = r.RunStaticMethod(this.classType, "getAvailableLocales", Null, Null)

   If pAll Then
     For i = 0 To aList.Length - 1
       Dim loc As AJLocale
       loc.InitializeInternal(aList(i))
       retList.Add(loc)
     Next
   Else
     For i = 0 To aList.Length - 1
       r.Target = aList(i)
    country = r.RunMethod("getCountry") : language = r.RunMethod("getLanguage")
       If Not (country = "" Or language = "") Then
         Dim loc As AJLocale
         loc.Initialize2(country, language) 
         retList.Add(loc)
       End If
     Next
   End If
   
   Return retList

End Sub

'Returns the country/region code for this locale, which should either be:
' the empty string,
' an uppercase ISO 3166 2-letter code,
' or a UN M.49 3-digit code.
Public Sub GetCountry As String
   r.Target = locale_
   Return r.RunMethod("getCountry")
End Sub

'Used Internally by AJLocale to retrieve device's default locale.
Private Sub getDefault_ As JavaObject
   Return r.RunStaticMethod(this.classType, "getDefault", Null, Null)
End Sub

'This method takes either Null or a Locale as parameter.
'If the argument is Null, it's equivalent to calling
'GetDisplayCountry on the default Locale
' Ex
' Log(oAJLocale.GetDisplayCountry(Null))
' is equivalent to:
'   Log(oAJLocale.GetDisplayCountry(oAJLocale.Default.Locale))
'
'If a locale is used, the method returns the name of this locale's language, localized to locale.
'EX: Log(oAJLocale.GetDisplayCountry(oAJLocale.Locale))
''Let's try Japanese
'Log(oAJLocale.GetDisplayCountry(oAJLocale.JAPAN))
Public Sub GetDisplayCountry(pLocale As JavaObject) As String
   r.Target = locale_

   If pLocale <> Null And pLocale.IsInitialized Then
     Return r.RunMethod4("getDisplayCountry", Array As Object(pLocale), Array As String(this.classType))
   Else
     Return r.RunMethod4("getDisplayCountry", Array As Object(getDefault_), Array As String(this.classType)) 
   End If
End Sub

Public Sub GetDisplayLanguage(pLocale As JavaObject) As String
   r.Target = locale_

   If pLocale <> Null And pLocale.IsInitialized Then
     Return r.RunMethod4("getDisplayLanguage", Array As Object(pLocale), Array As String(this.classType))
   Else
     Return r.RunMethod4("getDisplayLanguage", Array As Object(getDefault_), Array As String(this.classType)) 
   End If
End Sub

Public Sub GetDisplayName(pLocale As JavaObject) As String
   r.Target = locale_

   If pLocale <> Null And pLocale.IsInitialized Then
     Return r.RunMethod4("getDisplayName", Array As Object(pLocale), Array As String(this.classType))
   Else
     Return r.RunMethod4("getDisplayName", Array As Object(getDefault_), Array As String(this.classType)) 
   End If
End Sub

Public Sub GetDisplayVariant(pLocale As JavaObject) As String
   r.Target = locale_

   If pLocale <> Null And pLocale.IsInitialized Then
     Return r.RunMethod4("getDisplayVariant", Array As Object(pLocale), Array As String(this.classType))
   Else
     Return r.RunMethod4("getDisplayVariant", Array As Object(getDefault_), Array As String(this.classType)) 
   End If
End Sub

Public Sub GetISO3Country As String
   r.Target = locale_
   Return r.RunMethod("getISO3Country")
End Sub

Public Sub GetISO3Language As String
   r.Target = locale_
   Return r.RunMethod("getISO3Language")
End Sub

Public Sub GetISOCountries As String()
   r.Target = locale_
   Return r.RunMethod("getISOCountries")
End Sub

Public Sub GetISOLanguages As String()
   r.Target = locale_
   Return r.RunMethod("getISOLanguages")
End Sub

Public Sub GetLanguage As String
   r.Target = locale_
   Return r.RunMethod("getLanguage")
End Sub

Public Sub GetVariant As String
   r.Target = locale_
   Return r.RunMethod("getVariant")
End Sub

#Region locale helpers
Public Sub Name As String
    r.Target = locale_
    Return r.ToString
End Sub

Public Sub GetDefaultLanguage As String
  r.Target = getDefault_
  Return r.RunMethod("getDisplayName")
End Sub
#End Region locale helpers
#End Region java.util.Locale

Public Sub ToString As String
   r.Target = locale_
   Return r.RunMethod("toString")
End Sub
#End Region
#End if
 
Last edited:

cimperia

Active Member
Licensed User
Longtime User
Here's the documentation and code for another class of the BAJLocale library:AJCurrency. The class wraps java.util.Currency. As all the others, It has been coded in BA, not java.

The particularity of AJCurrency is that, though it's a "regular" BA(A/J) class, it behaves like a static code module. This is obviously by design as the java class itself is designed so that there's never more than one Currency instance for any given currency. Therefore, there's no public constructor. You obtain a Currency instance using one of the getInstance methods.
B4X:
Dim Currency As AJCurrency
Currency.GetInstance2("EUR")
Log(Currency.GetDisplayName)
'
Dim loc As AJLocale
loc.Initialize2("fr", "FR")
Currency.GetInstance(loc.Locale)
Log(Currency.GetDisplayName)
Log(Currency.GetSymbol(Null))

output:
B4X:
euro
euro
€
The second peculiarity is that the class, if run on Android OS, will check which OS version it's running on and behave graciously when calls are made to methods that belong to an ulterior version. It uses the class I posted there Class to check SDK levels at runtime. For example, getDisplayName was added to the class with the release of KitKat (API level 19) and if the device's API level is less than 19, the sub will return an empty string instead of raising an exception.
B4X:
Returns the localized name of this currency in the given locale.
'Returns the ISO 4217 currency code if no localized name is available.
Public Sub GetDisplayName2(pLocale As JavaObject) As String
   checkInstantiation
   '
#If B4A
  If (OS.SDK_INT < 19) Then
     Return ""
   End If
#End If
   r.Target = Currency_
  Return r.RunPublicmethod("getDisplayName", Array As Object(pLocale), Array As String("java.util.Locale"))
End Sub
AJCurrency (Class)
Methods:

  • IsInitialized As boolean
    Tests whether the object has been initialized.
  • GetAvailableCurrencies As List
    Returns a set of all known currencies.
    Added in API level 19
    Public static Set<Currency> getAvailableCurrencies ()
  • GetCurrencyCode As String
    Gets the ISO 4217 currency code of this currency.
    java: public String getCurrencyCode ()
  • GetDefaultFractionDigits As int
    Gets the default number of fraction digits used with this currency.
    For instance, the default number of fraction digits For the US dollar Is 2
    because there are 100 US cents in a US dollar.
    For the Japanese Yen, the number Is 0 because coins smaller than 1 Yen became invalid in 1953.
    In the Case of pseudo-currencies, such As IMF Special Drawing Rights, -1 Is returned.
    java: public int getDefaultFractionDigits ()
  • GetDisplayName As String
    Returns the localized name of this currency in the given locale.
    Returns the ISO 4217 currency code if no localized name is available.
    Equivalent to getDisplayName(Locale.getDefault())
    Added in API level 19
    java: public String getDisplayName ()
  • GetDisplayName2 (pLocale As JavaObject) As String
    Returns the localized name of this currency in the given locale.
    Returns the ISO 4217 currency code if no localized name is available.
    Added in API level 19
    java: public String getDisplayName (Locale locale)
  • GetInstance (pLocale As JavaObject) As String
    Returns the Currency instance for this Locale's country.
    Throws
    IllegalArgumentException if the locale's country is not a supported ISO 3166 country.
    java: public static Currency getInstance (String currencyCode)
  • GetInstance2 (currencyCode As String) As String
    Returns the Currency instance For the given ISO 4217 currency code.
    Throws
    IllegalArgumentException if the currency code Is Not a supported ISO 4217 currency code.
    java: public static Currency getInstance (Locale locale)
  • GetSymbol (pLocale As JavaObject) As String
    Returns the localized currency symbol For this currency in locale.
    That Is, given "USD" And Locale.US, you'd get "$", but given "USD" and a non-US locale, you'd get "US$".

    If the locale only specifies a language rather than a language And a country,
    (such As Locale.JAPANESE Or {new Locale("en", "")}, rather than Locale.JAPAN Or {new Locale("en", "US")}),
    the ISO 4217 currency code Is returned.

    If there Is no locale-specific currency symbol, the ISO 4217 currency code Is returned.
    java: public String getSymbol (Locale locale)
AJCurrency
B4X:
'Class module
'Version: 1.0
'Author: Cimperia
'Wraps java.util.Currency
#If B4A OR B4J
Private Sub Class_Globals
   Private r As Reflector
   Private const classType As String = "java.util.Currency"
   Private Currency_ As JavaObject
   Private OS As AJBuild
   Private this As AJCurrency = Me
End Sub

#region Initializers
#region Initialize
'There's no need nor possibility to call the Initialize method
'This class is used as if it were a static code module as you
'don't have to initialize it explicitely.
Private Sub Initialize
End Sub
#End Region Initialize
#region InternalInitialize
'Private Sub that calls B4's private class initializer.
'It has to be called for every additional initializer defined
'in the class.
Private Sub InternalInitialize
   'Do not initialize more than once as there's no benefit in doing so
   'in this particular instance.
   If Not (this <> Null And this.IsInitialized) Then
     Dim r As Reflector
     Initialize(r.GetProcessBA("main"))
   End If
   OS.Initialize
End Sub
#End Region InternalInitialize
#End Region Initializers

#Region Instantiators
#Region GetInstance(pLocale As JavaObject)
'Returns the Currency instance for this Locale's country.
'Throws
'  IllegalArgumentException if the locale's country is not a supported ISO 3166 country.
'java: public static Currency getInstance (String currencyCode)
Public Sub GetInstance(pLocale As JavaObject)
   InternalInitialize
   '
   Currency_ = Null
   Currency_ = r.RunStaticMethod(classType, "getInstance", Array As Object(pLocale), Array As String("java.util.Locale"))
End Sub
#End Region GetInstance(pLocale As JavaObject)

#Region GetInstance2(currencyCode As String)
'Returns the Currency instance For the given ISO 4217 currency code.
'Throws
'  IllegalArgumentException if the currency code Is Not a supported ISO 4217 currency code.
'java: public static Currency getInstance (Locale locale)
Public Sub GetInstance2(currencyCode As String)
   InternalInitialize
   '
   Currency_ = Null
   Currency_ = r.RunStaticMethod(classType, "getInstance", Array As String(currencyCode), Array As String("java.lang.String"))
End Sub
#End Region GetInstance2(currencyCode As String)
#End Region Instantiators

#Region Public Methods
#Region GetDisplayName
'Returns the localized name of this currency in the given locale.
'Returns the ISO 4217 currency code if no localized name is available.
'Equivalent to getDisplayName(Locale.getDefault())
'Added in [b]API level 19[/b]
'java:public String getDisplayName ()
Public Sub GetDisplayName As String
   checkInstantiation
   '
#If B4A
  If (OS.SDK_INT < 19) Then
     Return ""
   End If
#End If
   r.Target = Currency_
   Return r.RunPublicmethod("getDisplayName", Null, Null)
End Sub
#End Region GetDisplayName

#Region GetDisplayName2
'Returns the localized name of this currency in the given locale.
'Returns the ISO 4217 currency code if no localized name is available.
'Added in [b]API level 19[/b]
'java:public String getDisplayName (Locale locale)
Public Sub GetDisplayName2(pLocale As JavaObject) As String
   checkInstantiation
   '
#If B4A
  If (OS.SDK_INT < 19) Then
     Return ""
   End If
#End If
   r.Target = Currency_
  Return r.RunPublicmethod("getDisplayName", Array As Object(pLocale), Array As String("java.util.Locale"))
End Sub
#End Region GetDisplayName2

#Region GetCurrencyCode
'Gets the ISO 4217 currency code of this currency.
'java: public String getCurrencyCode ()
Public Sub GetCurrencyCode As String
   checkInstantiation
   '
  Return r.RunPublicmethod("getCurrencyCode", Null, Null)
End Sub
#End Region GetCurrencyCode

#Region GetAvailableCurrencies
'Returns a set of all known currencies.
'Added in [B]API level 19[/B]
'Public static Set<Currency> getAvailableCurrencies ()
Public Sub GetAvailableCurrencies As List
   checkInstantiation
   '
   Private myList As List  : myList.Initialize
   Dim sb As StringBuilder : sb.Initialize

#If B4A
  If (OS.SDK_INT < 19) Then
     Return myList
   End If
#End If

  r.Target = Currency_
  sb.Insert(0, r.RunStaticMethod(classType, "getAvailableCurrencies", Null, Null))

   'There must be at least one currency ISO 3 char symbol
   'Example: [EUR]
   If (sb.Length >= 5) Then 
     sb.Remove(sb.Length-1,sb.Length).Remove(0,1)
     '
     For Each curcy As String In Regex.Split(",", sb.ToString)
    myList.Add(curcy.Trim)
    Next
  End If

   Return myList
End Sub
#End Region GetAvailableCurrencies

#Region GetDefaultFractionDigits
'Gets the default number of fraction digits used with this currency.
'For instance, the default number of fraction digits For the US dollar Is 2
'because there are 100 US cents in a US dollar.
'For the Japanese Yen, the number Is 0 because coins smaller than 1 Yen became invalid in 1953.
'In the Case of pseudo-currencies, such As IMF Special Drawing Rights, -1 Is returned.
'java: public int getDefaultFractionDigits ()
Public Sub GetDefaultFractionDigits As Int
   checkInstantiation
   '
  Return r.RunMethod("getDefaultFractionDigits")
End Sub
#End Region GetDefaultFractionDigits

#Region GetSymbol(pLocale As JavaObject)
'Returns the localized currency symbol For this currency in locale.
'That Is, given "USD" And Locale.US, you'd get "$", but given "USD" and a non-US locale, you'd get "US$".
'
'If the locale only specifies a language rather than a language And a country,
'(such As Locale.JAPANESE Or {new Locale("en", "")}, rather than Locale.JAPAN Or {new Locale("en", "US")}),
'the ISO 4217 currency code Is returned.
'
'If there Is no locale-specific currency symbol, the ISO 4217 currency code Is returned.
'java: public String getSymbol (Locale locale)
Public Sub GetSymbol(pLocale As JavaObject) As String
   checkInstantiation
   '
   r.Target = Currency_
   If pLocale <> Null And pLocale.IsInitialized Then
     Return r.RunMethod4("getSymbol", Array As Object(pLocale), Array As String("java.util.Locale"))
   Else
     Return r.RunMethod("getSymbol")
   End If
End Sub
#End Region GetSymbol(pLocale As JavaObject)

#Region checkInstantiation
private Sub checkInstantiation
   If Not(Currency_.IsInitialized) Then
     Dim ex As ExceptionEx
     ex.Initialize("Currency was not instanciated. GetInstance or GetInstance2 must be called first")
     ex.Throw
   End If
End Sub
#End Region checkInstantiation
#End Region Public Methods
#End If
 

cimperia

Active Member
Licensed User
Longtime User
Here's a third class from the library: AJDateFormat, which wraps java.text.DateFormat.

AJDateFormat (Class)
Properties:

  • AM_PM_FIELD As int [read only]
    FieldPosition selector for 'a' field alignment, corresponds to the AM_PM field.
  • DATE_FIELD As int [read only]
    The FieldPosition selector for 'd' field alignment, corresponds to the DATE field.
  • DAY_OF_WEEK_FIELD As int [read only]
    FieldPosition selector for 'E' field alignment, corresponds to the DAY_OF_WEEK field.
  • DAY_OF_WEEK_IN_MONTH_FIELD As int [read only]
    FieldPosition selector for 'F' field alignment, corresponds to the DAY_OF_WEEK_IN_MONTH field.
  • DAY_OF_YEAR_FIELD As int [read only]
    FieldPosition selector for 'D' field alignment, corresponds to the DAY_OF_YEAR field.
  • DEFAULT As int [read only]
    The format style constant defining the default format style.
  • ERA_FIELD As int [read only]
    The FieldPosition selector for 'G' field alignment, corresponds to the ERA field.
  • FULL As int [read only]
    The format style constant defining the full style.
  • HOUR_OF_DAY0_FIELD As int [read only]
    The FieldPosition selector for 'H' field alignment, corresponds to the HOUR_OF_DAY field.
  • HOUR_OF_DAY1_FIELD As int [read only]
    The FieldPosition selector for 'k' field alignment, corresponds to the HOUR_OF_DAY field.
  • HOUR0_FIELD As int [read only]
    The FieldPosition selector for 'K' field alignment, corresponding to the HOUR field.
  • HOUR1_FIELD As int [read only]
    FieldPosition selector for 'h' field alignment, corresponding to the HOUR field.
  • LONG As int [read only]
    The format style constant defining the long style.
  • MEDIUM As int [read only]
    The format style constant defining the medium style.
  • MILLISECOND_FIELD As int [read only]
    FieldPosition selector for 'S' field alignment, corresponds to the MILLISECOND field.
  • MINUTE_FIELD As int [read only]
    FieldPosition selector for 'm' field alignment, corresponds to the MINUTE field.
  • MONTH_FIELD As int [read only]
    The FieldPosition selector for 'M' field alignment, corresponds to the MONTH field.
  • SECOND_FIELD As int [read only]
    FieldPosition selector for 's' field alignment, corresponds to the SECOND field.
  • SHORT As int [read only]
    The format style constant defining the short style.
  • TIMEZONE_FIELD As int [read only]
    The FieldPosition selector for 'z' field alignment, corresponds to the ZONE_OFFSET and DST_OFFSET fields.
  • WEEK_OF_MONTH_FIELD As int [read only]
    FieldPosition selector for 'W' field alignment, corresponds to the WEEK_OF_MONTH field.
  • WEEK_OF_YEAR_FIELD As int [read only]
    FieldPosition selector for 'w' field alignment, corresponds to the WEEK_OF_YEAR field.
  • YEAR_FIELD As int [read only]
    The FieldPosition selector for 'y' field alignment, corresponds to the YEAR field.
Methods:
  • IsInitialized As boolean
    Tests whether the object has been initialized.
  • Format (date As JavaObject) As String
    final String format(Date date)
    Formats the specified date using the rules of this date format.
  • GetAvailableLocales As List
    Returns a List of AJLocale For which custom DateFormat instances are available.
  • GetCalendar As JavaObject
    Returns the calendar used by this DateFormat.
    Returns
    the calendar used by this date Format.
    Java: Public Calendar getCalendar ()
  • GetDateInstance As String
    Sets a DateFormat instance For formatting And parsing dates in the DEFAULT style For the default locale.
    Returns
    void
  • GetDateInstance2 (style As int) As String
    Sets a DateFormat instance For formatting And parsing dates in the specified style For the user's default locale. See "Be wary of the default locale".
    Parameters
    style one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    Returns
    void
    Throws
    IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
  • GetDateInstance3 (style As int, locale As JavaObject) As String
    Sets a DateFormat instance For formatting And parsing dates in the specified style For the specified locale.
    Parameters
    style: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    locale: the locale (AJLocale.Locale)
    Returns
    void
    Throws
    IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
  • GetDateTimeInstance As String
    Sets a DateFormat instance For formatting And parsing dates And time values in the DEFAULT style For the default locale.
    Returns
    void
    Java: final static DateFormat getDateTimeInstance()
  • GetDateTimeInstance2 (dateStyle As int, timeStyle As int) As String
    Sets a DateFormat instance For formatting And parsing of both dates And time values in the manner appropriate For the user's default locale. See "Be wary of the default locale".
    Parameters
    dateStyle: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    timeStyle: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    Returns
    void
    Throws
    IllegalArgumentException if dateStyle Or timeStyle Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    Java: final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
  • GetDateTimeInstance3 (dateStyle As int, timeStyle As int, locale As JavaObject) As String
    Sets a DateFormat instance For formatting And parsing dates And time values in the specified styles For the specified locale.
    Parameters
    dateStyle: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    timeStyle: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    locale: the locale (AJLocale.Locale)
    Returns
    void
    Throws
    IllegalArgumentException if dateStyle Or timeStyle Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    Java: final static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, locale locale)
  • GetInstance As String
    Sets a DateFormat instance For formatting And parsing dates And times in the SHORT style For the default locale.
    Returns
    void
    Java: final static DateFormat getInstance()
  • GetNumberFormat As JavaObject
    Returns the NumberFormat used by this DateFormat.
    Returns
    the NumberFormat used by this date Format.
    Java: NumberFormat getNumberFormat()
  • GetTimeInstance As String
    Sets a DateFormat instance For formatting And parsing time values in the DEFAULT style For the default locale.
    Returns
    void
    Java: Public static final DateFormat getTimeInstance ()
  • GetTimeInstance2 (style As int) As String
    Sets a DateFormat instance For formatting And parsing time values in the specified style For the user's default locale. See "Be wary of the default locale".
    Parameters
    style: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    Returns
    void
    Throws
    IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    Java: Public static final DateFormat getTimeInstance (int style)
  • GetTimeInstance3 (style As int, locale As JavaObject) As String
    Returns a DateFormat instance For formatting And parsing time values in the specified style For the specified locale.
    Parameters
    style: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    locale: the locale (AJLocale.Locale)
    Returns
    void
    Throws
    IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
    Java: Public static final DateFormat getTimeInstance (int style, Locale locale)
  • GetTimeZone As JavaObject
    Returns the time zone of this date Format's calendar.
    Returns
    the time zone of the calendar used by this date Format.
    Java: Public TimeZone getTimeZone ()
  • Initialize (ba As BA) As String
    There's no need/possibility to call the Initialize method
  • IsLenient As boolean
    Indicates whether the calendar used by this date Format Is lenient.
    Returns
    true if the calendar is lenient; False otherwise.
    Java: Public boolean isLenient ()
  • Parse (pattern As String) As JavaObject
    Parses a date from the specified string using the rules of this date Format.
    Parameters
    pattern: the string To parse.
    Returns
    the java.util.Date resulting from the parsing.
    Store it in an AJDate wrapper.
    Ex:
    Dim oAJDate As AJDate
    oAJDate.Initialize3(df.Parse(myFormat))
    Throws
    ParseException if an error occurs during parsing.
    Java: Public Date parse (String string)
  • Parse2 (pattern As String, position As JavaObject) As JavaObject
    Parses a date from the specified string starting at the index specified by position. If the string Is successfully parsed Then the index of the ParsePosition Is updated To the index following the parsed text. On error, the index Is unchanged And the error index of ParsePosition Is set To the index where the error occurred.

    By default, parsing Is lenient: If the input Is Not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

    Parameters
    pattern: the string To Parse.
    position input/output parameter, specifies the start index in string from where To start parsing. If parsing Is successful, it Is updated with the index following the parsed text; on error, the index Is unchanged And the error index Is set To the index where the error occurred.
    Returns
    the date resulting from the Parse, Or Null If there Is an error.
    Java: Public abstract Date Parse (String string, ParsePosition position)
  • SetCalendar (cal As JavaObject) As String
    Sets the calendar used by this date Format.
    Parameters
    cal: the new calendar.
    Java: Public void setCalendar (Calendar cal)
  • SetLenient (lenient As boolean) As String
    Specifies whether Or Not date/time parsing shall be lenient. With lenient parsing, the parser may use heuristics To interpret inputs that Do Not precisely match this object's format. With strict parsing, inputs must match this object's format.
    Parameters
    value True To set the calendar To be lenient, False otherwise.
    Java: Public void setLenient (boolean value)
B4X:
#If B4A OR B4J
'Class module
'Version: 1
'Author: Cimperia
'Wraps: java.text.DateFormat
Private Sub Class_Globals
   Private r As Reflector
   Private const classType As String = "java.text.DateFormat"
   Private DateFormat_ As JavaObject
   Private this As AJDateFormat = Me
End Sub

#Region Initialize
Public Sub Initialize
   GetDateInstance
End Sub
#End Region Initialize

#Region INSTANTIATORS
#Region GetDateInstance
'Sets a DateFormat instance For formatting And parsing dates in the DEFAULT style For the default locale.
'Returns
'  void
Public Sub GetDateInstance
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getDateInstance", Null, Null)
End Sub
#End Region GetDateInstance

#Region GetDateInstance2
'Sets a DateFormat instance For formatting And parsing dates in the specified style For the user's default locale. See "Be wary of the default locale".
'Parameters
'  style one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'Returns
'  void
'Throws
'  IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
Public Sub GetDateInstance2(style As Int)
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getDateInstance", Array As Object(style), Array As String("java.lang.int"))
End Sub
#End Region GetDateInstance2

#Region GetDateInstance3
'Sets a DateFormat instance For formatting And parsing dates in the specified style For the specified locale.
'Parameters
'  style: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'  locale: the locale (AJLocale.Locale)
'Returns
'  void
'Throws
'  IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
Public Sub GetDateInstance3(style As Int, locale As JavaObject)
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getDateInstance", _
          Array As Object(style, locale), _
                                        Array As String("java.lang.int", "java.util.Locale"))
End Sub
#End Region GetDateInstance3

#Region getDateTimeInstance
'Sets a DateFormat instance For formatting And parsing dates And time values in the DEFAULT style For the default locale.
'Returns
'  void
'Java: final static DateFormat    getDateTimeInstance()
Public Sub GetDateTimeInstance
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getDateTimeInstance", Null, Null)
End Sub
#End Region getDateTimeInstance

#Region getDateTimeInstance2
'Sets a DateFormat instance For formatting And parsing of both dates And time values in the manner appropriate For the user's default locale. See "Be wary of the default locale".
'Parameters
'  dateStyle: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'  timeStyle:    one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'Returns
'  void
'Throws
'  IllegalArgumentException if dateStyle Or timeStyle Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'Java: final static DateFormat    getDateTimeInstance(int dateStyle, int timeStyle)
Public Sub GetDateTimeInstance2(dateStyle As Int, timeStyle As Int)
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getDateTimeInstance", _
        Array As Object(dateStyle, timeStyle), _
                                        Array As String("java.lang.int", "java.lang.int"))
End Sub
#End Region getDateTimeInstance2

#Region getDateTimeInstance3
'Sets a DateFormat instance For formatting And parsing dates And time values in the specified styles For the specified locale.
'Parameters
'  dateStyle: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'  timeStyle:    one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'  locale: the locale (AJLocale.Locale)
'Returns
'  void
'Throws
'  IllegalArgumentException if dateStyle Or timeStyle Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'Java: final static DateFormat    getDateTimeInstance(int dateStyle, int timeStyle, locale locale)
Public Sub GetDateTimeInstance3(dateStyle As Int, timeStyle As Int, locale As JavaObject)
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getDateTimeInstance", _
        Array As Object(dateStyle, timeStyle, locale), _
                                        Array As String("java.lang.int", "java.lang.int", "java.util.Locale"))
End Sub
#End Region getDateTimeInstance3

#Region GetInstance
'Sets a DateFormat instance For formatting And parsing dates And times in the SHORT style For the default locale.
'Returns
'  void
'Java: final static DateFormat    getInstance()
Public Sub GetInstance
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getInstance", Null, Null)
End Sub
#End Region GetInstance

#Region GetTimeInstance
'Sets a DateFormat instance For formatting And parsing time values in the DEFAULT style For the default locale.
'Returns
'  void
'Java: Public static final DateFormat getTimeInstance ()
Public Sub GetTimeInstance
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getTimeInstance", Null, Null)
End Sub
#End Region GetTimeInstance

#Region GetTimeInstance2
'Sets a DateFormat instance For formatting And parsing time values in the specified style For the user's default locale. See "Be wary of the default locale".
'Parameters
'  style: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'Returns
'  void
'Throws
'  IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'Java: Public static final DateFormat getTimeInstance (int style)
Public Sub GetTimeInstance2(style As Int)
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getTimeInstance", _
        Array As Object(style), _
                                        Array As String("java.lang.int"))
End Sub
#End Region GetTimeInstance2

#Region GetTimeInstance3
'Returns a DateFormat instance For formatting And parsing time values in the specified style For the specified locale.
'Parameters
'style: one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'locale: the locale (AJLocale.Locale)
'Returns
' void
'Throws
'  IllegalArgumentException if style Is Not one of SHORT, MEDIUM, LONG, FULL, Or DEFAULT.
'Java: Public static final DateFormat getTimeInstance (int style, Locale locale)
Public Sub GetTimeInstance3(style As Int, locale As JavaObject)
   this.DateFormat_ = r.RunStaticMethod(this.classType, "getTimeInstance", _
        Array As Object(style, locale), _
                                        Array As String("java.lang.int", "java.util.Locale"))
End Sub
#End Region GetTimeInstance3
#End Region INSTANTIATORS

#Region Public Methods
'abstract StringBuffer    Format(Date date, StringBuffer buffer, FieldPosition field)

'final StringBuffer    Format(Object object, StringBuffer buffer, FieldPosition field)

'final String    format(Date date)
'Formats the specified date using the rules of this date format.
Public Sub Format(date As JavaObject) As String
   r.Target = this.DateFormat_
   Return r.RunMethod4("format", Array As Object(date), Array As String("java.util.Date"))
End Sub

'Returns a List of AJLocale For which custom DateFormat instances are available.
Public Sub GetAvailableLocales As List
   Dim aList() As Object
   Dim retList As List : retList.Initialize
  Dim country, language As String

   aList = r.RunStaticMethod("java.util.Locale", "getAvailableLocales", Null, Null)

   For i = 0 To aList.Length - 1
     r.Target = aList(i)
  country = r.RunMethod("getCountry") : language = r.RunMethod("getLanguage")
     If Not (country = "" Or language = "") Then
       Dim loc As AJLocale
       loc.Initialize2(country, language)
       retList.Add(loc)
     else if language <> "" Then
       Dim loc As AJLocale
       loc.Initialize(language)
       retList.Add(loc)
     End If
   Next
  
   Return retList
End Sub

'Returns the calendar used by this DateFormat.
'Returns
'  the calendar used by this date Format.
'Java: Public Calendar getCalendar ()
Public Sub GetCalendar As JavaObject
   r.Target = this.DateFormat_
   Return r.RunMethod("getCalendar")
End Sub

'Public String FormatDateTime(ba ba, long Ticks, int Flags) {
'Public Sub FormatDateTime(Ticks As Long, Flags As Int) As String
'   Return r.RunStaticMethod("android.text.format.DateUtils", "formatDateTime", Array As Object (r.GetContext, Ticks, Flags), Array As String ("android.content.Context", "java.lang.long", "java.lang.int"))                                        
'End Sub

'Returns the NumberFormat used by this DateFormat.
'Returns
'  the NumberFormat used by this date Format.
'Java: NumberFormat    getNumberFormat()
Public Sub GetNumberFormat As JavaObject
   r.Target = this.DateFormat_
   Return r.RunMethod("getNumberFormat")
End Sub

'Returns the time zone of this date Format's calendar.
'Returns
'  the time zone of the calendar used by this date Format.
'Java: Public TimeZone getTimeZone ()
Public Sub GetTimeZone As JavaObject
   r.Target = this.DateFormat_
   Return r.RunMethod("getTimeZone")
End Sub

'Indicates whether the calendar used by this date Format Is lenient.
'Returns
'  true if the calendar is lenient; False otherwise.
'Java: Public boolean isLenient ()
Public Sub IsLenient As Boolean
   r.Target = this.DateFormat_
   Return r.RunMethod("isLenient")
End Sub

'Parses a date from the specified string using the rules of this date Format.
'Parameters
' pattern: the string To parse.
'Returns
'  the java.util.Date resulting from the parsing.
'  Store it in an AJDate wrapper.
' Ex:
' Dim oAJDate As AJDate
' oAJDate.Initialize3(df.Parse(myFormat))
'Throws
'  ParseException if an error occurs during parsing.
'Java: Public Date parse (String string)
Public Sub Parse(pattern As String) As JavaObject
   r.Target = this.DateFormat_
  Return r.RunPublicmethod("parse", Array As Object(pattern), Array As String("java.lang.String"))
End Sub

'Parses a date from the specified string starting at the index specified by position. If the string Is successfully parsed Then the index of the ParsePosition Is updated To the index following the parsed text. On error, the index Is unchanged And the error index of ParsePosition Is set To the index where the error occurred.
'
'By default, parsing Is lenient: If the input Is Not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
'
'Parameters
'  pattern: the string To Parse.
'position    input/output parameter, specifies the start index in string from where To start parsing. If parsing Is successful, it Is updated with the index following the parsed text; on error, the index Is unchanged And the error index Is set To the index where the error occurred.
'Returns
'  the date resulting from the Parse, Or Null If there Is an error.
'Java: Public abstract Date Parse (String string, ParsePosition position)
Public Sub Parse2(pattern As String , position As JavaObject) As JavaObject
  r.Target = this.DateFormat_
   Return r.RunPublicmethod("parse", Array As Object(pattern, position), Array As String("java.lang.String", "    java.text.ParsePosition"))
End Sub

'Sets the calendar used by this date Format.
'Parameters
'  cal: the new calendar.
'Java: Public void setCalendar (Calendar cal)
Public Sub SetCalendar (cal As JavaObject)
   r.Target = this.DateFormat_
   r.RunPublicmethod("setCalendar", Array As Object(cal), Array As String("java.util.Calendar"))
End Sub

'Specifies whether Or Not date/time parsing shall be lenient. With lenient parsing, the parser may use heuristics To interpret inputs that Do Not precisely match this object's format. With strict parsing, inputs must match this object's format.
'Parameters
'value    True To set the calendar To be lenient, False otherwise.
'Java: Public void setLenient (boolean value)
Public Sub SetLenient(lenient As Boolean)
'r.Target = this.DateFormat_ with or without r.Target = r.GetField("calendar") fails.
  this.DateFormat_.RunMethod("setLenient", Array As Object(lenient))
End Sub

'Sets the NumberFormat used by this date Format.
'Parameters
'Format    the new number Format.
'Java: Public void setNumberFormat (NumberFormat Format)


'Sets the time zone of the calendar used by this date Format.
'Parameters
'timezone    the new time zone.
'Java: Public void setTimeZone (TimeZone timezone)
#End Region Public Methods

#Region Styles Getters And Setters
'FieldPosition selector for 'a' field alignment, corresponds to the AM_PM field.
Public Sub getAM_PM_FIELD As Int
   Return r.GetStaticField(this.classType, "AM_PM_FIELD")
End Sub
  
'The FieldPosition selector for 'd' field alignment, corresponds to the DATE field.          
Public Sub getDATE_FIELD As Int
   Return r.GetStaticField(this.classType, "DATE_FIELD")
End Sub
      
'FieldPosition selector for 'E' field alignment, corresponds to the DAY_OF_WEEK field.        
Public Sub getDAY_OF_WEEK_FIELD As Int
   Return r.GetStaticField(this.classType, "DAY_OF_WEEK_FIELD")
End Sub
  
'FieldPosition selector for 'F' field alignment, corresponds to the DAY_OF_WEEK_IN_MONTH field.    
Public Sub getDAY_OF_WEEK_IN_MONTH_FIELD As Int
   Return r.GetStaticField(this.classType, "DAY_OF_WEEK_IN_MONTH_FIELD")
End Sub

'FieldPosition selector for 'D' field alignment, corresponds to the DAY_OF_YEAR field.        
Public Sub getDAY_OF_YEAR_FIELD As Int
   Return r.GetStaticField(this.classType, "DAY_OF_YEAR_FIELD")
End Sub
  
'The format style constant defining the default format style.                    
Public Sub getDEFAULT As Int
   Return r.GetStaticField(this.classType, "DEFAULT")
'  Return   this.DateFormat_.GetField("DEFAULT")
End Sub
      
'The FieldPosition selector for 'G' field alignment, corresponds to the ERA field.          
Public Sub getERA_FIELD As Int
   Return r.GetStaticField(this.classType, "ERA_FIELD")
End Sub
      
'The format style constant defining the full style.                          
Public Sub getFULL As Int
   Return r.GetStaticField(this.classType, "FULL")
End Sub
        
'The FieldPosition selector for 'K' field alignment, corresponding to the HOUR field.        
Public Sub getHOUR0_FIELD As Int
   Return r.GetStaticField(this.classType, "HOUR0_FIELD")
End Sub
    
'FieldPosition selector for 'h' field alignment, corresponding to the HOUR field.          
Public Sub getHOUR1_FIELD As Int
   Return r.GetStaticField(this.classType, "HOUR1_FIELD")
End Sub
    
'The FieldPosition selector for 'H' field alignment, corresponds to the HOUR_OF_DAY field.      
Public Sub getHOUR_OF_DAY0_FIELD As Int
   Return r.GetStaticField(this.classType, "HOUR_OF_DAY0_FIELD")
End Sub
  
'The FieldPosition selector for 'k' field alignment, corresponds to the HOUR_OF_DAY field.      
Public Sub getHOUR_OF_DAY1_FIELD As Int
   Return r.GetStaticField(this.classType, "HOUR_OF_DAY1_FIELD")
End Sub
  
'The format style constant defining the long style.                          
Public Sub getLONG As Int
   Return r.GetStaticField(this.classType, "LONG")
End Sub
        
'The format style constant defining the medium style.                        
Public Sub getMEDIUM As Int
   Return r.GetStaticField(this.classType, "MEDIUM")
End Sub
        
'FieldPosition selector for 'S' field alignment, corresponds to the MILLISECOND field.        
Public Sub getMILLISECOND_FIELD As Int
   Return r.GetStaticField(this.classType, "MILLISECOND_FIELD")
End Sub
  
'FieldPosition selector for 'm' field alignment, corresponds to the MINUTE field.          
Public Sub getMINUTE_FIELD As Int
   Return r.GetStaticField(this.classType, "MINUTE_FIELD")
End Sub
    
'The FieldPosition selector for 'M' field alignment, corresponds to the MONTH field.          
Public Sub getMONTH_FIELD As Int
   Return r.GetStaticField(this.classType, "MONTH_FIELD")
End Sub
    
'FieldPosition selector for 's' field alignment, corresponds to the SECOND field.          
Public Sub getSECOND_FIELD As Int
   Return r.GetStaticField(this.classType, "SECOND_FIELD")
End Sub
    
'The format style constant defining the short style.                          
Public Sub getSHORT As Int
   Return r.GetStaticField(this.classType, "SHORT")
End Sub
        
'The FieldPosition selector for 'z' field alignment, corresponds to the ZONE_OFFSET and DST_OFFSET fields.
Public Sub getTIMEZONE_FIELD As Int
   Return r.GetStaticField(this.classType, "TIMEZONE_FIELD")
End Sub
    
'FieldPosition selector for 'W' field alignment, corresponds to the WEEK_OF_MONTH field.        
Public Sub getWEEK_OF_MONTH_FIELD As Int
   Return r.GetStaticField(this.classType, "WEEK_OF_MONTH_FIELD")
End Sub

'FieldPosition selector for 'w' field alignment, corresponds to the WEEK_OF_YEAR field.        
Public Sub getWEEK_OF_YEAR_FIELD As Int
   Return r.GetStaticField(this.classType, "WEEK_OF_YEAR_FIELD")
End Sub
  
'The FieldPosition selector for 'y' field alignment, corresponds to the YEAR field.           
Public Sub getYEAR_FIELD As Int
   Return r.GetStaticField(this.classType, "YEAR_FIELD")
'   Return    this.DateFormat_.GetField("YEAR_FIELD")
End Sub
#End Region Styles Getters And Setters
#End If
 
Last edited:
Top