blob: 57d07c0d0eac859d41f5385274462bf74796523b [file] [log] [blame]
Clara Bayarri75e09792015-07-29 16:20:40 +01001/*
2 * Copyright (C) 2015 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 */
16package android.view;
17
18import android.annotation.NonNull;
19import android.annotation.Nullable;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23import java.util.ArrayList;
24import java.util.Collections;
25import java.util.List;
26
27import static com.android.internal.util.Preconditions.checkNotNull;
28
29/**
30 * A group of {@link KeyboardShortcutInfo}.
31 */
32public final class KeyboardShortcutGroup implements Parcelable {
33 private final CharSequence mLabel;
34 private final List<KeyboardShortcutInfo> mItems;
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000035 // The system group looks different UI wise.
36 private boolean mSystemGroup;
Clara Bayarri75e09792015-07-29 16:20:40 +010037
38 /**
39 * @param label The title to be used for this group, or null if there is none.
40 * @param items The set of items to be included.
41 */
42 public KeyboardShortcutGroup(@Nullable CharSequence label,
43 @NonNull List<KeyboardShortcutInfo> items) {
44 mLabel = label;
45 mItems = new ArrayList<>(checkNotNull(items));
46 }
47
48 /**
49 * @param label The title to be used for this group, or null if there is none.
50 */
51 public KeyboardShortcutGroup(@Nullable CharSequence label) {
52 this(label, Collections.<KeyboardShortcutInfo>emptyList());
53 }
54
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000055 /**
56 * @param label The title to be used for this group, or null if there is none.
57 * @param items The set of items to be included.
58 * @param isSystemGroup Set this to {@code true} if this is s system group.
59 * @hide
60 */
61 public KeyboardShortcutGroup(@Nullable CharSequence label,
62 @NonNull List<KeyboardShortcutInfo> items, boolean isSystemGroup) {
63 mLabel = label;
64 mItems = new ArrayList<>(checkNotNull(items));
65 mSystemGroup = isSystemGroup;
66 }
67
68 /**
69 * @param label The title to be used for this group, or null if there is none.
70 * @param isSystemGroup Set this to {@code true} if this is s system group.
71 * @hide
72 */
73 public KeyboardShortcutGroup(@Nullable CharSequence label, boolean isSystemGroup) {
74 this(label, Collections.<KeyboardShortcutInfo>emptyList(), isSystemGroup);
75 }
76
Clara Bayarri75e09792015-07-29 16:20:40 +010077 private KeyboardShortcutGroup(Parcel source) {
78 mItems = new ArrayList<>();
79 mLabel = source.readCharSequence();
80 source.readTypedList(mItems, KeyboardShortcutInfo.CREATOR);
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000081 mSystemGroup = source.readInt() == 1;
Clara Bayarri75e09792015-07-29 16:20:40 +010082 }
83
84 /**
85 * Returns the label to be used to describe this group.
86 */
87 public CharSequence getLabel() {
88 return mLabel;
89 }
90
91 /**
92 * Returns the list of items included in this group.
93 */
94 public List<KeyboardShortcutInfo> getItems() {
95 return mItems;
96 }
97
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000098 /** @hide **/
99 public boolean isSystemGroup() {
100 return mSystemGroup;
101 }
102
Clara Bayarri75e09792015-07-29 16:20:40 +0100103 /**
104 * Adds an item to the existing list.
105 *
106 * @param item The item to be added.
107 */
108 public void addItem(KeyboardShortcutInfo item) {
109 mItems.add(item);
110 }
111
112 @Override
113 public int describeContents() {
114 return 0;
115 }
116
117 @Override
118 public void writeToParcel(Parcel dest, int flags) {
119 dest.writeCharSequence(mLabel);
120 dest.writeTypedList(mItems);
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +0000121 dest.writeInt(mSystemGroup ? 1 : 0);
Clara Bayarri75e09792015-07-29 16:20:40 +0100122 }
123
124 public static final Creator<KeyboardShortcutGroup> CREATOR =
125 new Creator<KeyboardShortcutGroup>() {
126 public KeyboardShortcutGroup createFromParcel(Parcel source) {
127 return new KeyboardShortcutGroup(source);
128 }
129 public KeyboardShortcutGroup[] newArray(int size) {
130 return new KeyboardShortcutGroup[size];
131 }
132 };
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +0000133}