1cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck/*
2cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Copyright (C) 2013 The Android Open Source Project
3cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
4cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Licensed under the Apache License, Version 2.0 (the "License");
5cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * you may not use this file except in compliance with the License.
6cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * You may obtain a copy of the License at
7cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
8cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *      http://www.apache.org/licenses/LICENSE-2.0
9cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck *
10cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Unless required by applicable law or agreed to in writing, software
11cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * distributed under the License is distributed on an "AS IS" BASIS,
12cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * See the License for the specific language governing permissions and
14cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * limitations under the License.
15cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck */
16cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
17cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckpackage com.example.renderthread;
18cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
19cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.app.Activity;
20cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.Bundle;
21cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.Process;
22cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.SystemClock;
23cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.view.View;
24cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.view.ViewGroup;
25cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
26cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckpublic class SubActivity extends Activity {
27cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
28cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    protected void onCreate(Bundle savedInstanceState) {
29cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        super.onCreate(savedInstanceState);
30cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        long before = SystemClock.currentThreadTimeMillis();
31cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        setContentView(R.layout.activity_sub);
32cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        getActionBar().setTitle("SubActivity");
33cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        // Simulate being a real app!
34cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        while (SystemClock.currentThreadTimeMillis() - before < 100) {
35cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck            View v = new View(this, null);
36cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        }
37cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
38cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
39cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
40cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    protected void onResume() {
41cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        super.onResume();
42cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        ViewGroup container = (ViewGroup) findViewById(R.id.my_container);
43cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        int dx = getWindowManager().getDefaultDisplay().getWidth();
44cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        for (int i = 0; i < container.getChildCount(); i++) {
45cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck            View child = container.getChildAt(i);
46cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck            int dir = child.getId() == R.id.from_left ? 1 : -1;
47cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck            child.setTranslationX(dx * dir);
48cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck            child.animate().translationX(0).setDuration(MainActivity.DURATION);
49cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        }
50cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        View bg = findViewById(R.id.bg_container);
51cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        bg.setAlpha(0f);
52cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        bg.animate().alpha(1f).setDuration(MainActivity.DURATION);
53cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
54cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck
55cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    @Override
56cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    public void onBackPressed() {
57cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        super.onBackPressed();
58cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck        overridePendingTransition(0, 0);
59cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck    }
60cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck}
61