Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5500501 authored by Yohei Yukawa's avatar Yohei Yukawa Committed by Android (Google) Code Review
Browse files

Merge "Make LocaleList Parcelable."

parents e759cd58 789d8fdb
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -38651,10 +38651,11 @@ package android.util {
    field public static final int RTL = 1; // 0x1
  }
  public final class LocaleList {
  public final class LocaleList implements android.os.Parcelable {
    ctor public LocaleList();
    ctor public LocaleList(java.util.Locale);
    ctor public LocaleList(java.util.Locale[]);
    method public int describeContents();
    method public static android.util.LocaleList forLanguageTags(java.lang.String);
    method public java.util.Locale get(int);
    method public java.util.Locale getBestMatch(java.lang.String[]);
@@ -38664,6 +38665,8 @@ package android.util {
    method public boolean isEmpty();
    method public int size();
    method public java.lang.String toLanguageTags();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.util.LocaleList> CREATOR;
  }
  public final class Log {
+4 −1
Original line number Diff line number Diff line
@@ -40977,10 +40977,11 @@ package android.util {
    field public static final int RTL = 1; // 0x1
  }
  public final class LocaleList {
  public final class LocaleList implements android.os.Parcelable {
    ctor public LocaleList();
    ctor public LocaleList(java.util.Locale);
    ctor public LocaleList(java.util.Locale[]);
    method public int describeContents();
    method public static android.util.LocaleList forLanguageTags(java.lang.String);
    method public java.util.Locale get(int);
    method public java.util.Locale getBestMatch(java.lang.String[]);
@@ -40990,6 +40991,8 @@ package android.util {
    method public boolean isEmpty();
    method public int size();
    method public java.lang.String toLanguageTags();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.util.LocaleList> CREATOR;
  }
  public final class Log {
+4 −1
Original line number Diff line number Diff line
@@ -38653,10 +38653,11 @@ package android.util {
    field public static final int RTL = 1; // 0x1
  }
  public final class LocaleList {
  public final class LocaleList implements android.os.Parcelable {
    ctor public LocaleList();
    ctor public LocaleList(java.util.Locale);
    ctor public LocaleList(java.util.Locale[]);
    method public int describeContents();
    method public static android.util.LocaleList forLanguageTags(java.lang.String);
    method public java.util.Locale get(int);
    method public java.util.Locale getBestMatch(java.lang.String[]);
@@ -38666,6 +38667,8 @@ package android.util {
    method public boolean isEmpty();
    method public int size();
    method public java.lang.String toLanguageTags();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.util.LocaleList> CREATOR;
  }
  public final class Log {
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * 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 android.util;

parcelable LocaleList;
+29 −1
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package android.util;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Size;
import android.os.Parcel;
import android.os.Parcelable;

import com.android.internal.annotations.GuardedBy;

@@ -35,11 +37,12 @@ import java.util.Locale;
 * LocaleList is an immutable list of Locales, typically used to keep an
 * ordered user preferences for locales.
 */
public final class LocaleList {
public final class LocaleList implements Parcelable {
    private final Locale[] mList;
    // This is a comma-separated list of the locales in the LocaleList created at construction time,
    // basically the result of running each locale's toLanguageTag() method and concatenating them
    // with commas in between.
    @NonNull
    private final String mStringRepresentation;

    private static final Locale[] sEmptyList = new Locale[0];
@@ -101,6 +104,16 @@ public final class LocaleList {
        return sb.toString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int parcelableFlags) {
        dest.writeString(mStringRepresentation);
    }

    @NonNull
    public String toLanguageTags() {
        return mStringRepresentation;
@@ -163,10 +176,25 @@ public final class LocaleList {
        }
    }

    public static final Parcelable.Creator<LocaleList> CREATOR
            = new Parcelable.Creator<LocaleList>() {
        @Override
        public LocaleList createFromParcel(Parcel source) {
            return LocaleList.forLanguageTags(source.readString());
        }

        @Override
        public LocaleList[] newArray(int size) {
            return new LocaleList[size];
        }
    };

    @NonNull
    public static LocaleList getEmptyLocaleList() {
        return sEmptyLocaleList;
    }

    @NonNull
    public static LocaleList forLanguageTags(@Nullable String list) {
        if (list == null || list.equals("")) {
            return getEmptyLocaleList();