blob: c688237b24694cec5289157b219095316b80410e [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 */
16package com.android.launcher3;
17
18import android.content.Context;
19import android.util.AttributeSet;
20import android.view.KeyEvent;
21import android.widget.EditText;
22
23
24/**
25 * The edit text for the search container
26 */
27public class AppsContainerSearchEditTextView extends EditText {
28
29 /**
30 * Implemented by listeners of the back key.
31 */
32 public interface OnBackKeyListener {
33 public void onBackKey();
34 }
35
36 private OnBackKeyListener mBackKeyListener;
37
38 public AppsContainerSearchEditTextView(Context context) {
39 this(context, null);
40 }
41
42 public AppsContainerSearchEditTextView(Context context, AttributeSet attrs) {
43 this(context, attrs, 0);
44 }
45
46 public AppsContainerSearchEditTextView(Context context, AttributeSet attrs, int defStyleAttr) {
47 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) {
59 mBackKeyListener.onBackKey();
60 }
61 return false;
62 }
63 return super.onKeyPreIme(keyCode, event);
64 }
65}