Search in sources :

Example 1 with OnKeyListener

use of android.view.View.OnKeyListener in project KJFrameForAndroid by kymjs.

the class CurtainViewController method prepareSlidingLayout.

/**
     * 为控件做一些属性设置
     */
protected void prepareSlidingLayout() {
    curtainLayoutParams = (FrameLayout.LayoutParams) curtainParent.getLayoutParams();
    ViewTreeObserver vto = curtainParent.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {

        @Override
        @SuppressLint("NewApi")
        public void onGlobalLayout() {
            hideCurtainLayout();
            ViewTreeObserver obs = curtainParent.getViewTreeObserver();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                obs.removeOnGlobalLayoutListener(this);
            } else {
                obs.removeGlobalOnLayoutListener(this);
            }
        }
    });
    curtainParent.setOnTouchListener(new OnContentTouchListener());
    curtainParent.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && getSlidingStatus() == SlidingStatus.EXPANDED) {
                collapse();
                return true;
            } else {
                return false;
            }
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) FrameLayout(android.widget.FrameLayout) OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) SuppressLint(android.annotation.SuppressLint) OnKeyListener(android.view.View.OnKeyListener) ViewTreeObserver(android.view.ViewTreeObserver) View(android.view.View) SuppressLint(android.annotation.SuppressLint)

Example 2 with OnKeyListener

use of android.view.View.OnKeyListener in project mobile-android by photo.

the class TextPanel method beginEdit.

/**
	 * Begin edit and open the android soft keyboard if available
	 * 
	 * @param view
	 *           the view
	 */
private void beginEdit(final DrawableHighlightView view) {
    if (null != view) {
        view.setFocused(true);
    }
    mEditTextWatcher.view = null;
    mEditText.removeTextChangedListener(mEditTextWatcher);
    mEditText.setOnKeyListener(null);
    final EditableDrawable editable = (EditableDrawable) view.getContent();
    final String oldText = editable.isTextHint() ? "" : (String) editable.getText();
    mEditText.setText(oldText);
    mEditText.setSelection(mEditText.length());
    mEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    mEditText.requestFocusFromTouch();
    // mInputManager.showSoftInput( mEditText, InputMethodManager.SHOW_IMPLICIT );
    mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
    mEditTextWatcher.view = view;
    mEditText.setOnEditorActionListener(this);
    mEditText.addTextChangedListener(mEditTextWatcher);
    mEditText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            mLogger.log("onKey: " + event);
            if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_BACK) {
                if (editable.isTextHint() && editable.isEditing()) {
                    editable.setText("");
                    view.forceUpdate();
                }
            }
            return false;
        }
    });
}
Also used : KeyEvent(android.view.KeyEvent) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) OnKeyListener(android.view.View.OnKeyListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AdapterView(com.aviary.android.feather.widget.AdapterView) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) Paint(android.graphics.Paint)

Example 3 with OnKeyListener

use of android.view.View.OnKeyListener in project coursera-android by aporter.

the class SamplerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // 
    final ImageButton button = (ImageButton) findViewById(R.id.button);
    button.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Show Toast message 
            Toast.makeText(SamplerActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
        }
    });
    final EditText edittext = (EditText) findViewById(R.id.edittext);
    edittext.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "Done" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Show Toast message 
                Toast.makeText(SamplerActivity.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                return true;
            }
            return false;
        }
    });
    final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
    checkbox.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Show Toast message indicating the CheckBox's Checked state
            if (((CheckBox) v).isChecked()) {
                Toast.makeText(SamplerActivity.this, "CheckBox checked", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SamplerActivity.this, "CheckBox not checked", Toast.LENGTH_SHORT).show();
            }
        }
    });
    final RadioButton radio_red = (RadioButton) findViewById(R.id.radio_red);
    final RadioButton radio_blue = (RadioButton) findViewById(R.id.radio_blue);
    radio_red.setOnClickListener(radio_listener);
    radio_blue.setOnClickListener(radio_listener);
    final ToggleButton togglebutton = (ToggleButton) findViewById(R.id.togglebutton);
    togglebutton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // Perform action on clicks
            if (togglebutton.isChecked()) {
                Toast.makeText(SamplerActivity.this, "ToggleButton checked", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(SamplerActivity.this, "ToggleButton not checked", Toast.LENGTH_SHORT).show();
            }
        }
    });
    final RatingBar ratingbar = (RatingBar) findViewById(R.id.ratingbar);
    ratingbar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
            Toast.makeText(SamplerActivity.this, "New Rating: " + rating, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : EditText(android.widget.EditText) ToggleButton(android.widget.ToggleButton) OnRatingBarChangeListener(android.widget.RatingBar.OnRatingBarChangeListener) RadioButton(android.widget.RadioButton) View(android.view.View) RatingBar(android.widget.RatingBar) KeyEvent(android.view.KeyEvent) ImageButton(android.widget.ImageButton) CheckBox(android.widget.CheckBox) OnClickListener(android.view.View.OnClickListener) OnKeyListener(android.view.View.OnKeyListener)

Example 4 with OnKeyListener

use of android.view.View.OnKeyListener in project android-bootstrap by AndroidBootstrap.

the class BootstrapAuthenticatorActivity method onCreate.

@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    BootstrapApplication.component().inject(this);
    accountManager = AccountManager.get(this);
    final Intent intent = getIntent();
    email = intent.getStringExtra(PARAM_USERNAME);
    authTokenType = intent.getStringExtra(PARAM_AUTHTOKEN_TYPE);
    confirmCredentials = intent.getBooleanExtra(PARAM_CONFIRM_CREDENTIALS, false);
    requestNewAccount = email == null;
    setContentView(layout.login_activity);
    ButterKnife.bind(this);
    emailText.setAdapter(new ArrayAdapter<String>(this, simple_dropdown_item_1line, userEmailAccounts()));
    passwordText.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(final View v, final int keyCode, final KeyEvent event) {
            if (event != null && ACTION_DOWN == event.getAction() && keyCode == KEYCODE_ENTER && signInButton.isEnabled()) {
                handleLogin(signInButton);
                return true;
            }
            return false;
        }
    });
    passwordText.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(final TextView v, final int actionId, final KeyEvent event) {
            if (actionId == IME_ACTION_DONE && signInButton.isEnabled()) {
                handleLogin(signInButton);
                return true;
            }
            return false;
        }
    });
    emailText.addTextChangedListener(watcher);
    passwordText.addTextChangedListener(watcher);
    final TextView signUpText = (TextView) findViewById(id.tv_signup);
    signUpText.setMovementMethod(LinkMovementMethod.getInstance());
    signUpText.setText(Html.fromHtml(getString(string.signup_link)));
}
Also used : KeyEvent(android.view.KeyEvent) OnKeyListener(android.view.View.OnKeyListener) Intent(android.content.Intent) OnEditorActionListener(android.widget.TextView.OnEditorActionListener) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) View(android.view.View) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 5 with OnKeyListener

use of android.view.View.OnKeyListener in project double-espresso by JakeWharton.

the class SendActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.send_activity);
    EditText editText = (EditText) findViewById(R.id.enter_data_edit_text);
    editText.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View view, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                EditText editText = (EditText) view;
                TextView responseText = (TextView) findViewById(R.id.enter_data_response_text);
                responseText.setText(editText.getText());
                return true;
            } else {
                return false;
            }
        }
    });
    final EditText searchBox = (EditText) findViewById(R.id.search_box);
    searchBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                TextView result = (TextView) findViewById(R.id.search_result);
                result.setText(getString(R.string.searching_for_label) + " " + v.getText());
                result.setVisibility(View.VISIBLE);
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchBox.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });
    AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.auto_complete_text_view);
    String[] completions = new String[] { "Pacific Ocean", "Atlantic Ocean", "Indian Ocean", "Southern Ocean", "Artic Ocean", "Mediterranean Sea", "Caribbean Sea", "South China Sea", "Bering Sea", "Gulf of Mexico", "Okhotsk Sea", "East China Sea", "Hudson Bay", "Japan Sea", "Andaman Sea", "North Sea", "Red Sea", "Baltic Sea" };
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, completions);
    autoComplete.setAdapter(adapter);
}
Also used : EditText(android.widget.EditText) InputMethodManager(android.view.inputmethod.InputMethodManager) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) OnKeyListener(android.view.View.OnKeyListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Aggregations

KeyEvent (android.view.KeyEvent)9 View (android.view.View)9 OnKeyListener (android.view.View.OnKeyListener)9 TextView (android.widget.TextView)6 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 Intent (android.content.Intent)3 EditText (android.widget.EditText)3 OnClickListener (android.view.View.OnClickListener)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 ArrayAdapter (android.widget.ArrayAdapter)2 FrameLayout (android.widget.FrameLayout)2 OnEditorActionListener (android.widget.TextView.OnEditorActionListener)2 SuppressLint (android.annotation.SuppressLint)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 ContentResolver (android.content.ContentResolver)1 Context (android.content.Context)1 Cursor (android.database.Cursor)1 Paint (android.graphics.Paint)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1