forked from rengwuxian/HenCoderPlus3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pdog
committed
May 9, 2019
1 parent
f90f173
commit b8eacba
Showing
62 changed files
with
1,295 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
/captures | ||
.externalNativeBuild | ||
.idea/ | ||
/17_constraintlayout/images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
24 changes: 24 additions & 0 deletions
24
...tlayout/src/androidTest/java/com/hencoder/a19_constraintlayout/ExampleInstrumentedTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
49 changes: 49 additions & 0 deletions
49
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/CircularPositioning.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/CircularReveal.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/CircularRevealHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...onstraintlayout/src/main/java/com/hencoder/a19_constraintlayout/ConstraintLayoutSample.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/ConstraintSetActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/DimensionRatio.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/FlowActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/GuideLineActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/Linear.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
17_constraintlayout/src/main/java/com/hencoder/a19_constraintlayout/LinearActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Oops, something went wrong.