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");
}
}
}
}
}
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);
}
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;
}
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));
}
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();
}
Aggregations