1/* 2 * Copyright (C) 2007 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 17package com.android.internal.telephony.cat; 18 19import android.graphics.Bitmap; 20import android.os.Parcel; 21import android.os.Parcelable; 22 23import java.util.ArrayList; 24import java.util.List; 25 26/** 27 * Container class for CAT menu (SET UP MENU, SELECT ITEM) parameters. 28 * 29 */ 30public class Menu implements Parcelable { 31 public List<Item> items; 32 public List<TextAttribute> titleAttrs; 33 public PresentationType presentationType; 34 public String title; 35 public Bitmap titleIcon; 36 public int defaultItem; 37 public boolean softKeyPreferred; 38 public boolean helpAvailable; 39 public boolean titleIconSelfExplanatory; 40 public boolean itemsIconSelfExplanatory; 41 42 public Menu() { 43 // Create an empty list. 44 items = new ArrayList<Item>(); 45 title = null; 46 titleAttrs = null; 47 defaultItem = 0; 48 softKeyPreferred = false; 49 helpAvailable = false; 50 titleIconSelfExplanatory = false; 51 itemsIconSelfExplanatory = false; 52 titleIcon = null; 53 // set default style to be navigation menu. 54 presentationType = PresentationType.NAVIGATION_OPTIONS; 55 } 56 57 private Menu(Parcel in) { 58 title = in.readString(); 59 titleIcon = in.readParcelable(null); 60 // rebuild items list. 61 items = new ArrayList<Item>(); 62 int size = in.readInt(); 63 for (int i=0; i<size; i++) { 64 Item item = in.readParcelable(null); 65 items.add(item); 66 } 67 defaultItem = in.readInt(); 68 softKeyPreferred = in.readInt() == 1 ? true : false; 69 helpAvailable = in.readInt() == 1 ? true : false; 70 titleIconSelfExplanatory = in.readInt() == 1 ? true : false; 71 itemsIconSelfExplanatory = in.readInt() == 1 ? true : false; 72 presentationType = PresentationType.values()[in.readInt()]; 73 } 74 75 public int describeContents() { 76 return 0; 77 } 78 79 public void writeToParcel(Parcel dest, int flags) { 80 dest.writeString(title); 81 dest.writeParcelable(titleIcon, flags); 82 // write items list to the parcel. 83 int size = items.size(); 84 dest.writeInt(size); 85 for (int i=0; i<size; i++) { 86 dest.writeParcelable(items.get(i), flags); 87 } 88 dest.writeInt(defaultItem); 89 dest.writeInt(softKeyPreferred ? 1 : 0); 90 dest.writeInt(helpAvailable ? 1 : 0); 91 dest.writeInt(titleIconSelfExplanatory ? 1 : 0); 92 dest.writeInt(itemsIconSelfExplanatory ? 1 : 0); 93 dest.writeInt(presentationType.ordinal()); 94 } 95 96 public static final Parcelable.Creator<Menu> CREATOR = new Parcelable.Creator<Menu>() { 97 public Menu createFromParcel(Parcel in) { 98 return new Menu(in); 99 } 100 101 public Menu[] newArray(int size) { 102 return new Menu[size]; 103 } 104 }; 105} 106