<commit_before>/*
 * Copyright (C) 2014 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 com.google.android.exoplayer.demo.ui;

import com.google.android.exoplayer.DefaultTrackSelector;
import com.google.android.exoplayer.DefaultTrackSelector.TrackInfo;
import com.google.android.exoplayer.Format;
import com.google.android.exoplayer.TrackGroup;
import com.google.android.exoplayer.TrackGroupArray;
import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.TrackSelection;
import com.google.android.exoplayer.demo.R;
import com.google.android.exoplayer.util.MimeTypes;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckedTextView;

import java.util.Arrays;
import java.util.Locale;

/**
 * Helper class for displaying track selection dialogs.
 */
public class TrackSelectionHelper implements View.OnClickListener, DialogInterface.OnClickListener {

  private final DefaultTrackSelector selector;

  private CheckedTextView disableView;
  private CheckedTextView defaultView;
  private CheckedTextView[][] trackViews;

  private TrackInfo trackInfo;
  private int rendererIndex;
  private TrackGroupArray trackGroups;
  private boolean[] trackGroupsAdaptive;

  private boolean isDisabled;
  private TrackSelection override;

  /**
   * @param selector The track selector.
   */
  public TrackSelectionHelper(DefaultTrackSelector selector) {
    this.selector = selector;
  }

  /**
   * Shows the selection dialog for a given renderer.
   *
   * @param activity The parent activity.
   * @param titleId The dialog's title.
   * @param trackInfo The current track information.
   * @param rendererIndex The index of the renderer.
   */
  public void showSelectionDialog(Activity activity, int titleId, TrackInfo trackInfo,
      int rendererIndex) {
    this.trackInfo = trackInfo;
    this.rendererIndex = rendererIndex;

    trackGroups = trackInfo.getTrackGroups(rendererIndex);
    trackGroupsAdaptive = new boolean[trackGroups.length];
    for (int i = 0; i < trackGroups.length; i++) {
      trackGroupsAdaptive[i] = trackInfo.getAdaptiveSupport(rendererIndex, i, false)
          != TrackRenderer.ADAPTIVE_NOT_SUPPORTED;
    }
    isDisabled = selector.getRendererDisabled(rendererIndex);
    if (selector.hasSelectionOverride(rendererIndex, trackGroups)) {
      override = trackInfo.getTrackSelection(rendererIndex);
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(titleId)
        .setView(buildView(LayoutInflater.from(builder.getContext())))
        .setPositiveButton(android.R.string.ok, this)
        .setNegativeButton(android.R.string.cancel, null)
        .create()
        .show();<commit_msg>Fully reset state when displaying track selections.<commit_after>/*
 * Copyright (C) 2014 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 com.google.android.exoplayer.demo.ui;

import com.google.android.exoplayer.DefaultTrackSelector;
import com.google.android.exoplayer.DefaultTrackSelector.TrackInfo;
import com.google.android.exoplayer.Format;
import com.google.android.exoplayer.TrackGroup;
import com.google.android.exoplayer.TrackGroupArray;
import com.google.android.exoplayer.TrackRenderer;
import com.google.android.exoplayer.TrackSelection;
import com.google.android.exoplayer.demo.R;
import com.google.android.exoplayer.util.MimeTypes;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckedTextView;

import java.util.Arrays;
import java.util.Locale;

/**
 * Helper class for displaying track selection dialogs.
 */
public class TrackSelectionHelper implements View.OnClickListener, DialogInterface.OnClickListener {

  private final DefaultTrackSelector selector;

  private TrackInfo trackInfo;
  private int rendererIndex;
  private TrackGroupArray trackGroups;
  private boolean[] trackGroupsAdaptive;
  private boolean isDisabled;
  private TrackSelection override;

  private CheckedTextView disableView;
  private CheckedTextView defaultView;
  private CheckedTextView[][] trackViews;

  /**
   * @param selector The track selector.
   */
  public TrackSelectionHelper(DefaultTrackSelector selector) {
    this.selector = selector;
  }

  /**
   * Shows the selection dialog for a given renderer.
   *
   * @param activity The parent activity.
   * @param titleId The dialog's title.
   * @param trackInfo The current track information.
   * @param rendererIndex The index of the renderer.
   */
  public void showSelectionDialog(Activity activity, int titleId, TrackInfo trackInfo,
      int rendererIndex) {
    this.trackInfo = trackInfo;
    this.rendererIndex = rendererIndex;

    trackGroups = trackInfo.getTrackGroups(rendererIndex);
    trackGroupsAdaptive = new boolean[trackGroups.length];
    for (int i = 0; i < trackGroups.length; i++) {
      trackGroupsAdaptive[i] = trackInfo.getAdaptiveSupport(rendererIndex, i, false)
          != TrackRenderer.ADAPTIVE_NOT_SUPPORTED;
    }
    isDisabled = selector.getRendererDisabled(rendererIndex);
    override = selector.hasSelectionOverride(rendererIndex, trackGroups)
        ? trackInfo.getTrackSelection(rendererIndex) : null;

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(titleId)
        .setView(buildView(LayoutInflater.from(builder.getContext())))
        .setPositiveButton(android.R.string.ok, this)
        .setNegativeButton(android.R.string.cancel, null)
        .create()
        .show();
{'fraction_non_alphanumeric': 0.08570619067856637, 'fraction_numerical': 0.0025499362515937103, 'mean_word_length': 4.46862896979086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2565104', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1887, 'n_words': 537}