com.bugvm.apple.foundation.NSLocale Maven / Gradle / Ivy
/*
* Copyright (C) 2013-2015 RoboVM AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.bugvm.apple.foundation;
/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.corefoundation.*;
import com.bugvm.apple.uikit.*;
import com.bugvm.apple.coretext.*;
import com.bugvm.apple.coreanimation.*;
import com.bugvm.apple.coredata.*;
import com.bugvm.apple.coregraphics.*;
import com.bugvm.apple.coremedia.*;
import com.bugvm.apple.security.*;
import com.bugvm.apple.dispatch.*;
/* */
/**/
/* */
/**/@Library("Foundation") @NativeClass/* */
/**/public/* */ class /**/NSLocale/* */
extends /**/NSObject/* */
/**//* */ {
public static class Notifications {
/**
* @since Available in iOS 2.0 and later.
*/
public static NSObject observeCurrentLocaleDidChange(final Runnable block) {
return NSNotificationCenter.getDefaultCenter().addObserver(CurrentLocaleDidChangeNotification(), null, NSOperationQueue.getMainQueue(), new VoidBlock1() {
@Override
public void invoke(NSNotification a) {
block.run();
}
});
}
}
/**/public static class NSLocalePtr extends Ptr {}/* */
/**/static { ObjCRuntime.bind(NSLocale.class); }/* */
/**//* */
/**/
protected NSLocale(SkipInit skipInit) { super(skipInit); }
public NSLocale(String string) { super((SkipInit) null); initObject(init(string)); }
/* */
public NSLocale(Locale locale) {
super((SkipInit) null);
initObject(init(locale.toString()));
}
/**/
@Property(selector = "localeIdentifier")
public native String getLocaleIdentifier();
/* */
/**//* */
public Locale toLocale() {
String language = getLanguageCode();
String country = getCountryCode();
String variant = getVariantCode();
if (language != null && country != null && variant != null) {
return new Locale(language, country, variant);
}
if (language != null && country != null) {
return new Locale(language, country);
}
if (language != null) {
return new Locale(language);
}
throw new IllegalArgumentException("Failed to convert NSLocale " + toString() + " to Java Locale");
}
/* Convenience methods */
public String getLanguageCode() {
NSString val = (NSString)getComponent(NSLocaleComponent.LanguageCode);
return val.toString();
}
public String getCountryCode() {
NSString val = (NSString)getComponent(NSLocaleComponent.CountryCode);
return val.toString();
}
public String getScriptCode() {
NSString val = (NSString)getComponent(NSLocaleComponent.ScriptCode);
return val.toString();
}
public String getVariantCode() {
NSString val = (NSString)getComponent(NSLocaleComponent.VariantCode);
return val.toString();
}
public NSCharacterSet getExemplarCharacterSet() {
NSCharacterSet val = (NSCharacterSet)getComponent(NSLocaleComponent.ExemplarCharacterSet);
return val;
}
public String getCollationIdentifier() {
NSString val = (NSString)getComponent(NSLocaleComponent.CollationIdentifier);
return val.toString();
}
public boolean isUsingMetricSystem() {
NSNumber val = (NSNumber)getComponent(NSLocaleComponent.UsesMetricSystem);
return val.booleanValue();
}
public String getMeasurementSystem() {
NSString val = (NSString)getComponent(NSLocaleComponent.MeasurementSystem);
return val.toString();
}
public String getDecimalSeparator() {
NSString val = (NSString)getComponent(NSLocaleComponent.DecimalSeparator);
return val.toString();
}
public String getGroupingSeparator() {
NSString val = (NSString)getComponent(NSLocaleComponent.GroupingSeparator);
return val.toString();
}
public String getCurrencySymbol() {
NSString val = (NSString)getComponent(NSLocaleComponent.CurrencySymbol);
return val.toString();
}
public String getCurrencyCode() {
NSString val = (NSString)getComponent(NSLocaleComponent.CurrencyCode);
return val.toString();
}
/**
* @since Available in iOS 4.0 and later.
*/
public String getCollatorIdentifier() {
NSString val = (NSString)getComponent(NSLocaleComponent.CollatorIdentifier);
return val.toString();
}
/**
* @since Available in iOS 4.0 and later.
*/
public String getQuotationBeginDelimiterKey() {
NSString val = (NSString)getComponent(NSLocaleComponent.QuotationBeginDelimiterKey);
return val.toString();
}
/**
* @since Available in iOS 4.0 and later.
*/
public String getQuotationEndDelimiterKey() {
NSString val = (NSString)getComponent(NSLocaleComponent.QuotationEndDelimiterKey);
return val.toString();
}
/**
* @since Available in iOS 4.0 and later.
*/
public String getAlternateQuotationBeginDelimiterKey() {
NSString val = (NSString)getComponent(NSLocaleComponent.AlternateQuotationBeginDelimiterKey);
return val.toString();
}
/**
* @since Available in iOS 4.0 and later.
*/
public String getAlternateQuotationEndDelimiterKey() {
NSString val = (NSString)getComponent(NSLocaleComponent.AlternateQuotationEndDelimiterKey);
return val.toString();
}
/**/
/**
* @since Available in iOS 2.0 and later.
*/
@GlobalValue(symbol="NSCurrentLocaleDidChangeNotification", optional=true)
public static native NSString CurrentLocaleDidChangeNotification();
@Method(selector = "objectForKey:")
public native NSObject getComponent(NSLocaleComponent key);
@Method(selector = "displayNameForKey:value:")
public native String getComponentDisplayName(NSLocaleComponent key, NSObject value);
@Method(selector = "initWithLocaleIdentifier:")
protected native @Pointer long init(String string);
/**
* @since Available in iOS 2.0 and later.
*/
@Method(selector = "autoupdatingCurrentLocale")
public static native NSLocale getAutoupdatingCurrentLocale();
@Method(selector = "currentLocale")
public static native NSLocale getCurrentLocale();
@Method(selector = "systemLocale")
public static native NSLocale getSystemLocale();
@Method(selector = "availableLocaleIdentifiers")
public static native @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List getAvailableLocaleIdentifiers();
@Method(selector = "ISOLanguageCodes")
public static native @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List getISOLanguageCodes();
@Method(selector = "ISOCountryCodes")
public static native @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List getISOCountryCodes();
@Method(selector = "ISOCurrencyCodes")
public static native @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List getISOCurrencyCodes();
/**
* @since Available in iOS 2.0 and later.
*/
@Method(selector = "commonISOCurrencyCodes")
public static native @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List getCommonISOCurrencyCodes();
/**
* @since Available in iOS 2.0 and later.
*/
@Method(selector = "preferredLanguages")
public static native @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List getPreferredLanguages();
@Method(selector = "componentsFromLocaleIdentifier:")
public static native NSLocaleComponents getComponentsFromLocaleIdentifier(String string);
@Method(selector = "localeIdentifierFromComponents:")
public static native String getLocaleIdentifierFromComponents(NSLocaleComponents dict);
@Method(selector = "canonicalLocaleIdentifierFromString:")
public static native String getCanonicalLocaleIdentifier(String string);
@Method(selector = "canonicalLanguageIdentifierFromString:")
public static native String getCanonicalLanguageIdentifier(String string);
/**
* @since Available in iOS 4.0 and later.
*/
@Method(selector = "localeIdentifierFromWindowsLocaleCode:")
public static native String getLocaleIdentifierFromWindowsLocaleCode(int lcid);
/**
* @since Available in iOS 4.0 and later.
*/
@Method(selector = "windowsLocaleCodeFromLocaleIdentifier:")
public static native int getWindowsLocaleCodeFromLocaleIdentifier(String localeIdentifier);
/**
* @since Available in iOS 4.0 and later.
*/
@Method(selector = "characterDirectionForLanguage:")
public static native NSLocaleLanguageDirection getCharacterDirection(String isoLangCode);
/**
* @since Available in iOS 4.0 and later.
*/
@Method(selector = "lineDirectionForLanguage:")
public static native NSLocaleLanguageDirection getLineDirection(String isoLangCode);
/* */
}