<commit_before>package com.example.android.boombox;


import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.os.Handler;

import java.util.ArrayList;

import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import java.util.concurrent.TimeUnit;

import org.w3c.dom.Text;


/**
 * A simple {@link Fragment} subclass.
 */
public class SongsFragment extends Fragment {

    //Declare Variables
    private Handler songHandler = new Handler();

    private ImageView previousButton, rewindButton, pauseButton, playButton, forwardButton, nextButton;
    private SeekBar seekBar;
    //private TextView startTimeView, songTitle, endTimeView;

    private double startTime = 0;
    private double finalTime = 0;

    private int forwardTime = 5000;
    private int backwardTime = 5000;

    //Keeps track of Current Song
    private int currentIndex;



    private MediaPlayer mMediaPlayer;
    private MediaPlayer.OnCompletionListener mCompletionListener = new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            releaseMediaPlayer();
        }
    };


    private AudioManager mAudioManager;
    AudioManager.OnAudioFocusChangeListener afListener = new AudioManager.OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {
            if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
                mMediaPlayer.start();

            } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
                releaseMediaPlayer();
            } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
                mMediaPlayer.pause();
                mMediaPlayer.seekTo(0);
            }

        }
    };


    public SongsFragment() {
        // Required empty public constructor
    }

    public static int oneTimeOnly = 0;

    @Override
    public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.words_list, container, false);

        //Initialize Views and Buttons
        previousButton = (ImageView) rootView.findViewById(R.id.previousButton);
        rewindButton = (ImageView) rootView.findViewById(R.id.rewindButton);
        pauseButton = (ImageView) rootView.findViewById(R.id.pauseButton);
        playButton = (ImageView) rootView.findViewById(R.id.playButton);
        forwardButton = (ImageView) rootView.findViewById(R.id.forwardButton);
        nextButton = (ImageView) rootView.findViewById(R.id.nextButton);

        seekBar = (SeekBar) rootView.findViewById(R.id.seekBar);
        seekBar.setClickable(false);


        //startTimeView = (TextView) rootView.findViewById(R.id.startTime);
        //songTitle = (TextView) rootView.findViewById(R.id.songTitle);
       // endTimeView = (TextView) rootView.findViewById(R.id.endTime);


        mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);


        final ArrayList<Word> songs = new ArrayList<>();

        songs.add(new Word("Childish Gambino", "3005", R.drawable.childish_gambino_because, R.raw.childish_gambino_3005));
        songs.add(new Word("Childish Gambino", "Freestyle", R.drawable.childish_gambino, R.raw.childish_gambino_freestyle));
        songs.add(new Word("Gas Lab", "Chemistry", R.drawable.gas_lab, R.raw.gas_lab_chemistry));
        songs.add(new Word("Gas Lab (feat. Natayla & Traum Diggs)", "Jazz Hop", R.drawable.gas_lab, R.raw.gas_lab_jazz_hop));
        songs.add(new Word("J.Cole", "Losing my Balance", R.drawable.j_cole, R.raw.jcole_losing_my_balance));
        songs.add(new Word("JABS (feat. Willow)", "Payíva (Prod. JABS)", R.drawable.jabs_willow, R.raw.jabs_payiva));
        songs.add(new Word("Téo", "Enlightened Now", R.drawable.teo, R.raw.teo_enlightened_now));
        songs.add(new Word("Téo", "How Low", R.drawable.teo, R.raw.teo_how_low));
        songs.add(new Word("Téo", "Selfless-ish", R.drawable.teo, R.raw.teo_selflessish));
        songs.add(new Word("Tyler The Creator (feat. Frank Ocean) ", "She", R.drawable.tyler_the_creator, R.raw.tyler_the_creator_she));
        songs.add(new Word("Willow (feat. SZA) ", "9", R.drawable.willow, R.raw.willow_9));
        songs.add(new Word("Willow ", "Female Energy", R.drawable.willow, R.raw.willow_female_energy));
        songs.add(new Word("Willow ", "Marceline", R.drawable.willow, R.raw.willow_marceline));


        WordAdapter itemsAdapter = new WordAdapter(getActivity(), songs, R.color.category_colors);
        ListView listView = (ListView) rootView.findViewById(R.id.list);
        //final LinearLayout musicControls = (LinearLayout) rootView.findViewById(R.id.musicControls);


        listView.setAdapter(itemsAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               //Hide the music controls until a user clicks on a song for better User Experience
                // musicControls.setVisibility(View.VISIBLE);
                final Word word = songs.get(position);
                releaseMediaPlayer();

                int requestResult = mAudioManager.requestAudioFocus(afListener,
                        AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
                if (requestResult == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
                    mMediaPlayer = MediaPlayer.create(getActivity(), word.getSoundResourceId());
                    mMediaPlayer.start();

                    //Method to Play Next Song
                    nextButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mMediaPlayer.pause();
                            currentIndex =1;
                            if (currentIndex < (songs.size() - 1)) {
                                mMediaPlayer = MediaPlayer.create(getActivity(), word.getSoundResourceId() + currentIndex);
                                mMediaPlayer.start();
                                currentIndex ++;
                            }
                            else if(mMediaPlayer != null){
                                // Set the media player back to null. For our code, we've decided that
                                // setting the media player to null is an easy way to tell that the media player
                                // is not configured to play an audio file at the moment.
                                mMediaPlayer = null;
                                mAudioManager.abandonAudioFocus(afListener);
                            }
                        }
                    });
<commit_msg>Initial Commit<commit_after>package com.example.android.boombox;


import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.os.Handler;

import java.util.ArrayList;

import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import java.util.concurrent.TimeUnit;

import org.w3c.dom.Text;


/**
 * A simple {@link Fragment} subclass.
 */
public class SongsFragment extends Fragment {

    //Declare Variables
    private Handler songHandler = new Handler();

    private ImageView previousButton, rewindButton, pauseButton, playButton, forwardButton, nextButton;
    private SeekBar seekBar;
    //private TextView startTimeView, songTitle, endTimeView;

    private double startTime = 0;
    private double finalTime = 0;

    private int forwardTime = 5000;
    private int backwardTime = 5000;

    //Keeps track of Current Song
    private int currentIndex;



    private MediaPlayer mMediaPlayer;
    private MediaPlayer.OnCompletionListener mCompletionListener = new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            releaseMediaPlayer();
        }
    };


    private AudioManager mAudioManager;
    AudioManager.OnAudioFocusChangeListener afListener = new AudioManager.OnAudioFocusChangeListener() {
        public void onAudioFocusChange(int focusChange) {
            if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
                mMediaPlayer.start();

            } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
                releaseMediaPlayer();
            } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
                mMediaPlayer.pause();
                mMediaPlayer.seekTo(0);
            }

        }
    };


    public SongsFragment() {
        // Required empty public constructor
    }

    public static int oneTimeOnly = 0;

    @Override
    public View onCreateView(LayoutInflater inflater, final ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.words_list, container, false);

        //Initialize Views and Buttons
        previousButton = (ImageView) rootView.findViewById(R.id.previousButton);
        rewindButton = (ImageView) rootView.findViewById(R.id.rewindButton);
        pauseButton = (ImageView) rootView.findViewById(R.id.pauseButton);
        playButton = (ImageView) rootView.findViewById(R.id.playButton);
        forwardButton = (ImageView) rootView.findViewById(R.id.forwardButton);
        nextButton = (ImageView) rootView.findViewById(R.id.nextButton);

        seekBar = (SeekBar) rootView.findViewById(R.id.seekBar);
        seekBar.setClickable(false);


        //startTimeView = (TextView) rootView.findViewById(R.id.startTime);
        //songTitle = (TextView) rootView.findViewById(R.id.songTitle);
       // endTimeView = (TextView) rootView.findViewById(R.id.endTime);


        mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);


        final ArrayList<Word> songs = new ArrayList<>();

        songs.add(new Word("Childish Gambino", "3005", R.drawable.childish_gambino_because, R.raw.childish_gambino_3005));
        songs.add(new Word("Childish Gambino", "Freestyle", R.drawable.childish_gambino, R.raw.childish_gambino_freestyle));
        songs.add(new Word("Gas Lab", "Chemistry", R.drawable.gas_lab, R.raw.gas_lab_chemistry));
        songs.add(new Word("Gas Lab (feat. Natayla & Traum Diggs)", "Jazz Hop", R.drawable.gas_lab, R.raw.gas_lab_jazz_hop));
        songs.add(new Word("J.Cole", "Losing my Balance", R.drawable.j_cole, R.raw.jcole_losing_my_balance));
        songs.add(new Word("JABS (feat. Willow)", "Payíva (Prod. JABS)", R.drawable.jabs_willow, R.raw.jabs_payiva));
        songs.add(new Word("Téo", "Enlightened Now", R.drawable.teo, R.raw.teo_enlightened_now));
        songs.add(new Word("Téo", "How Low", R.drawable.teo, R.raw.teo_how_low));
        songs.add(new Word("Téo", "Selfless-ish", R.drawable.teo, R.raw.teo_selflessish));
        songs.add(new Word("Tyler The Creator (feat. Frank Ocean) ", "She", R.drawable.tyler_the_creator, R.raw.tyler_the_creator_she));
        songs.add(new Word("Willow (feat. SZA) ", "9", R.drawable.willow, R.raw.willow_9));
        songs.add(new Word("Willow ", "Female Energy", R.drawable.willow, R.raw.willow_female_energy));
        songs.add(new Word("Willow ", "Marceline", R.drawable.willow, R.raw.willow_marceline));


        WordAdapter itemsAdapter = new WordAdapter(getActivity(), songs, R.color.category_colors);
        ListView listView = (ListView) rootView.findViewById(R.id.list);
        //final LinearLayout musicControls = (LinearLayout) rootView.findViewById(R.id.musicControls);


        listView.setAdapter(itemsAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
               //Hide the music controls until a user clicks on a song for better User Experience
                // musicControls.setVisibility(View.VISIBLE);
                final Word word = songs.get(position);
                releaseMediaPlayer();

                int requestResult = mAudioManager.requestAudioFocus(afListener,
                        AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
                if (requestResult == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
                    mMediaPlayer = MediaPlayer.create(getActivity(), word.getSoundResourceId());
                    mMediaPlayer.start();

                    //Method to Play Next Song
                    nextButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            mMediaPlayer.pause();
                            currentIndex ++;
                            if (currentIndex < (songs.size() - 1)) {
                                mMediaPlayer = MediaPlayer.create(getActivity(), word.getSoundResourceId() + currentIndex);
                                mMediaPlayer.start();
                            }
                           // else if(mMediaPlayer != null){
                                // Set the media player back to null. For our code, we've decided that
                                // setting the media player to null is an easy way to tell that the media player
                                // is not configured to play an audio file at the moment.
                              //  mMediaPlayer = null;
                              //  mAudioManager.abandonAudioFocus(afListener);
                           // }
                        }
                    });

{'fraction_non_alphanumeric': 0.10093767236624379, 'fraction_numerical': 0.0035162713734142306, 'mean_word_length': 2.522340942204954, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1217882', 'n_tokens_mistral': 4165, 'n_tokens_neox': 3899, 'n_words': 857}