blob: 320c8b982c3b1865601f44dc9b10a00092acf196 [file] [log] [blame]
Daniel Olshansky5bcd87e2013-07-15 09:29:51 -07001/*
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
17package com.example.android.insertingcells;
18
19import android.animation.ObjectAnimator;
20import android.animation.PropertyValuesHolder;
21import android.animation.ValueAnimator;
22import android.content.Context;
23import android.graphics.Canvas;
24import android.graphics.Color;
25import android.graphics.Paint;
26import android.util.AttributeSet;
27import android.view.View;
28
29/**
30 * This round view draws a circle from which the image pops out of and into
31 * the corresponding cell in the list.
32 */
33public class RoundView extends View {
34
35 private final int STROKE_WIDTH = 6;
36 private final int RADIUS = 20;
37 private final int ANIMATION_DURATION = 300;
38 private final float SCALE_FACTOR = 0.3f;
39
40 private Paint mPaint;
41
42 public RoundView(Context context) {
43 super(context);
44 init();
45 }
46
47 public RoundView(Context context, AttributeSet attrs) {
48 super(context, attrs);
49 init();
50 }
51
52 public RoundView(Context context, AttributeSet attrs, int defStyle) {
53 super(context, attrs, defStyle);
54 init();
55 }
56
57 private void init() {
58 mPaint = new Paint();
59 mPaint.setAntiAlias(true);
60 mPaint.setColor(Color.WHITE);
61 mPaint.setStyle(Paint.Style.STROKE);
62 mPaint.setStrokeWidth(STROKE_WIDTH);
63 }
64
65 @Override
66 protected void onDraw(Canvas canvas) {
67 canvas.drawCircle(canvas.getWidth() / 2, canvas.getHeight() / 2,
68 RADIUS, mPaint);
69 }
70
71 public ObjectAnimator getScalingAnimator() {
72 PropertyValuesHolder imgViewScaleY = PropertyValuesHolder.ofFloat(View
73 .SCALE_Y, SCALE_FACTOR);
74 PropertyValuesHolder imgViewScaleX = PropertyValuesHolder.ofFloat(View
75 .SCALE_X, SCALE_FACTOR);
76
77 ObjectAnimator imgViewScaleAnimator = ObjectAnimator
78 .ofPropertyValuesHolder(this, imgViewScaleX, imgViewScaleY);
79 imgViewScaleAnimator.setRepeatCount(1);
80 imgViewScaleAnimator.setRepeatMode(ValueAnimator.REVERSE);
81 imgViewScaleAnimator.setDuration(ANIMATION_DURATION);
82
83 return imgViewScaleAnimator;
84 }
85}