Search in sources :

Example 11 with ViewAttribute

use of com.willowtreeapps.hyperion.attr.ViewAttribute 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 12 with ViewAttribute

use of com.willowtreeapps.hyperion.attr.ViewAttribute 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

ViewAttribute (com.willowtreeapps.hyperion.attr.ViewAttribute)12 ArrayList (java.util.ArrayList)11 NonNull (android.support.annotation.NonNull)10 MutableBooleanViewAttribute (com.willowtreeapps.hyperion.attr.MutableBooleanViewAttribute)7 MutableStringViewAttribute (com.willowtreeapps.hyperion.attr.MutableStringViewAttribute)4 Resources (android.content.res.Resources)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 RequiresApi (android.support.annotation.RequiresApi)2 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 Rect (android.graphics.Rect)1 MenuItem (android.view.MenuItem)1 ResourceValue (com.willowtreeapps.hyperion.attr.collectors.ResourceValue)1