1 /* 2 * Copyright (C) 2014 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.tv.settings.widget.picker; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * Picker column class used by {@link Picker} 24 */ 25 public class PickerColumn implements Parcelable { 26 27 private final String[] mItems; 28 29 public PickerColumn(String[] items) { 30 if (items == null) { 31 throw new IllegalArgumentException("items for PickerColumn cannot be null"); 32 } 33 mItems = items; 34 } 35 36 public PickerColumn(Parcel source) { 37 int count = source.readInt(); 38 mItems = new String[count]; 39 source.readStringArray(mItems); 40 } 41 42 public String[] getItems() { 43 return mItems; 44 } 45 46 public static Parcelable.Creator<PickerColumn> 47 CREATOR = new Parcelable.Creator<PickerColumn>() { 48 49 @Override 50 public PickerColumn createFromParcel(Parcel source) { 51 return new PickerColumn(source); 52 } 53 54 @Override 55 public PickerColumn[] newArray(int size) { 56 return new PickerColumn[size]; 57 } 58 }; 59 60 @Override 61 public int describeContents() { 62 return 0; 63 } 64 65 @Override 66 public void writeToParcel(Parcel dest, int flags) { 67 dest.writeInt(mItems.length); 68 dest.writeStringArray(mItems); 69 } 70 71 @Override 72 public String toString() { 73 StringBuilder sb = new StringBuilder(); 74 75 for (String s : mItems) { 76 sb.append(s).append("\n"); 77 } 78 return sb.toString(); 79 } 80 } 81