<commit_before>package se.chalmers.dat255.sleepfighter.activity;

import se.chalmers.dat255.sleepfighter.R;
import se.chalmers.dat255.sleepfighter.SFApplication;
import se.chalmers.dat255.sleepfighter.audio.AudioDriver;
import se.chalmers.dat255.sleepfighter.audio.AudioDriverFactory;
import se.chalmers.dat255.sleepfighter.model.Alarm;
import se.chalmers.dat255.sleepfighter.model.audio.AudioSource;
import se.chalmers.dat255.sleepfighter.model.audio.AudioSourceType;
import se.chalmers.dat255.sleepfighter.preference.InitializableRingtonePreference;
import se.chalmers.dat255.sleepfighter.utils.android.IntentUtils;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

/**
 * RingerSettingsActivity handles alarm instance settings related to ringing, i.e AudioSource.
 *
 * @author Centril<<EMAIL>> / <NAME>.
 * @version 1.0
 * @since Sep 27, 2013
 */
public class RingerSettingsActivity extends PreferenceActivity {
	private final static String TAG = RingerSettingsActivity.class.getSimpleName();

	public enum ID {
		RINGTONE_PICKER( "pref_ringtone_picker" ),
		MUSIC_PICKER( "pref_local_content_uri_picker" ),
		PLAYLIST_PICKER( "pref_playlist_picker" );

		public final String id;

		ID( String id ) {
			this.id = id;
		}
	}

	private Alarm alarm;

	private AudioDriver driver;
	private AudioDriverFactory factory;

	private TextView summaryName;
	private TextView summaryType;

	@SuppressWarnings( "deprecation" )
	@Override
	protected void onCreate( Bundle savedInstanceState ) {
		super.onCreate( savedInstanceState );

		this.fetchAlarm();

		// Setup views.
		addPreferencesFromResource(R.xml.perf_alarm_ringer);
		this.setContentView(R.layout.perf_alarm_ringer_layout);

		// Setup factory & make driver from current source.
		this.setupDriver();

		// Setup summary.
		this.setupSummary();

		// Setup pickers, etc.
		this.setupRingtonePicker();
		this.setupMusicPicker();
		this.setupPlaylistPicker();
	}

	/**
	 * Sets up the summary in the top.
	 */
	private void setupSummary() {
		this.summaryName = (TextView) findViewById( R.id.alarm_audiosource_summary_name );
		this.summaryType = (TextView) findViewById( R.id.alarm_audiosource_summary_type );

		this.updateSummary();
	}

	/**
	 * Updates the summary in the top.
	 */
	private void updateSummary() {
		this.summaryName.setText( this.driver.printSourceName() );

		// Make and set typeText.
		String typeText;
		AudioSource source = this.driver.getSource();
		if ( source == null ) {
			typeText = this.getString( R.string.alarm_audiosource_summary_type_none );
		} else {
			Resources res = this.getResources();
			typeText = res.getStringArray( R.array.alarm_audiosource_summary_type )[source.getType().ordinal()];
		}

		this.summaryType.setText( typeText );
	}

	/**
	 * Sets up factory & make driver from current source.<commit_msg>Changed to ternary operator in updateSummary.<commit_after>package se.chalmers.dat255.sleepfighter.activity;

import se.chalmers.dat255.sleepfighter.R;
import se.chalmers.dat255.sleepfighter.SFApplication;
import se.chalmers.dat255.sleepfighter.audio.AudioDriver;
import se.chalmers.dat255.sleepfighter.audio.AudioDriverFactory;
import se.chalmers.dat255.sleepfighter.model.Alarm;
import se.chalmers.dat255.sleepfighter.model.audio.AudioSource;
import se.chalmers.dat255.sleepfighter.model.audio.AudioSourceType;
import se.chalmers.dat255.sleepfighter.preference.InitializableRingtonePreference;
import se.chalmers.dat255.sleepfighter.utils.android.IntentUtils;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

/**
 * RingerSettingsActivity handles alarm instance settings related to ringing, i.e AudioSource.
 *
 * @author Centril<<EMAIL>> / <NAME>.
 * @version 1.0
 * @since Sep 27, 2013
 */
public class RingerSettingsActivity extends PreferenceActivity {
	private final static String TAG = RingerSettingsActivity.class.getSimpleName();

	public enum ID {
		RINGTONE_PICKER( "pref_ringtone_picker" ),
		MUSIC_PICKER( "pref_local_content_uri_picker" ),
		PLAYLIST_PICKER( "pref_playlist_picker" );

		public final String id;

		ID( String id ) {
			this.id = id;
		}
	}

	private Alarm alarm;

	private AudioDriver driver;
	private AudioDriverFactory factory;

	private TextView summaryName;
	private TextView summaryType;

	@SuppressWarnings( "deprecation" )
	@Override
	protected void onCreate( Bundle savedInstanceState ) {
		super.onCreate( savedInstanceState );

		this.fetchAlarm();

		// Setup views.
		addPreferencesFromResource(R.xml.perf_alarm_ringer);
		this.setContentView(R.layout.perf_alarm_ringer_layout);

		// Setup factory & make driver from current source.
		this.setupDriver();

		// Setup summary.
		this.setupSummary();

		// Setup pickers, etc.
		this.setupRingtonePicker();
		this.setupMusicPicker();
		this.setupPlaylistPicker();
	}

	/**
	 * Sets up the summary in the top.
	 */
	private void setupSummary() {
		this.summaryName = (TextView) findViewById( R.id.alarm_audiosource_summary_name );
		this.summaryType = (TextView) findViewById( R.id.alarm_audiosource_summary_type );

		this.updateSummary();
	}

	/**
	 * Updates the summary in the top.
	 */
	private void updateSummary() {
		this.summaryName.setText( this.driver.printSourceName() );

		// Make and set typeText.
		String typeText;
		AudioSource source = this.driver.getSource();

		Resources res = this.getResources();
		typeText = source == null
				 ? this.getString( R.string.alarm_audiosource_summary_type_none )
				 : res.getStringArray( R.array.alarm_audiosource_summary_type )[source.getType().ordinal()];

		this.summaryType.setText( typeText );
	}

	/**
	 * Sets up factory & make driver from current source.
{'fraction_non_alphanumeric': 0.10403822441430333, 'fraction_numerical': 0.011713933415536375, 'mean_word_length': 5.025069637883008, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2408733', 'n_tokens_mistral': 2213, 'n_tokens_neox': 1965, 'n_words': 409}