List of usage examples for android.text.method TextKeyListener TextKeyListener
public TextKeyListener(Capitalize cap, boolean autotext)
From source file:org.odk.collect.android.widgets.StringWidget.java
protected StringWidget(Context context, FormEntryPrompt prompt, boolean readOnlyOverride, boolean derived) { super(context, prompt); answerText = new EditText(context); answerText.setId(ViewIds.generateViewId()); readOnly = prompt.isReadOnly() || readOnlyOverride; answerText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, answerFontsize); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); /*// w w w . j ava2s. c o m * If a 'rows' attribute is on the input tag, set the minimum number of lines * to display in the field to that value. * * I.e., * <input ref="foo" rows="5"> * ... * </input> * * will set the height of the EditText box to 5 rows high. */ String height = prompt.getQuestion().getAdditionalAttribute(null, ROWS); if (height != null && height.length() != 0) { try { int rows = Integer.parseInt(height); answerText.setMinLines(rows); answerText.setGravity(Gravity.TOP); // to write test starting at the top of the edit area } catch (Exception e) { Timber.e("Unable to process the rows setting for the answerText field: %s", e.toString()); } } params.setMargins(7, 5, 7, 5); answerText.setLayoutParams(params); // capitalize the first letter of the sentence answerText.setKeyListener(new TextKeyListener(Capitalize.SENTENCES, false)); // needed to make long read only text scroll answerText.setHorizontallyScrolling(false); answerText.setSingleLine(false); String s = prompt.getAnswerText(); if (s != null) { answerText.setText(s); Selection.setSelection(answerText.getText(), answerText.getText().toString().length()); } if (readOnly) { answerText.setBackground(null); answerText.setEnabled(false); answerText.setTextColor(ContextCompat.getColor(context, R.color.primaryTextColor)); answerText.setFocusable(false); } addAnswerView(answerText); }
From source file:org.odk.collect.android.widgets.ExStringWidget.java
public ExStringWidget(Context context, FormEntryPrompt prompt) { super(context, prompt); TableLayout.LayoutParams params = new TableLayout.LayoutParams(); params.setMargins(7, 5, 7, 5);//from w w w .j a v a2 s .co m // set text formatting answer = new EditText(context); answer.setId(ViewIds.generateViewId()); answer.setTextSize(TypedValue.COMPLEX_UNIT_DIP, answerFontsize); answer.setLayoutParams(params); textBackground = answer.getBackground(); answer.setBackground(null); answer.setTextColor(ContextCompat.getColor(context, R.color.primaryTextColor)); // capitalize nothing answer.setKeyListener(new TextKeyListener(Capitalize.NONE, false)); // needed to make long read only text scroll answer.setHorizontallyScrolling(false); answer.setSingleLine(false); String s = prompt.getAnswerText(); if (s != null) { answer.setText(s); } if (formEntryPrompt.isReadOnly() || hasExApp) { answer.setFocusable(false); answer.setEnabled(false); } String exSpec = prompt.getAppearanceHint().replaceFirst("^ex[:]", ""); final String intentName = ExternalAppsUtils.extractIntentName(exSpec); final Map<String, String> exParams = ExternalAppsUtils.extractParameters(exSpec); final String buttonText; final String errorString; String v = formEntryPrompt.getSpecialFormQuestionText("buttonText"); buttonText = (v != null) ? v : context.getString(R.string.launch_app); v = formEntryPrompt.getSpecialFormQuestionText("noAppErrorString"); errorString = (v != null) ? v : context.getString(R.string.no_app); launchIntentButton = getSimpleButton(buttonText); launchIntentButton.setEnabled(!formEntryPrompt.isReadOnly()); launchIntentButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(intentName); if (isActivityAvailable(i)) { try { ExternalAppsUtils.populateParameters(i, exParams, formEntryPrompt.getIndex().getReference()); FormController formController = Collect.getInstance().getFormController(); if (formController == null) { return; } formController.setIndexWaitingForData(formEntryPrompt.getIndex()); fireActivity(i); } catch (ExternalParamsException e) { Timber.e(e); onException(e.getMessage()); } } else { onException(errorString); } } private void onException(String toastText) { hasExApp = false; if (!formEntryPrompt.isReadOnly()) { answer.setBackground(textBackground); answer.setFocusable(true); answer.setFocusableInTouchMode(true); answer.setEnabled(true); } launchIntentButton.setEnabled(false); launchIntentButton.setFocusable(false); cancelWaitingForBinaryData(); Toast.makeText(getContext(), toastText, Toast.LENGTH_SHORT).show(); ExStringWidget.this.answer.requestFocus(); Timber.e(toastText); } }); // finish complex layout LinearLayout answerLayout = new LinearLayout(getContext()); answerLayout.setOrientation(LinearLayout.VERTICAL); answerLayout.addView(launchIntentButton); answerLayout.addView(answer); addAnswerView(answerLayout); }