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 
     21 import android.content.Context;
     22 import android.util.AttributeSet;
     23 import android.view.View;
     24 import android.widget.RelativeLayout;
     25 import android.widget.TextView;
     26 
     27 /**
     28  * This is a tab in the {@link ContactDetailTabCarousel}.
     29  */
     30 public class CarouselTab extends RelativeLayout implements ViewOverlay {
     31 
     32     private static final String TAG = CarouselTab.class.getSimpleName();
     33 
     34     private TextView mLabelView;
     35 
     36     /**
     37      * This view adds an alpha layer over the entire tab.
     38      */
     39     private View mAlphaLayer;
     40 
     41     /**
     42      * This view adds a layer over the entire tab so that when visible, it intercepts all touch
     43      * events on the tab.
     44      */
     45     private View mTouchInterceptLayer;
     46 
     47     public CarouselTab(Context context, AttributeSet attrs) {
     48         super(context, attrs);
     49     }
     50 
     51     @Override
     52     protected void onFinishInflate() {
     53         super.onFinishInflate();
     54 
     55         mLabelView = (TextView) findViewById(R.id.label);
     56         mLabelView.setClickable(true);
     57 
     58         mAlphaLayer = findViewById(R.id.alpha_overlay);
     59         mTouchInterceptLayer = findViewById(R.id.touch_intercept_overlay);
     60     }
     61 
     62     public void setLabel(String label) {
     63         mLabelView.setText(label);
     64     }
     65 
     66     public void showSelectedState() {
     67         mLabelView.setSelected(true);
     68     }
     69 
     70     public void showDeselectedState() {
     71         mLabelView.setSelected(false);
     72     }
     73 
     74     @Override
     75     public void disableTouchInterceptor() {
     76         // This shouldn't be called because there is no need to disable the touch interceptor if
     77         // there is no content within the tab that needs to be clicked.
     78     }
     79 
     80     @Override
     81     public void enableTouchInterceptor(OnClickListener clickListener) {
     82         if (mTouchInterceptLayer != null) {
     83             mTouchInterceptLayer.setVisibility(View.VISIBLE);
     84             mTouchInterceptLayer.setOnClickListener(clickListener);
     85         }
     86     }
     87 
     88     @Override
     89     public void setAlphaLayerValue(float alpha) {
     90         ContactDetailDisplayUtils.setAlphaOnViewBackground(mAlphaLayer, alpha);
     91     }
     92 }
     93