Home | History | Annotate | Download | only in detail
      1 /*
      2  * Copyright (C) 2011 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 
     17 package com.android.contacts.detail;
     18 
     19 import com.android.contacts.R;
     20 import com.android.contacts.widget.FrameLayoutWithOverlay;
     21 
     22 import android.content.Context;
     23 import android.util.AttributeSet;
     24 import android.view.View;
     25 import android.view.ViewPropertyAnimator;
     26 import android.widget.TextView;
     27 
     28 /**
     29  * This is a tab in the {@link ContactDetailTabCarousel}.
     30  */
     31 public class CarouselTab extends FrameLayoutWithOverlay {
     32 
     33     private static final String TAG = CarouselTab.class.getSimpleName();
     34 
     35     private static final long FADE_TRANSITION_TIME = 150;
     36 
     37     private TextView mLabelView;
     38     private View mLabelBackgroundView;
     39 
     40     /**
     41      * This view adds an alpha layer over the entire tab (except for the label).
     42      */
     43     private View mAlphaLayer;
     44 
     45     public CarouselTab(Context context, AttributeSet attrs) {
     46         super(context, attrs);
     47     }
     48 
     49     @Override
     50     protected void onFinishInflate() {
     51         super.onFinishInflate();
     52 
     53         mLabelView = (TextView) findViewById(R.id.label);
     54         mLabelBackgroundView = findViewById(R.id.label_background);
     55         mAlphaLayer = findViewById(R.id.alpha_overlay);
     56         setAlphaLayer(mAlphaLayer);
     57     }
     58 
     59     public void setLabel(String label) {
     60         mLabelView.setText(label);
     61     }
     62 
     63     public void showSelectedState() {
     64         mLabelView.setSelected(true);
     65     }
     66 
     67     public void showDeselectedState() {
     68         mLabelView.setSelected(false);
     69     }
     70 
     71     public void fadeInLabelViewAnimator(int startDelay, boolean fadeBackground) {
     72         final ViewPropertyAnimator labelAnimator = mLabelView.animate();
     73         mLabelView.setAlpha(0.0f);
     74         labelAnimator.alpha(1.0f);
     75         labelAnimator.setStartDelay(startDelay);
     76         labelAnimator.setDuration(FADE_TRANSITION_TIME);
     77 
     78         if (fadeBackground) {
     79             final ViewPropertyAnimator backgroundAnimator = mLabelBackgroundView.animate();
     80             mLabelBackgroundView.setAlpha(0.0f);
     81             backgroundAnimator.alpha(1.0f);
     82             backgroundAnimator.setStartDelay(startDelay);
     83             backgroundAnimator.setDuration(FADE_TRANSITION_TIME);
     84         }
     85     }
     86 }
     87