/**
* Copyright (c) 2010 Perforce Software. All rights reserved.
*/
package com.perforce.p4scout;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;
import android.widget.Toast;
/**
* This class handles the globally used preferences.
*/
public class GlobalSettings extends PreferenceActivity {
/**
* This is the overridden initialisation method, setting up the preferences View and handling
* validation.
*
* @see android.preference.PreferenceActivity#onCreate(android.os.Bundle)
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.globalsettings);
EditTextPreference uname = (EditTextPreference) this.findPreference("prefDefaultUser");
uname.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
if (((String)newValue).length() <= 0) {
// We don't allow empty default usernames.
return false;
}
// Update the preference summary.
preference.setSummary(getString(R.string.strUsing) + " " + ((String)newValue));
return true;
}
});
uname.setSummary(getString(R.string.strUsing) + " " + uname.getText());
EditTextPreference simOps = (EditTextPreference) this.findPreference("prefSimOps");
simOps.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// The user number threshold must be an integer.
try {
if (Integer.parseInt(((String)newValue).toString()) < 0) {
return false;
}
} catch (NumberFormatException nfe) {
Toast.makeText(getApplicationContext(), R.string.errIntTooBig, Toast.LENGTH_LONG).show();
return false;
}
// Update the preference summary.
preference.setSummary(((String)newValue));
return true;
}
});
simOps.setSummary(simOps.getText());
EditTextPreference uthresh = (EditTextPreference) this.findPreference("prefUserThreshold");
uthresh.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// The user number threshold must be an integer.
try {
if (Integer.parseInt(((String)newValue).toString()) < 0) {
return false;
}
} catch (NumberFormatException nfe) {
Toast.makeText(getApplicationContext(), R.string.errIntTooBig, Toast.LENGTH_LONG).show();
return false;
}
// Update the preference summary.
preference.setSummary(((String)newValue) + " " + getString(R.string.strUsers));
return true;
}
});
uthresh.setSummary(uthresh.getText() + " " + getString(R.string.strUsers));
EditTextPreference lthresh = (EditTextPreference) this.findPreference("prefExpiryThreshold");
lthresh.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// The license expiry threshold must be an integer.
try {
if (Integer.parseInt(((String)newValue).toString()) < 0) {
return false;
}
} catch (NumberFormatException nfe) {
Toast.makeText(getApplicationContext(), R.string.errIntTooBig, Toast.LENGTH_LONG).show();
return false;
}
// Update the preference summary.
preference.setSummary(((String)newValue) + " " + getString(R.string.strDays));
return true;
}
});
lthresh.setSummary(lthresh.getText() + " " + getString(R.string.strDays));
EditTextPreference mthresh = (EditTextPreference) this.findPreference("prefMonitorThreshold");
mthresh.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// The user long running commands threshold must be an integer.
try {
if (Integer.parseInt(((String)newValue).toString()) < 0) {
return false;
}
} catch (NumberFormatException nfe) {
Toast.makeText(getApplicationContext(), R.string.errIntTooBig, Toast.LENGTH_LONG).show();
return false;
}
// Update the preference summary.
preference.setSummary(((String)newValue) + " " + getString(R.string.strSeconds));
return true;
}
});
mthresh.setSummary(mthresh.getText() + " " + getString(R.string.strSeconds));
EditTextPreference ccount = (EditTextPreference) this.findPreference("prefGetChangelists");
ccount.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// The number of changelists to fetch must be an integer.
try {
if (Integer.parseInt(((String)newValue).toString()) < 0) {
return false;
}
} catch (NumberFormatException nfe) {
Toast.makeText(getApplicationContext(), R.string.errIntTooBig, Toast.LENGTH_LONG).show();
return false;
}
// Update the preference summary.
preference.setSummary(((String)newValue) + " " + getString(R.string.strChangelists));
return true;
}
});
ccount.setSummary(ccount.getText() + " " + getString(R.string.strChangelists));
EditTextPreference fcount = (EditTextPreference) this.findPreference("prefGetChangeFiles");
fcount.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// The number of files to fetch must be an integer.
try {
if (Integer.parseInt(((String)newValue).toString()) < 0) {
return false;
}
} catch (NumberFormatException nfe) {
Toast.makeText(getApplicationContext(), R.string.errIntTooBig, Toast.LENGTH_LONG).show();
return false;
}
// Update the preference summary.
preference.setSummary(((String)newValue) + " " + getString(R.string.strChangeFiles));
return true;
}
});
fcount.setSummary(fcount.getText() + " " + getString(R.string.strChangeFiles));
EditTextPreference jcount = (EditTextPreference) this.findPreference("prefGetJobs");
jcount.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference,
Object newValue) {
// The number of jobs to fetch must be an integer.
try {
if (Integer.parseInt(((String)newValue).toString()) < 0) {
return false;
}
} catch (NumberFormatException nfe) {
Toast.makeText(getApplicationContext(), R.string.errIntTooBig, Toast.LENGTH_LONG).show();
return false;
}
// Update the preference summary.
preference.setSummary(((String)newValue) + " " + getString(R.string.strJobs));
return true;
}
});
jcount.setSummary(jcount.getText() + " " + getString(R.string.strJobs));
}
/**
* This prevents the activity from being restarted when the orientation changes
*/
@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
8980 |
Matt Attaway |
Add source code for both the Android and iOS versions of P4Scout. |
|
|