Example usage for android.view KeyEvent KEYCODE_BACK

List of usage examples for android.view KeyEvent KEYCODE_BACK

Introduction

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

Prototype

int KEYCODE_BACK

To view the source code for android.view KeyEvent KEYCODE_BACK.

Click Source Link

Document

Key code constant: Back key.

Usage

From source file:com.slim.turboeditor.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        onBackPressed();//w w w .ja  va 2  s  .  co  m
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_MENU) {
        return false;
    } else {
        if (mEditor == null)
            mEditor = findById(this, R.id.editor);

        // this will happen on first key pressed on hard-keyboard only. Once myInputField
        // gets the focus again, it will automatically receive further key presses.

        try {
            if (fileOpened && mEditor != null && !mEditor.hasFocus()) {
                mEditor.requestFocus();
                mEditor.onKeyDown(keyCode, event);
                return true;
            }
        } catch (NullPointerException ex) {
            // Ignore
        }
    }

    return false;
}

From source file:com.app.blockydemo.ui.fragment.FormulaEditorListFragment.java

@Override
public boolean onKey(DialogInterface d, int keyCode, KeyEvent event) {
    Log.i("info", "onKey() in FE-ListFragment! keyCode: " + keyCode);
    boolean returnValue = false;
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        Log.i("info", "KEYCODE_BACK pressed in FE-ListFragment!");
        FragmentTransaction fragTransaction = getActivity().getSupportFragmentManager().beginTransaction();
        fragTransaction.hide(this);
        fragTransaction.show(getActivity().getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG));
        fragTransaction.commit();/*from w  w w. j  a v  a 2 s.  c  o m*/
        returnValue = true;
        break;
    }
    return returnValue;
}

From source file:com.cw.litenote.note.Note.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int newPos;/*from  w  w  w  .  j  a va 2  s.c  o m*/
    System.out.println("Note / _onKeyDown / keyCode = " + keyCode);
    switch (keyCode) {
    case KeyEvent.KEYCODE_MEDIA_PREVIOUS: //88
        if (viewPager.getCurrentItem() == 0)
            newPos = mPagerAdapter.getCount() - 1;//back to last one
        else
            newPos = NoteUi.getFocus_notePos() - 1;

        NoteUi.setFocus_notePos(newPos);
        viewPager.setCurrentItem(newPos);

        BackgroundAudioService.mIsPrepared = false;
        BackgroundAudioService.mMediaPlayer = null;
        Audio_manager.isRunnableOn_page = false;
        findViewById(R.id.pager_btn_audio_play).performClick();
        return true;

    case KeyEvent.KEYCODE_MEDIA_NEXT: //87
        if (viewPager.getCurrentItem() == (mPagerAdapter.getCount() - 1))
            newPos = 0;
        else
            newPos = NoteUi.getFocus_notePos() + 1;

        NoteUi.setFocus_notePos(newPos);
        viewPager.setCurrentItem(newPos);

        BackgroundAudioService.mIsPrepared = false;
        BackgroundAudioService.mMediaPlayer = null;
        Audio_manager.isRunnableOn_page = false;
        AudioUi_note.mPager_audio_play_button.performClick();
        return true;

    case KeyEvent.KEYCODE_MEDIA_PLAY: //126
        AudioUi_note.mPager_audio_play_button.performClick();
        return true;

    case KeyEvent.KEYCODE_MEDIA_PAUSE: //127
        AudioUi_note.mPager_audio_play_button.performClick();
        return true;

    case KeyEvent.KEYCODE_BACK:
        onBackPressed();
        return true;

    case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
        return true;

    case KeyEvent.KEYCODE_MEDIA_REWIND:
        return true;

    case KeyEvent.KEYCODE_MEDIA_STOP:
        return true;
    }
    return false;
}

From source file:com.aman.stockcalculator.Calculator.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
    if (keyCode == KeyEvent.KEYCODE_BACK && getAdvancedVisibility() && mPager != null) {
        mPager.setCurrentItem(BASIC_PANEL);
        return true;
    } else {//  w  w w.ja  v a  2  s .c  o m
        return super.onKeyDown(keyCode, keyEvent);
    }
}

From source file:com.example.sample.provider.SampleProvider.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        try {/* w w  w. j a  va2s  . co m*/
            mySensor.destroyResource();

            if (isExecutePresence == true) {
                OcPlatform.stopPresence();
                isExecutePresence = false;
            }
        } catch (OcException e) {

            e.printStackTrace();
        }
        LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver);
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.dnielfe.manager.BrowserActivity.java

@Override
public boolean onKeyDown(int keycode, @NonNull KeyEvent event) {
    if (keycode != KeyEvent.KEYCODE_BACK)
        return false;

    if (isDrawerOpen()) {
        mDrawerLayout.closeDrawer(mDrawer);
        return true;
    }//www .  j  a va 2 s  .c o  m
    return BrowserTabsAdapter.getCurrentBrowserFragment().onBackPressed();
}

From source file:com.metinkale.prayerapp.vakit.Main.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        Fragment frag = getSupportFragmentManager().findFragmentByTag("notPrefs");
        if (frag != null) {
            setFooterText(getString(R.string.monthly), true);
            getSupportFragmentManager().beginTransaction().remove(frag).commit();
            return true;
        } else if (mBottomSlider.isOpened()) {
            mBottomSlider.animateClose();
            return true;
        } else if (mTopSlider.isOpened()) {
            mTopSlider.animateClose();//  ww w . java 2 s  . co m
            return true;
        }

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

From source file:com.best.ui.Otpdescdetail.java

public boolean onKeyDown(int keyCode, KeyEvent event) {//If back was pressed
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        System.out.println("back of Otpdescdetail clicked");
        back();//w  w w.j a va2 s .  com
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:apijson.demo.client.activity_fragment.MainTabActivity.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        long secondTime = System.currentTimeMillis();
        if (secondTime - firstTime > 2000) {
            showShortToast("?");
            firstTime = secondTime;//from  ww  w . j a  v a  2  s . c om
        } else {//
            sendBroadcast(new Intent(ACTION_EXIT_APP));
        }
        return true;
    }

    return super.onKeyUp(keyCode, event);
}

From source file:com.ichi2.anki.PreferenceContext.java

@Override
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Timber.i("Preferences:: onBackPressed()");
        closePreferences();/*from   ww w.  ja  v  a 2s.  co m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}