Home | History | Annotate | Download | only in transitiontests
      1 /*
      2  * Copyright (C) 2013 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 package com.android.transitiontests;
     17 
     18 import android.animation.ObjectAnimator;
     19 import android.animation.ValueAnimator;
     20 import android.app.Activity;
     21 import android.content.Context;
     22 import android.graphics.Canvas;
     23 import android.graphics.Color;
     24 import android.graphics.Paint;
     25 import android.graphics.Rect;
     26 import android.os.Bundle;
     27 import android.view.View;
     28 import android.widget.ImageView;
     29 import android.widget.RelativeLayout;
     30 
     31 
     32 public class HitRectBug extends Activity {
     33     @Override
     34     protected void onCreate(Bundle savedInstanceState)
     35     {
     36         super.onCreate(savedInstanceState);
     37         setContentView(new TestDrawingView(this));
     38     }
     39 
     40     public static class TestDrawingView extends RelativeLayout
     41     {
     42         private Rect mRect = new Rect();
     43         private Paint mPaint;
     44         private ImageView mImageView;
     45 
     46         public TestDrawingView(Context context)
     47         {
     48             super(context);
     49             setWillNotDraw(false);
     50 
     51             mPaint = new Paint();
     52             mPaint.setColor(Color.RED);
     53             mPaint.setStyle(Paint.Style.STROKE);
     54 
     55             mImageView = new ImageView(context);
     56             mImageView.setLeft(100);
     57             mImageView.setRight(200);
     58             mImageView.setImageResource(R.drawable.self_portrait_square);
     59             mImageView.setScaleX(3);
     60             mImageView.setScaleY(3);
     61 //            mImageView.setRotation(145);
     62 
     63             ObjectAnimator anim = ObjectAnimator.ofFloat(mImageView, View.ROTATION, 0, 360);
     64             anim.setRepeatCount(ValueAnimator.INFINITE);
     65             anim.setDuration(5000);
     66             anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
     67                 @Override
     68                 public void onAnimationUpdate(ValueAnimator animation) {
     69                     invalidate();
     70                 }
     71             });
     72             anim.start();
     73             RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(128, 128);
     74             params.addRule(RelativeLayout.CENTER_IN_PARENT);
     75             addView(mImageView, params);
     76         }
     77 
     78         @Override
     79         protected void onDraw(Canvas canvas)
     80         {
     81             super.onDraw(canvas);
     82         }
     83 
     84         @Override
     85         protected void dispatchDraw(Canvas canvas) {
     86             super.dispatchDraw(canvas);
     87             mImageView.getHitRect(mRect);
     88             canvas.drawRect(mRect, mPaint);
     89         }
     90     }
     91 }
     92