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

Constraint Layout DSL #132

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
15 changes: 10 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions anvil-constraintlayout/attr-quirks.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def nop = { builder -> null }

ext.QUIRKS = [:]
148 changes: 148 additions & 0 deletions anvil-constraintlayout/build.gradle
Original file line number Diff line number Diff line change
@@ -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)
}
}
4 changes: 4 additions & 0 deletions anvil-constraintlayout/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
POM_ARTIFACT_ID=anvil-constraintlayout
POM_PACKAGE_NAME=anvil
POM_NAME=Anvil (Constraint Layout)
POM_PACKAGING=aar
2 changes: 2 additions & 0 deletions anvil-constraintlayout/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="trikita.anvil.constrainedlayout" />
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading