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.ichi2.anki2.StudyOptionsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        Log.i(AnkiDroidApp.TAG, "StudyOptions - onBackPressed()");
        if (mCurrentFragment == null || !mCurrentFragment.congratsShowing()) {
            closeStudyOptions();/*  w w  w .j a v  a2s  .co m*/
        }
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.itude.mobile.mobbl.core.controller.MBViewManager.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Take care of calling this method on earlier versions of
        // the platform where it doesn't exist.
        onBackPressed();//from w w  w.j a va  2s  .c o m

        return true;
    } else {
        // Pass this onKeyDown event trough to the underlying fragments
        if (!getActiveDialog().onKeyDown(keyCode, event))
            return super.onKeyDown(keyCode, event);
        else
            return true;
    }

}

From source file:course1778.mobileapp.safeMedicare.Main.FamMemFrag.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    //ListView listView = (ListView) view.findViewById(R.id.list_view);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.fam_mem_frag, current,
            new String[] { DatabaseHelper.TITLE,
                    //String.format(format, DatabaseHelper.TIME_H),
                    DatabaseHelper.TIME_H,
                    //String.format(format, DatabaseHelper.TIME_M)},
                    DatabaseHelper.TIME_M },
            new int[] { R.id.title, R.id.time_h, R.id.time_m }, 0);

    setListAdapter(adapter);/*from www  .  j  av  a2s  . co  m*/
    //listView.setAdapter(adapter);

    //        if (current == null) {
    db = new DatabaseHelper(getActivity());
    dbInteraction = new DatabaseInteractionHelper(getActivity());
    task = new LoadCursorTask().execute();
    //        }

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                Intent intent = new Intent(getActivity().getApplicationContext(), WelcomePage.class);
                startActivity(intent);
                return true;
            } else {
                return false;
            }
        }
    });
}

From source file:com.horaapps.leafpic.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_player);

    FrameLayout root = (FrameLayout) findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override/*from w ww .j  a  va2 s.  c om*/
        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) {
            return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event);
        }
    });

    root.setBackgroundColor(R.color.md_black_1000);

    shutterView = findViewById(R.id.shutter);

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

    mediaController = new KeyCompatibleMediaController(this);

    mediController_anchor = findViewById(R.id.media_player_anchor);
    mediaController.setAnchorView(mediController_anchor);
    mediaController.setPaddingRelative(0, 0, 0, Measure.getNavBarHeight(PlayerActivity.this));
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    initUI();

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

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

From source file:org.madmatrix.zxing.android.CaptureActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK: // ?
        if ((source == IntentSource.NONE) && lastResult != null) {
            restartPreviewAfterDelay(0L);
            return true;
        }/*from   w ww .java  2s . c o m*/
        break;
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
        // Handle these events so they don't launch the Camera app
        return true;
    // Use volume up/down to turn on light
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        cameraManager.setTorch(false);
        return true;
    case KeyEvent.KEYCODE_VOLUME_UP:
        cameraManager.setTorch(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.mercandalli.android.apps.files.user.ConversationActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        finish();/*  w  w w .  java 2  s .c  om*/
        overridePendingTransition(R.anim.right_in, R.anim.right_out);
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.hichinaschool.flashcards.anki.StudyOptionsActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        // Log.i(AnkiDroidApp.TAG, "StudyOptions - onBackPressed()");
        if (mCurrentFragment != null && mCurrentFragment.congratsShowing()) {
            mCurrentFragment.finishCongrats();
            return true;
        }//from   ww  w. ja v a 2  s.co  m
        closeStudyOptions();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.drunkenhamster.facerecognitionfps.SnapFaceActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        updateScore();/* ww w  .  j a va2s.c o  m*/
        if (calledACTION_GET_CONTENT_) {
            setResult(RESULT_CANCELED);
            tracker_.trackEvent(getString(R.string.GA_CAT_ACT), getString(R.string.GA_ACT_GET_CONTENT),
                    getString(R.string.GA_LBL_CANCEL), 1);
            finish();
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.mercandalli.android.apps.files.file.audio.FileAudioActivity.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        finishActivity();//from   ww  w.  j ava 2  s .  c o  m
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.example.android.CreateNewPlayer.java

/**
 * onKeyDown overrides onKeyDown and allows code to be executed when the
 * back button is pushed in the simulator / on the mobile phone Since
 * pushing "back" won't necessarily call the destroy method as far as I
 * understand it.//from  w  ww .j  a  v a  2  s.c o  m
 * 
 * @param keyCode
 *            : code of the key pressed
 * @param event
 *            : the event for the key pressed
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == zero) {

        // continue backwards (kills current activity calling onDestroy)
        finish();

        return true;
    }

    return super.onKeyDown(keyCode, event);
}