From bfc2faa269aba3e006b5da547e7d0fbfc1033b6d Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 29 Nov 2016 07:59:49 -0800 Subject: [PATCH] Enable focus highlighting in track selection dialogs ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=140479099 --- .../exoplayer2/demo/TrackSelectionHelper.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java b/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java index 8892c138d0..936cdf90f8 100644 --- a/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java +++ b/demo/src/main/java/com/google/android/exoplayer2/demo/TrackSelectionHelper.java @@ -18,7 +18,9 @@ package com.google.android.exoplayer2.demo; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; +import android.content.Context; import android.content.DialogInterface; +import android.content.res.TypedArray; import android.text.TextUtils; import android.util.Pair; import android.view.LayoutInflater; @@ -100,7 +102,7 @@ import java.util.Locale; AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(title) - .setView(buildView(LayoutInflater.from(builder.getContext()))) + .setView(buildView(builder.getContext())) .setPositiveButton(android.R.string.ok, this) .setNegativeButton(android.R.string.cancel, null) .create() @@ -108,13 +110,20 @@ import java.util.Locale; } @SuppressLint("InflateParams") - private View buildView(LayoutInflater inflater) { + private View buildView(Context context) { + LayoutInflater inflater = LayoutInflater.from(context); View view = inflater.inflate(R.layout.track_selection_dialog, null); ViewGroup root = (ViewGroup) view.findViewById(R.id.root); + TypedArray attributeArray = context.getTheme().obtainStyledAttributes( + new int[] {android.R.attr.selectableItemBackground}); + int selectableItemBackgroundResourceId = attributeArray.getResourceId(0, 0); + attributeArray.recycle(); + // View for disabling the renderer. disableView = (CheckedTextView) inflater.inflate( android.R.layout.simple_list_item_single_choice, root, false); + disableView.setBackgroundResource(selectableItemBackgroundResourceId); disableView.setText(R.string.selection_disabled); disableView.setFocusable(true); disableView.setOnClickListener(this); @@ -123,6 +132,7 @@ import java.util.Locale; // View for clearing the override to allow the selector to use its default selection logic. defaultView = (CheckedTextView) inflater.inflate( android.R.layout.simple_list_item_single_choice, root, false); + defaultView.setBackgroundResource(selectableItemBackgroundResourceId); defaultView.setText(R.string.selection_default); defaultView.setFocusable(true); defaultView.setOnClickListener(this); @@ -146,6 +156,7 @@ import java.util.Locale; : android.R.layout.simple_list_item_single_choice; CheckedTextView trackView = (CheckedTextView) inflater.inflate( trackViewLayoutId, root, false); + trackView.setBackgroundResource(selectableItemBackgroundResourceId); trackView.setText(buildTrackName(group.getFormat(trackIndex))); if (trackInfo.getTrackFormatSupport(rendererIndex, groupIndex, trackIndex) == RendererCapabilities.FORMAT_HANDLED) { @@ -169,6 +180,7 @@ import java.util.Locale; // View for using random adaptation. enableRandomAdaptationView = (CheckedTextView) inflater.inflate( android.R.layout.simple_list_item_multiple_choice, root, false); + enableRandomAdaptationView.setBackgroundResource(selectableItemBackgroundResourceId); enableRandomAdaptationView.setText(R.string.enable_random_adaptation); enableRandomAdaptationView.setOnClickListener(this); root.addView(inflater.inflate(R.layout.list_divider, root, false));