<commit_before>package com.dptsolutions.youtubeplayercustomoverlayexample;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.GestureDetectorCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerFragment;

import org.apache.commons.lang3.time.DurationFormatUtils;

/**
 * Fragment for playing YouTube videos in Fullscreen landscape
 */
public class CustomUIYouTubePlayerFragment extends YouTubePlayerFragment implements YouTubePlayer.OnInitializedListener, YouTubePlayer.PlayerStateChangeListener, YouTubePlayer.PlaybackEventListener {

    private static final String TAG = "CustomUIYTPlayerFrag";

    protected String youtubeId;

    protected PlayerControlsPopupWindow playerControls;
    protected int lastPositionMillis;

    private YouTubePlayer youtubePlayer;
    private GestureDetectorCompat gestureDetector;

    private static final int RECOVERY_DIALOG_REQUEST = 1;
    private static final int HIDE_STATUS_BAR_FLAGS_IMMERSIVE = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    private static final int HIDE_STATUS_BAR_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_FULLSCREEN;
    private static final int SEEK_BAR_UPDATE_INTERVAL = 1000;
    private static final int HIDE_STATUS_BAR_DELAY_MILLIS = 3000;

    public static final String ARG_VIDEO_YOUTUBE_ID = CustomUIYouTubePlayerFragment.class.getPackage().getName() + ".arg_video_youtube_id";
    public static final String STATE_LAST_POSITION_MILLIS = CustomUIYouTubePlayerFragment.class.getPackage().getName() + ".state_last_millis";

    private Handler seekBarPositionHandler = new Handler();
    private Runnable seekBarPositionRunnable = new Runnable() {
        @Override
        public void run() {
            Log.d(TAG, String.format("In CustomUIYouTubePlayerFragment#seekBarPositionRunnable.run. Current time in millis is %d. Current length in millis is %d", youtubePlayer.getCurrentTimeMillis(), youtubePlayer.getDurationMillis()));
            //Docs say that getDurationMillis() can change over time, so if things have changed, update SeekBarMax so we don't potentially get out of range
            if(playerControls.getSeekBarMax() != youtubePlayer.getDurationMillis()) {
                Log.d(TAG, String.format("In CustomUIYouTubePlayerFragment#seekBarPositionRunnable.run. Updating SeekBarMax from %d to %d", playerControls.getSeekBarMax(), youtubePlayer.getDurationMillis()));
                playerControls.setSeekBarMax(youtubePlayer.getDurationMillis());
            }
            playerControls.setSeekBarPosition(youtubePlayer.getCurrentTimeMillis());
            scheduleSeekBarUpdate();
        }
    };
    private GestureDetector.OnGestureListener onGestureListener = new GestureDetector.OnGestureListener() {

        @Override
        public boolean onDown(MotionEvent e) {
            toggleControlsVisibility();
            return true;
        }

        @Override
        public void onShowPress(MotionEvent e) {

        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }<commit_msg>Fix the tap gesture. Gotta eat the onDown to keep whatever voodoo the YouTubePlayerFragment code is doing to eat touches on it. Now controls properly show/hide only on a tap.<commit_after>package com.dptsolutions.youtubeplayercustomoverlayexample;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.GestureDetectorCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerFragment;

import org.apache.commons.lang3.time.DurationFormatUtils;

/**
 * Fragment for playing YouTube videos in Fullscreen landscape
 */
public class CustomUIYouTubePlayerFragment extends YouTubePlayerFragment implements YouTubePlayer.OnInitializedListener, YouTubePlayer.PlayerStateChangeListener, YouTubePlayer.PlaybackEventListener {

    private static final String TAG = "CustomUIYTPlayerFrag";

    protected String youtubeId;

    protected PlayerControlsPopupWindow playerControls;
    protected int lastPositionMillis;

    private YouTubePlayer youtubePlayer;
    private GestureDetectorCompat gestureDetector;

    private static final int RECOVERY_DIALOG_REQUEST = 1;
    private static final int HIDE_STATUS_BAR_FLAGS_IMMERSIVE = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_FULLSCREEN|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    private static final int HIDE_STATUS_BAR_FLAGS = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LAYOUT_STABLE|View.SYSTEM_UI_FLAG_FULLSCREEN;
    private static final int SEEK_BAR_UPDATE_INTERVAL = 1000;
    private static final int HIDE_STATUS_BAR_DELAY_MILLIS = 3000;

    public static final String ARG_VIDEO_YOUTUBE_ID = CustomUIYouTubePlayerFragment.class.getPackage().getName() + ".arg_video_youtube_id";
    public static final String STATE_LAST_POSITION_MILLIS = CustomUIYouTubePlayerFragment.class.getPackage().getName() + ".state_last_millis";

    private Handler seekBarPositionHandler = new Handler();
    private Runnable seekBarPositionRunnable = new Runnable() {
        @Override
        public void run() {
            Log.d(TAG, String.format("In CustomUIYouTubePlayerFragment#seekBarPositionRunnable.run. Current time in millis is %d. Current length in millis is %d", youtubePlayer.getCurrentTimeMillis(), youtubePlayer.getDurationMillis()));
            //Docs say that getDurationMillis() can change over time, so if things have changed, update SeekBarMax so we don't potentially get out of range
            if(playerControls.getSeekBarMax() != youtubePlayer.getDurationMillis()) {
                Log.d(TAG, String.format("In CustomUIYouTubePlayerFragment#seekBarPositionRunnable.run. Updating SeekBarMax from %d to %d", playerControls.getSeekBarMax(), youtubePlayer.getDurationMillis()));
                playerControls.setSeekBarMax(youtubePlayer.getDurationMillis());
            }
            playerControls.setSeekBarPosition(youtubePlayer.getCurrentTimeMillis());
            scheduleSeekBarUpdate();
        }
    };
    private GestureDetector.OnGestureListener onGestureListener = new GestureDetector.OnGestureListener() {

        @Override
        public boolean onDown(MotionEvent e) {
            return true;
        }

        @Override
        public void onShowPress(MotionEvent e) {

        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            toggleControlsVisibility();
            return true;
        }
{'fraction_non_alphanumeric': 0.07225934174709231, 'fraction_numerical': 0.002722098490472655, 'mean_word_length': 4.716407355021216, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6653226', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2196, 'n_words': 488}