• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
16 package com.android.transitiontests;
17 
18 import android.app.Activity;
19 import android.os.Bundle;
20 import android.view.View;
21 import android.view.ViewGroup;
22 import android.transition.Scene;
23 import android.transition.TransitionInflater;
24 import android.widget.TextView;
25 import android.transition.TransitionManager;
26 
27 
28 public 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
onCreate(Bundle savedInstanceState)36     public void onCreate(Bundle savedInstanceState) {
37         super.onCreate(savedInstanceState);
38         setContentView(R.layout.activity_login);
39         View container = findViewById(R.id.container);
40         mSceneRoot = (ViewGroup) container.getParent();
41 
42     }
43 
applyScene(Scene scene)44     public void applyScene(Scene scene) {
45         mTransitionManager.transitionTo(scene);
46         mCurrentScene = scene;
47     }
48 
sendMessage(View view)49     public void sendMessage(View view) {
50         if (mTransitionManager == null) {
51             TransitionInflater inflater = TransitionInflater.from(this);
52 
53             mLoginScene = Scene.getSceneForLayout(mSceneRoot, R.layout.activity_login, this);
54             mPasswordScene = Scene.getSceneForLayout(mSceneRoot, R.layout.login_password, this);
55             mIncorrectPasswordScene = Scene.getSceneForLayout(mSceneRoot, R.layout
56                     .incorrect_password, this);
57             mUsernameTakenScene = Scene.getSceneForLayout(mSceneRoot, R.layout.username_taken, this);
58             mSuccessScene = Scene.getSceneForLayout(mSceneRoot, R.layout.success, this);
59             mNewUserScene = Scene.getSceneForLayout(mSceneRoot, R.layout.new_user, this);
60 
61             mTransitionManager =
62                     inflater.inflateTransitionManager(R.transition.login_transition_mgr,
63                             mSceneRoot);
64 
65             mCurrentScene = mLoginScene;
66         }
67         TextView textView = (TextView) view;
68         CharSequence text = textView.getText();
69         if (text.equals("Cancel")) {
70             applyScene(mLoginScene);
71         } else if (text.equals("Submit")) {
72             if (mCurrentScene == mLoginScene) {
73                 applyScene(mPasswordScene);
74             } else if (mCurrentScene == mPasswordScene) {
75                 applyScene(Math.random() < .5 ? mSuccessScene : mIncorrectPasswordScene);
76             } else if (mCurrentScene == mNewUserScene) {
77                 applyScene(Math.random() < .5 ? mSuccessScene : mUsernameTakenScene);
78             }
79         } else if (text.equals("New User?")) {
80             applyScene(mNewUserScene);
81         } else if (text.equals("Okay")) {
82             if (mCurrentScene == mIncorrectPasswordScene) {
83                 applyScene(mPasswordScene);
84             } else { // username taken scene
85                 applyScene(mNewUserScene);
86             }
87         } else if (text.equals("Reset")) {
88             applyScene(mLoginScene);
89         }
90     }
91 }
92