Example usage for android.view KeyEvent getRepeatCount

List of usage examples for android.view KeyEvent getRepeatCount

Introduction

In this page you can find the example usage for android.view KeyEvent getRepeatCount.

Prototype

public final int getRepeatCount() 

Source Link

Document

Retrieve the repeat count of the event.

Usage

From source file:com.bluros.music.helpers.MediaButtonIntentReceiver.java

@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        if (PreferencesUtility.getInstance(context).pauseEnabledOnDetach())
            startService(context, MusicService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }/*  ww w. j a v a  2 s  .  co m*/

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MusicService.CMDTOGGLEPAUSE.equals(command) || MusicService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {

                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:com.gecq.musicwave.player.MediaButtonIntentReceiver.java

/**
 * {@inheritDoc}/*  w w  w  .j  a  v a  2 s  .  c o m*/
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    if (DEBUG)
        Log.v(TAG, "Received intent: " + intent);
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, PlayerService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = PlayerService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = PlayerService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = PlayerService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = PlayerService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = PlayerService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = PlayerService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (PlayerService.CMDTOGGLEPAUSE.equals(command) || PlayerService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:com.andrew.apollo.MediaButtonIntentReceiver.java

/**
 * {@inheritDoc}/*from  w w w .  j ava 2 s. c o  m*/
 */
@Override
public void onReceive(final Context context, final Intent intent) {
    if (DEBUG)
        Log.v(TAG, "Received intent: " + intent);
    final String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
        startService(context, MusicPlaybackService.CMDPAUSE);
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        final KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
        if (event == null) {
            return;
        }

        final int keycode = event.getKeyCode();
        final int action = event.getAction();
        final long eventtime = event.getEventTime();

        String command = null;
        switch (keycode) {
        case KeyEvent.KEYCODE_MEDIA_STOP:
            command = MusicPlaybackService.CMDSTOP;
            break;
        case KeyEvent.KEYCODE_HEADSETHOOK:
        case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
            command = MusicPlaybackService.CMDTOGGLEPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_NEXT:
            command = MusicPlaybackService.CMDNEXT;
            break;
        case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
            command = MusicPlaybackService.CMDPREVIOUS;
            break;
        case KeyEvent.KEYCODE_MEDIA_PAUSE:
            command = MusicPlaybackService.CMDPAUSE;
            break;
        case KeyEvent.KEYCODE_MEDIA_PLAY:
            command = MusicPlaybackService.CMDPLAY;
            break;
        }
        if (command != null) {
            if (action == KeyEvent.ACTION_DOWN) {
                if (mDown) {
                    if (MusicPlaybackService.CMDTOGGLEPAUSE.equals(command)
                            || MusicPlaybackService.CMDPLAY.equals(command)) {
                        if (mLastClickTime != 0 && eventtime - mLastClickTime > LONG_PRESS_DELAY) {
                            acquireWakeLockAndSendMessage(context,
                                    mHandler.obtainMessage(MSG_LONGPRESS_TIMEOUT, context), 0);
                        }
                    }
                } else if (event.getRepeatCount() == 0) {
                    // Only consider the first event in a sequence, not the repeat events,
                    // so that we don't trigger in cases where the first event went to
                    // a different app (e.g. when the user ends a phone call by
                    // long pressing the headset button)

                    // The service may or may not be running, but we need to send it
                    // a command.
                    if (keycode == KeyEvent.KEYCODE_HEADSETHOOK) {
                        if (eventtime - mLastClickTime >= DOUBLE_CLICK) {
                            mClickCounter = 0;
                        }

                        mClickCounter++;
                        if (DEBUG)
                            Log.v(TAG, "Got headset click, count = " + mClickCounter);
                        mHandler.removeMessages(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT);

                        Message msg = mHandler.obtainMessage(MSG_HEADSET_DOUBLE_CLICK_TIMEOUT, mClickCounter, 0,
                                context);

                        long delay = mClickCounter < 3 ? DOUBLE_CLICK : 0;
                        if (mClickCounter >= 3) {
                            mClickCounter = 0;
                        }
                        mLastClickTime = eventtime;
                        acquireWakeLockAndSendMessage(context, msg, delay);
                    } else {
                        startService(context, command);
                    }
                    mLaunched = false;
                    mDown = true;
                }
            } else {
                mHandler.removeMessages(MSG_LONGPRESS_TIMEOUT);
                mDown = false;
            }
            if (isOrderedBroadcast()) {
                abortBroadcast();
            }
            releaseWakeLockIfHandlerIdle();
        }
    }
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * Filter pre-IME key events. By forwarding {@link View#onKeyPreIme(int, KeyEvent)}
 * events to this function, views using ListPopupWindow can have it dismiss the popup
 * when the back key is pressed.//from  ww  w.  j a  v a 2s  .c o  m
 *
 * @param keyCode keyCode param passed to the host view's onKeyPreIme
 * @param event event param passed to the host view's onKeyPreIme
 * @return true if the event was handled, false if it was ignored.
 * @see #setModal(boolean)
 */
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && isShowing()) {
        // special case for the back key, we do not even try to send it
        // to the drop down list but instead, consume it immediately
        final View anchorView = mDropDownAnchorView;
        if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) {
            KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState();
            if (state != null) {
                state.startTracking(event, this);
            }
            return true;
        } else if (event.getAction() == KeyEvent.ACTION_UP) {
            KeyEvent.DispatcherState state = anchorView.getKeyDispatcherState();
            if (state != null) {
                state.handleUpEvent(event);
            }
            if (event.isTracking() && !event.isCanceled()) {
                dismiss();
                return true;
            }
        }
    }
    return false;
}

From source file:org.xingjitong.LinphoneActivity.java

@SuppressLint("NewApi")
public boolean onKeyDown(int keyCode, KeyEvent event) {
    //Log.v("LinphoneActiviey.class", "yypp exit wecareapp 000");

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        //yyppoption add
        if ((statusFragment != null) && (event.getRepeatCount() < 1)) {
            if (pop.isShowing()) {
                pop.dismiss();/*from  w  ww. j  a v  a 2s  . co  m*/
                isPopShowing = false;
                return true;
            }
        }
        //yyppoption end
        if (currentFragment == FragmentsAvailable.DIALER) {
            //yyppexit  add
            /*
            Dialog dialog= new AlertDialog.Builder(this).setTitle("??????")  
                   .setIcon(android.R.drawable.ic_dialog_info)  
                   .setPositiveButton("", new DialogInterface.OnClickListener() {
               @Override  
               public void onClick(DialogInterface dialog, int which) {
               // ???  
                // System.exit(0);
                LinphoneActivity.instance().exit();
                  //?
                   //startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                    //.addCategory(Intent.CATEGORY_HOME));
               }
                   })
                   .setNegativeButton("??", new DialogInterface.OnClickListener() {
               @Override  
               public void onClick(DialogInterface dialog, int which) {
               // ???,??  
                // System.exit(0);
                //LinphoneActivity.instance().exit();
                  //?
                   startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                       .addCategory(Intent.CATEGORY_HOME));        
                    
               }  
                   }).show(); 
                    
            */
            //yyppexit end            
            //yyppexit 222 add
            /*
                AlertDialog.Builder builder = new AlertDialog.Builder(this,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
                builder.setTitle("?")    //
            .setIcon(android.R.drawable.ic_dialog_info)    //icon
            .setCancelable(false)    //??back
            .setMessage("??-????")    //?
            //
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                   //
                   dialog.dismiss();
             // System.exit(0);
             LinphoneActivity.instance().exit();
               //?
                //startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                 //.addCategory(Intent.CATEGORY_HOME));                           
                }
            })
            .setNeutralButton("?", new DialogInterface.OnClickListener() {                        
                @Override
                public void onClick(DialogInterface dialog, int which) {
                   //
                   dialog.dismiss();
                            
                }
            })
            .setNegativeButton("??", new DialogInterface.OnClickListener() {                    
                @Override
                public void onClick(DialogInterface dialog, int which) {
                   //
                   dialog.dismiss();
             // System.exit(0);
             //LinphoneActivity.instance().exit();
               //?
                startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                 .addCategory(Intent.CATEGORY_HOME));                          
                }
            }).show();
                //Dialog
                //AlertDialog dlg = builder.create();
                */

            //yyppexit 222 end            

            //yyppexit 333 add

            if ((System.currentTimeMillis() - exitTime) > 2000) {
                //Log.v("LinphoneActiviey.class", "yypp exit wecareapp 222");
                Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show();
                exitTime = System.currentTimeMillis();
                //changeCurrentFragment(FragmentsAvailable.DIALER, null);
                return true;
            } else {
                //Log.v("LinphoneActiviey.class", "yypp exit wecareapp 333");
                //finish();
                //System.exit(0);

                //?
                LinphoneActivity.instance().exit();
                //?
                //this.startActivity(new Intent().setAction(Intent.ACTION_MAIN)
                //.addCategory(Intent.CATEGORY_HOME));

                return true;
            }

            //yyppexit 333 end                  

            /*
            if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
                       
               Log.v("LinphoneActiviey.class", "yypp exit wecareapp 444");
               return true;
                       
                       
            }
            */
            //???????
        } else if (!isTablet()) {
            int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
            if (backStackEntryCount <= 1) {
                showStatusBar();
            }

            if (currentFragment == FragmentsAvailable.SETTINGS) {
                showStatusBar();
                reloadConfig();
                updateAnimationsState();
            }
            if (currentFragment == FragmentsAvailable.SETTINGS || currentFragment == FragmentsAvailable.CHATLIST
                    || currentFragment == FragmentsAvailable.HISTORY
                    || currentFragment == FragmentsAvailable.CONTACTS) {
                changeCurrentFragment(FragmentsAvailable.DIALER, null);
                return true;
            } else if (currentFragment == FragmentsAvailable.SET_CHONGZHI
                    || currentFragment == FragmentsAvailable.SET_MES
                    || currentFragment == FragmentsAvailable.SET_QUERY) {
                if (tableindex == 1)
                    changeCurrentFragment(FragmentsAvailable.SETTINGS, null);
                else
                    changeCurrentFragment(FragmentsAvailable.CHATLIST, null);
                //               resetSelection();
                //               settings.setSelected(true);
                return true;
            } else if (currentFragment == FragmentsAvailable.SET_CHONGZHIKA
                    || currentFragment == FragmentsAvailable.SET_ALIPAY) {
                changeCurrentFragment(FragmentsAvailable.SET_CHONGZHI, new Bundle());
                //               resetSelection();
                //               settings.setSelected(true);
                return true;
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_MENU && statusFragment != null) {

        Log.v("yyppdebug", "yyppoption keyevent  menu 000");
        if (event.getRepeatCount() < 1) {
            // statusFragment.openOrCloseStatusBar();
            Log.v("yyppdebug", "yyppoption keyevent  menu 111");
            //yyppoption add
            if (!pop.isShowing()) {
                Log.v("yyppdebug", "yyppoption keyevent  menu 222");
                //pop.showAtLocation(view, Gravity.BOTTOM, 0, 0);
                pop.showAtLocation(findViewById(R.id.menu), Gravity.BOTTOM, 0, 0);
                isPopShowing = true;
            } else {
                Log.v("yyppdebug", "yyppoption keyevent  menu 333");
                pop.dismiss();
                isPopShowing = false;
            }
            return true;

            //yyppoption end

        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.youku.player.base.YoukuBasePlayerActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    try {//from   w  ww.j  a  va  2  s.  c om
        switch (keyCode) {
        case KeyEvent.KEYCODE_MENU:
            // ?menu?
            if (event.getRepeatCount() > 0) {
                return true;
            }
            return mediaPlayerDelegate.isFullScreen;
        case KeyEvent.KEYCODE_BACK:
            // ???
            if (event.getRepeatCount() > 0) {
                return true;
            }
            if (!mediaPlayerDelegate.isDLNA) {
                if (mediaPlayerDelegate.isFullScreen && !isFromLocal()
                        && (mediaPlayerDelegate.videoInfo != null && !mediaPlayerDelegate.videoInfo.isHLS)) {
                    goSmall();
                    return true;
                } else {
                    onkeyback();
                    return true;
                }
            } else {
                return true;
            }
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            return volumeDown();
        case KeyEvent.KEYCODE_VOLUME_UP:
            return volumeUp();
        case KeyEvent.KEYCODE_SEARCH:
            return mediaPlayerDelegate.isFullScreen;
        case 125:
            /** popupwindow */
            return true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * Use this to monitor key events being delivered to the application.
 * We get first crack at them, and can either resume them or let them
 * continue to the app.//from w w w . ja  v a2 s  . c o m
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

    //event.
    //Log.i("OnKeyDown", "Keycode: "+keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        // The InputMethodService already takes care of the back
        // key for us, to dismiss the input method if it is shown.
        // However, our keyboard could be showing a pop-up window
        // that back should dismiss, so we first allow it to do that.
        if (event.getRepeatCount() == 0 && mInputView != null) {
            if (mInputView.handleBack()) {
                return true;
            }
        }
        break;

    case KeyEvent.KEYCODE_DEL:
        // Special handling of the delete key: if we currently are
        // composing text for the user, we want to modify that instead
        // of let the application to the delete itself.
        if (mComposing.length() > 0) {
            onKey(Keyboard.KEYCODE_DELETE, null);
            return true;
        }
        break;

    case -2: //123 button
        //Log.i("KeyDown", "Keycode: "+keyCode);
        event.startTracking();
        return true;

    case KeyEvent.KEYCODE_ENTER:
        // Let the underlying text editor always handle these.
        return false;

    default:
        // For all other keys, if we want to do transformations on
        // text being entered with a hard keyboard, we need to process
        // it and do the appropriate action.
        if (PROCESS_HARD_KEYS) {
            if (keyCode == KeyEvent.KEYCODE_SPACE && (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) {
                // A silly example: in our input method, Alt+Space
                // is a shortcut for 'android' in lower case.
                //InputConnection ic = ic;
                if (ic != null) {
                    // First, tell the editor that it is no longer in the
                    // shift state, since we are consuming this.
                    ic.clearMetaKeyStates(KeyEvent.META_ALT_ON);
                    keyDownUp(KeyEvent.KEYCODE_A);
                    keyDownUp(KeyEvent.KEYCODE_N);
                    keyDownUp(KeyEvent.KEYCODE_D);
                    keyDownUp(KeyEvent.KEYCODE_R);
                    keyDownUp(KeyEvent.KEYCODE_O);
                    keyDownUp(KeyEvent.KEYCODE_I);
                    keyDownUp(KeyEvent.KEYCODE_D);
                    // And we consume this event.
                    return true;
                }
            }
            if (mPredictionOn && translateKeyDown(keyCode, event)) {
                return true;
            }
        }
    }

    return super.onKeyDown(keyCode, event);
}

From source file:com.edible.ocr.CaptureActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        // First check if we're paused in continuous mode, and if so, just unpause.
        if (isPaused) {
            Log.d(TAG, "only resuming continuous recognition, not quitting...");
            resumeContinuousDecoding();//from   ww w .j a  va  2s .  c om
            return true;
        }

        // Exit the app if we're not viewing an OCR result.
        if (lastResult == null) {
            setResult(RESULT_CANCELED);
            finish();
            return true;
        } else {
            // Go back to previewing in regular OCR mode.
            resetStatusView();
            if (handler != null) {
                handler.sendEmptyMessage(R.id.restart_preview);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_CAMERA) {
        if (isContinuousModeActive) {
            onShutterButtonPressContinuous();
        } else {
            handler.hardwareShutterButtonClick();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_FOCUS) {
        // Only perform autofocus if user is not holding down the button.
        if (event.getRepeatCount() == 0) {
            cameraManager.requestAutoFocus(500L);
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.linphone.LinphoneActivity.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (currentFragment == FragmentsAvailable.SETTINGS) {
            //dialer.setVisibility(View.GONE);
            settings.setVisibility(View.VISIBLE);
            //mCall.setVisibility(View.VISIBLE);
        }/*w  w w  . ja va  2s  .  c  o  m*/
        if (currentFragment == FragmentsAvailable.DIALER || currentFragment == FragmentsAvailable.CONTACTS
                || currentFragment == FragmentsAvailable.HISTORY
                || currentFragment == FragmentsAvailable.CHATLIST
                || currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_CHAT
                || currentFragment == FragmentsAvailable.ABOUT_INSTEAD_OF_SETTINGS) {
            boolean isBackgroundModeActive = LinphonePreferences.instance().isBackgroundModeEnabled();
            if (!isBackgroundModeActive) {
                stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
                finish();
            } else if (LinphoneUtils.onKeyBackGoHome(this, keyCode, event)) {
                return true;
            }
        } else {
            if (isTablet()) {
                if (currentFragment == FragmentsAvailable.SETTINGS) {
                    updateAnimationsState();
                }
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_MENU && statusFragment != null) {
        if (event.getRepeatCount() < 1) {
            statusFragment.openOrCloseStatusBar(true);
        }
    }
    return super.onKeyDown(keyCode, event);
}