Merge "Add Locale#script to Configuration proto." into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
cc1159a166
@@ -55,6 +55,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Slog;
|
||||
import android.util.proto.ProtoInputStream;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
import android.util.proto.WireTypeMismatchException;
|
||||
@@ -70,6 +71,7 @@ import java.io.IOException;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.IllformedLocaleException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -87,6 +89,8 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
/** @hide */
|
||||
public static final Configuration EMPTY = new Configuration();
|
||||
|
||||
private static final String TAG = "Configuration";
|
||||
|
||||
/**
|
||||
* Current user preference for the scaling factor for fonts, relative
|
||||
* to the base density scaling.
|
||||
@@ -1186,6 +1190,7 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
String language = "";
|
||||
String country = "";
|
||||
String variant = "";
|
||||
String script = "";
|
||||
try {
|
||||
while (protoInputStream.nextField()
|
||||
!= ProtoInputStream.NO_MORE_FIELDS) {
|
||||
@@ -1200,6 +1205,9 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
case (int) LocaleProto.VARIANT:
|
||||
variant = protoInputStream.readString(LocaleProto.VARIANT);
|
||||
break;
|
||||
case (int) LocaleProto.SCRIPT:
|
||||
script = protoInputStream.readString(LocaleProto.SCRIPT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (WireTypeMismatchException wtme) {
|
||||
@@ -1207,7 +1215,19 @@ public final class Configuration implements Parcelable, Comparable<Configuration
|
||||
throw wtme;
|
||||
} finally {
|
||||
protoInputStream.end(localeToken);
|
||||
list.add(new Locale(language, country, variant));
|
||||
try {
|
||||
final Locale locale = new Locale.Builder()
|
||||
.setLanguage(language)
|
||||
.setRegion(country)
|
||||
.setVariant(variant)
|
||||
.setScript(script)
|
||||
.build();
|
||||
list.add(locale);
|
||||
} catch (IllformedLocaleException e) {
|
||||
Slog.e(TAG, "readFromProto error building locale with: "
|
||||
+ "language-" + language + ";country-" + country
|
||||
+ ";variant-" + variant + ";script-" + script);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case (int) SCREEN_LAYOUT:
|
||||
|
||||
@@ -157,6 +157,7 @@ public final class LocaleList implements Parcelable {
|
||||
protoOutputStream.write(LocaleProto.LANGUAGE, locale.getLanguage());
|
||||
protoOutputStream.write(LocaleProto.COUNTRY, locale.getCountry());
|
||||
protoOutputStream.write(LocaleProto.VARIANT, locale.getVariant());
|
||||
protoOutputStream.write(LocaleProto.SCRIPT, locale.getScript());
|
||||
protoOutputStream.end(token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,5 +27,6 @@ message LocaleProto {
|
||||
optional string language = 1;
|
||||
optional string country = 2;
|
||||
optional string variant = 3;
|
||||
optional string script = 4;
|
||||
}
|
||||
|
||||
|
||||
@@ -223,6 +223,22 @@ public class UsageStatsDatabaseTest {
|
||||
config9.densityDpi = 19;
|
||||
mIntervalStats.getOrCreateConfigurationStats(config9);
|
||||
|
||||
Configuration config10 = new Configuration();
|
||||
final Locale locale10 = new Locale.Builder()
|
||||
.setLocale(new Locale("zh", "CN"))
|
||||
.setScript("Hans")
|
||||
.build();
|
||||
config10.setLocale(locale10);
|
||||
mIntervalStats.getOrCreateConfigurationStats(config10);
|
||||
|
||||
Configuration config11 = new Configuration();
|
||||
final Locale locale11 = new Locale.Builder()
|
||||
.setLocale(new Locale("zh", "CN"))
|
||||
.setScript("Hant")
|
||||
.build();
|
||||
config11.setLocale(locale11);
|
||||
mIntervalStats.getOrCreateConfigurationStats(config11);
|
||||
|
||||
mIntervalStats.activeConfiguration = config9;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user