use of com.willowtreeapps.hyperion.attr.MutableStringViewAttribute 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.MutableStringViewAttribute in project Hyperion-Android by willowtreeapps.
the class TextViewAttributeCollector method collect.
@NonNull
@Override
public List<ViewAttribute> collect(final TextView view, AttributeTranslator attributeTranslator) {
List<ViewAttribute> attributes = new ArrayList<>();
attributes.add(new MutableStringViewAttribute("Text", view.getText().toString()) {
@Override
protected void mutate(CharSequence value) {
view.setText(value);
}
});
attributes.add(new MutableStringViewAttribute("Hint", view.getHint()) {
@Override
protected void mutate(CharSequence value) {
view.setHint(value);
}
});
attributes.add(new ViewAttribute<>("TextColor", new ColorValue(view.getCurrentTextColor()), new ColorDrawable(view.getCurrentTextColor())));
attributes.add(new ViewAttribute<>("HintColor", new ColorValue(view.getCurrentHintTextColor()), new ColorDrawable(view.getCurrentHintTextColor())));
attributes.add(new ViewAttribute<>("Typeface", view.getTypeface()));
attributes.add(new ViewAttribute<>("TextSize", attributeTranslator.translatePxToSp((int) view.getTextSize())));
attributes.add(new ViewAttribute<>("AutoSizeMaxTextSize", TextViewCompat.getAutoSizeMaxTextSize(view)));
attributes.add(new ViewAttribute<>("AutoSizeMinTextSize", TextViewCompat.getAutoSizeMinTextSize(view)));
attributes.add(new ViewAttribute<>("AutoSizeStepGranularity", TextViewCompat.getAutoSizeStepGranularity(view)));
attributes.add(new ViewAttribute<>("Gravity", new GravityValue(view.getGravity())));
attributes.add(new ViewAttribute<>("ImeAction", view.getImeActionId()));
attributes.add(new ViewAttribute<>("ImeActionLabel", view.getImeActionLabel()));
attributes.add(new ViewAttribute<>("ImeOptions", new ImeOptionsValue(view.getImeOptions())));
attributes.add(new ViewAttribute<>("CompoundPaddingLeft", attributeTranslator.translatePx(view.getCompoundPaddingLeft())));
attributes.add(new ViewAttribute<>("CompoundPaddingTop", attributeTranslator.translatePx(view.getCompoundPaddingTop())));
attributes.add(new ViewAttribute<>("CompoundPaddingRight", attributeTranslator.translatePx(view.getCompoundPaddingRight())));
attributes.add(new ViewAttribute<>("CompoundPaddingBottom", attributeTranslator.translatePx(view.getCompoundPaddingBottom())));
attributes.add(new ViewAttribute<>("CompoundDrawable", attributeTranslator.translatePx(view.getCompoundDrawablePadding())));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
attributes.add(Collectors.createColorAttribute(view, "CompoundDrawableTint", view.getCompoundDrawableTintList()));
attributes.add(new ViewAttribute<>("CompoundDrawableTintMode", new PorterDuffModeValue(view.getCompoundDrawableTintMode())));
}
return attributes;
}
use of com.willowtreeapps.hyperion.attr.MutableStringViewAttribute in project Hyperion-Android by willowtreeapps.
the class LinearLayoutAttributeCollector method collect.
@NonNull
@Override
public List<ViewAttribute> collect(final LinearLayout view, AttributeTranslator attributeTranslator) {
List<ViewAttribute> attributes = new ArrayList<>();
attributes.add(new ViewAttribute<>("Orientation", new OrientationValue(view.getOrientation())));
attributes.add(new ViewAttribute<>("WeightSum", view.getWeightSum()));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
attributes.add(new ViewAttribute<>("Gravity", new GravityValue(view.getGravity())));
}
attributes.add(new ViewAttribute<>("ShowDividers", new DividerModeValue(view.getShowDividers())));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
attributes.add(new ViewAttribute<Void>("Divider", view.getDividerDrawable()));
}
attributes.add(new ViewAttribute<>("DividerPadding", attributeTranslator.translatePx(view.getDividerPadding())));
attributes.add(new MutableBooleanViewAttribute("MeasureWithLargestChild", view.isMeasureWithLargestChildEnabled()) {
@Override
protected void mutate(Boolean value) throws Exception {
view.setMeasureWithLargestChildEnabled(value);
}
});
attributes.add(new MutableBooleanViewAttribute("BaselineAligned", view.isBaselineAligned()) {
@Override
protected void mutate(Boolean value) throws Exception {
view.setBaselineAligned(value);
}
});
attributes.add(new MutableStringViewAttribute("BaselineAlignedChildIndex", String.valueOf(view.getBaselineAlignedChildIndex())) {
@Override
protected void mutate(CharSequence value) throws Exception {
int index = Integer.parseInt(value.toString());
view.setBaselineAlignedChildIndex(index);
}
});
return attributes;
}
use of com.willowtreeapps.hyperion.attr.MutableStringViewAttribute in project Hyperion-Android by willowtreeapps.
the class SwitchAttributeCollector method collect.
@NonNull
@Override
public List<ViewAttribute> collect(final Switch view, AttributeTranslator attributeTranslator) {
List<ViewAttribute> attributes = new ArrayList<>();
attributes.add(new MutableStringViewAttribute("TextOn", view.getTextOn()) {
@Override
protected void mutate(CharSequence value) {
view.setTextOn(value);
}
});
attributes.add(new MutableStringViewAttribute("TextOff", view.getTextOff()) {
@Override
protected void mutate(CharSequence value) {
view.setTextOff(value);
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
attributes.add(new MutableBooleanViewAttribute("ShowText", view.getShowText()) {
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void mutate(Boolean value) {
view.setShowText(value);
}
});
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
attributes.add(new ViewAttribute<>("SwitchPadding", attributeTranslator.translatePx(view.getSwitchPadding())));
attributes.add(new ViewAttribute<>("SwitchMinWidth", attributeTranslator.translatePx(view.getSwitchMinWidth())));
attributes.add(new ViewAttribute<>("ThumbTextPadding", attributeTranslator.translatePx(view.getThumbTextPadding())));
attributes.add(new ViewAttribute<Void>("ThumbDrawable", view.getThumbDrawable()));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
attributes.add(Collectors.createColorAttribute(view, "ThumbTint", view.getThumbTintList()));
attributes.add(new ViewAttribute<>("ThumbTintMode", new PorterDuffModeValue(view.getThumbTintMode())));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
attributes.add(new ViewAttribute<Void>("TrackDrawable", view.getTrackDrawable()));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
attributes.add(Collectors.createColorAttribute(view, "TrackTint", view.getTrackTintList()));
attributes.add(new ViewAttribute<>("TrackTintMode", new PorterDuffModeValue(view.getTrackTintMode())));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
attributes.add(new MutableBooleanViewAttribute("SplitTrack", view.getSplitTrack()) {
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected void mutate(Boolean value) {
view.setSplitTrack(value);
}
});
}
return attributes;
}
Aggregations