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:de.uni.stuttgart.informatik.ToureNPlaner.UI.Dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    input = new EditText(getActivity());
    String message = getArguments().getString("title");
    CharSequence content;//from w  w  w. j a  v a2 s .  c om
    if (savedInstanceState == null) {
        content = getArguments().getCharSequence("content");
    } else {
        content = savedInstanceState.getCharSequence("content");
    }
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
    input.setText(content, TextView.BufferType.SPANNABLE);
    return new AlertDialog.Builder(getActivity()).setTitle(message).setView(input)
            .setPositiveButton(getResources().getText(android.R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doPositiveClick();
                        }
                    })
            .setNegativeButton(getResources().getText(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int whichButton) {
                            doNegativeClick();
                        }
                    })
            .setOnKeyListener(new DialogInterface.OnKeyListener() {

                @Override
                public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
                    if ((keyEvent.getAction() == KeyEvent.ACTION_DOWN) && (i == KeyEvent.KEYCODE_ENTER)) {
                        dialogInterface.dismiss();
                        doPositiveClick();
                        return true;
                    }
                    return false;
                }
            }).create();
}

From source file:org.linesofcode.alltrack.graph.CreateGraphActivity.java

private void initializeContent() {
    Button okButton = (Button) findViewById(R.id.graph_detail_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   w  w w .java 2 s . co  m
        public void onClick(View v) {
            createGraph();
        }
    });

    Button cancelButton = (Button) findViewById(R.id.graph_detail_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED, new Intent(CREATE_GRAPH_ACTION_CODE));
            finish();
        }
    });

    EditText graphName = (EditText) findViewById(R.id.edit_graph_name);
    graphName.setOnKeyListener(new View.OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    createGraph();
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:de.enlightened.peris.WebViewer.java

@Override
public boolean onKeyDown(final int keyCode, final KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (this.wvMain.canGoBack()) {
                this.wvMain.goBack();
            } else {
                this.finish();
            }/*from   w ww .j a v  a 2  s  .  c  o  m*/
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.wordpress.jftreading.BaseFragmentWebView.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    fragmentView = inflater.inflate(R.layout.webview_fragment, container, false);
    browser = (WebView) fragmentView.findViewById(R.id.webkit);
    browser.getSettings().setJavaScriptEnabled(true);
    browser.setWebViewClient(new WebViewClient() {
        @Override//from  w w  w. ja v  a 2s  .c  o m
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!networkIsUp() && !offlinePage) {
                view.loadUrl(getErrorPage());
                return true;
            }
            if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            startActivity(intent);
            return true;
        }
    });
    browser.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
            return super.onJsConfirm(view, url, message, result);
        }
    });
    browser.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                WebView webView = (WebView) v;

                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });
    browser.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });
    browser.addJavascriptInterface(new MyJavascriptInterface(), "Android");
    browser.loadUrl(linkSelector());
    return fragmentView;
}

From source file:com.towerlabs.yildizyemek.AboutWeb.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub

    if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
        if (webView.canGoBack()) {
            webView.goBack();/*from  w  w w .  j a va  2 s .  c o m*/
        } else {
            // getActivity().finish();

            MainActivity.exitDialog();
        }

    }

    return true;
}

From source file:com.saulcintero.moveon.services.MediaButtonEventReceiver.java

@Override
public void onReceive(Context mContext, Intent intent) {
    String intentAction = intent.getAction();
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intentAction)) {
    } else if (Intent.ACTION_MEDIA_BUTTON.equals(intentAction)) {
        KeyEvent event = (KeyEvent) intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);

        if (event == null)
            return;

        if (event.getAction() == KeyEvent.ACTION_UP) {
            Intent i = new Intent("android.intent.action.ACTION_SAY_PRACTICE_INFORMATION");
            i.putExtra("type", String.valueOf(NotificationTypes.TIME.getTypes()));
            mContext.sendBroadcast(i);// www  . j  a  v  a 2 s . c  om
        }
    }
}

From source file:com.ruesga.rview.EditorActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
        if (fragment != null && fragment instanceof KeyEventBindable) {
            if (((KeyEventBindable) fragment).onKeyDown(event.getKeyCode(), event)) {
                return true;
            }//from  ww  w . j  a  va2  s  . c o m
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.cybrosys.basic.EventListener.java

@Override
public boolean onKey(View vwView, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }//from w  w w  .j ava  2  s . c o  m
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true;
    }
    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }
    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        return false;
    }
    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:com.oda.calculator.EventListener.java

public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    int action = keyEvent.getAction();

    if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        boolean eat = mHandler.eatHorizontalMove(keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
        return eat;
    }/*  ww  w  . j a v a  2  s  . c om*/

    //Work-around for spurious key event from IME, bug #1639445
    if (action == KeyEvent.ACTION_MULTIPLE && keyCode == KeyEvent.KEYCODE_UNKNOWN) {
        return true; // eat it
    }

    //Calculator.log("KEY " + keyCode + "; " + action);

    if (keyEvent.getUnicodeChar() == '=') {
        if (action == KeyEvent.ACTION_UP) {
            mHandler.onEnter();
        }
        return true;
    }

    if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER && keyCode != KeyEvent.KEYCODE_DPAD_UP
            && keyCode != KeyEvent.KEYCODE_DPAD_DOWN && keyCode != KeyEvent.KEYCODE_ENTER) {
        if (keyEvent.isPrintingKey() && action == KeyEvent.ACTION_UP) {
            // Tell the handler that text was updated.
            mHandler.onTextChanged();
        }
        return false;
    }

    /*
       We should act on KeyEvent.ACTION_DOWN, but strangely
       sometimes the DOWN event isn't received, only the UP.
       So the workaround is to act on UP...
       http://b/issue?id=1022478
     */

    if (action == KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        case KeyEvent.KEYCODE_DPAD_CENTER:
            mHandler.onEnter();
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            mHandler.onUp();
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            mHandler.onDown();
            break;
        }
    }
    return true;
}

From source file:org.totschnig.myexpenses.dialog.EditTextDialog.java

@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (EditorInfo.IME_ACTION_DONE == actionId
            || (actionId == EditorInfo.IME_NULL && event.getAction() == KeyEvent.ACTION_DOWN)) {
        // Return input text to activity
        EditTextDialogListener activity = (EditTextDialogListener) getActivity();
        Bundle args = getArguments();//w w w .  ja va 2  s .  com
        String result = mEditText.getText().toString();
        if (result.equals(""))
            Toast.makeText(getActivity(), getString(R.string.no_title_given), Toast.LENGTH_LONG).show();
        else {
            args.putString("result", result);
            activity.onFinishEditDialog(args);
            this.dismiss();
            return true;
        }
    }
    return false;
}