blob: bf4551b26174f632c110cf5b4eb3e3497a982f55 [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;
Winson4e7a1012015-08-13 16:47:55 -070020import android.view.DragEvent;
Winson Chungde34aa42015-05-07 18:21:28 -070021import android.view.KeyEvent;
22import android.widget.EditText;
23
24
25/**
Winson97b0d082015-08-13 15:18:25 -070026 * The edit text that reports back when the back key has been pressed.
Winson Chungde34aa42015-05-07 18:21:28 -070027 */
Winson97b0d082015-08-13 15:18:25 -070028public class ExtendedEditText extends EditText {
Winson Chungde34aa42015-05-07 18:21:28 -070029
30 /**
31 * Implemented by listeners of the back key.
32 */
33 public interface OnBackKeyListener {
Winson97b0d082015-08-13 15:18:25 -070034 public boolean onBackKey();
Winson Chungde34aa42015-05-07 18:21:28 -070035 }
36
37 private OnBackKeyListener mBackKeyListener;
38
Winson97b0d082015-08-13 15:18:25 -070039 public ExtendedEditText(Context context) {
40 super(context);
Winson Chungde34aa42015-05-07 18:21:28 -070041 }
42
Winson97b0d082015-08-13 15:18:25 -070043 public ExtendedEditText(Context context, AttributeSet attrs) {
44 super(context, attrs);
Winson Chungde34aa42015-05-07 18:21:28 -070045 }
46
Winson97b0d082015-08-13 15:18:25 -070047 public ExtendedEditText(Context context, AttributeSet attrs, int defStyleAttr) {
Winson Chungde34aa42015-05-07 18:21:28 -070048 super(context, attrs, defStyleAttr);
49 }
50
51 public void setOnBackKeyListener(OnBackKeyListener listener) {
52 mBackKeyListener = listener;
53 }
54
55 @Override
56 public boolean onKeyPreIme(int keyCode, KeyEvent event) {
57 // If this is a back key, propagate the key back to the listener
58 if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
59 if (mBackKeyListener != null) {
Winson97b0d082015-08-13 15:18:25 -070060 return mBackKeyListener.onBackKey();
Winson Chungde34aa42015-05-07 18:21:28 -070061 }
62 return false;
63 }
64 return super.onKeyPreIme(keyCode, event);
65 }
Winson4e7a1012015-08-13 16:47:55 -070066
67 @Override
68 public boolean onDragEvent(DragEvent event) {
69 // We don't want this view to interfere with Launcher own drag and drop.
70 return false;
71 }
Winson Chungde34aa42015-05-07 18:21:28 -070072}