Debian Codegraph @

core/java/android/view/selectiontoolbar/ToolbarMenuItem.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 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 android.view.selectiontoolbar;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.graphics.drawable.Icon;
22 import android.os.Parcelable;
23 import android.view.MenuItem;
24
25 import com.android.internal.util.DataClass;
26
27 /**
28 * The menu item that is used to show the selection toolbar.
29 *
30 * @hide
31 */
32 @DataClass(genBuilder = true, genToString = true, genEqualsHashCode = true)
33 public final class ToolbarMenuItem implements Parcelable {
34
35 /**
36 * The priority of menu item is unknown.
37 */
38 public static final int PRIORITY_UNKNOWN = 0;
39
40 /**
41 * The priority of menu item is shown in primary selection toolbar.
42 */
43 public static final int PRIORITY_PRIMARY = 1;
44
45 /**
46 * The priority of menu item is shown in overflow selection toolbar.
47 */
48 public static final int PRIORITY_OVERFLOW = 2;
49
50 /**
51 * The id of the menu item.
52 *
53 * @see MenuItem#getItemId()
54 */
55 private final int mItemId;
56
57 /**
58 * The title of the menu item.
59 *
60 * @see MenuItem#getTitle()
61 */
62 @NonNull
63 private final CharSequence mTitle;
64
65 /**
66 * The content description of the menu item.
67 *
68 * @see MenuItem#getContentDescription()
69 */
70 @Nullable
71 private final CharSequence mContentDescription;
72
73 /**
74 * The group id of the menu item.
75 *
76 * @see MenuItem#getGroupId()
77 */
78 private final int mGroupId;
79
80 /**
81 * The icon id of the menu item.
82 *
83 * @see MenuItem#getIcon()
84 */
85 @Nullable
86 private final Icon mIcon;
87
88 /**
89 * The tooltip text of the menu item.
90 *
91 * @see MenuItem#getTooltipText()
92 */
93 @Nullable
94 private final CharSequence mTooltipText;
95
96 /**
97 * The priority of the menu item used to display the order of the menu item.
98 */
99 private final int mPriority;
100
101 /**
102 * Returns the priority from a given {@link MenuItem}.
103 */
104 public static int getPriorityFromMenuItem(MenuItem menuItem) {
105 if (menuItem.requiresActionButton()) {
106 return PRIORITY_PRIMARY;
107 } else if (menuItem.requiresOverflow()) {
108 return PRIORITY_OVERFLOW;
109 }
110 return PRIORITY_UNKNOWN;
111 }
112
113
114
115
116 // Code below generated by codegen v1.0.23.
117 //
118 // DO NOT MODIFY!
119 // CHECKSTYLE:OFF Generated code
120 //
121 // To regenerate run:
122 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/selectiontoolbar/ToolbarMenuItem.java
123 //
124 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
125 // Settings > Editor > Code Style > Formatter Control
126 //@formatter:off
127
128
129 @android.annotation.IntDef(prefix = "PRIORITY_", value = {
130 PRIORITY_UNKNOWN,
131 PRIORITY_PRIMARY,
132 PRIORITY_OVERFLOW
133 })
134 @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
135 @DataClass.Generated.Member
136 public @interface Priority {}
137
138 @DataClass.Generated.Member
139 public static String priorityToString(@Priority int value) {
140 switch (value) {
141 case PRIORITY_UNKNOWN:
142 return "PRIORITY_UNKNOWN";
143 case PRIORITY_PRIMARY:
144 return "PRIORITY_PRIMARY";
145 case PRIORITY_OVERFLOW:
146 return "PRIORITY_OVERFLOW";
147 default: return Integer.toHexString(value);
148 }
149 }
150
151 @DataClass.Generated.Member
152 /* package-private */ ToolbarMenuItem(
153 int itemId,
154 @NonNull CharSequence title,
155 @Nullable CharSequence contentDescription,
156 int groupId,
157 @Nullable Icon icon,
158 @Nullable CharSequence tooltipText,
159 int priority) {
160 this.mItemId = itemId;
161 this.mTitle = title;
162 com.android.internal.util.AnnotationValidations.validate(
163 NonNull.class, null, mTitle);
164 this.mContentDescription = contentDescription;
165 this.mGroupId = groupId;
166 this.mIcon = icon;
167 this.mTooltipText = tooltipText;
168 this.mPriority = priority;
169
170 // onConstructed(); // You can define this method to get a callback
171 }
172
173 /**
174 * The id of the menu item.
175 *
176 * @see MenuItem#getItemId()
177 */
178 @DataClass.Generated.Member
179 public int getItemId() {
180 return mItemId;
181 }
182
183 /**
184 * The title of the menu item.
185 *
186 * @see MenuItem#getTitle()
187 */
188 @DataClass.Generated.Member
189 public @NonNull CharSequence getTitle() {
190 return mTitle;
191 }
192
193 /**
194 * The content description of the menu item.
195 *
196 * @see MenuItem#getContentDescription()
197 */
198 @DataClass.Generated.Member
199 public @Nullable CharSequence getContentDescription() {
200 return mContentDescription;
201 }
202
203 /**
204 * The group id of the menu item.
205 *
206 * @see MenuItem#getGroupId()
207 */
208 @DataClass.Generated.Member
209 public int getGroupId() {
210 return mGroupId;
211 }
212
213 /**
214 * The icon id of the menu item.
215 *
216 * @see MenuItem#getIcon()
217 */
218 @DataClass.Generated.Member
219 public @Nullable Icon getIcon() {
220 return mIcon;
221 }
222
223 /**
224 * The tooltip text of the menu item.
225 *
226 * @see MenuItem#getTooltipText()
227 */
228 @DataClass.Generated.Member
229 public @Nullable CharSequence getTooltipText() {
230 return mTooltipText;
231 }
232
233 /**
234 * The priority of the menu item used to display the order of the menu item.
235 */
236 @DataClass.Generated.Member
237 public int getPriority() {
238 return mPriority;
239 }
240
241 @Override
242 @DataClass.Generated.Member
243 public String toString() {
244 // You can override field toString logic by defining methods like:
245 // String fieldNameToString() { ... }
246
247 return "ToolbarMenuItem { " +
248 "itemId = " + mItemId + ", " +
249 "title = " + mTitle + ", " +
250 "contentDescription = " + mContentDescription + ", " +
251 "groupId = " + mGroupId + ", " +
252 "icon = " + mIcon + ", " +
253 "tooltipText = " + mTooltipText + ", " +
254 "priority = " + mPriority +
255 " }";
256 }
257
258 @Override
259 @DataClass.Generated.Member
260 public boolean equals(@Nullable Object o) {
261 // You can override field equality logic by defining either of the methods like:
262 // boolean fieldNameEquals(ToolbarMenuItem other) { ... }
263 // boolean fieldNameEquals(FieldType otherValue) { ... }
264
265 if (this == o) return true;
266 if (o == null || getClass() != o.getClass()) return false;
267 @SuppressWarnings("unchecked")
268 ToolbarMenuItem that = (ToolbarMenuItem) o;
269 //noinspection PointlessBooleanExpression
270 return true
271 && mItemId == that.mItemId
272 && java.util.Objects.equals(mTitle, that.mTitle)
273 && java.util.Objects.equals(mContentDescription, that.mContentDescription)
274 && mGroupId == that.mGroupId
275 && java.util.Objects.equals(mIcon, that.mIcon)
276 && java.util.Objects.equals(mTooltipText, that.mTooltipText)
277 && mPriority == that.mPriority;
278 }
279
280 @Override
281 @DataClass.Generated.Member
282 public int hashCode() {
283 // You can override field hashCode logic by defining methods like:
284 // int fieldNameHashCode() { ... }
285
286 int _hash = 1;
287 _hash = 31 * _hash + mItemId;
288 _hash = 31 * _hash + java.util.Objects.hashCode(mTitle);
289 _hash = 31 * _hash + java.util.Objects.hashCode(mContentDescription);
290 _hash = 31 * _hash + mGroupId;
291 _hash = 31 * _hash + java.util.Objects.hashCode(mIcon);
292 _hash = 31 * _hash + java.util.Objects.hashCode(mTooltipText);
293 _hash = 31 * _hash + mPriority;
294 return _hash;
295 }
296
297 @Override
298 @DataClass.Generated.Member
299 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
300 // You can override field parcelling by defining methods like:
301 // void parcelFieldName(Parcel dest, int flags) { ... }
302
303 byte flg = 0;
304 if (mContentDescription != null) flg |= 0x4;
305 if (mIcon != null) flg |= 0x10;
306 if (mTooltipText != null) flg |= 0x20;
307 dest.writeByte(flg);
308 dest.writeInt(mItemId);
309 dest.writeCharSequence(mTitle);
310 if (mContentDescription != null) dest.writeCharSequence(mContentDescription);
311 dest.writeInt(mGroupId);
312 if (mIcon != null) dest.writeTypedObject(mIcon, flags);
313 if (mTooltipText != null) dest.writeCharSequence(mTooltipText);
314 dest.writeInt(mPriority);
315 }
316
317 @Override
318 @DataClass.Generated.Member
319 public int describeContents() { return 0; }
320
321 /** @hide */
322 @SuppressWarnings({"unchecked", "RedundantCast"})
323 @DataClass.Generated.Member
324 /* package-private */ ToolbarMenuItem(@NonNull android.os.Parcel in) {
325 // You can override field unparcelling by defining methods like:
326 // static FieldType unparcelFieldName(Parcel in) { ... }
327
328 byte flg = in.readByte();
329 int itemId = in.readInt();
330 CharSequence title = (CharSequence) in.readCharSequence();
331 CharSequence contentDescription = (flg & 0x4) == 0 ? null : (CharSequence) in.readCharSequence();
332 int groupId = in.readInt();
333 Icon icon = (flg & 0x10) == 0 ? null : (Icon) in.readTypedObject(Icon.CREATOR);
334 CharSequence tooltipText = (flg & 0x20) == 0 ? null : (CharSequence) in.readCharSequence();
335 int priority = in.readInt();
336
337 this.mItemId = itemId;
338 this.mTitle = title;
339 com.android.internal.util.AnnotationValidations.validate(
340 NonNull.class, null, mTitle);
341 this.mContentDescription = contentDescription;
342 this.mGroupId = groupId;
343 this.mIcon = icon;
344 this.mTooltipText = tooltipText;
345 this.mPriority = priority;
346
347 // onConstructed(); // You can define this method to get a callback
348 }
349
350 @DataClass.Generated.Member
351 public static final @NonNull Parcelable.Creator<ToolbarMenuItem> CREATOR
352 = new Parcelable.Creator<ToolbarMenuItem>() {
353 @Override
354 public ToolbarMenuItem[] newArray(int size) {
355 return new ToolbarMenuItem[size];
356 }
357
358 @Override
359 public ToolbarMenuItem createFromParcel(@NonNull android.os.Parcel in) {
360 return new ToolbarMenuItem(in);
361 }
362 };
363
364 /**
365 * A builder for {@link ToolbarMenuItem}
366 */
367 @SuppressWarnings("WeakerAccess")
368 @DataClass.Generated.Member
369 public static final class Builder {
370
371 private int mItemId;
372 private @NonNull CharSequence mTitle;
373 private @Nullable CharSequence mContentDescription;
374 private int mGroupId;
375 private @Nullable Icon mIcon;
376 private @Nullable CharSequence mTooltipText;
377 private int mPriority;
378
379 private long mBuilderFieldsSet = 0L;
380
381 /**
382 * Creates a new Builder.
383 *
384 * @param itemId
385 * The id of the menu item.
386 * @param title
387 * The title of the menu item.
388 * @param contentDescription
389 * The content description of the menu item.
390 * @param groupId
391 * The group id of the menu item.
392 * @param icon
393 * The icon id of the menu item.
394 * @param tooltipText
395 * The tooltip text of the menu item.
396 * @param priority
397 * The priority of the menu item used to display the order of the menu item.
398 */
399 public Builder(
400 int itemId,
401 @NonNull CharSequence title,
402 @Nullable CharSequence contentDescription,
403 int groupId,
404 @Nullable Icon icon,
405 @Nullable CharSequence tooltipText,
406 int priority) {
407 mItemId = itemId;
408 mTitle = title;
409 com.android.internal.util.AnnotationValidations.validate(
410 NonNull.class, null, mTitle);
411 mContentDescription = contentDescription;
412 mGroupId = groupId;
413 mIcon = icon;
414 mTooltipText = tooltipText;
415 mPriority = priority;
416 }
417
418 /**
419 * The id of the menu item.
420 *
421 * @see MenuItem#getItemId()
422 */
423 @DataClass.Generated.Member
424 public @NonNull Builder setItemId(int value) {
425 checkNotUsed();
426 mBuilderFieldsSet |= 0x1;
427 mItemId = value;
428 return this;
429 }
430
431 /**
432 * The title of the menu item.
433 *
434 * @see MenuItem#getTitle()
435 */
436 @DataClass.Generated.Member
437 public @NonNull Builder setTitle(@NonNull CharSequence value) {
438 checkNotUsed();
439 mBuilderFieldsSet |= 0x2;
440 mTitle = value;
441 return this;
442 }
443
444 /**
445 * The content description of the menu item.
446 *
447 * @see MenuItem#getContentDescription()
448 */
449 @DataClass.Generated.Member
450 public @NonNull Builder setContentDescription(@NonNull CharSequence value) {
451 checkNotUsed();
452 mBuilderFieldsSet |= 0x4;
453 mContentDescription = value;
454 return this;
455 }
456
457 /**
458 * The group id of the menu item.
459 *
460 * @see MenuItem#getGroupId()
461 */
462 @DataClass.Generated.Member
463 public @NonNull Builder setGroupId(int value) {
464 checkNotUsed();
465 mBuilderFieldsSet |= 0x8;
466 mGroupId = value;
467 return this;
468 }
469
470 /**
471 * The icon id of the menu item.
472 *
473 * @see MenuItem#getIcon()
474 */
475 @DataClass.Generated.Member
476 public @NonNull Builder setIcon(@NonNull Icon value) {
477 checkNotUsed();
478 mBuilderFieldsSet |= 0x10;
479 mIcon = value;
480 return this;
481 }
482
483 /**
484 * The tooltip text of the menu item.
485 *
486 * @see MenuItem#getTooltipText()
487 */
488 @DataClass.Generated.Member
489 public @NonNull Builder setTooltipText(@NonNull CharSequence value) {
490 checkNotUsed();
491 mBuilderFieldsSet |= 0x20;
492 mTooltipText = value;
493 return this;
494 }
495
496 /**
497 * The priority of the menu item used to display the order of the menu item.
498 */
499 @DataClass.Generated.Member
500 public @NonNull Builder setPriority(int value) {
501 checkNotUsed();
502 mBuilderFieldsSet |= 0x40;
503 mPriority = value;
504 return this;
505 }
506
507 /** Builds the instance. This builder should not be touched after calling this! */
508 public @NonNull ToolbarMenuItem build() {
509 checkNotUsed();
510 mBuilderFieldsSet |= 0x80; // Mark builder used
511
512 ToolbarMenuItem o = new ToolbarMenuItem(
513 mItemId,
514 mTitle,
515 mContentDescription,
516 mGroupId,
517 mIcon,
518 mTooltipText,
519 mPriority);
520 return o;
521 }
522
523 private void checkNotUsed() {
524 if ((mBuilderFieldsSet & 0x80) != 0) {
525 throw new IllegalStateException(
526 "This Builder should not be reused. Use a new Builder instance instead");
527 }
528 }
529 }
530
531 @DataClass.Generated(
532 time = 1643200806234L,
533 codegenVersion = "1.0.23",
534 sourceFile = "frameworks/base/core/java/android/view/selectiontoolbar/ToolbarMenuItem.java",
535 inputSignatures = "public static final int PRIORITY_UNKNOWN\npublic static final int PRIORITY_PRIMARY\npublic static final int PRIORITY_OVERFLOW\nprivate final int mItemId\nprivate final @android.annotation.NonNull java.lang.CharSequence mTitle\nprivate final @android.annotation.Nullable java.lang.CharSequence mContentDescription\nprivate final int mGroupId\nprivate final @android.annotation.Nullable android.graphics.drawable.Icon mIcon\nprivate final @android.annotation.Nullable java.lang.CharSequence mTooltipText\nprivate final int mPriority\npublic static int getPriorityFromMenuItem(android.view.MenuItem)\nclass ToolbarMenuItem extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genBuilder=true, genToString=true, genEqualsHashCode=true)")
536 @Deprecated
537 private void __metadata() {}
538
539
540 //@formatter:on
541 // End of generated code
542
543 }