blob: 52e9832eeb90f22f676e1e7f3fa7bd6c718368db [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
Aurimas Liutikas67e2ae82016-10-11 18:17:42 -070018import static com.android.internal.util.Preconditions.checkNotNull;
19
Clara Bayarri75e09792015-07-29 16:20:40 +010020import android.annotation.NonNull;
21import android.annotation.Nullable;
Clara Bayarri35a078f2017-05-26 13:09:56 +010022import android.annotation.TestApi;
Clara Bayarri75e09792015-07-29 16:20:40 +010023import android.os.Parcel;
24import android.os.Parcelable;
25
26import java.util.ArrayList;
27import java.util.Collections;
28import java.util.List;
29
Clara Bayarri75e09792015-07-29 16:20:40 +010030/**
31 * A group of {@link KeyboardShortcutInfo}.
32 */
33public final class KeyboardShortcutGroup implements Parcelable {
34 private final CharSequence mLabel;
35 private final List<KeyboardShortcutInfo> mItems;
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000036 // The system group looks different UI wise.
37 private boolean mSystemGroup;
Clara Bayarri75e09792015-07-29 16:20:40 +010038
39 /**
40 * @param label The title to be used for this group, or null if there is none.
41 * @param items The set of items to be included.
42 */
43 public KeyboardShortcutGroup(@Nullable CharSequence label,
44 @NonNull List<KeyboardShortcutInfo> items) {
45 mLabel = label;
46 mItems = new ArrayList<>(checkNotNull(items));
47 }
48
49 /**
50 * @param label The title to be used for this group, or null if there is none.
51 */
52 public KeyboardShortcutGroup(@Nullable CharSequence label) {
53 this(label, Collections.<KeyboardShortcutInfo>emptyList());
54 }
55
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000056 /**
57 * @param label The title to be used for this group, or null if there is none.
58 * @param items The set of items to be included.
59 * @param isSystemGroup Set this to {@code true} if this is s system group.
60 * @hide
61 */
Clara Bayarri35a078f2017-05-26 13:09:56 +010062 @TestApi
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000063 public KeyboardShortcutGroup(@Nullable CharSequence label,
64 @NonNull List<KeyboardShortcutInfo> items, boolean isSystemGroup) {
65 mLabel = label;
66 mItems = new ArrayList<>(checkNotNull(items));
67 mSystemGroup = isSystemGroup;
68 }
69
70 /**
71 * @param label The title to be used for this group, or null if there is none.
72 * @param isSystemGroup Set this to {@code true} if this is s system group.
73 * @hide
74 */
Clara Bayarri35a078f2017-05-26 13:09:56 +010075 @TestApi
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000076 public KeyboardShortcutGroup(@Nullable CharSequence label, boolean isSystemGroup) {
77 this(label, Collections.<KeyboardShortcutInfo>emptyList(), isSystemGroup);
78 }
79
Clara Bayarri75e09792015-07-29 16:20:40 +010080 private KeyboardShortcutGroup(Parcel source) {
81 mItems = new ArrayList<>();
82 mLabel = source.readCharSequence();
83 source.readTypedList(mItems, KeyboardShortcutInfo.CREATOR);
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +000084 mSystemGroup = source.readInt() == 1;
Clara Bayarri75e09792015-07-29 16:20:40 +010085 }
86
87 /**
88 * Returns the label to be used to describe this group.
89 */
90 public CharSequence getLabel() {
91 return mLabel;
92 }
93
94 /**
95 * Returns the list of items included in this group.
96 */
97 public List<KeyboardShortcutInfo> getItems() {
98 return mItems;
99 }
100
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +0000101 /** @hide **/
Clara Bayarri35a078f2017-05-26 13:09:56 +0100102 @TestApi
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +0000103 public boolean isSystemGroup() {
104 return mSystemGroup;
105 }
106
Clara Bayarri75e09792015-07-29 16:20:40 +0100107 /**
108 * Adds an item to the existing list.
109 *
110 * @param item The item to be added.
111 */
112 public void addItem(KeyboardShortcutInfo item) {
113 mItems.add(item);
114 }
115
116 @Override
117 public int describeContents() {
118 return 0;
119 }
120
121 @Override
122 public void writeToParcel(Parcel dest, int flags) {
123 dest.writeCharSequence(mLabel);
124 dest.writeTypedList(mItems);
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +0000125 dest.writeInt(mSystemGroup ? 1 : 0);
Clara Bayarri75e09792015-07-29 16:20:40 +0100126 }
127
128 public static final Creator<KeyboardShortcutGroup> CREATOR =
129 new Creator<KeyboardShortcutGroup>() {
Clara Bayarri35a078f2017-05-26 13:09:56 +0100130 public KeyboardShortcutGroup createFromParcel(Parcel source) {
131 return new KeyboardShortcutGroup(source);
132 }
133 public KeyboardShortcutGroup[] newArray(int size) {
134 return new KeyboardShortcutGroup[size];
135 }
136 };
Andrei Stingaceanu8861cb02016-01-20 16:48:30 +0000137}