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