1 /* 2 * Copyright (C) 2010 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.contacts.widget; 17 18 import android.animation.ObjectAnimator; 19 import android.content.Context; 20 import android.graphics.Color; 21 import android.util.AttributeSet; 22 import android.view.View; 23 import android.widget.FrameLayout; 24 25 /** 26 * A container that places a masking view on top of all other views. The masking view can be 27 * faded in and out. Currently, the masking view is solid color white. 28 */ 29 public class TransitionAnimationView extends FrameLayout { 30 private View mMaskingView; 31 private ObjectAnimator mAnimator; 32 TransitionAnimationView(Context context)33 public TransitionAnimationView(Context context) { 34 this(context, null, 0); 35 } 36 TransitionAnimationView(Context context, AttributeSet attrs)37 public TransitionAnimationView(Context context, AttributeSet attrs) { 38 this(context, attrs, 0); 39 } 40 TransitionAnimationView(Context context, AttributeSet attrs, int defStyle)41 public TransitionAnimationView(Context context, AttributeSet attrs, int defStyle) { 42 super(context, attrs, defStyle); 43 } 44 45 @Override onFinishInflate()46 protected void onFinishInflate() { 47 super.onFinishInflate(); 48 mMaskingView = new View(getContext()); 49 mMaskingView.setVisibility(View.INVISIBLE); 50 mMaskingView.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, 51 LayoutParams.MATCH_PARENT)); 52 mMaskingView.setBackgroundColor(Color.WHITE); 53 addView(mMaskingView); 54 } 55 setMaskVisibility(boolean flag)56 public void setMaskVisibility(boolean flag) { 57 if (flag) { 58 mMaskingView.setAlpha(1.0f); 59 mMaskingView.setVisibility(View.VISIBLE); 60 } else { 61 mMaskingView.setVisibility(View.INVISIBLE); 62 } 63 } 64 65 /** 66 * Starts the transition of showing or hiding the mask. 67 * If showMask is true, the mask will be set to be invisible then fade into hide the other 68 * views in this container. If showMask is false, the mask will be set to be hide other views 69 * initially. Then, the other views in this container will be revealed. 70 */ startMaskTransition(boolean showMask)71 public void startMaskTransition(boolean showMask) { 72 // Stop any animation that may still be running. 73 if (mAnimator != null && mAnimator.isRunning()) { 74 mAnimator.end(); 75 } 76 77 mMaskingView.setVisibility(View.VISIBLE); 78 if (showMask) { 79 mAnimator = ObjectAnimator.ofFloat(mMaskingView, View.ALPHA, 0.0f, 1.0f); 80 mAnimator.start(); 81 } else { 82 // asked to hide the view 83 mAnimator = ObjectAnimator.ofFloat(mMaskingView, View.ALPHA, 1.0f, 0.0f); 84 mAnimator.start(); 85 } 86 } 87 } 88