-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
144 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 45 additions & 53 deletions
98
libraries/common/src/main/java/androidx/media3/common/Label.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,94 +1,86 @@ | ||
/* | ||
* Copyright 2024 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 androidx.media3.common; | ||
|
||
import static androidx.media3.common.util.Assertions.checkNotNull; | ||
|
||
import android.os.Bundle; | ||
import android.os.Parcel; | ||
import android.os.Parcelable; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.media3.common.util.UnstableApi; | ||
import androidx.media3.common.util.Util; | ||
|
||
/** A Label, as defined by ISO 23009-1, 4th edition, 5.3.7.2. */ | ||
/** A label for a {@link Format}. */ | ||
@UnstableApi | ||
public class Label implements Parcelable, Bundleable { | ||
/** Declares the language code(s) for this Label. */ | ||
@Nullable public final String lang; | ||
public class Label { | ||
/** | ||
* The language of this label, as an IETF BCP 47 conformant tag, or null if unknown or not | ||
* applicable. | ||
*/ | ||
@Nullable public final String language; | ||
|
||
/** The value for this Label. */ | ||
/** The value for this label. */ | ||
public final String value; | ||
|
||
/** | ||
* @param lang The lang code. | ||
* @param value The value. | ||
* Creates a label. | ||
* | ||
* @param language The language of this label, as an IETF BCP 47 conformant tag, or null if | ||
* unknown or not applicable. | ||
* @param value The label value. | ||
*/ | ||
public Label(@Nullable String lang, String value) { | ||
this.lang = lang; | ||
public Label(@Nullable String language, String value) { | ||
this.language = Util.normalizeLanguageCode(language); | ||
this.value = value; | ||
} | ||
|
||
/* package */ Label(Parcel in) { | ||
lang = in.readString(); | ||
value = in.readString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(@Nullable Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
Label label = (Label) o; | ||
return Util.areEqual(lang, label.lang) && Util.areEqual(value, label.value); | ||
return Util.areEqual(language, label.language) && Util.areEqual(value, label.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = value.hashCode(); | ||
result = 31 * result + (lang != null ? lang.hashCode() : 0); | ||
result = 31 * result + (language != null ? language.hashCode() : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public int describeContents() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeToParcel(@NonNull Parcel dest, int flags) { | ||
dest.writeString(lang); | ||
dest.writeString(value); | ||
} | ||
|
||
public static final Parcelable.Creator<Label> CREATOR = | ||
new Parcelable.Creator<Label>() { | ||
|
||
@Override | ||
public Label createFromParcel(Parcel in) { | ||
return new Label(in); | ||
} | ||
|
||
@Override | ||
public Label[] newArray(int size) { | ||
return new Label[size]; | ||
} | ||
}; | ||
|
||
private static final String FIELD_LANG_INDEX = Util.intToStringMaxRadix(0); | ||
private static final String FIELD_LANGUAGE_INDEX = Util.intToStringMaxRadix(0); | ||
private static final String FIELD_VALUE_INDEX = Util.intToStringMaxRadix(1); | ||
|
||
@Override | ||
/** Serializes this instance to a {@link Bundle}. */ | ||
public Bundle toBundle() { | ||
Bundle bundle = new Bundle(); | ||
bundle.putString(FIELD_LANG_INDEX, lang); | ||
if (language != null) { | ||
bundle.putString(FIELD_LANGUAGE_INDEX, language); | ||
} | ||
bundle.putString(FIELD_VALUE_INDEX, value); | ||
return bundle; | ||
} | ||
|
||
/** | ||
* Constructs an instance of {@link Label} from a {@link Bundle} produced by {@link #toBundle()}. | ||
*/ | ||
/** Deserializes an instance from a {@link Bundle} produced by {@link #toBundle()}. */ | ||
public static Label fromBundle(Bundle bundle) { | ||
return new Label( | ||
bundle.getString(FIELD_LANG_INDEX), checkNotNull(bundle.getString(FIELD_VALUE_INDEX))); | ||
bundle.getString(FIELD_LANGUAGE_INDEX), checkNotNull(bundle.getString(FIELD_VALUE_INDEX))); | ||
} | ||
} |
Oops, something went wrong.