GuidedActionEditText.java revision ac07e9d12b10138d4a449522f7082a40f18861e2
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14package android.support.v17.leanback.widget;
15
16import android.content.Context;
17import android.support.v17.leanback.widget.ImeKeyMonitor.ImeKeyListener;
18import android.util.AttributeSet;
19import android.widget.EditText;
20import android.view.KeyEvent;
21
22/**
23 * A custom EditText that satisfies the IME key monitoring requirements of GuidedStepFragment.
24 */
25public class GuidedActionEditText extends EditText implements ImeKeyMonitor {
26
27    private ImeKeyListener mKeyListener;
28
29    public GuidedActionEditText(Context ctx) {
30        this(ctx, null);
31    }
32
33    public GuidedActionEditText(Context ctx, AttributeSet attrs) {
34        this(ctx, attrs, android.R.attr.editTextStyle);
35    }
36
37    public GuidedActionEditText(Context ctx, AttributeSet attrs, int defStyleAttr) {
38        super(ctx, attrs, defStyleAttr);
39    }
40
41    @Override
42    public void setImeKeyListener(ImeKeyListener listener) {
43        mKeyListener = listener;
44    }
45
46    @Override
47    public boolean onKeyPreIme(int keyCode, KeyEvent event) {
48        boolean result = false;
49        if (mKeyListener != null) {
50            result = mKeyListener.onKeyPreIme(this, keyCode, event);
51        }
52        if (!result) {
53            result = super.onKeyPreIme(keyCode, event);
54        }
55        return result;
56    }
57
58}
59