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 private boolean mImageScaleUpAllowed = true; 36 37 /** 38 * Constructor for a DetailsOverviewRow. 39 * 40 * @param item The main item for the details page. 41 */ 42 public DetailsOverviewRow(Object item) { 43 super(null); 44 mItem = item; 45 verify(); 46 } 47 48 /** 49 * Gets the main item for the details page. 50 */ 51 public final Object getItem() { 52 return mItem; 53 } 54 55 /** 56 * Sets a drawable as the image of this details overview. 57 * 58 * @param drawable The drawable to set. 59 */ 60 public final void setImageDrawable(Drawable drawable) { 61 mImageDrawable = drawable; 62 } 63 64 /** 65 * Sets a Bitmap as the image of this details overview. 66 * 67 * @param context The context to retrieve display metrics from. 68 * @param bm The bitmap to set. 69 */ 70 public final void setImageBitmap(Context context, Bitmap bm) { 71 mImageDrawable = new BitmapDrawable(context.getResources(), bm); 72 } 73 74 /** 75 * Gets the image drawable of this details overview. 76 * 77 * @return The overview's image drawable, or null if no drawable has been 78 * assigned. 79 */ 80 public final Drawable getImageDrawable() { 81 return mImageDrawable; 82 } 83 84 /** 85 * Allows or disallows scaling up of images. 86 * Images will always be scaled down if necessary. 87 */ 88 public void setImageScaleUpAllowed(boolean allowed) { 89 mImageScaleUpAllowed = allowed; 90 } 91 92 /** 93 * Returns true if the image may be scaled up; false otherwise. 94 */ 95 public boolean isImageScaleUpAllowed() { 96 return mImageScaleUpAllowed; 97 } 98 99 /** 100 * Add an Action to the overview. 101 * 102 * @param action The Action to add. 103 */ 104 public final void addAction(Action action) { 105 mActions.add(action); 106 } 107 108 /** 109 * Add an Action to the overview at the specified position. 110 * 111 * @param pos The position to insert the Action. 112 * @param action The Action to add. 113 */ 114 public final void addAction(int pos, Action action) { 115 mActions.add(pos, action); 116 } 117 118 /** 119 * Remove the given Action from the overview. 120 * 121 * @param action The Action to remove. 122 * @return true if the overview contained the specified Action. 123 */ 124 public final boolean removeAction(Action action) { 125 return mActions.remove(action); 126 } 127 128 /** 129 * Gets a read-only view of the list of Actions of this details overview. 130 * 131 * @return An unmodifiable view of the list of Actions. 132 */ 133 public final List<Action> getActions() { 134 return Collections.unmodifiableList(mActions); 135 } 136 137 private void verify() { 138 if (mItem == null) { 139 throw new IllegalArgumentException("Object cannot be null"); 140 } 141 } 142} 143