Home | History | Annotate | Download | only in browse
      1 /*
      2  * Copyright (C) 2012 Google Inc.
      3  * Licensed to The Android Open Source Project.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.android.mail.browse;
     19 
     20 import android.content.Context;
     21 import android.util.AttributeSet;
     22 import android.view.View;
     23 import android.widget.LinearLayout;
     24 import android.widget.TextView;
     25 
     26 import com.android.mail.R;
     27 import com.android.mail.browse.ConversationViewAdapter.SuperCollapsedBlockItem;
     28 
     29 /**
     30  * A header block that expands to a list of collapsed message headers. Will notify a listener on tap
     31  * so the listener can hide the block and reveal the corresponding collapsed message headers.
     32  *
     33  */
     34 public class SuperCollapsedBlock extends LinearLayout implements View.OnClickListener {
     35 
     36     public interface OnClickListener {
     37         /**
     38          * Handle a click on a super-collapsed block.
     39          *
     40          */
     41         void onSuperCollapsedClick(SuperCollapsedBlockItem item);
     42     }
     43 
     44     private SuperCollapsedBlockItem mModel;
     45     private OnClickListener mClick;
     46     private TextView mSuperCollapsedText;
     47 
     48     public SuperCollapsedBlock(Context context) {
     49         this(context, null);
     50     }
     51 
     52     public SuperCollapsedBlock(Context context, AttributeSet attrs) {
     53         super(context, attrs);
     54         setActivated(false);
     55         setOnClickListener(this);
     56     }
     57 
     58     public void initialize(OnClickListener onClick) {
     59         mClick = onClick;
     60     }
     61 
     62     @Override
     63     protected void onFinishInflate() {
     64         super.onFinishInflate();
     65         mSuperCollapsedText = (TextView) findViewById(R.id.super_collapsed_text);
     66     }
     67 
     68     public void bind(SuperCollapsedBlockItem item) {
     69         mModel = item;
     70         setCount(item.getEnd() - item.getStart() + 1);
     71     }
     72 
     73     public void setCount(int count) {
     74         mSuperCollapsedText.setText(
     75                 getResources().getQuantityString(R.plurals.show_messages_read, count, count));
     76     }
     77 
     78     @Override
     79     public void onClick(final View v) {
     80         ((TextView) findViewById(R.id.super_collapsed_text)).setText(
     81                 R.string.loading_conversation);
     82 
     83         if (mClick != null) {
     84             getHandler().post(new Runnable() {
     85                 @Override
     86                 public void run() {
     87                     mClick.onSuperCollapsedClick(mModel);
     88                 }
     89             });
     90         }
     91     }
     92 }
     93