• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.inputmethod.research;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 import android.util.AttributeSet;
22 import android.view.KeyEvent;
23 import android.widget.LinearLayout;
24 
25 public class FeedbackLayout extends LinearLayout {
26     private Activity mActivity;
27 
FeedbackLayout(Context context)28     public FeedbackLayout(Context context) {
29         super(context);
30     }
31 
FeedbackLayout(Context context, AttributeSet attrs)32     public FeedbackLayout(Context context, AttributeSet attrs) {
33         super(context, attrs);
34     }
35 
FeedbackLayout(Context context, AttributeSet attrs, int defstyle)36     public FeedbackLayout(Context context, AttributeSet attrs, int defstyle) {
37         super(context, attrs, defstyle);
38     }
39 
setActivity(Activity activity)40     public void setActivity(Activity activity) {
41         mActivity = activity;
42     }
43 
44     @Override
dispatchKeyEventPreIme(KeyEvent event)45     public boolean dispatchKeyEventPreIme(KeyEvent event) {
46         if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
47             KeyEvent.DispatcherState state = getKeyDispatcherState();
48             if (state != null) {
49                 if (event.getAction() == KeyEvent.ACTION_DOWN
50                         && event.getRepeatCount() == 0) {
51                     state.startTracking(event, this);
52                     return true;
53                 } else if (event.getAction() == KeyEvent.ACTION_UP
54                         && !event.isCanceled() && state.isTracking(event)) {
55                     mActivity.onBackPressed();
56                     return true;
57                 }
58             }
59         }
60         return super.dispatchKeyEventPreIme(event);
61     }
62 }
63