ResizeHWLayerActivity.java revision 6337f4fb27836cdb9055c6e79d6fc3d62d7c9e67
1/* 2 * Copyright (C) 2017 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 */ 16package com.android.test.uibench; 17 18import android.animation.PropertyValuesHolder; 19import android.animation.ValueAnimator; 20import android.graphics.Color; 21import android.os.Bundle; 22import android.support.v7.app.AppCompatActivity; 23import android.util.DisplayMetrics; 24import android.view.View; 25import android.view.ViewGroup.LayoutParams; 26import android.widget.FrameLayout; 27 28/** 29 * Tests resizing of a View backed by a hardware layer. 30 */ 31public class ResizeHWLayerActivity extends AppCompatActivity { 32 33 @Override 34 protected void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 DisplayMetrics metrics = getResources().getDisplayMetrics(); 37 int width = metrics.widthPixels; 38 int height = metrics.heightPixels; 39 View child = new View(this); 40 child.setBackgroundColor(Color.BLUE); 41 child.setLayoutParams(new FrameLayout.LayoutParams(width, height)); 42 child.setLayerType(View.LAYER_TYPE_HARDWARE, null); 43 PropertyValuesHolder pvhWidth = PropertyValuesHolder.ofInt("width", width, 1); 44 PropertyValuesHolder pvhHeight = PropertyValuesHolder.ofInt("height", height, 1); 45 final LayoutParams params = child.getLayoutParams(); 46 ValueAnimator animator = ValueAnimator.ofPropertyValuesHolder(pvhWidth, pvhHeight); 47 animator.setRepeatMode(ValueAnimator.REVERSE); 48 animator.setRepeatCount(ValueAnimator.INFINITE); 49 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 50 @Override 51 public void onAnimationUpdate(ValueAnimator valueAnimator) { 52 params.width = (Integer)valueAnimator.getAnimatedValue("width"); 53 params.height = (Integer)valueAnimator.getAnimatedValue("height"); 54 child.requestLayout(); 55 } 56 }); 57 animator.start(); 58 setContentView(child); 59 } 60} 61