Search in sources :

Example 6 with MutableBooleanViewAttribute

use of com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute 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;
}
Also used : ArrayList(java.util.ArrayList) MutableStringViewAttribute(com.willowtreeapps.hyperion.attr.MutableStringViewAttribute) ViewAttribute(com.willowtreeapps.hyperion.attr.ViewAttribute) MutableBooleanViewAttribute(com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute) MutableStringViewAttribute(com.willowtreeapps.hyperion.attr.MutableStringViewAttribute) MutableBooleanViewAttribute(com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute) TargetApi(android.annotation.TargetApi) NonNull(android.support.annotation.NonNull)

Example 7 with MutableBooleanViewAttribute

use of com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute in project Hyperion-Android by willowtreeapps.

the class CompoundButtonAttributeCollector method collect.

@NonNull
@Override
public List<ViewAttribute> collect(final CompoundButton view, AttributeTranslator attributeTranslator) {
    List<ViewAttribute> attributes = new ArrayList<>();
    attributes.add(new MutableBooleanViewAttribute("Checked", view.isChecked()) {

        @Override
        protected void mutate(Boolean value) {
            view.setChecked(value);
        }
    });
    attributes.add(new ViewAttribute<Void>("ButtonDrawable", CompoundButtonCompat.getButtonDrawable(view)));
    return attributes;
}
Also used : ArrayList(java.util.ArrayList) MutableBooleanViewAttribute(com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute) ViewAttribute(com.willowtreeapps.hyperion.attr.ViewAttribute) MutableBooleanViewAttribute(com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute) NonNull(android.support.annotation.NonNull)

Aggregations

NonNull (android.support.annotation.NonNull)7 MutableBooleanViewAttribute (com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute)7 ViewAttribute (com.willowtreeapps.hyperion.attr.ViewAttribute)7 ArrayList (java.util.ArrayList)7 MutableStringViewAttribute (com.willowtreeapps.hyperion.attr.MutableStringViewAttribute)3 RequiresApi (android.support.annotation.RequiresApi)2 TargetApi (android.annotation.TargetApi)1 Rect (android.graphics.Rect)1