Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Import examples for MotionLayout.
Browse files Browse the repository at this point in the history
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
thagikura committed Jun 27, 2018
1 parent 454ed2b commit 1c642c5
Show file tree
Hide file tree
Showing 170 changed files with 4,581 additions and 8 deletions.
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 The Android Open Source Project
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,11 +17,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:3.2.0-alpha17'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -30,6 +33,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
}
}
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions app/build.gradle → constraintlayout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 27
defaultConfig {
applicationId "com.example.android.constraintlayoutexamples"
minSdkVersion 19
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -37,5 +36,5 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.1.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.android.support.constraint:constraint-layout:1.1.2'
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
1 change: 1 addition & 0 deletions motionlayout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions motionlayout/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'

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'
}
21 changes: 21 additions & 0 deletions motionlayout/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.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)
}
}
26 changes: 26 additions & 0 deletions motionlayout/src/main/AndroidManifest.xml
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>
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()
}
}
}
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
}
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)
}

}
Loading

0 comments on commit 1c642c5

Please sign in to comment.