<commit_before>package com.kaltura.basicplayerdemo;

import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import com.kaltura.playersdk.KPPlayerConfig;
import com.kaltura.playersdk.PlayerViewController;
import com.kaltura.playersdk.casting.KCastRouterManagerListener;
import com.kaltura.playersdk.casting.KRouterInfo;
import com.kaltura.playersdk.events.KPErrorEventListener;
import com.kaltura.playersdk.events.KPPlayheadUpdateEventListener;
import com.kaltura.playersdk.events.KPStateChangedEventListener;
import com.kaltura.playersdk.events.KPlayerState;
import com.kaltura.playersdk.tracks.KTrackActions;
import com.kaltura.playersdk.tracks.TrackFormat;
import com.kaltura.playersdk.types.KPError;
import com.kaltura.playersdk.tracks.TrackType;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

//<<<<<<< HEAD
//public class MainActivity extends AppCompatActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, /*KPFullScreenToggeledEventListener,*/ KPPlayheadUpdateEventListener,KPErrorEventListener,KPStateChangedEventListener {
//=======
public class MainActivity extends AppCompatActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, KTrackActions.EventListener, KPErrorEventListener, KPPlayheadUpdateEventListener, KPStateChangedEventListener {
//>>>>>>> FEM-385_Tracks
    private static final String TAG = "BasicPlayerDemo";

    private static final int MENU_GROUP_TRACKS = 1;
    private static final int TRACK_DISABLED = -1;
    private static final int ID_OFFSET = 2;

    private Button mPlayPauseButton;
//    private Button ccButton;
    private SeekBar mSeekBar;
    private PlayerViewController mPlayer;
    private boolean onCreate = false;
    private ArrayList<KRouterInfo> mRouterInfos = new ArrayList<>();
    private boolean isCCActive = false;

    private Button ccButton;
    private boolean enableBackgroundAudio;
    private Button videoButton;
    private Button audioButton;
    private Button textButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        setContentView(R.layout.activity_main);

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }

        videoButton = (Button) findViewById(R.id.video_controls);
        audioButton = (Button) findViewById(R.id.audio_controls);
        textButton = (Button) findViewById(R.id.text_controls);
        mPlayPauseButton = (Button)findViewById(R.id.button);
        mPlayPauseButton.setOnClickListener(this);
        mPlayPauseButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                getPlayer().getMediaControl().replay();
                return true;
            }
        });
        mSeekBar = (SeekBar)findViewById(R.id.seekBar);
        mSeekBar.setOnSeekBarChangeListener(this);
        ccButton = (Button)findViewById(R.id.ccButto);
        ccButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presentCCDevices();
            }
        });
        onCreate = true;
        getPlayer();
    }

    private PlayerViewController getPlayer() {
        if (mPlayer == null) {
            mPlayer = (PlayerViewController)findViewById(R.id.player);
            mPlayer.loadPlayerIntoActivity(this);


            KPPlayerConfig config = new KPPlayerConfig("http://kgit.html5video.org/tags/v2.43.rc11/mwEmbedFrame.php", "31638861", "1831271").setEntryId("1_ng282arr");
            //KPPlayerConfig config = new KPPlayerConfig("http://192.168.1.10/html5.kaltura/mwEmbed/mwEmbedFrame.php", "12905712", "243342").setEntryId("0_uka1msg4");
            //KPPlayerConfig config = new KPPlayerConfig("http://kgit.html5video.org/branches/master/mwEmbedFrame.php", "12905712", "243342").setEntryId("0_uka1msg4");
            config.addConfig("autoPlay", "true");
            
            config.addConfig("closedCaptions.plugin", "true");
            config.addConfig("sourceSelector.plugin", "true");
            config.addConfig("sourceSelector.displayMode", "bitrate");
            config.addConfig("audioSelector.plugin", "true");
            config.addConfig("closedCaptions.showEmbeddedCaptions", "true");

            
           // config.setAutoPlay(true);
            mPlayPauseButton.setText("Pause");

            config.addConfig("chromecast.plugin", "true");
            config.addConfig("chromecast.applicationID", "5247861F");
            config.addConfig("chromecast.useKalturaPlayer", "true");
            config.addConfig("chromecast.receiverLogo", "true");
            mPlayer.getKCastRouterManager().enableKalturaCastButton(false);

            mPlayer.addKPlayerEventListener("onEnableKeyboardBinding", "someId", new PlayerViewController.EventListener() {
                @Override
                public void handler(String eventName, String params) {
                    Log.d(TAG, eventName);
                }
            });

            mPlayer.getKCastRouterManager().setCastRouterManagerListener(new KCastRouterManagerListener() {
                @Override
                public void onCastButtonClicked() {
                    if (!isCCActive) {
                        presentCCDevices();
                    } else {
                        mPlayer.getKCastRouterManager().disconnect();
                    }
                }

                @Override
                public void onApplicationStatusChanged(boolean isConnected) {
                    isCCActive = isConnected;
                }

                @Override
                public void shouldPresentCastIcon(boolean didDetect) {
                    ccButton.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAddedCastDevice(KRouterInfo info) {
                    mRouterInfos.add(info);
                }

                @Override
                public void onRemovedCastDevice(KRouterInfo info) {
                    mRouterInfos.remove(info);
                }
            });
            mPlayer.initWithConfiguration(config);
//<<<<<<< HEAD
            //mPlayer.addEventListener(this);
            mPlayer.setOnKPErrorEventListener(this);
            mPlayer.setOnKPPlayheadUpdateEventListener(this);
            //mPlayer.setOnKPFullScreenToggeledEventListener(this);
            mPlayer.setOnKPStateChangedEventListener(this);
//=======
//            mPlayer.addEventListener(this);

            //// Tracks on Web supported only from 2.44
            //// if TracksEventListener  is removed the tracks will be pushed to the web layer o/w app controled via
            ////onTracksUpdate and the mPlayer.getTrackManager() methodes

            //mPlayer.setTracksEventListener(this);

//>>>>>>> FEM-385_Tracks
        }
        return mPlayer;
    }

    private void presentCCDevices() {
        final String[] items = new String[mRouterInfos.size()];
        for (int i = 0; i < items.length; i++   ) {
            items[i] = mRouterInfos.get(i).getRouterName();
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Make your selection");
        builder.setItems(items, new DialogInterface.OnClickListener() {<commit_msg>Main Activity cosmetics<commit_after>package com.kaltura.basicplayerdemo;

import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.SeekBar;

import com.kaltura.playersdk.KPPlayerConfig;
import com.kaltura.playersdk.PlayerViewController;
import com.kaltura.playersdk.casting.KCastRouterManagerListener;
import com.kaltura.playersdk.casting.KRouterInfo;
import com.kaltura.playersdk.events.KPErrorEventListener;
import com.kaltura.playersdk.events.KPPlayheadUpdateEventListener;
import com.kaltura.playersdk.events.KPStateChangedEventListener;
import com.kaltura.playersdk.events.KPlayerState;
import com.kaltura.playersdk.tracks.KTrackActions;
import com.kaltura.playersdk.tracks.TrackFormat;
import com.kaltura.playersdk.types.KPError;
import com.kaltura.playersdk.tracks.TrackType;

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;


// we can also add  implements for - KPFullScreenToggeledEventListener
public class MainActivity extends AppCompatActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, KTrackActions.EventListener, KPErrorEventListener, KPPlayheadUpdateEventListener, KPStateChangedEventListener {

    private static final String TAG = "BasicPlayerDemo";

    private static final int MENU_GROUP_TRACKS = 1;
    private static final int TRACK_DISABLED = -1;
    private static final int ID_OFFSET = 2;

    private Button mPlayPauseButton;
//    private Button ccButton;
    private SeekBar mSeekBar;
    private PlayerViewController mPlayer;
    private boolean onCreate = false;
    private ArrayList<KRouterInfo> mRouterInfos = new ArrayList<>();
    private boolean isCCActive = false;

    private Button ccButton;
    private boolean enableBackgroundAudio;
    private Button videoButton;
    private Button audioButton;
    private Button textButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
        setContentView(R.layout.activity_main);

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }

        videoButton = (Button) findViewById(R.id.video_controls);
        audioButton = (Button) findViewById(R.id.audio_controls);
        textButton = (Button) findViewById(R.id.text_controls);
        mPlayPauseButton = (Button)findViewById(R.id.button);
        mPlayPauseButton.setOnClickListener(this);
        mPlayPauseButton.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                getPlayer().getMediaControl().replay();
                return true;
            }
        });
        mSeekBar = (SeekBar)findViewById(R.id.seekBar);
        mSeekBar.setOnSeekBarChangeListener(this);
        ccButton = (Button)findViewById(R.id.ccButto);
        ccButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                presentCCDevices();
            }
        });
        onCreate = true;
        getPlayer();
    }

    private PlayerViewController getPlayer() {
        if (mPlayer == null) {
            mPlayer = (PlayerViewController)findViewById(R.id.player);
            mPlayer.loadPlayerIntoActivity(this);


            KPPlayerConfig config = new KPPlayerConfig("http://kgit.html5video.org/tags/v2.43.rc11/mwEmbedFrame.php", "31638861", "1831271").setEntryId("1_ng282arr");
            //KPPlayerConfig config = new KPPlayerConfig("http://192.168.1.10/html5.kaltura/mwEmbed/mwEmbedFrame.php", "12905712", "243342").setEntryId("0_uka1msg4");
            //KPPlayerConfig config = new KPPlayerConfig("http://kgit.html5video.org/branches/master/mwEmbedFrame.php", "12905712", "243342").setEntryId("0_uka1msg4");
            config.addConfig("autoPlay", "true");
            
            config.addConfig("closedCaptions.plugin", "true");
            config.addConfig("sourceSelector.plugin", "true");
            config.addConfig("sourceSelector.displayMode", "bitrate");
            config.addConfig("audioSelector.plugin", "true");
            config.addConfig("closedCaptions.showEmbeddedCaptions", "true");

            
           // config.setAutoPlay(true);
            mPlayPauseButton.setText("Pause");

            config.addConfig("chromecast.plugin", "true");
            config.addConfig("chromecast.applicationID", "5247861F");
            config.addConfig("chromecast.useKalturaPlayer", "true");
            config.addConfig("chromecast.receiverLogo", "true");
            mPlayer.getKCastRouterManager().enableKalturaCastButton(false);

            mPlayer.addKPlayerEventListener("onEnableKeyboardBinding", "someId", new PlayerViewController.EventListener() {
                @Override
                public void handler(String eventName, String params) {
                    Log.d(TAG, eventName);
                }
            });

            mPlayer.getKCastRouterManager().setCastRouterManagerListener(new KCastRouterManagerListener() {
                @Override
                public void onCastButtonClicked() {
                    if (!isCCActive) {
                        presentCCDevices();
                    } else {
                        mPlayer.getKCastRouterManager().disconnect();
                    }
                }

                @Override
                public void onApplicationStatusChanged(boolean isConnected) {
                    isCCActive = isConnected;
                }

                @Override
                public void shouldPresentCastIcon(boolean didDetect) {
                    ccButton.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAddedCastDevice(KRouterInfo info) {
                    mRouterInfos.add(info);
                }

                @Override
                public void onRemovedCastDevice(KRouterInfo info) {
                    mRouterInfos.remove(info);
                }
            });
            mPlayer.initWithConfiguration(config);

            //mPlayer.addEventListener(this); // if non separated listeners approach is used if not the below listeners are needed
            mPlayer.setOnKPErrorEventListener(this);
            mPlayer.setOnKPPlayheadUpdateEventListener(this);
            //mPlayer.setOnKPFullScreenToggeledEventListener(this);
            mPlayer.setOnKPStateChangedEventListener(this);


            ///  FOR TRACKS   ///
            //// Tracks on Web supported only from 2.44
            //// if TracksEventListener  is removed the tracks will be pushed to the web layer o/w app controled via
            ////onTracksUpdate and the mPlayer.getTrackManager() methodes

            //mPlayer.setTracksEventListener(this);


        }
        return mPlayer;
    }

    private void presentCCDevices() {
        final String[] items = new String[mRouterInfos.size()];
        for (int i = 0; i < items.length; i++   ) {
            items[i] = mRouterInfos.get(i).getRouterName();
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Make your selection");
        builder.setItems(items, new DialogInterface.OnClickListener() {
{'fraction_non_alphanumeric': 0.09780892845867273, 'fraction_numerical': 0.011239502431015975, 'mean_word_length': 2.7459791863765375, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6651932', 'n_tokens_mistral': 4489, 'n_tokens_neox': 4157, 'n_words': 750}