android.widget.ToggleButton#setEnabled ( )源码实例Demo

下面列出了android.widget.ToggleButton#setEnabled ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: NoiseCapture   文件: CommentActivity.java
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();
}
 
源代码2 项目: SuntimesWidget   文件: AlarmRepeatDialog.java
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);
        }
    }
}
 
源代码3 项目: sniffer154   文件: PacketListActivity.java
/**
 * 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());
}