diff --git a/anvil-appcompat-v7/src/main/java/trikita/anvil/appcompat/v7/BaseAppCompat.java b/anvil-appcompat-v7/src/main/java/trikita/anvil/appcompat/v7/BaseAppCompat.java new file mode 100644 index 00000000..eb5d12ee --- /dev/null +++ b/anvil-appcompat-v7/src/main/java/trikita/anvil/appcompat/v7/BaseAppCompat.java @@ -0,0 +1,27 @@ +package trikita.anvil.appcompat.v7; + +import android.support.v7.widget.Toolbar; +import android.view.View; +import trikita.anvil.Anvil; + +public class BaseAppCompat implements Anvil.AttributeSetter { + + static { + Anvil.registerAttributeSetter(new BaseAppCompat()); + } + + @Override + public boolean set(View v, String name, Object value, Object prevValue) { + switch (name) { + case "layoutGravity": + if (v.getLayoutParams() instanceof Toolbar.LayoutParams && value instanceof Integer) { + ((Toolbar.LayoutParams) v.getLayoutParams()).gravity = (int) value; + return true; + } + break; + } + + return false; + } + +} diff --git a/anvil-design/src/main/java/trikita/anvil/design/BaseDesign.java b/anvil-design/src/main/java/trikita/anvil/design/BaseDesign.java new file mode 100644 index 00000000..07eea548 --- /dev/null +++ b/anvil-design/src/main/java/trikita/anvil/design/BaseDesign.java @@ -0,0 +1,56 @@ +package trikita.anvil.design; + +import static trikita.anvil.BaseDSL.attr; + +import android.support.design.widget.AppBarLayout; +import android.support.design.widget.CollapsingToolbarLayout; +import android.support.design.widget.CoordinatorLayout; +import android.view.View; +import trikita.anvil.Anvil; + +public class BaseDesign implements Anvil.AttributeSetter { + + static { + Anvil.registerAttributeSetter(new BaseDesign()); + } + + public static Void collapseMode(int collapseMode) { + return attr("collapseMode", collapseMode); + } + + public static Void scrollFlags(int collapseMode) { + return attr("scrollFlags", collapseMode); + } + + public static Void behavior(CoordinatorLayout.Behavior behavior) { + return attr("behavior", behavior); + } + + @Override + public boolean set(View v, String name, Object value, Object prevValue) { + switch (name) { + + case "collapseMode": + if (v.getLayoutParams() instanceof CollapsingToolbarLayout.LayoutParams && value instanceof Integer) { + ((CollapsingToolbarLayout.LayoutParams) v.getLayoutParams()).setCollapseMode((int) value); + return true; + } + break; + case "scrollFlags": + if (v.getLayoutParams() instanceof AppBarLayout.LayoutParams && value instanceof Integer) { + ((AppBarLayout.LayoutParams) v.getLayoutParams()).setScrollFlags((int) value); + return true; + } + break; + case "behavior": + if (v.getLayoutParams() instanceof CoordinatorLayout.LayoutParams && (value == null || value instanceof CoordinatorLayout.Behavior)) { + ((CoordinatorLayout.LayoutParams) v.getLayoutParams()).setBehavior((CoordinatorLayout.Behavior) value); + return true; + } + break; + } + + return false; + } + +}