Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App compat setters #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}

}
56 changes: 56 additions & 0 deletions anvil-design/src/main/java/trikita/anvil/design/BaseDesign.java
Original file line number Diff line number Diff line change
@@ -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;
}

}