Example usage for android.view KeyEvent KEYCODE_ENTER

List of usage examples for android.view KeyEvent KEYCODE_ENTER

Introduction

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

Prototype

int KEYCODE_ENTER

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

Click Source Link

Document

Key code constant: Enter key.

Usage

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  w w.  j ava2 s .c o m*/
    }

    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:net.olejon.mdapp.DiseasesAndTreatmentsActivity.java

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

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout// w  w w  . ja v  a2s .  c  om
    setContentView(R.layout.activity_diseases_and_treatments);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.diseases_and_treatments_toolbar);
    toolbar.setTitle(getString(R.string.diseases_and_treatments_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.diseases_and_treatments_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.diseases_and_treatments_toolbar_search);

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());

                return true;
            }

            return false;
        }
    });

    final ImageButton toolbarSearchClearButton = (ImageButton) findViewById(
            R.id.diseases_and_treatments_toolbar_clear_search);

    toolbarSearchClearButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    // List
    mListView = (ListView) findViewById(R.id.diseases_and_treatments_list);

    View listViewEmpty = findViewById(R.id.diseases_and_treatments_list_empty);
    mListView.setEmptyView(listViewEmpty);

    View listViewHeader = getLayoutInflater().inflate(R.layout.activity_diseases_and_treatments_list_subheader,
            mListView, false);
    mListView.addHeaderView(listViewHeader, null, false);

    // Floating action buttons
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.diseases_and_treatments_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String string = mToolbarSearchEditText.getText().toString().trim();

            if (mToolbarSearchLayout.getVisibility() == View.VISIBLE && !string.equals("")) {
                search(string);
            } else {
                showSearchLanguageDialog();
            }
        }
    });
}

From source file:org.linesofcode.alltrack.graph.AddValueActivity.java

private void initializeContent() {
    calendar = Calendar.getInstance();
    dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault());
    timeFormat = new SimpleDateFormat(TIME_PATTERN, Locale.getDefault());

    dateView = (TextView) findViewById(R.id.add_value_date);
    timeView = (TextView) findViewById(R.id.add_value_time);

    Button okButton = (Button) findViewById(R.id.add_value_ok);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from w  ww  .  j  av a2 s.  c  o  m*/
        public void onClick(View v) {
            addValue();
        }
    });

    Button cancelButton = (Button) findViewById(R.id.add_value_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            setResult(Activity.RESULT_CANCELED, new Intent(ADD_VALUE_ACTION_CODE));
            finish();
        }
    });

    EditText value = (EditText) findViewById(R.id.add_value_value);
    value.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:
                    addValue();
                    return true;
                }
            }
            return false;
        }
    });

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

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

    updateDateTimeFields();

    Bundle extras = getIntent().getExtras();
    graphId = extras.getInt("graphId");
    position = extras.getInt("position");
    Log.d(TAG, "Starting addValue Activity for graph [" + graphId + "] in position [" + position + "].");
    graph = graphService.getById(graphId);
}

From source file:net.olejon.mdapp.PoisoningsActivity.java

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

    // Intent/*w  ww . jav a2 s .  c  o  m*/
    final Intent intent = getIntent();

    final String searchString = intent.getStringExtra("search");

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout
    setContentView(R.layout.activity_poisonings);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.poisonings_toolbar);
    toolbar.setTitle(getString(R.string.poisonings_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.poisonings_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.poisonings_toolbar_search);

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());

                return true;
            }

            return false;
        }
    });

    ImageButton imageButton = (ImageButton) findViewById(R.id.poisonings_toolbar_clear_search);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.poisonings_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());
            } else {
                mToolbarSearchLayout.setVisibility(View.VISIBLE);
                mToolbarSearchEditText.requestFocus();

                mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0);
            }
        }
    });

    // List
    mListView = (ListView) findViewById(R.id.poisonings_list);

    View listViewEmpty = findViewById(R.id.poisonings_list_empty);
    mListView.setEmptyView(listViewEmpty);

    View listViewHeader = getLayoutInflater().inflate(R.layout.activity_poisonings_list_subheader, mListView,
            false);
    mListView.addHeaderView(listViewHeader, null, false);

    // Search
    if (searchString != null)
        search(searchString.split(" ")[0]);
}

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());//  w  w w. ja v a 2  s.  com
    }

    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");
    }/*w  w  w  .  j  a  v a  2  s .  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:net.simno.klingar.ui.LoginController.java

@OnEditorAction(R.id.password_edit)
boolean onPasswordEditorAction(TextView view, int actionId, KeyEvent event) {
    if ((event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
            || (actionId == EditorInfo.IME_ACTION_DONE)) {
        login();/*from w  w  w  . j  av  a 2s  . com*/
        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 www.j  a v a 2  s  .c  o  m

    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:com.jefftharris.passwdsafe.lib.view.GuiUtils.java

/**
 * Setup the keyboard on a form.  The final field performs the supplied
 * runnable when enter is pressed.//w  w w  .  j av a 2  s  .c o 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: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  ww  . java  2  s  . co 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);
        }
    });

}