/** @see Widget.getProperty. */ @Override public String getProperty(String property) { TextView textView = (TextView) getView(); if (property.equals(IX_WIDGET.MAW_LABEL_TEXT)) { if (textView.getText() != null && textView.getText().length() > 0) { return textView.getText().toString(); } else if (textView.getHint() != null && textView.getText().length() > 0) { return textView.getHint().toString(); } else { return ""; } } else if (property.equals(IX_WIDGET.MAW_LABEL_MAX_NUMBER_OF_LINES)) { // If max number lines was not set, will return the default 0. return Integer.toString(m_maxNrLines); } else { return super.getProperty(property); } }
private void initData() { Calendar cal = Calendar.getInstance(); entreprise.setText(null); post.setText(null); yearStart.setText(String.valueOf(cal.get(Calendar.YEAR))); yearEnd.setText(yearEnd.getHint().toString()); deleteWork.setOnClickListener(new deleteClick(this)); backLayout.setOnClickListener(new backClick(this)); yearStart.setOnClickListener(new SelectStartYear(this)); yearEnd.setOnClickListener(new SelectEndYear(this)); }
/** * Checks if a View matches a certain string and returns the amount of total matches. * * @param regex the regex to match * @param view the view to check * @param uniqueTextViews set of views that have matched * @return number of total matches */ public static int getNumberOfMatches(String regex, TextView view, Set<TextView> uniqueTextViews) { if (view == null) { return uniqueTextViews.size(); } Pattern pattern = null; try { pattern = Pattern.compile(regex); } catch (PatternSyntaxException e) { pattern = Pattern.compile(regex, Pattern.LITERAL); } String viewText = view.getText().toString(); viewText = viewText.replaceAll("[\n\r]", " "); Matcher matcher = pattern.matcher(viewText); if (!matcher.find()) { regex = regex.replaceAll("[\n\r]", " "); matcher = Pattern.compile(regex).matcher(viewText); } if (matcher.find(0)) { uniqueTextViews.add(view); } if (view.getError() != null) { matcher = pattern.matcher(view.getError().toString()); if (matcher.find()) { uniqueTextViews.add(view); } } if (view.getText().toString().equals("") && view.getHint() != null) { matcher = pattern.matcher(view.getHint().toString()); if (matcher.find()) { uniqueTextViews.add(view); } } return uniqueTextViews.size(); }
private void init(Context context, AttributeSet attrs, int defStyle) { // Load custom attributes final int layout; final CharSequence text; final CharSequence hint; final ColorStateList hintColor; final int inputType; final int imeOptions; if (attrs == null) { layout = R.layout.float_label; text = null; hint = null; hintColor = null; inputType = EditorInfo.TYPE_CLASS_TEXT; imeOptions = EditorInfo.IME_ACTION_UNSPECIFIED; } else { final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabel, defStyle, 0); layout = a.getResourceId(R.styleable.FloatLabel_android_layout, R.layout.float_label); text = a.getText(R.styleable.FloatLabel_android_text); hint = a.getText(R.styleable.FloatLabel_android_hint); hintColor = a.getColorStateList(R.styleable.FloatLabel_android_textColorHint); inputType = a.getInt(R.styleable.FloatLabel_android_inputType, EditorInfo.TYPE_CLASS_TEXT); imeOptions = a.getInt(R.styleable.FloatLabel_android_imeOptions, EditorInfo.IME_ACTION_UNSPECIFIED); a.recycle(); } inflate(context, layout, this); mEditText = (TextView) findViewById(R.id.edit_text); if (mEditText == null) { throw new RuntimeException("Your layout must have an EditText whose ID is @id/edit_text"); } mEditText.setHint(hint); mEditText.setText(text); if (hintColor != null) { mEditText.setHintTextColor(hintColor); } mEditText.setInputType(inputType); mEditText.setImeOptions(imeOptions); mLabel = (TextView) findViewById(R.id.float_label); if (mLabel == null) { throw new RuntimeException("Your layout must have a TextView whose ID is @id/float_label"); } mLabel.setText(mEditText.getHint()); // Listen to EditText to know when it is empty or nonempty mEditText.addTextChangedListener(new EditTextWatcher()); // Check current state of EditText if (mEditText.getText().length() == 0) { mLabel.setAlpha(0); mLabelShowing = false; } else { mLabel.setVisibility(View.VISIBLE); mLabelShowing = true; } // Mark init as complete to prevent accidentally breaking the view by // adding children mInitComplete = true; }