Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.test.uibench; |
| 18 | |
| 19 | import android.animation.ObjectAnimator; |
| 20 | import android.animation.ValueAnimator; |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 21 | import android.graphics.SurfaceTexture; |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 22 | import android.os.Bundle; |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 23 | import android.support.v7.app.AppCompatActivity; |
| 24 | import android.util.Log; |
| 25 | import android.view.Gravity; |
| 26 | import android.view.TextureView; |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 27 | import android.view.ViewGroup; |
| 28 | import android.widget.FrameLayout; |
| 29 | |
Chris Craik | baf4129 | 2015-08-31 14:51:03 -0700 | [diff] [blame] | 30 | import com.android.test.uibench.opengl.ImageFlipRenderThread; |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 31 | |
| 32 | public class GlTextureViewActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener { |
Chris Craik | baf4129 | 2015-08-31 14:51:03 -0700 | [diff] [blame] | 33 | private ImageFlipRenderThread mRenderThread; |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 34 | 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 Craik | baf4129 | 2015-08-31 14:51:03 -0700 | [diff] [blame] | 49 | mRenderThread = new ImageFlipRenderThread(getResources(), surface); |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 50 | 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 Craik | baf4129 | 2015-08-31 14:51:03 -0700 | [diff] [blame] | 77 | Log.e(ImageFlipRenderThread.LOG_TAG, "Could not wait for render thread"); |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 78 | } |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
| 84 | } |
| 85 | |
Chris Craik | 65b04b6 | 2015-08-27 14:34:17 -0700 | [diff] [blame] | 86 | } |