blob: c7b64ec7def8217b2e6ef8371f1b715b69ed73f0 [file] [log] [blame]
Winson Chungde34aa42015-05-07 18:21:28 -07001/*
2 * Copyright (C) 2015 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 */
Winson97b0d082015-08-13 15:18:25 -070016package com.android.launcher3;
Winson Chungde34aa42015-05-07 18:21:28 -070017
18import android.content.Context;
19import android.util.AttributeSet;
20import android.view.KeyEvent;
21import android.widget.EditText;
22
23
24/**
Winson97b0d082015-08-13 15:18:25 -070025 * The edit text that reports back when the back key has been pressed.
Winson Chungde34aa42015-05-07 18:21:28 -070026 */
Winson97b0d082015-08-13 15:18:25 -070027public class ExtendedEditText extends EditText {
Winson Chungde34aa42015-05-07 18:21:28 -070028
29 /**
30 * Implemented by listeners of the back key.
31 */
32 public interface OnBackKeyListener {
Winson97b0d082015-08-13 15:18:25 -070033 public boolean onBackKey();
Winson Chungde34aa42015-05-07 18:21:28 -070034 }
35
36 private OnBackKeyListener mBackKeyListener;
37
Winson97b0d082015-08-13 15:18:25 -070038 public ExtendedEditText(Context context) {
39 super(context);
Winson Chungde34aa42015-05-07 18:21:28 -070040 }
41
Winson97b0d082015-08-13 15:18:25 -070042 public ExtendedEditText(Context context, AttributeSet attrs) {
43 super(context, attrs);
Winson Chungde34aa42015-05-07 18:21:28 -070044 }
45
Winson97b0d082015-08-13 15:18:25 -070046 public ExtendedEditText(Context context, AttributeSet attrs, int defStyleAttr) {
Winson Chungde34aa42015-05-07 18:21:28 -070047 super(context, attrs, defStyleAttr);
48 }
49
50 public void setOnBackKeyListener(OnBackKeyListener listener) {
51 mBackKeyListener = listener;
52 }
53
54 @Override
55 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
56 // If this is a back key, propagate the key back to the listener
57 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
58 if (mBackKeyListener != null) {
Winson97b0d082015-08-13 15:18:25 -070059 return mBackKeyListener.onBackKey();
Winson Chungde34aa42015-05-07 18:21:28 -070060 }
61 return false;
62 }
63 return super.onKeyPreIme(keyCode, event);
64 }
65}