Java Code Examples for android.widget.EditText#setKeyListener()

The following examples show how to use android.widget.EditText#setKeyListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivityMain.java    From nfcspy with GNU General Public License v3.0 6 votes vote down vote up
private void setDiscoveryDelay() {

		final EditText input = new EditText(this);
		input.setHint(this.getString(R.string.hint_discoverydelay));
		input.setText(Integer.toString(nfc.getDiscoveryDelay()));
		input.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
		input.setKeyListener(DigitsKeyListener.getInstance("01234567890"));
		input.setSingleLine(true);

		SetDelayHelper helper = new SetDelayHelper(nfc, input);

		new AlertDialog.Builder(this, AlertDialog.THEME_HOLO_LIGHT)
				.setTitle(R.string.action_discoverydelay)
				.setMessage(R.string.lab_discoverydelay).setView(input)
				.setPositiveButton(R.string.action_ok, helper)
				.setNegativeButton(R.string.action_cancel, helper).show();
	}
 
Example 2
Source File: TextEntryElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected View createView(Context c) {
    et = new EditText(c);
    et.setBackgroundResource(R.drawable.oval);
    et.setTextColor(c.getResources()
            .getColorStateList(R.color.primary_text_holo_light));
    et.setText(answer);
    et.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    if (!NumericType.NONE.equals(numericType)) {
        KeyListener listener = getKeyListenerForType(numericType);
        if (listener != null)
            et.setKeyListener(listener);
    } else {
        et.setRawInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES |
                TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    }
    return encapsulateQuestion(c, et);
}
 
Example 3
Source File: EditTextAty.java    From Huochexing12306 with Apache License 2.0 5 votes vote down vote up
private void initViews() {
	etPwd = (EditText)findViewById(R.id.pwd);
	etInfo = (EditText)findViewById(R.id.info);
	tvTip = (TextView)findViewById(R.id.tip);
	tvErrorMsg = (TextView)findViewById(R.id.errorMsg);
	btnOperate = (Button)findViewById(R.id.ok);
	btnOperate.setOnClickListener(this);
	
	//取得从上一个Activity传递过来的数据
	bundle = this.getIntent().getExtras();
	actBar.setTitle(bundle.getString(BAR_TITLE));
	etInfo.setText(bundle.getString(INFO));
	if (bundle.getBoolean(INFO_READONLY)){
		etInfo.setKeyListener(null);
	}else{
		etInfo.setSelection(etInfo.getText().length());
	}
	strRegex = bundle.getString(REGEX);
	tvTip.setText(bundle.getString(TIP));
	btnOperate.setText(bundle.getString(OPERATE_TEXT));
	
	//设置隐藏项
	String strOperate = bundle.getString(OPERATE);
	if (strOperate.equals(OPERATE_BIND_EMAIL) || strOperate.equals(OPERATE_BIND_PHONE)){
		etPwd.setVisibility(View.VISIBLE);
	}else{
		etPwd.setVisibility(View.GONE);
	}
}
 
Example 4
Source File: EditCommandAliasActivity.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
private static void setEditTextDisabled(EditText editText) {
    editText.setInputType(InputType.TYPE_NULL);
    editText.setTextIsSelectable(true);
    editText.setKeyListener(null);

    editText.setBackgroundResource(R.drawable.edit_text_readonly);
    int color = StyledAttributesHelper.getColor(editText.getContext(), android.R.attr.textColorSecondary, 0);
    ViewCompat.setBackgroundTintList(editText, ColorStateList.valueOf(color));
    ((ViewGroup) editText.getParent()).setAddStatesFromChildren(false);
}
 
Example 5
Source File: ConfigureStandupTimer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private View createMeetingLengthTextBox() {
    meetingLengthEditText = new EditText(this);
    meetingLengthEditText.setGravity(Gravity.CENTER);
    meetingLengthEditText.setKeyListener(new DigitsKeyListener());
    meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
    meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
    meetingLengthEditText.setText(Integer.toString(meetingLength));
    meetingLengthEditText.setLines(1);

    meetingLengthSpinner = null;
    return meetingLengthEditText;
}
 
Example 6
Source File: ConfigureStandupTimer.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private View createMeetingLengthTextBox() {
    meetingLengthEditText = new EditText(this);
    meetingLengthEditText.setGravity(Gravity.CENTER);
    meetingLengthEditText.setKeyListener(new DigitsKeyListener());
    meetingLengthEditText.setRawInputType(InputType.TYPE_CLASS_PHONE);
    meetingLengthEditText.setLayoutParams(new LayoutParams(dipsToPixels(60), LayoutParams.WRAP_CONTENT));
    meetingLengthEditText.setText(Integer.toString(meetingLength));
    meetingLengthEditText.setLines(1);

    meetingLengthSpinner = null;
    return meetingLengthEditText;
}
 
Example 7
Source File: PatientIdElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected View createView(Context c) {

    et = new EditText(c);
    et.setPadding(10, 5, 10, 5);
    et.setText(answer);
    et.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT));
    et.setGravity(Gravity.CENTER_HORIZONTAL);
    et.setKeyListener(new DialerKeyListener());

    LinearLayout ll = new LinearLayout(c);
    ll.setOrientation(LinearLayout.VERTICAL);

    ll.addView(et, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));
    ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT));

    //SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(c);
    boolean barcodeEnable = true; //sp.getBoolean(Constants.PREFERENCE_BARCODE_ENABLED, false);

    if (barcodeEnable) {
        barcodeButton = new Button(c);
        barcodeButton.setText(c.getResources().getString(
                R.string.procedurerunner_scan_id));
        barcodeButton.setOnClickListener(this);
        barcodeButton.setGravity(Gravity.CENTER_HORIZONTAL);
        ll.addView(barcodeButton, new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    }
    return encapsulateQuestion(c, ll);
}
 
Example 8
Source File: ApkInstrumenterActivity.java    From hk with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	context = getApplicationContext();

	// Init attributes
	serviceStarted = (TextView) findViewById(R.id.serviceStatus);
	idXp = (TextView) findViewById(R.id.idExperiment);
	esState = (TextView) findViewById(R.id.esStatus);
	esIP = (EditText) findViewById(R.id.esIP);
	Log.i(TAG, "1");
	esPort = (EditText) findViewById(R.id.esPort);
	Log.i(TAG, "2");
	esIndex = (EditText) findViewById(R.id.esIndex);
	Log.i(TAG, "3");
	docType = (EditText) findViewById(R.id.docType);
	Log.i(TAG, "4");
	filemode = (TextView) findViewById(R.id.filemodeStatus);
	Log.i(TAG, "5");
	filename = (EditText) findViewById(R.id.filename);

	// Disable edittext
	esIP.setKeyListener(null);
	esPort.setKeyListener(null);
	filename.setKeyListener(null);
	esIndex.setKeyListener(null);
	docType.setKeyListener(null);
	filemode.setKeyListener(null);
	
	doBindService();
	if (checkIfServiceIsRunning()) {
		serviceStarted.setText("ON");
	} else {
		serviceStarted.setText("OFF");
	}
}
 
Example 9
Source File: PadActivity.java    From Bluefruit_LE_Connect_Android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pad);

    mBleManager = BleManager.getInstance(this);
    restoreRetainedDataFragment();

    // UI
    mContentView = (ViewGroup) findViewById(R.id.contentView);
    mBufferTextView = (EditText) findViewById(R.id.bufferTextView);
    if (mBufferTextView != null) {
        mBufferTextView.setKeyListener(null);     // make it not editable
    }

    ImageButton upArrowImageButton = (ImageButton) findViewById(R.id.upArrowImageButton);
    upArrowImageButton.setOnTouchListener(mPadButtonTouchListener);
    ImageButton leftArrowImageButton = (ImageButton) findViewById(R.id.leftArrowImageButton);
    leftArrowImageButton.setOnTouchListener(mPadButtonTouchListener);
    ImageButton rightArrowImageButton = (ImageButton) findViewById(R.id.rightArrowImageButton);
    rightArrowImageButton.setOnTouchListener(mPadButtonTouchListener);
    ImageButton bottomArrowImageButton = (ImageButton) findViewById(R.id.bottomArrowImageButton);
    bottomArrowImageButton.setOnTouchListener(mPadButtonTouchListener);

    ImageButton button1ImageButton = (ImageButton) findViewById(R.id.button1ImageButton);
    button1ImageButton.setOnTouchListener(mPadButtonTouchListener);
    ImageButton button2ImageButton = (ImageButton) findViewById(R.id.button2ImageButton);
    button2ImageButton.setOnTouchListener(mPadButtonTouchListener);
    ImageButton button3ImageButton = (ImageButton) findViewById(R.id.button3ImageButton);
    button3ImageButton.setOnTouchListener(mPadButtonTouchListener);
    ImageButton button4ImageButton = (ImageButton) findViewById(R.id.button4ImageButton);
    button4ImageButton.setOnTouchListener(mPadButtonTouchListener);

    // Read shared preferences
    maxPacketsToPaintAsText = PreferencesFragment.getUartTextMaxPackets(this);
    //Log.d(TAG, "maxPacketsToPaintAsText: "+maxPacketsToPaintAsText);

    // Start services
    onServicesDiscovered();
}
 
Example 10
Source File: ProfileLayout.java    From kakao-android-sdk-standalone with Apache License 2.0 5 votes vote down vote up
/**
 * 사용자 정보를 layout에 그려준다.
 */
@Override
protected void onAttachedToWindow () {
    super.onAttachedToWindow();
    View view = inflate(getContext(), R.layout.kakao_profile_layout, this);

    profile = (ImageView) view.findViewById(R.id.com_kakao_profile_image);
    if (profileImageURL != null)
        setProfileURL(profileImageURL);
    if (!editable) {
        ImageView editableMark = (ImageView) view.findViewById(R.id.profile_edit);
        editableMark.setVisibility(View.INVISIBLE);
    }

    nicknameText = (EditText) view.findViewById(R.id.com_kakao_profile_nickname);
    if (!editable) {
        nicknameText.setEnabled(false);
        nicknameText.setKeyListener(null);
        setBackgroundCompat(nicknameText, null);
        nicknameText.setPadding(0, 0, 0, 0);
        nicknameText.setTextColor(getResources().getColor(R.color.com_kakao_profile_text));
    }
    if (nickname != null)
        nicknameText.setText(nickname);

    userIdText = (TextView) view.findViewById(R.id.com_kakao_profile_userId);
    if (userId != null)
        userIdText.setText(userId);
}
 
Example 11
Source File: ViewUtils.java    From Shield with MIT License 4 votes vote down vote up
public static void readOnlyView(EditText v) {
    if (v == null) {
        return;
    }
    v.setKeyListener(null);
}
 
Example 12
Source File: StringWidget.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public StringWidget(Context context, FormEntryPrompt prompt, boolean secret, boolean inCompactGroup) {
    super(context, prompt, inCompactGroup);
    mAnswer = (EditText)LayoutInflater.from(getContext()).inflate(getAnswerLayout(), this, false);
    mAnswer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontSize);
    mAnswer.setOnClickListener(this);

    mAnswer.addTextChangedListener(this);

    //Let's see if we can figure out a constraint for this string
    try {
        addAnswerFilter(new InputFilter.LengthFilter(guessMaxStringLength(prompt)));
    } catch (UnpivotableExpressionException e) {
        //expected if there isn't a constraint that does this
    }

    this.secret = secret;

    if (!secret) {
        // capitalize the first letter of the sentence
        mAnswer.setKeyListener(new TextKeyListener(Capitalize.SENTENCES, false));
    }
    setTextInputType(mAnswer);

    if (!secret) {
        mAnswer.setSingleLine(false);
    }

    if (prompt != null) {
        mReadOnly = prompt.isReadOnly();
        IAnswerData value = prompt.getAnswerValue();
        if (value != null) {
            mAnswer.setText(value.getDisplayText());
        }

        if (mReadOnly) {
            if (value == null) {
                mAnswer.setText("---");
            }
            mAnswer.setBackgroundDrawable(null);
            mAnswer.setFocusable(false);
            mAnswer.setClickable(false);
        }
    }

    if (isInCompactMode()) {
        addToCompactLayout(mAnswer);
    } else {
        addView(mAnswer);
    }
}
 
Example 13
Source File: UartActivity.java    From Bluefruit_LE_Connect_Android with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_uart);

    mBleManager = BleManager.getInstance(this);
    restoreRetainedDataFragment();

    // Get default theme colors
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = getTheme();
    theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
    mTxColor = typedValue.data;
    theme.resolveAttribute(R.attr.colorControlActivated, typedValue, true);
    mRxColor = typedValue.data;

    // UI
    mBufferListView = (ListView) findViewById(R.id.bufferListView);
    mBufferListAdapter = new TimestampListAdapter(this, R.layout.layout_uart_datachunkitem);
    mBufferListView.setAdapter(mBufferListAdapter);
    mBufferListView.setDivider(null);

    mBufferTextView = (EditText) findViewById(R.id.bufferTextView);
    if (mBufferTextView != null) {
        mBufferTextView.setKeyListener(null);     // make it not editable
    }

    mSendEditText = (EditText) findViewById(R.id.sendEditText);
    mSendEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                onClickSend(null);
                return true;
            }

            return false;
        }
    });
    mSendEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(View view, boolean hasFocus) {
            if (!hasFocus) {
                // Dismiss keyboard when sendEditText loses focus
                dismissKeyboard(view);
            }
        }
    });

    mSentBytesTextView = (TextView) findViewById(R.id.sentBytesTextView);
    mReceivedBytesTextView = (TextView) findViewById(R.id.receivedBytesTextView);

    // Read shared preferences
    maxPacketsToPaintAsText = PreferencesFragment.getUartTextMaxPackets(this);
    //Log.d(TAG, "maxPacketsToPaintAsText: "+maxPacketsToPaintAsText);

    // Read local preferences
    SharedPreferences preferences = getSharedPreferences(kPreferences, MODE_PRIVATE);
    mShowDataInHexFormat = !preferences.getBoolean(kPreferences_asciiMode, true);
    final boolean isTimestampDisplayMode = preferences.getBoolean(kPreferences_timestampDisplayMode, false);
    setDisplayFormatToTimestamp(isTimestampDisplayMode);
    mIsEchoEnabled = preferences.getBoolean(kPreferences_echo, true);
    mIsEolEnabled = preferences.getBoolean(kPreferences_eol, true);
    mEolCharactersId = preferences.getInt(kPreferences_eolCharactersId, 0);
    invalidateOptionsMenu();        // udpate options menu with current values

    // Continue
    onServicesDiscovered();

    // Mqtt init
    mMqttManager = MqttManager.getInstance(this);
    if (MqttSettings.getInstance(this).isConnected()) {
        mMqttManager.connectFromSavedSettings(this);
    }
}
 
Example 14
Source File: ChannelDetailActivity.java    From buddycloud-android with Apache License 2.0 4 votes vote down vote up
private void setEditable(boolean editable, EditText editText) {
	if (!editable) {
		editText.setKeyListener(null);
	}
}
 
Example 15
Source File: GNfcUidView.java    From geopaparazzi with GNU General Public License v3.0 4 votes vote down vote up
private void handleView(final Activity activity, final int requestCode, LinearLayout parentView, String label, String value,
                        String constraintDescription) {
    _value = value;

    LinearLayout textLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(activity);
    textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    textView.setText(label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription);
    textView.setTextColor(Compat.getColor(activity, R.color.formcolor));
    textLayout.addView(textView);

    final Button button = new Button(activity);
    StyleHelper.styleButton(activity, button);
    button.setText(R.string.read_nfc_uid);
    textLayout.addView(button);

    uidText = new EditText(activity);
    uidText.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    uidText.setPadding(2, 2, 2, 2);
    uidText.setEnabled(false);
    uidText.setText(value);
    uidText.setTextColor(Compat.getColor(activity, R.color.main_text_color_neutral));
    uidText.setKeyListener(null);
    textLayout.addView(uidText);

    button.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent nfcIntent = new Intent(activity, NfcIdReaderActivity.class);
            if (fragmentDetail != null) {
                fragmentDetail.startActivityForResult(nfcIntent, requestCode);
            } else {
                activity.startActivityForResult(nfcIntent, requestCode);
            }
        }
    });
}