Skip to content

Commit

Permalink
17_constraint layout
Browse files Browse the repository at this point in the history
  • Loading branch information
pdog committed May 9, 2019
1 parent f90f173 commit b8eacba
Show file tree
Hide file tree
Showing 62 changed files with 1,295 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
/captures
.externalNativeBuild
.idea/
/17_constraintlayout/images
1 change: 1 addition & 0 deletions 17_constraintlayout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions 17_constraintlayout/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28


defaultConfig {
applicationId "com.hencoder.a19_constraintlayout"
minSdkVersion 18
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
21 changes: 21 additions & 0 deletions 17_constraintlayout/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hencoder.a19_constraintlayout

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.hencoder.a19_constraintlayout", appContext.packageName)
}
}
38 changes: 38 additions & 0 deletions 17_constraintlayout/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.hencoder.a19_constraintlayout">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">

<activity android:name=".GuideLineActivity"/>
<activity android:name=".DimensionRatio"/>
<activity android:name=".CircularPositioning"/>
<activity android:name=".CircularReveal"/>
<activity android:name=".PlaceHolder"/>
<activity android:name=".ConstraintSetActivity"/>
<activity android:name=".LinearActivity"/>
<activity android:name=".FlowActivity"/>


<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity android:name=".ConstraintLayoutSample">

</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.hencoder.a19_constraintlayout

import android.animation.ValueAnimator
import android.animation.ValueAnimator.INFINITE
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.view.animation.LinearInterpolator
import androidx.constraintlayout.widget.ConstraintLayout

class CircularPositioning : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_circular_positioning)

val earth = findViewById<View>(R.id.earth)
val moon = findViewById<View>(R.id.moon)
val sun = findViewById<View>(R.id.sun)

val earthAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
duration = 10000L
repeatCount = INFINITE
interpolator = LinearInterpolator()
}

val moonAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
duration = 2000L
repeatCount = INFINITE
interpolator = LinearInterpolator()
}

earthAnimator.addUpdateListener {
val params = earth.layoutParams as ConstraintLayout.LayoutParams
params.circleAngle = 45 + it.animatedFraction * 360
moon.requestLayout()
}
moonAnimator.addUpdateListener {
val params = moon.layoutParams as ConstraintLayout.LayoutParams
params.circleAngle = 270 + it.animatedFraction * 360
moon.requestLayout()
}

sun.setOnClickListener {
earthAnimator.start()
moonAnimator.start()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hencoder.a19_constraintlayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class CircularReveal : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_circular_reveal)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hencoder.a19_constraintlayout

import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.view.View
import android.view.ViewAnimationUtils
import androidx.constraintlayout.widget.ConstraintHelper
import androidx.constraintlayout.widget.ConstraintLayout

class CircularRevealHelper(context: Context, attrs: AttributeSet) :
ConstraintHelper(context, attrs) {

override fun updatePostLayout(container: ConstraintLayout?) {
super.updatePostLayout(container)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return

for (referencedId in referencedIds) {
val view = container!!.getViewById(referencedId)
val radius = Math.hypot(view.width.toDouble(), view.height.toDouble()).toInt()

ViewAnimationUtils.createCircularReveal(view, 0, 0, 0f, radius.toFloat())
.setDuration(2000L)
.start()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hencoder.a19_constraintlayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class ConstraintLayoutSample : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_constraint_layout_sample)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hencoder.a19_constraintlayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.transition.TransitionManager
import android.view.View
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet

class ConstraintSetActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_constraint_start)
}


fun onClick(view: View) {
val constraintLayout = view as ConstraintLayout
TransitionManager.beginDelayedTransition(constraintLayout)

val constraintSet = ConstraintSet().apply {
clone(this@ConstraintSetActivity, R.layout.activity_constraint_end)
}
constraintSet.applyTo(constraintLayout)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hencoder.a19_constraintlayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class DimensionRatio : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dimension_ratio)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.hencoder.a19_constraintlayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.constraintlayout.helper.widget.Flow
import androidx.constraintlayout.helper.widget.Flow.VERTICAL
import androidx.constraintlayout.helper.widget.Flow.WRAP_NONE

class FlowActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_flow)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hencoder.a19_constraintlayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class GuideLineActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_guide_line)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hencoder.a19_constraintlayout

import android.content.Context
import android.util.AttributeSet

import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.constraintlayout.widget.VirtualLayout


class Linear(context: Context, attrs: AttributeSet) : VirtualLayout(context, attrs) {

private val constraintSet: ConstraintSet by lazy {
ConstraintSet().apply {
isForceId = false
}
}

override fun updatePreLayout(container: ConstraintLayout) {
super.updatePreLayout(container)
constraintSet.clone(container)

val viewIds = referencedIds
for (i in 1 until mCount) {

val current = viewIds[i]
val before = viewIds[i - 1]

constraintSet.connect(current, ConstraintSet.START, before, ConstraintSet.START)
constraintSet.connect(current, ConstraintSet.TOP, before, ConstraintSet.BOTTOM)

constraintSet.applyTo(container)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hencoder.a19_constraintlayout

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle

class LinearActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_linear)
}
}
Loading

0 comments on commit b8eacba

Please sign in to comment.