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; |
Clara Bayarri | 35a078f | 2017-05-26 13:09:56 +0100 | [diff] [blame] | 22 | import android.annotation.TestApi; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 23 | import android.os.Parcel; |
| 24 | import android.os.Parcelable; |
| 25 | |
| 26 | import java.util.ArrayList; |
| 27 | import java.util.Collections; |
| 28 | import java.util.List; |
| 29 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 30 | /** |
| 31 | * A group of {@link KeyboardShortcutInfo}. |
| 32 | */ |
| 33 | public final class KeyboardShortcutGroup implements Parcelable { |
| 34 | private final CharSequence mLabel; |
| 35 | private final List<KeyboardShortcutInfo> mItems; |
Andrei Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 36 | // The system group looks different UI wise. |
| 37 | private boolean mSystemGroup; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 38 | |
| 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 56 | /** |
| 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 Bayarri | 35a078f | 2017-05-26 13:09:56 +0100 | [diff] [blame] | 62 | @TestApi |
Andrei Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 63 | 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 Bayarri | 35a078f | 2017-05-26 13:09:56 +0100 | [diff] [blame] | 75 | @TestApi |
Andrei Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 76 | public KeyboardShortcutGroup(@Nullable CharSequence label, boolean isSystemGroup) { |
| 77 | this(label, Collections.<KeyboardShortcutInfo>emptyList(), isSystemGroup); |
| 78 | } |
| 79 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 80 | private KeyboardShortcutGroup(Parcel source) { |
| 81 | mItems = new ArrayList<>(); |
| 82 | mLabel = source.readCharSequence(); |
| 83 | source.readTypedList(mItems, KeyboardShortcutInfo.CREATOR); |
Andrei Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 84 | mSystemGroup = source.readInt() == 1; |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 85 | } |
| 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 101 | /** @hide **/ |
Clara Bayarri | 35a078f | 2017-05-26 13:09:56 +0100 | [diff] [blame] | 102 | @TestApi |
Andrei Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 103 | public boolean isSystemGroup() { |
| 104 | return mSystemGroup; |
| 105 | } |
| 106 | |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 107 | /** |
| 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 125 | dest.writeInt(mSystemGroup ? 1 : 0); |
Clara Bayarri | 75e0979 | 2015-07-29 16:20:40 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | public static final Creator<KeyboardShortcutGroup> CREATOR = |
| 129 | new Creator<KeyboardShortcutGroup>() { |
Clara Bayarri | 35a078f | 2017-05-26 13:09:56 +0100 | [diff] [blame] | 130 | 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 Stingaceanu | 8861cb0 | 2016-01-20 16:48:30 +0000 | [diff] [blame] | 137 | } |