| 12
 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
 
 | /*
 * Copyright (C) 2022 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.service.chooser;
import android.annotation.NonNull;
import android.app.PendingIntent;
import android.graphics.drawable.Icon;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.util.Objects;
/**
 * A ChooserAction is an app-defined action that can be provided to the Android Sharesheet to
 * be shown to the user when {@link android.content.Intent.ACTION_CHOOSER} is invoked.
 *
 * @see android.content.Intent.EXTRA_CHOOSER_CUSTOM_ACTIONS
 * @see android.content.Intent.EXTRA_CHOOSER_PAYLOAD_RESELECTION_ACTION
 * @hide
 */
public final class ChooserAction implements Parcelable {
    private final Icon mIcon;
    private final CharSequence mLabel;
    private final PendingIntent mAction;
    private ChooserAction(
            Icon icon,
            CharSequence label,
            PendingIntent action) {
        mIcon = icon;
        mLabel = label;
        mAction = action;
    }
    /**
     * Return a user-readable label for this action.
     */
    @NonNull
    public CharSequence getLabel() {
        return mLabel;
    }
    /**
     * Return an {@link Icon} representing this action.
     */
    @NonNull
    public Icon getIcon() {
        return mIcon;
    }
    /**
     * Return the action intent.
     */
    @NonNull
    public PendingIntent getAction() {
        return mAction;
    }
    @Override
    public int describeContents() {
        return 0;
    }
    @Override
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        mIcon.writeToParcel(dest, flags);
        TextUtils.writeToParcel(mLabel, dest, flags);
        mAction.writeToParcel(dest, flags);
    }
    @Override
    public String toString() {
        return "ChooserAction {" + "label=" + mLabel + ", intent=" + mAction + "}";
    }
    public static final Parcelable.Creator<ChooserAction> CREATOR =
            new Creator<ChooserAction>() {
                @Override
                public ChooserAction createFromParcel(Parcel source) {
                    return new ChooserAction(
                            Icon.CREATOR.createFromParcel(source),
                            TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source),
                            PendingIntent.CREATOR.createFromParcel(source));
                }
                @Override
                public ChooserAction[] newArray(int size) {
                    return new ChooserAction[size];
                }
            };
    /**
     * Builder class for {@link ChooserAction} objects
     */
    public static final class Builder {
        private final Icon mIcon;
        private final CharSequence mLabel;
        private final PendingIntent mAction;
        /**
         * Construct a new builder for {@link ChooserAction} object.
         *
         * @param icon an {@link Icon} representing this action, consisting of a white foreground
         * atop a transparent background.
         * @param label label the user-readable label for this action.
         * @param action {@link PendingIntent} to be invoked when the action is selected.
         */
        public Builder(
                @NonNull Icon icon,
                @NonNull CharSequence label,
                @NonNull PendingIntent action) {
            Objects.requireNonNull(icon, "icon can not be null");
            Objects.requireNonNull(label, "label can not be null");
            Objects.requireNonNull(action, "pending intent can not be null");
            mIcon = icon;
            mLabel = label;
            mAction = action;
        }
        /**
         * Combine all of the options that have been set and return a new {@link ChooserAction}
         * object.
         * @return the built action
         */
        public ChooserAction build() {
            return new ChooserAction(mIcon, mLabel, mAction);
        }
    }
}
 |