From 88d7587ca7846718c3964dfe580e799e7cf0462c Mon Sep 17 00:00:00 2001 From: Yoni Obadia Date: Wed, 26 Aug 2020 11:40:48 +0200 Subject: [PATCH 1/2] dev: add setting theme for TrackSelectionDialogBuilder --- .../exoplayer2/ui/TrackSelectionDialogBuilder.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java index 30098054ef..ab5437790e 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java @@ -24,6 +24,7 @@ import android.content.DialogInterface; import android.view.LayoutInflater; import android.view.View; import androidx.annotation.Nullable; +import androidx.annotation.StyleRes; import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride; @@ -49,6 +50,7 @@ public final class TrackSelectionDialogBuilder { } private final Context context; + @StyleRes private int themeResId; private final CharSequence title; private final MappedTrackInfo mappedTrackInfo; private final int rendererIndex; @@ -121,6 +123,11 @@ public final class TrackSelectionDialogBuilder { newOverrides.isEmpty() ? null : newOverrides.get(0))); } + public TrackSelectionDialogBuilder setTheme(int themeResId) { + this.themeResId = themeResId; + return this; + } + /** * Sets whether the selection is initially shown as disabled. * @@ -214,7 +221,7 @@ public final class TrackSelectionDialogBuilder { } private Dialog buildForPlatform() { - AlertDialog.Builder builder = new AlertDialog.Builder(context); + AlertDialog.Builder builder = new AlertDialog.Builder(context, themeResId); // Inflate with the builder's context to ensure the correct style is used. LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext()); @@ -238,8 +245,8 @@ public final class TrackSelectionDialogBuilder { // the APK size even with shrinking. See https://issuetracker.google.com/161514204. // LINT.IfChange Class builderClazz = Class.forName("androidx.appcompat.app.AlertDialog$Builder"); - Constructor builderConstructor = builderClazz.getConstructor(Context.class); - Object builder = builderConstructor.newInstance(context); + Constructor builderConstructor = builderClazz.getConstructor(Context.class, int.class); + Object builder = builderConstructor.newInstance(context, themeResId); // Inflate with the builder's context to ensure the correct style is used. Context builderContext = (Context) builderClazz.getMethod("getContext").invoke(builder); From 0176422f0b0fc65f1ee64d98c5a9a8eb0e579492 Mon Sep 17 00:00:00 2001 From: Yoni Obadia Date: Wed, 26 Aug 2020 19:07:47 +0200 Subject: [PATCH 2/2] Review: Update according to review --- library/ui/proguard-rules.txt | 1 + .../android/exoplayer2/ui/TrackSelectionDialogBuilder.java | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/library/ui/proguard-rules.txt b/library/ui/proguard-rules.txt index 9bfde914b2..bee72e1d3a 100644 --- a/library/ui/proguard-rules.txt +++ b/library/ui/proguard-rules.txt @@ -4,6 +4,7 @@ -dontnote androidx.appcompat.app.AlertDialog.Builder -keepclassmembers class androidx.appcompat.app.AlertDialog$Builder { (android.content.Context); + (android.content.Context, int); public android.content.Context getContext(); public androidx.appcompat.app.AlertDialog$Builder setTitle(java.lang.CharSequence); public androidx.appcompat.app.AlertDialog$Builder setView(android.view.View); diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java index ab5437790e..6227f0490e 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/TrackSelectionDialogBuilder.java @@ -123,7 +123,12 @@ public final class TrackSelectionDialogBuilder { newOverrides.isEmpty() ? null : newOverrides.get(0))); } - public TrackSelectionDialogBuilder setTheme(int themeResId) { + /** + * Sets the resource ID of the theme used to inflate this dialog. + * @param themeResId the resource ID to use + * @return This builder, for convenience. + */ + public TrackSelectionDialogBuilder setTheme(@StyleRes int themeResId) { this.themeResId = themeResId; return this; }