blob: a12742d83fe7d8f915fc8ce8ad043ee339d5f31a [file] [log] [blame]
Chris Craik65b04b62015-08-27 14:34:17 -07001/*
2 * Copyright (C) 2015 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.android.test.uibench;
18
19import android.animation.ObjectAnimator;
20import android.animation.ValueAnimator;
Chris Craik65b04b62015-08-27 14:34:17 -070021import android.graphics.SurfaceTexture;
Chris Craik65b04b62015-08-27 14:34:17 -070022import android.os.Bundle;
Chris Craik65b04b62015-08-27 14:34:17 -070023import android.support.v7.app.AppCompatActivity;
24import android.util.Log;
25import android.view.Gravity;
26import android.view.TextureView;
Chris Craik65b04b62015-08-27 14:34:17 -070027import android.view.ViewGroup;
28import android.widget.FrameLayout;
29
Chris Craikbaf41292015-08-31 14:51:03 -070030import com.android.test.uibench.opengl.ImageFlipRenderThread;
Chris Craik65b04b62015-08-27 14:34:17 -070031
32public class GlTextureViewActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
Chris Craikbaf41292015-08-31 14:51:03 -070033 private ImageFlipRenderThread mRenderThread;
Chris Craik65b04b62015-08-27 14:34:17 -070034 private TextureView mTextureView;
35
36 @Override
37 protected void onCreate(Bundle savedInstanceState) {
38 super.onCreate(savedInstanceState);
39
40 mTextureView = new TextureView(this);
41 mTextureView.setSurfaceTextureListener(this);
42 setContentView(mTextureView, new FrameLayout.LayoutParams(
43 ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
44 Gravity.CENTER));
45 }
46
47 @Override
48 public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Chris Craikbaf41292015-08-31 14:51:03 -070049 mRenderThread = new ImageFlipRenderThread(getResources(), surface);
Chris Craik65b04b62015-08-27 14:34:17 -070050 mRenderThread.start();
51
52 mTextureView.setCameraDistance(5000);
53
54 ObjectAnimator animator = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f);
55 animator.setRepeatMode(ObjectAnimator.REVERSE);
56 animator.setRepeatCount(ObjectAnimator.INFINITE);
57 animator.setDuration(4000);
58 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
59 @Override
60 public void onAnimationUpdate(ValueAnimator animation) {
61 mTextureView.invalidate();
62 }
63 });
64 animator.start();
65 }
66
67 @Override
68 public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
69 }
70
71 @Override
72 public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
73 mRenderThread.finish();
74 try {
75 mRenderThread.join();
76 } catch (InterruptedException e) {
Chris Craikbaf41292015-08-31 14:51:03 -070077 Log.e(ImageFlipRenderThread.LOG_TAG, "Could not wait for render thread");
Chris Craik65b04b62015-08-27 14:34:17 -070078 }
79 return true;
80 }
81
82 @Override
83 public void onSurfaceTextureUpdated(SurfaceTexture surface) {
84 }
85
Chris Craik65b04b62015-08-27 14:34:17 -070086}