am 6598022d: am bdf952aa: Merge "Make Hyphenator#get() return an object." into mnc-dr-dev

* commit '6598022de5447691be3551d86ad31f2e3fe0e567':
  Make Hyphenator#get() return an object.
This commit is contained in:
Roozbeh Pournader
2015-10-14 21:18:39 +00:00
committed by Android Git Automerger
2 changed files with 11 additions and 6 deletions

View File

@@ -53,11 +53,15 @@ public class Hyphenator {
mNativePtr = nativePtr; mNativePtr = nativePtr;
} }
public static long get(@Nullable Locale locale) { public long getNativePtr() {
return mNativePtr;
}
public static Hyphenator get(@Nullable Locale locale) {
synchronized (sLock) { synchronized (sLock) {
Hyphenator result = sMap.get(locale); Hyphenator result = sMap.get(locale);
if (result != null) { if (result != null) {
return result.mNativePtr; return result;
} }
// TODO: Convert this a proper locale-fallback system // TODO: Convert this a proper locale-fallback system
@@ -67,7 +71,7 @@ public class Hyphenator {
result = sMap.get(languageOnlyLocale); result = sMap.get(languageOnlyLocale);
if (result != null) { if (result != null) {
sMap.put(locale, result); sMap.put(locale, result);
return result.mNativePtr; return result;
} }
// Fall back to script-only, if available // Fall back to script-only, if available
@@ -80,13 +84,13 @@ public class Hyphenator {
result = sMap.get(scriptOnlyLocale); result = sMap.get(scriptOnlyLocale);
if (result != null) { if (result != null) {
sMap.put(locale, result); sMap.put(locale, result);
return result.mNativePtr; return result;
} }
} }
sMap.put(locale, sEmptyHyphenator); // To remember we found nothing. sMap.put(locale, sEmptyHyphenator); // To remember we found nothing.
} }
return sEmptyHyphenator.mNativePtr; return sEmptyHyphenator;
} }
private static Hyphenator loadHyphenator(String languageTag) { private static Hyphenator loadHyphenator(String languageTag) {

View File

@@ -341,7 +341,8 @@ public class StaticLayout extends Layout {
private void setLocale(Locale locale) { private void setLocale(Locale locale) {
if (!locale.equals(mLocale)) { if (!locale.equals(mLocale)) {
nSetLocale(mNativePtr, locale.toLanguageTag(), Hyphenator.get(locale)); nSetLocale(mNativePtr, locale.toLanguageTag(),
Hyphenator.get(locale).getNativePtr());
mLocale = locale; mLocale = locale;
} }
} }