| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 androidx.appcompat.app.AppCompatActivity; |
| 24 |
import android.util.DisplayMetrics; |
| 25 |
import android.util.Log; |
| 26 |
import android.view.Gravity; |
| 27 |
import android.view.TextureView; |
| 28 |
import android.view.ViewGroup; |
| 29 |
import android.widget.FrameLayout; |
| 30 |
|
| 31 |
import com.android.test.uibench.opengl.ImageFlipRenderThread; |
| 32 |
|
| 33 |
public class GlTextureViewActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener { |
| 34 |
private ImageFlipRenderThread mRenderThread; |
| 35 |
private TextureView mTextureView; |
| 36 |
|
| 37 |
@Override |
| 38 |
protected void onCreate(Bundle savedInstanceState) { |
| 39 |
super.onCreate(savedInstanceState); |
| 40 |
|
| 41 |
mTextureView = new TextureView(this); |
| 42 |
mTextureView.setSurfaceTextureListener(this); |
| 43 |
setContentView(mTextureView, new FrameLayout.LayoutParams( |
| 44 |
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, |
| 45 |
Gravity.CENTER)); |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { |
| 50 |
mRenderThread = new ImageFlipRenderThread(getResources(), surface); |
| 51 |
mRenderThread.start(); |
| 52 |
|
| 53 |
DisplayMetrics metrics = mTextureView.getContext().getResources().getDisplayMetrics(); |
| 54 |
int distance = Math.max(mTextureView.getWidth(), mTextureView.getHeight()); |
| 55 |
mTextureView.setCameraDistance(distance * metrics.density); |
| 56 |
|
| 57 |
ObjectAnimator animator = ObjectAnimator.ofFloat(mTextureView, "rotationY", 0.0f, 360.0f); |
| 58 |
animator.setRepeatMode(ObjectAnimator.REVERSE); |
| 59 |
animator.setRepeatCount(ObjectAnimator.INFINITE); |
| 60 |
animator.setDuration(4000); |
| 61 |
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 62 |
@Override |
| 63 |
public void onAnimationUpdate(ValueAnimator animation) { |
| 64 |
mTextureView.invalidate(); |
| 65 |
} |
| 66 |
}); |
| 67 |
animator.start(); |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
| 76 |
mRenderThread.finish(); |
| 77 |
try { |
| 78 |
mRenderThread.join(); |
| 79 |
} catch (InterruptedException e) { |
| 80 |
Log.e(ImageFlipRenderThread.LOG_TAG, "Could not wait for render thread"); |
| 81 |
} |
| 82 |
return true; |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
| 87 |
} |
| 88 |
|
| 89 |
} |