DetailsOverviewRow.java revision 80d04d2265fe28800fcbc7e8cc7d6d229a7913d8
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14package android.support.v17.leanback.widget; 15 16import android.content.Context; 17import android.graphics.Bitmap; 18import android.graphics.drawable.BitmapDrawable; 19import android.graphics.drawable.Drawable; 20 21import java.util.ArrayList; 22import java.util.Collections; 23import java.util.List; 24 25/** 26 * An overview row for a details fragment. This row consists of an image, a 27 * description view, and optionally a series of {@link Action}s that can be taken for 28 * the item. 29 */ 30public class DetailsOverviewRow extends Row { 31 32 private Object mItem; 33 private Drawable mImageDrawable; 34 private ArrayList<Action> mActions = new ArrayList<Action>(); 35 36 /** 37 * Constructor for a DetailsOverviewRow. 38 * 39 * @param item The main item for the details page. 40 */ 41 public DetailsOverviewRow(Object item) { 42 super(null); 43 mItem = item; 44 verify(); 45 } 46 47 /** 48 * Gets the main item for the details page. 49 */ 50 public final Object getItem() { 51 return mItem; 52 } 53 54 /** 55 * Sets a drawable as the image of this details overview. 56 * 57 * @param drawable The drawable to set. 58 */ 59 public final void setImageDrawable(Drawable drawable) { 60 mImageDrawable = drawable; 61 } 62 63 /** 64 * Sets a Bitmap as the image of this details overview. 65 * 66 * @param context The context to retrieve display metrics from. 67 * @param bm The bitmap to set. 68 */ 69 public final void setImageBitmap(Context context, Bitmap bm) { 70 mImageDrawable = new BitmapDrawable(context.getResources(), bm); 71 } 72 73 /** 74 * Gets the image drawable of this details overview. 75 * 76 * @return The overview's image drawable, or null if no drawable has been 77 * assigned. 78 */ 79 public final Drawable getImageDrawable() { 80 return mImageDrawable; 81 } 82 83 /** 84 * Add an Action to the overview. 85 * 86 * @param action The Action to add. 87 */ 88 public final void addAction(Action action) { 89 mActions.add(action); 90 } 91 92 /** 93 * Add an Action to the overview at the specified position. 94 * 95 * @param pos The position to insert the Action. 96 * @param action The Action to add. 97 */ 98 public final void addAction(int pos, Action action) { 99 mActions.add(pos, action); 100 } 101 102 /** 103 * Remove the given Action from the overview. 104 * 105 * @param action The Action to remove. 106 * @return true if the overview contained the specified Action. 107 */ 108 public final boolean removeAction(Action action) { 109 return mActions.remove(action); 110 } 111 112 /** 113 * Gets a read-only view of the list of Actions of this details overview. 114 * 115 * @return An unmodifiable view of the list of Actions. 116 */ 117 public final List<Action> getActions() { 118 return Collections.unmodifiableList(mActions); 119 } 120 121 private void verify() { 122 if (mItem == null) { 123 throw new IllegalArgumentException("Object cannot be null"); 124 } 125 } 126} 127