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