Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package android.view; |
| 17 | |
Aurimas Liutikas | 67e2ae8 | 2016-10-11 18:17:42 -0700 | [diff] [blame] | 18 | import static com.android.internal.util.Preconditions.checkNotNull; |
| 19 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 20 | import android.annotation.NonNull; |
| 21 | import android.annotation.Nullable; |
| 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| 24 | |
| 25 | import java.util.ArrayList; |
| 26 | import java.util.Collections; |
| 27 | import java.util.List; |
| 28 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 29 | /** |
| 30 | * A group of {@link KeyboardShortcutInfo}. |
| 31 | */ |
| 32 | public final class KeyboardShortcutGroup implements Parcelable { |
| 33 | private final CharSequence mLabel; |
| 34 | private final List<KeyboardShortcutInfo> mItems; |
Andrei Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 35 | // The system group looks different UI wise. |
| 36 | private boolean mSystemGroup; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 37 | |
| 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 55 | /** |
| 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 Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 77 | private KeyboardShortcutGroup(Parcel source) { |
| 78 | mItems = new ArrayList<>(); |
| 79 | mLabel = source.readCharSequence(); |
| 80 | source.readTypedList(mItems, KeyboardShortcutInfo.CREATOR); |
Andrei Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 81 | mSystemGroup = source.readInt() == 1; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 82 | } |
| 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 98 | /** @hide **/ |
| 99 | public boolean isSystemGroup() { |
| 100 | return mSystemGroup; |
| 101 | } |
| 102 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 103 | /** |
| 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 121 | dest.writeInt(mSystemGroup ? 1 : 0); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 122 | } |
| 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 133 | } |