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: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   www  . j  a va 2 s.c o m*/

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

From source file:com.app.blockydemo.ui.dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());//from   w  ww. jav  a 2 s  .c om
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener(dialog);

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.TextDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getActivity())
            .inflate(hku.fyp14017.blencode.R.layout.dialog_text_dialog, null);
    input = (EditText) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_edit_text);
    inputTitle = (TextView) dialogView.findViewById(hku.fyp14017.blencode.R.id.dialog_text_text_view);

    if (getHint() != null) {
        input.setHint(getHint());//from  ww  w.j a v  a  2 s. c  om
    }

    input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                getDialog().getWindow()
                        .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });

    initialize();

    Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView).setTitle(getTitle())
            .setNegativeButton(hku.fyp14017.blencode.R.string.cancel_button, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dismiss();
                }
            }).setPositiveButton(hku.fyp14017.blencode.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).create();

    dialog.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                boolean okButtonResult = handleOkButton();
                onOkButtonHandled();
                if (okButtonResult) {
                    dismiss();
                }
                return okButtonResult;
            }

            return false;
        }
    });

    dialog.setCanceledOnTouchOutside(true);
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            Button buttonPositive = ((AlertDialog) getDialog()).getButton(DialogInterface.BUTTON_POSITIVE);
            buttonPositive.setEnabled(getPositiveButtonEnabled());

            setPositiveButtonClickCustomListener();

            InputMethodManager inputManager = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);

            initTextChangedListener();
        }
    });

    return dialog;
}

From source file:pt.hive.cameo.activities.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // saves a reference to the current instance under the self variable
    // so that it may be used by any clojure method
    final LoginActivity self = this;

    // tries to retrieve the extras set of parameters from the intent
    // and in case they exist, tries to retrieve the login path (parameter)
    Bundle extras = this.getIntent().getExtras();
    if (extras != null) {
        this.loginPath = extras.getString("LOGIN_PATH");
        this.logoId = extras.getInt("LOGO_ID");
    }//from w  w  w  .j a v  a  2s.  c  o m

    // removes the title bar from the window (improves readability)
    // and then sets the login layout on it (starts the layout)
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.setContentView(R.layout.login);

    // in case we've received a valid logo identifier the logo image must be
    // updated with the associated resource (customized view)
    if (this.logoId != 0) {
        Drawable logoResource = this.getResources().getDrawable(this.logoId);
        ImageView logo = (ImageView) this.findViewById(R.id.logo);
        logo.setImageDrawable(logoResource);
    }

    // retrieves the password edit text field and updates it to the
    // sans serif typeface and then updates the transformation method
    EditText password = (EditText) this.findViewById(R.id.password);
    password.setTypeface(Typeface.SANS_SERIF);
    password.setTransformationMethod(new PasswordTransformationMethod());
    password.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                self.login();
            }
            return false;
        }
    });

    // retrieves the reference to the various button in the current activity
    // and registers the current instance as the click listener
    Button signIn = (Button) findViewById(R.id.sign_in);
    signIn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            self.login();
        }
    });
}

From source file:com.jefftharris.passwdsafe.lib.view.GuiUtils.java

/**
 * Setup the keyboard on a form.  The final field performs the supplied
 * runnable when enter is pressed.//from   w ww  . ja  v  a2s .co  m
 */
public static void setupFormKeyboard(TextView firstField, TextView finalField, Context ctx,
        final Runnable enterRunnable) {
    if (firstField != null) {
        GuiUtilsFroyo.showKeyboard(firstField, ctx);
    }

    finalField.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: {
                    enterRunnable.run();
                    return true;
                }
                }
            }
            return false;
        }
    });
}

From source file:com.mobshep.mobileshepherd.UDataLeakage.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.udl_layout);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  w  w w  . j ava  2 s . c  om*/

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    String destinationDir = "/data/data/" + getPackageName() + "/files/";

    String destinationPath = destinationDir + "Tue Jul 08 172618 EDT 2014";

    File f = new File(destinationPath);

    if (!f.exists()) {
        File directory = new File(destinationDir);
        directory.mkdirs();
        //assets members.db -> /databases/

        try {
            copyKey(getBaseContext().getAssets().open("Tue Jul 08 172618 EDT 2014"),
                    new FileOutputStream(destinationPath));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    ListView noteList = (ListView) findViewById(R.id.noteList);
    final EditText miniNote = (EditText) findViewById(R.id.miniNote);
    final ArrayList<String> noteItems = new ArrayList<String>();
    final ArrayAdapter<String> arrayAdapter;

    arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, noteItems);

    noteList.setAdapter(arrayAdapter);

    miniNote.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
                if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER) || keyCode == KeyEvent.KEYCODE_ENTER) {

                    String Log = miniNote.getText().toString();

                    logDetails(Log);

                    noteItems.add(0, miniNote.getText().toString());
                    arrayAdapter.notifyDataSetChanged();
                    miniNote.setText("");
                    miniNote.setTextColor(Color.WHITE);

                    return true;
                }
            return false;
        }
    }

    );

}

From source file:illab.nabal.proxy.AuthWebDialog.java

/**
 * Override hardware back key to close this dialog.
 * /* w w w  .  j  a v  a  2s. com*/
 * @deprecated
 */
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
        //Log.d(TAG, "keyCode : " + keyCode + " | event.getAction() : " + event.getAction());
        Log.d(TAG, "BACK key has been pressed on WebView");
        mNetworkWebViewClient.onCancel();
    }
    return true;
}

From source file:online.privacy.SetupActivity.java

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

    connectivityWarning = findViewById(R.id.warning_connectivity);
    connectivityWarningHeight = (int) getResources().getDimension(R.dimen.warning_connectivity_height);

    SharedPreferences preferences = getSharedPreferences(getString(R.string.privacyonline_preferences),
            MODE_PRIVATE);//from   w w w.j  a v  a2 s  . c  o  m
    defaultVPNLocationUpdate = defaultVPNLocationStart = preferences.getString("default_vpn_location", "");

    final EditText usernameInput = (EditText) findViewById(R.id.input_text_username);
    final EditText passwordInput = (EditText) findViewById(R.id.input_password_password);

    usernameInput.setText(preferences.getString("username", ""));
    usernameInput.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                usernameInput.clearFocus();
                passwordInput.requestFocus();
                return true;
            }
            return false;
        }
    });

    passwordInput.setText(preferences.getString("password", ""));

    // Ugh, apparently we can't define text on buttons to have the underlined property from
    // within the XML, so we'll do it here we have to set the intent chooser here anyway.
    Button buttonSignUp = (Button) findViewById(R.id.button_cta_signup);
    buttonSignUp.setPaintFlags(buttonSignUp.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
    buttonSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent ctaIntent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(getString(R.string.privacy_online_signup)));
            startActivity(ctaIntent);
        }
    });

    final Button buttonSave = (Button) findViewById(R.id.button_save);
    buttonSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText inputTextUsername = (EditText) findViewById(R.id.input_text_username);
            EditText inputTextPassword = (EditText) findViewById(R.id.input_password_password);
            clearErrorState(inputTextUsername);
            clearErrorState(inputTextPassword);
            setErrorInfoVisibility(View.INVISIBLE);

            setWorkingState(true);

            Intent apiIntent = new Intent(contextSetup, PrivacyOnlineAPIService.class);
            apiIntent.putExtra(PrivacyOnlineAPIService.PARAM_USERNAME, inputTextUsername.getText().toString());
            apiIntent.putExtra(PrivacyOnlineAPIService.PARAM_PASSWORD, inputTextPassword.getText().toString());
            apiIntent.setAction(PrivacyOnlineAPIService.ACTION_VERIFY_USERNAME);
            startService(apiIntent);
        }
    });

}

From source file:com.android.settings.SeekBarPreference.java

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (event.getAction() != KeyEvent.ACTION_DOWN) {
        return false;
    }//from   ww w  .  j a  v  a  2s . c o  m

    SeekBar seekBar = (SeekBar) v.findViewById(com.android.internal.R.id.seekbar);
    if (seekBar == null) {
        return false;
    }
    return seekBar.onKeyDown(keyCode, event);
}

From source file:com.github.yuukis.businessmap.app.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        switch (event.getKeyCode()) {
        case KeyEvent.KEYCODE_BACK:
            // ?//from ww  w  .  j a  v a  2s . c o m
            ContactsListFragment listFragment = (ContactsListFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.contacts_list);
            if (listFragment != null && listFragment.getVisibility()) {
                // ????????
                listFragment.setVisibility(false);
                return true;
            }
        }
    }
    return super.dispatchKeyEvent(event);
}