List of usage examples for android.text InputType TYPE_CLASS_DATETIME
int TYPE_CLASS_DATETIME
To view the source code for android.text InputType TYPE_CLASS_DATETIME.
Click Source Link
From source file:Main.java
public static void autoCompleteTime(CharSequence text, EditText time, TextView timeHint) { String stringText = text.toString(); String textToBeSet = ""; int inputType = InputType.TYPE_CLASS_DATETIME | InputType.TYPE_DATETIME_VARIATION_TIME; time.setError(null); //remove any error set from previously boolean error = false; if (stringText.matches("^\\d$")) { if (stringText.equals("1") || stringText.equals("0")) textToBeSet = "0:00AM"; else {//from ww w. j av a 2 s . c o m textToBeSet = ":00AM"; } } else if (stringText.matches("^\\d\\d$")) { int intText = Integer.parseInt(stringText); if (intText >= 0 && intText <= 12) textToBeSet = ":00AM"; else error = true; } else if (stringText.matches("^\\d+:$")) textToBeSet = "00AM"; else if (stringText.matches("^\\d+:\\d$")) textToBeSet = "0AM"; else if (stringText.matches("^\\d+:\\d\\d$")) { int intText = Integer.parseInt(stringText.replaceAll("^\\d+:", "")); //get minutes if (intText > 0 && intText < 60) { inputType = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; textToBeSet = "AM"; } else error = true; } else if (stringText.matches("^\\d+:\\d\\d(A|P)$")) { inputType = InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; textToBeSet = "M"; } else if (stringText.equals("")) textToBeSet = ""; else if (stringText.matches("^\\d+:\\d+(A|P)M")) { //To-do - take control to next input field } else {//error condition error = true; } if (error) { textToBeSet = ""; time.setError("Incorrect time format"); } time.setInputType(inputType); timeHint.setText(textToBeSet); }
From source file:Main.java
/** Returns true if number keyboard is preferred by EditorInfo.inputType. */ public static boolean isNumberKeyboardPreferred(int inputType) { int typeClass = inputType & InputType.TYPE_MASK_CLASS; // As of API Level 21, following condition equals to "typeClass != InputType.TYPE_CLASS_TEXT". // However type-class might be added in future so safer expression is employed here. return typeClass == InputType.TYPE_CLASS_DATETIME || typeClass == InputType.TYPE_CLASS_NUMBER || typeClass == InputType.TYPE_CLASS_PHONE; }
From source file:eu.hydrologis.geopaparazzi.maptools.FeaturePageAdapter.java
@Override public Object instantiateItem(ViewGroup container, int position) { final Feature feature = featuresList.get(position); int bgColor = context.getResources().getColor(R.color.formbgcolor); int textColor = context.getResources().getColor(R.color.formcolor); ScrollView scrollView = new ScrollView(context); ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);//from w w w . j a v a2s. co m scrollLayoutParams.setMargins(10, 10, 10, 10); scrollView.setLayoutParams(scrollLayoutParams); scrollView.setBackgroundColor(bgColor); LinearLayout linearLayoutView = new LinearLayout(context); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); int margin = 10; layoutParams.setMargins(margin, margin, margin, margin); linearLayoutView.setLayoutParams(layoutParams); linearLayoutView.setOrientation(LinearLayout.VERTICAL); int padding = 10; linearLayoutView.setPadding(padding, padding, padding, padding); scrollView.addView(linearLayoutView); List<String> attributeNames = feature.getAttributeNames(); List<String> attributeValues = feature.getAttributeValuesStrings(); List<String> attributeTypes = feature.getAttributeTypes(); for (int i = 0; i < attributeNames.size(); i++) { final String name = attributeNames.get(i); String value = attributeValues.get(i); String typeString = attributeTypes.get(i); DataType type = DataType.getType4Name(typeString); TextView textView = new TextView(context); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); textView.setPadding(padding, padding, padding, padding); textView.setText(name); textView.setTextColor(textColor); // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium); linearLayoutView.addView(textView); final EditText editView = new EditText(context); LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); editViewParams.setMargins(margin, 0, margin, 0); editView.setLayoutParams(editViewParams); editView.setPadding(padding * 2, padding, padding * 2, padding); editView.setText(value); // editView.setEnabled(!isReadOnly); editView.setFocusable(!isReadOnly); // editView.setTextAppearance(context, android.R.style.TextAppearance_Medium); if (isReadOnly) { editView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { String text = editView.getText().toString(); FeatureUtilities.viewIfApplicable(v.getContext(), text); return false; } }); } switch (type) { case DOUBLE: case FLOAT: editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); break; case PHONE: editView.setInputType(InputType.TYPE_CLASS_PHONE); break; case DATE: editView.setInputType(InputType.TYPE_CLASS_DATETIME); break; case INTEGER: editView.setInputType(InputType.TYPE_CLASS_NUMBER); break; default: break; } editView.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { // ignore } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // ignore } public void afterTextChanged(Editable s) { String text = editView.getText().toString(); feature.setAttribute(name, text); } }); linearLayoutView.addView(editView); } /* * add also area and length */ if (feature.getOriginalArea() > -1) { TextView areaTextView = new TextView(context); areaTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); areaTextView.setPadding(padding, padding, padding, padding); areaTextView.setText("Area: " + areaLengthFormatter.format(feature.getOriginalArea())); areaTextView.setTextColor(textColor); TextView lengthTextView = new TextView(context); lengthTextView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); lengthTextView.setPadding(padding, padding, padding, padding); lengthTextView.setText("Length: " + areaLengthFormatter.format(feature.getOriginalLength())); lengthTextView.setTextColor(textColor); linearLayoutView.addView(areaTextView); linearLayoutView.addView(lengthTextView); } container.addView(scrollView); return scrollView; }
From source file:pl.wasat.smarthma.ui.frags.base.BaseCollectionDetailsFragment.java
private AutoCompleteTextView resolvePattern(AutoCompleteTextView autoTextView, String pattern) { if (pattern == null) { autoTextView.setInputType(InputType.TYPE_CLASS_TEXT); return autoTextView; } else if (pattern.equalsIgnoreCase("[0-9]+")) { autoTextView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); return autoTextView; } else if (pattern.equalsIgnoreCase( "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?(Z|[\\+\\-][0-9]{2}:[0-9]{2})$")) { autoTextView.setInputType(InputType.TYPE_CLASS_DATETIME); return autoTextView; } else if (pattern.equalsIgnoreCase( "(\\[|\\])(100|[0-9]\\d?),(100|[0-9]\\d?)(\\[|\\])|(\\[|\\])?(100|[0-9]\\d?)|(100|[0-9]\\d?)(\\[|\\])?|\\{(100|[0-9]\\d?),(100|[0-9]\\d?)\\}")) { //autoTextView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); autoTextView.setKeyListener(new PatternNumberKeyListener()); return autoTextView; } else if (pattern.equalsIgnoreCase( "(\\[|\\])[0-9]+,[0-9]+(\\[|\\])|(\\[|\\])?[0-9]+|[0-9]+(\\[|\\])?|\\{[0-9]+,[0-9]+\\}")) { autoTextView.setKeyListener(new PatternNumberKeyListener()); return autoTextView; } else if (pattern.equalsIgnoreCase( "(\\[|\\])[0-9]+(.[0-9]+)?,[0-9]+(.[0-9]+)?(\\[|\\])|(\\[|\\])?[0-9]+(.[0-9]+)?|[0-9]+(.[0-9]+)?(\\[|\\])?|\\{[0-9]+(.[0-9]+)?,[0-9]+(.[0-9]+)?\\}")) { autoTextView.setKeyListener(new PatternNumberKeyListener()); return autoTextView; } else if (pattern.equalsIgnoreCase( "(\\[|\\])[0-9]+,[0-9]+(\\[|\\])|(\\[|\\])?[0-9]+|[0-9]+(\\[|\\])?|\\{[0-9]+,[0-9]+\\}")) { autoTextView.setKeyListener(new PatternNumberKeyListener()); return autoTextView; }// w w w.ja va 2s . c o m return autoTextView; }
From source file:eu.geopaparazzi.core.maptools.FeaturePageAdapter.java
private TextView getEditView(final Feature feature, final String fieldName, EDataType type, String value) { final TextView editView; switch (type) { case DATE://from w ww. jav a 2 s .com editView = new TextView(context); editView.setInputType(InputType.TYPE_CLASS_DATETIME); editView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FeaturePageAdapter.this.openDatePicker((EditText) view); } }); if (value == null || value.equals("")) { value = "____-__-__"; } break; default: editView = new EditText(context); break; } editView.setText(value); switch (type) { case DOUBLE: case FLOAT: editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); break; case PHONE: editView.setInputType(InputType.TYPE_CLASS_PHONE); break; case DATE: editView.setInputType(InputType.TYPE_CLASS_DATETIME); editView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { FeaturePageAdapter.this.openDatePicker((TextView) view); } }); break; case INTEGER: editView.setInputType(InputType.TYPE_CLASS_NUMBER); break; default: break; } editView.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { // ignore } public void beforeTextChanged(CharSequence s, int start, int count, int after) { // ignore } public void afterTextChanged(Editable s) { String text = editView.getText().toString(); feature.setAttribute(fieldName, text); } }); return editView; }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
/** * This is the main point where we do our initialization of the input method * to begin operating on an application. At this point we have been * bound to the client, and are now receiving all of the detailed information * about the target of our edits./* w w w. j a v a 2s.c o m*/ */ @Override public void onStartInput(EditorInfo attribute, boolean restarting) { super.onStartInput(attribute, restarting); // Reset our state. We want to do this even if restarting, because // the underlying state of the text editor could have changed in any way. mComposing.setLength(0); updateCandidates(); if (!restarting) { // Clear shift states. mMetaState = 0; } mPredictionOn = false; mCompletionOn = false; mCompletions = null; // We are now going to initialize our state based on the type of // text being edited. switch (attribute.inputType & InputType.TYPE_MASK_CLASS) { case InputType.TYPE_CLASS_NUMBER: case InputType.TYPE_CLASS_DATETIME: // Numbers and dates default to the symbols keyboard, with // no extra features. mCurKeyboard = mSymbolsKeyboard; break; case InputType.TYPE_CLASS_PHONE: // Phones will also default to the symbols keyboard, though // often you will want to have a dedicated phone keyboard. mCurKeyboard = mSymbolsKeyboard; break; case InputType.TYPE_CLASS_TEXT: // This is general text editing. We will default to the // normal alphabetic keyboard, and assume that we should // be doing predictive text (showing candidates as the // user types). mCurKeyboard = mQwertyKeyboard; mPredictionOn = true; //mPredictionOn = false; // We now look for a few special variations of text that will // modify our behavior. int variation = attribute.inputType & InputType.TYPE_MASK_VARIATION; if (variation == InputType.TYPE_TEXT_VARIATION_PASSWORD || variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) { // Do not display predictions / what the user is typing // when they are entering a password. mPredictionOn = false; } if (variation == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS || variation == InputType.TYPE_TEXT_VARIATION_URI || variation == InputType.TYPE_TEXT_VARIATION_FILTER) { // Our predictions are not useful for e-mail addresses // or URIs. mPredictionOn = false; } if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) { // If this is an auto-complete text view, then our predictions // will not be shown and instead we will allow the editor // to supply their own. We only show the editor's // candidates when in fullscreen mode, otherwise relying // own it displaying its own UI. mPredictionOn = false; mCompletionOn = isFullscreenMode(); } // We also want to look at the current state of the editor // to decide whether our alphabetic keyboard should start out // shifted. updateShiftKeyState(attribute); break; default: // For all unknown input types, default to the alphabetic // keyboard with no special features. mCurKeyboard = mQwertyKeyboard; updateShiftKeyState(attribute); } // Update the label on the enter key, depending on what the application // says it will do. mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions); }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates an edit text/*w ww . j a v a 2 s .c o m*/ * * @param open311Attribute contains the open311 attributes */ private void createEditText(Open311Attribute open311Attribute) { LayoutInflater inflater = LayoutInflater.from(getActivity()); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_text_item, null, false); ImageView icon = ((ImageView) layout.findViewById(R.id.ri_ic_question_answer)); icon.setColorFilter(getResources().getColor(R.color.material_gray)); Spannable desc = new SpannableString(MyTextUtils.toSentenceCase(open311Attribute.getDescription())); EditText editText = ((EditText) layout.findViewById(R.id.riti_editText)); if (open311Attribute.getRequired()) { Spannable req = new SpannableString("(required)"); req.setSpan(new ForegroundColorSpan(Color.RED), 0, req.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); editText.setHint(TextUtils.concat(desc, " ", req)); } else { editText.setHint(desc); } if (Open311DataType.NUMBER.equals(open311Attribute.getDatatype())) { editText.setInputType(InputType.TYPE_CLASS_NUMBER); } else if (Open311DataType.DATETIME.equals(open311Attribute.getDatatype())) { editText.setInputType(InputType.TYPE_CLASS_DATETIME); } // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); if (av != null) { editText.setText(av.getSingleValue()); } // Dynamically fill stop id if this is a transit service // And if this is a bus stop field if (ServiceUtils.isTransitServiceByType(mService.getType()) && ServiceUtils.isStopIdField(open311Attribute.getDescription())) { icon.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ri_flag_triangle)); ObaStop obaStop = getIssueLocationHelper().getObaStop(); if (obaStop != null) { editText.setText(obaStop.getStopCode()); } } mInfoLayout.addView(layout); mDynamicAttributeUIMap.put(open311Attribute.getCode(), editText); }