<commit_before>/************************************************************************\
 *                                                                       *
 * Libre Droid - A GNU FM streaming music client for the Android mobile  *
 * platform                                                              *
 * Copyright (C) 2009 Free Software Foundation, Inc                      *
 *                                                                       *
 * This program is free software: you can redistribute it and/or modify  *
 * it under the terms of the GNU General Public License as published by  *
 * the Free Software Foundation, either version 3 of the License, or     *
 * (at your option) any later version.                                   *
 *                                                                       *
 * 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, see <http://www.gnu.org/licenses/>. *
 *                                                                       *
 *************************************************************************/

package fm.libre.droid;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreProtocolPNames;

import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewAnimator;

public class LibreDroid extends ListActivity {
	private LibreServiceConnection libreServiceConn;
	private String username;
	private String password;
	private ArrayList<String> customStations;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		libreServiceConn = new LibreServiceConnection();
		bindService(new Intent(this, LibreService.class), libreServiceConn,	Context.BIND_AUTO_CREATE);

		this.registerReceiver(new MediaButtonReceiver(), new IntentFilter(Intent.ACTION_MEDIA_BUTTON));
		this.registerReceiver(new UIUpdateReceiver(), new IntentFilter("LibreDroidNewSong"));
		setContentView(R.layout.main);
		
		// Load settings
		final SharedPreferences settings = getSharedPreferences("LibreDroid", MODE_PRIVATE);
		username = settings.getString("Username", "");
		password = settings.getString("Password", "");

		final EditText usernameEntry = (EditText) findViewById(R.id.usernameEntry);
		final EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry);
		usernameEntry.setText(username);
		passwordEntry.setText(password);

		final Button loginButton = (Button) findViewById(R.id.loginButton);
		loginButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Editor editor = settings.edit();
				editor.putString("Username", usernameEntry.getText().toString());
				editor.putString("Password", passwordEntry.getText().toString());
				editor.commit();

				LibreDroid.this.login();
			}
		});

		customStations = new ArrayList<String>();
		try {
			FileInputStream stationFile = openFileInput("libredroid-custom-stations.conf");
			
		} catch (IOException ex) {
			Log.d("libredroid", ex.getMessage());
		}
		// Add default stations if empty
		if(customStations.isEmpty()) {
			String radioButtons[] = { "Folk", "Rock", "Metal", "Classical", "Pop",
					"Punk", "Jazz", "Blues", "Rap", "Ambient", "Add A Custom Station..." };
			customStations.addAll(Arrays.asList(radioButtons));
		}
		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, customStations));
		
		Button tagStation = (Button) findViewById(R.id.tagStationButton);
		tagStation.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				LibreDroid.this.nextPage();
			}
		});
		
		Button loveStation = (Button) findViewById(R.id.loveStationButton);
		loveStation.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				LibreDroid.this.libreServiceConn.service.tuneStation("user", username + "/loved");
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
			}
		});
		
		Button communityLoveStation = (Button) findViewById(R.id.communityStationButton);
		communityLoveStation.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				LibreDroid.this.libreServiceConn.service.tuneStation("community", "loved");
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
			}
		});
<commit_msg>Load custom stations from config file in Libre Droid<commit_after>/************************************************************************\
 *                                                                       *
 * Libre Droid - A GNU FM streaming music client for the Android mobile  *
 * platform                                                              *
 * Copyright (C) 2009 Free Software Foundation, Inc                      *
 *                                                                       *
 * This program is free software: you can redistribute it and/or modify  *
 * it under the terms of the GNU General Public License as published by  *
 * the Free Software Foundation, either version 3 of the License, or     *
 * (at your option) any later version.                                   *
 *                                                                       *
 * 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, see <http://www.gnu.org/licenses/>. *
 *                                                                       *
 *************************************************************************/

package fm.libre.droid;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.CoreProtocolPNames;

import android.app.ListActivity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewAnimator;

public class LibreDroid extends ListActivity {
	private LibreServiceConnection libreServiceConn;
	private String username;
	private String password;
	private ArrayList<String> stations;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		libreServiceConn = new LibreServiceConnection();
		bindService(new Intent(this, LibreService.class), libreServiceConn,	Context.BIND_AUTO_CREATE);

		this.registerReceiver(new MediaButtonReceiver(), new IntentFilter(Intent.ACTION_MEDIA_BUTTON));
		this.registerReceiver(new UIUpdateReceiver(), new IntentFilter("LibreDroidNewSong"));
		setContentView(R.layout.main);
		
		// Load settings
		final SharedPreferences settings = getSharedPreferences("LibreDroid", MODE_PRIVATE);
		username = settings.getString("Username", "");
		password = settings.getString("Password", "");

		final EditText usernameEntry = (EditText) findViewById(R.id.usernameEntry);
		final EditText passwordEntry = (EditText) findViewById(R.id.passwordEntry);
		usernameEntry.setText(username);
		passwordEntry.setText(password);

		final Button loginButton = (Button) findViewById(R.id.loginButton);
		loginButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Editor editor = settings.edit();
				editor.putString("Username", usernameEntry.getText().toString());
				editor.putString("Password", <PASSWORD>());
				editor.commit();

				LibreDroid.this.login();
			}
		});

		stations = new ArrayList<String>();
		try {
			BufferedReader stationReader = new BufferedReader(new InputStreamReader(openFileInput("libredroid-custom-stations.conf")));
			String station;
			while((station = stationReader.readLine()) != null) {
				stations.add(station);
			}
		} catch (IOException ex) {
			Log.d("libredroid", ex.getMessage());
		}
		// Add default stations if empty
		String radioButtons[] = { "Folk", "Rock", "Metal", "Classical", "Pop",
				"Punk", "Jazz", "Blues", "Rap", "Ambient", "Add A Custom Station..." };
		stations.addAll(Arrays.asList(radioButtons));
		setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, stations));
		
		Button tagStation = (Button) findViewById(R.id.tagStationButton);
		tagStation.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				LibreDroid.this.nextPage();
			}
		});
		
		Button loveStation = (Button) findViewById(R.id.loveStationButton);
		loveStation.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				LibreDroid.this.libreServiceConn.service.tuneStation("user", username + "/loved");
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
			}
		});
		
		Button communityLoveStation = (Button) findViewById(R.id.communityStationButton);
		communityLoveStation.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				LibreDroid.this.libreServiceConn.service.tuneStation("community", "loved");
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
				LibreDroid.this.nextPage();
			}
		});

{'fraction_non_alphanumeric': 0.12055800293685756, 'fraction_numerical': 0.0007342143906020558, 'mean_word_length': 3.560093739537998, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2137102', 'n_tokens_mistral': 3758, 'n_tokens_neox': 3473, 'n_words': 841}