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.pbi.live.VideoView.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        stopPlayback();//ww  w .  j a v  a  2  s. co  m
        mLivePlayer = null;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.example.android.foodrecipes.app.RecipeDetailsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Bundle args = getArguments();/*  ww  w.ja v  a  2 s .co m*/
    if (args != null) {
        mRecipeExternalId = args.getString(RECIPE_EXTERNAL_ID);
        RecipesLoaderAdapterFactory factory = (RecipesLoaderAdapterFactory) args
                .getSerializable(LOADER_ADAPTER_FACTORY);
        if (factory != null)
            mLoaderAdapter = factory.newLoaderAdapter();

        mExecuteRecipeRemove = args.getBoolean(EXECUTE_RECIPE_REMOVE, false);
        mTwoPane = args.getBoolean(TWO_PANE, false);
    }

    View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
    mRecipeTitle = (TextView) rootView.findViewById(R.id.detail_recipe_title);
    mRecipeImage = (SquareImageView) rootView.findViewById(R.id.detail_recipe_picture);
    mSocialRank = (RatingBar) rootView.findViewById(R.id.detail_recipe_rating);
    mIngredients = (TextView) rootView.findViewById(R.id.detail_recipe_ingredients);

    Button openInBrowserButton = (Button) rootView.findViewById(R.id.detail_recipe_source);
    openInBrowserButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(mRecipe.getSourceUrl()));
            startActivity(i);
        }
    });

    mRecipeDetailsLayout = (ScrollView) rootView.findViewById(R.id.recipe_details_layout);
    mOfflineItems = (LinearLayout) rootView.findViewById(R.id.offline_items);
    mFavoritesActionButton = (Button) rootView.findViewById(R.id.detail_recipe_favourites_action);
    int textId = mExecuteRecipeRemove ? R.string.recipe_details_remove_from_favorites
            : R.string.recipe_details_save_in_favourites;

    mFavoritesActionButton.setText(getActivity().getString(textId));
    mFavoritesActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mRecipe != null) {
                if (mExecuteRecipeRemove)
                    removeCurrentRecipeFromFavorites();
                else
                    saveCurrentRecipeInFavorites();
            }
        }
    });

    if (mRecipeExternalId != null && mLoaderAdapter != null) {
        // if there is recipe id set and the loader adapter then show the progress dialog
        // indicating the recipe load started
        mProgressDialog = UIUtil.createAndShowDefaultProgressDialog(getActivity());

        mProgressDialog.setOnKeyListener(new Dialog.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    if (mLoaderAdapter != null)
                        mLoaderAdapter.cancelLoading();
                    mProgressDialog.dismiss();

                    // if it's not the tablet layout and user cancelled the loading,
                    // then there is no point to stay in this Activity
                    if (!mTwoPane)
                        getActivity().finish();
                }
                return true;
            }
        });
    }

    return rootView;
}

From source file:csic.ceab.movelab.beepath.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Check if the key event was the Back button and if there's history
    if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
        myWebView.goBack();/*from  ww w.  ja  va  2s. c o m*/
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    _isDialogClosable = getArguments().getBoolean("closable", false);
    _isDialogFullscreen = getArguments().getBoolean("fullscreen", false);
    _isDialogCancelable = getArguments().getBoolean("cancelable", false) || _isDialogCancelable;

    if (_isDialogClosable) {
        ViewGroup view = buildInitialView(LayoutInflater.from(getActivity()));

        /*/*from  w  w  w .  j  a va  2  s  .c  om*/
         * Add this view and a close button to a wrapper view that will be used as the content view of our AlertDialog
         */

        // unable to use the holo light theme as pre honeycomb doesn't know AlertDialog.Builder(context, theme) 
        AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
        AlertDialog dialog = adb.create();

        View content = addCloseButtonToClosableDialogView(view, dialog);

        dialog.setView(content);

        dialog.setOnKeyListener(new OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
                    return onBackKeyPressed();
                }

                return false;
            }
        });

        return dialog;
    }

    if (_isDialogFullscreen) {
        setStyle(STYLE_NO_TITLE, android.R.style.Theme);
    }

    return super.onCreateDialog(savedInstanceState);
}

From source file:com.google.zxing.demo.CaptureActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        finish();/* w w  w  .  ja v a 2s .  c om*/
        return true;
    case KeyEvent.KEYCODE_FOCUS:
    case KeyEvent.KEYCODE_CAMERA:
        // Handle these events so they don't launch the Camera app
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.coincollection.ReorderCollections.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // If the screen rotated and our view got destroyed/recreated,
    // grab the list of collections from the old view (that we stored
    // in the bundle.)
    if (savedInstanceState != null) {
        mItems = savedInstanceState.getParcelableArrayList("mItems");
        mUnsavedChanges = savedInstanceState.getBoolean("mUnsavedChanges");
    }/*from  ww w . ja v a  2s  .c  o  m*/

    RecyclerView mRecyclerView = (RecyclerView) view.findViewById(R.id.reorder_collections_recycler_view);

    mRecyclerView.setBackgroundColor(Color.BLACK);

    // Indicate that the contents do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // Use a linear layout manager
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
    mRecyclerView.setLayoutManager(mLayoutManager);

    // Set up the adapter that provides the collection entries
    ReorderAdapter mAdapter = new ReorderAdapter(mItems, this);
    mRecyclerView.setAdapter(mAdapter);

    // Register the ItemTouchHelper Callback so that we can allow reordering
    // collections when the user drags the coin images or long presses and then
    // drags.
    ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(mAdapter);
    mItemTouchHelper = new ItemTouchHelper(callback);
    mItemTouchHelper.attachToRecyclerView(mRecyclerView);

    // Register a callback so we can know when the list has been reordered
    mAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) {
            super.onItemRangeMoved(fromPosition, toPosition, itemCount);

            Log.d("onItemRangeMoved", String.valueOf(fromPosition) + " " + String.valueOf(toPosition) + " "
                    + String.valueOf(itemCount));

            ReorderCollections fragment = (ReorderCollections) getFragmentManager()
                    .findFragmentByTag("ReorderFragment");

            fragment.setUnsavedChanges(true);
            fragment.showUnsavedTextView();
        }
    });

    if (mUnsavedChanges) {
        showUnsavedTextView();
    }

    //http://stackoverflow.com/questions/7992216/android-fragment-handle-back-button-press
    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                if (mUnsavedChanges) {
                    showUnsavedChangesMessage();
                } else {
                    closeFragment();
                }
                return true;
            }
            return false;
        }
    });
}

From source file:com.bjdz.brsse.ui.gallery.ActivityGallery.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        mBack.performClick();// w w w  . ja v  a2s . c  o  m
    }
    return super.onKeyDown(keyCode, event);
}

From source file:net.reichholf.dreamdroid.activities.ServiceListActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // back to standard back-button-behaviour when we're already at root
    // level/*from  w ww  . j  ava 2  s  .  c o m*/
    if (!"default".equals(mReference)) {
        int index = mHistory.size() - 1;
        if (index >= 0) {
            ExtendedHashMap map = (mHistory.get(index));

            String oldref = (String) map.get(Event.SERVICE_REFERENCE);
            String oldname = (String) map.get(Event.SERVICE_NAME);

            if ((keyCode == KeyEvent.KEYCODE_BACK) && !mReference.equals(oldref)) {
                // there is a download Task running, the list may have
                // already been altered so we let that request finish

                if (!isListTaskRunning()) {
                    mReference = String.valueOf(oldref);
                    mName = String.valueOf(oldname);

                    mHistory.remove(index);

                    if (isBouquetReference(mReference)) {
                        mIsBouquetList = true;
                    }
                    reload();

                } else {
                    showToast(getText(R.string.wait_request_finished));
                }
                return true;
            }
        }
    }
    return super.onKeyDown(keyCode, event);
}

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

@Override
public boolean onKey(DialogInterface d, int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_BACK:
        getActivity().findViewById(R.id.bottom_bar).setVisibility(View.GONE);
        ((ScriptActivity) getActivity()).updateHandleAddButtonClickListener();

        FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
        fragmentTransaction.hide(this);
        FormulaEditorFragment formulaEditorFragment = (FormulaEditorFragment) getActivity()
                .getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);
        formulaEditorFragment.updateBrickView();
        fragmentTransaction.show(formulaEditorFragment);
        fragmentTransaction.commit();//from  www .ja  va 2 s .c om
        return true;
    default:
        break;
    }
    return false;
}

From source file:com.codestation.henkakuserver.MainActivity.java

public boolean onKeyDown(int keyCode, KeyEvent evt) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isStarted) {
            new AlertDialog.Builder(this).setTitle(R.string.warning).setMessage(R.string.dialog_exit_message)
                    .setPositiveButton(getResources().getString(android.R.string.ok),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int id) {
                                    finish();
                                }/*  w  ww  . j a  va2  s  . com*/
                            })
                    .setNegativeButton(getResources().getString(android.R.string.cancel), null).show();
        } else {
            finish();
        }
        return true;
    }
    return false;
}