use of com.willowtreeapps.hyperion.attr.ViewAttribute in project Hyperion-Android by willowtreeapps.
the class Collectors method createMenuAttributes.
public static Collection<ViewAttribute> createMenuAttributes(@NonNull Context context, @NonNull Menu menu) {
final Resources res = context.getResources();
List<ViewAttribute> attributes = new ArrayList<>();
attributes.add(new ViewAttribute<>("MenuSize", menu.size()));
attributes.add(new ViewAttribute<>("MenuHasVisibleItems", menu.hasVisibleItems()));
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
String prefix = "Item " + i + ": ";
attributes.add(new ViewAttribute<>(prefix + "Title", item.getTitle()));
attributes.add(new ViewAttribute<>(prefix + "ContentDescription", MenuItemCompat.getContentDescription(item)));
attributes.add(new ViewAttribute<>(prefix + "TooltipText", MenuItemCompat.getTooltipText(item)));
attributes.add(new ViewAttribute<>(prefix + "Checkable", item.isCheckable()));
attributes.add(new ViewAttribute<>(prefix + "Checked", item.isChecked()));
attributes.add(new ViewAttribute<>(prefix + "Enabled", item.isEnabled()));
attributes.add(new ViewAttribute<>(prefix + "Visible", item.isVisible()));
attributes.add(new ViewAttribute<>(prefix + "Order", item.getOrder()));
attributes.add(new ViewAttribute<Void>(prefix + "Icon", item.getIcon()));
attributes.add(createColorAttribute("IconTint", MenuItemCompat.getIconTintList(item)));
attributes.add(new ViewAttribute<>("IconTintMode", new PorterDuffModeValue(MenuItemCompat.getIconTintMode(item))));
attributes.add(new ViewAttribute<>(prefix + "Id", new ResourceValue(res, item.getItemId())));
attributes.add(new ViewAttribute<>(prefix + "GroupId", new ResourceValue(res, item.getGroupId())));
}
return attributes;
}
use of com.willowtreeapps.hyperion.attr.ViewAttribute in project Hyperion-Android by willowtreeapps.
the class Collectors method createColorAttribute.
public static ViewAttribute<ColorValue> createColorAttribute(@Nullable View view, @NonNull String name, @Nullable ColorStateList color) {
int tintColorInt;
if (color == null) {
tintColorInt = 0x000;
} else {
int[] state = view == null ? new int[] {} : view.getDrawableState();
tintColorInt = color.getColorForState(state, color.getDefaultColor());
}
return new ViewAttribute<>(name, new ColorValue(tintColorInt), new ColorDrawable(tintColorInt));
}
use of com.willowtreeapps.hyperion.attr.ViewAttribute in project Hyperion-Android by willowtreeapps.
the class ViewAttributeCollector method collect.
@NonNull
@Override
public List<ViewAttribute> collect(final View view, AttributeTranslator attributeTranslator) {
List<ViewAttribute> attributes = new ArrayList<>();
Rect rect = new Rect();
String value;
attributes.add(new ViewAttribute<>("Id", new ResourceValue(view.getResources(), view.getId())));
value = attributeTranslator.translatePx(view.getHeight());
attributes.add(new ViewAttribute<>("Height", value));
value = attributeTranslator.translatePx(view.getWidth());
attributes.add(new ViewAttribute<>("Width", value));
attributes.add(new ViewAttribute<>("Baseline", view.getBaseline()));
view.getGlobalVisibleRect(rect);
attributes.add(new ViewAttribute<>("GlobalLeft", String.valueOf(rect.left)));
attributes.add(new ViewAttribute<>("GlobalTop", String.valueOf(rect.top)));
attributes.add(new ViewAttribute<>("GlobalRight", String.valueOf(rect.right)));
attributes.add(new ViewAttribute<>("GlobalBottom", String.valueOf(rect.bottom)));
view.getLocalVisibleRect(rect);
attributes.add(new ViewAttribute<>("LocalLeft", String.valueOf(rect.left)));
attributes.add(new ViewAttribute<>("LocalTop", String.valueOf(rect.top)));
attributes.add(new ViewAttribute<>("LocalRight", String.valueOf(rect.right)));
attributes.add(new ViewAttribute<>("LocalBottom", String.valueOf(rect.bottom)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
attributes.add(new ViewAttribute<>("InLayout", view.isInLayout()));
}
attributes.add(new MutableBooleanViewAttribute("Clickable", view.isClickable()) {
@Override
protected void mutate(Boolean value) {
view.setClickable(value);
}
});
attributes.add(new MutableBooleanViewAttribute("LongClickable", view.isLongClickable()) {
@Override
protected void mutate(Boolean value) {
view.setLongClickable(value);
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
attributes.add(new ViewAttribute<>("ContextClickable", view.isContextClickable()));
}
attributes.add(new MutableBooleanViewAttribute("Enabled", view.isEnabled()) {
@Override
protected void mutate(Boolean value) {
view.setEnabled(value);
}
});
attributes.add(new MutableBooleanViewAttribute("Activated", view.isActivated()) {
@Override
protected void mutate(Boolean value) {
view.setActivated(value);
}
});
attributes.add(new MutableBooleanViewAttribute("Selected", view.isSelected()) {
@Override
protected void mutate(Boolean value) {
view.setSelected(value);
}
});
attributes.add(new ViewAttribute<>("AttachedToWindow", ViewCompat.isAttachedToWindow(view)));
attributes.add(new ViewAttribute<>("Dirty", view.isDirty()));
attributes.add(new MutableBooleanViewAttribute("IsFocusable", view.isFocusable()) {
@Override
protected void mutate(Boolean value) {
view.setFocusable(value);
}
});
attributes.add(new MutableBooleanViewAttribute("IsFocusableInTouchMode", view.isFocusableInTouchMode()) {
@Override
protected void mutate(Boolean value) {
view.setFocusableInTouchMode(value);
}
});
attributes.add(new ViewAttribute<>("HasFocus", view.hasFocus()));
attributes.add(new ViewAttribute<>("HasFocusable", view.hasFocusable()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
attributes.add(new ViewAttribute<>("HasTransientState", view.hasTransientState()));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
attributes.add(new ViewAttribute<>("ForegroundGravity", new GravityValue(view.getForegroundGravity())));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
attributes.add(new MutableStringViewAttribute("TransitionName", view.getTransitionName()) {
@Override
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
protected void mutate(CharSequence value) {
view.setTransitionName(value.toString());
}
});
attributes.add(new ViewAttribute<>("Elevation", view.getElevation()));
}
attributes.add(new ViewAttribute<>("BackgroundTintMode", new PorterDuffModeValue(ViewCompat.getBackgroundTintMode(view))));
attributes.add(Collectors.createColorAttribute(view, "BackgroundTint", ViewCompat.getBackgroundTintList(view)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
attributes.add(new ViewAttribute<>("AccessibilityClassName", view.getAccessibilityClassName()));
}
return attributes;
}
use of com.willowtreeapps.hyperion.attr.ViewAttribute in project Hyperion-Android by willowtreeapps.
the class ViewGroupAttributeCollector method collect.
@NonNull
@Override
public List<ViewAttribute> collect(final ViewGroup view, AttributeTranslator attributeTranslator) {
List<ViewAttribute> attributes = new ArrayList<>();
attributes.add(new ViewAttribute<>("ChildCount", view.getChildCount()));
attributes.add(new MutableBooleanViewAttribute("MotionEventSplittingEnabled", view.isMotionEventSplittingEnabled()) {
@Override
protected void mutate(Boolean value) {
view.setMotionEventSplittingEnabled(value);
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
attributes.add(new ViewAttribute<>("LayoutMode", new LayoutModeValue(view.getLayoutMode())));
attributes.add(new MutableBooleanViewAttribute("ClipChildren", view.getClipChildren()) {
@Override
protected void mutate(Boolean value) {
view.setClipChildren(value);
}
});
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
attributes.add(new MutableBooleanViewAttribute("ClipToPadding", view.getClipToPadding()) {
@Override
protected void mutate(Boolean value) {
view.setClipToPadding(value);
}
});
attributes.add(new ViewAttribute<>("TouchscreenBlocksFocus", view.getTouchscreenBlocksFocus()));
attributes.add(new MutableBooleanViewAttribute("IsTransitionGroup", view.isTransitionGroup()) {
@Override
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
protected void mutate(Boolean value) {
view.setTransitionGroup(value);
}
});
}
attributes.add(new ViewAttribute<>("DelayChildPressed", view.shouldDelayChildPressedState()));
return attributes;
}
use of com.willowtreeapps.hyperion.attr.ViewAttribute in project Hyperion-Android by willowtreeapps.
the class ImageViewAttributeCollector method collect.
@NonNull
@Override
public List<ViewAttribute> collect(ImageView view, AttributeTranslator attributeTranslator) {
List<ViewAttribute> attributes = new ArrayList<>();
attributes.add(new ViewAttribute("Image", view.getDrawable()));
attributes.add(new ViewAttribute<>("ScaleType", view.getScaleType().toString()));
return attributes;
}
Aggregations