• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
21 import android.graphics.SurfaceTexture;
22 import android.os.Bundle;
23 import android.support.v7.app.AppCompatActivity;
24 import android.util.Log;
25 import android.view.Gravity;
26 import android.view.TextureView;
27 import android.view.ViewGroup;
28 import android.widget.FrameLayout;
29 
30 import com.android.test.uibench.opengl.ImageFlipRenderThread;
31 
32 public class GlTextureViewActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
33     private ImageFlipRenderThread mRenderThread;
34     private TextureView mTextureView;
35 
36     @Override
onCreate(Bundle savedInstanceState)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
onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)48     public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
49         mRenderThread = new ImageFlipRenderThread(getResources(), surface);
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
onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)68     public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
69     }
70 
71     @Override
onSurfaceTextureDestroyed(SurfaceTexture surface)72     public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
73         mRenderThread.finish();
74         try {
75             mRenderThread.join();
76         } catch (InterruptedException e) {
77             Log.e(ImageFlipRenderThread.LOG_TAG, "Could not wait for render thread");
78         }
79         return true;
80     }
81 
82     @Override
onSurfaceTextureUpdated(SurfaceTexture surface)83     public void onSurfaceTextureUpdated(SurfaceTexture surface) {
84     }
85 
86 }