EmojiKeyListener.java revision 77b5c5b734f9f665577d1e3d178615db43ae1d4f
1/*
2 * Copyright (C) 2017 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 */
16package android.support.text.emoji.widget;
17
18import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
19
20import android.support.annotation.RequiresApi;
21import android.support.annotation.RestrictTo;
22import android.support.text.emoji.EmojiCompat;
23import android.text.Editable;
24import android.view.KeyEvent;
25import android.view.View;
26
27/**
28 * KeyListener class to handle delete operations correctly.
29 *
30 * @hide
31 */
32@RestrictTo(LIBRARY_GROUP)
33@RequiresApi(19)
34final class EmojiKeyListener implements android.text.method.KeyListener {
35    private final android.text.method.KeyListener mKeyListener;
36
37    EmojiKeyListener(android.text.method.KeyListener keyListener) {
38        mKeyListener = keyListener;
39    }
40
41    @Override
42    public int getInputType() {
43        return mKeyListener.getInputType();
44    }
45
46    @Override
47    public boolean onKeyDown(View view, Editable content, int keyCode, KeyEvent event) {
48        final boolean result = EmojiCompat.handleOnKeyDown(content, keyCode, event);
49        return result || mKeyListener.onKeyDown(view, content, keyCode, event);
50    }
51
52    @Override
53    public boolean onKeyUp(View view, Editable text, int keyCode, KeyEvent event) {
54        return mKeyListener.onKeyUp(view, text, keyCode, event);
55    }
56
57    @Override
58    public boolean onKeyOther(View view, Editable text, KeyEvent event) {
59        return mKeyListener.onKeyOther(view, text, event);
60    }
61
62    @Override
63    public void clearMetaKeyState(View view, Editable content, int states) {
64        mKeyListener.clearMetaKeyState(view, content, states);
65    }
66}
67