List of usage examples for android.widget Spinner setEnabled
@Override public void setEnabled(boolean enabled)
From source file:de.blinkt.openvpn.ActivityServerList.java
public void setStatus(Status status) { Button btnConnect = (Button) findViewById(R.id.button_dashboard_connect); TextView textStatus = (TextView) findViewById(R.id.view_dashboard_status); Spinner spinPackage = (Spinner) findViewById(R.id.spinner_dashboard_package); Spinner spinServer = (Spinner) findViewById(R.id.spinner_dashboard_location); if (btnConnect == null || textStatus == null || spinPackage == null || spinServer == null) { Log.e("ibVPN", "at least one item do not exist."); return;/* www . ja v a 2 s.co m*/ } m_status = status; switch (m_status) { case Connecting: { spinPackage.setEnabled(false); spinServer.setEnabled(false); btnConnect.setEnabled(true); btnConnect.setText(R.string.text_cancel); textStatus.setText(Html.fromHtml( "<font color=#FFFFFF>Status: </font><font color=#fdbb2f>CONNECTING...</font><b> >>></b>")); break; } case Connected: { spinPackage.setEnabled(false); spinServer.setEnabled(false); btnConnect.setEnabled(true); btnConnect.setText("Disconnect"); textStatus.setText(Html.fromHtml( "<font color=#FFFFFF>Status: </font><font color=#00FF20>CONNECTED</font><b> >>></b>")); break; } case Disconnecting: { spinPackage.setEnabled(false); spinServer.setEnabled(false); btnConnect.setEnabled(false); btnConnect.setText("Disconnect"); textStatus.setText(Html.fromHtml( "<font color=#FFFFFF>Status: </font><font color=#FF0000>DISCONNECTING...</font><b> >>></b>")); break; } case Disconnected: { spinPackage.setEnabled(true); spinServer.setEnabled(true); btnConnect.setEnabled(true); btnConnect.setText("Connect"); textStatus.setText(Html.fromHtml( "<font color=#FFFFFF>Status: </font><font color=#FF0000>NOT CONNECTED</font><b> >>></b>")); break; } default: Log.e("ibVPN", "no such status."); return; } }
From source file:com.hivewallet.androidclient.wallet.ui.WalletActivity.java
private void prepareImportKeysDialog(final Dialog dialog) { final AlertDialog alertDialog = (AlertDialog) dialog; final List<File> files = new LinkedList<File>(); // result of ACTION_PICk File selectedExternalWalletBackup = new File(getFilesDir(), Constants.Files.EXTERNAL_WALLET_TMP_FILE); if (selectedExternalWalletBackup.exists()) files.add(selectedExternalWalletBackup); // local copies of external backups File externalWalletBackupDir = new File(getFilesDir(), Constants.Files.EXTERNAL_WALLET_BACKUP_DIR); if (externalWalletBackupDir.exists() && externalWalletBackupDir.isDirectory()) for (final File file : externalWalletBackupDir.listFiles()) if (WalletUtils.BACKUP_FILE_FILTER.accept(file) || WalletUtils.KEYS_FILE_FILTER.accept(file) || Crypto.OPENSSL_FILE_FILTER.accept(file)) files.add(file);//w w w.j av a 2s. c o m // internal storage for (final String filename : fileList()) if (filename.startsWith(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + '.')) files.add(new File(getFilesDir(), filename)); // sort Collections.sort(files, new Comparator<File>() { @Override public int compare(final File lhs, final File rhs) { return lhs.getName().compareToIgnoreCase(rhs.getName()); } }); final View replaceWarningView = alertDialog .findViewById(R.id.restore_wallet_from_storage_dialog_replace_warning); final boolean hasCoins = wallet.getBalance(BalanceType.ESTIMATED).signum() > 0; replaceWarningView.setVisibility(hasCoins ? View.VISIBLE : View.GONE); final Spinner fileView = (Spinner) alertDialog.findViewById(R.id.import_keys_from_storage_file); final FileAdapter adapter = (FileAdapter) fileView.getAdapter(); adapter.setFiles(files); fileView.setEnabled(!adapter.isEmpty()); final EditText passwordView = (EditText) alertDialog.findViewById(R.id.import_keys_from_storage_password); passwordView.setText(null); final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener( passwordView, alertDialog) { @Override protected boolean hasFile() { return fileView.getSelectedItem() != null; } @Override protected boolean needsPassword() { final File selectedFile = (File) fileView.getSelectedItem(); return selectedFile != null ? Crypto.OPENSSL_FILE_FILTER.accept(selectedFile) : false; } }; passwordView.addTextChangedListener(dialogButtonEnabler); fileView.setOnItemSelectedListener(dialogButtonEnabler); final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_storage_show); showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView)); }
From source file:own.projects.lemiroapp.OptionsActivity.java
private void setPlayerDifficultyFor(final Player player) { final ArrayAdapter<String> items = new ArrayAdapter<String>(this, layout.simple_list_item_1); items.add("Human Player"); for (Options.Difficulties diff : Options.Difficulties.values()) { items.add(diff + " Bot"); }//from w ww . ja v a 2s .c o m Spinner spinner = null; if (player.getColor().equals(Options.Color.WHITE)) { playerWhiteSpinner = (Spinner) findViewById(R.id.playerWhiteSpinner); spinner = playerWhiteSpinner; } else { playerBlackSpinner = (Spinner) findViewById(R.id.playerBlackSpinner); spinner = playerBlackSpinner; } spinner.setAdapter(items); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { if (pos == 0) { // no difficulty for human player return; } else { // -1 offset because first entry is the human player player.setDifficulty(Options.Difficulties.values()[pos - 1]); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); spinner.setClickable(true); spinner.setEnabled(true); }
From source file:hu.fnf.devel.atlas.Atlas.java
@SuppressLint("SimpleDateFormat") public void startParseAllSmsConfig(View v) { EditText password = (EditText) v.getRootView().findViewById(R.id.password); EditText number = (EditText) v.getRootView().findViewById(R.id.smsnumber); Spinner bank = (Spinner) v.getRootView().findViewById(R.id.bankpreset); Spinner dbpre = (Spinner) v.getRootView().findViewById(R.id.databasepreset); EditText from = (EditText) v.getRootView().findViewById(R.id.from); password.setEnabled(false);/*from w w w. j a v a2 s . c o m*/ number.setEnabled(false); bank.setEnabled(false); dbpre.setEnabled(false); from.setEnabled(false); SimpleDateFormat formatter = new SimpleDateFormat("yyyy.MM"); String date = (formatter.format(new Date())); String enc = AtlasData.setDBPassword(password.getText().toString()); Editor edit = AtlasData.config.edit(); String warn = "[\';]"; edit.putString(AtlasData.CONFIG_PASSWORD, enc); edit.putString(AtlasData.CONFIG_NUMBER, number.getText().toString().replaceAll(warn, " ")); edit.putString(AtlasData.CONFIG_BANK, bank.getSelectedItem().toString().replaceAll(warn, " ")); edit.putString(AtlasData.CONFIG_DATABASE, dbpre.getSelectedItem().toString().replaceAll(warn, " ")); edit.putString(AtlasData.CONFIG_FROM, from.getText().toString().replaceAll(warn, " ")); edit.putString(AtlasData.CONFIG_DATE, date); edit.commit(); Button progress = (Button) v.getRootView().findViewById(R.id.parse); new AtlasParseSMSTask(getApplicationContext(), progress, onStartAtlasClick).execute(); }
From source file:com.kncwallet.wallet.ui.WalletActivity.java
private void prepareImportKeysDialog(final Dialog dialog) { final AlertDialog alertDialog = (AlertDialog) dialog; final List<File> files = new LinkedList<File>(); // external storage if (Constants.EXTERNAL_WALLET_BACKUP_DIR.exists() && Constants.EXTERNAL_WALLET_BACKUP_DIR.isDirectory()) for (final File file : Constants.EXTERNAL_WALLET_BACKUP_DIR.listFiles()) if (WalletUtils.KEYS_FILE_FILTER.accept(file) || Crypto.OPENSSL_FILE_FILTER.accept(file)) files.add(file);/*from w w w . j a v a2 s . co m*/ // internal storage for (final String filename : fileList()) if (filename.startsWith(Constants.WALLET_KEY_BACKUP_BASE58 + '.')) files.add(new File(getFilesDir(), filename)); // sort Collections.sort(files, new Comparator<File>() { @Override public int compare(final File lhs, final File rhs) { return lhs.getName().compareToIgnoreCase(rhs.getName()); } }); final FileAdapter adapter = new FileAdapter(this, files) { @Override public View getDropDownView(final int position, View row, final ViewGroup parent) { final File file = getItem(position); final boolean isExternal = Constants.EXTERNAL_WALLET_BACKUP_DIR.equals(file.getParentFile()); final boolean isEncrypted = Crypto.OPENSSL_FILE_FILTER.accept(file); if (row == null) row = inflater.inflate(R.layout.wallet_import_keys_file_row, null); final TextView filenameView = (TextView) row .findViewById(R.id.wallet_import_keys_file_row_filename); filenameView.setText(file.getName()); final TextView securityView = (TextView) row .findViewById(R.id.wallet_import_keys_file_row_security); final String encryptedStr = context .getString(isEncrypted ? R.string.import_keys_dialog_file_security_encrypted : R.string.import_keys_dialog_file_security_unencrypted); final String storageStr = context .getString(isExternal ? R.string.import_keys_dialog_file_security_external : R.string.import_keys_dialog_file_security_internal); securityView.setText(encryptedStr + ", " + storageStr); final TextView createdView = (TextView) row.findViewById(R.id.wallet_import_keys_file_row_created); createdView.setText(context.getString( isExternal ? R.string.import_keys_dialog_file_created_manual : R.string.import_keys_dialog_file_created_automatic, DateUtils.getRelativeTimeSpanString(context, file.lastModified(), true))); return row; } }; final Spinner fileView = (Spinner) alertDialog.findViewById(R.id.import_keys_from_storage_file); fileView.setAdapter(adapter); fileView.setEnabled(!adapter.isEmpty()); final EditText passwordView = (EditText) alertDialog.findViewById(R.id.import_keys_from_storage_password); passwordView.setText(null); final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener( passwordView, alertDialog) { @Override protected boolean hasFile() { return fileView.getSelectedItem() != null; } @Override protected boolean needsPassword() { final File selectedFile = (File) fileView.getSelectedItem(); return selectedFile != null ? Crypto.OPENSSL_FILE_FILTER.accept(selectedFile) : false; } }; passwordView.addTextChangedListener(dialogButtonEnabler); fileView.setOnItemSelectedListener(dialogButtonEnabler); final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_storage_show); showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView)); KnCDialog.fixDialogDivider(alertDialog); }
From source file:com.mantz_it.rfanalyzer.ui.activity.MainActivity.java
/** * Will pop up a dialog to let the user input a new frequency. * Note: A frequency can be entered either in Hz or in MHz. If the input value * is a number smaller than the maximum frequency of the source in MHz, then it * is interpreted as a frequency in MHz. Otherwise it will be handled as frequency * in Hz.//from w w w . j a v a2s .c o m */ private void tuneToFrequency() { if (source == null) return; // calculate max frequency of the source in MHz: final double maxFreqMHz = rxFrequency.getMax() / 1000000f; final LinearLayout ll_view = (LinearLayout) this.getLayoutInflater().inflate(R.layout.tune_to_frequency, null); final EditText et_frequency = (EditText) ll_view.findViewById(R.id.et_tune_to_frequency); final Spinner sp_unit = (Spinner) ll_view.findViewById(R.id.sp_tune_to_frequency_unit); final CheckBox cb_bandwidth = (CheckBox) ll_view.findViewById(R.id.cb_tune_to_frequency_bandwidth); final EditText et_bandwidth = (EditText) ll_view.findViewById(R.id.et_tune_to_frequency_bandwidth); final Spinner sp_bandwidthUnit = (Spinner) ll_view.findViewById(R.id.sp_tune_to_frequency_bandwidth_unit); final TextView tv_warning = (TextView) ll_view.findViewById(R.id.tv_tune_to_frequency_warning); // Show warning if we are currently recording to file: if (recordingFile != null) tv_warning.setVisibility(View.VISIBLE); cb_bandwidth.setOnCheckedChangeListener((buttonView, isChecked) -> { et_bandwidth.setEnabled(isChecked); sp_bandwidthUnit.setEnabled(isChecked); }); cb_bandwidth.toggle(); // to trigger the onCheckedChangeListener at least once to set inital state cb_bandwidth .setChecked(preferences.getBoolean(getString(R.string.pref_tune_to_frequency_setBandwidth), false)); et_bandwidth.setText(preferences.getString(getString(R.string.pref_tune_to_frequency_bandwidth), "1")); sp_unit.setSelection(preferences.getInt(getString(R.string.pref_tune_to_frequency_unit), 0)); sp_bandwidthUnit .setSelection(preferences.getInt(getString(R.string.pref_tune_to_frequency_bandwidthUnit), 0)); new AlertDialog.Builder(this).setTitle("Tune to Frequency") .setMessage( String.format("Frequency is %f MHz. Type a new Frequency: ", rxFrequency.get() / 1000000f)) .setView(ll_view).setPositiveButton("Set", (dialog, whichButton) -> { try { double newFreq = rxFrequency.get() / 1000000f; if (et_frequency.getText().length() != 0) newFreq = Double.valueOf(et_frequency.getText().toString()); switch (sp_unit.getSelectedItemPosition()) { case 0: // MHz newFreq *= 1000000; break; case 1: // KHz newFreq *= 1000; break; default: // Hz } if (newFreq < maxFreqMHz) newFreq = newFreq * 1000000; if (newFreq <= rxFrequency.getMax() && newFreq >= rxFrequency.getMin()) { rxFrequency.set((long) newFreq); analyzerSurface.setVirtualFrequency((long) newFreq); if (demodulationMode != Demodulator.DEMODULATION_OFF) analyzerSurface.setDemodulationEnabled(true); // This will re-adjust the channel freq correctly // Set bandwidth (virtual sample rate): if (cb_bandwidth.isChecked() && et_bandwidth.getText().length() != 0) { float bandwidth = Float.parseFloat(et_bandwidth.getText().toString()); if (sp_bandwidthUnit.getSelectedItemPosition() == 0) //MHz bandwidth *= 1000000; else if (sp_bandwidthUnit.getSelectedItemPosition() == 1) //KHz bandwidth *= 1000; if (bandwidth > rxSampleRate.getMax()) bandwidth = rxFrequency.getMax(); rxSampleRate.set(rxSampleRate.getNextHigherOptimalSampleRate((int) bandwidth)); analyzerSurface.setVirtualSampleRate((int) bandwidth); } // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_tune_to_frequency_unit), sp_unit.getSelectedItemPosition()); edit.putBoolean(getString(R.string.pref_tune_to_frequency_setBandwidth), cb_bandwidth.isChecked()); edit.putString(getString(R.string.pref_tune_to_frequency_bandwidth), et_bandwidth.getText().toString()); edit.putInt(getString(R.string.pref_tune_to_frequency_bandwidthUnit), sp_bandwidthUnit.getSelectedItemPosition()); edit.apply(); } else { toaster.showLong("Frequency is out of the valid range: " + (long) newFreq + " Hz"); } } catch (NumberFormatException e) { // todo: notify user Log.e(LOGTAG, "tuneToFrequency: Error while setting frequency: " + e.getMessage()); } }).setNegativeButton("Cancel", (dialog, whichButton) -> { // do nothing }).show(); }
From source file:com.mantz_it.rfanalyzer.MainActivity.java
/** * Will pop up a dialog to let the user input a new frequency. * Note: A frequency can be entered either in Hz or in MHz. If the input value * is a number smaller than the maximum frequency of the source in MHz, then it * is interpreted as a frequency in MHz. Otherwise it will be handled as frequency * in Hz.// ww w .j av a2 s .c o m */ private void tuneToFrequency() { if (source == null) return; // calculate max frequency of the source in MHz: final double maxFreqMHz = source.getMaxFrequency() / 1000000f; final LinearLayout ll_view = (LinearLayout) this.getLayoutInflater().inflate(R.layout.tune_to_frequency, null); final EditText et_frequency = (EditText) ll_view.findViewById(R.id.et_tune_to_frequency); final Spinner sp_unit = (Spinner) ll_view.findViewById(R.id.sp_tune_to_frequency_unit); final CheckBox cb_bandwidth = (CheckBox) ll_view.findViewById(R.id.cb_tune_to_frequency_bandwidth); final EditText et_bandwidth = (EditText) ll_view.findViewById(R.id.et_tune_to_frequency_bandwidth); final Spinner sp_bandwidthUnit = (Spinner) ll_view.findViewById(R.id.sp_tune_to_frequency_bandwidth_unit); final TextView tv_warning = (TextView) ll_view.findViewById(R.id.tv_tune_to_frequency_warning); // Show warning if we are currently recording to file: if (recordingFile != null) tv_warning.setVisibility(View.VISIBLE); cb_bandwidth.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { et_bandwidth.setEnabled(isChecked); sp_bandwidthUnit.setEnabled(isChecked); } }); cb_bandwidth.toggle(); // to trigger the onCheckedChangeListener at least once to set inital state cb_bandwidth .setChecked(preferences.getBoolean(getString(R.string.pref_tune_to_frequency_setBandwidth), false)); et_bandwidth.setText(preferences.getString(getString(R.string.pref_tune_to_frequency_bandwidth), "1")); sp_unit.setSelection(preferences.getInt(getString(R.string.pref_tune_to_frequency_unit), 0)); sp_bandwidthUnit .setSelection(preferences.getInt(getString(R.string.pref_tune_to_frequency_bandwidthUnit), 0)); new AlertDialog.Builder(this).setTitle("Tune to Frequency") .setMessage(String.format("Frequency is %f MHz. Type a new Frequency: ", source.getFrequency() / 1000000f)) .setView(ll_view).setPositiveButton("Set", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { double newFreq = source.getFrequency(); if (et_frequency.getText().length() != 0) newFreq = Double.valueOf(et_frequency.getText().toString()); if (sp_unit.getSelectedItemPosition() == 0) //MHz newFreq *= 1000000; else if (sp_unit.getSelectedItemPosition() == 1) //KHz newFreq *= 1000; if (newFreq <= source.getMaxFrequency() && newFreq >= source.getMinFrequency()) { source.setFrequency((long) newFreq); analyzerSurface.setVirtualFrequency((long) newFreq); if (demodulationMode != Demodulator.DEMODULATION_OFF) analyzerSurface.setDemodulationEnabled(true); // This will re-adjust the channel freq correctly // Set bandwidth (virtual sample rate): if (cb_bandwidth.isChecked() && et_bandwidth.getText().length() != 0) { float bandwidth = Float.valueOf(et_bandwidth.getText().toString()); if (sp_bandwidthUnit.getSelectedItemPosition() == 0) //MHz bandwidth *= 1000000; else if (sp_bandwidthUnit.getSelectedItemPosition() == 1) //KHz bandwidth *= 1000; if (bandwidth > source.getMaxSampleRate()) bandwidth = source.getMaxFrequency(); source.setSampleRate(source.getNextHigherOptimalSampleRate((int) bandwidth)); analyzerSurface.setVirtualSampleRate((int) bandwidth); } // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_tune_to_frequency_unit), sp_unit.getSelectedItemPosition()); edit.putBoolean(getString(R.string.pref_tune_to_frequency_setBandwidth), cb_bandwidth.isChecked()); edit.putString(getString(R.string.pref_tune_to_frequency_bandwidth), et_bandwidth.getText().toString()); edit.putInt(getString(R.string.pref_tune_to_frequency_bandwidthUnit), sp_bandwidthUnit.getSelectedItemPosition()); edit.apply(); } else { Toast.makeText(MainActivity.this, "Frequency is out of the valid range: " + (long) newFreq + " Hz", Toast.LENGTH_LONG).show(); } } catch (NumberFormatException e) { Log.e(LOGTAG, "tuneToFrequency: Error while setting frequency: " + e.getMessage()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).show(); }
From source file:hu.fnf.devel.atlas.Atlas.java
public void addCat(View view) { Spinner spinner = (Spinner) findViewById(R.id.taskSpinner); // In case of null add! if (spinner.getSelectedItem() == null) { Log.d("Atlas", "null selection"); return;/*from www.ja va 2s. c om*/ } String selected = (String) spinner.getSelectedItem(); /* * add to list */ Category sel = categories.get(selected); Log.d("Atlas", "selected: " + selected); Log.d("Atlas", "id: " + sel.getId()); ListView cats = (ListView) findViewById(R.id.taskCats); CatAddAdapter catAddAdapter = (CatAddAdapter) cats.getAdapter(); if (catAddAdapter.getSum() >= (int) (catAddAdapter.getAmount()) + Integer.valueOf(sel.getAmount())) { AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this); myAlertDialog.setTitle("--- Task ---"); myAlertDialog.setMessage("Nothing left to categorize"); myAlertDialog.setPositiveButton(getResources().getString(R.string.ok), AtlasData.ackClick); myAlertDialog.show(); return; } catAddAdapter.add(new Category(sel.getId(), sel.getName(), sel.getAmount(), sel.getDepth(), sel.getColorr(), sel.getColorg(), sel.getColorb())); cats.setAdapter(catAddAdapter); //remove from spinner ArrayList<String> array_spinner = new ArrayList<String>(); int spin_count = spinner.getAdapter().getCount(); Log.d("Atlas", "spinner count: " + spin_count); if (spin_count == 1) { // no more category in spinner (ASANA: mi legyen ha elfogy a spinner) Log.d("Atlas", "no more category in spinner"); ImageView add = (ImageView) findViewById(R.id.taskAdd); add.setVisibility(View.INVISIBLE); add.setEnabled(false); spinner.setVisibility(View.INVISIBLE); spinner.setEnabled(false); } for (int i = 0; i < spin_count; i++) { String s = (String) spinner.getAdapter().getItem(i); if (!s.equalsIgnoreCase(selected)) { array_spinner.add(s); } } ArrayAdapter<String> arrayadapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.custom_simple_spinner, array_spinner); spinner.setAdapter(arrayadapter); }
From source file:com.digi.android.wva.fragments.EndpointOptionsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (mConfig == null && savedInstanceState == null) { Log.e(TAG, "mConfig is null, not showing dialog!"); return null; }//from ww w . ja va 2 s . c o m LayoutInflater inf = getActivity().getLayoutInflater(); View v = inf.inflate(R.layout.dialog_endpoint_options, null); // Suppresses warnings, and ensures the layout exists. assert v != null; final TextView subIntervalTV = (TextView) v.findViewById(R.id.textView_interval); final TextView alarmInfoTV = (TextView) v.findViewById(R.id.alarm_info); final CheckBox subscribedCB = (CheckBox) v.findViewById(R.id.subscribedCheckbox); final CheckBox alarmCB = (CheckBox) v.findViewById(R.id.alarmCheckbox); final EditText subInterval = (EditText) v.findViewById(R.id.subscriptionInterval); final EditText alarmThreshold = (EditText) v.findViewById(R.id.alarmThreshold); final Spinner typeSpinner = (Spinner) v.findViewById(R.id.alarmTypeSpinner); final LinearLayout makeAlarmSection = (LinearLayout) v.findViewById(R.id.section_make_alarm); final LinearLayout showAlarmSection = (LinearLayout) v.findViewById(R.id.section_show_alarm); final CheckBox dcSendCB = (CheckBox) v.findViewById(R.id.dcPushCheckbox); String alarmInfo = "No alarm yet"; boolean isSubscribed = false; String endpointName = "UNKNOWN"; int sinterval = 10; boolean alarmCreated = false; double threshold = 0; int alarmtypeidx = 0; boolean isSendingToDC = false; if (savedInstanceState != null && savedInstanceState.containsKey("config")) { mConfig = savedInstanceState.getParcelable("config"); } if (mConfig != null) { endpointName = mConfig.getEndpoint(); alarmInfo = mConfig.getAlarmSummary(); if (mConfig.getSubscriptionConfig() != null) { isSubscribed = mConfig.getSubscriptionConfig().isSubscribed(); sinterval = mConfig.getSubscriptionConfig().getInterval(); isSendingToDC = mConfig.shouldBePushedToDeviceCloud(); } else { // Not subscribed; default interval value from preferences. String i = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString("pref_default_interval", "0"); try { sinterval = Integer.parseInt(i); } catch (NumberFormatException e) { Log.d(TAG, "Failed to parse default interval from preferences: " + i); sinterval = 0; } } if (mConfig.getAlarmConfig() != null) { alarmCreated = mConfig.getAlarmConfig().isCreated(); threshold = mConfig.getAlarmConfig().getThreshold(); String typestr = AlarmType.makeString(mConfig.getAlarmConfig().getType()); for (int i = 0; i < alarmTypes.length; i++) { if (alarmTypes[i].toLowerCase(Locale.US).equals(typestr)) alarmtypeidx = i; } } } // Set up event listeners on EditText and CheckBox items subscribedCB.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { subInterval.setEnabled(isChecked); subIntervalTV.setEnabled(isChecked); } }); alarmCB.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { typeSpinner.setEnabled(isChecked); alarmThreshold.setEnabled(false); // If type spinner is set to Change, we want threshold disabled again if (isChecked) { alarmThreshold.setEnabled(!shouldDisableAlarmThreshold(typeSpinner.getSelectedItemPosition())); } } }); typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { if (alarmCB.isChecked() && shouldDisableAlarmThreshold(position)) alarmThreshold.setEnabled(false); else if (!alarmCB.isChecked()) alarmThreshold.setEnabled(false); else alarmThreshold.setEnabled(true); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); subIntervalTV.setEnabled(false); subInterval.setEnabled(false); alarmThreshold.setEnabled(false); typeSpinner.setEnabled(false); alarmInfoTV.setText(alarmInfo); // Click checkboxes, show data depending on if subscription or alarm // has been added already if (isSubscribed) subscribedCB.performClick(); if (alarmCreated) { showAlarmSection.setVisibility(View.VISIBLE); makeAlarmSection.setVisibility(View.GONE); alarmCB.setText("Remove alarm"); } else { makeAlarmSection.setVisibility(View.VISIBLE); showAlarmSection.setVisibility(View.GONE); alarmCB.setText("Create alarm"); } dcSendCB.setChecked(isSendingToDC); subInterval.setText(Integer.toString(sinterval)); alarmThreshold.setText(Double.toString(threshold)); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alarm_types, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); typeSpinner.setAdapter(adapter); typeSpinner.setSelection(alarmtypeidx); DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { // Fetch the EndpointsAdapter's configuration for this endpoint. // (We might have gotten mConfig from the saved instance bundle) EndpointConfiguration cfg = EndpointsAdapter.getInstance() .findEndpointConfiguration(mConfig.getEndpoint()); // Set whether this endpoint's data should be pushed to Device Cloud if (cfg != null) { cfg.setPushToDeviceCloud(dcSendCB.isChecked()); } // Handle (un)subscribing if (isUnsubscribing(subscribedCB.isChecked())) { unsubscribe(mConfig.getEndpoint()); } else if (subscribedCB.isChecked()) { if (handleMakingSubscription(subInterval)) { // Subscription was successful... most likely. Log.d(TAG, "Probably subscribed to endpoint."); } else { // Invalid interval. Toast.makeText(getActivity(), getString(R.string.configure_endpoints_toast_invalid_sub_interval), Toast.LENGTH_SHORT).show(); } } // Handle adding/removing alarm as necessary if (isRemovingAlarm(alarmCB.isChecked())) { removeAlarm(mConfig.getEndpoint(), mConfig.getAlarmConfig().getType()); } else if (alarmCB.isChecked()) { Editable thresholdText = alarmThreshold.getText(); String thresholdString; if (thresholdText == null) thresholdString = ""; else thresholdString = thresholdText.toString(); double threshold; try { threshold = Double.parseDouble(thresholdString); } catch (NumberFormatException e) { Toast.makeText(getActivity(), getString(R.string.configure_endpoints_invalid_threshold), Toast.LENGTH_SHORT).show(); return; } int alarmidx = typeSpinner.getSelectedItemPosition(); if (alarmidx == -1) { // But... how? Log.wtf(TAG, "alarm type index -1 ?"); return; } String type = alarmTypes[alarmidx]; AlarmType atype = AlarmType.fromString(type); createAlarm(mConfig.getEndpoint(), atype, threshold); } dialog.dismiss(); } }; return new AlertDialog.Builder(getActivity()).setView(v).setTitle("Endpoint: " + endpointName) .setPositiveButton("Save", clickListener) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Cancel means just dismiss the dialog. dialog.dismiss(); } }).create(); }
From source file:com.sunmeng.educationaladministration.animateview.GoogleCardsActivity.java
/** * Item??//from w w w .ja va 2s . c om */ public void getDetails() { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Map<String, Object> map; map = (Map<String, Object>) parent.getItemAtPosition(position); LayoutInflater inflater1 = getLayoutInflater(); View view1 = inflater1.inflate(R.layout.activity_extra_detailsinfo, (ViewGroup) findViewById(R.id.toast_layout)); final Spinner spn_extraclassName = (Spinner) view1.findViewById(R.id.spn_uextraclassName); final TextView tv_date = (TextView) view1.findViewById(R.id.ued_date_reply); final EditText et_teacher = (EditText) view1.findViewById(R.id.et_uextrateacher); final EditText et_jointeacher = (EditText) view1.findViewById(R.id.et_uextrajoin); final EditText et_address = (EditText) view1.findViewById(R.id.et_uaddress); final TextView tv_update_reply = (TextView) view1.findViewById(R.id.tvUpdate); final EditText et_uatime = (EditText) view1.findViewById(R.id.et_uatime); img_back = (ImageView) view1.findViewById(R.id.ivBack); img_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); /** * ??? */ httpUtils.send(HttpRequest.HttpMethod.GET, HttpClientUtil.HTTP_URL + "ClassAllServlet", new RequestCallBack() { @Override public void onSuccess(final ResponseInfo responseInfo) { //Toast.makeText(mContext, responseInfo.toString(), Toast.LENGTH_LONG).show(); final List<String> list = new ArrayList<String>(); list.add("cnname"); list.add("cnid"); new AsyncTask<String, String, Map<String, String>>() { @Override protected Map<String, String> doInBackground(String... params) { classNameArr = JsonUtil .getJsonToSpinnerListMap(responseInfo.result.toString(), list); return classNameArr; } @Override protected void onPostExecute(Map<String, String> s) { //android.R.layout.simple_spinner_dropdown_item// //R.layout.myspinner spn_extraclassName.setAdapter( new android.widget.ArrayAdapter<String>(GoogleCardsActivity.this, android.R.layout.simple_spinner_dropdown_item, Utils.getMapListToListString(s))); if (map.get("cnname").toString() != "") { spn_extraclassName.setSelection( Utils.getMapListId(s, map.get("cnname").toString())); spn_extraclassName.setEnabled(false); } else { } // et_classname_reply.setSelection(2, true); } }.execute(""); } @Override public void onFailure(HttpException e, String s) { } }); et_teacher.setText(map.get("ateacher").toString()); et_jointeacher.setText(map.get("ajointeacher").toString()); et_address.setText(map.get("aaddress").toString()); tv_date.setText(map.get("adate").toString()); et_uatime.setText(map.get("atime").toString()); tv_update_reply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (tv_update_reply.getText().equals("")) { setClickble(true); tv_update_reply.setText("?"); } else if (tv_update_reply.getText().equals("?")) { setClickble(false); tv_update_reply.setText(""); // TODO ?? updateReply(); } } /** * ?? */ private void setClickble(boolean flag) { et_teacher.setEnabled(flag); et_jointeacher.setEnabled(flag); et_address.setEnabled(flag); spn_extraclassName.setEnabled(flag); et_uatime.setEnabled(flag); } public void updateReply() { String etteacher = et_teacher.getText().toString().trim(); String etjointeacher = et_jointeacher.getText().toString().trim(); String ettime = et_uatime.getText().toString().trim(); String etaddress = et_address.getText().toString().trim(); String tvdate = tv_date.getText().toString().trim(); String classnumid = classNameArr .get(spn_extraclassName.getSelectedItem().toString().trim());//?id String id = map.get("aid").toString(); //Toast.makeText(GoogleCardsActivity.this, "="+etteacher+etjointeacher+ettime+etaddress, Toast.LENGTH_SHORT).show(); if ("".equals(etteacher) && "".equals(etjointeacher) && "".equals(etaddress)) { Toast.makeText(GoogleCardsActivity.this, "???", Toast.LENGTH_SHORT) .show(); return; } else { RequestParams params = new RequestParams(); params.addBodyParameter("activitiesupcdate", tvdate); params.addBodyParameter("activitiesuptime", ettime); params.addBodyParameter("activitiesupclassnumid", classnumid); params.addBodyParameter("activitiesupteacher", etteacher); params.addBodyParameter("activitiesupjointeacher", etjointeacher); params.addBodyParameter("activitiesupaddress", etaddress); params.addBodyParameter("activitiesuprid", id); Toast.makeText(GoogleCardsActivity.this, "id==" + id, Toast.LENGTH_SHORT).show(); httpUtils.send(HttpRequest.HttpMethod.POST, HttpClientUtil.HTTP_URL + "ActivitiesUpdateServlet", params, new RequestCallBack() { @Override public void onSuccess(ResponseInfo responseInfo) { Toast.makeText(GoogleCardsActivity.this, "?", Toast.LENGTH_SHORT).show(); getData(); dialog.cancel(); } @Override public void onFailure(HttpException e, String s) { Toast.makeText(GoogleCardsActivity.this, "", Toast.LENGTH_SHORT).show(); } }); } } }); builder = new AlertDialog.Builder(parent.getContext()); builder.setView(view1); dialog = builder.create(); dialog.show(); } }); }