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
17package com.example.renderthread;
18
19import android.app.Activity;
20import android.os.Bundle;
21import android.os.Process;
22import android.os.SystemClock;
23import android.view.View;
24import android.view.ViewGroup;
25
26public class SubActivity extends Activity {
27    @Override
28    protected void onCreate(Bundle savedInstanceState) {
29        super.onCreate(savedInstanceState);
30        long before = SystemClock.currentThreadTimeMillis();
31        setContentView(R.layout.activity_sub);
32        getActionBar().setTitle("SubActivity");
33        // Simulate being a real app!
34        while (SystemClock.currentThreadTimeMillis() - before < 100) {
35            View v = new View(this, null);
36        }
37    }
38
39    @Override
40    protected void onResume() {
41        super.onResume();
42        ViewGroup container = (ViewGroup) findViewById(R.id.my_container);
43        int dx = getWindowManager().getDefaultDisplay().getWidth();
44        for (int i = 0; i < container.getChildCount(); i++) {
45            View child = container.getChildAt(i);
46            int dir = child.getId() == R.id.from_left ? 1 : -1;
47            child.setTranslationX(dx * dir);
48            child.animate().translationX(0).setDuration(MainActivity.DURATION);
49        }
50        View bg = findViewById(R.id.bg_container);
51        bg.setAlpha(0f);
52        bg.animate().alpha(1f).setDuration(MainActivity.DURATION);
53    }
54
55    @Override
56    public void onBackPressed() {
57        super.onBackPressed();
58        overridePendingTransition(0, 0);
59    }
60}
61