Java Code Examples for android.widget.ToggleButton#setEnabled()
The following examples show how to use
android.widget.ToggleButton#setEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommentActivity.java From NoiseCapture with GNU General Public License v3.0 | 5 votes |
private void addTag(String tagName, int id, ViewGroup column, int color) { ToggleButton tagButton = new ToggleButton(this); if(color != -1) { LinearLayout colorBox = new LinearLayout(this); // Convert the dps to pixels, based on density scale final int tagPaddingPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, getResources().getDisplayMetrics()); final int tagPaddingPxBottom = (int) TypedValue.applyDimension(TypedValue .COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics()); //use a GradientDrawable with only one color set, to make it a solid color colorBox.setBackgroundResource(R.drawable.tag_round_corner); GradientDrawable gradientDrawable = (GradientDrawable) colorBox.getBackground(); gradientDrawable.setColor(color); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams .MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(tagPaddingPx,tagPaddingPx,tagPaddingPx,tagPaddingPxBottom); colorBox.setLayoutParams(params); colorBox.addView(tagButton); column.addView(colorBox); } else { column.addView(tagButton); } tagButton.setTextOff(tagName); tagButton.setTextOn(tagName); boolean isChecked = checkedTags.contains(id); tagButton.setChecked(isChecked); if(isChecked) { tagButton.setTextColor(selectedColor); } tagButton.setOnCheckedChangeListener(new TagStateListener(id, checkedTags)); tagButton.setMinHeight(0); tagButton.setMinimumHeight(0); tagButton.setTextSize(Dimension.SP, 12); tagButton.setEnabled(record == null || record.getUploadId().isEmpty()); tagButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); tagButton.invalidate(); }
Example 2
Source File: AlarmRepeatDialog.java From SuntimesWidget with GNU General Public License v3.0 | 4 votes |
private void updateViews(Context context) { if (Build.VERSION.SDK_INT >= 14) { if (switchRepeat != null) { if (repeatDays == null || repeatDays.isEmpty()) switchRepeat.setText(context.getString(R.string.alarmOption_repeat_none)); else switchRepeat.setText(AlarmClockItem.repeatsEveryDay(repeatDays) ? context.getString(R.string.alarmOption_repeat_all) : context.getString(R.string.alarmOption_repeat)); switchRepeat.setOnCheckedChangeListener(null); switchRepeat.setChecked(this.repeat); switchRepeat.setOnCheckedChangeListener(onRepeatChanged); } } else { if (checkRepeat != null) { if (repeatDays == null || repeatDays.isEmpty()) checkRepeat.setText(context.getString(R.string.alarmOption_repeat_none)); else checkRepeat.setText(AlarmClockItem.repeatsEveryDay(repeatDays) ? context.getString(R.string.alarmOption_repeat_all) : context.getString(R.string.alarmOption_repeat)); checkRepeat.setOnCheckedChangeListener(null); checkRepeat.setChecked(this.repeat); checkRepeat.setOnCheckedChangeListener(onRepeatChanged); } } if (btnDays != null) { int n = btnDays.size(); for (int i=0; i<n; i++) { ToggleButton button = btnDays.valueAt(i); if (button != null) { Integer day = tagToDay(button.getTag()); if (day != null) { button.setChecked(repeatDays.contains(day)); button.setEnabled(repeat); } else Log.d("DEBUG", "updateViews: missing button tag " + i); } else Log.d("DEBUG", "updateViews: missing button " + i); } } }
Example 3
Source File: PacketListActivity.java From sniffer154 with GNU General Public License v3.0 | 3 votes |
/** * Updates the status of the "Capture" button. * * The button is checked if a capture is in progress, unchecked otherwise. * The button is enabled if a sniffer is attached to the android device, * disabled otherwise */ private void updateCaptureButton() { AppSniffer154 app = (AppSniffer154) getApplication(); ToggleButton tb = (ToggleButton) findViewById(R.id.toggleCapture); tb.setChecked(app.isSniffingInProgress()); tb.setEnabled(app.isSniffingEnabled()); }