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