List of usage examples for android.widget TextView setEnabled
@android.view.RemotableViewMethod @Override public void setEnabled(boolean enabled)
From source file:org.sufficientlysecure.keychain.ui.widget.SelectKeyCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { boolean valid = cursor.getInt(cursor.getColumnIndex(PROJECTION_ROW_VALID)) > 0; TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); mainUserId.setText(R.string.unknownUserId); TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); mainUserIdRest.setText(""); TextView keyId = (TextView) view.findViewById(R.id.keyId); keyId.setText(R.string.noKey);//w w w .j a v a 2s . c o m TextView status = (TextView) view.findViewById(R.id.status); status.setText(R.string.unknownStatus); String userId = cursor.getString(cursor.getColumnIndex(UserIds.USER_ID)); if (userId != null) { String[] userIdSplit = OtherHelper.splitUserId(userId); if (userIdSplit[1] != null) { mainUserIdRest.setText(userIdSplit[1]); } mainUserId.setText(userIdSplit[0]); } long masterKeyId = cursor.getLong(cursor.getColumnIndex(KeyRings.MASTER_KEY_ID)); keyId.setText(PgpHelper.getSmallFingerPrint(masterKeyId)); if (mainUserIdRest.getText().length() == 0) { mainUserIdRest.setVisibility(View.GONE); } if (valid) { if (mKeyType == Id.type.public_key) { status.setText(R.string.canEncrypt); } else { status.setText(R.string.canSign); } } else { if (cursor.getInt(cursor.getColumnIndex(PROJECTION_ROW_AVAILABLE)) > 0) { // has some CAN_ENCRYPT keys, but col(ROW_VALID) = 0, so must be revoked or // expired status.setText(R.string.expired); } else { status.setText(R.string.noKey); } } CheckBox selected = (CheckBox) view.findViewById(R.id.selected); if (mKeyType == Id.type.public_key) { selected.setVisibility(View.VISIBLE); if (!valid) { mListView.setItemChecked(cursor.getPosition(), false); } selected.setChecked(mListView.isItemChecked(cursor.getPosition())); selected.setEnabled(valid); } else { selected.setVisibility(View.GONE); } status.setText(status.getText() + " "); view.setEnabled(valid); mainUserId.setEnabled(valid); mainUserIdRest.setEnabled(valid); keyId.setEnabled(valid); status.setEnabled(valid); }
From source file:id.nci.stm_9.SelectKeyCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { boolean valid = cursor.getInt(cursor.getColumnIndex(PROJECTION_ROW_VALID)) > 0; TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId); mainUserId.setText(R.string.unknown_user_id); TextView mainUserIdRest = (TextView) view.findViewById(R.id.mainUserIdRest); mainUserIdRest.setText(""); TextView keyId = (TextView) view.findViewById(R.id.keyId); keyId.setText(R.string.no_key);/* w w w . ja v a 2 s.com*/ TextView status = (TextView) view.findViewById(R.id.status); status.setText(R.string.unknown_status); String userId = cursor.getString(cursor.getColumnIndex(UserIds.USER_ID)); if (userId != null) { String[] userIdSplit = OtherHelper.splitUserId(userId); if (userIdSplit[1] != null) { mainUserIdRest.setText(userIdSplit[1]); } mainUserId.setText(userIdSplit[0]); } long masterKeyId = cursor.getLong(cursor.getColumnIndex(KeyRings.MASTER_KEY_ID)); keyId.setText(PgpKeyHelper.convertKeyIdToHex(masterKeyId)); if (mainUserIdRest.getText().length() == 0) { mainUserIdRest.setVisibility(View.GONE); } if (valid) { // if (mKeyType == Id.type.public_key) { if (mKeyType == 0x21070001) { status.setText(R.string.can_encrypt); } else { status.setText(R.string.can_sign); } } else { if (cursor.getInt(cursor.getColumnIndex(PROJECTION_ROW_AVAILABLE)) > 0) { // has some CAN_ENCRYPT keys, but col(ROW_VALID) = 0, so must be revoked or // expired status.setText(R.string.expired); } else { status.setText(R.string.no_key); } } CheckBox selected = (CheckBox) view.findViewById(R.id.selected); // if (mKeyType == Id.type.public_key) { if (mKeyType == 0x21070001) { selected.setVisibility(View.VISIBLE); if (!valid) { mListView.setItemChecked(cursor.getPosition(), false); } selected.setChecked(mListView.isItemChecked(cursor.getPosition())); selected.setEnabled(valid); } else { selected.setVisibility(View.GONE); } status.setText(status.getText() + " "); view.setEnabled(valid); mainUserId.setEnabled(valid); mainUserIdRest.setEnabled(valid); keyId.setEnabled(valid); status.setEnabled(valid); }
From source file:org.glucosio.android.activity.MainActivity.java
public void showExportCsvDialog() { final Dialog exportDialog = new Dialog(MainActivity.this, R.style.GlucosioTheme); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(exportDialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.WRAP_CONTENT; lp.height = WindowManager.LayoutParams.WRAP_CONTENT; exportDialog.setContentView(R.layout.dialog_export); exportDialog.getWindow().setAttributes(lp); exportDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); exportDialog.getWindow().setDimAmount(0.5f); exportDialog.show();//from w w w.j a va2s. com exportDialogDateFrom = (TextView) exportDialog.findViewById(R.id.activity_export_date_from); exportDialogDateTo = (TextView) exportDialog.findViewById(R.id.activity_export_date_to); exportRangeButton = (RadioButton) exportDialog.findViewById(R.id.activity_export_range); final RadioButton exportAllButton = (RadioButton) exportDialog.findViewById(R.id.activity_export_all); final TextView exportButton = (TextView) exportDialog.findViewById(R.id.dialog_export_add); final TextView cancelButton = (TextView) exportDialog.findViewById(R.id.dialog_export_cancel); exportRangeButton.setChecked(true); exportDialogDateFrom.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); DatePickerDialog dpd = DatePickerDialog.newInstance(MainActivity.this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dpd.show(getFragmentManager(), "fromDateDialog"); dpd.setMaxDate(now); } }); exportDialogDateTo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Calendar now = Calendar.getInstance(); DatePickerDialog dpd = DatePickerDialog.newInstance(MainActivity.this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dpd.show(getFragmentManager(), "toDateDialog"); dpd.setMaxDate(now); } }); exportRangeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean isChecked = exportRangeButton.isChecked(); exportDialogDateFrom.setEnabled(true); exportDialogDateTo.setEnabled(true); exportAllButton.setChecked(!isChecked); } }); exportAllButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean isChecked = exportAllButton.isChecked(); exportDialogDateFrom.setEnabled(false); exportDialogDateTo.setEnabled(false); exportRangeButton.setChecked(!isChecked); exportButton.setEnabled(true); } }); exportButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (validateExportDialog()) { exportPresenter.onExportClicked(exportAllButton.isChecked()); exportDialog.dismiss(); } else { showSnackBar(getResources().getString(R.string.dialog_error), Snackbar.LENGTH_LONG); } } }); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { exportDialog.dismiss(); } }); }
From source file:org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView vName = (TextView) view.findViewById(R.id.user_id_item_name); TextView vAddress = (TextView) view.findViewById(R.id.user_id_item_address); TextView vComment = (TextView) view.findViewById(R.id.user_id_item_comment); ImageView vVerified = (ImageView) view.findViewById(R.id.user_id_item_certified); ViewAnimator vVerifiedLayout = (ViewAnimator) view.findViewById(R.id.user_id_icon_animator); ImageView vDeleteButton = (ImageView) view.findViewById(R.id.user_id_item_delete_button); vDeleteButton.setVisibility(View.GONE); // not used String userId = cursor.getString(INDEX_USER_ID); OpenPgpUtils.UserId splitUserId = KeyRing.splitUserId(userId); if (splitUserId.name != null) { vName.setText(splitUserId.name); } else {/*w w w . j a va 2 s . co m*/ vName.setText(R.string.user_id_no_name); } if (splitUserId.email != null) { vAddress.setText(splitUserId.email); vAddress.setVisibility(View.VISIBLE); } else { vAddress.setVisibility(View.GONE); } if (splitUserId.comment != null) { vComment.setText(splitUserId.comment); vComment.setVisibility(View.VISIBLE); } else { vComment.setVisibility(View.GONE); } boolean isPrimary = cursor.getInt(INDEX_IS_PRIMARY) != 0; boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0; // for edit key if (mSaveKeyringParcel != null) { boolean changeAnyPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null); boolean changeThisPrimaryUserId = (mSaveKeyringParcel.mChangePrimaryUserId != null && mSaveKeyringParcel.mChangePrimaryUserId.equals(userId)); boolean revokeThisUserId = (mSaveKeyringParcel.mRevokeUserIds.contains(userId)); // only if primary user id will be changed // (this is not triggered if the user id is currently the primary one) if (changeAnyPrimaryUserId) { // change _all_ primary user ids and set new one to true isPrimary = changeThisPrimaryUserId; } if (revokeThisUserId) { if (!isRevoked) { isRevoked = true; } } vVerifiedLayout.setDisplayedChild(2); } else { vVerifiedLayout.setDisplayedChild(mShowStatusImages ? 1 : 0); } if (isRevoked) { // set revocation icon (can this even be primary?) KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.REVOKED, R.color.key_flag_gray); // disable revoked user ids vName.setEnabled(false); vAddress.setEnabled(false); vComment.setEnabled(false); } else { vName.setEnabled(true); vAddress.setEnabled(true); vComment.setEnabled(true); if (isPrimary) { vName.setTypeface(null, Typeface.BOLD); vAddress.setTypeface(null, Typeface.BOLD); } else { vName.setTypeface(null, Typeface.NORMAL); vAddress.setTypeface(null, Typeface.NORMAL); } int isVerified = cursor.getInt(INDEX_VERIFIED); switch (isVerified) { case Certs.VERIFIED_SECRET: KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.VERIFIED, KeyFormattingUtils.DEFAULT_COLOR); break; case Certs.VERIFIED_SELF: KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.UNVERIFIED, KeyFormattingUtils.DEFAULT_COLOR); break; default: KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.INVALID, KeyFormattingUtils.DEFAULT_COLOR); break; } } }
From source file:co.nerdart.ourss.adapter.FeedsCursorAdapter.java
@Override protected void bindChildView(View view, Context context, Cursor cursor) { view.findViewById(R.id.indicator).setVisibility(View.INVISIBLE); TextView textView = ((TextView) view.findViewById(android.R.id.text1)); long feedId = cursor.getLong(idPosition); if (feedId == mSelectedFeedId) { view.setBackgroundResource(android.R.color.holo_blue_dark); } else {// w ww. j a v a 2 s.c o m view.setBackgroundResource(android.R.color.transparent); } TextView updateTextView = ((TextView) view.findViewById(android.R.id.text2)); updateTextView.setVisibility(View.VISIBLE); if (cursor.isNull(errorPosition)) { long timestamp = cursor.getLong(lastUpdateColumn); // Date formatting is expensive, look at the cache String formattedDate = mFormattedDateCache.get(timestamp); if (formattedDate == null) { Date date = new Date(timestamp); formattedDate = context.getString(R.string.update) + COLON + (timestamp == 0 ? context.getString(R.string.never) : new StringBuilder(Constants.DATE_FORMAT.format(date)).append(' ') .append(Constants.TIME_FORMAT.format(date))); mFormattedDateCache.put(timestamp, formattedDate); } updateTextView.setText(formattedDate); } else { updateTextView.setText(new StringBuilder(context.getString(R.string.error)).append(COLON) .append(cursor.getString(errorPosition))); } byte[] iconBytes = cursor.getBlob(iconPosition); if (iconBytes != null && iconBytes.length > 0) { Bitmap bitmap = BitmapFactory.decodeByteArray(iconBytes, 0, iconBytes.length); if (bitmap != null && bitmap.getHeight() > 0 && bitmap.getWidth() > 0) { int bitmapSizeInDip = UiUtils.dpToPixel(18); if (bitmap.getHeight() != bitmapSizeInDip) { bitmap = Bitmap.createScaledBitmap(bitmap, bitmapSizeInDip, bitmapSizeInDip, false); } textView.setCompoundDrawablesWithIntrinsicBounds(new BitmapDrawable(context.getResources(), bitmap), null, null, null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } } else { view.setTag(null); textView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null); } int unreadCount; synchronized (mUnreadItemsByFeed) { unreadCount = mUnreadItemsByFeed.get(feedId); } if (unreadCount > 0) { textView.setEnabled(true); updateTextView.setEnabled(true); } else { textView.setEnabled(false); updateTextView.setEnabled(false); } textView.setText( (cursor.isNull(namePosition) ? cursor.getString(linkPosition) : cursor.getString(namePosition)) + (unreadCount > 0 ? " (" + unreadCount + ")" : "")); View sortView = view.findViewById(R.id.sortitem); if (!sortViews.contains(sortView)) { // as we are reusing views, this is fine sortViews.add(sortView); } sortView.setVisibility(feedSort ? View.VISIBLE : View.GONE); }
From source file:org.sufficientlysecure.keychain.ui.adapter.ViewKeyKeysAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView keyId = (TextView) view.findViewById(R.id.keyId); TextView keyDetails = (TextView) view.findViewById(R.id.keyDetails); TextView keyExpiry = (TextView) view.findViewById(R.id.keyExpiry); ImageView masterKeyIcon = (ImageView) view.findViewById(R.id.ic_masterKey); ImageView certifyIcon = (ImageView) view.findViewById(R.id.ic_certifyKey); ImageView encryptIcon = (ImageView) view.findViewById(R.id.ic_encryptKey); ImageView signIcon = (ImageView) view.findViewById(R.id.ic_signKey); ImageView revokedKeyIcon = (ImageView) view.findViewById(R.id.ic_revokedKey); String keyIdStr = PgpKeyHelper.convertKeyIdToHex(cursor.getLong(mIndexKeyId)); String algorithmStr = PgpKeyHelper.getAlgorithmInfo(context, cursor.getInt(mIndexAlgorithm), cursor.getInt(mIndexKeySize)); keyId.setText(keyIdStr);/*w ww . j a v a 2 s.c o m*/ // may be set with additional "stripped" later on if (hasAnySecret && cursor.getInt(mIndexHasSecret) == 0) { keyDetails.setText(algorithmStr + ", " + context.getString(R.string.key_stripped)); } else { keyDetails.setText(algorithmStr); } // Set icons according to properties masterKeyIcon.setVisibility(cursor.getInt(mIndexRank) == 0 ? View.VISIBLE : View.INVISIBLE); certifyIcon.setVisibility(cursor.getInt(mIndexCanCertify) != 0 ? View.VISIBLE : View.GONE); encryptIcon.setVisibility(cursor.getInt(mIndexCanEncrypt) != 0 ? View.VISIBLE : View.GONE); signIcon.setVisibility(cursor.getInt(mIndexCanSign) != 0 ? View.VISIBLE : View.GONE); boolean valid = true; if (cursor.getInt(mIndexRevokedKey) > 0) { revokedKeyIcon.setVisibility(View.VISIBLE); valid = false; } else { keyId.setTextColor(mDefaultTextColor); keyDetails.setTextColor(mDefaultTextColor); keyExpiry.setTextColor(mDefaultTextColor); revokedKeyIcon.setVisibility(View.GONE); } if (!cursor.isNull(mIndexExpiry)) { Date expiryDate = new Date(cursor.getLong(mIndexExpiry) * 1000); valid = valid && expiryDate.after(new Date()); keyExpiry.setText(context.getString(R.string.label_expiry) + ": " + DateFormat.getDateFormat(context).format(expiryDate)); } else { keyExpiry.setText(context.getString(R.string.label_expiry) + ": " + context.getString(R.string.none)); } // if key is expired or revoked, strike through text if (!valid) { keyId.setText(OtherHelper.strikeOutText(keyId.getText())); keyDetails.setText(OtherHelper.strikeOutText(keyDetails.getText())); keyExpiry.setText(OtherHelper.strikeOutText(keyExpiry.getText())); } keyId.setEnabled(valid); keyDetails.setEnabled(valid); keyExpiry.setEnabled(valid); }
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; }// w w w .j a v a2s.co 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.mantz_it.rfanalyzer.MainActivity.java
/** * Will pop up a dialog to let the user adjust gain settings *//*from w w w . ja v a 2s. c o m*/ private void adjustGain() { if (source == null) return; int sourceType = Integer.valueOf(preferences.getString(getString(R.string.pref_sourceType), "1")); switch (sourceType) { case FILE_SOURCE: Toast.makeText(this, getString(R.string.filesource_doesnt_support_gain), Toast.LENGTH_LONG).show(); break; case HACKRF_SOURCE: // Prepare layout: final LinearLayout view_hackrf = (LinearLayout) this.getLayoutInflater().inflate(R.layout.hackrf_gain, null); final SeekBar sb_hackrf_vga = (SeekBar) view_hackrf.findViewById(R.id.sb_hackrf_vga_gain); final SeekBar sb_hackrf_lna = (SeekBar) view_hackrf.findViewById(R.id.sb_hackrf_lna_gain); final TextView tv_hackrf_vga = (TextView) view_hackrf.findViewById(R.id.tv_hackrf_vga_gain); final TextView tv_hackrf_lna = (TextView) view_hackrf.findViewById(R.id.tv_hackrf_lna_gain); sb_hackrf_vga.setMax(HackrfSource.MAX_VGA_RX_GAIN / HackrfSource.VGA_RX_GAIN_STEP_SIZE); sb_hackrf_lna.setMax(HackrfSource.MAX_LNA_GAIN / HackrfSource.LNA_GAIN_STEP_SIZE); sb_hackrf_vga.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_hackrf_vga.setText("" + progress * HackrfSource.VGA_RX_GAIN_STEP_SIZE); ((HackrfSource) source).setVgaRxGain(progress * HackrfSource.VGA_RX_GAIN_STEP_SIZE); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); sb_hackrf_lna.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_hackrf_lna.setText("" + progress * HackrfSource.LNA_GAIN_STEP_SIZE); ((HackrfSource) source).setLnaGain(progress * HackrfSource.LNA_GAIN_STEP_SIZE); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); sb_hackrf_vga.setProgress(((HackrfSource) source).getVgaRxGain() / HackrfSource.VGA_RX_GAIN_STEP_SIZE); sb_hackrf_lna.setProgress(((HackrfSource) source).getLnaGain() / HackrfSource.LNA_GAIN_STEP_SIZE); // Show dialog: AlertDialog hackrfDialog = new AlertDialog.Builder(this).setTitle("Adjust Gain Settings") .setView(view_hackrf).setPositiveButton("Set", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putInt(getString(R.string.pref_hackrf_vgaRxGain), sb_hackrf_vga.getProgress() * HackrfSource.VGA_RX_GAIN_STEP_SIZE); edit.putInt(getString(R.string.pref_hackrf_lnaGain), sb_hackrf_lna.getProgress() * HackrfSource.LNA_GAIN_STEP_SIZE); edit.apply(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).create(); hackrfDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { // sync source with (new/old) settings int vgaRxGain = preferences.getInt(getString(R.string.pref_hackrf_vgaRxGain), HackrfSource.MAX_VGA_RX_GAIN / 2); int lnaGain = preferences.getInt(getString(R.string.pref_hackrf_lnaGain), HackrfSource.MAX_LNA_GAIN / 2); if (((HackrfSource) source).getVgaRxGain() != vgaRxGain) ((HackrfSource) source).setVgaRxGain(vgaRxGain); if (((HackrfSource) source).getLnaGain() != lnaGain) ((HackrfSource) source).setLnaGain(lnaGain); } }); hackrfDialog.show(); hackrfDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); break; case RTLSDR_SOURCE: final int[] possibleGainValues = ((RtlsdrSource) source).getPossibleGainValues(); final int[] possibleIFGainValues = ((RtlsdrSource) source).getPossibleIFGainValues(); if (possibleGainValues.length <= 1 && possibleIFGainValues.length <= 1) { Toast.makeText(MainActivity.this, source.getName() + " does not support gain adjustment!", Toast.LENGTH_LONG).show(); } // Prepare layout: final LinearLayout view_rtlsdr = (LinearLayout) this.getLayoutInflater().inflate(R.layout.rtlsdr_gain, null); final LinearLayout ll_rtlsdr_gain = (LinearLayout) view_rtlsdr.findViewById(R.id.ll_rtlsdr_gain); final LinearLayout ll_rtlsdr_ifgain = (LinearLayout) view_rtlsdr.findViewById(R.id.ll_rtlsdr_ifgain); final Switch sw_rtlsdr_manual_gain = (Switch) view_rtlsdr.findViewById(R.id.sw_rtlsdr_manual_gain); final CheckBox cb_rtlsdr_agc = (CheckBox) view_rtlsdr.findViewById(R.id.cb_rtlsdr_agc); final SeekBar sb_rtlsdr_gain = (SeekBar) view_rtlsdr.findViewById(R.id.sb_rtlsdr_gain); final SeekBar sb_rtlsdr_ifGain = (SeekBar) view_rtlsdr.findViewById(R.id.sb_rtlsdr_ifgain); final TextView tv_rtlsdr_gain = (TextView) view_rtlsdr.findViewById(R.id.tv_rtlsdr_gain); final TextView tv_rtlsdr_ifGain = (TextView) view_rtlsdr.findViewById(R.id.tv_rtlsdr_ifgain); // Assign current gain: int gainIndex = 0; int ifGainIndex = 0; for (int i = 0; i < possibleGainValues.length; i++) { if (((RtlsdrSource) source).getGain() == possibleGainValues[i]) { gainIndex = i; break; } } for (int i = 0; i < possibleIFGainValues.length; i++) { if (((RtlsdrSource) source).getIFGain() == possibleIFGainValues[i]) { ifGainIndex = i; break; } } sb_rtlsdr_gain.setMax(possibleGainValues.length - 1); sb_rtlsdr_ifGain.setMax(possibleIFGainValues.length - 1); sb_rtlsdr_gain.setProgress(gainIndex); sb_rtlsdr_ifGain.setProgress(ifGainIndex); tv_rtlsdr_gain.setText("" + possibleGainValues[gainIndex]); tv_rtlsdr_ifGain.setText("" + possibleIFGainValues[ifGainIndex]); // Assign current manual gain and agc setting sw_rtlsdr_manual_gain.setChecked(((RtlsdrSource) source).isManualGain()); cb_rtlsdr_agc.setChecked(((RtlsdrSource) source).isAutomaticGainControl()); // Add listener to gui elements: sw_rtlsdr_manual_gain.setOnCheckedChangeListener(new Switch.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { sb_rtlsdr_gain.setEnabled(isChecked); tv_rtlsdr_gain.setEnabled(isChecked); sb_rtlsdr_ifGain.setEnabled(isChecked); tv_rtlsdr_ifGain.setEnabled(isChecked); ((RtlsdrSource) source).setManualGain(isChecked); if (isChecked) { ((RtlsdrSource) source).setGain(possibleGainValues[sb_rtlsdr_gain.getProgress()]); ((RtlsdrSource) source).setIFGain(possibleIFGainValues[sb_rtlsdr_ifGain.getProgress()]); } } }); cb_rtlsdr_agc.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { ((RtlsdrSource) source).setAutomaticGainControl(isChecked); } }); sb_rtlsdr_gain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_rtlsdr_gain.setText("" + possibleGainValues[progress]); ((RtlsdrSource) source).setGain(possibleGainValues[progress]); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); sb_rtlsdr_ifGain.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv_rtlsdr_ifGain.setText("" + possibleIFGainValues[progress]); ((RtlsdrSource) source).setIFGain(possibleIFGainValues[progress]); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); // Disable gui elements if gain cannot be adjusted: if (possibleGainValues.length <= 1) ll_rtlsdr_gain.setVisibility(View.GONE); if (possibleIFGainValues.length <= 1) ll_rtlsdr_ifgain.setVisibility(View.GONE); if (!sw_rtlsdr_manual_gain.isChecked()) { sb_rtlsdr_gain.setEnabled(false); tv_rtlsdr_gain.setEnabled(false); sb_rtlsdr_ifGain.setEnabled(false); tv_rtlsdr_ifGain.setEnabled(false); } // Show dialog: AlertDialog rtlsdrDialog = new AlertDialog.Builder(this).setTitle("Adjust Gain Settings") .setView(view_rtlsdr).setPositiveButton("Set", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // safe preferences: SharedPreferences.Editor edit = preferences.edit(); edit.putBoolean(getString(R.string.pref_rtlsdr_manual_gain), sw_rtlsdr_manual_gain.isChecked()); edit.putBoolean(getString(R.string.pref_rtlsdr_agc), cb_rtlsdr_agc.isChecked()); edit.putInt(getString(R.string.pref_rtlsdr_gain), possibleGainValues[sb_rtlsdr_gain.getProgress()]); edit.putInt(getString(R.string.pref_rtlsdr_ifGain), possibleIFGainValues[sb_rtlsdr_ifGain.getProgress()]); edit.apply(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // do nothing } }).create(); rtlsdrDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { boolean manualGain = preferences.getBoolean(getString(R.string.pref_rtlsdr_manual_gain), false); boolean agc = preferences.getBoolean(getString(R.string.pref_rtlsdr_agc), false); int gain = preferences.getInt(getString(R.string.pref_rtlsdr_gain), 0); int ifGain = preferences.getInt(getString(R.string.pref_rtlsdr_ifGain), 0); ((RtlsdrSource) source).setGain(gain); ((RtlsdrSource) source).setIFGain(ifGain); ((RtlsdrSource) source).setManualGain(manualGain); ((RtlsdrSource) source).setAutomaticGainControl(agc); if (manualGain) { // Note: This is a workaround. After setting manual gain to true we must // rewrite the manual gain values: ((RtlsdrSource) source).setGain(gain); ((RtlsdrSource) source).setIFGain(ifGain); } } }); rtlsdrDialog.show(); rtlsdrDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); break; default: Log.e(LOGTAG, "adjustGain: Invalid source type: " + sourceType); break; } }
From source file:com.dsi.ant.antplus.pluginsampler.geocache.Dialog_GeoProgramDevice.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Program Device " + deviceData.deviceId); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); View detailsView = inflater.inflate(R.layout.dialog_geocache_programdevice, null); // Inflate and set the layout for the dialog // Pass null as the parent view because its going in the dialog layout builder.setView(detailsView);/*from ww w . ja v a 2s . c o m*/ // Add action buttons //Note we override the positive button in show() below so we can prevent it from closing builder.setPositiveButton("Begin Programing", null); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Let dialog dismiss } }); checkBox_EnableIdString = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableIdentifcationString); checkBox_EnablePIN = (CheckBox) detailsView.findViewById(R.id.checkBox_EnablePIN); checkBox_EnableLatitude = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLatitude); checkBox_EnableLongitude = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLongitude); checkBox_EnableHintString = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableHintString); checkBox_EnableLastVisit = (CheckBox) detailsView.findViewById(R.id.checkBox_EnableLastVisitInfo); final TextView textView_NumVisitsTitle = (TextView) detailsView .findViewById(R.id.textView_NumberOfVisitsTitle); final TextView textView_LastVisitDateTitle = (TextView) detailsView .findViewById(R.id.textView_LastVisitDateTitle); final TextView textView_LastVisitTimeTitle = (TextView) detailsView .findViewById(R.id.textView_LastVisitTimeTitle); editText_IdString = (EditText) detailsView.findViewById(R.id.editText_IdentificationString); editText_PIN = (EditText) detailsView.findViewById(R.id.editText_PIN); editText_Latitude = (EditText) detailsView.findViewById(R.id.editText_Latitude); editText_Longitude = (EditText) detailsView.findViewById(R.id.editText_Longitude); editText_HintString = (EditText) detailsView.findViewById(R.id.editText_HintString); editText_NumVisits = (EditText) detailsView.findViewById(R.id.editText_NumberOfVisits); textView_LastVisitDate = (TextView) detailsView.findViewById(R.id.textView_LastVisitDate); textView_LastVisitTime = (TextView) detailsView.findViewById(R.id.textView_LastVisitTime); radioButton_ClearExisitingData = (RadioButton) detailsView.findViewById(R.id.radioButton_ClearExistingData); //Hook up checkboxes to enable/disable fields checkBox_EnableIdString.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_IdString.setEnabled(isChecked); if (isChecked && editText_IdString.getText().length() == 0) editText_IdString.setText("ID STR"); } }); checkBox_EnablePIN.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_PIN.setEnabled(isChecked); if (isChecked && editText_PIN.getText().length() == 0) editText_PIN.setText("123456"); } }); checkBox_EnableLatitude.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_Latitude.setEnabled(isChecked); if (isChecked && editText_Latitude.getText().length() == 0) editText_Latitude.setText("-40.1"); } }); checkBox_EnableLongitude.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_Longitude.setEnabled(isChecked); if (isChecked && editText_Longitude.getText().length() == 0) editText_Longitude.setText("-20.1"); } }); checkBox_EnableHintString.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { editText_HintString.setEnabled(isChecked); if (isChecked && editText_HintString.getText().length() == 0) editText_HintString.setText("Hint string."); } }); checkBox_EnableLastVisit.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { textView_NumVisitsTitle.setEnabled(isChecked); textView_LastVisitDateTitle.setEnabled(isChecked); textView_LastVisitTimeTitle.setEnabled(isChecked); editText_NumVisits.setEnabled(isChecked); textView_LastVisitDate.setEnabled(isChecked); textView_LastVisitTime.setEnabled(isChecked); if (isChecked) { if (editText_NumVisits.length() == 0) editText_NumVisits.setText("0"); if (textView_LastVisitDate.length() == 0) textView_LastVisitDate.setText("dd/mmm/yyyy"); if (textView_LastVisitTime.length() == 0) textView_LastVisitDate.setText("hh:mm"); } } }); //Set data editText_IdString.setText(String.valueOf(deviceData.programmableData.identificationString)); editText_PIN.setText(String.valueOf(deviceData.programmableData.PIN)); if (deviceData.programmableData.latitude != null) editText_Latitude.setText( String.valueOf(deviceData.programmableData.latitude.setScale(5, BigDecimal.ROUND_HALF_UP))); else editText_Latitude.setText(""); if (deviceData.programmableData.longitude != null) editText_Longitude.setText( String.valueOf(deviceData.programmableData.longitude.setScale(5, BigDecimal.ROUND_HALF_UP))); else editText_Longitude.setText(""); if (deviceData.programmableData.hintString != null) editText_HintString.setText(String.valueOf(deviceData.programmableData.hintString)); else editText_HintString.setText(""); if (deviceData.programmableData.numberOfVisits != null) editText_NumVisits.setText(String.valueOf(deviceData.programmableData.numberOfVisits)); else editText_NumVisits.setText(""); if (deviceData.programmableData.lastVisitTimestamp != null) { currentDisplayDatetime = deviceData.programmableData.lastVisitTimestamp; updateDateAndTime(); } else { textView_LastVisitDate.setText(""); textView_LastVisitTime.setText(""); } //Hook up date and time fields to pickers textView_LastVisitDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentDisplayDatetime == null) currentDisplayDatetime = new GregorianCalendar(TimeZone.getTimeZone("UTC")); DatePickerDialog d = new DatePickerDialog(getActivity(), new OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { currentDisplayDatetime.set(year, monthOfYear, dayOfMonth); updateDateAndTime(); } }, currentDisplayDatetime.get(Calendar.YEAR), currentDisplayDatetime.get(Calendar.MONTH), currentDisplayDatetime.get(Calendar.DAY_OF_MONTH)); d.show(); } }); textView_LastVisitTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (currentDisplayDatetime == null) currentDisplayDatetime = new GregorianCalendar(TimeZone.getTimeZone("UTC")); TimePickerDialog d = new TimePickerDialog(getActivity(), new OnTimeSetListener() { @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { currentDisplayDatetime.set(Calendar.HOUR_OF_DAY, hourOfDay); currentDisplayDatetime.set(Calendar.MINUTE, minute); updateDateAndTime(); } }, currentDisplayDatetime.get(Calendar.HOUR_OF_DAY), currentDisplayDatetime.get(Calendar.MINUTE), false); d.show(); } }); return builder.create(); }
From source file:org.tvbrowser.tvbrowser.TvBrowser.java
private void updateTvData() { if (!TvDataUpdateService.IS_RUNNING) { Cursor test = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, TvBrowserContentProvider.CHANNEL_KEY_SELECTION + "=1", null, null); if (test.getCount() > 0) { AlertDialog.Builder builder = new AlertDialog.Builder(TvBrowser.this); RelativeLayout dataDownload = (RelativeLayout) getLayoutInflater() .inflate(R.layout.dialog_data_update_selection, getParentViewGroup(), false); final Spinner days = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_selection_download_days); final CheckBox pictures = (CheckBox) dataDownload .findViewById(R.id.dialog_data_update_selection_download_picture); final Spinner autoUpdate = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type); final Spinner frequency = (Spinner) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_frequency); final CheckBox onlyWiFi = (CheckBox) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_type_connection); final TextView timeLabel = (TextView) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time_label); final TextView time = (TextView) dataDownload .findViewById(R.id.dialog_data_update_preferences_auto_update_selection_time); time.setTextColor(onlyWiFi.getTextColors()); String currentDownloadDays = PrefUtils.getStringValue(R.string.DAYS_TO_DOWNLOAD, R.string.days_to_download_default); final String[] possibleDownloadDays = getResources().getStringArray(R.array.download_days); for (int i = 0; i < possibleDownloadDays.length; i++) { if (currentDownloadDays.equals(possibleDownloadDays[i])) { days.setSelection(i); break; }/*from www . j ava 2s . c o m*/ } pictures.setChecked( PrefUtils.getBooleanValue(R.string.LOAD_PICTURE_DATA, R.bool.load_picture_data_default)); String currentAutoUpdateValue = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_TYPE, R.string.pref_auto_update_type_default); String currentAutoUpdateFrequency = PrefUtils.getStringValue(R.string.PREF_AUTO_UPDATE_FREQUENCY, R.string.pref_auto_update_frequency_default); if (currentAutoUpdateValue.equals("0")) { frequency.setEnabled(false); onlyWiFi.setEnabled(false); timeLabel.setEnabled(false); time.setEnabled(false); frequency.setVisibility(View.GONE); onlyWiFi.setVisibility(View.GONE); timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } else if (currentAutoUpdateValue.equals("1")) { autoUpdate.setSelection(1); timeLabel.setEnabled(false); time.setEnabled(false); timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } else if (currentAutoUpdateValue.equals("2")) { autoUpdate.setSelection(2); } final String[] autoFrequencyPossibleValues = getResources() .getStringArray(R.array.pref_auto_update_frequency_values); for (int i = 0; i < autoFrequencyPossibleValues.length; i++) { if (autoFrequencyPossibleValues[i].equals(currentAutoUpdateFrequency)) { frequency.setSelection(i); break; } } onlyWiFi.setChecked(PrefUtils.getBooleanValue(R.string.PREF_AUTO_UPDATE_ONLY_WIFI, R.bool.pref_auto_update_only_wifi_default)); final AtomicInteger currentAutoUpdateTime = new AtomicInteger(PrefUtils.getIntValue( R.string.PREF_AUTO_UPDATE_START_TIME, R.integer.pref_auto_update_start_time_default)); Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60); now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime())); autoUpdate.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { frequency.setEnabled(position != 0); onlyWiFi.setEnabled(position != 0); if (position != 0) { frequency.setVisibility(View.VISIBLE); onlyWiFi.setVisibility(View.VISIBLE); } else { frequency.setVisibility(View.GONE); onlyWiFi.setVisibility(View.GONE); } timeLabel.setEnabled(position == 2); time.setEnabled(position == 2); if (position == 2) { timeLabel.setVisibility(View.VISIBLE); time.setVisibility(View.VISIBLE); } else { timeLabel.setVisibility(View.GONE); time.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); View.OnClickListener onClickListener = new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder b2 = new AlertDialog.Builder(TvBrowser.this); LinearLayout timeSelection = (LinearLayout) getLayoutInflater().inflate( R.layout.dialog_data_update_selection_auto_update_time, getParentViewGroup(), false); final TimePicker timePick = (TimePicker) timeSelection .findViewById(R.id.dialog_data_update_selection_auto_update_selection_time); timePick.setIs24HourView(DateFormat.is24HourFormat(TvBrowser.this)); timePick.setCurrentHour(currentAutoUpdateTime.get() / 60); timePick.setCurrentMinute(currentAutoUpdateTime.get() % 60); b2.setView(timeSelection); b2.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { currentAutoUpdateTime .set(timePick.getCurrentHour() * 60 + timePick.getCurrentMinute()); Calendar now = Calendar.getInstance(); now.set(Calendar.HOUR_OF_DAY, currentAutoUpdateTime.get() / 60); now.set(Calendar.MINUTE, currentAutoUpdateTime.get() % 60); now.set(Calendar.SECOND, 0); now.set(Calendar.MILLISECOND, 0); time.setText(DateFormat.getTimeFormat(TvBrowser.this).format(now.getTime())); } }); b2.setNegativeButton(android.R.string.cancel, null); b2.show(); } }; time.setOnClickListener(onClickListener); timeLabel.setOnClickListener(onClickListener); builder.setTitle(R.string.download_data); builder.setView(dataDownload); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String value = possibleDownloadDays[days.getSelectedItemPosition()]; Editor settings = PreferenceManager.getDefaultSharedPreferences(TvBrowser.this).edit(); if (PrefUtils.getStringValueAsInt(R.string.PREF_AUTO_UPDATE_RANGE, R.string.pref_auto_update_range_default) < Integer.parseInt(value)) { settings.putString(getString(R.string.PREF_AUTO_UPDATE_RANGE), value); } settings.putString(getString(R.string.DAYS_TO_DOWNLOAD), value); settings.putBoolean(getString(R.string.LOAD_PICTURE_DATA), pictures.isChecked()); settings.putString(getString(R.string.PREF_AUTO_UPDATE_TYPE), String.valueOf(autoUpdate.getSelectedItemPosition())); if (autoUpdate.getSelectedItemPosition() == 1 || autoUpdate.getSelectedItemPosition() == 2) { settings.putString(getString(R.string.PREF_AUTO_UPDATE_FREQUENCY), autoFrequencyPossibleValues[frequency.getSelectedItemPosition()]); settings.putBoolean(getString(R.string.PREF_AUTO_UPDATE_ONLY_WIFI), onlyWiFi.isChecked()); if (autoUpdate.getSelectedItemPosition() == 2) { settings.putInt(getString(R.string.PREF_AUTO_UPDATE_START_TIME), currentAutoUpdateTime.get()); } } settings.commit(); IOUtils.handleDataUpdatePreferences(TvBrowser.this); Intent startDownload = new Intent(TvBrowser.this, TvDataUpdateService.class); startDownload.putExtra(TvDataUpdateService.TYPE, TvDataUpdateService.TV_DATA_TYPE); startDownload.putExtra(getResources().getString(R.string.DAYS_TO_DOWNLOAD), Integer.parseInt(value)); startService(startDownload); updateProgressIcon(true); } }); builder.setNegativeButton(android.R.string.cancel, null); builder.show(); } else { Cursor test2 = getContentResolver().query(TvBrowserContentProvider.CONTENT_URI_CHANNELS, null, null, null, null); boolean loadAgain = test2.getCount() < 1; test2.close(); selectChannels(loadAgain); } test.close(); } }