ConversationOverlayItem.java revision 31c38a8247b4583ac1cc506acf8454d8922ee491
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 18package com.android.mail.browse; 19 20import android.content.Context; 21import android.view.LayoutInflater; 22import android.view.View; 23import android.view.ViewGroup; 24import android.widget.Adapter; 25import android.widget.CursorAdapter; 26 27import com.android.mail.ui.ConversationViewFragment; 28import com.android.mail.utils.LogUtils; 29 30public abstract class ConversationOverlayItem { 31 private int mHeight; // in px 32 private int mTop; // in px 33 private boolean mNeedsMeasure; 34 35 public static final String LOG_TAG = ConversationViewFragment.LAYOUT_TAG; 36 37 /** 38 * @see Adapter#getItemViewType(int) 39 */ 40 public abstract int getType(); 41 /** 42 * Inflate and perform one-time initialization on a view for later binding. 43 */ 44 public abstract View createView(Context context, LayoutInflater inflater, 45 ViewGroup parent); 46 47 /** 48 * @see CursorAdapter#bindView(View, Context, android.database.Cursor) 49 * @param v a view to bind to 50 * @param measureOnly true iff we are binding this view only to measure its height (so items 51 * know they can cut certain corners that do not affect a view's height) 52 */ 53 public abstract void bindView(View v, boolean measureOnly); 54 /** 55 * Returns true if this overlay view is meant to be positioned right on top of the overlay 56 * below. This special positioning allows {@link ConversationContainer} to stack overlays 57 * together even when zoomed into a conversation, when the overlay spacers spread farther 58 * apart. 59 */ 60 public abstract boolean isContiguous(); 61 62 /** 63 * This method's behavior is critical and requires some 'splainin. 64 * <p> 65 * Subclasses that return a zero-size height to the {@link ConversationContainer} will 66 * cause the scrolling/recycling logic there to remove any matching view from the container. 67 * The item should switch to returning a non-zero height when its view should re-appear. 68 * <p> 69 * It's imperative that this method stay in sync with the current height of the HTML spacer 70 * that matches this overlay. 71 */ 72 public int getHeight() { 73 return mHeight; 74 } 75 76 public void setHeight(int h) { 77 LogUtils.i(LOG_TAG, "IN setHeight=%dpx of overlay item: %s", h, this); 78 if (mHeight != h) { 79 mHeight = h; 80 mNeedsMeasure = true; 81 } 82 } 83 84 public int getTop() { 85 return mTop; 86 } 87 88 public void setTop(int top) { 89 mTop = top; 90 } 91 92 public boolean isMeasurementValid() { 93 return !mNeedsMeasure; 94 } 95 96 public void markMeasurementValid() { 97 mNeedsMeasure = false; 98 } 99 100 public void invalidateMeasurement() { 101 mNeedsMeasure = true; 102 } 103 104 public boolean canBecomeSnapHeader() { 105 return false; 106 } 107 108 public boolean canPushSnapHeader() { 109 return false; 110 } 111 112} 113