This repository has been archived by the owner on Nov 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also rename the module existing samples for CosntraintLayout from "app" to "constraintlayout" to be consistent with the samples for MotionLayout. Change-Id: I953df4803e376ce0461a9acb1731d1ec87b17fce
- Loading branch information
Showing
170 changed files
with
4,581 additions
and
8 deletions.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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' | ||
|
||
apply plugin: 'kotlin-android-extensions' | ||
|
||
android { | ||
compileSdkVersion 27 | ||
defaultConfig { | ||
applicationId "com.google.androidstudio.motionlayoutexample" | ||
minSdkVersion 18 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | ||
implementation 'com.android.support:appcompat-v7:27.1.1' | ||
|
||
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha1' | ||
implementation 'android.arch.lifecycle:extensions:1.1.1' | ||
implementation 'com.android.support:design:27.1.1' | ||
implementation 'com.airbnb.android:lottie:2.5.1' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
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
.../androidTest/java/com/google/androidstudio/motionlayoutexample/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.google.androidstudio.motionlayoutexample | ||
|
||
import android.support.test.InstrumentationRegistry | ||
import android.support.test.runner.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.getTargetContext() | ||
assertEquals("com.google.androidstudio.motionlayoutexample", 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,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.google.androidstudio.motionlayoutexample"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@drawable/ml_logo" | ||
android:label="@string/app_name" | ||
android:roundIcon="@drawable/ml_logo" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme.NoActionBar"> | ||
<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=".DemoActivity"/> | ||
<activity android:name=".viewpagerdemo.ViewPagerActivity"/> | ||
<activity android:name=".viewpagerdemo.ViewPagerActivity2"/> | ||
<activity android:name=".FragmentExampleActivity"/> | ||
<activity android:name=".FragmentExample2Activity"/> | ||
</application> | ||
|
||
</manifest> |
41 changes: 41 additions & 0 deletions
41
motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/DemoActivity.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,41 @@ | ||
package com.google.androidstudio.motionlayoutexample | ||
|
||
import android.os.Bundle | ||
import android.support.constraint.motion.MotionLayout | ||
import android.support.v7.app.AppCompatActivity | ||
import android.view.View | ||
import android.widget.ImageView | ||
|
||
class DemoActivity : AppCompatActivity() { | ||
var motionLayout : View? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val layout = intent.getIntExtra("layout_file_id", R.layout.motion_01_basic) | ||
setContentView(layout) | ||
motionLayout = findViewById<View>(R.id.motionLayout) | ||
|
||
if (layout == R.layout.motion_11_coordinatorlayout) { | ||
var icon = findViewById<ImageView>(R.id.icon) | ||
icon?.clipToOutline = true | ||
} | ||
|
||
var doShowPaths = intent.getBooleanExtra("showPaths", false) | ||
(motionLayout as? MotionLayout)?.setShowPaths(doShowPaths) | ||
} | ||
|
||
fun changeState(v: View?) { | ||
if (motionLayout == null || motionLayout !is MotionLayout) { | ||
return | ||
} | ||
var ml = motionLayout as? MotionLayout | ||
if (ml == null) { | ||
return | ||
} | ||
if (ml.getProgress() > 0.5f) { | ||
ml.transitionToStart() | ||
} else { | ||
ml.transitionToEnd() | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/DemosAdapter.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,51 @@ | ||
package com.google.androidstudio.motionlayoutexample | ||
|
||
import android.content.Intent | ||
import android.support.constraint.ConstraintLayout | ||
import android.support.v4.content.ContextCompat.startActivity | ||
import android.support.v7.app.AppCompatActivity | ||
import android.support.v7.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import android.widget.TextView | ||
|
||
class DemosAdapter(private val myDataset: Array<DemosAdapter.Demo>) : | ||
RecyclerView.Adapter<DemosAdapter.ViewHolder>() { | ||
|
||
data class Demo(val title: String, val description : String, val layout : Int = 0, val activity : Class<*> = DemoActivity::class.java) { | ||
constructor(title: String, description: String, activity : Class<*> = DemoActivity::class.java) : this(title, description, 0, activity) {} | ||
} | ||
|
||
class ViewHolder(val layout: ConstraintLayout) : RecyclerView.ViewHolder(layout) { | ||
var title = layout.findViewById<TextView>(R.id.title) | ||
var description = layout.findViewById<TextView>(R.id.description) | ||
var layoutFileId = 0 | ||
var activity : Class<*>? = null | ||
|
||
init { | ||
layout.setOnClickListener { | ||
var context = it?.context as MainActivity | ||
if (activity != null) { | ||
context.start(activity!!, layoutFileId) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
override fun onCreateViewHolder(parent: ViewGroup, | ||
viewType: Int): DemosAdapter.ViewHolder { | ||
val row = LayoutInflater.from(parent.context) | ||
.inflate(R.layout.row, parent, false) as ConstraintLayout | ||
return ViewHolder(row) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.title.text = myDataset[position].title | ||
holder.description.text = myDataset[position].description | ||
holder.layoutFileId = myDataset[position].layout | ||
holder.activity = myDataset[position].activity | ||
} | ||
|
||
override fun getItemCount() = myDataset.size | ||
} |
72 changes: 72 additions & 0 deletions
72
motionlayout/src/main/java/com/google/androidstudio/motionlayoutexample/MainActivity.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,72 @@ | ||
package com.google.androidstudio.motionlayoutexample | ||
|
||
import android.content.Intent | ||
import android.support.v7.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.support.v7.widget.LinearLayoutManager | ||
import android.support.v7.widget.RecyclerView | ||
import android.widget.CompoundButton | ||
import com.google.androidstudio.motionlayoutexample.viewpagerdemo.ViewPagerActivity | ||
import com.google.androidstudio.motionlayoutexample.viewpagerdemo.ViewPagerActivity2 | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
class MainActivity : AppCompatActivity(), CompoundButton.OnCheckedChangeListener { | ||
private lateinit var recyclerView: RecyclerView | ||
private lateinit var viewAdapter: RecyclerView.Adapter<*> | ||
private lateinit var viewManager: RecyclerView.LayoutManager | ||
var doShowPaths = false | ||
|
||
private val myDataset: Array<DemosAdapter.Demo> = arrayOf( | ||
DemosAdapter.Demo("Basic Example (1/2)", "Basic motion example using referenced ConstraintLayout files", R.layout.motion_01_basic), | ||
DemosAdapter.Demo("Basic Example (2/2)", "Basic motion example using ConstraintSets defined in the MotionScene file", R.layout.motion_02_basic), | ||
DemosAdapter.Demo("Custom Attribute", "Show color interpolation (custom attribute)", R.layout.motion_03_custom_attribute), | ||
DemosAdapter.Demo("ImageFilterView (1/2)", "Show image cross-fade (using ML's ImageFilterView + custom attribute)", R.layout.motion_04_imagefilter), | ||
DemosAdapter.Demo("ImageFilterView (2/2)", "Show image saturation transition (using ML's ImageFilterView + custom attribute)", R.layout.motion_05_imagefilter), | ||
DemosAdapter.Demo("Keyframe Position (1/3)", "Use a simple keyframe to change the interpolated motion", R.layout.motion_06_keyframe), | ||
DemosAdapter.Demo("Keyframe Interpolation (2/3)", "More complex keyframe, adding rotation interpolation", R.layout.motion_07_keyframe), | ||
DemosAdapter.Demo("Keyframe Cycle (3/3)", "Basic example of using a keyframe cycle ", R.layout.motion_08_cycle), | ||
DemosAdapter.Demo("CoordinatorLayout Example (1/3)", "Basic example of using MotionLayout instead of AppBarLayout", R.layout.motion_09_coordinatorlayout), | ||
DemosAdapter.Demo("CoordinatorLayout Example (2/3)", "Slightly more complex example of MotionLayout replacing AppBarLayout, with multiple elements and parallax background", R.layout.motion_10_coordinatorlayout), | ||
DemosAdapter.Demo("CoordinatorLayout Example (3/3)", "Another AppBarLayout replacement example", R.layout.motion_11_coordinatorlayout), | ||
DemosAdapter.Demo("DrawerLayout Example (1/2)", "Basic DrawerLayout with MotionLayout", R.layout.motion_12_drawerlayout), | ||
DemosAdapter.Demo("DrawerLayout Example (2/2)", "Advanced DrawerLayout with MotionLayout", R.layout.motion_13_drawerlayout), | ||
DemosAdapter.Demo("Side Panel Example", "Side Panel, implemented with MotionLayout only", R.layout.motion_14_side_panel), | ||
DemosAdapter.Demo("Parallax Example", "Parallax background. Drag the car.", R.layout.motion_15_parallax), | ||
DemosAdapter.Demo("ViewPager Example", "Using MotionLayout with ViewPager", ViewPagerActivity::class.java), | ||
DemosAdapter.Demo("ViewPager Lottie Example", "Using MotionLayout and Lottie with ViewPager", ViewPagerActivity2::class.java), | ||
DemosAdapter.Demo("Complex Motion Example (1/4)", "Basic CoordinatorLayout-like behavior. Implemented with MotionLayout only, using a moving guideline. Note the view isn't resized. ", R.layout.motion_17_coordination), | ||
DemosAdapter.Demo("Complex Motion Example (2/4)", "Advanced CoordinatorLayout-like behavior (adding a FAB). Implemented with MotionLayout only, using a moving guideline. Note the view isn't resized.", R.layout.motion_18_coordination), | ||
DemosAdapter.Demo("Complex Motion Example (3/4)", "Advanced CoordinatorLayout-like behavior (adding a FAB). Implemented with MotionLayout only, using direct resizing of the view.", R.layout.motion_19_coordination), | ||
DemosAdapter.Demo("Complex Motion Example (4/4)", "Advanced Synchronized reval motion + helper (bounce). Implemented with MotionLayout only.", R.layout.motion_20_reveal), | ||
DemosAdapter.Demo("Fragment Transition Example (1/2)", "Example showing transitioning fragments within MotionLayout", FragmentExampleActivity::class.java), | ||
DemosAdapter.Demo("Fragment Transition Example (2/2)", "Example showing transitioning fragments within MotionLayout", FragmentExample2Activity::class.java) | ||
) | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
viewManager = LinearLayoutManager(this) | ||
viewAdapter = DemosAdapter(myDataset) | ||
|
||
recyclerView = findViewById<RecyclerView>(R.id.recyclerview).apply { | ||
setHasFixedSize(true) | ||
layoutManager = viewManager | ||
adapter = viewAdapter | ||
} | ||
|
||
showPaths.setOnCheckedChangeListener(this) | ||
} | ||
|
||
override fun onCheckedChanged(p0: CompoundButton?, value: Boolean) { | ||
doShowPaths = value | ||
} | ||
|
||
fun start(activity: Class<*>, layoutFileId: Int) { | ||
val intent = Intent(this, activity).apply { | ||
putExtra("layout_file_id", layoutFileId) | ||
putExtra("showPaths", doShowPaths) | ||
} | ||
startActivity(intent) | ||
} | ||
|
||
} |
Oops, something went wrong.