<commit_before>/**
   iAndroidRemote - Control your Android phone's music player using Apple Remote 
    
   Copyright 2011  <NAME>  (email : <EMAIL>)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

package com.sudarmuthu.android.iandroidremote;

import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

/**
 * The Android service which interacts with the Music Player service
 * 
 * @author "<NAME> (http://sudarmuthu.com)"
 *
 */
public class AdjustVolumeService extends Service {
	private static final String TAG = "iAndroidRemote";
	
	private AudioManager audioManager;
	private boolean isHtc; // Flag to identify whether the phone is using HTC Music player
	private MediaPlayerServiceConnection musicConn; //handler to music player service

	/**
	 * When the service is created for the first time
	 * 		 
	 * @see android.app.Service#onCreate()
	 */
	@Override
	public void onCreate() {
		Log.d(TAG, "Service Created");
		
		Context context = getApplicationContext();
		
		audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
		musicConn = new MediaPlayerServiceConnection();
		isHtc = true;
		
		Intent i = new Intent();
		
		// First try to connect to HTC Music player service
		i.setClassName("com.htc.music", "com.htc.music.MediaPlaybackService");
		
        if (!context.bindService(i, musicConn, Context.MODE_PRIVATE)) {
        	Log.d(TAG, "Using built-in media player");
        	
        	// Default to Android's Music Player service
        	isHtc = false;
            i.setClassName("com.android.music", "com.android.music.MediaPlaybackService");
            context.bindService(i, musicConn, Context.MODE_PRIVATE);
        }
		
		super.onCreate();
	}

	/**
	 * When the service is started
	 * 
	 * @see android.app.Service#onStart(android.content.Intent, int)
	 */
	@Override
	public void onStart(Intent intent, int startId) {
		
		Bundle bundle = intent.getExtras();
		String data = bundle.getString("Data");

		// Increase volume
		if (data.equals("Plus")) {
			Log.d(TAG, "Increased Volume");
			audioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND + AudioManager.FLAG_SHOW_UI);
		}

		// Decrease volume
		if (data.equals("Minus")) {
			Log.d(TAG, "Decreased Volume");			
			audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND + AudioManager.FLAG_SHOW_UI);
		}

		// Select Next song
		if (data.equals("Next")) {
			Log.d(TAG, "Next Song");
			try {
				musicConn.nextSong();
			} catch (RemoteException e) {
				Log.w(TAG, "Some Exception while selecting next song");
				e.printStackTrace();
			}
		}
		
		// Select Previous song
		if (data.equals("Prev")) {
			Log.d(TAG, "Prev Song");
			try {
				musicConn.prevSong();
			} catch (RemoteException e) {
				Log.w(TAG, "Some Exception while selecting prev song");				
				e.printStackTrace();
			}
		}
		
		// Play/Pause song
		if (data.equals("Center")) {
			Log.d(TAG, "Play/Pausing Song");
			try {
				musicConn.playPause();
			} catch (RemoteException e) {
				Log.w(TAG, "Some Exception while play/pausing song");				
				e.printStackTrace();
			}
		}
		
		super.onStart(intent, startId);
	}
	
	/**
	 * When the service is destroyed.
	 * 
	 * @see android.app.Service#onDestroy()
	 */
	@Override
	public void onDestroy() {
		Log.d(TAG, "Service Destroyed");

		// clean up
		audioManager = null;
		musicConn = null;
		super.onDestroy();
	}
<commit_msg>Moved remote button ids to constants<commit_after>/**
   iAndroidRemote - Control your Android phone's music player using Apple Remote 
    
   Copyright 2011  <NAME>  (email : <EMAIL>)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License, version 2, as
    published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

package com.sudarmuthu.android.iandroidremote;

import android.app.Service;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.AudioManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

/**
 * The Android service which interacts with the Music Player service
 * 
 * @author "<NAME> (http://sudarmuthu.com)"
 *
 */
public class AdjustVolumeService extends Service {
	
	// Remote button
	private static final String REMOTE_CENTER_BUTTON = "Center";
	private static final String REMOTE_PREVIOUS_BUTTON = "Prev";
	private static final String REMOTE_NEXT_BUTTON = "Next";
	private static final String REMOTE_MINUS_BUTTON = "Minus";
	private static final String REMOTE_PLUS_BUTTON = "Plus";

	private static final String TAG = "iAndroidRemote";
	
	private AudioManager audioManager;
	private boolean isHtc; // Flag to identify whether the phone is using HTC Music player
	private MediaPlayerServiceConnection musicConn; //handler to music player service

	/**
	 * When the service is created for the first time
	 * 		 
	 * @see android.app.Service#onCreate()
	 */
	@Override
	public void onCreate() {
		Log.d(TAG, "Service Created");
		
		Context context = getApplicationContext();
		
		audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
		musicConn = new MediaPlayerServiceConnection();
		isHtc = true;
		
		Intent i = new Intent();
		
		// First try to connect to HTC Music player service
		i.setClassName("com.htc.music", "com.htc.music.MediaPlaybackService");
		
        if (!context.bindService(i, musicConn, Context.MODE_PRIVATE)) {
        	Log.d(TAG, "Using built-in media player");
        	
        	// Default to Android's Music Player service
        	isHtc = false;
            i.setClassName("com.android.music", "com.android.music.MediaPlaybackService");
            context.bindService(i, musicConn, Context.MODE_PRIVATE);
        }
		
		super.onCreate();
	}

	/**
	 * When the service is started
	 * 
	 * @see android.app.Service#onStart(android.content.Intent, int)
	 */
	@Override
	public void onStart(Intent intent, int startId) {
		
		Bundle bundle = intent.getExtras();
		String data = bundle.getString("Data");

		// Increase volume
		if (data.equals(REMOTE_PLUS_BUTTON)) {
			Log.d(TAG, "Increased Volume");
			audioManager.adjustVolume(AudioManager.ADJUST_RAISE, AudioManager.FLAG_PLAY_SOUND + AudioManager.FLAG_SHOW_UI);
		}

		// Decrease volume
		if (data.equals(REMOTE_MINUS_BUTTON)) {
			Log.d(TAG, "Decreased Volume");			
			audioManager.adjustVolume(AudioManager.ADJUST_LOWER, AudioManager.FLAG_PLAY_SOUND + AudioManager.FLAG_SHOW_UI);
		}

		// Select Next song
		if (data.equals(REMOTE_NEXT_BUTTON)) {
			Log.d(TAG, "Next Song");
			try {
				musicConn.nextSong();
			} catch (RemoteException e) {
				Log.w(TAG, "Some Exception while selecting next song");
				e.printStackTrace();
			}
		}
		
		// Select Previous song
		if (data.equals(REMOTE_PREVIOUS_BUTTON)) {
			Log.d(TAG, "Prev Song");
			try {
				musicConn.prevSong();
			} catch (RemoteException e) {
				Log.w(TAG, "Some Exception while selecting prev song");				
				e.printStackTrace();
			}
		}
		
		// Play/Pause song
		if (data.equals(REMOTE_CENTER_BUTTON)) {
			Log.d(TAG, "Play/Pausing Song");
			try {
				musicConn.playPause();
			} catch (RemoteException e) {
				Log.w(TAG, "Some Exception while play/pausing song");				
				e.printStackTrace();
			}
		}
		
		super.onStart(intent, startId);
	}
	
	/**
	 * When the service is destroyed.
	 * 
	 * @see android.app.Service#onDestroy()
	 */
	@Override
	public void onDestroy() {
		Log.d(TAG, "Service Destroyed");

		// clean up
		audioManager = null;
		musicConn = null;
		super.onDestroy();
	}

{'fraction_non_alphanumeric': 0.10471320586927524, 'fraction_numerical': 0.0035571365051133837, 'mean_word_length': 3.4738935852809547, 'pattern_counts': {'":': 0, '<': 9, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5109082', 'n_tokens_mistral': 3022, 'n_tokens_neox': 2610, 'n_words': 799}