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:com.digium.respoke.GroupChatActivity.java

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

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

    EditText 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();//  ww w.  j  av  a2 s . c o m
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String groupID = null;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        groupID = savedInstanceState.getString(GROUP_ID_KEY);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            groupID = extras.getString(GROUP_ID_KEY);
        } 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);
            groupID = prefs.getString(GROUP_ID_KEY, "");
        }
    }

    this.setTitle(groupID);

    for (RespokeGroup eachGroup : ContactManager.sharedInstance().groups) {
        if (eachGroup.getGroupID().equals(groupID)) {
            group = eachGroup;
            break;
        }
    }

    conversation = ContactManager.sharedInstance().groupConversations.get(groupID);

    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
}

From source file:org.alfresco.mobile.android.application.fragments.node.comment.CommentsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRetainInstance(false);/* w ww .ja  va 2  s. c o m*/
    setRootView(inflater.inflate(R.layout.app_comments, container, false));

    init(getRootView(), R.string.empty_comment);

    commentText = (EditText) viewById(R.id.comment_value);
    bAdd = (ImageButton) viewById(R.id.send_comment);
    bAdd.setEnabled(false);

    bAdd.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            addcomment();
        }
    });

    commentText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            activateSend();
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    commentText.setImeOptions(EditorInfo.IME_ACTION_SEND);
    commentText.setOnEditorActionListener(new OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && (event.getAction() == KeyEvent.ACTION_DOWN)
                    && ((actionId == EditorInfo.IME_ACTION_SEND))) {
                addcomment();
                return true;
            }
            return false;
        }
    });

    gv.setSelector(android.R.color.transparent);
    gv.setCacheColorHint(getResources().getColor(android.R.color.transparent));

    return getRootView();
}

From source file:at.alladin.rmbt.android.map.RMBTMapFilterFragment.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
        if (currentOptionList != null && !isRoot) {
            populateList(options.getRootOptions(), true);
            return true;
        }//w w w.  ja v  a 2  s.co  m
    }
    return false;
}

From source file:com.battlelancer.seriesguide.ui.FixGetGlueCheckInActivity.java

private void setupViews() {
    mHeaderView = getLayoutInflater().inflate(R.layout.getglue_header, null);
    mSelectedValue = (TextView) mHeaderView.findViewById(R.id.textViewSelectedShowValue);

    mFooterView = getLayoutInflater().inflate(R.layout.getglue_footer, null);
    mSearchBox = (EditText) mFooterView.findViewById(R.id.editTextGetGlueSearch);
    mSearchBox.setOnKeyListener(new OnKeyListener() {
        @Override/*  ww  w.  j  av a 2 s.co m*/
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // we only want to react to down events
            if (event.getAction() != KeyEvent.ACTION_DOWN) {
                return false;
            }

            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                onSearch(mSearchBox.getText().toString());
                return true;
            } else {
                return false;
            }
        }
    });
    mFooterView.findViewById(R.id.buttonShowSearch).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            v.setVisibility(View.GONE);
            mSearchBox.setVisibility(View.VISIBLE);
            mSearchBox.requestFocus();
        }
    });

    findViewById(R.id.buttonDiscard).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    final Context context = this;
    mSaveButton = findViewById(R.id.buttonSaveSelection);
    mSaveButton.setEnabled(false);
    mSaveButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // save new GetGlue object id
            CharSequence text = mSelectedValue.getText();
            ShowTools.get(context).storeGetGlueId(Integer.valueOf(mShowId),
                    text != null ? text.toString() : "");
            finish();
        }
    });
}

From source file:com.jungle.apps.photos.module.homepage.HomepageActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        long time = System.currentTimeMillis();
        if (time - mLastBackKeyUpTime <= 800) {
            exitApp();//from  ww  w . j  a  va 2s .c o m
        } else {
            mLastBackKeyUpTime = time;
            JungleToast.makeText(this, R.string.back_press_exit_tips).show();
        }

        return true;
    }

    return super.onKeyDown(keyCode, event);
}

From source file:de.qspool.clementineremote.ui.Player.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        // Control the volume of clementine if enabled in the options
        switch (keyCode) {
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            if (mSharedPref.getBoolean(App.SP_KEY_USE_VOLUMEKEYS, true)) {
                Message msgDown = Message.obtain();
                msgDown.obj = new RequestVolume(App.mClementine.getVolume() - 10);
                App.mClementineConnection.mHandler.sendMessage(msgDown);
                return true;
            }/* www.  ja  va2s  .c  om*/
            break;
        case KeyEvent.KEYCODE_VOLUME_UP:
            if (mSharedPref.getBoolean(App.SP_KEY_USE_VOLUMEKEYS, true)) {
                Message msgUp = Message.obtain();
                msgUp.obj = new RequestVolume(App.mClementine.getVolume() + 10);
                App.mClementineConnection.mHandler.sendMessage(msgUp);
                return true;
            }
            break;
        default:
            break;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.shenma.yueba.yangjia.activity.MainActivityForYangJia.java

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        if ((System.currentTimeMillis() - exitTime) > 2000) {
            exitTime = System.currentTimeMillis();
            Toast.makeText(getApplicationContext(), "??", Toast.LENGTH_SHORT).show();
        } else {/*from www  .  j a  v  a2  s  .  c  o m*/
            MyApplication.getInstance().exit();
        }
        return true; // true???
    }
    return super.onKeyDown(keyCode, event);
}

From source file:it.rignanese.leo.slimtwitter.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            if (webViewTwitter.canGoBack()) {
                webViewTwitter.goBack();
            } else {
                // exit
                finish();/* w  ww.java  2s. c  o m*/
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.whisperim.android.ui.ChatWindow.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER)
            && (event.getAction() == KeyEvent.ACTION_DOWN)) {
        Log.i("WhisperIM", "KeyCodeIntercepted: " + keyCode);

        if (messageBox_.getText().toString().equalsIgnoreCase("")) {
            return true;
        }//from   w w w .  java  2 s.  c  o m

        sendMessage();
        return true;
    }
    return false;
}

From source file:com.activiti.android.app.fragments.HelpDialogFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.app_webview, container, false);

    getToolbar().setVisibility(View.GONE);

    webView = (WebView) v.findViewById(R.id.webview);
    webView.getSettings().setJavaScriptEnabled(true);
    emptyView = v.findViewById(R.id.empty);
    emptyTextView = (TextView) v.findViewById(R.id.empty_text);
    emptyTextView.setText(Html.fromHtml(getString(R.string.error_offline)));

    final Activity activity = getActivity();

    defaultUrl = activity.getString(R.string.help_user_guide_default_url);

    webView.setWebViewClient(new WebViewClient() {
        boolean hasError = false;

        @Override//from  w  w  w  .  ja v  a2  s  .  c om
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            hasError = false;
            getActivity().setProgressBarIndeterminateVisibility(true);
            refreshIcon.setVisible(false);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);

            // We redirect to default EN documentation if locale docs are
            // not available.
            if ((errorCode == ERROR_FILE_NOT_FOUND || errorCode == ERROR_HOST_LOOKUP) && !isDefault
                    && failingUrl.equals(rootUrl)) {
                hasError = true;
                view.loadUrl(defaultUrl);
                view.setVisibility(View.GONE);
            } else if (!ConnectivityUtils.hasInternetAvailable(getActivity())) {
                view.setVisibility(View.GONE);
                emptyView.setVisibility(View.VISIBLE);
                hasError = true;
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if (hasError) {
                view.setVisibility(View.GONE);
            } else {
                view.setVisibility(View.VISIBLE);
            }

            if (getActivity() != null) {
                getActivity().setProgressBarIndeterminateVisibility(false);
                refreshIcon.setVisible(true);
            }
        }

        public void onFormResubmission(WebView view, Message dontResend, Message resend) {
            resend.sendToTarget();
        }

    });

    webView.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                    if (webView.canGoBack()) {
                        webView.goBack();
                        return true;
                    }
                    break;
                }
            }
            return false;
        }
    });

    rootUrl = getUrl(activity);
    webView.loadUrl(rootUrl);

    return v;
}