1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.compose.ui.text.input
18 
19 import androidx.compose.runtime.Stable
20 
21 /**
22  * Signals the keyboard what type of action should be displayed. It is not guaranteed that the
23  * keyboard will show the requested action.
24  */
25 @kotlin.jvm.JvmInline
26 value class ImeAction private constructor(@Suppress("unused") private val value: Int) {
27 
toStringnull28     override fun toString(): String {
29         return when (this) {
30             Unspecified -> "Unspecified"
31             None -> "None"
32             Default -> "Default"
33             Go -> "Go"
34             Search -> "Search"
35             Send -> "Send"
36             Previous -> "Previous"
37             Next -> "Next"
38             Done -> "Done"
39             else -> "Invalid"
40         }
41     }
42 
43     companion object {
44         /**
45          * The action is not specified. This defaults to [Default], which explicitly requests the
46          * platform and keyboard to make the decision, but [Default] will take precedence when
47          * merging [ImeAction]s.
48          */
49         @Stable val Unspecified: ImeAction = ImeAction(-1)
50 
51         /**
52          * Use the platform and keyboard defaults and let the keyboard decide the action it is going
53          * to show. The keyboards will mostly show one of [Done] or [None] actions based on the
54          * single/multi line configuration. This action will never be sent as the performed action
55          * to IME action callbacks.
56          */
57         @Stable val Default: ImeAction = ImeAction(1)
58 
59         /**
60          * Represents that no action is expected from the keyboard. Keyboard might choose to show an
61          * action which mostly will be newline, however this action will never be sent as the
62          * performed action to IME action callbacks.
63          */
64         @Stable val None: ImeAction = ImeAction(0)
65 
66         /**
67          * Represents that the user would like to go to the target of the text in the input i.e.
68          * visiting a URL.
69          */
70         @Stable val Go: ImeAction = ImeAction(2)
71 
72         /** Represents that the user wants to execute a search, i.e. web search query. */
73         @Stable val Search: ImeAction = ImeAction(3)
74 
75         /** Represents that the user wants to send the text in the input, i.e. an SMS. */
76         @Stable val Send: ImeAction = ImeAction(4)
77 
78         /**
79          * Represents that the user wants to return to the previous input i.e. going back to the
80          * previous field in a form.
81          */
82         @Stable val Previous: ImeAction = ImeAction(5)
83 
84         /**
85          * Represents that the user is done with the current input, and wants to move to the next
86          * one i.e. moving to the next field in a form.
87          */
88         @Stable val Next: ImeAction = ImeAction(6)
89 
90         /**
91          * Represents that the user is done providing input to a group of inputs. Some kind of
92          * finalization behavior should now take place i.e. the field was the last element in a
93          * group and the data input is finalized.
94          */
95         @Stable val Done: ImeAction = ImeAction(7)
96     }
97 }
98