|
| 1 | +/* |
| 2 | + * Copyright (C) 2018 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.core.widget |
| 18 | + |
| 19 | +import android.support.test.InstrumentationRegistry |
| 20 | +import android.view.inputmethod.EditorInfo |
| 21 | +import android.widget.TextView |
| 22 | +import org.junit.Assert.assertEquals |
| 23 | +import org.junit.Test |
| 24 | + |
| 25 | +class TextViewTest { |
| 26 | + private val textView = TextView(InstrumentationRegistry.getTargetContext()) |
| 27 | + |
| 28 | + @Test fun doOnEditorAction() { |
| 29 | + val actionDone = EditorInfo.IME_ACTION_DONE |
| 30 | + val actionNext = EditorInfo.IME_ACTION_NEXT |
| 31 | + val actionSend = EditorInfo.IME_ACTION_SEND |
| 32 | + textView.imeOptions = actionDone or actionNext |
| 33 | + |
| 34 | + var calls = 0 |
| 35 | + textView.doOnEditorAction(actionDone, actionNext) { |
| 36 | + calls++ |
| 37 | + } |
| 38 | + |
| 39 | + textView.onEditorAction(actionDone) |
| 40 | + assertEquals(calls, 1) |
| 41 | + textView.onEditorAction(actionNext) |
| 42 | + assertEquals(calls, 2) |
| 43 | + // as the IME_ACTION_SEND is not in the given actionIds, the listener shouldn't get called |
| 44 | + textView.onEditorAction(actionSend) |
| 45 | + assertEquals(calls, 2) |
| 46 | + } |
| 47 | +} |
0 commit comments