Java 类android.view.View.OnKeyListener 实例源码

项目:Microsoft_Band    文件:BottomPushPopupWindow.java   
private void addMaskView(IBinder token) {
    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.width = WindowManager.LayoutParams.MATCH_PARENT;
    p.height = WindowManager.LayoutParams.MATCH_PARENT;
    p.format = PixelFormat.TRANSLUCENT;
    p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
    p.token = token;
    p.windowAnimations = android.R.style.Animation_Toast;
    maskView = new View(context);
    maskView.setBackgroundColor(0x7f000000);
    maskView.setFitsSystemWindows(false);
    // 华为手机在home建进入后台后,在进入应用,蒙层出现在popupWindow上层,导致界面卡死,
    // 这里新增加按bug返回。
    // initType方法已经解决该问题,但是还是留着这个按back返回功能,防止其他手机出现华为手机类似问题。
    maskView.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                removeMaskView();
                return true;
            }
            return false;
        }
    });
    wm.addView(maskView, p);
}
项目:ACCAndroid    文件:TimeViewManager.java   
public void rigistTimeAction(final EditText editText,
        final Context context, Date date,
        final OnValidateListener onValidateListener) {
    editText.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            TimeViewManager.this.validateTimeEditText(editText,
                    onValidateListener);
            return false;
        }
    });
    // date = date == null ? new Date() : date;
    editText.setText(TimeUtil.dateToAppStringEx(date));
    // editText.setEnabled(false);
    editText.setOnClickListener(new TimeOnClickListener(editText, context,
            onValidateListener));
}
项目:glasgow_uni_map    文件:GlaUniActivity.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home_screen);
    context = this.getApplicationContext();

    // TODO(radkokotev) redesign the initialization.
    allBuildings = new DataHolder();
    allBuildings.initialize();
    matchedBuildings = new DataHolder();

    final EditText id_field = (EditText)findViewById(R.id.nameOfPlace_field);
    id_field.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // If the user pressed ENTER, directly search for the place.
                onFindButtonClick(findViewById(R.id.findOnMapButton));
                return true;
            }
            return false;
        }
    });
}
项目:android-stuff    文件:BluetoothTexting.java   
private void switchUI() {
    final TextView messageText = (TextView)findViewById(R.id.text_messages);
    final EditText textEntry = (EditText)findViewById(R.id.text_message);
    messageText.setVisibility(View.VISIBLE);
    list.setVisibility(View.GONE);
    textEntry.setEnabled(true);
    textEntry.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_DPAD_CENTER)) {
                sendMessage(socket, textEntry.getText().toString());
                textEntry.setText("");
                return true;
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:ContactUpdate.java   
/**
 * Attaches onKey listener to the Button passed as a parameter to the
 * method. If enter key on the keyboard or center key on the keypad is
 * pressed, the value of the parameter passed is checked.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 * @param buttonFlag
 *            If the value of buttonFlag is 1, the number is set as primary
 *            by calling the setPrimaryNumberAndGiveFeedback method. If the
 *            value of buttonFlag is 2, the email ID is set as primary by
 *            calling the setPrimaryMailAndGiveFeedback method.
 */

void attachKeyListener(final Button button, final int buttonFlag) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    switch (buttonFlag) {
                    case 1:
                        setPrimaryNumberAndGiveFeedback();
                        break;
                    case 2:
                        setPrimaryMailAndGiveFeedback();
                        break;
                    }
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:ContactsApp.java   
/**
 * Attaches onKey listener to the Button passed as a parameter to the
 * method. If enter key on the keyboard or center key on the keypad is
 * pressed, the value of the parameter passed is checked.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 * @param buttonFlag
 *            If the value of buttonFlag is 1, a call is made to the
 *            specified number or name. If the value of buttonFlag is 2, the
 *            number is saved in the phone's contacts.
 */
void attachKeyListener(Button button, final int buttonFlag) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    switch (buttonFlag) {
                    case 1:
                        callContact(inputContacts.getText().toString());
                        break;
                    case 2:
                        saveContact(inputContacts.getText().toString());
                        break;
                    }
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:SaveContact.java   
/**
 * Attaches onKey listener to the Button passed as a parameter to the
 * method. If enter key on the keyboard or center key on the keypad is
 * pressed, saveAndGiveFeedback method is called.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 */
void attachKeyListener(final Button button) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    saveAndGiveFeedback();
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:TextMessagesComposerRecipientApp.java   
/**
 * Attaches onKeyListener to the button passed as a parameter to the method.
 * The method corresponding to the button on which the enter key of the
 * keyboard or the center key of the keypad is pressed.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 */
void attachKeyListener(Button button) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    proceed();
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:TextMessagesComposerApp.java   
/**
 * Attaches onKey listener to the button passed as a parameter to the
 * method. If enter key on the keyboard or center key on the keypad is
 * pressed, sendMessage method is called, which will be used to send the
 * text message to the recipient.
 * 
 * @param button
 *            The button with which the onKey listener is to be associated.
 */
void attachKeyListener(Button button) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    sendMessage();
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:SettingsColor.java   
/**
 * Attaches onKey listener to the Button passed as a parameter to the
 * method. If enter key on the keyboard or center key on the keypad is
 * pressed, it resets the text color and the background color of the app to
 * their default values.
 * 
 * @param button
 *            This is an instance of Button
 */
void attachKeyListener(final Button button) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    reset();
                    break;
                }
            }
            return false;
        }
    });
}
项目:EatingClub    文件:RegisterPage.java   
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.registerpage);
    EditText passwordField = (EditText) findViewById(R.id.registerPassword2);
    passwordField.setOnKeyListener(new OnKeyListener()
    {
        public boolean onKey(View v, int keyCode, KeyEvent event)
        {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
            {
                switch (keyCode)
                {
                    case KeyEvent.KEYCODE_DPAD_CENTER:
                    case KeyEvent.KEYCODE_ENTER:
                        registerButtonClicked(v);
                        return true;
                    default:
                        break;
                }
            }
            return false;
        }
    });
    ParseAnalytics.trackAppOpened(getIntent());
}
项目:EatingClub    文件:FriendPage.java   
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.friendpage);

    EditText searchField = (EditText) findViewById(R.id.searchFriendField);
    searchField.setOnKeyListener(new OnKeyListener()
    {
        public boolean onKey(View v, int keyCode, KeyEvent event)
        {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
            {
                switch (keyCode)
                {
                    case KeyEvent.KEYCODE_DPAD_CENTER:
                    case KeyEvent.KEYCODE_ENTER:
                        backButtonClicked(v);
                        return true;
                    default:
                        break;
                }
            }
            return false;
        }
    });
}
项目:openxface-android    文件:XInAppBrowser.java   
/**
 * 构建文本框
 */
protected void buildEditText() {
    RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
    textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
    OnKeyListener keyListener = new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN)
                    && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                navigate(mEditText.getText().toString());
                return true;
            }
            return false;
        }
    };
    mEditText =  createEditText(EDITTEXT_ID, textLayoutParams, true, mUrl,
            InputType.TYPE_TEXT_VARIATION_URI, EditorInfo.IME_ACTION_GO,
            keyListener);
}
项目:NoticeDog    文件:InboxViewController.java   
public void createView() {
    this.inboxView = ((LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(geLayoutId(), null);
    this.listView = (ExpandableListView) this.inboxView.findViewById(R.id.swipe_side_listview);
    this.listView.setEmptyView(this.inboxView.findViewById(R.id.inbox_empty_view));
    InboxViewManager inboxViewManager = (InboxViewManager) GuiceModule.get().getInstance(InboxViewManager.class);
    this.inboxView.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View view, int i, KeyEvent keyEvent) {
            return false;
        }
    });
}
项目:boohee_v5.6    文件:MQBasePopupWindow.java   
private void init(Activity activity, View anchorView) {
    getContentView().setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode != 4) {
                return false;
            }
            MQBasePopupWindow.this.dismiss();
            return true;
        }
    });
    setBackgroundDrawable(new ColorDrawable(0));
    this.mAnchorView = anchorView;
    this.mActivity = activity;
    this.mWindowRootView = activity.getWindow().peekDecorView();
}
项目:ircradio    文件:ActChatLog.java   
synchronized private void initialize() {


    listview = (ListView)this.findViewById(R.id.ListViewServerLog);
    //font style  mono for server log.
    Typeface typeface = Typeface.DEFAULT;
    if (Globo.chatlogActType.equals("server") ) {
        typeface = Typeface.MONOSPACE;
    }

    adapter = new ListChatAdapter(this, typeface, Globo.chatlogActAccountName  );
    listview.setAdapter(adapter);
    this.registerForContextMenu(listview);
    Globo.actChatlogVisisble = true;



    //initialize textbox
    et = (EditText)this.findViewById(R.id.textinput);
    et.setOnKeyListener(new OnKeyListener()
      {public boolean onKey(View v, int keyCode, KeyEvent event){

        if (keyCode == KeyEvent.KEYCODE_ENTER) {                
            if (event.getAction() == KeyEvent.ACTION_UP) {                  
                postmessage();
                return true;                        
            }               
            return true;
        }
        return false;
      }
      }); 



}
项目:AbacusUtil    文件:Observer.java   
public Disposable onKey(final OnKeyListener onNext, final Consumer<? super Exception> onError, final Runnable onComplete) {
    N.requireNonNull(onNext, "onNext");
    N.requireNonNull(onError, "onError");
    N.requireNonNull(onComplete, "onComplete");

    dispatcher.append(new DispatcherBase<Object>(onError, onComplete) {
        @Override
        public void onNext(Object param) {
            final Tuple3<View, Integer, KeyEvent> tmp = (Tuple3<View, Integer, KeyEvent>) param;

            if (Fu.isUiThread()) {
                onNext.onKey(tmp._1, tmp._2, tmp._3);
            } else {
                UIExecutor.execute(new Runnable() {
                    @Override
                    public void run() {
                        onNext.onKey(tmp._1, tmp._2, tmp._3);
                    }
                });
            }
        }
    });

    _view.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            dispatcher.onNext(Tuple.of(view, keyCode, event));
            return true;
        }
    });

    disposeActions.add(new Runnable() {
        @Override
        public void run() {
            _view.setOnKeyListener(null);
        }
    });

    return this;
}
项目:IPRJapp    文件:Iprj_Fragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
           Bundle savedInstanceState) {


     View rootView = inflater.inflate(R.layout.fragment_horario, container, false);

    //ActionBar actionBar = getActivity().getActionBar();

     //  actionBar.hide();

       webView = (WebView) rootView.findViewById(R.id.webView1);
       WebSettings settings = webView.getSettings();
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
       progress = (ProgressBar) rootView.findViewById(R.id.progressBar1);
    webView.setWebViewClient(new myWebClient());        
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setBuiltInZoomControls(true);

//  webView.getSettings().setBuiltInZoomControls(true);

    webView.loadUrl("http://iprj.uerj.br/");        
    webView.setOnKeyListener(new OnKeyListener(){

            public boolean onKey(View v, int keyCode, KeyEvent event) {
                  if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
                        handler.sendEmptyMessage(1);
                        return true;
                    }
                    return true;
            }


        });


      return rootView;
   }
项目:IPRJapp    文件:AlunoOnlineFragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
           Bundle savedInstanceState) {

      //inflando layout reusável
       View rootView = inflater.inflate(R.layout.fragment_horario, container, false);

       ActionBar actionBar = getActivity().getActionBar();

       //declarando a webview
       webView = (WebView) rootView.findViewById(R.id.webView1);
       progress = (ProgressBar) rootView.findViewById(R.id.progressBar1);       
    webView.setWebViewClient(new myWebClient());        
    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.loadUrl("https://www.alunoonline.uerj.br/requisicaoaluno/requisicaoacesso.php?requisicao=LoginAlunoOnline");

    webView.setOnKeyListener(new OnKeyListener(){

           public boolean onKey(View v, int keyCode, KeyEvent event) {
                 if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
                       handler.sendEmptyMessage(1);
                       return true;
                   }
                   return true;
           }



       });


       return rootView;
   }
项目:IPRJapp    文件:Uerj_tk_Fragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
           Bundle savedInstanceState) {


     View rootView = inflater.inflate(R.layout.fragment_horario, container, false);

    //ActionBar actionBar = getActivity().getActionBar();

     //  actionBar.hide();

       webView = (WebView) rootView.findViewById(R.id.webView1);
       progress = (ProgressBar) rootView.findViewById(R.id.progressBar1);
    webView.setWebViewClient(new myWebClient());
       WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.loadUrl("http://uerj.tk/index.php");        
    webView.setOnKeyListener(new OnKeyListener(){

           public boolean onKey(View v, int keyCode, KeyEvent event) {
                 if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
                       handler.sendEmptyMessage(1);
                       return true;
                   }
                   return true;
           }


       });
      return rootView;
   }
项目:IPRJapp    文件:Moodle_Fragment.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
           Bundle savedInstanceState) {


    View rootView = inflater.inflate(R.layout.fragment_horario, container, false);

       webView = (WebView) rootView.findViewById(R.id.webView1);
       WebSettings settings = webView.getSettings();
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
       progress = (ProgressBar) rootView.findViewById(R.id.progressBar1);
    webView.setWebViewClient(new myWebClient());

        //  webView.getSettings().setBuiltInZoomControls(true);
    webView.loadUrl("http://ead.iprj.uerj.br/moodle/");
    webView.setOnKeyListener(new OnKeyListener(){

           public boolean onKey(View v, int keyCode, KeyEvent event) {
                 if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
                       handler.sendEmptyMessage(1);
                       return true;
                   }
                   return true;
           }


       });


      return rootView;
   }
项目:KJBlog    文件:CurtainViewController.java   
/**
 * 为控件做一些属性设置
 */
protected void prepareSlidingLayout() {
    curtainLayoutParams = (FrameLayout.LayoutParams) curtainParent
            .getLayoutParams();
    ViewTreeObserver vto = curtainParent.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            hideCurtainLayout();
            ViewTreeObserver obs = curtainParent.getViewTreeObserver();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                obs.removeOnGlobalLayoutListener(this);
            } else {
                obs.removeGlobalOnLayoutListener(this);
            }
        }

    });

    curtainParent.setOnTouchListener(new OnContentTouchListener());

    curtainParent.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK
                    && getSlidingStatus() == SlidingStatus.EXPANDED) {
                collapse();
                return true;
            } else {
                return false;
            }
        }
    });
}
项目:Logistics    文件:PulldownMenuView.java   
/**
 * ע��˵�������¼�
 * @param gridView
 */
private void setMenuListener(GridView gridView){
    if (null == gridView.getOnItemClickListener()){
        gridView.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(
                    AdapterView<?> parent, 
                    View view,
                    int position, 
                    long id){
                if (null != menuItemListener){
                    menuItemListener.onMenuItemClick(parent, view, position);
                }

                hide();
            }
        });
    }

    // �����ؼ���˵������ز˵�
    gridView.setOnKeyListener(new OnKeyListener(){
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event){
            if (event.getAction() == KeyEvent.ACTION_DOWN){
                switch (keyCode){
                case KeyEvent.KEYCODE_BACK:
                case KeyEvent.KEYCODE_MENU:
                    hide();
                    break;
                }
            }

            return false;
        }
    });
}
项目:itmarry    文件:MainActivity.java   
public void showPopupWindow(int x, int y) {
    //
    if (mFileLists != null && mFileLists.size() > 0) {
        mSearchAdatper = new ScanFileAdapter(MainActivity.this, mFileLists);
        scanFileGridView.setAdapter(mSearchAdatper);
        scanFileGridView.requestFocus();
    }
    //
    scanFileGridView.setOnKeyListener(new OnKeyListener() {
        // 焦点到了gridview上,所以需要监听此处的键盘事件。否则会出现不响应键盘事件的情况
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            switch (keyCode) {
            case KeyEvent.KEYCODE_MENU:
                if (mPopuwindow != null && mPopuwindow.isShowing()) {
                    mPopuwindow.dismiss();
                }
                break;
            }
            return true;
        }
    });

    mPopuwindow = new PopupWindow(searchDialoglayout,
            ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    //
    ColorDrawable cd = new ColorDrawable(-0000);
    mPopuwindow.setBackgroundDrawable(cd);
    // mPopuwindow.setAnimationStyle(R.style.popuWindowAnimationStyle);
    mPopuwindow.setOutsideTouchable(true);
    mPopuwindow.setFocusable(true);
    mPopuwindow.showAtLocation(searchDialoglayout, Gravity.TOP, x, y);
    searchDialoglayout.startAnimation(AnimationUtils.loadAnimation(
            MainActivity.this, R.anim.popu_enter));
}
项目:KJFrameForAndroid    文件:CurtainViewController.java   
/**
 * 为控件做一些属性设置
 */
protected void prepareSlidingLayout() {
    curtainLayoutParams = (FrameLayout.LayoutParams) curtainParent
            .getLayoutParams();
    ViewTreeObserver vto = curtainParent.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            hideCurtainLayout();
            ViewTreeObserver obs = curtainParent.getViewTreeObserver();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                obs.removeOnGlobalLayoutListener(this);
            } else {
                obs.removeGlobalOnLayoutListener(this);
            }
        }

    });

    curtainParent.setOnTouchListener(new OnContentTouchListener());

    curtainParent.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK
                    && getSlidingStatus() == SlidingStatus.EXPANDED) {
                collapse();
                return true;
            } else {
                return false;
            }
        }
    });
}
项目:EasyAccess    文件:ContactsDetailsMenu.java   
/**
 * Attaches onKey listener to the Button passed as a parameter to the
 * method. If enter key on the keyboard or center key on the keypad is
 * pressed, the value of the parameter passed is checked and passed to
 * onSpaceEvent method.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 * @param buttonFlag
 *            If the value of buttonFlag is 1, the contact ID is passed to
 *            onSpaceEvent method. If the value of buttonFlag is 2 or 3, the
 *            contact ID, number and type of number are passed to
 *            onSpaceEvent method. If the value of buttonFlag is 4, the
 *            contact ID and email ID of the contact are passed to
 *            onSpaceEvent method.
 * @param num
 *            The number of the contact.
 * @param numType
 *            The type of number of the contact.
 * @param email
 *            The email ID of the contact.
 */
void attachKeyListener(final Button button, final int buttonFlag,
        final String num, final String numType, final String email) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_SPACE:
                    switch (buttonFlag) {
                    case 1:
                        onSpaceEvent(button,
                                ContactsDetailsMenu.this.contactId, button
                                        .getText().toString(), null, null,
                                null);
                        break;
                    case 2:
                    case 3:
                        onSpaceEvent(button,
                                ContactsDetailsMenu.this.contactId, button
                                        .getText().toString(), num,
                                numType, null);
                        break;
                    case 4:
                        onSpaceEvent(button,
                                ContactsDetailsMenu.this.contactId, button
                                        .getText().toString(), null, null,
                                email);
                        break;
                    }
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:ContactsOtherOptions.java   
/**
 * Attaches onKey listener to the Button passed as a parameter to the
 * method. If enter key on the keyboard or center key on the keypad is
 * pressed, the value of the parameter passed is checked.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 * @param buttonFlag
 *            If the value of buttonFlag is 1, an alert dialog is displayed,
 *            to confirm the delete operation. If the value of buttonFlag is
 *            2, the contact is copied to the SD card. If the value of
 *            buttonFlag is 3, all the contacts are exported to the SD card.
 *            If the value of buttonFlag is 4, contacts are imported from
 *            the SD card.
 */

private void attachKeyListener(Button button, final int buttonFlag) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    switch (buttonFlag) {
                    case 1:
                        confirmDelete(getString(R.string.deleteSingleContacConfirm));
                        break;
                    case 2:
                        copyToSDcard();
                        break;
                    case 3:
                        export();
                        break;
                    case 4:
                        importContact();
                        break;
                    }
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:TextMessagesViewerApp.java   
/**
 * Attaches onKeyListener to the button passed as a parameter to the method.
 * If enter key on the keyboard or center key on the keypad is pressed, the
 * value of the parameter passed is checked.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 * @param buttonFlag
 *            If the value of buttonFlag is 1, the method used to reply to
 *            the sender is called. If the value of buttonFlag is 2, the
 *            method used to call the sender is called. If the value of
 *            buttonFlag is 3, the user is asked if he would like to delete
 *            all them messages from the sender.
 */
void attachKeyListener(Button button, final int buttonFlag) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    switch (buttonFlag) {
                    case 1:
                        reply();
                        break;
                    case 2:
                        call();
                        break;
                    case 3:
                        confirmDelete(
                                getString(R.string.deleteConfirmation), 1,
                                null);
                        break;
                    }
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:TextMessagesApp.java   
/**
 * Attaches onKeyListener to the Button passed as a parameter to the method.
 * The method corresponding to the button on which the enter key of the
 * keyboard or the center key of the keypad is pressed.
 * 
 * @param button
 *            The button with which the onKeyListener is to be associated.
 * @param buttonFlag
 *            If the value of buttonFlag is 1, the messages in the inbox are
 *            loaded. If the value of buttonFlag is 2, the messages that are
 *            sent are loaded. If the value of buttonFlag is 3, the activity
 *            required to compose a text message is launched.
 */
void attachKeyListener(final Button button, final int buttonFlag) {
    button.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    switch (buttonFlag) {
                    case 1:
                        loadInboxMessages();
                        break;
                    case 2:
                        loadSentMessages();
                        break;
                    case 3:
                        compose();
                        break;
                    }
                    break;
                }
            }
            return false;
        }
    });
}
项目:EasyAccess    文件:SettingsFont.java   
/**
 * Attaches onKey listener to the Button passed as a parameter to the
 * method. The method corresponding to the button on which the enter key of
 * the keyboard or the center key of the keypad is pressed.
 * 
 * @param button
 *            This is an instance of Button.
 */
void attachKeyListener(final Button button) {
    button.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
            if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    switch (view.getId()) {
                    case R.id.btnApplyFont:
                        reset();
                        break;
                    case R.id.btnIncrease:
                        increase();
                        break;
                    case R.id.btnDecrease:
                        decrease();
                        break;
                    }
                    break;
                }
            }
            return false;
        }
    });
}
项目:XAppSearch    文件:ViewManagerService.java   
public void addView(boolean hide) {
    createView();
    showMainView(false);
    if (hide) {
        showSideView(false);
    }
    mT9AppsView.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View arg0, int arg1, KeyEvent event) {
            Log.d(TAG, "onKeyDown : " + KeyEvent.keyCodeToString(event.getKeyCode()));
            return false;
        }
    });
}
项目:HereAStory-Android    文件:EcommerceFragment.java   
private void setupAutoCalculate(View view, int editTextId) {
    final EditText editText = (EditText) view.findViewById(editTextId);
    editText.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            calculate(getView());
            return false;
        }
    });
}
项目:mythling    文件:MediaActivity.java   
void initListViewDpadHandler() {
    if (getAppSettings().isTv()) {
        getListView().setOnKeyListener(new OnKeyListener() {
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN) {
                    if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
                        Listable listable = getListables().get(getSelItemIndex());
                        if (listable instanceof Category) {
                            getListView().performItemClick(getListAdapter().getView(selItemIndex, null, null),
                                    selItemIndex, getListAdapter().getItemId(selItemIndex));
                            return true;
                        } else if (isSplitView()) {
                            getListAdapter().setSelection(selItemIndex);
                            getListView().setItemChecked(selItemIndex, true);
                            showItemInDetailPane(selItemIndex, true);
                            return true;
                        }
                    }
                    else if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT && !"".equals(getPath())) {
                        onBackPressed();
                        return true;
                    }
                }
                return false;
            }
        });
    }
}
项目:IkantechSupport    文件:YiPopupWindow.java   
protected void initContentView(View contentView)
{
    if (contentView == null)
    {
        return;
    }
    contentView.setFocusable(true);
    contentView.setFocusableInTouchMode(true);
    contentView.setOnKeyListener(new OnKeyListener()
    {
        @Override
        public boolean onKey(View arg0, int arg1, KeyEvent arg2)
        {
            if (arg1 == KeyEvent.KEYCODE_BACK)
            {
                if (isShowing())
                {
                    dismiss();
                }
            }
            return false;
        }
    });
    contentView.setOnTouchListener(new OnTouchListener()
    {
        @Override
        public boolean onTouch(View v, MotionEvent event)
        {
            if (isShowing())
            {
                dismiss();
            }
            return false;
        }
    });
}
项目:openxface-android    文件:XInAppBrowser.java   
/**
 * 创建文本编辑框
 * @param id 文本编辑框的唯一标识
 * @param layoutParams 布局参数
 * @param isSingleLine 是否是单行显示
 * @param text 文本框的内容
 * @param inputType 输入类型
 * @param imeOption ime选项
 * @param listener 事件监听器
 * @return
 */
protected EditText createEditText(int id,
        RelativeLayout.LayoutParams layoutParams, boolean isSingleLine,
        String text, int inputType, int imeOption,
        View.OnKeyListener listener) {
    EditText editText = new EditText(mContext);
    editText.setLayoutParams(layoutParams);
    editText.setId(id);
    editText.setSingleLine(true);
    editText.setText(text);
    editText.setInputType(inputType);
    editText.setImeOptions(imeOption);
    editText.setOnKeyListener(listener);
    return editText;
}
项目:Huochexing12306    文件:TicketOnlineAty.java   
private void initViews() {
    mStartPage = getIntent().getStringExtra(EXTRA_START_PAGE);
    mPostParams = getIntent().getStringExtra(EXTRA_POST_PARAMS);

    llytAddrBar = (LinearLayout)findViewById(R.id.llyt1);
    etUrl = (EditText) findViewById(R.id.content);
    btnGo = (ImageButton)findViewById(R.id.ok);
    btnGo.setOnClickListener(this);
    pb1 = (ProgressBar)findViewById(R.id.pb1);
    btnBack = (ImageButton)findViewById(R.id.back);
    btnBack.setOnClickListener(this);
    btnForward = (ImageButton)findViewById(R.id.forward);
    btnForward.setOnClickListener(this);
    btnHome = (ImageButton)findViewById(R.id.home);
    btnHome.setOnClickListener(this);
    btnStop = (ImageButton)findViewById(R.id.stop);
    btnStop.setOnClickListener(this);
    btnRefesh = (ImageButton)findViewById(R.id.refesh);
    btnRefesh.setOnClickListener(this);
    llytWebViewContainer = (LinearLayout)findViewById(R.id.ticketOnline_llytWebViewContainer);
    wv1 = WebViewUtil.buildWebView(this, pb1);
    wv1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    llytWebViewContainer.addView(wv1);
    etUrl.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    String url = etUrl.getText().toString();
                    if (!url.startsWith("http://") || !url.startsWith("https://")){
                        url = "http://" + url;
                    }
                    wv1.loadUrl(url);
                    InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    inputManager.hideSoftInputFromWindow(
                            etUrl.getWindowToken(), 0);
                    return true;
                default:
                    break;
                }
            }
            return false;
        }
    });
    if (HttpUtil.isNetworkConnected(this)){
        if (mStartPage == null || "".equals(mStartPage)){
            etUrl.setText(mHomePage);
            wv1.loadUrl(mHomePage);
        }else{
            if (mPostParams == null){
                etUrl.setText(mStartPage);
                wv1.loadUrl(mStartPage);
            }else{
                //以post方式打开页面
                llytAddrBar.setVisibility(View.GONE);
                wv1.postUrl(mStartPage, EncodingUtils.getBytes(mPostParams, "BASE64"));
            }
        }
    }else{
        showMsg("没有网络" + SF.NO_NETWORK);
    }
}
项目:aos-Video    文件:Browser.java   
/**
 * According the view mode, get the common object for the adapter.
 */
private void initList(final AbsListView list){
    list.setOnItemClickListener(this);
    list.setOnItemLongClickListener(this);
    // register for context menu.
    list.setOnCreateContextMenuListener(this);
    list.setOnScrollListener(this);
    list.setOnTouchListener(this);
    list.setChoiceMode(AbsListView.CHOICE_MODE_NONE);

    // Setup key listener to open extender with right key or L1 or R1 or "i"
    list.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // All is done on action down because it also moves the focus, hence we can't wait for action up


             /*
              * Work around to handle issues on focus for android 4.1
              * 
              * Sometimes it is impossible to down with the pad.
              * what we know :
              * before going to the onkey method, list should have scrolled (except when and issue occured)
              * so, if we are going down, the last visible item has to be focused item +1 (focus is done after the function, when  return false)
              * if last visible item == selected item even if this isn't the last item of the list, then the list won't scroll anymore.
              * So we scroll it manually.
              * 
              */
            if (event.getAction() == KeyEvent.ACTION_DOWN && mArchosGridView instanceof ListView) {
                if (keyCode == KeyEvent.KEYCODE_DPAD_UP && mArchosGridView.getFirstVisiblePosition() == mArchosGridView.getSelectedItemPosition() && mArchosGridView.getSelectedItemPosition() > 0) {

                    mArchosGridView.setSelection(mArchosGridView.getSelectedItemPosition() - 1);
                    return true;


                }
                if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && mArchosGridView.getLastVisiblePosition() == mArchosGridView.getSelectedItemPosition()
                        && mArchosGridView.getSelectedItemPosition() < mArchosGridView.getCount()) {
                    View v2 = mArchosGridView.getChildAt(mArchosGridView.getSelectedItemPosition() - mArchosGridView.getFirstVisiblePosition());
                    int scrollTo = (v2 == null) ? 0 : v2.getTop();
                    //we want the selected item to be at the end of the list
                    if (mArchosGridView instanceof ListView)
                        ((ListView) mArchosGridView).setSelectionFromTop(mArchosGridView.getSelectedItemPosition() + 1,
                                scrollTo);
                    return true;


                }

            }
            if (event.getAction() != KeyEvent.ACTION_DOWN)
                return false;
            if ((keyCode == KeyEvent.KEYCODE_BUTTON_L1) || (keyCode == KeyEvent.KEYCODE_BUTTON_R1) ||   // Nice for LUDO (even if an hidden feature)
                    (keyCode == KeyEvent.KEYCODE_I) ||                                                // Nice for any keyboard, LUDO included
                    ((keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) && (list instanceof GridView && (((GridView) list).getNumColumns() < 2) || list instanceof ListView)))// Right arrow is only used in list mode, can't be in grid mode
            {
                View selectedView = list.getSelectedView();
                if (selectedView != null) {
                    // Check that there is a visible "expander" in the selected list item
                    View expandView = selectedView.findViewById(R.id.expanded);
                    if ((expandView != null) && (expandView.getVisibility() == View.VISIBLE)) {
                        if (getFileType(list.getSelectedItemPosition()) == FileType.SmbDir)
                            return false;
                        expandView.requestFocus(); //test
                        displayInfo(list.getSelectedItemPosition());
                        return true;
                    }
                }
            }
            return false;
        }
    });

}
项目:AndroidViewHelper    文件:ViewWrapper.java   
/**
* @see View#setOnKeyListener(OnKeyListener)
*/
 public W setOnKeyListener(OnKeyListener l) {
     mView.setOnKeyListener(l);
     return (W)this;
 }
项目:android-project-gallery    文件:BottomMenu.java   
@SuppressWarnings("deprecation")
public void showBottomView(boolean onTouchOutsideable)
{
    if (this.mTheme == 0)
    {
        this.dialog = new Dialog(mContext);
    }
    else
    {
        this.dialog = new Dialog(mContext, mTheme);
    }

    this.dialog.setCanceledOnTouchOutside(onTouchOutsideable);
    this.dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    this.dialog.setContentView(this.mContentView);

    this.mContentView.setFocusable(true);
    this.mContentView.setFocusableInTouchMode(true);
    this.mContentView.setOnKeyListener(new OnKeyListener()
    {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event)
        {
            if (keyCode == KeyEvent.KEYCODE_MENU && event.getAction() == KeyEvent.ACTION_DOWN && dialog.isShowing())
            {
                dialog.dismiss();

                return true;
            }

            return false;
        }
    });


    Window wm = this.dialog.getWindow();
    WindowManager m = wm.getWindowManager();
    Display d = m.getDefaultDisplay();
    WindowManager.LayoutParams p = wm.getAttributes();
    p.width = (d.getWidth() * 1);
    if (this.isTop)
    {
        p.gravity = Gravity.TOP;
    }
    else
    {
        p.gravity = Gravity.BOTTOM;
    }

    if (this.animationStyle != 0)
    {
        wm.setWindowAnimations(this.animationStyle);
    }

    wm.setAttributes(p);
    this.dialog.show();
}
项目:ExoPlayerController    文件:PlayerActivity.java   
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
// TODO:
//      setContentView(R.layout.player_activity);
        setContentView(R.layout.player_activity_two);
        root = findViewById(R.id.root);
        root.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    toggleControlsVisibility();
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                    view.performClick();
                }
                return true;
            }
        });
        root.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                        || keyCode == KeyEvent.KEYCODE_MENU) {
                    return false;
                }
                // TODO: return mediaController.dispatchKeyEvent(event);
                return goatMediaController.dispatchKeyEvent(event);
            }
        });

        shutterView = findViewById(R.id.shutter);
        debugRootView = findViewById(R.id.controls_root);

        videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
        surfaceView = (SurfaceView) findViewById(R.id.surface_view);
        surfaceView.getHolder().addCallback(this);
        debugTextView = (TextView) findViewById(R.id.debug_text_view);

        playerStateTextView = (TextView) findViewById(R.id.player_state_view);
        subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles);
        // TODO:
        // mediaController = new MediaController(this);
        // mediaController.setAnchorView(root);
        goatMediaController = (GoatMediaController) findViewById(R.id.media_controller);
        retryButton = (Button) findViewById(R.id.retry_button);
        retryButton.setOnClickListener(this);
        videoButton = (Button) findViewById(R.id.video_controls);
        audioButton = (Button) findViewById(R.id.audio_controls);
        textButton = (Button) findViewById(R.id.text_controls);

        CookieHandler currentHandler = CookieHandler.getDefault();
        if (currentHandler != defaultCookieManager) {
            CookieHandler.setDefault(defaultCookieManager);
        }

        audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
        audioCapabilitiesReceiver.register();

        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
    }