OSPreferences_android.cpp (2282B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "OSPreferences.h" 8 #include "mozilla/Preferences.h" 9 10 #include "mozilla/java/GeckoAppShellWrappers.h" 11 12 using namespace mozilla::intl; 13 14 OSPreferences::OSPreferences() {} 15 16 bool OSPreferences::ReadSystemLocales(nsTArray<nsCString>& aLocaleList) { 17 if (!mozilla::jni::IsAvailable()) { 18 return false; 19 } 20 21 // XXX: Notice, this value may be empty on an early read. In that case 22 // we won't add anything to the return list so that it doesn't get 23 // cached in mSystemLocales. 24 auto locales = java::GeckoAppShell::GetDefaultLocales(); 25 if (locales) { 26 for (size_t i = 0; i < locales->Length(); i++) { 27 jni::String::LocalRef locale = locales->GetElement(i); 28 aLocaleList.AppendElement(locale->ToCString()); 29 } 30 return true; 31 } 32 return false; 33 } 34 35 bool OSPreferences::ReadRegionalPrefsLocales(nsTArray<nsCString>& aLocaleList) { 36 // For now we're just taking System Locales since we don't know of any better 37 // API for regional prefs. 38 return ReadSystemLocales(aLocaleList); 39 } 40 41 /* 42 * Similar to Gtk, Android does not provide a way to customize or format 43 * date/time patterns, so we're reusing ICU data here, but we do modify it 44 * according to the Android DateFormat is24HourFormat setting. 45 */ 46 bool OSPreferences::ReadDateTimePattern(DateTimeFormatStyle aDateStyle, 47 DateTimeFormatStyle aTimeStyle, 48 const nsACString& aLocale, 49 nsACString& aRetVal) { 50 if (!mozilla::jni::IsAvailable()) { 51 return false; 52 } 53 54 nsAutoCString skeleton; 55 if (!GetDateTimeSkeletonForStyle(aDateStyle, aTimeStyle, aLocale, skeleton)) { 56 return false; 57 } 58 59 // Customize the skeleton if necessary to reflect user's 12/24hr pref 60 OverrideSkeletonHourCycle(java::GeckoAppShell::GetIs24HourFormat(), skeleton); 61 62 if (!GetPatternForSkeleton(skeleton, aLocale, aRetVal)) { 63 return false; 64 } 65 66 return true; 67 } 68 69 void OSPreferences::RemoveObservers() {}