1ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing/*
2ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * Copyright (C) 2015 The Android Open Source Project
3ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing *
4ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * in compliance with the License. You may obtain a copy of the License at
6ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing *
7ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * http://www.apache.org/licenses/LICENSE-2.0
8ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing *
9ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * Unless required by applicable law or agreed to in writing, software distributed under the License
10ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * or implied. See the License for the specific language governing permissions and limitations under
12ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * the License.
13ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing */
14ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesingpackage android.support.v17.leanback.widget;
15ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
169050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Guimport android.os.Bundle;
17bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Guimport android.support.annotation.DrawableRes;
18bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Guimport android.support.annotation.StringRes;
196f09284ea29241b4d4700ea89111f30517b958e7Dake Guimport android.support.v17.leanback.R;
20bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Guimport android.support.v4.content.ContextCompat;
216f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
22ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesingimport android.content.Context;
23ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesingimport android.content.Intent;
24ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesingimport android.graphics.drawable.Drawable;
259562425bf9bc15281ac27df817141854769c1042Dake Guimport android.text.InputType;
26ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
27be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Guimport java.util.List;
28be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu
29ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing/**
30ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * A data class which represents an action within a {@link
31ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * android.support.v17.leanback.app.GuidedStepFragment}. GuidedActions contain at minimum a title
32ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * and a description, and typically also an icon.
33ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * <p>
34ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * A GuidedAction typically represents a single action a user may take, but may also represent a
35ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * possible choice out of a group of mutually exclusive choices (similar to radio buttons), or an
36ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * information-only label (in which case the item cannot be clicked).
37ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * <p>
38ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * GuidedActions may optionally be checked. They may also indicate that they will request further
39ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing * user input on selection, in which case they will be displayed with a chevron indicator.
40a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu * <p>
41a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu * GuidedAction recommends to use {@link Builder}. When application subclass GuidedAction, it
42b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu * can subclass {@link BuilderBase}, implement its own builder() method where it should
43a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu * call {@link BuilderBase#applyValues(GuidedAction)}.
44ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing */
45ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesingpublic class GuidedAction extends Action {
46ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
47ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    private static final String TAG = "GuidedAction";
48ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
4911cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu    /**
5011cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     * Special check set Id that is neither checkbox nor radio.
5111cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     */
52ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public static final int NO_CHECK_SET = 0;
5311cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu    /**
5411cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     * Default checkset Id for radio.
5511cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     */
56ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public static final int DEFAULT_CHECK_SET_ID = 1;
5711cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu    /**
5811cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     * Checkset Id for checkbox.
5911cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     */
6011cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu    public static final int CHECKBOX_CHECK_SET_ID = -1;
61ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
62ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
63c1741246af607f6be2389056da0182c40f938348Dake Gu     * When finishing editing, goes to next action.
64c1741246af607f6be2389056da0182c40f938348Dake Gu     */
656f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_NEXT = -2;
66c1741246af607f6be2389056da0182c40f938348Dake Gu    /**
67c1741246af607f6be2389056da0182c40f938348Dake Gu     * When finishing editing, stay on current action.
68c1741246af607f6be2389056da0182c40f938348Dake Gu     */
696f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_CURRENT = -3;
706f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
716f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    /**
726f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     * Id of standard OK action.
736f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     */
746f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_OK = -4;
756f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
766f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    /**
776f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     * Id of standard Cancel action.
786f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     */
796f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_CANCEL = -5;
806f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
816f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    /**
826f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     * Id of standard Finish action.
836f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     */
846f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_FINISH = -6;
856f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
866f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    /**
876f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     * Id of standard Finish action.
886f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     */
896f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_CONTINUE = -7;
906f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
916f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    /**
926f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     * Id of standard Yes action.
936f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     */
946f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_YES = -8;
956f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
966f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    /**
976f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     * Id of standard No action.
986f09284ea29241b4d4700ea89111f30517b958e7Dake Gu     */
996f09284ea29241b4d4700ea89111f30517b958e7Dake Gu    public static final long ACTION_ID_NO = -9;
100c1741246af607f6be2389056da0182c40f938348Dake Gu
101b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    static final int EDITING_NONE = 0;
102b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    static final int EDITING_TITLE = 1;
103b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    static final int EDITING_DESCRIPTION = 2;
104b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    static final int EDITING_ACTIVATOR_VIEW = 3;
105b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu
106c1741246af607f6be2389056da0182c40f938348Dake Gu    /**
107a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu     * Base builder class to build a {@link GuidedAction} object.  When subclass GuidedAction, you
108b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu     * can override this BuilderBase class, implements your build() method which should call
109a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu     * {@link #applyValues(GuidedAction)}.  When using GuidedAction directly, use {@link Builder}.
110ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
111b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    public abstract static class BuilderBase<B extends BuilderBase> {
112bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        private Context mContext;
113ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        private long mId;
114c1741246af607f6be2389056da0182c40f938348Dake Gu        private CharSequence mTitle;
115c1741246af607f6be2389056da0182c40f938348Dake Gu        private CharSequence mEditTitle;
116c1741246af607f6be2389056da0182c40f938348Dake Gu        private CharSequence mDescription;
117c1741246af607f6be2389056da0182c40f938348Dake Gu        private CharSequence mEditDescription;
118ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        private Drawable mIcon;
119accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        /**
120accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri         * The mActionFlags holds various action states such as whether title or description are
121accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri         * editable, or the action is focusable.
122accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri         *
123accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri         */
124accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        private int mActionFlags;
125accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri
126b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        private int mEditable = EDITING_NONE;
1279562425bf9bc15281ac27df817141854769c1042Dake Gu        private int mInputType = InputType.TYPE_CLASS_TEXT;
1289562425bf9bc15281ac27df817141854769c1042Dake Gu        private int mDescriptionInputType = InputType.TYPE_CLASS_TEXT;
1299562425bf9bc15281ac27df817141854769c1042Dake Gu        private int mEditInputType = InputType.TYPE_CLASS_TEXT;
1309562425bf9bc15281ac27df817141854769c1042Dake Gu        private int mDescriptionEditInputType = InputType.TYPE_CLASS_TEXT;
131ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        private int mCheckSetId = NO_CHECK_SET;
132be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu        private List<GuidedAction> mSubActions;
133ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        private Intent mIntent;
134ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
135ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
136bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Creates a BuilderBase for GuidedAction or its subclass.
137bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param context Context object used to build the GuidedAction.
138bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
139bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        public BuilderBase(Context context) {
140bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            mContext = context;
1419050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            mActionFlags = PF_ENABLED | PF_FOCUSABLE | PF_AUTORESTORE;
142bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
143bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
144bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
145bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Returns Context of this Builder.
146bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @return Context of this Builder.
147bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
148bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        public Context getContext() {
149bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            return mContext;
150bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
151bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
152accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        private void setFlags(int flag, int mask) {
153accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            mActionFlags = (mActionFlags & ~mask) | (flag & mask);
154accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        }
155accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri
156bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
157a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu         * Subclass of BuilderBase should call this function to apply values.
158a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu         * @param action GuidedAction to apply BuilderBase values.
1597af424644dc8daae5298a5ca2f655770270366feDake Gu         */
1607af424644dc8daae5298a5ca2f655770270366feDake Gu        protected final void applyValues(GuidedAction action) {
161ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            // Base Action values
162ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            action.setId(mId);
163ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            action.setLabel1(mTitle);
1645356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu            action.setEditTitle(mEditTitle);
165ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            action.setLabel2(mDescription);
166c1741246af607f6be2389056da0182c40f938348Dake Gu            action.setEditDescription(mEditDescription);
167ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            action.setIcon(mIcon);
168ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
169ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            // Subclass values
170ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            action.mIntent = mIntent;
1714158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing            action.mEditable = mEditable;
1729562425bf9bc15281ac27df817141854769c1042Dake Gu            action.mInputType = mInputType;
1739562425bf9bc15281ac27df817141854769c1042Dake Gu            action.mDescriptionInputType = mDescriptionInputType;
1749562425bf9bc15281ac27df817141854769c1042Dake Gu            action.mEditInputType = mEditInputType;
1759562425bf9bc15281ac27df817141854769c1042Dake Gu            action.mDescriptionEditInputType = mDescriptionEditInputType;
176accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            action.mActionFlags = mActionFlags;
177ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            action.mCheckSetId = mCheckSetId;
178be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu            action.mSubActions = mSubActions;
179ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
180ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
181ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
182bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Construct a clickable action with associated id and auto assign pre-defined title for the
183bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * action. If the id is not supported, the method simply does nothing.
184bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param id One of {@link GuidedAction#ACTION_ID_OK} {@link GuidedAction#ACTION_ID_CANCEL}
185bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * {@link GuidedAction#ACTION_ID_FINISH} {@link GuidedAction#ACTION_ID_CONTINUE}
186bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * {@link GuidedAction#ACTION_ID_YES} {@link GuidedAction#ACTION_ID_NO}.
187a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu         * @return The same BuilderBase object.
1886f09284ea29241b4d4700ea89111f30517b958e7Dake Gu         */
189b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B clickAction(long id) {
190bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            if (id == ACTION_ID_OK) {
191bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mId = ACTION_ID_OK;
192bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mTitle = mContext.getString(android.R.string.ok);
193bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            } else if (id == ACTION_ID_CANCEL) {
194bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mId = ACTION_ID_CANCEL;
195bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mTitle = mContext.getString(android.R.string.cancel);
196bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            } else if (id == ACTION_ID_FINISH) {
197bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mId = ACTION_ID_FINISH;
198bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mTitle = mContext.getString(R.string.lb_guidedaction_finish_title);
199bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            } else if (id == ACTION_ID_CONTINUE) {
200bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mId = ACTION_ID_CONTINUE;
201bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mTitle = mContext.getString(R.string.lb_guidedaction_continue_title);
202bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            } else if (id == ACTION_ID_YES) {
203bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mId = ACTION_ID_YES;
204bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mTitle = mContext.getString(android.R.string.yes);
205bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            } else if (id == ACTION_ID_NO) {
206bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mId = ACTION_ID_NO;
207bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu                mTitle = mContext.getString(android.R.string.no);
208bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            }
209b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
2106f09284ea29241b4d4700ea89111f30517b958e7Dake Gu        }
2116f09284ea29241b4d4700ea89111f30517b958e7Dake Gu
2126f09284ea29241b4d4700ea89111f30517b958e7Dake Gu        /**
213ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Sets the ID associated with this action.  The ID can be any value the client wishes;
214ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * it is typically used to determine what to do when an action is clicked.
215ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param id The ID to associate with this action.
216ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
217b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B id(long id) {
218ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            mId = id;
219b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
220ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
221ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
222ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
223ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Sets the title for this action.  The title is typically a short string indicating the
224ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * action to be taken on click, e.g. "Continue" or "Cancel".
225ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param title The title for this action.
226ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
227b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B title(CharSequence title) {
228ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            mTitle = title;
229b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
230ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
231ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
232ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
233bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Sets the title for this action.  The title is typically a short string indicating the
234bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * action to be taken on click, e.g. "Continue" or "Cancel".
235bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param titleResourceId The resource id of title for this action.
236bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
237b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B title(@StringRes int titleResourceId) {
238bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            mTitle = getContext().getString(titleResourceId);
239b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
240bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
241bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
242bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
2435356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu         * Sets the optional title text to edit.  When TextView is activated, the edit title
2445356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu         * replaces the string of title.
245bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param editTitle The optional title text to edit when TextView is activated.
2465356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu         */
247b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B editTitle(CharSequence editTitle) {
2485356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu            mEditTitle = editTitle;
249b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
2505356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu        }
2515356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu
2525356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu        /**
253bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Sets the optional title text to edit.  When TextView is activated, the edit title
254bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * replaces the string of title.
255bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param editTitleResourceId String resource id of the optional title text to edit when
256bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * TextView is activated.
257bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
258b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B editTitle(@StringRes int editTitleResourceId) {
259bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            mEditTitle = getContext().getString(editTitleResourceId);
260b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
261bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
262bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
263bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
264ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Sets the description for this action.  The description is typically a longer string
265ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * providing extra information on what the action will do.
266ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param description The description for this action.
267ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
268b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B description(CharSequence description) {
269ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            mDescription = description;
270b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
271ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
272ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
273ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
274bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Sets the description for this action.  The description is typically a longer string
275bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * providing extra information on what the action will do.
276bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param descriptionResourceId String resource id of the description for this action.
277bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
278b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B description(@StringRes int descriptionResourceId) {
279bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            mDescription = getContext().getString(descriptionResourceId);
280b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
281bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
282bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
283bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
284c1741246af607f6be2389056da0182c40f938348Dake Gu         * Sets the optional description text to edit.  When TextView is activated, the edit
285c1741246af607f6be2389056da0182c40f938348Dake Gu         * description replaces the string of description.
286c1741246af607f6be2389056da0182c40f938348Dake Gu         * @param description The description to edit for this action.
287c1741246af607f6be2389056da0182c40f938348Dake Gu         */
288b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B editDescription(CharSequence description) {
289c1741246af607f6be2389056da0182c40f938348Dake Gu            mEditDescription = description;
290b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
291c1741246af607f6be2389056da0182c40f938348Dake Gu        }
292c1741246af607f6be2389056da0182c40f938348Dake Gu
293c1741246af607f6be2389056da0182c40f938348Dake Gu        /**
294bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Sets the optional description text to edit.  When TextView is activated, the edit
295bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * description replaces the string of description.
296bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param descriptionResourceId String resource id of the description to edit for this
297bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * action.
298bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
299b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B editDescription(@StringRes int descriptionResourceId) {
300bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            mEditDescription = getContext().getString(descriptionResourceId);
301b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
302bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
303bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
304bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
305ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Sets the intent associated with this action.  Clients would typically fire this intent
306ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * directly when the action is clicked.
307ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param intent The intent associated with this action.
308ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
309b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B intent(Intent intent) {
310ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            mIntent = intent;
311b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
312ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
313ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
314ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
315ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Sets the action's icon drawable.
316ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param icon The drawable for the icon associated with this action.
317ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
318b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B icon(Drawable icon) {
319ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            mIcon = icon;
320b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
321ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
322ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
323ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
324ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Sets the action's icon drawable by retrieving it by resource ID from the specified
325ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * context. This is a convenience function that simply looks up the drawable and calls
326bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * {@link #icon(Drawable)}.
327ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param iconResourceId The resource ID for the icon associated with this action.
328ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param context The context whose resource ID should be retrieved.
329bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @deprecated Use {@link #icon(int)}.
330ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
331bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        @Deprecated
332b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B iconResourceId(@DrawableRes int iconResourceId, Context context) {
333bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            return icon(ContextCompat.getDrawable(context, iconResourceId));
334bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
335bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
336bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
337bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Sets the action's icon drawable by retrieving it by resource ID from Builder's
338bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * context. This is a convenience function that simply looks up the drawable and calls
339bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * {@link #icon(Drawable)}.
340bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param iconResourceId The resource ID for the icon associated with this action.
341bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
342b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B icon(@DrawableRes int iconResourceId) {
343bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            return icon(ContextCompat.getDrawable(getContext(), iconResourceId));
344ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
345ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
346ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
347e2f7aef2f45dcdfe116995b64f9a7be5c68a36a1Dake Gu         * Indicates whether this action title is editable. Note: Editable actions cannot also be
3484158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing         * checked, or belong to a check set.
3494158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing         * @param editable Whether this action is editable.
3504158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing         */
351b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B editable(boolean editable) {
3527b93b3baf1195fbd286517556b981e25cb542a40Dake Gu            if (!editable) {
3537b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                if (mEditable == EDITING_TITLE) {
3547b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                    mEditable = EDITING_NONE;
3557b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                }
356b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu                return (B) this;
357b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            }
358b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            mEditable = EDITING_TITLE;
359accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            if (isChecked() || mCheckSetId != NO_CHECK_SET) {
3604158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing                throw new IllegalArgumentException("Editable actions cannot also be checked");
3614158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing            }
362b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
3634158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing        }
3644158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing
3654158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing        /**
366c1741246af607f6be2389056da0182c40f938348Dake Gu         * Indicates whether this action's description is editable
367c1741246af607f6be2389056da0182c40f938348Dake Gu         * @param editable Whether this action description is editable.
368c1741246af607f6be2389056da0182c40f938348Dake Gu         */
369b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B descriptionEditable(boolean editable) {
3707b93b3baf1195fbd286517556b981e25cb542a40Dake Gu            if (!editable) {
3717b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                if (mEditable == EDITING_DESCRIPTION) {
3727b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                    mEditable = EDITING_NONE;
3737b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                }
374b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu                return (B) this;
375b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            }
376b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            mEditable = EDITING_DESCRIPTION;
377accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            if (isChecked() || mCheckSetId != NO_CHECK_SET) {
378b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu                throw new IllegalArgumentException("Editable actions cannot also be checked");
379b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            }
380b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
381b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        }
382b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu
383b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        /**
384b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu         * Indicates whether this action has a view can be activated to edit, e.g. a DatePicker.
385b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu         * @param editable Whether this action has view can be activated to edit.
386b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu         */
387b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B hasEditableActivatorView(boolean editable) {
3887b93b3baf1195fbd286517556b981e25cb542a40Dake Gu            if (!editable) {
3897b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                if (mEditable == EDITING_ACTIVATOR_VIEW) {
3907b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                    mEditable = EDITING_NONE;
3917b93b3baf1195fbd286517556b981e25cb542a40Dake Gu                }
392b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu                return (B) this;
393b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            }
394b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            mEditable = EDITING_ACTIVATOR_VIEW;
395accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            if (isChecked() || mCheckSetId != NO_CHECK_SET) {
396c1741246af607f6be2389056da0182c40f938348Dake Gu                throw new IllegalArgumentException("Editable actions cannot also be checked");
397c1741246af607f6be2389056da0182c40f938348Dake Gu            }
398b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
399c1741246af607f6be2389056da0182c40f938348Dake Gu        }
400c1741246af607f6be2389056da0182c40f938348Dake Gu
401c1741246af607f6be2389056da0182c40f938348Dake Gu        /**
4029562425bf9bc15281ac27df817141854769c1042Dake Gu         * Sets {@link InputType} of this action title not in editing.
4039562425bf9bc15281ac27df817141854769c1042Dake Gu         *
4049562425bf9bc15281ac27df817141854769c1042Dake Gu         * @param inputType InputType for the action title not in editing.
4059562425bf9bc15281ac27df817141854769c1042Dake Gu         */
406b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B inputType(int inputType) {
4079562425bf9bc15281ac27df817141854769c1042Dake Gu            mInputType = inputType;
408b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
4099562425bf9bc15281ac27df817141854769c1042Dake Gu        }
4109562425bf9bc15281ac27df817141854769c1042Dake Gu
4119562425bf9bc15281ac27df817141854769c1042Dake Gu        /**
4129562425bf9bc15281ac27df817141854769c1042Dake Gu         * Sets {@link InputType} of this action description not in editing.
4139562425bf9bc15281ac27df817141854769c1042Dake Gu         *
4149562425bf9bc15281ac27df817141854769c1042Dake Gu         * @param inputType InputType for the action description not in editing.
4159562425bf9bc15281ac27df817141854769c1042Dake Gu         */
416b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B descriptionInputType(int inputType) {
4179562425bf9bc15281ac27df817141854769c1042Dake Gu            mDescriptionInputType = inputType;
418b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
4199562425bf9bc15281ac27df817141854769c1042Dake Gu        }
4209562425bf9bc15281ac27df817141854769c1042Dake Gu
4219562425bf9bc15281ac27df817141854769c1042Dake Gu
4229562425bf9bc15281ac27df817141854769c1042Dake Gu        /**
4239562425bf9bc15281ac27df817141854769c1042Dake Gu         * Sets {@link InputType} of this action title in editing.
4249562425bf9bc15281ac27df817141854769c1042Dake Gu         *
4259562425bf9bc15281ac27df817141854769c1042Dake Gu         * @param inputType InputType for the action title in editing.
4269562425bf9bc15281ac27df817141854769c1042Dake Gu         */
427b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B editInputType(int inputType) {
4289562425bf9bc15281ac27df817141854769c1042Dake Gu            mEditInputType = inputType;
429b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
4309562425bf9bc15281ac27df817141854769c1042Dake Gu        }
4319562425bf9bc15281ac27df817141854769c1042Dake Gu
4329562425bf9bc15281ac27df817141854769c1042Dake Gu        /**
4339562425bf9bc15281ac27df817141854769c1042Dake Gu         * Sets {@link InputType} of this action description in editing.
4349562425bf9bc15281ac27df817141854769c1042Dake Gu         *
4359562425bf9bc15281ac27df817141854769c1042Dake Gu         * @param inputType InputType for the action description in editing.
4369562425bf9bc15281ac27df817141854769c1042Dake Gu         */
437b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B descriptionEditInputType(int inputType) {
4389562425bf9bc15281ac27df817141854769c1042Dake Gu            mDescriptionEditInputType = inputType;
439b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
4409562425bf9bc15281ac27df817141854769c1042Dake Gu        }
4419562425bf9bc15281ac27df817141854769c1042Dake Gu
4429562425bf9bc15281ac27df817141854769c1042Dake Gu
443accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        private boolean isChecked() {
444accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            return (mActionFlags & PF_CHECKED) == PF_CHECKED;
445accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        }
4469562425bf9bc15281ac27df817141854769c1042Dake Gu        /**
447ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Indicates whether this action is initially checked.
448ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param checked Whether this action is checked.
449ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
450b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B checked(boolean checked) {
451accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            setFlags(checked ? PF_CHECKED : 0, PF_CHECKED);
452b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            if (mEditable != EDITING_NONE) {
4534158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing                throw new IllegalArgumentException("Editable actions cannot also be checked");
4544158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing            }
455b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
456ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
457ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
458ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
45911cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu         * Indicates whether this action is part of a single-select group similar to radio buttons
46011cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu         * or this action is a checkbox. When one item in a check set is checked, all others with
461bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * the same check set ID will be checked automatically.
46211cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu         * @param checkSetId The check set ID, or {@link GuidedAction#NO_CHECK_SET} to indicate not
46311cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu         * radio or checkbox, or {@link GuidedAction#CHECKBOX_CHECK_SET_ID} to indicate a checkbox.
464ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
465b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B checkSetId(int checkSetId) {
466ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing            mCheckSetId = checkSetId;
467b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            if (mEditable != EDITING_NONE) {
4684158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing                throw new IllegalArgumentException("Editable actions cannot also be in check sets");
4694158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing            }
470b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
471ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
472ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
473ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
474ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Indicates whether the title and description are long, and should be displayed
475ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * appropriately.
476ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param multilineDescription Whether this action has a multiline description.
477ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
478b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B multilineDescription(boolean multilineDescription) {
479accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            setFlags(multilineDescription ? PF_MULTI_lINE_DESCRIPTION : 0,
480accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri                    PF_MULTI_lINE_DESCRIPTION);
481b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
482ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
483ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
484ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
485ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Indicates whether this action has a next state and should display a chevron.
486ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param hasNext Whether this action has a next state.
487ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
488b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B hasNext(boolean hasNext) {
489accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            setFlags(hasNext ? PF_HAS_NEXT : 0, PF_HAS_NEXT);
490b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
491ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
492ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
493ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
494ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Indicates whether this action is for information purposes only and cannot be clicked.
495ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param infoOnly Whether this action has a next state.
496ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
497b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B infoOnly(boolean infoOnly) {
498accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            setFlags(infoOnly ? PF_INFO_ONLY : 0, PF_INFO_ONLY);
499b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
500ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
501ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
502ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        /**
503ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * Indicates whether this action is enabled.  If not enabled, an action cannot be clicked.
504ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         * @param enabled Whether the action is enabled.
505ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing         */
506b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B enabled(boolean enabled) {
507accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            setFlags(enabled ? PF_ENABLED : 0, PF_ENABLED);
508b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
509ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        }
5107af424644dc8daae5298a5ca2f655770270366feDake Gu
5117af424644dc8daae5298a5ca2f655770270366feDake Gu        /**
5127af424644dc8daae5298a5ca2f655770270366feDake Gu         * Indicates whether this action can take focus.
5137af424644dc8daae5298a5ca2f655770270366feDake Gu         * @param focusable
514a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu         * @return The same BuilderBase object.
5157af424644dc8daae5298a5ca2f655770270366feDake Gu         */
516b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B focusable(boolean focusable) {
517accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri            setFlags(focusable ? PF_FOCUSABLE : 0, PF_FOCUSABLE);
518b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
5197af424644dc8daae5298a5ca2f655770270366feDake Gu        }
520be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu
521be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu        /**
522be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu         * Sets sub actions list.
523be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu         * @param subActions
524a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu         * @return The same BuilderBase object.
525be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu         */
526b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        public B subActions(List<GuidedAction> subActions) {
527be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu            mSubActions = subActions;
528b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu            return (B) this;
529be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu        }
5309050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
5319050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        /**
5329050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu         * Explicitly sets auto restore feature on the GuidedAction.  It's by default true.
533c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas         * @param autoSaveRestoreEnabled True if turn on auto save/restore of GuidedAction content,
5349050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu         *                                false otherwise.
5359050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu         * @return The same BuilderBase object.
5369050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu         * @see GuidedAction#isAutoSaveRestoreEnabled()
5379050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu         */
538c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas        public B autoSaveRestoreEnabled(boolean autoSaveRestoreEnabled) {
539c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas            setFlags(autoSaveRestoreEnabled ? PF_AUTORESTORE : 0, PF_AUTORESTORE);
5409050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            return (B) this;
5419050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        }
5429050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
543ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
544ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
545a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu    /**
546a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu     * Builds a {@link GuidedAction} object.
547a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu     */
548b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    public static class Builder extends BuilderBase<Builder> {
549a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu
550bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
551bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @deprecated Use {@link GuidedAction.Builder#GuidedAction.Builder(Context)}.
552bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
553bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        @Deprecated
554bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        public Builder() {
555bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            super(null);
556bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
557bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
558bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        /**
559bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * Creates a Builder for GuidedAction.
560bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         * @param context Context to build GuidedAction.
561bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu         */
562bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        public Builder(Context context) {
563bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu            super(context);
564bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        }
565bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
566b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        /**
567b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu         * Builds the GuidedAction corresponding to this Builder.
568b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu         * @return The GuidedAction as configured through this Builder.
569b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu         */
570a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu        public GuidedAction build() {
571a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu            GuidedAction action = new GuidedAction();
572a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu            applyValues(action);
573a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu            return action;
574a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu        }
575a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu
576a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu    }
577a7f9f2928b60143e09f216a10ea50f2dd4581170Dake Gu
57899ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static final int PF_CHECKED = 0x00000001;
57999ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static final int PF_MULTI_lINE_DESCRIPTION = 0x00000002;
58099ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static final int PF_HAS_NEXT = 0x00000004;
58199ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static final int PF_INFO_ONLY = 0x00000008;
58299ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static final int PF_ENABLED = 0x00000010;
58399ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static final int PF_FOCUSABLE = 0x00000020;
58499ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static final int PF_AUTORESTORE = 0x00000040;
58599ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mActionFlags;
586accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri
5875356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    private CharSequence mEditTitle;
588c1741246af607f6be2389056da0182c40f938348Dake Gu    private CharSequence mEditDescription;
58999ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mEditable;
59099ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mInputType;
59199ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mDescriptionInputType;
59299ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mEditInputType;
59399ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mDescriptionEditInputType;
594accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri
59599ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mCheckSetId;
596accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri
59799ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    List<GuidedAction> mSubActions;
598ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
59999ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    Intent mIntent;
600ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
6017af424644dc8daae5298a5ca2f655770270366feDake Gu    protected GuidedAction() {
602ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        super(0);
603ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
604ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
605accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri    private void setFlags(int flag, int mask) {
606accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        mActionFlags = (mActionFlags & ~mask) | (flag & mask);
607accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri    }
608accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri
609ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
610ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns the title of this action.
611ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return The title set when this action was built.
612ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
613ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public CharSequence getTitle() {
614ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        return getLabel1();
615ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
616ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
617ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
6185356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * Sets the title of this action.
6195356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * @param title The title set when this action was built.
6204158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing     */
6214158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing    public void setTitle(CharSequence title) {
6224158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing        setLabel1(title);
6234158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing    }
6244158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing
6254158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing    /**
6265356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * Returns the optional title text to edit.  When not null, it is being edited instead of
6275356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * {@link #getTitle()}.
6285356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * @return Optional title text to edit instead of {@link #getTitle()}.
6295356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     */
6305356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    public CharSequence getEditTitle() {
6315356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu        return mEditTitle;
6325356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    }
6335356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu
6345356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    /**
6355356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * Sets the optional title text to edit instead of {@link #setTitle(CharSequence)}.
6365356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * @param editTitle Optional title text to edit instead of {@link #setTitle(CharSequence)}.
6375356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     */
6385356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    public void setEditTitle(CharSequence editTitle) {
6395356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu        mEditTitle = editTitle;
6405356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    }
6415356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu
6425356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    /**
643c1741246af607f6be2389056da0182c40f938348Dake Gu     * Returns the optional description text to edit.  When not null, it is being edited instead of
644c1741246af607f6be2389056da0182c40f938348Dake Gu     * {@link #getDescription()}.
645c1741246af607f6be2389056da0182c40f938348Dake Gu     * @return Optional description text to edit instead of {@link #getDescription()}.
646c1741246af607f6be2389056da0182c40f938348Dake Gu     */
647c1741246af607f6be2389056da0182c40f938348Dake Gu    public CharSequence getEditDescription() {
648c1741246af607f6be2389056da0182c40f938348Dake Gu        return mEditDescription;
649c1741246af607f6be2389056da0182c40f938348Dake Gu    }
650c1741246af607f6be2389056da0182c40f938348Dake Gu
651c1741246af607f6be2389056da0182c40f938348Dake Gu    /**
652c1741246af607f6be2389056da0182c40f938348Dake Gu     * Sets the optional description text to edit instead of {@link #setDescription(CharSequence)}.
653c1741246af607f6be2389056da0182c40f938348Dake Gu     * @param editDescription Optional description text to edit instead of
654c1741246af607f6be2389056da0182c40f938348Dake Gu     * {@link #setDescription(CharSequence)}.
655c1741246af607f6be2389056da0182c40f938348Dake Gu     */
656c1741246af607f6be2389056da0182c40f938348Dake Gu    public void setEditDescription(CharSequence editDescription) {
657c1741246af607f6be2389056da0182c40f938348Dake Gu        mEditDescription = editDescription;
658c1741246af607f6be2389056da0182c40f938348Dake Gu    }
659c1741246af607f6be2389056da0182c40f938348Dake Gu
660c1741246af607f6be2389056da0182c40f938348Dake Gu    /**
6615356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * Returns true if {@link #getEditTitle()} is not null.  When true, the {@link #getEditTitle()}
6625356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * is being edited instead of {@link #getTitle()}.
6635356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * @return true if {@link #getEditTitle()} is not null.
6645356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     */
6655356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    public boolean isEditTitleUsed() {
6665356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu        return mEditTitle != null;
6675356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    }
6685356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu
6695356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    /**
670ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns the description of this action.
6715356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * @return The description of this action.
672ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
673ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public CharSequence getDescription() {
674ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        return getLabel2();
675ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
676ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
677ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
6785356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * Sets the description of this action.
6795356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     * @param description The description of the action.
6805356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu     */
6815356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    public void setDescription(CharSequence description) {
6825356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu        setLabel2(description);
6835356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    }
6845356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu
6855356bc373aa2c51ff7dac08058e7ae5e53e20509Dake Gu    /**
686ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns the intent associated with this action.
687ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return The intent set when this action was built.
688ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
689ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public Intent getIntent() {
690ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        return mIntent;
691ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
692ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
693ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
694bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu     * Sets the intent of this action.
695bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu     * @param intent New intent to set on this action.
696bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu     */
697bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu    public void setIntent(Intent intent) {
698bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu        mIntent = intent;
699bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu    }
700bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu
701bc62e0bf64bc727e7fe983ee1ffe07e266f143c8Dake Gu    /**
702e2f7aef2f45dcdfe116995b64f9a7be5c68a36a1Dake Gu     * Returns whether this action title is editable.
703e2f7aef2f45dcdfe116995b64f9a7be5c68a36a1Dake Gu     * @return true if the action title is editable, false otherwise.
7044158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing     */
7054158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing    public boolean isEditable() {
706b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        return mEditable == EDITING_TITLE;
7074158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing    }
7084158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing
7094158705d3f0751d419a08c47a659abeae5f6c196Kris Giesing    /**
710c1741246af607f6be2389056da0182c40f938348Dake Gu     * Returns whether this action description is editable.
711c1741246af607f6be2389056da0182c40f938348Dake Gu     * @return true if the action description is editable, false otherwise.
712c1741246af607f6be2389056da0182c40f938348Dake Gu     */
713c1741246af607f6be2389056da0182c40f938348Dake Gu    public boolean isDescriptionEditable() {
714b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        return mEditable == EDITING_DESCRIPTION;
715b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    }
716b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu
717b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    /**
718b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu     * Returns if this action has editable title or editable description.
719b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu     * @return True if this action has editable title or editable description, false otherwise.
720b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu     */
721b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    public boolean hasTextEditable() {
722b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        return mEditable == EDITING_TITLE || mEditable == EDITING_DESCRIPTION;
723b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    }
724b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu
725b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    /**
726b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu     * Returns whether this action can be activated to edit, e.g. a DatePicker.
727b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu     * @return true if the action can be activated to edit.
728b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu     */
729b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu    public boolean hasEditableActivatorView() {
730b88b36aa081a500eb0e9d4be0bac85b33cd57ddeDake Gu        return mEditable == EDITING_ACTIVATOR_VIEW;
731c1741246af607f6be2389056da0182c40f938348Dake Gu    }
732c1741246af607f6be2389056da0182c40f938348Dake Gu
733c1741246af607f6be2389056da0182c40f938348Dake Gu    /**
7349562425bf9bc15281ac27df817141854769c1042Dake Gu     * Returns InputType of action title in editing; only valid when {@link #isEditable()} is true.
7359562425bf9bc15281ac27df817141854769c1042Dake Gu     * @return InputType of action title in editing.
7369562425bf9bc15281ac27df817141854769c1042Dake Gu     */
7379562425bf9bc15281ac27df817141854769c1042Dake Gu    public int getEditInputType() {
7389562425bf9bc15281ac27df817141854769c1042Dake Gu        return mEditInputType;
7399562425bf9bc15281ac27df817141854769c1042Dake Gu    }
7409562425bf9bc15281ac27df817141854769c1042Dake Gu
7419562425bf9bc15281ac27df817141854769c1042Dake Gu    /**
7429562425bf9bc15281ac27df817141854769c1042Dake Gu     * Returns InputType of action description in editing; only valid when
7439562425bf9bc15281ac27df817141854769c1042Dake Gu     * {@link #isDescriptionEditable()} is true.
7449562425bf9bc15281ac27df817141854769c1042Dake Gu     * @return InputType of action description in editing.
7459562425bf9bc15281ac27df817141854769c1042Dake Gu     */
7469562425bf9bc15281ac27df817141854769c1042Dake Gu    public int getDescriptionEditInputType() {
7479562425bf9bc15281ac27df817141854769c1042Dake Gu        return mDescriptionEditInputType;
7489562425bf9bc15281ac27df817141854769c1042Dake Gu    }
7499562425bf9bc15281ac27df817141854769c1042Dake Gu
7509562425bf9bc15281ac27df817141854769c1042Dake Gu    /**
7519562425bf9bc15281ac27df817141854769c1042Dake Gu     * Returns InputType of action title not in editing.
7529562425bf9bc15281ac27df817141854769c1042Dake Gu     * @return InputType of action title not in editing.
7539562425bf9bc15281ac27df817141854769c1042Dake Gu     */
7549562425bf9bc15281ac27df817141854769c1042Dake Gu    public int getInputType() {
7559562425bf9bc15281ac27df817141854769c1042Dake Gu        return mInputType;
7569562425bf9bc15281ac27df817141854769c1042Dake Gu    }
7579562425bf9bc15281ac27df817141854769c1042Dake Gu
7589562425bf9bc15281ac27df817141854769c1042Dake Gu    /**
7599562425bf9bc15281ac27df817141854769c1042Dake Gu     * Returns InputType of action description not in editing.
7609562425bf9bc15281ac27df817141854769c1042Dake Gu     * @return InputType of action description not in editing.
7619562425bf9bc15281ac27df817141854769c1042Dake Gu     */
7629562425bf9bc15281ac27df817141854769c1042Dake Gu    public int getDescriptionInputType() {
7639562425bf9bc15281ac27df817141854769c1042Dake Gu        return mDescriptionInputType;
7649562425bf9bc15281ac27df817141854769c1042Dake Gu    }
7659562425bf9bc15281ac27df817141854769c1042Dake Gu
7669562425bf9bc15281ac27df817141854769c1042Dake Gu    /**
767ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns whether this action is checked.
768ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return true if the action is currently checked, false otherwise.
769ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
770ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public boolean isChecked() {
771accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        return (mActionFlags & PF_CHECKED) == PF_CHECKED;
772ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
773ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
774ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
775ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Sets whether this action is checked.
776ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @param checked Whether this action should be checked.
777ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
778ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public void setChecked(boolean checked) {
779accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        setFlags(checked ? PF_CHECKED : 0, PF_CHECKED);
780ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
781ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
782ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
78311cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     * Returns the check set id this action is a part of. All actions in the same list with the same
78411cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     * check set id are considered linked. When one of the actions within that set is selected, that
78511cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     * action becomes checked, while all the other actions become unchecked.
786ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     *
787ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return an integer representing the check set this action is a part of, or
78811cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     *         {@link #CHECKBOX_CHECK_SET_ID} if this is a checkbox, or {@link #NO_CHECK_SET} if
78911cb62de8bfc6b5b6d22811ad12a1e60451b82beDake Gu     *         this action is not a checkbox or radiobutton.
790ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
791ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public int getCheckSetId() {
792ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing        return mCheckSetId;
793ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
794ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
795ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
796ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns whether this action is has a multiline description.
797ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return true if the action was constructed as having a multiline description, false
798ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * otherwise.
799ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
800ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public boolean hasMultilineDescription() {
801accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        return (mActionFlags & PF_MULTI_lINE_DESCRIPTION) == PF_MULTI_lINE_DESCRIPTION;
802ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
803ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
804ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
805ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns whether this action is enabled.
806ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return true if the action is currently enabled, false otherwise.
807ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
808ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public boolean isEnabled() {
809accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        return (mActionFlags & PF_ENABLED) == PF_ENABLED;
810ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
811ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
812ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
813ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Sets whether this action is enabled.
814ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @param enabled Whether this action should be enabled.
815ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
816ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public void setEnabled(boolean enabled) {
817accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        setFlags(enabled ? PF_ENABLED : 0, PF_ENABLED);
818ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
819ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
820ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
8217af424644dc8daae5298a5ca2f655770270366feDake Gu     * Returns whether this action is focusable.
8227af424644dc8daae5298a5ca2f655770270366feDake Gu     * @return true if the action is currently focusable, false otherwise.
8237af424644dc8daae5298a5ca2f655770270366feDake Gu     */
8247af424644dc8daae5298a5ca2f655770270366feDake Gu    public boolean isFocusable() {
825accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        return (mActionFlags & PF_FOCUSABLE) == PF_FOCUSABLE;
8267af424644dc8daae5298a5ca2f655770270366feDake Gu    }
8277af424644dc8daae5298a5ca2f655770270366feDake Gu
8287af424644dc8daae5298a5ca2f655770270366feDake Gu    /**
8297af424644dc8daae5298a5ca2f655770270366feDake Gu     * Sets whether this action is focusable.
8307af424644dc8daae5298a5ca2f655770270366feDake Gu     * @param focusable Whether this action should be focusable.
8317af424644dc8daae5298a5ca2f655770270366feDake Gu     */
8327af424644dc8daae5298a5ca2f655770270366feDake Gu    public void setFocusable(boolean focusable) {
833accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        setFlags(focusable ? PF_FOCUSABLE : 0, PF_FOCUSABLE);
8347af424644dc8daae5298a5ca2f655770270366feDake Gu    }
8357af424644dc8daae5298a5ca2f655770270366feDake Gu
8367af424644dc8daae5298a5ca2f655770270366feDake Gu    /**
837ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns whether this action will request further user input when selected, such as showing
838ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * another GuidedStepFragment or launching a new activity. Configured during construction.
839ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return true if the action will request further user input when selected, false otherwise.
840ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
841ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public boolean hasNext() {
842accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        return (mActionFlags & PF_HAS_NEXT) == PF_HAS_NEXT;
843ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
844ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
845ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    /**
846ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * Returns whether the action will only display information and is thus not clickable. If both
847ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * this and {@link #hasNext()} are true, infoOnly takes precedence. The default is false. For
848ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * example, this might represent e.g. the amount of storage a document uses, or the cost of an
849ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * app.
850ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     * @return true if will only display information, false otherwise.
851ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing     */
852ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    public boolean infoOnly() {
853accd54788b769d62a99300306741551fe207b2d4Keyvan Amiri        return (mActionFlags & PF_INFO_ONLY) == PF_INFO_ONLY;
854ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing    }
855ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing
856be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    /**
857be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu     * Change sub actions list.
858be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu     * @param actions Sub actions list to set on this action.  Sets null to disable sub actions.
859be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu     */
860be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    public void setSubActions(List<GuidedAction> actions) {
861be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu        mSubActions = actions;
862be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    }
863be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu
864be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    /**
865be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu     * @return List of sub actions or null if sub actions list is not enabled.
866be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu     */
867be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    public List<GuidedAction> getSubActions() {
868be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu        return mSubActions;
869be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    }
870be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu
871be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    /**
872be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu     * @return True if has sub actions list, even it's currently empty.
873be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu     */
874be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    public boolean hasSubActions() {
875be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu        return mSubActions != null;
876be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu    }
877be6eb618b4ba8a74d69fa04c77c717b1fcbea818Dake Gu
8789050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    /**
8799050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * Returns true if Action will be saved to instanceState and restored later, false otherwise.
8809050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * The default value is true.  When isAutoSaveRestoreEnabled() is true and {@link #getId()} is
8819050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * not {@link #NO_ID}:
8829050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #isEditable()} is true: save text of {@link #getTitle()}</li>
8839050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #isDescriptionEditable()} is true: save text of {@link #getDescription()}</li>
8849050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #getCheckSetId()} is not {@link #NO_CHECK_SET}: save {@link #isChecked()}}</li>
8859050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link GuidedDatePickerAction} will be saved</li>
8869050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * App may explicitly disable auto restore and handle by itself. App should override Fragment
8879050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * onSaveInstanceState() and onCreateActions()
8889050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * @return True if Action will be saved to instanceState and restored later, false otherwise.
8899050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     */
8909050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    public final boolean isAutoSaveRestoreEnabled() {
8919050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        return (mActionFlags & PF_AUTORESTORE) == PF_AUTORESTORE;
8929050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    }
8939050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
8949050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    /**
8959050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * Save action into a bundle using a given key. When isAutoRestoreEna() is true:
8969050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #isEditable()} is true: save text of {@link #getTitle()}</li>
8979050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #isDescriptionEditable()} is true: save text of {@link #getDescription()}</li>
8989050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #getCheckSetId()} is not {@link #NO_CHECK_SET}: save {@link #isChecked()}}</li>
8999050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link GuidedDatePickerAction} will be saved</li>
9009050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * Subclass may override this method.
9019050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * @param bundle  Bundle to save the Action.
9029050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * @param key Key used to save the Action.
9039050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     */
9049050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    public void onSaveInstanceState(Bundle bundle, String key) {
9059050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        if (needAutoSaveTitle() && getTitle() != null) {
9069050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            bundle.putString(key, getTitle().toString());
9079050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        } else if (needAutoSaveDescription() && getDescription() != null) {
9089050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            bundle.putString(key, getDescription().toString());
9099050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        } else if (getCheckSetId() != NO_CHECK_SET) {
9109050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            bundle.putBoolean(key, isChecked());
9119050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        }
9129050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    }
9139050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
9149050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    /**
9159050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * Restore action from a bundle using a given key. When isAutoRestore() is true:
9169050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #isEditable()} is true: save text of {@link #getTitle()}</li>
9179050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #isDescriptionEditable()} is true: save text of {@link #getDescription()}</li>
9189050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link #getCheckSetId()} is not {@link #NO_CHECK_SET}: save {@link #isChecked()}}</li>
9199050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * <li>{@link GuidedDatePickerAction} will be saved</li>
9209050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * Subclass may override this method.
9219050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * @param bundle  Bundle to restore the Action from.
9229050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     * @param key Key used to restore the Action.
9239050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu     */
9249050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    public void onRestoreInstanceState(Bundle bundle, String key) {
9259050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        if (needAutoSaveTitle()) {
9269050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            String title = bundle.getString(key);
9279050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            if (title != null) {
9289050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu                setTitle(title);
9299050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            }
9309050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        } else if (needAutoSaveDescription()) {
9319050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            String description = bundle.getString(key);
9329050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            if (description != null) {
9339050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu                setDescription(description);
9349050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            }
9359050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        } else if (getCheckSetId() != NO_CHECK_SET) {
9369050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu            setChecked(bundle.getBoolean(key, isChecked()));
9379050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        }
9389050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    }
9399050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
9409050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    final static boolean isPasswordVariant(int inputType) {
941c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas        final int variation = inputType & InputType.TYPE_MASK_VARIATION;
942c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas        return variation == InputType.TYPE_TEXT_VARIATION_PASSWORD
943c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas                || variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
944c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas                || variation == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
9459050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    }
9469050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
9479050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    final boolean needAutoSaveTitle() {
9489050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        return isEditable() && !isPasswordVariant(getEditInputType());
9499050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    }
9509050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
9519050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    final boolean needAutoSaveDescription() {
9529050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu        return isDescriptionEditable() && !isPasswordVariant(getDescriptionEditInputType());
9539050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu    }
9549050c0fc8fbcd8ffe794915375efd5d2b96a0b2dDake Gu
955ebd3d9078dbaebd10a9506ca086435eb63e8a2d2Kris Giesing}
956