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:org.ednovo.goorusearchwidget.HomeScreenActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home_screen);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    prefsPrivate = getSharedPreferences(PREFS_PRIVATE, Context.MODE_PRIVATE);
    headerSearch = (RelativeLayout) findViewById(R.id.layoutHeader);
    imgViewGooruSearch = (ImageView) findViewById(R.id.ivGooruLogo);
    imgViewSections = (ImageView) findViewById(R.id.imgViewSections);
    imgViewSettings = (ImageView) findViewById(R.id.imgViewSettings);
    imageViewClose = (ImageView) findViewById(R.id.imageViewClose);
    imageViewSearch = (ImageView) findViewById(R.id.imageViewSearch);
    editTexthome = (EditText) findViewById(R.id.textViewSearch);
    switchResColl = (Switch) findViewById(R.id.switchResColl);

    dialog = new ProgressDialog(this);
    imm = (InputMethodManager) this.getSystemService(Service.INPUT_METHOD_SERVICE);
    new Loginform().execute();
    switchResColl.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override//from   w  ww.  j  ava 2  s .c om
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                Log.i("Hello", "True");
                searchCriteria = true;
            } else {
                Log.i("Hello", "False");
                searchCriteria = false;
            }
        }
    });

    editTexthome.setOnKeyListener(new OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                    searchKeyword = editTexthome.getText().toString().trim();
                    if (searchKeyword.isEmpty() || searchKeyword.length() == 0) {

                    } else {
                        if (!searchCriteria) {
                            Log.i("Resources", searchKeyword);
                            Intent intentResResults = new Intent(getBaseContext(),
                                    SearchResults_resource.class);

                            Bundle extras = new Bundle();
                            extras.putString("keyWord", searchKeyword);
                            intentResResults.putExtras(extras);
                            startActivity(intentResResults);
                            finish();
                        }
                    }
                    return true;
                default:
                    break;
                }
            }
            return false;
        }
    });

    imageViewClose.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            finish();
        }
    });

    imgViewGooruSearch.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Intent intentResResults = new Intent(getBaseContext(), SearchDialogpopup.class);

            startActivity(intentResResults);

        }
    });

}

From source file:com.xee.auth.SignInButton.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_UP && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER
            || event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
        if (mListener != null) {
            mListener.onClick(this);
        }//ww w. j  a v a 2  s  . c  om
        if (mConnectionCallback != null) {
            signIn();
        }
    }
    return super.dispatchKeyEvent(event);
}

From source file:com.vladstirbu.cordova.Gamepad.java

/**
 * Constructs the JavaScript string that triggers the event in Cordova WebView
 * @param keyCode/*w  w w  .j a  va2s .c om*/
 * @param event
 * @return
 */
private String jsString(int keyCode, KeyEvent event) {
    String eventType;
    JSONObject data = new JSONObject();

    if (this.map.containsKey(KeyEvent.keyCodeToString(keyCode))) {

        if (event.getAction() == 0) {
            eventType = "GamepadButtonDown";
            this.buttons[this.map.get(KeyEvent.keyCodeToString(keyCode))] = 1;
        } else {
            eventType = "GamepadButtonUp";
            this.buttons[this.map.get(KeyEvent.keyCodeToString(keyCode))] = 0;
        }

        try {
            data.put("button", this.map.get(KeyEvent.keyCodeToString(keyCode)));
            data.put("deviceId", event.getDeviceId());
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return "cordova.fireWindowEvent('" + eventType + "', " + data.toString() + ");";
    } else {
        return "";
    }
}

From source file:net.sourceforge.servestream.fragment.AddUrlFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    mUrlEditText.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (event.getAction() == KeyEvent.ACTION_UP)
                return false;

            if (keyCode != KeyEvent.KEYCODE_ENTER)
                return false;

            processUri();//from w w w  . j  ava2 s.c  o  m

            return true;
        }

    });

    mCancelButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().finish();
        }

    });

    mConfirmButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            processUri();
        }
    });

    mSavePlaylistEntriesCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                mNicknameEditText.setEnabled(false);
            } else {
                mNicknameEditText.setEnabled(true);
            }
        }
    });
}

From source file:com.waz.zclient.pages.main.popup.QuickReplyFragment.java

@Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_SEND || (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
            && event.getAction() == KeyEvent.ACTION_DOWN)) {
        final String sendText = textView.getText().toString();
        if (TextUtils.isEmpty(sendText)) {
            return false;
        }/* www  .  j  av a 2 s. c om*/
        conversation.sendMessage(new MessageContent.Text(sendText));

        TrackingUtils.onSentTextMessage(getControllerFactory().getTrackingController(),
                getStoreFactory().getConversationStore().getCurrentConversation());
        getActivity().finish();
        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   w  ww .  j  a v a2  s  . c  o  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:com.example.android.leanback.PlaybackTransportControlGlueSample.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        Action action = getControlsRow().getActionForKeyCode(keyEvent.getKeyCode());
        if (shouldDispatchAction(action)) {
            dispatchAction(action);//from ww w . j  a v  a 2 s .  c o  m
            return true;
        }
    }
    return super.onKey(view, keyCode, keyEvent);
}

From source file:com.google.cloud.solutions.flexenv.PlayActivity.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).push()
                .setValue(new Message(messageText.getText().toString(), acct.getDisplayName()));
        return true;
    }/*  w ww  .  j a  v  a  2 s.  c  om*/
    return false;
}

From source file:hku.fyp14017.blencode.ui.ProjectActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Dismiss ActionMode without effecting sounds
    if (spritesListFragment.getActionModeActive() && event.getKeyCode() == KeyEvent.KEYCODE_BACK
            && event.getAction() == KeyEvent.ACTION_UP) {
        SpriteAdapter adapter = (SpriteAdapter) spritesListFragment.getListAdapter();
        adapter.clearCheckedSprites();/*  www  .ja  va2 s . co m*/
    }

    return super.dispatchKeyEvent(event);
}

From source file:com.example.photoremark.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            onExit();/*from w w  w  . java  2 s  .  c om*/
        }
    }
    return true;
}