From 8257b975e961c7ec35ca6c6a2ebf6e76908790d5 Mon Sep 17 00:00:00 2001 From: Sergey Grekov Date: Tue, 2 Apr 2019 01:09:08 +0300 Subject: [PATCH 1/2] constraint layout dsl --- anvil-constraintlayout/attr-quirks.gradle | 3 + anvil-constraintlayout/build.gradle | 148 ++++++ anvil-constraintlayout/gradle.properties | 4 + .../src/main/AndroidManifest.xml | 2 + .../constraint/layout/CircleConstraint.java | 38 ++ .../constraint/layout/ConstraintChain.java | 52 ++ .../constraint/layout/ConstraintDSL.java | 479 ++++++++++++++++++ .../constraint/layout/ConstraintSide.java | 38 ++ settings.gradle | 1 + 9 files changed, 765 insertions(+) create mode 100644 anvil-constraintlayout/attr-quirks.gradle create mode 100644 anvil-constraintlayout/build.gradle create mode 100644 anvil-constraintlayout/gradle.properties create mode 100644 anvil-constraintlayout/src/main/AndroidManifest.xml create mode 100644 anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/CircleConstraint.java create mode 100644 anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintChain.java create mode 100644 anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintDSL.java create mode 100644 anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintSide.java diff --git a/anvil-constraintlayout/attr-quirks.gradle b/anvil-constraintlayout/attr-quirks.gradle new file mode 100644 index 00000000..b3937369 --- /dev/null +++ b/anvil-constraintlayout/attr-quirks.gradle @@ -0,0 +1,3 @@ +def nop = { builder -> null } + +ext.QUIRKS = [:] \ No newline at end of file diff --git a/anvil-constraintlayout/build.gradle b/anvil-constraintlayout/build.gradle new file mode 100644 index 00000000..ad37f424 --- /dev/null +++ b/anvil-constraintlayout/build.gradle @@ -0,0 +1,148 @@ +buildscript { + dependencies { + classpath "com.android.tools.build:gradle:$agp_version" + classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.5' + } +} + +apply plugin: 'com.android.library' +apply plugin: 'trikita.anvilgen' +apply from: "$rootProject.projectDir/copyDeps.gradle" + +android { + compileSdkVersion 27 + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 + } + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 27 + + missingDimensionStrategy 'api', 'sdk15' + } + + lintOptions { + abortOnError false + } + + testOptions { + unitTests.returnDefaultValues = true + } +} + +apply from: 'attr-quirks.gradle' +anvilgen { + type = "support" + libraryName = "constraint-layout" + camelCaseName = "Constraint" + version = "1.1.3" + dependencies = [ + "com.android.support.constraint-constraint-layout-solver" : null + ] + quirks = QUIRKS +} + +dependencies { + implementation project(path: ':anvil') + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + + testImplementation 'junit:junit:4.12' + testImplementation "org.mockito:mockito-core:$mockito_version" +} + +apply plugin: 'maven-publish' +apply plugin: 'com.jfrog.bintray' + +def fixPom(pom) { + pom.withXml { + def root = asNode() + root.appendNode('description', POM_DESCRIPTION) + root.appendNode('name', POM_NAME) + root.appendNode('url', POM_URL) + def scm = root.appendNode('scm') + scm.appendNode('url', POM_SCM_URL) + scm.appendNode('connection', POM_SCM_CONNECTION) + scm.appendNode('developerConnection', POM_SCM_DEV_CONNECTION) + def developer = root.appendNode('developers').appendNode('developer') + developer.appendNode('id', POM_DEVELOPER_ID) + developer.appendNode('name', POM_DEVELOPER_NAME) + developer.appendNode('email', POM_DEVELOPER_EMAIL) + def license = root.appendNode('licenses').appendNode('license') + license.appendNode('name', POM_LICENCE_NAME) + license.appendNode('url', POM_LICENCE_URL) + license.appendNode('distribution', POM_LICENCE_DIST) + } +} + +publishing { + publications { + design(MavenPublication) { + groupId project.group + version project.version + artifactId POM_ARTIFACT_ID + artifact "$buildDir/outputs/aar/$POM_ARTIFACT_ID-release.aar" + artifact sourcesJar + artifact javadocJar + fixPom(pom) + } + } +} + +bintray { + user = project.hasProperty('bintrayUser') ? bintrayUser : '' + key = project.hasProperty('bintrayApiKey') ? bintrayApiKey : '' + publications = ['design'] + pkg { + repo = 'maven' + name = POM_PACKAGE_NAME + websiteUrl = POM_URL + vcsUrl = POM_SCM_URL + licenses = [POM_LICENCE_SHORT_NAME] + publish = true + version { + name = project.version + gpg { + sign = true + passphrase = project.hasProperty('bintrayGpgPassword') ? bintrayGpgPassword : '' + } + mavenCentralSync { + sync = true + user = project.hasProperty('bintrayOssUser') ? bintrayOssUser : '' + password = project.hasProperty('bintrayOssPassword') ? bintrayOssPassword : '' + close = '1' + } + } + } +} + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' +} + +task javadoc(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +artifacts { + archives javadocJar + archives sourcesJar +} + +android.libraryVariants.all { variant -> + task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) { + description "Generates Javadoc for $variant.name." + source = variant.getCompileClasspath(null).getAsFileTree() + ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar" + classpath = files(variant.getCompileClasspath(null)) + files(ext.androidJar) + } +} diff --git a/anvil-constraintlayout/gradle.properties b/anvil-constraintlayout/gradle.properties new file mode 100644 index 00000000..370ee25b --- /dev/null +++ b/anvil-constraintlayout/gradle.properties @@ -0,0 +1,4 @@ +POM_ARTIFACT_ID=anvil-constraintlayout +POM_PACKAGE_NAME=anvil +POM_NAME=Anvil (Constraint Layout) +POM_PACKAGING=aar diff --git a/anvil-constraintlayout/src/main/AndroidManifest.xml b/anvil-constraintlayout/src/main/AndroidManifest.xml new file mode 100644 index 00000000..b260c0ba --- /dev/null +++ b/anvil-constraintlayout/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + + diff --git a/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/CircleConstraint.java b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/CircleConstraint.java new file mode 100644 index 00000000..87ccc55c --- /dev/null +++ b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/CircleConstraint.java @@ -0,0 +1,38 @@ +package trikita.anvil.constraint.layout; + +final class CircleConstraint { + public int centerId; + public final int id; + public final int angle; + public final int radius; + + public CircleConstraint(int centerId, int id, int angle, int radius) { + this.centerId = centerId; + this.id = id; + this.angle = angle; + this.radius = radius; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CircleConstraint that = (CircleConstraint) o; + + if (centerId != that.centerId) return false; + if (id != that.id) return false; + if (angle != that.angle) return false; + return radius == that.radius; + + } + + @Override + public int hashCode() { + int result = centerId; + result = 31 * result + id; + result = 31 * result + angle; + result = 31 * result + radius; + return result; + } +} \ No newline at end of file diff --git a/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintChain.java b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintChain.java new file mode 100644 index 00000000..55444e2d --- /dev/null +++ b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintChain.java @@ -0,0 +1,52 @@ +package trikita.anvil.constraint.layout; + +import java.util.Arrays; + +final class ConstraintChain { + public final int leftId; + public final int leftSide; + public final int rightId; + public final int rightSide; + public final int[] chainIds; + public final float[] weights; + public final int style; + + public ConstraintChain(int leftId, int leftSide, int rightId, int rightSide, int[] chainIds, float[] weights, int style) { + this.leftId = leftId; + this.leftSide = leftSide; + this.rightId = rightId; + this.rightSide = rightSide; + this.chainIds = chainIds; + this.weights = weights; + this.style = style; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ConstraintChain chain = (ConstraintChain) o; + + if (leftId != chain.leftId) return false; + if (leftSide != chain.leftSide) return false; + if (rightId != chain.rightId) return false; + if (rightSide != chain.rightSide) return false; + if (style != chain.style) return false; + if (!Arrays.equals(chainIds, chain.chainIds)) return false; + return Arrays.equals(weights, chain.weights); + + } + + @Override + public int hashCode() { + int result = leftId; + result = 31 * result + leftSide; + result = 31 * result + rightId; + result = 31 * result + rightSide; + result = 31 * result + Arrays.hashCode(chainIds); + result = 31 * result + Arrays.hashCode(weights); + result = 31 * result + style; + return result; + } +} diff --git a/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintDSL.java b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintDSL.java new file mode 100644 index 00000000..3622f892 --- /dev/null +++ b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintDSL.java @@ -0,0 +1,479 @@ +package trikita.anvil.constraint.layout; + +import android.support.constraint.Barrier; +import android.support.constraint.ConstraintLayout; +import android.support.constraint.ConstraintSet; +import android.support.constraint.Group; +import android.support.constraint.Guideline; +import android.support.constraint.Placeholder; +import android.view.View; + +import java.util.LinkedList; + +import trikita.anvil.Anvil; +import trikita.anvil.BaseDSL; + +/** + * DSL for creating views and settings their attributes. + * It contains views and their setters from the library constraint-layout. + */ +public final class ConstraintDSL implements Anvil.AttributeSetter { + static { + Anvil.registerAttributeSetter(new ConstraintDSL()); + } + + public static BaseDSL.ViewClassResult constraintLayout() { + return BaseDSL.v(ConstraintLayout.class); + } + + public static Void constraintLayout(Anvil.Renderable r) { + return BaseDSL.v(ConstraintLayout.class, r); + } + + public static BaseDSL.ViewClassResult barrier() { + return BaseDSL.v(Barrier.class); + } + + public static Void barrier(Anvil.Renderable r) { + return BaseDSL.v(Barrier.class, r); + } + + public static BaseDSL.ViewClassResult placeholder() { + return BaseDSL.v(Placeholder.class); + } + + public static Void placeholder(Anvil.Renderable r) { + return BaseDSL.v(Placeholder.class, r); + } + + public static BaseDSL.ViewClassResult group() { + return BaseDSL.v(Group.class); + } + + public static Void group(Anvil.Renderable r) { + return BaseDSL.v(Group.class, r); + } + + public static BaseDSL.ViewClassResult guideline() { + return BaseDSL.v(Guideline.class); + } + + public static Void guideline(Anvil.Renderable r) { + return BaseDSL.v(Guideline.class, r); + } + + public static Void type(int arg) { + return BaseDSL.attr("type", arg); + } + + public static Void referencedIds(int[] arg) { + return BaseDSL.attr("referencedIds", arg); + } + + public static Void leftConstraintToLeft(int toId) { + return BaseDSL.attr("leftConstraintToLeft", toId); + } + + public static Void leftConstraintToRight(int toId) { + return BaseDSL.attr("leftConstraintToRight", toId); + } + + public static Void leftConstraintToTop(int toId) { + return BaseDSL.attr("leftConstraintToTop", toId); + } + + public static Void leftConstraintToBottom(int toId) { + return BaseDSL.attr("leftConstraintToBottom", toId); + } + + public static Void leftConstraintToParent() { + return leftConstraintToLeft(ConstraintSet.PARENT_ID); + } + + public static Void rightConstraintToRight(int toId) { + return BaseDSL.attr("rightConstraintToRight", toId); + } + + public static Void rightConstraintToLeft(int toId) { + return BaseDSL.attr("rightConstraintToLeft", toId); + } + + public static Void rightConstraintToTop(int toId) { + return BaseDSL.attr("rightConstraintToTop", toId); + } + + public static Void rightConstraintToBottom(int toId) { + return BaseDSL.attr("rightConstraintToBottom", toId); + } + + public static Void rightConstraintToParent() { + return rightConstraintToRight(ConstraintSet.PARENT_ID); + } + + public static Void topConstraintToRight(int toId) { + return BaseDSL.attr("topConstraintToRight", toId); + } + + public static Void topConstraintToLeft(int toId) { + return BaseDSL.attr("topConstraintToLeft", toId); + } + + public static Void topConstraintToTop(int toId) { + return BaseDSL.attr("topConstraintToTop", toId); + } + + public static Void topConstraintToBottom(int toId) { + return BaseDSL.attr("topConstraintToBottom", toId); + } + + public static Void topConstraintToParent() { + return topConstraintToTop(ConstraintSet.PARENT_ID); + } + + public static Void bottomConstraintToRight(int toId) { + return BaseDSL.attr("bottomConstraintToRight", toId); + } + + public static Void bottomConstraintToLeft(int toId) { + return BaseDSL.attr("bottomConstraintToLeft", toId); + } + + public static Void bottomConstraintToTop(int toId) { + return BaseDSL.attr("bottomConstraintToTop", toId); + } + + public static Void bottomConstraintToBottom(int toId) { + return BaseDSL.attr("bottomConstraintToBottom", toId); + } + + public static Void bottomConstraintToParent() { + return bottomConstraintToBottom(ConstraintSet.PARENT_ID); + } + + public static Void chain(int leftId, int leftSide, int rightId, int rightSide, int[] chainIds, float[] weights, int style) { + return BaseDSL.attr("chain", new ConstraintChain(leftId, leftSide, rightId, rightSide, chainIds, weights, style)); + } + + public static Void circleConstraint(int id, int angle, int radius) { + return BaseDSL.attr("circleConstraint", new CircleConstraint(0, id, angle, radius)); + } + + public static Void id(int id) { + return BaseDSL.attr("idForConstraint", id); + } + + public static Void applyConstraints() { + return BaseDSL.attr("apply", true); + } + + public static Void orientation(int orientation) { + return BaseDSL.attr("orientation", orientation); + } + + public static Void guideBegin(int margin) { + return BaseDSL.attr("guideBegin", margin); + } + + public static Void guideEnd(int margin) { + return BaseDSL.attr("guideEnd", margin); + } + + public static Void guidelinePercent(float ratio) { + return BaseDSL.attr("guidelinePercent", ratio); + } + + public static Void contentId(int contentId) { + return BaseDSL.attr("contentId", contentId); + } + + public final int CONSTRAINTS_KEY = 1 + 2 << 24; + public final int CHAIN_KEY = 1 + 3 << 24; + public final int CIRCLE_KEY = 1 + 4 << 24; + + public boolean set(View v, String name, final Object arg, final Object old) { + switch (name) { + case "allowsGoneWidget": + if (v instanceof Barrier && arg instanceof Boolean) { + ((Barrier) v).setAllowsGoneWidget((boolean) arg); + return true; + } + break; + case "constraintSet": + if (v instanceof ConstraintLayout && arg instanceof ConstraintSet) { + ((ConstraintLayout) v).setConstraintSet((ConstraintSet) arg); + return true; + } + break; + case "leftConstraintToLeft": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.LEFT, (Integer) arg, ConstraintSet.LEFT); + return true; + } + break; + case "leftConstraintToRight": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.LEFT, (Integer) arg, ConstraintSet.RIGHT); + return true; + } + break; + case "leftConstraintToTop": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.LEFT, (Integer) arg, ConstraintSet.TOP); + return true; + } + break; + case "leftConstraintToBottom": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.LEFT, (Integer) arg, ConstraintSet.BOTTOM); + return true; + } + break; + case "rightConstraintToLeft": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.RIGHT, (Integer) arg, ConstraintSet.LEFT); + return true; + } + break; + case "rightConstraintToRight": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.RIGHT, (Integer) arg, ConstraintSet.RIGHT); + return true; + } + break; + case "rightConstraintToTop": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.RIGHT, (Integer) arg, ConstraintSet.TOP); + return true; + } + break; + case "rightConstraintToBottom": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.RIGHT, (Integer) arg, ConstraintSet.BOTTOM); + return true; + } + break; + case "topConstraintToLeft": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.TOP, (Integer) arg, ConstraintSet.LEFT); + return true; + } + break; + case "topConstraintToRight": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.TOP, (Integer) arg, ConstraintSet.RIGHT); + return true; + } + break; + case "topConstraintToTop": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.TOP, (Integer) arg, ConstraintSet.TOP); + return true; + } + break; + case "topConstraintToBottom": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.TOP, (Integer) arg, ConstraintSet.BOTTOM); + return true; + } + break; + case "bottomConstraintToLeft": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.BOTTOM, (Integer) arg, ConstraintSet.LEFT); + return true; + } + break; + case "bottomConstraintToRight": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.BOTTOM, (Integer) arg, ConstraintSet.RIGHT); + return true; + } + break; + case "bottomConstraintToTop": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.BOTTOM, (Integer) arg, ConstraintSet.TOP); + return true; + } + break; + case "bottomConstraintToBottom": + if (v.getParent() instanceof ConstraintLayout && arg instanceof Integer) { + addConstraint(((ConstraintLayout) v.getParent()), v.getId(), ConstraintSet.BOTTOM, (Integer) arg, ConstraintSet.BOTTOM); + return true; + } + break; + case "chain": + if (v.getParent() instanceof ConstraintLayout && arg instanceof ConstraintChain) { + ConstraintLayout cl = ((ConstraintLayout) v.getParent()); + LinkedList chainsList = (LinkedList) cl.getTag(CHAIN_KEY); + if (chainsList == null) { + chainsList = new LinkedList<>(); + } + chainsList.add((ConstraintChain) arg); + cl.setTag(CHAIN_KEY, chainsList); + return true; + } + break; + case "circleConstraint": + if (v.getParent() instanceof ConstraintLayout && arg instanceof CircleConstraint) { + ConstraintLayout cl = ((ConstraintLayout) v.getParent()); + LinkedList circlesList = (LinkedList) cl.getTag(CIRCLE_KEY); + if (circlesList == null) { + circlesList = new LinkedList<>(); + } + CircleConstraint arg2 = (CircleConstraint) arg; + arg2.centerId = v.getId(); + circlesList.add(arg2); + cl.setTag(CIRCLE_KEY, circlesList); + return true; + } + break; + case "apply": + if (v instanceof ConstraintLayout && arg instanceof Boolean) { + ConstraintLayout cl = ((ConstraintLayout) v); + LinkedList constraintSideList = (LinkedList) cl.getTag(CONSTRAINTS_KEY); + LinkedList chainsList = (LinkedList) cl.getTag(CHAIN_KEY); + LinkedList circlesList = (LinkedList) cl.getTag(CIRCLE_KEY); + + if ((constraintSideList == null || constraintSideList.size() == 0) + && (chainsList == null || chainsList.size() == 0) + && (circlesList == null || circlesList.size() == 0)) { + return false; + } + + ConstraintSet cs1 = new ConstraintSet(); + cs1.clone(cl); + + if (constraintSideList != null && constraintSideList.size() > 0) { + for (int i = 0; i < constraintSideList.size(); i++) { + ConstraintSide side = constraintSideList.get(i); + cs1.connect(side.startID, side.startSide, side.endID, side.endSide); + } + constraintSideList.clear(); + } + + if (chainsList != null && chainsList.size() > 0) { + for (int i = 0; i < chainsList.size(); i++) { + ConstraintChain chain = chainsList.get(i); + cs1.createHorizontalChain(chain.leftId, chain.leftSide, chain.rightId, chain.rightSide, chain.chainIds, chain.weights, chain.style); + } + chainsList.clear(); + } + + if (circlesList != null && circlesList.size() > 0) { + for (int i = 0; i < circlesList.size(); i++) { + CircleConstraint circleConstraint = circlesList.get(i); + cs1.constrainCircle(circleConstraint.id, circleConstraint.centerId, circleConstraint.radius, circleConstraint.angle); + } + circlesList.clear(); + } + + cs1.applyTo(cl); + return false; + } + break; + case "maxHeight": + if (v instanceof ConstraintLayout && arg instanceof Integer) { + ((ConstraintLayout) v).setMaxHeight((int) arg); + return true; + } + break; + case "maxWidth": + if (v instanceof ConstraintLayout && arg instanceof Integer) { + ((ConstraintLayout) v).setMaxWidth((int) arg); + return true; + } + break; + case "minHeight": + if (v instanceof ConstraintLayout && arg instanceof Integer) { + ((ConstraintLayout) v).setMinHeight((int) arg); + return true; + } + break; + case "minWidth": + if (v instanceof ConstraintLayout && arg instanceof Integer) { + ((ConstraintLayout) v).setMinWidth((int) arg); + return true; + } + break; + case "optimizationLevel": + if (v instanceof ConstraintLayout && arg instanceof Integer) { + ((ConstraintLayout) v).setOptimizationLevel((int) arg); + return true; + } + break; + case "referencedIds": + if (v instanceof Barrier && arg instanceof int[]) { + ((Barrier) v).setReferencedIds((int[]) arg); + return true; + } + if (v instanceof Group && arg instanceof int[]) { + ((Group) v).setReferencedIds((int[]) arg); + return true; + } + break; + case "type": + if (v instanceof Barrier && arg instanceof Integer) { + ((Barrier) v).setType((int) arg); + return true; + } + break; + case "idForConstraint": + if (arg instanceof Integer) { + v.setId((Integer) arg); + if (v.getParent() instanceof ConstraintLayout) { + ((ConstraintLayout) v.getParent()).onViewAdded(v); + } + return true; + } + break; + case "orientation": + if (v instanceof Guideline && arg instanceof Integer) { + ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) v.getLayoutParams(); + params.orientation = (Integer) arg; + v.setLayoutParams(params); + return true; + } + break; + case "guideBegin": + if (v instanceof Guideline && arg instanceof Integer) { + ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) v.getLayoutParams(); + params.guideBegin = (Integer) arg; + v.setLayoutParams(params); + return true; + } + break; + case "guideEnd": + if (v instanceof Guideline && arg instanceof Integer) { + ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) v.getLayoutParams(); + params.guideEnd = (Integer) arg; + v.setLayoutParams(params); + return true; + } + break; + case "guidelinePercent": + if (v instanceof Guideline && arg instanceof Float) { + ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) v.getLayoutParams(); + params.guidePercent = (Float) arg; + v.setLayoutParams(params); + return true; + } + break; + case "contentId": + if (v instanceof Placeholder && arg instanceof Integer) { + ((Placeholder) v).setContentId((int) arg); + return true; + } + break; + } + return false; + } + + private void addConstraint(ConstraintLayout cl, int fromId, int fromSide, int toId, int endSide) { + LinkedList constraintSideList = (LinkedList) cl.getTag(CONSTRAINTS_KEY); + if (constraintSideList == null) { + constraintSideList = new LinkedList<>(); + cl.setTag(CONSTRAINTS_KEY, constraintSideList); + } + constraintSideList.add( + new ConstraintSide(fromId, fromSide, toId, endSide)); + } +} diff --git a/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintSide.java b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintSide.java new file mode 100644 index 00000000..1c78aa33 --- /dev/null +++ b/anvil-constraintlayout/src/main/java/trikita/anvil/constraint/layout/ConstraintSide.java @@ -0,0 +1,38 @@ +package trikita.anvil.constraint.layout; + +final class ConstraintSide { + public final int startID; + public final int startSide; + public final int endID; + public final int endSide; + + public ConstraintSide(int startID, int startSide, int endID, int endSide) { + this.startID = startID; + this.startSide = startSide; + this.endID = endID; + this.endSide = endSide; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ConstraintSide that = (ConstraintSide) o; + + if (startID != that.startID) return false; + if (startSide != that.startSide) return false; + if (endID != that.endID) return false; + return endSide == that.endSide; + + } + + @Override + public int hashCode() { + int result = startID; + result = 31 * result + startSide; + result = 31 * result + endID; + result = 31 * result + endSide; + return result; + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 9c28a352..9ca95344 100644 --- a/settings.gradle +++ b/settings.gradle @@ -5,4 +5,5 @@ include 'anvil-cardview-v7' include 'anvil-gridlayout-v7' include 'anvil-design' include 'anvil-recyclerview-v7' +include 'anvil-constraintlayout' From f94d2684cd6ed73c3551bf49c4cdf02454cb1295 Mon Sep 17 00:00:00 2001 From: Sergey Grekov Date: Fri, 7 Jun 2019 23:27:48 +0300 Subject: [PATCH 2/2] update travis ci config --- .travis.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7fe9630e..16e359ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,23 +1,28 @@ language: android +sudo: required +jdk: oraclejdk8 env: global: - GRADLE_OPTS=-Xmx512m + - ANDROID_API_LEVEL=28 + - ANDROID_BUILD_TOOLS_VERSION=28.0.3 + - ANDROID_ABI=armeabi-v7a android: components: - tools - - build-tools-27.0.3 - - android-27 + - platform-tools + - tools - extra-android-m2repository licenses: + - 'android-sdk-preview-license-52d11cd2' - 'android-sdk-license-.+' + - 'google-gdk-license-.+' before_install: - yes | sdkmanager "platforms;android-28" - -jdk: - - oraclejdk8 + - yes | sdkmanager "build-tools;28.0.3" script: - ./gradlew assemble anvil:check --stacktrace