blob: 06fa9f4654da0b13c41018bd4a684e9c75291cf2 [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.widget.TextView;
24import android.view.transition.Fade;
25import android.view.transition.Recolor;
26import android.view.transition.Slide;
27import android.view.transition.Transition;
28import android.view.transition.TransitionGroup;
29import android.view.transition.TransitionManager;
Chet Haasefaebd8f2012-05-18 14:17:57 -070030
31
32public class LoginActivity extends Activity {
33 ViewGroup mSceneRoot;
34 Scene mCurrentScene;
35 TransitionManager mTransitionManager;
36 Scene mLoginScene, mPasswordScene, mIncorrectPasswordScene, mSuccessScene, mUsernameTakenScene,
37 mNewUserScene;
38
39 @Override
40 public void onCreate(Bundle savedInstanceState) {
41 super.onCreate(savedInstanceState);
42 setContentView(R.layout.activity_login);
43 View container = (View) findViewById(R.id.container);
44 mSceneRoot = (ViewGroup) container.getParent();
45
46 mLoginScene = new Scene(mSceneRoot, R.layout.activity_login, this);
47 mPasswordScene = new Scene(mSceneRoot, R.layout.login_password, this);
48 mIncorrectPasswordScene = new Scene(mSceneRoot, R.layout.incorrect_password, this);
49 mUsernameTakenScene = new Scene(mSceneRoot, R.layout.username_taken, this);
50 mSuccessScene = new Scene(mSceneRoot, R.layout.success, this);
51 mNewUserScene = new Scene(mSceneRoot, R.layout.new_user, this);
52
53 mTransitionManager = new TransitionManager();
54
55 // Custom transitions in/out of NewUser screen - slide in the 2nd password UI
56 TransitionGroup slider = new TransitionGroup();
57 slider.addTransitions(new Slide().setTargetIds(R.id.retype, R.id.retypeEdit));
58 slider.addTransitions(new Recolor().setTargetIds(R.id.password, R.id.passwordEdit));
59 slider.addTransitions(new Fade());
60 mTransitionManager.setTransition(mLoginScene, mNewUserScene, slider);
61 mTransitionManager.setTransition(mPasswordScene, mNewUserScene, slider);
62 mTransitionManager.setTransition(mNewUserScene, mLoginScene, slider);
63 mTransitionManager.setTransition(mNewUserScene, mPasswordScene, slider);
64
65 // Custom transitions with recoloring password field
66 Transition colorizer = new Recolor().setTargetIds(R.id.password, R.id.passwordEdit);
67 mTransitionManager.setTransition(mLoginScene, mPasswordScene, colorizer);
68 mTransitionManager.setTransition(mPasswordScene, mLoginScene, colorizer);
69
70 mCurrentScene = mLoginScene;
71 mSceneRoot.setCurrentScene(mLoginScene);
72 }
73
74 public void applyScene(Scene scene) {
75 mTransitionManager.transitionTo(scene);
76 mCurrentScene = scene;
77 }
78
79 public void sendMessage(View view) {
80 TextView textView = (TextView) view;
81 CharSequence text = textView.getText();
82 if (text.equals("Cancel")) {
83 applyScene(mLoginScene);
84 } else if (text.equals("Submit")) {
85 if (mCurrentScene == mLoginScene) {
86 applyScene(mPasswordScene);
87 } else if (mCurrentScene == mPasswordScene) {
88 applyScene(Math.random() < .5 ? mSuccessScene : mIncorrectPasswordScene);
89 } else if (mCurrentScene == mNewUserScene) {
90 applyScene(Math.random() < .5 ? mSuccessScene : mUsernameTakenScene);
91 }
92 } else if (text.equals("New User?")) {
93 applyScene(mNewUserScene);
94 } else if (text.equals("Okay")) {
95 if (mCurrentScene == mIncorrectPasswordScene) {
96 applyScene(mPasswordScene);
97 } else { // username taken scene
98 applyScene(mNewUserScene);
99 }
100 } else if (text.equals("Reset")) {
101 applyScene(mLoginScene);
102 }
103 }
104}