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:io.github.hidroh.materialistic.WebFragment.java

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    if (mIsHackerNewsUrl) {
        return createLocalView(container, savedInstanceState);
    }//ww w . j  a va 2  s  .c o  m

    final View view = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_web, container, false);
    mScrollView = (NestedScrollView) view.findViewById(R.id.nested_scroll_view);
    final ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.progress);
    mWebView = (WebView) view.findViewById(R.id.web_view);
    mWebView.setBackgroundColor(Color.TRANSPARENT);
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            progressBar.setVisibility(View.VISIBLE);
            progressBar.setProgress(newProgress);
            if (newProgress == 100) {
                progressBar.setVisibility(View.GONE);
                mWebView.setBackgroundColor(Color.WHITE);
                mWebView.setVisibility(mExternalRequired ? View.GONE : View.VISIBLE);
            }
        }
    });
    mWebView.setDownloadListener(new DownloadListener() {
        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            if (getActivity() == null) {
                return;
            }
            final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            if (intent.resolveActivity(getActivity().getPackageManager()) == null) {
                return;
            }
            mExternalRequired = true;
            mWebView.setVisibility(View.GONE);
            view.findViewById(R.id.empty).setVisibility(View.VISIBLE);
            view.findViewById(R.id.download_button).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivity(intent);
                }
            });
        }
    });
    mWebView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK) {
                if (mWebView.canGoBack()) {
                    mWebView.goBack();
                    return true;
                }
            }
            return false;
        }
    });
    setWebViewSettings(mWebView.getSettings());
    return view;
}

From source file:com.google.android.marvin.mytalkback.ProcessorVolumeStream.java

@Override
public boolean onKeyEvent(KeyEvent event) {
    boolean handled = false;
    switch (event.getAction()) {
    case KeyEvent.ACTION_DOWN:
        handled = handleKeyDown(event.getKeyCode());
        break;//from   w w w.j  a  v  a 2s  .c  om
    case KeyEvent.ACTION_UP:
        handled = handleKeyUp(event.getKeyCode());
        break;
    }

    if (handled) {
        // Quickly acquire and release the wake lock so that
        // PowerManager.ON_AFTER_RELEASE takes effect.
        mWakeLock.acquire();
        mWakeLock.release();
    }

    return handled;
}

From source file:com.glanznig.beepme.view.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_UP) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }/*from w w w. j  a  v  a2s.  c om*/
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:mobisocial.bento.todo.ui.TodoDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // extract UUID from intent
    mTodoUuid = getActivity().getIntent().getStringExtra(EXTRA_TODO_UUID);

    // View/*from  ww w .ja v  a2 s.  c o m*/
    mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_todo_detail, container);

    mTitle = (EditText) mRootView.findViewById(R.id.todo_title);
    mDescription = (EditText) mRootView.findViewById(R.id.todo_description);
    mDescription.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE
                    || event.getAction() == KeyEvent.ACTION_DOWN
                            && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                Log.d(TAG, "onEditorAction");
                // clear focus
                v.clearFocus();

                // close keyboard
                InputMethodManager mgr = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                mgr.hideSoftInputFromWindow(mDescription.getWindowToken(), 0);

                return true;
            }
            return false;
        }
    });
    mImageView = (ImageView) mRootView.findViewById(R.id.todo_image);

    // retrieve Todo data
    if (mTodoUuid != null) {
        mTodoItem = mManager.getTodoListItem(mTodoUuid);
        if (mTodoItem != null) {
            mTitle.setText(mTodoItem.title);
            mDescription.setText(mTodoItem.description);
            if (mTodoItem.hasImage) {
                mImageView.setImageBitmap(mManager.getTodoBitmap(mTodoItem.uuid, IMG_WIDTH, IMG_HEIGHT, 0));
                mImageView.setVisibility(View.VISIBLE);
            } else {
                mImageView.setVisibility(View.GONE);
            }
        }
    }

    return mRootView;
}

From source file:com.luo.luofist.base.BaseAppCompatActivity.java

/**
 * Loadding/*from  ww w.j  a  v  a2s .  c  om*/
 */
public void showLoadingDialog() {
    try {
        mLoadingDialog = LoadingDialog.createDialog(this);
        mLoadingDialog.setTitle(null);
        mLoadingDialog.setCancelable(false);
        mLoadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
                    hideLoadingDialog();
                }
                return true;
            }
        });
        if (!isFinishing()) {
            mLoadingDialog.show();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:cn.eoe.android.libraries.ui.activity.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        if (isExit) {
            System.exit(0);/* w  w w.j a va2s.  com*/
        }
        Toast.makeText(this, "??", Toast.LENGTH_SHORT).show();
        countDownTimer.start();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.aevi.simpleexample.SecureCommunicationsActivity.java

private void setupSearchTextEnterListener() {
    EditText searchText = (EditText) findViewById(R.id.searchText);
    searchText.setImeActionLabel("Search", KeyEvent.KEYCODE_ENTER);

    searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override/* ww  w  . j av  a 2s  .c om*/
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER
                    && keyEvent.getAction() == keyEvent.ACTION_DOWN) {
                searchProjectsClick(textView);
                return true;
            }
            return false;
        }
    });
}

From source file:com.example.messaging.MessageActivity.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
        firebase.child(CHS + "/" + currentChannel + "/history").push()
                .setValue(new Message(messageText.getText().toString(), firebaseUser.getDisplayName()));

        return true;
    }//w w w . j av  a  2  s  . c  om
    return false;
}

From source file:com.irccloud.android.activity.QuickReplyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_quick_reply);

    if (getIntent().hasExtra("cid") && getIntent().hasExtra("bid")) {
        onNewIntent(getIntent());/*from  w w w  . ja  v a2 s.c om*/
    } else {
        finish();
        return;
    }

    final ImageButton send = (ImageButton) findViewById(R.id.sendBtn);
    final EditText message = (EditText) findViewById(R.id.messageTxt);
    message.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if (actionId == EditorInfo.IME_ACTION_SEND && message.getText() != null
                    && message.getText().length() > 0)
                send.performClick();
            return true;
        }
    });
    message.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER
                    && message.getText() != null && message.getText().length() > 0)
                send.performClick();
            return false;
        }
    });
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (message.getText() != null && message.getText().length() > 0) {
                Intent i = new Intent(RemoteInputService.ACTION_REPLY);
                i.setComponent(new ComponentName(getPackageName(), RemoteInputService.class.getName()));
                i.putExtras(getIntent());
                i.putExtra("reply", message.getText().toString());
                startService(i);
                finish();
            }
        }
    });

    ListView listView = (ListView) findViewById(R.id.conversation);
    listView.setAdapter(adapter);
}

From source file:com.fusionx.lightirc.ui.IRCFragment.java

@Override
public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
    final CharSequence text = mMessageBox.getText();
    if ((event == null || actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE
            || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
            && StringUtils.isNotEmpty(text)) {
        final String message = text.toString();
        mMessageBox.setText("");
        onSendMessage(message);//from   w  w  w  .j  a v a 2s  .  co m
        return true;
    }
    return false;
}