Example usage for android.view KeyEvent ACTION_DOWN

List of usage examples for android.view KeyEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

To view the source code for android.view KeyEvent ACTION_DOWN.

Click Source Link

Document

#getAction value: the key has been pressed down.

Usage

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 . j  a  v  a2 s .c  om
            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:com.achep.acdisplay.services.media.MediaController2.java

/**
 * Emulates hardware buttons' click via broadcast system.
 *
 * @see android.view.KeyEvent//from w  ww . j av  a2 s  .c  o m
 */
public static void broadcastMediaAction(@NonNull Context context, int action) {
    int keyCode;
    switch (action) {
    case ACTION_PLAY_PAUSE:
        keyCode = KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE;
        break;
    case ACTION_STOP:
        keyCode = KeyEvent.KEYCODE_MEDIA_STOP;
        break;
    case ACTION_SKIP_TO_NEXT:
        keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
        break;
    case ACTION_SKIP_TO_PREVIOUS:
        keyCode = KeyEvent.KEYCODE_MEDIA_PREVIOUS;
        break;
    default:
        throw new IllegalArgumentException();
    }

    Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
    KeyEvent keyDown = new KeyEvent(KeyEvent.ACTION_DOWN, keyCode);
    KeyEvent keyUp = new KeyEvent(KeyEvent.ACTION_UP, keyCode);

    context.sendOrderedBroadcast(intent.putExtra(Intent.EXTRA_KEY_EVENT, keyDown), null);
    context.sendOrderedBroadcast(intent.putExtra(Intent.EXTRA_KEY_EVENT, keyUp), null);
}

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();/*from  ww w. j  av  a 2 s  .  c  o m*/
        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;
}

From source file:net.thetabx.gcd.activity.ChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    header = (TextView) findViewById(R.id.txt_chat_header);
    listView = (ListView) findViewById(R.id.lview_chat);
    swipe = (SwipeRefreshLayout) findViewById(R.id.swipe_chat);
    swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override/*from   ww w  .  j ava 2s  .co m*/
        public void onRefresh() {
            fetchFreshData();
        }
    });
    edit = (EditText) findViewById(R.id.etxt_chat_send);
    edit.setOnEditorActionListener(new TextView.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) {
                header.setText(String.format("Sent %s", v.getText()));
                sendChatMessage(v);
                //v.setText("");
                fetchFreshData();
            }
            return false;
        }
    });

    header.setText("Start");
    if (messages == null) {
        fetchFreshData();
    } else
        fillActivity();
}

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 .  jav a 2 s. com*/
        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: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  va  2 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.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 ww  w  .  j  ava2  s  .  co  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.bellman.bible.android.view.activity.search.Search.java

/**
 * Called when the activity is first created.
 */// w  w  w . j  a v a  2s .  co  m
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState, true);
    Log.i(TAG, "Displaying Search view");
    setContentView(R.layout.search);

    if (!searchControl.validateIndex(getDocumentToSearch())) {
        Dialogs.getInstance().showErrorMsg(R.string.error_occurred, new Callback() {
            @Override
            public void okay() {
                finish();
            }
        });
    }

    mSearchTextInput = (EditText) findViewById(R.id.searchText);
    mSearchTextInput.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
                onSearch(null);
                return true;
            }
            return false;
        }
    });

    // pre-load search string if passed in
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String searchText = extras.getString(SEARCH_TEXT_SAVE);
        if (StringUtils.isNotEmpty(searchText)) {
            mSearchTextInput.setText(searchText);
        }
    }

    RadioGroup wordsRadioGroup = (RadioGroup) findViewById(R.id.wordsGroup);
    wordsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            wordsRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int wordsSelection = extras.getInt(WORDS_SELECTION_SAVE, -1);
        if (wordsSelection != -1) {
            wordsRadioGroup.check(wordsSelection);
        }
    }

    RadioGroup sectionRadioGroup = (RadioGroup) findViewById(R.id.bibleSectionGroup);
    sectionRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            sectionRadioSelection = checkedId;
        }
    });
    if (extras != null) {
        int sectionSelection = extras.getInt(SECTION_SELECTION_SAVE, -1);
        if (sectionSelection != -1) {
            sectionRadioGroup.check(sectionSelection);
        }
    }

    // set text for current bible book on appropriate radio button
    RadioButton currentBookRadioButton = (RadioButton) findViewById(R.id.searchCurrentBook);

    // set current book to default and allow override if saved - implies returning via Back button
    currentBookName = searchControl.getCurrentBookName();
    if (extras != null) {
        String currentBibleBookSaved = extras.getString(CURRENT_BIBLE_BOOK_SAVE);
        if (currentBibleBookSaved != null) {
            currentBookName = currentBibleBookSaved;
        }
    }
    currentBookRadioButton.setText(currentBookName);

    Log.d(TAG, "Finished displaying Search view");
}

From source file:com.digium.respoke.ChatActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chat);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    Button buttonSend = (Button) findViewById(R.id.buttonSend);

    EditText chatText = (EditText) findViewById(R.id.chatText);
    chatText = (EditText) findViewById(R.id.chatText);
    chatText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                sendChatMessage();/*w  w w  .  j  av  a2 s  .  c om*/
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String remoteEndpointID = null;
    boolean shouldStartDirectConnection = false;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        remoteEndpointID = savedInstanceState.getString(ENDPOINT_ID_KEY);
        shouldStartDirectConnection = savedInstanceState.getBoolean(DIRECT_CONNECTION_KEY, false);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            remoteEndpointID = extras.getString(ENDPOINT_ID_KEY);
            shouldStartDirectConnection = extras.getBoolean(DIRECT_CONNECTION_KEY, false);
        } else {
            // The activity must have been destroyed while it was hidden to save memory. Use the most recent persistent data.
            SharedPreferences prefs = getSharedPreferences(ConnectActivity.RESPOKE_SETTINGS, 0);
            remoteEndpointID = prefs.getString(ENDPOINT_ID_KEY, "");
            shouldStartDirectConnection = prefs.getBoolean(DIRECT_CONNECTION_KEY, false);
        }
    }

    conversation = ContactManager.sharedInstance().conversations.get(remoteEndpointID);
    remoteEndpoint = ContactManager.sharedInstance().sharedClient.getEndpoint(remoteEndpointID, true);
    setTitle(remoteEndpoint.getEndpointID());

    listAdapter = new ListDataAdapter();

    ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout
    lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView

    if (shouldStartDirectConnection && (null == remoteEndpoint.directConnection())) {
        // If the direct connection has not been started yet, start it now
        remoteEndpoint.startDirectConnection();
    }

    directConnection = remoteEndpoint.directConnection();
    if (null != directConnection) {
        directConnection.setListener(this);
        RespokeCall call = directConnection.getCall();
        boolean caller = false;

        if (null != call) {
            call.setListener(this);
            caller = call.isCaller();
        }

        View answerView = findViewById(R.id.answer_view);
        View connectingView = findViewById(R.id.connecting_view);
        TextView callerNameView = (TextView) findViewById(R.id.caller_name_text);

        if (caller) {
            answerView.setVisibility(View.INVISIBLE);
            connectingView.setVisibility(View.VISIBLE);
        } else {
            answerView.setVisibility(View.VISIBLE);
            connectingView.setVisibility(View.INVISIBLE);
        }

        if (null != remoteEndpoint) {
            callerNameView.setText(remoteEndpoint.getEndpointID());
        } else {
            callerNameView.setText("Unknown Caller");
        }

        ActionBar actionBar = getActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(R.color.incoming_connection_bg));
        actionBar.setDisplayShowTitleEnabled(false);
        actionBar.setDisplayShowTitleEnabled(true);
    }
}

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();
            }//ww  w .j  a  v  a  2  s. c om
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}