New demo for transitions feature

New demo in ApiDemos: animations/Simple Transitions

Issue #10460684 KLP API Review: android.view.transition and android.animation

Change-Id: I2c376343c2b945240bc5f3619786e9354a8c1a10
This commit is contained in:
Chet Haase
2013-08-29 13:52:06 -07:00
parent 61c7ea8e1e
commit ea3e7cdb90
10 changed files with 458 additions and 2 deletions

View File

@@ -1366,6 +1366,15 @@
</intent-filter>
</activity>
<activity android:name=".animation.Transitions"
android:label="Animation/Simple Transitions"
android:enabled="@bool/atLeastHoneycomb">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
<!-- ************************************* -->
<!-- ANIMATION PACKAGE SAMPLES -->
<!-- ************************************* -->

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton android:id="@+id/scene1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:onClick="selectScene"
android:text="Scene 1" />
<RadioButton android:id="@+id/scene2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="selectScene"
android:text="Scene 2" />
<RadioButton android:id="@+id/scene3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="selectScene"
android:text="Scene 3" />
<RadioButton android:id="@+id/scene4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="selectScene"
android:text="Scene 4" />
</RadioGroup>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sceneRoot">
<include layout="@layout/transition_scene1"/>
</LinearLayout>
</LinearLayout>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="#f00"
android:id="@+id/view1"/>
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:background="#0f0"
android:id="@+id/view2"/>
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:background="#00f"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:id="@+id/view3"/>
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:background="#0ff"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:id="@+id/view4"/>
</RelativeLayout>

View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<View
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:background="#f00"
android:id="@+id/view1"/>
<View
android:layout_width="100dip"
android:layout_height="100dip"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#0f0"
android:id="@+id/view2"/>
<View
android:layout_width="100dip"
android:layout_height="100dip"
android:background="#00f"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:id="@+id/view3"/>
<View
android:layout_width="100dip"
android:layout_height="100dip"
android:background="#0ff"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:id="@+id/view4"/>
</RelativeLayout>

View File

@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:background="#f00"
android:id="@+id/view1"/>
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:background="#0f0"
android:id="@+id/view2"/>
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:background="#00f"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:id="@+id/view3"/>
<View
android:layout_width="100dip"
android:layout_height="50dip"
android:background="#0ff"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:id="@+id/view4"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:id="@+id/grayscaleContainer">
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#000"
android:id="@+id/gray1"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#222"
android:id="@+id/gray2"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#444"
android:id="@+id/gray3"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#666"
android:id="@+id/gray4"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#888"
android:id="@+id/gray5"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#aaa"
android:id="@+id/gray6"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#ccc"
android:id="@+id/gray7"/>
<View
android:layout_width="match_parent"
android:layout_height="10dip"
android:background="#fff"
android:id="@+id/gray8"/>
</LinearLayout>
</RelativeLayout>

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- BEGIN_INCLUDE(ChangeBounds) -->
<changeBounds/>
<!-- END_INCLUDE(ChangeBounds) -->

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<set xmlns:android="http://schemas.android.com/apk/res/android">
<changeBounds/>
<fade android:fadingMode="fade_in" >
<targets>
<target android:targetId="@id/grayscaleContainer" />
</targets>
</fade>
</set>

View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- BEGIN_INCLUDE(TransitionSet) -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:transitionOrdering="sequential">
<changeBounds/>
<fade android:fadingMode="fade_out" >
<targets>
<target android:targetId="@id/grayscaleContainer" />
</targets>
</fade>
</set>
<!-- END_INCLUDE(TransitionSet) -->

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- BEGIN_INCLUDE(TransitionManager) -->
<transitionManager xmlns:android="http://schemas.android.com/apk/res/android">
<transition android:fromScene="@layout/transition_scene1"
android:toScene="@layout/transition_scene2"
android:transition="@transition/changebounds"/>
<transition android:fromScene="@layout/transition_scene2"
android:toScene="@layout/transition_scene1"
android:transition="@transition/changebounds"/>
<transition android:toScene="@layout/transition_scene3"
android:transition="@transition/changebounds_fadein_together"/>
<transition android:fromScene="@layout/transition_scene3"
android:toScene="@layout/transition_scene1"
android:transition="@transition/changebounds_fadeout_sequential"/>
<transition android:fromScene="@layout/transition_scene3"
android:toScene="@layout/transition_scene2"
android:transition="@transition/changebounds_fadeout_sequential"/>
</transitionManager>
<!-- END_INCLUDE(TransitionManager) -->

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2013 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.apis.animation;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.transition.Scene;
import android.transition.TransitionInflater;
import android.transition.TransitionManager;
import com.example.android.apis.R;
public class Transitions extends Activity {
Scene mScene1, mScene2, mScene3;
ViewGroup mSceneRoot;
TransitionManager mTransitionManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.transition);
mSceneRoot = (ViewGroup) findViewById(R.id.sceneRoot);
TransitionInflater inflater = TransitionInflater.from(this);
mScene1 = Scene.getSceneForLayout(mSceneRoot, R.layout.transition_scene1, this);
mScene2 = Scene.getSceneForLayout(mSceneRoot, R.layout.transition_scene2, this);
mScene3 = Scene.getSceneForLayout(mSceneRoot, R.layout.transition_scene3, this);
mTransitionManager = inflater.inflateTransitionManager(R.transition.transitions_mgr,
mSceneRoot);
}
public void selectScene(View view) {
switch (view.getId()) {
case R.id.scene1:
mTransitionManager.transitionTo(mScene1);
break;
case R.id.scene2:
mTransitionManager.transitionTo(mScene2);
break;
case R.id.scene3:
mTransitionManager.transitionTo(mScene3);
break;
case R.id.scene4:
TransitionManager.beginDelayedTransition(mSceneRoot, null);
setNewSize(R.id.view1, 150, 25);
setNewSize(R.id.view2, 150, 25);
setNewSize(R.id.view3, 150, 25);
setNewSize(R.id.view4, 150, 25);
break;
}
}
private void setNewSize(int id, int width, int height) {
View view = findViewById(id);
ViewGroup.LayoutParams params = view.getLayoutParams();
params.width = width;
params.height = height;
view.setLayoutParams(params);
}
}