File: ToolbarMenuItem.java

package info (click to toggle)
android-platform-frameworks-base 1%3A14~beta1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 326,084 kB
  • sloc: java: 2,032,373; xml: 343,016; cpp: 304,181; python: 3,683; ansic: 2,090; sh: 1,871; makefile: 120; sed: 19
file content (543 lines) | stat: -rw-r--r-- 17,345 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.view.selectiontoolbar;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.drawable.Icon;
import android.os.Parcelable;
import android.view.MenuItem;

import com.android.internal.util.DataClass;

/**
 * The menu item that is used to show the selection toolbar.
 *
 * @hide
 */
@DataClass(genBuilder = true, genToString = true, genEqualsHashCode = true)
public final class ToolbarMenuItem implements Parcelable {

    /**
     * The priority of menu item is unknown.
     */
    public static final int PRIORITY_UNKNOWN = 0;

    /**
     * The priority of menu item is shown in primary selection toolbar.
     */
    public static final int PRIORITY_PRIMARY = 1;

    /**
     * The priority of menu item is shown in overflow selection toolbar.
     */
    public static final int PRIORITY_OVERFLOW = 2;

    /**
     * The id of the menu item.
     *
     * @see MenuItem#getItemId()
     */
    private final int mItemId;

    /**
     * The title of the menu item.
     *
     * @see MenuItem#getTitle()
     */
    @NonNull
    private final CharSequence mTitle;

    /**
     * The content description of the menu item.
     *
     * @see MenuItem#getContentDescription()
     */
    @Nullable
    private final CharSequence mContentDescription;

    /**
     * The group id of the menu item.
     *
     * @see MenuItem#getGroupId()
     */
    private final int mGroupId;

    /**
     * The icon id of the menu item.
     *
     * @see MenuItem#getIcon()
     */
    @Nullable
    private final Icon mIcon;

    /**
     * The tooltip text of the menu item.
     *
     * @see MenuItem#getTooltipText()
     */
    @Nullable
    private final CharSequence mTooltipText;

    /**
     * The priority of the menu item used to display the order of the menu item.
     */
    private final int mPriority;

    /**
     * Returns the priority from a given {@link MenuItem}.
     */
    public static int getPriorityFromMenuItem(MenuItem menuItem) {
        if (menuItem.requiresActionButton()) {
            return PRIORITY_PRIMARY;
        } else if (menuItem.requiresOverflow()) {
            return PRIORITY_OVERFLOW;
        }
        return PRIORITY_UNKNOWN;
    }




    // Code below generated by codegen v1.0.23.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/selectiontoolbar/ToolbarMenuItem.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    @android.annotation.IntDef(prefix = "PRIORITY_", value = {
        PRIORITY_UNKNOWN,
        PRIORITY_PRIMARY,
        PRIORITY_OVERFLOW
    })
    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
    @DataClass.Generated.Member
    public @interface Priority {}

    @DataClass.Generated.Member
    public static String priorityToString(@Priority int value) {
        switch (value) {
            case PRIORITY_UNKNOWN:
                    return "PRIORITY_UNKNOWN";
            case PRIORITY_PRIMARY:
                    return "PRIORITY_PRIMARY";
            case PRIORITY_OVERFLOW:
                    return "PRIORITY_OVERFLOW";
            default: return Integer.toHexString(value);
        }
    }

    @DataClass.Generated.Member
    /* package-private */ ToolbarMenuItem(
            int itemId,
            @NonNull CharSequence title,
            @Nullable CharSequence contentDescription,
            int groupId,
            @Nullable Icon icon,
            @Nullable CharSequence tooltipText,
            int priority) {
        this.mItemId = itemId;
        this.mTitle = title;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mTitle);
        this.mContentDescription = contentDescription;
        this.mGroupId = groupId;
        this.mIcon = icon;
        this.mTooltipText = tooltipText;
        this.mPriority = priority;

        // onConstructed(); // You can define this method to get a callback
    }

    /**
     * The id of the menu item.
     *
     * @see MenuItem#getItemId()
     */
    @DataClass.Generated.Member
    public int getItemId() {
        return mItemId;
    }

    /**
     * The title of the menu item.
     *
     * @see MenuItem#getTitle()
     */
    @DataClass.Generated.Member
    public @NonNull CharSequence getTitle() {
        return mTitle;
    }

    /**
     * The content description of the menu item.
     *
     * @see MenuItem#getContentDescription()
     */
    @DataClass.Generated.Member
    public @Nullable CharSequence getContentDescription() {
        return mContentDescription;
    }

    /**
     * The group id of the menu item.
     *
     * @see MenuItem#getGroupId()
     */
    @DataClass.Generated.Member
    public int getGroupId() {
        return mGroupId;
    }

    /**
     * The icon id of the menu item.
     *
     * @see MenuItem#getIcon()
     */
    @DataClass.Generated.Member
    public @Nullable Icon getIcon() {
        return mIcon;
    }

    /**
     * The tooltip text of the menu item.
     *
     * @see MenuItem#getTooltipText()
     */
    @DataClass.Generated.Member
    public @Nullable CharSequence getTooltipText() {
        return mTooltipText;
    }

    /**
     * The priority of the menu item used to display the order of the menu item.
     */
    @DataClass.Generated.Member
    public int getPriority() {
        return mPriority;
    }

    @Override
    @DataClass.Generated.Member
    public String toString() {
        // You can override field toString logic by defining methods like:
        // String fieldNameToString() { ... }

        return "ToolbarMenuItem { " +
                "itemId = " + mItemId + ", " +
                "title = " + mTitle + ", " +
                "contentDescription = " + mContentDescription + ", " +
                "groupId = " + mGroupId + ", " +
                "icon = " + mIcon + ", " +
                "tooltipText = " + mTooltipText + ", " +
                "priority = " + mPriority +
        " }";
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@Nullable Object o) {
        // You can override field equality logic by defining either of the methods like:
        // boolean fieldNameEquals(ToolbarMenuItem other) { ... }
        // boolean fieldNameEquals(FieldType otherValue) { ... }

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        @SuppressWarnings("unchecked")
        ToolbarMenuItem that = (ToolbarMenuItem) o;
        //noinspection PointlessBooleanExpression
        return true
                && mItemId == that.mItemId
                && java.util.Objects.equals(mTitle, that.mTitle)
                && java.util.Objects.equals(mContentDescription, that.mContentDescription)
                && mGroupId == that.mGroupId
                && java.util.Objects.equals(mIcon, that.mIcon)
                && java.util.Objects.equals(mTooltipText, that.mTooltipText)
                && mPriority == that.mPriority;
    }

    @Override
    @DataClass.Generated.Member
    public int hashCode() {
        // You can override field hashCode logic by defining methods like:
        // int fieldNameHashCode() { ... }

        int _hash = 1;
        _hash = 31 * _hash + mItemId;
        _hash = 31 * _hash + java.util.Objects.hashCode(mTitle);
        _hash = 31 * _hash + java.util.Objects.hashCode(mContentDescription);
        _hash = 31 * _hash + mGroupId;
        _hash = 31 * _hash + java.util.Objects.hashCode(mIcon);
        _hash = 31 * _hash + java.util.Objects.hashCode(mTooltipText);
        _hash = 31 * _hash + mPriority;
        return _hash;
    }

    @Override
    @DataClass.Generated.Member
    public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }

        byte flg = 0;
        if (mContentDescription != null) flg |= 0x4;
        if (mIcon != null) flg |= 0x10;
        if (mTooltipText != null) flg |= 0x20;
        dest.writeByte(flg);
        dest.writeInt(mItemId);
        dest.writeCharSequence(mTitle);
        if (mContentDescription != null) dest.writeCharSequence(mContentDescription);
        dest.writeInt(mGroupId);
        if (mIcon != null) dest.writeTypedObject(mIcon, flags);
        if (mTooltipText != null) dest.writeCharSequence(mTooltipText);
        dest.writeInt(mPriority);
    }

    @Override
    @DataClass.Generated.Member
    public int describeContents() { return 0; }

    /** @hide */
    @SuppressWarnings({"unchecked", "RedundantCast"})
    @DataClass.Generated.Member
    /* package-private */ ToolbarMenuItem(@NonNull android.os.Parcel in) {
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }

        byte flg = in.readByte();
        int itemId = in.readInt();
        CharSequence title = (CharSequence) in.readCharSequence();
        CharSequence contentDescription = (flg & 0x4) == 0 ? null : (CharSequence) in.readCharSequence();
        int groupId = in.readInt();
        Icon icon = (flg & 0x10) == 0 ? null : (Icon) in.readTypedObject(Icon.CREATOR);
        CharSequence tooltipText = (flg & 0x20) == 0 ? null : (CharSequence) in.readCharSequence();
        int priority = in.readInt();

        this.mItemId = itemId;
        this.mTitle = title;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mTitle);
        this.mContentDescription = contentDescription;
        this.mGroupId = groupId;
        this.mIcon = icon;
        this.mTooltipText = tooltipText;
        this.mPriority = priority;

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public static final @NonNull Parcelable.Creator<ToolbarMenuItem> CREATOR
            = new Parcelable.Creator<ToolbarMenuItem>() {
        @Override
        public ToolbarMenuItem[] newArray(int size) {
            return new ToolbarMenuItem[size];
        }

        @Override
        public ToolbarMenuItem createFromParcel(@NonNull android.os.Parcel in) {
            return new ToolbarMenuItem(in);
        }
    };

    /**
     * A builder for {@link ToolbarMenuItem}
     */
    @SuppressWarnings("WeakerAccess")
    @DataClass.Generated.Member
    public static final class Builder {

        private int mItemId;
        private @NonNull CharSequence mTitle;
        private @Nullable CharSequence mContentDescription;
        private int mGroupId;
        private @Nullable Icon mIcon;
        private @Nullable CharSequence mTooltipText;
        private int mPriority;

        private long mBuilderFieldsSet = 0L;

        /**
         * Creates a new Builder.
         *
         * @param itemId
         *   The id of the menu item.
         * @param title
         *   The title of the menu item.
         * @param contentDescription
         *   The content description of the menu item.
         * @param groupId
         *   The group id of the menu item.
         * @param icon
         *   The icon id of the menu item.
         * @param tooltipText
         *   The tooltip text of the menu item.
         * @param priority
         *   The priority of the menu item used to display the order of the menu item.
         */
        public Builder(
                int itemId,
                @NonNull CharSequence title,
                @Nullable CharSequence contentDescription,
                int groupId,
                @Nullable Icon icon,
                @Nullable CharSequence tooltipText,
                int priority) {
            mItemId = itemId;
            mTitle = title;
            com.android.internal.util.AnnotationValidations.validate(
                    NonNull.class, null, mTitle);
            mContentDescription = contentDescription;
            mGroupId = groupId;
            mIcon = icon;
            mTooltipText = tooltipText;
            mPriority = priority;
        }

        /**
         * The id of the menu item.
         *
         * @see MenuItem#getItemId()
         */
        @DataClass.Generated.Member
        public @NonNull Builder setItemId(int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x1;
            mItemId = value;
            return this;
        }

        /**
         * The title of the menu item.
         *
         * @see MenuItem#getTitle()
         */
        @DataClass.Generated.Member
        public @NonNull Builder setTitle(@NonNull CharSequence value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x2;
            mTitle = value;
            return this;
        }

        /**
         * The content description of the menu item.
         *
         * @see MenuItem#getContentDescription()
         */
        @DataClass.Generated.Member
        public @NonNull Builder setContentDescription(@NonNull CharSequence value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x4;
            mContentDescription = value;
            return this;
        }

        /**
         * The group id of the menu item.
         *
         * @see MenuItem#getGroupId()
         */
        @DataClass.Generated.Member
        public @NonNull Builder setGroupId(int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x8;
            mGroupId = value;
            return this;
        }

        /**
         * The icon id of the menu item.
         *
         * @see MenuItem#getIcon()
         */
        @DataClass.Generated.Member
        public @NonNull Builder setIcon(@NonNull Icon value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x10;
            mIcon = value;
            return this;
        }

        /**
         * The tooltip text of the menu item.
         *
         * @see MenuItem#getTooltipText()
         */
        @DataClass.Generated.Member
        public @NonNull Builder setTooltipText(@NonNull CharSequence value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x20;
            mTooltipText = value;
            return this;
        }

        /**
         * The priority of the menu item used to display the order of the menu item.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setPriority(int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x40;
            mPriority = value;
            return this;
        }

        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull ToolbarMenuItem build() {
            checkNotUsed();
            mBuilderFieldsSet |= 0x80; // Mark builder used

            ToolbarMenuItem o = new ToolbarMenuItem(
                    mItemId,
                    mTitle,
                    mContentDescription,
                    mGroupId,
                    mIcon,
                    mTooltipText,
                    mPriority);
            return o;
        }

        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x80) != 0) {
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
        }
    }

    @DataClass.Generated(
            time = 1643200806234L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/view/selectiontoolbar/ToolbarMenuItem.java",
            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)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}