<commit_before>package info.curtbinder.reefangel.phone;

import android.content.Context;
import android.content.Intent;
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.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

public class Prefs extends PreferenceActivity implements OnPreferenceChangeListener {

	private static final String TAG = "RAPrefs";
	private static final String NUMBER_PATTERN = "\\d+";
	private static final String HOST_PATTERN = "^(?i:[[0-9][a-z]]+)(?i:[\\w\\.\\-]*)(?i:[[0-9][a-z]]+)$";
	private static final String USERID_PATTERN = "[\\w\\-\\.]+";
	
	private Preference portkey;
	private Preference hostkey;
	private Preference useridkey;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.settings);
		
		portkey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefPortKey));
		portkey.setOnPreferenceChangeListener(this);
		hostkey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefHostKey));
		hostkey.setOnPreferenceChangeListener(this);
		useridkey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefUserIdKey));
		useridkey.setOnPreferenceChangeListener(this);
		Preference devicekey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefDeviceKey));
		devicekey.setOnPreferenceChangeListener(this);
		Preference raWebsite = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefReefAngelKey));
		raWebsite.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			
			@Override
			public boolean onPreferenceClick(Preference preference) {
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, 
						Uri.parse(getBaseContext().getString(R.string.websiteReefangel)));
				startActivity(browserIntent);
				return true;
			}
		});
		Preference license = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefLicenseKey));
		license.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			
			@Override
			public boolean onPreferenceClick(Preference preference) {
				startActivity(new Intent(getBaseContext(), License.class));
				return true;
			}
		});

		// toggle the visibility of preferences based on device selection
		toggleDevicePrefVisibility(Integer.parseInt(getDevice(getBaseContext())));
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		Log.d(TAG, "Prefs Pause / Restart App");
		Intent i = new Intent(this, ReefAngelStatusActivity.class);
		i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
		startActivity(i);
		finish();
	}
		
	@Override
	public boolean onPreferenceChange(Preference preference, Object newValue) {
		// return true to change, false to not
		if ( preference.getKey().equals(preference.getContext().getString(R.string.prefPortKey))) {
			Log.d(TAG, "Validate entered port");
			if ( ! isNumber(newValue) ) {
				// not a number
				Log.d(TAG, "Invalid port");<commit_msg>Fixed screen update on exiting preferences<commit_after>package info.curtbinder.reefangel.phone;

import android.content.Context;
import android.content.Intent;
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.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

public class Prefs extends PreferenceActivity implements OnPreferenceChangeListener {

	private static final String TAG = "RAPrefs";
	private static final String NUMBER_PATTERN = "\\d+";
	private static final String HOST_PATTERN = "^(?i:[[0-9][a-z]]+)(?i:[\\w\\.\\-]*)(?i:[[0-9][a-z]]+)$";
	private static final String USERID_PATTERN = "[\\w\\-\\.]+";
	
	private Preference portkey;
	private Preference hostkey;
	private Preference useridkey;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.settings);
		
		portkey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefPortKey));
		portkey.setOnPreferenceChangeListener(this);
		hostkey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefHostKey));
		hostkey.setOnPreferenceChangeListener(this);
		useridkey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefUserIdKey));
		useridkey.setOnPreferenceChangeListener(this);
		Preference devicekey = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefDeviceKey));
		devicekey.setOnPreferenceChangeListener(this);
		Preference raWebsite = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefReefAngelKey));
		raWebsite.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			
			@Override
			public boolean onPreferenceClick(Preference preference) {
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, 
						Uri.parse(getBaseContext().getString(R.string.websiteReefangel)));
				startActivity(browserIntent);
				return true;
			}
		});
		Preference license = getPreferenceScreen().findPreference(getBaseContext().getString(R.string.prefLicenseKey));
		license.setOnPreferenceClickListener(new OnPreferenceClickListener() {
			
			@Override
			public boolean onPreferenceClick(Preference preference) {
				startActivity(new Intent(getBaseContext(), License.class));
				return true;
			}
		});

		// toggle the visibility of preferences based on device selection
		toggleDevicePrefVisibility(Integer.parseInt(getDevice(getBaseContext())));
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		Log.d(TAG, "Prefs Pause / Restart App");
		Intent i = new Intent(this, ReefAngelStatusActivity.class);
		i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		startActivity(i);
		finish();
	}
		
	@Override
	public boolean onPreferenceChange(Preference preference, Object newValue) {
		// return true to change, false to not
		if ( preference.getKey().equals(preference.getContext().getString(R.string.prefPortKey))) {
			Log.d(TAG, "Validate entered port");
			if ( ! isNumber(newValue) ) {
				// not a number
				Log.d(TAG, "Invalid port");
{'fraction_non_alphanumeric': 0.11604302378427511, 'fraction_numerical': 0.0012119375852143615, 'mean_word_length': 6.015940488841657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3512612', 'n_tokens_mistral': 2105, 'n_tokens_neox': 1904, 'n_words': 350}