use of android.widget.AdapterView.OnItemSelectedListener in project k-9 by k9mail.
the class AccountSetupOutgoing method validateFields.
/**
* This is invoked only when the user makes changes to a widget, not when
* widgets are changed programmatically. (The logic is simpler when you know
* that this is the last thing called after an input change.)
*/
private void validateFields() {
AuthType authType = getSelectedAuthType();
boolean isAuthTypeExternal = (AuthType.EXTERNAL == authType);
ConnectionSecurity connectionSecurity = getSelectedSecurity();
boolean hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
if (isAuthTypeExternal && !hasConnectionSecurity) {
// Notify user of an invalid combination of AuthType.EXTERNAL & ConnectionSecurity.NONE
String toastText = getString(R.string.account_setup_outgoing_invalid_setting_combo_notice, getString(R.string.account_setup_incoming_auth_type_label), AuthType.EXTERNAL.toString(), getString(R.string.account_setup_incoming_security_label), ConnectionSecurity.NONE.toString());
Toast.makeText(this, toastText, Toast.LENGTH_LONG).show();
// Reset the views back to their previous settings without recursing through here again
OnItemSelectedListener onItemSelectedListener = mAuthTypeView.getOnItemSelectedListener();
mAuthTypeView.setOnItemSelectedListener(null);
mAuthTypeView.setSelection(mCurrentAuthTypeViewPosition, false);
mAuthTypeView.setOnItemSelectedListener(onItemSelectedListener);
updateViewFromAuthType();
onItemSelectedListener = mSecurityTypeView.getOnItemSelectedListener();
mSecurityTypeView.setOnItemSelectedListener(null);
mSecurityTypeView.setSelection(mCurrentSecurityTypeViewPosition, false);
mSecurityTypeView.setOnItemSelectedListener(onItemSelectedListener);
updateAuthPlainTextFromSecurityType(getSelectedSecurity());
mPortView.removeTextChangedListener(validationTextWatcher);
mPortView.setText(mCurrentPortViewSetting);
mPortView.addTextChangedListener(validationTextWatcher);
authType = getSelectedAuthType();
isAuthTypeExternal = (AuthType.EXTERNAL == authType);
connectionSecurity = getSelectedSecurity();
hasConnectionSecurity = (connectionSecurity != ConnectionSecurity.NONE);
} else {
mCurrentAuthTypeViewPosition = mAuthTypeView.getSelectedItemPosition();
mCurrentSecurityTypeViewPosition = mSecurityTypeView.getSelectedItemPosition();
mCurrentPortViewSetting = mPortView.getText().toString();
}
boolean hasValidCertificateAlias = mClientCertificateSpinner.getAlias() != null;
boolean hasValidUserName = Utility.requiredFieldValid(mUsernameView);
boolean hasValidPasswordSettings = hasValidUserName && !isAuthTypeExternal && Utility.requiredFieldValid(mPasswordView);
boolean hasValidExternalAuthSettings = hasValidUserName && isAuthTypeExternal && hasConnectionSecurity && hasValidCertificateAlias;
mNextButton.setEnabled(Utility.domainFieldValid(mServerView) && Utility.requiredFieldValid(mPortView) && (!mRequireLoginView.isChecked() || hasValidPasswordSettings || hasValidExternalAuthSettings));
Utility.setCompoundDrawablesAlpha(mNextButton, mNextButton.isEnabled() ? 255 : 128);
}
use of android.widget.AdapterView.OnItemSelectedListener in project launchy by kaze0.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAppHelper = new AppHelper(this);
mAppHelper.loadApplications(true);
mAppHelper.bindApplications();
mAppHelper.registerIntentReceivers();
// setupTestReceiver();
mGestureDetector = createGestureDetector(this);
final ListView list = (ListView) findViewById(android.R.id.list);
list.setSelection(0);
list.requestFocus();
list.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
list.smoothScrollToPositionFromTop(list.getSelectedItemPosition(), 0);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addDataScheme("package");
registerReceiver(mPackageBroadcastReciever, intentFilter);
// publishCard(this);
}
use of android.widget.AdapterView.OnItemSelectedListener in project android by cSploit.
the class LoginCracker method onCreate.
public void onCreate(Bundle savedInstanceState) {
SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
Boolean isDark = themePrefs.getBoolean("isDark", false);
if (isDark)
setTheme(R.style.DarkTheme);
else
setTheme(R.style.AppTheme);
super.onCreate(savedInstanceState);
if (!System.getCurrentTarget().hasOpenPorts())
new FinishDialog(getString(R.string.warning), getString(R.string.no_open_ports), this).show();
final ArrayList<String> ports = new ArrayList<String>();
for (Port port : System.getCurrentTarget().getOpenPorts()) ports.add(Integer.toString(port.getNumber()));
mProtocolAdapter = new ProtocolAdapter();
mPortSpinner = (Spinner) findViewById(R.id.portSpinner);
mPortSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ports));
mPortSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
String port = (String) adapter.getItemAtPosition(position);
int protocolIndex = mProtocolAdapter.getIndexByPort(port);
if (protocolIndex != -1)
mProtocolSpinner.setSelection(protocolIndex);
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
mProtocolSpinner = (Spinner) findViewById(R.id.protocolSpinner);
mProtocolSpinner.setAdapter(new ProtocolAdapter());
mProtocolSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
int portIndex = mProtocolAdapter.getPortIndexByProtocol(position);
if (portIndex != -1)
mPortSpinner.setSelection(portIndex);
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
mCharsetSpinner = (Spinner) findViewById(R.id.charsetSpinner);
mCharsetSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, CHARSETS));
mCharsetSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
if (CHARSETS_MAPPING[position] == null) {
new InputDialog(getString(R.string.custom_charset), getString(R.string.enter_chars_wanted), LoginCracker.this, new InputDialogListener() {
@Override
public void onInputEntered(String input) {
input = input.trim();
if (!input.isEmpty())
mCustomCharset = "aA1" + input;
else {
mCustomCharset = null;
mCharsetSpinner.setSelection(0);
}
}
}).show();
} else
mCustomCharset = null;
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
mUserSpinner = (Spinner) findViewById(R.id.userSpinner);
mUserSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, USERNAMES));
mUserSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) {
String user = (String) adapter.getItemAtPosition(position);
if (user != null && user.equals("-- ADD --")) {
new InputDialog(getString(R.string.add_username), getString(R.string.enter_username), LoginCracker.this, new InputDialogListener() {
@Override
public void onInputEntered(String input) {
USERNAMES = Arrays.copyOf(USERNAMES, USERNAMES.length + 1);
USERNAMES[USERNAMES.length - 1] = "-- ADD --";
USERNAMES[USERNAMES.length - 2] = input;
mUserSpinner.setAdapter(new ArrayAdapter<String>(LoginCracker.this, android.R.layout.simple_spinner_item, USERNAMES));
mUserSpinner.setSelection(USERNAMES.length - 2);
}
}).show();
}
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
mMaxSpinner = (Spinner) findViewById(R.id.maxSpinner);
mMaxSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, LENGTHS));
mMinSpinner = (Spinner) findViewById(R.id.minSpinner);
mMinSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, LENGTHS));
mStartButton = (FloatingActionButton) findViewById(R.id.startFAB);
mStatusText = (TextView) findViewById(R.id.statusText);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
mActivity = (ProgressBar) findViewById(R.id.activity);
mProgressBar.setMax(100);
mReceiver = new AttemptReceiver();
mStartButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mRunning) {
setStoppedState();
} else {
setStartedState();
}
}
});
mWordlistPicker = new Intent();
mWordlistPicker.addCategory(Intent.CATEGORY_OPENABLE);
mWordlistPicker.setType("text/*");
mWordlistPicker.setAction(Intent.ACTION_GET_CONTENT);
if (Build.VERSION.SDK_INT >= 11)
mWordlistPicker.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
}
use of android.widget.AdapterView.OnItemSelectedListener in project XPrivacy by M66B.
the class ActivityMain method optionTemplate.
@SuppressLint("InflateParams")
private void optionTemplate() {
final int userId = Util.getUserId(Process.myUid());
// Build view
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.template, null);
final Spinner spTemplate = (Spinner) view.findViewById(R.id.spTemplate);
Button btnRename = (Button) view.findViewById(R.id.btnRename);
ExpandableListView elvTemplate = (ExpandableListView) view.findViewById(R.id.elvTemplate);
// Template selector
final SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0", getString(R.string.title_default));
spAdapter.add(defaultName);
for (int i = 1; i <= 4; i++) {
String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i), getString(R.string.title_alternate) + " " + i);
spAdapter.add(alternateName);
}
spTemplate.setAdapter(spAdapter);
// Template definition
final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry);
elvTemplate.setAdapter(templateAdapter);
elvTemplate.setGroupIndicator(null);
spTemplate.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
templateAdapter.notifyDataSetChanged();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
templateAdapter.notifyDataSetChanged();
}
});
btnRename.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Util.hasProLicense(ActivityMain.this) == null) {
// Redirect to pro page
Util.viewUri(ActivityMain.this, cProUri);
return;
}
final int templateId = spTemplate.getSelectedItemPosition();
if (templateId == AdapterView.INVALID_POSITION)
return;
AlertDialog.Builder dlgRename = new AlertDialog.Builder(spTemplate.getContext());
dlgRename.setTitle(R.string.title_rename);
final String original = (templateId == 0 ? getString(R.string.title_default) : getString(R.string.title_alternate) + " " + templateId);
dlgRename.setMessage(original);
final EditText input = new EditText(spTemplate.getContext());
dlgRename.setView(input);
dlgRename.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String name = input.getText().toString();
if (TextUtils.isEmpty(name)) {
PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId), null);
name = original;
} else {
PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId), name);
}
spAdapter.remove(spAdapter.getItem(templateId));
spAdapter.insert(name, templateId);
spAdapter.notifyDataSetChanged();
}
});
dlgRename.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing
}
});
dlgRename.create().show();
}
});
// Build dialog
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle(R.string.menu_template);
alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
alertDialogBuilder.setView(view);
alertDialogBuilder.setPositiveButton(getString(R.string.msg_done), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});
// Show dialog
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
use of android.widget.AdapterView.OnItemSelectedListener in project fitscales by paulburton.
the class SettingsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.settings_fragment, container, false);
editHeightMain = (EditText) v.findViewById(R.id.editHeightMain);
editHeightSub = (EditText) v.findViewById(R.id.editHeightSub);
rowHeightSub = (TableRow) v.findViewById(R.id.rowHeightSub);
spinHeightUnit = (Spinner) v.findViewById(R.id.spinHeightUnit);
spinWeightUnit = (Spinner) v.findViewById(R.id.spinWeightUnit);
seekStabilityPrecision = (SeekBar) v.findViewById(R.id.seekStabilityPrecision);
textHeightSubUnit = (TextView) v.findViewById(R.id.textHeightSubUnit);
listSyncServices = (ListView) v.findViewById(R.id.listSyncServices);
swSyncAuto = (Switch) v.findViewById(R.id.swSyncAuto);
btnDonate = (Button) v.findViewById(R.id.btnDonate);
TabHost tabHost = (TabHost) v.findViewById(android.R.id.tabhost);
tabHost.setup();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (DEBUG)
Log.d(TAG, "Using horizontal layout");
LinearLayout llMain = (LinearLayout) v.findViewById(R.id.llMain);
llMain.setOrientation(LinearLayout.HORIZONTAL);
TabWidget tw = tabHost.getTabWidget();
tw.setOrientation(LinearLayout.VERTICAL);
tw.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0f));
FrameLayout tc = tabHost.getTabContentView();
tc.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f));
}
tabHost.addTab(tabHost.newTabSpec("tab_body").setIndicator(createIndicatorView(tabHost, "Body", null, inflater)).setContent(R.id.tabViewBody));
tabHost.addTab(tabHost.newTabSpec("tab_sync").setIndicator(createIndicatorView(tabHost, "Sync", null, inflater)).setContent(R.id.tabViewSync));
tabHost.addTab(tabHost.newTabSpec("tab_about").setIndicator(createIndicatorView(tabHost, "About", null, inflater)).setContent(R.id.tabViewAbout));
tabHost.setCurrentTab(0);
ArrayAdapter<CharSequence> heightUnitAdapter = ArrayAdapter.createFromResource(inflater.getContext(), R.array.height_units_main_array, android.R.layout.simple_spinner_item);
heightUnitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinHeightUnit.setAdapter(heightUnitAdapter);
spinHeightUnit.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
edit.putInt(Prefs.KEY_HEIGHTUNIT, spinHeightUnit.getSelectedItemPosition());
Prefs.save(edit);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
editHeightMain.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
saveHeight();
}
});
editHeightSub.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
saveHeight();
}
});
ArrayAdapter<CharSequence> weightUnitAdapter = ArrayAdapter.createFromResource(inflater.getContext(), R.array.weight_units_main_array, android.R.layout.simple_spinner_item);
weightUnitAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinWeightUnit.setAdapter(weightUnitAdapter);
spinWeightUnit.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
edit.putInt(Prefs.KEY_WEIGHTUNIT, spinWeightUnit.getSelectedItemPosition());
Prefs.save(edit);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
final float stabilityPrecisionStep = 0.1f;
seekStabilityPrecision.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (!fromUser)
return;
float precision = Prefs.STABILITY_PRECISION_MIN + (progress * stabilityPrecisionStep);
if (precision == Prefs.getStabilityPrecision())
return;
if (DEBUG)
Log.d(TAG, "Stability precision change to " + precision);
SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
edit.putFloat(Prefs.KEY_STABILITY_PRECISION, precision);
Prefs.save(edit);
}
});
seekStabilityPrecision.setMax((int) ((Prefs.STABILITY_PRECISION_MAX - Prefs.STABILITY_PRECISION_MIN) / stabilityPrecisionStep) + 1);
seekStabilityPrecision.setProgress((int) ((Prefs.getStabilityPrecision() - Prefs.STABILITY_PRECISION_MIN) / stabilityPrecisionStep));
swSyncAuto.setChecked(Prefs.getSyncAuto());
swSyncAuto.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked == Prefs.getSyncAuto())
return;
SharedPreferences.Editor edit = FitscalesApplication.inst.prefs.edit();
edit.putBoolean(Prefs.KEY_SYNCAUTO, isChecked);
Prefs.save(edit);
}
});
btnDonate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=396BVJNLQFD62&lc=GB&item_name=FitScales%20Android%20App¤cy_code=GBP&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"));
startActivity(intent);
}
});
/* Prevent onClick being passed up to the settingsView */
v.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
listSyncServices.setAdapter(new SyncServiceAdapter(this, inflater.getContext(), R.layout.settings_sync_item, FitscalesApplication.inst.syncServices));
loadSettings();
return v;
}
Aggregations