<commit_before>/*
 * Copyright (C) 2017 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.exoplayer2.castdemo;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ext.cast.MediaItem;
import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.gms.cast.CastMediaControlIntent;
import com.google.android.gms.cast.framework.CastButtonFactory;
import com.google.android.gms.cast.framework.CastContext;
import com.google.android.gms.dynamite.DynamiteModule;
import java.util.Collections;

/**
 * An activity that plays video using {@link SimpleExoPlayer} and supports casting using ExoPlayer's
 * Cast extension.
 */
public class MainActivity extends AppCompatActivity
    implements OnClickListener, PlayerManager.Listener {

  private final MediaItem.Builder mediaItemBuilder;

  private PlayerView localPlayerView;
  private PlayerControlView castControlView;
  private PlayerManager playerManager;
  private RecyclerView mediaQueueList;
  private MediaQueueListAdapter mediaQueueListAdapter;
  private CastContext castContext;

  public MainActivity() {
    mediaItemBuilder = new MediaItem.Builder();
  }

  // Activity lifecycle methods.

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Getting the cast context later than onStart can cause device discovery not to take place.
    try {
      castContext = CastContext.getSharedInstance(this);
    } catch (RuntimeException e) {
      Throwable cause = e.getCause();
      while (cause != null) {
        if (cause instanceof DynamiteModule.LoadingException) {
          setContentView(R.layout.cast_context_error);
          return;
        }
        cause = cause.getCause();
      }
      // Unknown error. We propagate it.
      throw e;
    }

    setContentView(R.layout.main_activity);

    localPlayerView = findViewById(R.id.local_player_view);
    localPlayerView.requestFocus();

    castControlView = findViewById(R.id.cast_control_view);

    mediaQueueList = findViewById(R.id.sample_list);
    ItemTouchHelper helper = new ItemTouchHelper(new RecyclerViewCallback());
    helper.attachToRecyclerView(mediaQueueList);
    mediaQueueList.setLayoutManager(new LinearLayoutManager(this));
    mediaQueueList.setHasFixedSize(true);
    mediaQueueListAdapter = new MediaQueueListAdapter();

    findViewById(R.id.add_sample_button).setOnClickListener(this);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu, menu);
    CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
    return true;
  }

  @Override
  public void onResume() {
    super.onResume();
    if (castContext == null) {
      // There is no Cast context to work with. Do nothing.
      return;
    }
    String applicationId = castContext.getCastOptions().getReceiverApplicationId();
    switch (applicationId) {
      case CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID:
        playerManager =
            new DefaultReceiverPlayerManager(
                /* listener= */ this,
                localPlayerView,
                castControlView,
                /* context= */ this,
                castContext);
        break;
      case ExoCastOptionsProvider.RECEIVER_ID:
        playerManager =
            new ExoCastPlayerManager(
                /* listener= */ this,
                localPlayerView,
                castControlView,
                /* context= */ this,
                castContext);
        break;
      default:
        throw new IllegalStateException("Illegal receiver app id: " + applicationId);
    }
    mediaQueueList.setAdapter(mediaQueueListAdapter);
  }<commit_msg>Fix copybara stripping<commit_after>/*
 * Copyright (C) 2017 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.exoplayer2.castdemo;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.ext.cast.MediaItem;
import com.google.android.exoplayer2.ui.PlayerControlView;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.gms.cast.CastMediaControlIntent;
import com.google.android.gms.cast.framework.CastButtonFactory;
import com.google.android.gms.cast.framework.CastContext;
import com.google.android.gms.dynamite.DynamiteModule;
import java.util.Collections;

/**
 * An activity that plays video using {@link SimpleExoPlayer} and supports casting using ExoPlayer's
 * Cast extension.
 */
public class MainActivity extends AppCompatActivity
    implements OnClickListener, PlayerManager.Listener {

  private final MediaItem.Builder mediaItemBuilder;

  private PlayerView localPlayerView;
  private PlayerControlView castControlView;
  private PlayerManager playerManager;
  private RecyclerView mediaQueueList;
  private MediaQueueListAdapter mediaQueueListAdapter;
  private CastContext castContext;

  public MainActivity() {
    mediaItemBuilder = new MediaItem.Builder();
  }

  // Activity lifecycle methods.

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Getting the cast context later than onStart can cause device discovery not to take place.
    try {
      castContext = CastContext.getSharedInstance(this);
    } catch (RuntimeException e) {
      Throwable cause = e.getCause();
      while (cause != null) {
        if (cause instanceof DynamiteModule.LoadingException) {
          setContentView(R.layout.cast_context_error);
          return;
        }
        cause = cause.getCause();
      }
      // Unknown error. We propagate it.
      throw e;
    }

    setContentView(R.layout.main_activity);

    localPlayerView = findViewById(R.id.local_player_view);
    localPlayerView.requestFocus();

    castControlView = findViewById(R.id.cast_control_view);

    mediaQueueList = findViewById(R.id.sample_list);
    ItemTouchHelper helper = new ItemTouchHelper(new RecyclerViewCallback());
    helper.attachToRecyclerView(mediaQueueList);
    mediaQueueList.setLayoutManager(new LinearLayoutManager(this));
    mediaQueueList.setHasFixedSize(true);
    mediaQueueListAdapter = new MediaQueueListAdapter();

    findViewById(R.id.add_sample_button).setOnClickListener(this);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu, menu);
    CastButtonFactory.setUpMediaRouteButton(this, menu, R.id.media_route_menu_item);
    return true;
  }

  @Override
  public void onResume() {
    super.onResume();
    if (castContext == null) {
      // There is no Cast context to work with. Do nothing.
      return;
    }
    String applicationId = castContext.getCastOptions().getReceiverApplicationId();
    switch (applicationId) {
      case CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID:
        playerManager =
            new DefaultReceiverPlayerManager(
                /* listener= */ this,
                localPlayerView,
                castControlView,
                /* context= */ this,
                castContext);
        break;
      default:
        throw new IllegalStateException("Illegal receiver app id: " + applicationId);
    }
    mediaQueueList.setAdapter(mediaQueueListAdapter);
  }
{'fraction_non_alphanumeric': 0.08610780816488307, 'fraction_numerical': 0.004161712247324614, 'mean_word_length': 3.815362595419847, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5566721', 'n_tokens_mistral': 2800, 'n_tokens_neox': 2694, 'n_words': 671}