Search in sources :

Example 26 with Checkable

use of android.widget.Checkable in project BlogSource by TeachCourse.

the class MultiLayoutSimpleAdapter method bindView.

private void bindView(int position, View view) {
    final Map<String, ?> dataSet = mData.get(position);
    if (dataSet == null) {
        return;
    }
    final ViewBinder binder = mViewBinder;
    final String[] from = mFrom;
    final int[] to = mTo;
    final int count = to.length;
    for (int i = 0; i < count; i++) {
        final View v = view.findViewById(to[i]);
        if (v != null) {
            final Object data = dataSet.get(from[i]);
            String text = data == null ? "" : data.toString();
            if (text == null) {
                text = "";
            }
            boolean bound = false;
            if (binder != null) {
                bound = binder.setViewValue(v, data, text);
            }
            if (!bound) {
                if (v instanceof Checkable) {
                    if (data instanceof Boolean) {
                        ((Checkable) v).setChecked((Boolean) data);
                    } else if (v instanceof TextView) {
                        // Note: keep the instanceof TextView check at the bottom of these
                        // ifs since a lot of views are TextViews (e.g. CheckBoxes).
                        setViewText((TextView) v, text);
                    } else {
                        throw new IllegalStateException(v.getClass().getName() + " should be bound to a Boolean, not a " + (data == null ? "<unknown type>" : data.getClass()));
                    }
                } else if (v instanceof TextView) {
                    // Note: keep the instanceof TextView check at the bottom of these
                    // ifs since a lot of views are TextViews (e.g. CheckBoxes).
                    setViewText((TextView) v, text);
                } else if (v instanceof ImageView) {
                    if (data instanceof Integer) {
                        setViewImage((ImageView) v, (Integer) data);
                    } else {
                        setViewImage((ImageView) v, text);
                    }
                } else if (v instanceof Spinner) {
                    if (data instanceof Integer) {
                        ((Spinner) v).setSelection((Integer) data);
                    } else {
                        continue;
                    }
                } else {
                    throw new IllegalStateException(v.getClass().getName() + " is not a " + " view that can be bounds by this SimpleAdapter");
                }
            }
        }
    }
}
Also used : Spinner(android.widget.Spinner) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) Checkable(android.widget.Checkable) ImageView(android.widget.ImageView)

Example 27 with Checkable

use of android.widget.Checkable in project Carbon by ZieIony.

the class RadioGroup method addView.

@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child instanceof Checkable) {
        final Checkable button = (Checkable) child;
        if (button.isChecked()) {
            mProtectFromCheckedChange = true;
            if (mCheckedId != -1) {
                setCheckedStateForView(mCheckedId, false);
            }
            mProtectFromCheckedChange = false;
            setCheckedId(child.getId());
        }
    }
    super.addView(child, index, params);
}
Also used : Checkable(android.widget.Checkable)

Example 28 with Checkable

use of android.widget.Checkable in project BookReader by JustWayward.

the class BaseViewHolder method setChecked.

public BaseViewHolder setChecked(int viewId, boolean checked) {
    Checkable view = getView(viewId);
    view.setChecked(checked);
    return this;
}
Also used : Checkable(android.widget.Checkable)

Example 29 with Checkable

use of android.widget.Checkable in project double-espresso by JakeWharton.

the class ViewMatchersTest method testCheckBoxMatchers.

public void testCheckBoxMatchers() {
    assertFalse(isChecked().matches(new Spinner(getInstrumentation().getTargetContext())));
    assertFalse(isNotChecked().matches(new Spinner(getInstrumentation().getTargetContext())));
    CheckBox checkBox = new CheckBox(getInstrumentation().getTargetContext());
    checkBox.setChecked(true);
    assertTrue(isChecked().matches(checkBox));
    assertFalse(isNotChecked().matches(checkBox));
    checkBox.setChecked(false);
    assertFalse(isChecked().matches(checkBox));
    assertTrue(isNotChecked().matches(checkBox));
    RadioButton radioButton = new RadioButton(getInstrumentation().getTargetContext());
    radioButton.setChecked(false);
    assertFalse(isChecked().matches(radioButton));
    assertTrue(isNotChecked().matches(radioButton));
    radioButton.setChecked(true);
    assertTrue(isChecked().matches(radioButton));
    assertFalse(isNotChecked().matches(radioButton));
    CheckedTextView checkedText = new CheckedTextView(getInstrumentation().getTargetContext());
    checkedText.setChecked(false);
    assertFalse(isChecked().matches(checkedText));
    assertTrue(isNotChecked().matches(checkedText));
    checkedText.setChecked(true);
    assertTrue(isChecked().matches(checkedText));
    assertFalse(isNotChecked().matches(checkedText));
    Checkable checkable = new Checkable() {

        @Override
        public boolean isChecked() {
            return true;
        }

        @Override
        public void setChecked(boolean ignored) {
        }

        @Override
        public void toggle() {
        }
    };
    assertFalse(isChecked().matches(checkable));
    assertFalse(isNotChecked().matches(checkable));
}
Also used : Spinner(android.widget.Spinner) CheckBox(android.widget.CheckBox) CheckedTextView(android.widget.CheckedTextView) RadioButton(android.widget.RadioButton) Checkable(android.widget.Checkable)

Example 30 with Checkable

use of android.widget.Checkable in project double-espresso by JakeWharton.

the class HumanReadables method describe.

/**
 * Transforms an arbitrary view into a string with (hopefully) enough debug info.
 *
 * @param v nullable view
 * @return a string for human consumption.
 */
public static String describe(View v) {
    if (null == v) {
        return "null";
    }
    ToStringHelper helper = Objects.toStringHelper(v).add("id", v.getId());
    if (v.getId() != -1 && v.getResources() != null) {
        try {
            helper.add("res-name", v.getResources().getResourceEntryName(v.getId()));
        } catch (Resources.NotFoundException ignore) {
        // Do nothing.
        }
    }
    if (null != v.getContentDescription()) {
        helper.add("desc", v.getContentDescription());
    }
    switch(v.getVisibility()) {
        case View.GONE:
            helper.add("visibility", "GONE");
            break;
        case View.INVISIBLE:
            helper.add("visibility", "INVISIBLE");
            break;
        case View.VISIBLE:
            helper.add("visibility", "VISIBLE");
            break;
        default:
            helper.add("visibility", v.getVisibility());
    }
    helper.add("width", v.getWidth()).add("height", v.getHeight()).add("has-focus", v.hasFocus()).add("has-focusable", v.hasFocusable()).add("has-window-focus", v.hasWindowFocus()).add("is-clickable", v.isClickable()).add("is-enabled", v.isEnabled()).add("is-focused", v.isFocused()).add("is-focusable", v.isFocusable()).add("is-layout-requested", v.isLayoutRequested()).add("is-selected", v.isSelected());
    if (null != v.getRootView()) {
        // pretty much only true in unit-tests.
        helper.add("root-is-layout-requested", v.getRootView().isLayoutRequested());
    }
    EditorInfo ei = new EditorInfo();
    InputConnection ic = v.onCreateInputConnection(ei);
    boolean hasInputConnection = ic != null;
    helper.add("has-input-connection", hasInputConnection);
    if (hasInputConnection) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        Printer p = new StringBuilderPrinter(sb);
        ei.dump(p, "");
        sb.append("]");
        helper.add("editor-info", sb.toString().replace("\n", " "));
    }
    if (Build.VERSION.SDK_INT > 10) {
        helper.add("x", v.getX()).add("y", v.getY());
    }
    if (v instanceof TextView) {
        innerDescribe((TextView) v, helper);
    }
    if (v instanceof Checkable) {
        innerDescribe((Checkable) v, helper);
    }
    if (v instanceof ViewGroup) {
        innerDescribe((ViewGroup) v, helper);
    }
    return helper.toString();
}
Also used : InputConnection(android.view.inputmethod.InputConnection) EditorInfo(android.view.inputmethod.EditorInfo) ViewGroup(android.view.ViewGroup) StringBuilderPrinter(android.util.StringBuilderPrinter) TextView(android.widget.TextView) Resources(android.content.res.Resources) Checkable(android.widget.Checkable) Printer(android.util.Printer) StringBuilderPrinter(android.util.StringBuilderPrinter) ToStringHelper(com.google.common.base.Objects.ToStringHelper)

Aggregations

Checkable (android.widget.Checkable)80 View (android.view.View)47 TextView (android.widget.TextView)18 ViewGroup (android.view.ViewGroup)9 OnClickListener (android.view.View.OnClickListener)7 ImageView (android.widget.ImageView)7 Switch (android.widget.Switch)7 ResourceReference (com.android.ide.common.rendering.api.ResourceReference)6 Resources (android.content.res.Resources)5 Paint (android.graphics.Paint)5 Point (android.graphics.Point)4 SuppressLint (android.annotation.SuppressLint)3 AdapterView (android.widget.AdapterView)3 CheckBox (android.widget.CheckBox)3 ListView (android.widget.ListView)3 Spinner (android.widget.Spinner)3 Map (java.util.Map)3 Switch (org.holoeverywhere.widget.Switch)3 SimpleArrayMap (android.support.v4.util.SimpleArrayMap)2 AlertDialog (android.support.v7.app.AlertDialog)2