blob: ff617aa4f59354623aaffb06438643af878d2cf5 [file] [log] [blame]
Chet Haasefaebd8f2012-05-18 14:17:57 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.transitiontests;
17
18import android.app.Activity;
19import android.os.Bundle;
20import android.view.View;
21import android.view.ViewGroup;
22import android.view.transition.Scene;
23import android.view.transition.TransitionInflater;
24import android.widget.TextView;
25import android.view.transition.TransitionManager;
Chet Haasefaebd8f2012-05-18 14:17:57 -070026
27
28public class LoginActivityFromResources extends Activity {
29 ViewGroup mSceneRoot;
30 Scene mCurrentScene;
31 TransitionManager mTransitionManager = null;
32 Scene mLoginScene, mPasswordScene, mIncorrectPasswordScene, mSuccessScene, mUsernameTakenScene,
33 mNewUserScene;
34
35 @Override
36 public void onCreate(Bundle savedInstanceState) {
37 super.onCreate(savedInstanceState);
38 setContentView(R.layout.activity_login);
39 View container = (View) findViewById(R.id.container);
40 mSceneRoot = (ViewGroup) container.getParent();
41
42 }
43
44 public void applyScene(Scene scene) {
45 mTransitionManager.transitionTo(scene);
46 mCurrentScene = scene;
47 }
48
49 public void sendMessage(View view) {
50 if (mTransitionManager == null) {
51 TransitionInflater inflater = TransitionInflater.from(this);
52
53 mLoginScene = inflater.inflateScene(R.scene.login_scene, mSceneRoot);
54 mPasswordScene = inflater.inflateScene(R.scene.password_scene, mSceneRoot);
55 mIncorrectPasswordScene =
56 inflater.inflateScene(R.scene.incorrect_password_scene,mSceneRoot);
57 mUsernameTakenScene =
58 inflater.inflateScene(R.scene.username_taken_scene, mSceneRoot);
59 mSuccessScene = inflater.inflateScene(R.scene.success_scene, mSceneRoot);
60 mNewUserScene = inflater.inflateScene(R.scene.new_user_scene, mSceneRoot);
61
62 mTransitionManager =
63 inflater.inflateTransitionManager(R.transition.login_transition_mgr,
64 mSceneRoot);
65
66 mCurrentScene = mLoginScene;
67 mSceneRoot.setCurrentScene(mLoginScene);
68 }
69 TextView textView = (TextView) view;
70 CharSequence text = textView.getText();
71 if (text.equals("Cancel")) {
72 applyScene(mLoginScene);
73 } else if (text.equals("Submit")) {
74 if (mCurrentScene == mLoginScene) {
75 applyScene(mPasswordScene);
76 } else if (mCurrentScene == mPasswordScene) {
77 applyScene(Math.random() < .5 ? mSuccessScene : mIncorrectPasswordScene);
78 } else if (mCurrentScene == mNewUserScene) {
79 applyScene(Math.random() < .5 ? mSuccessScene : mUsernameTakenScene);
80 }
81 } else if (text.equals("New User?")) {
82 applyScene(mNewUserScene);
83 } else if (text.equals("Okay")) {
84 if (mCurrentScene == mIncorrectPasswordScene) {
85 applyScene(mPasswordScene);
86 } else { // username taken scene
87 applyScene(mNewUserScene);
88 }
89 } else if (text.equals("Reset")) {
90 applyScene(mLoginScene);
91 }
92 }
93}