Example usage for android.view KeyEvent getAction

List of usage examples for android.view KeyEvent getAction

Introduction

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

Prototype

public final int getAction() 

Source Link

Document

Retrieve the action of this key event.

Usage

From source file:it.mb.whatshare.PatchedDialogFragment.java

/**
 * Returns a builder that will create a dialog that can only be canceled by
 * clicking OK or by pressing back./*from   w w  w. ja  v a  2 s .co  m*/
 * 
 * <p>
 * Whenever the dialog is dismissed, {@link Activity#finish()} is called on
 * the argument <tt>activity</tt>.
 * 
 * <p>
 * The builder has already the correct theme set (for making it look ok even
 * on wonderful Android pre-v11), so {@link Builder#getContext()} can be
 * used to inflate layouts with.
 * 
 * @param activity
 *            the caller activity
 * @return a builder to be used to create a dialog with
 */
protected Builder getNoUiBuilder(final FragmentActivity activity) {
    context = new ContextThemeWrapper(activity, R.style.DialogTheme);
    // @formatter:off
    return new AlertDialog.Builder(context).setCancelable(false)
            .setOnKeyListener(new DialogInterface.OnKeyListener() {
                @Override
                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP
                            && !event.isCanceled()) {
                        dialog.cancel();
                        activity.finish();
                        return true;
                    }
                    return false;
                }
            }).setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    activity.finish();
                }
            });
    // @formatter:on
}

From source file:andlabs.lounge.lobby.ui.ChatFragment.java

@Override
public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) {
    final View chat = infl.inflate(R.layout.fragment_chat, p, false);
    mChatEditText = ((EditText) chat.findViewById(R.id.msg_field));
    ((ImageButton) chat.findViewById(R.id.btn_send)).setOnClickListener(this);
    ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() {

        @Override/*  w w w .j av  a  2  s  .c  om*/
        public int getCount() {
            return mConversation.size();
        }

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            if (view == null)
                view = infl.inflate(R.layout.chat_list_entry, null);
            final ChatMessage msg = mConversation.get(position);
            ((TextView) view.findViewById(R.id.sender)).setText(msg.getPlayerName());
            ((TextView) view.findViewById(R.id.msg_text)).setText(msg.getMessage());
            return view;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }
    });
    // http://code.google.com/p/android/issues/detail?id=2516
    mChatEditText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                onClick(null);
                return true;
            }
            return false;
        }
    });
    return chat;
}

From source file:com.judepereira.android.co.uncyclopedia.UncyclopediaActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/* www .j  a  va  2  s . c o  m*/
    searchText = (EditText) findViewById(R.id.search_edittext);
    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView tv, int i, KeyEvent ke) {
            if ((ke != null) && ke.getAction() == KeyEvent.ACTION_DOWN) {
                search(null);
            }
            if (ke == null) {
                search(null);
            }
            return true;
        }
    });
    wikiView = (WebView) findViewById(R.id.webview);
    client = new UncyclopediaWebViewClient(this, wikiView);
    wikiView.setWebViewClient(client);
    if (savedInstanceState == null) {
        history = new Stack<ArticleHistory>();
        client.setHistory(history);
        client.setUniqueId(Math.random());
        client.setFeatured(true);
        wikiView.loadUrl(c.RANDOM_FEATURED_URL);
    }
}

From source file:com.kogitune.activity_transition.fragment.ExitFragmentTransition.java

public void startExitListening(final Runnable popBackStackRunnable) {
    if (interpolator == null) {
        interpolator = new DecelerateInterpolator();
    }/*from w  w w .  j  av  a2  s. c o  m*/
    final View toView = moveData.toView;
    toView.setFocusableInTouchMode(true);
    toView.requestFocus();
    toView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                if (event.getAction() != KeyEvent.ACTION_UP) {
                    return true;
                }
                TransitionAnimation.startExitAnimation(moveData, interpolator, new Runnable() {
                    @Override
                    public void run() {
                        if (popBackStackRunnable != null) {
                            popBackStackRunnable.run();
                            return;
                        }
                        if (fragment == null) {
                            if (!supportFragment.isResumed()) {
                                return;
                            }
                            final FragmentManager fragmentManager = supportFragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        } else {
                            if (!fragment.isResumed()) {
                                return;
                            }
                            final android.app.FragmentManager fragmentManager = fragment.getFragmentManager();
                            if (fragmentManager != null) {
                                fragmentManager.popBackStack();
                            }
                        }
                    }
                }, listener);
                return true;
            }
            return false;
        }
    });
}

From source file:eu.andlabs.studiolounge.chat.ChatFragment.java

@Override
public View onCreateView(final LayoutInflater infl, ViewGroup p, Bundle b) {
    final View chat = infl.inflate(R.layout.chat, p, false);
    mChatEditText = ((EditText) chat.findViewById(R.id.msg_field));
    ((ImageButton) chat.findViewById(R.id.btn_msgSend)).setOnClickListener(this);
    ((ListView) chat.findViewById(R.id.list)).setAdapter(new BaseAdapter() {
        @Override/*from  w w w  .  j a  v a2  s.  c o  m*/
        public int getCount() {
            return mConversation.size();
        }

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            if (view == null)
                view = infl.inflate(R.layout.chat_list_entry, null);
            final ChatMessage msg = mConversation.get(position);
            final Player player = new Player(msg.player);
            ((TextView) view.findViewById(R.id.sender)).setText(player.getShortPlayername());
            ((TextView) view.findViewById(R.id.msg_text)).setText(msg.text);
            return view;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }
    });
    // http://code.google.com/p/android/issues/detail?id=2516
    mChatEditText.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
                onClick(null);
                return true;
            }
            return false;
        }
    });
    return chat;
}

From source file:com.flipzu.flipzu.SearchFragment.java

@Override
public void onResume() {
    super.onResume();

    debug.logV(TAG, "onResume()");

    final EditText search_et = (EditText) getActivity().findViewById(R.id.search);
    search_et.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                mSearch = search_et.getText().toString().trim();
                debug.logV(TAG, "onKey, got " + mSearch);
                EventNotifier.getInstance().signalNewSearch(mSearch);
                return true;
            }/*from  w  w  w.  ja  va 2 s  .  c o m*/
            return false;
        }
    });

    search_et.setText("");
    //      mSearch = search_et.getText().toString();
    //      
    //      if ( mSearch != null ) {
    //         debug.logV(TAG, "searching for " + mSearch);
    //         EventNotifier.getInstance().signalNewSearch(mSearch);         
    //      }
}

From source file:illab.nabal.proxy.AuthWebDialog.java

/**
 * Override hardware back key to close this dialog.
 * /*  w  w  w  .j a  v  a2  s  .  co m*/
 * @deprecated
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        //Log.d(TAG, "keyCode : " + keyCode + " | event.getAction() : " + event.getAction());
        Log.d(TAG, "BACK key has been pressed on WebView");
        mNetworkWebViewClient.onCancel();
    }
    return true;
}

From source file:com.mooshim.mooshimeter.main.PreferencesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final PreferencesActivity mThis = this;
    Intent intent = getIntent();//  www. j av a 2 s . c  o  m
    mMeter = ScanActivity.getDeviceWithAddress(intent.getStringExtra("addr"));
    setContentView(R.layout.activity_meter_preference);
    final EditText name_editor = (EditText) findViewById(R.id.meter_rename_edit);
    rateButtons[0] = (Button) findViewById(R.id.rate_button0);
    rateButtons[1] = (Button) findViewById(R.id.rate_button1);
    rateButtons[2] = (Button) findViewById(R.id.rate_button2);
    rateButtons[3] = (Button) findViewById(R.id.rate_button3);

    if (mMeter.meter_name.name != null) {
        name_editor.setText(mMeter.meter_name.name);
    } else {
        name_editor.setText("Mooshimeter V.1");
    }
    name_editor.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                mMeter.meter_name.name = String.valueOf(name_editor.getText());
                mMeter.meter_name.send();
                Log.d(null, "Name sent");
                Toast.makeText(mThis, "Name Sent", Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });
    rateButtonRefresh();
}

From source file:org.catrobat.catroid.ui.dialogs.OverwriteRenameDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_overwrite_project, null);

    replaceButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_project_radio_replace);
    replaceButton.setOnClickListener(this);
    renameButton = (RadioButton) dialogView.findViewById(R.id.dialog_overwrite_project_radio_rename);
    renameButton.setOnClickListener(this);
    projectText = (EditText) dialogView.findViewById(R.id.dialog_overwrite_project_edit);
    projectText.setText(programName);/*w  w w.ja  v  a  2s.c  o  m*/
    projectTextView = (TextView) dialogView.findViewById(R.id.dialog_overwrite_project_edit_text);
    projectTextLine = dialogView.findViewById(R.id.dialog_overwrite_project_edit_line);

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(R.string.overwrite_text)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ToastUtil.showError(context, R.string.notification_download_project_cancel);
                }
            }).create();

    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    handleOkButton();
                }
            });
        }
    });

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            } else if (keyCode == KeyEvent.KEYCODE_BACK) {
                ToastUtil.showError(context, R.string.notification_download_project_cancel);
                return true;
            }

            return false;
        }
    });

    return dialog;
}

From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java

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

    if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {

        showDialog(this);
        return true;

    } else {//  ww w . ja  v a 2 s .co m
        return false;
    }
}