<commit_before>package com.cube.storm.ui.activity;

import android.annotation.SuppressLint;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.cube.storm.UiSettings;
import com.cube.storm.ui.R;
import com.cube.storm.ui.lib.handler.LinkHandler;
import com.cube.storm.ui.model.property.VideoProperty;
import com.cube.storm.util.lib.resolver.Resolver;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.PlaybackPreparer;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.TrackSelectionView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener;

import java.util.Arrays;
import java.util.List;

import static android.util.TypedValue.COMPLEX_UNIT_SP;
import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;

/**
 * Video player used to play videos from assets/file/http URI streams.
 *
 * @author <NAME>
 * @project LightningUi
 */
public class VideoPlayerActivity extends AppCompatActivity implements PlaybackPreparer, View.OnClickListener
{
	public static final String EXTRA_VIDEO = "extra_video";

	/**
	 * Priority list of Youtube itag formats to attempt to retrieve
	 * <p>
	 * See http://en.wikipedia.org/wiki/YouTube#Quality_and_formats
	 * <p>
	 * TODO: In future can add DASH media sources
	 */
	private static final List<Integer> YOUTUBE_ITAG_PREFERENCE = Arrays.asList(22, 18, 43, 5, 36, 17);

	// Saved instance state keys.
	private static final String KEY_WINDOW = "window";
	private static final String KEY_POSITION = "position";
	private static final String KEY_AUTO_PLAY = "auto_play";
	private static final String KEY_URI = "playing_uri";
	private static final String KEY_TRACK_SELECTOR_PARAMETERS = "track_selector_parameters";

	private PlayerView playerView;
	private ProgressBar progressBar;

	private DataSource.Factory dataSourceFactory;
	private SimpleExoPlayer player;
	private MediaSource mediaSource;
	private DefaultTrackSelector trackSelector;

	private Uri uri;
	private boolean startAutoPlay;
	private int startWindow;
	private long startPosition;
	private ImageButton closedCaptionsButton;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "storm-video-player"));
		setContentView(R.layout.activity_video_player);

		closedCaptionsButton = findViewById(R.id.cc_button);
		closedCaptionsButton.setOnClickListener(this);
		playerView = findViewById(R.id.player_view);
		progressBar = findViewById(R.id.progress);
		playerView.requestFocus();

		playerView.getSubtitleView().setFixedTextSize(COMPLEX_UNIT_SP, 10f);

		if (uri == null
		    && getIntent().hasExtra(EXTRA_VIDEO)
		    && getIntent().getExtras().getSerializable(EXTRA_VIDEO) != null)
		{
			VideoProperty videoProperty = (VideoProperty) getIntent().getSerializableExtra(EXTRA_VIDEO);
			uri = Uri.parse(videoProperty.getSrc().getDestination());
		}

		trackSelector = new DefaultTrackSelector();

		if (savedInstanceState != null)
		{
			startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY);
			startWindow = savedInstanceState.getInt(KEY_WINDOW);
			startPosition = savedInstanceState.getLong(KEY_POSITION);
			String uriString = savedInstanceState.getString(KEY_URI);
			uri = uriString != null ? Uri.parse(uriString) : null;

			DefaultTrackSelector.Parameters initialTrackSelectorParameters = savedInstanceState.getParcelable(KEY_TRACK_SELECTOR_PARAMETERS);
			if (initialTrackSelectorParameters != null)
			{
				trackSelector.setParameters(initialTrackSelectorParameters);<commit_msg>Remove caption textSize override. Using caption settings on device instead.<commit_after>package com.cube.storm.ui.activity;

import android.annotation.SuppressLint;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.Toast;
import com.cube.storm.UiSettings;
import com.cube.storm.ui.R;
import com.cube.storm.ui.lib.handler.LinkHandler;
import com.cube.storm.ui.model.property.VideoProperty;
import com.cube.storm.util.lib.resolver.Resolver;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.ExoPlayerFactory;
import com.google.android.exoplayer2.PlaybackPreparer;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
import com.google.android.exoplayer2.ui.PlayerView;
import com.google.android.exoplayer2.ui.TrackSelectionView;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener;

import java.util.Arrays;
import java.util.List;

import static com.google.android.exoplayer2.Player.REPEAT_MODE_ONE;

/**
 * Video player used to play videos from assets/file/http URI streams.
 *
 * @author <NAME>
 * @project LightningUi
 */
public class VideoPlayerActivity extends AppCompatActivity implements PlaybackPreparer, View.OnClickListener
{
	public static final String EXTRA_VIDEO = "extra_video";

	/**
	 * Priority list of Youtube itag formats to attempt to retrieve
	 * <p>
	 * See http://en.wikipedia.org/wiki/YouTube#Quality_and_formats
	 * <p>
	 * TODO: In future can add DASH media sources
	 */
	private static final List<Integer> YOUTUBE_ITAG_PREFERENCE = Arrays.asList(22, 18, 43, 5, 36, 17);

	// Saved instance state keys.
	private static final String KEY_WINDOW = "window";
	private static final String KEY_POSITION = "position";
	private static final String KEY_AUTO_PLAY = "auto_play";
	private static final String KEY_URI = "playing_uri";
	private static final String KEY_TRACK_SELECTOR_PARAMETERS = "track_selector_parameters";

	private PlayerView playerView;
	private ProgressBar progressBar;

	private DataSource.Factory dataSourceFactory;
	private SimpleExoPlayer player;
	private MediaSource mediaSource;
	private DefaultTrackSelector trackSelector;

	private Uri uri;
	private boolean startAutoPlay;
	private int startWindow;
	private long startPosition;
	private ImageButton closedCaptionsButton;

	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "storm-video-player"));
		setContentView(R.layout.activity_video_player);

		closedCaptionsButton = findViewById(R.id.cc_button);
		closedCaptionsButton.setOnClickListener(this);
		playerView = findViewById(R.id.player_view);
		progressBar = findViewById(R.id.progress);
		playerView.requestFocus();

		if (uri == null
		    && getIntent().hasExtra(EXTRA_VIDEO)
		    && getIntent().getExtras().getSerializable(EXTRA_VIDEO) != null)
		{
			VideoProperty videoProperty = (VideoProperty) getIntent().getSerializableExtra(EXTRA_VIDEO);
			uri = Uri.parse(videoProperty.getSrc().getDestination());
		}

		trackSelector = new DefaultTrackSelector();

		if (savedInstanceState != null)
		{
			startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY);
			startWindow = savedInstanceState.getInt(KEY_WINDOW);
			startPosition = savedInstanceState.getLong(KEY_POSITION);
			String uriString = savedInstanceState.getString(KEY_URI);
			uri = uriString != null ? Uri.parse(uriString) : null;

			DefaultTrackSelector.Parameters initialTrackSelectorParameters = savedInstanceState.getParcelable(KEY_TRACK_SELECTOR_PARAMETERS);
			if (initialTrackSelectorParameters != null)
			{
				trackSelector.setParameters(initialTrackSelectorParameters);
{'fraction_non_alphanumeric': 0.0946619972407938, 'fraction_numerical': 0.0067918921787116626, 'mean_word_length': 6.166539923954373, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6204601', 'n_tokens_mistral': 2944, 'n_tokens_neox': 2776, 'n_words': 545}