android.widget.EditText#addTextChangedListener ( )源码实例Demo

下面列出了android.widget.EditText#addTextChangedListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ploggy   文件: ActivityGenerateSelf.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_generate_self);

    mAvatarImage = (ImageView)findViewById(R.id.generate_self_avatar_image);
    mAvatarImage.setImageResource(R.drawable.ic_unknown_avatar);
    mNicknameEdit = (EditText)findViewById(R.id.generate_self_nickname_edit);
    mNicknameEdit.addTextChangedListener(getNicknameTextChangedListener());
    mNicknameEdit.setEnabled(false);
    mFingerprintText = (TextView)findViewById(R.id.generate_self_fingerprint_text);
    mRegenerateButton = (Button)findViewById(R.id.generate_self_regenerate_button);
    mRegenerateButton.setEnabled(false);
    mRegenerateButton.setVisibility(View.GONE);
    mRegenerateButton.setOnClickListener(this);
    mSaveButton = (Button)findViewById(R.id.generate_self_save_button);
    mSaveButton.setEnabled(false);
    mSaveButton.setVisibility(View.GONE);
    mSaveButton.setOnClickListener(this);
    mProgressDialog = new ProgressDialog(this);
    mProgressDialog.setMessage(getText(R.string.prompt_generate_self_progress));
    mProgressDialog.setCancelable(false);
    mAvatarTimer = new Timer();
}
 
源代码2 项目: Klyph   文件: PlacePickerFragment.java
@Override
void setupViews(ViewGroup view) {
    if (showSearchBox) {
        ListView listView = (ListView) view.findViewById(R.id.com_facebook_picker_list_view);

        View searchHeaderView = getActivity().getLayoutInflater().inflate(
                R.layout.com_facebook_picker_search_box, listView, false);

        listView.addHeaderView(searchHeaderView, null, false);

        searchBox = (EditText) view.findViewById(R.id.com_facebook_picker_search_text);

        searchBox.addTextChangedListener(new SearchTextWatcher());
        if (!TextUtils.isEmpty(searchText)) {
            searchBox.setText(searchText);
        }
    }
}
 
源代码3 项目: AndroidChromium   文件: HomepageEditor.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mHomepageManager = HomepageManager.getInstance(getActivity());
    getActivity().setTitle(R.string.options_homepage_edit_title);
    View v = inflater.inflate(R.layout.homepage_editor, container, false);

    FloatLabelLayout homepageUrl = (FloatLabelLayout) v.findViewById(R.id.homepage_url);
    homepageUrl.focusWithoutAnimation();

    mHomepageUrlEdit = (EditText) v.findViewById(R.id.homepage_url_edit);
    mHomepageUrlEdit.setText((mHomepageManager.getPrefHomepageUseDefaultUri()
            ? PartnerBrowserCustomizations.getHomePageUrl()
            : mHomepageManager.getPrefHomepageCustomUri()));
    mHomepageUrlEdit.addTextChangedListener(this);

    initializeSaveCancelResetButtons(v);
    return v;
}
 
private void initView() {
    findViewById(R.id.ibtn_back).setOnClickListener(new IBackClickListener());
    imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
    etAddress = (EditText) findViewById(R.id.et_address);
    etMessage = (EditText) findViewById(R.id.et_message);
    etSignature = (EditText) findViewById(R.id.et_signature);
    btnQrAddress = (Button) findViewById(R.id.btn_qr_address);
    btnQrMessage = (Button) findViewById(R.id.btn_qr_message);
    btnQrSignature = (Button) findViewById(R.id.btn_qr_signature);
    btnVerify = (Button) findViewById(R.id.btn_verify);
    pb = (ProgressBar) findViewById(R.id.pb_verify);
    ivVerifyFailed = (ImageView) findViewById(R.id.iv_verify_failed);
    ivVerifySuccess = (ImageView) findViewById(R.id.iv_verify_success);
    btnQrAddress.setOnClickListener(qrClick);
    btnQrMessage.setOnClickListener(qrClick);
    btnQrSignature.setOnClickListener(qrClick);
    btnVerify.setOnClickListener(verifyClick);
    etAddress.addTextChangedListener(textWatcher);
    etMessage.addTextChangedListener(textWatcher);
    etSignature.addTextChangedListener(textWatcher);
}
 
源代码5 项目: CreditCardView   文件: CardCVVFragment.java
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle state) {
    View v = inflater.inflate(R.layout.lyt_card_cvv, group, false);
    mCardCVVView = (EditText) v.findViewById(R.id.card_cvv);

    String cvv = null;
    if (getArguments() != null && getArguments().containsKey(EXTRA_CARD_CVV)) {
        cvv = getArguments().getString(EXTRA_CARD_CVV);
    }

    if (cvv == null) {
        cvv = "";
    }

    mCardCVVView.setText(cvv);
    mCardCVVView.addTextChangedListener(this);

    return v;
}
 
private void buildUi() {
    LinearLayout scrollView = findViewById(R.id.levels);

    for (final AudioType type : AudioType.getAudioTypes(isExtendedVolumesEnabled())) {
        final VolumeSliderView volumeSliderView = new VolumeSliderView(this);
        scrollView.addView(volumeSliderView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        volumeSliderView.setVolumeName(getString(type.nameId));
        volumeSliderView.setMaxVolume(control.getMaxLevel(type.audioStreamName));
        volumeSliderView.setMinVolume(control.getMinLevel(type.audioStreamName));
        if (!volumes.containsKey(type.audioStreamName)) {
            int currentVolume = control.getLevel(type.audioStreamName);
            volumeSliderView.setCurrentVolume(currentVolume, false);
            volumes.put(type.audioStreamName, currentVolume);
        } else {
            volumeSliderView.setCurrentVolume(volumes.get(type.audioStreamName), false);
        }

        volumeSliderView.setListener((volume, fromUser) -> {
            if (fromUser) {
                volumes.put(type.audioStreamName, volume);
                volumeSliderView.updateProgressText(volume);
            }
        });


        EditText t = findViewById(R.id.profile_name);
        t.setText(name);
        t.addTextChangedListener(textWatcher);

        findViewById(R.id.save_button).setOnClickListener(v -> requiredSave());
    }
}
 
源代码7 项目: AndroidLinkup   文件: ContactsPage.java
private void initView() {
    int resId = getIdRes(activity, "clContact");
    if (resId > 0) {
        listView = (ContactsListView) activity.findViewById(resId);
    }
    resId = getIdRes(activity, "ll_back");
    if (resId > 0) {
        activity.findViewById(resId).setOnClickListener(this);
    }
    resId = getIdRes(activity, "ivSearch");
    if (resId > 0) {
        activity.findViewById(resId).setOnClickListener(this);
    }
    resId = getIdRes(activity, "iv_clear");
    if (resId > 0) {
        activity.findViewById(resId).setOnClickListener(this);
    }
    resId = getIdRes(activity, "tv_title");
    if (resId > 0) {
        TextView tv = (TextView) activity.findViewById(resId);
        resId = getStringRes(activity, "smssdk_search_contact");
        if (resId > 0) {
            tv.setText(resId);
        }
    }
    resId = getIdRes(activity, "et_put_identify");
    if (resId > 0) {
        etSearch = (EditText) activity.findViewById(resId);
        etSearch.addTextChangedListener(this);
    }
}
 
源代码8 项目: mollyim-android   文件: BackupDialog.java
public static void showVerifyBackupPassphraseDialog(@NonNull Context context) {
  View        view   = LayoutInflater.from(context).inflate(R.layout.enter_backup_passphrase_dialog, null);
  EditText    prompt = view.findViewById(R.id.restore_passphrase_input);
  AlertDialog dialog = new AlertDialog.Builder(context)
                                      .setTitle(R.string.BackupDialog_enter_backup_passphrase_to_verify)
                                      .setView(view)
                                      .setPositiveButton(R.string.BackupDialog_verify, null)
                                      .setNegativeButton(android.R.string.cancel, null)
                                      .show();

  Button positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
  positiveButton.setEnabled(false);

  RestoreBackupFragment.PassphraseAsYouTypeFormatter formatter = new RestoreBackupFragment.PassphraseAsYouTypeFormatter();

  prompt.addTextChangedListener(new AfterTextChanged(editable -> {
      formatter.afterTextChanged(editable);
      positiveButton.setEnabled(editable.length() == BackupUtil.PASSPHRASE_LENGTH);
    }));

  positiveButton.setOnClickListener(v -> {
                                      String passphrase = prompt.getText().toString();
                                      if (passphrase.equals(BackupPassphrase.get(context))) {
                                        Toast.makeText(context, R.string.BackupDialog_you_successfully_entered_your_backup_passphrase, Toast.LENGTH_SHORT).show();
                                        dialog.dismiss();
                                      } else {
                                        Toast.makeText(context, R.string.BackupDialog_passphrase_was_not_correct, Toast.LENGTH_SHORT).show();
                                      }
                                    });
}
 
@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    ViewGroup view = (ViewGroup) getView();
    if (showSearchBox) {
        ViewStub stub = (ViewStub) view.findViewById(R.id.com_facebook_placepickerfragment_search_box_stub);
        if (stub != null) {
            searchBox = (EditText) stub.inflate();

            // Put the list under the search box
            RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.FILL_PARENT,
                    RelativeLayout.LayoutParams.FILL_PARENT);
            layoutParams.addRule(RelativeLayout.BELOW, R.id.search_box);

            ListView listView = (ListView) view.findViewById(R.id.com_facebook_picker_list_view);
            listView.setLayoutParams(layoutParams);

            // If we need to, put the search box under the title bar.
            if (view.findViewById(R.id.com_facebook_picker_title_bar) != null) {
                layoutParams = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.FILL_PARENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
                layoutParams.addRule(RelativeLayout.BELOW, R.id.com_facebook_picker_title_bar);

                searchBox.setLayoutParams(layoutParams);
            }

            searchBox.addTextChangedListener(new SearchTextWatcher());
            if (!TextUtils.isEmpty(searchText)) {
                searchBox.setText(searchText);
            }
        }
    }
}
 
@Override
public View buildOptionsView(final ActiveBundle activeBundle, Context context) {
  @SuppressLint("InflateParams")
  final View inflated = LayoutInflater.from(context).inflate(R.layout.frequency_options, null);

  if (additionalPresenter != null) {
    final ViewGroup additionalView = (ViewGroup) inflated.findViewById(R.id.additional_options);
    additionalView.setVisibility(View.VISIBLE);
    additionalView.addView(additionalPresenter.buildOptionsView(activeBundle, context));
  }

  final EditText windowEditText = getWindowEditText(inflated);
  final ReadableSensorOptions roBundle = activeBundle.getReadOnly();
  windowEditText.setText(String.valueOf(getFrequencyWindow(roBundle)));
  windowEditText.addTextChangedListener(
      new LongUpdatingWatcher(activeBundle, PREFS_KEY_FREQUENCY_WINDOW, windowEditText));

  final EditText filterEditText = getFilterEditText(inflated);
  filterEditText.setText(String.valueOf(getFrequencyFilter(roBundle)));
  filterEditText.addTextChangedListener(
      new FloatUpdatingWatcher(activeBundle, PREFS_KEY_FREQUENCY_FILTER, filterEditText));

  CheckBox enableFrequencyBox = getFrequencyCheckbox(inflated);
  enableFrequencyBox.setChecked(getFrequencyChecked(roBundle));
  enableFrequencyBox.setOnCheckedChangeListener(
      new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          activeBundle.changeBoolean(PREFS_KEY_FREQUENCY_ENABLED, isChecked);
        }
      });

  return inflated;
}
 
源代码11 项目: BigApp_WordPress_Android   文件: EditPage.java
private LinearLayout getMainBody() {
	LinearLayout llMainBody = new LinearLayout(getContext());
	llMainBody.setOrientation(LinearLayout.VERTICAL);
	LayoutParams lpMain = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpMain.weight = 1;
	int dp_4 = dipToPx(getContext(), 4);
	lpMain.setMargins(dp_4, dp_4, dp_4, dp_4);
	llMainBody.setLayoutParams(lpMain);

	LinearLayout llContent = new LinearLayout(getContext());
	LayoutParams lpContent = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	lpContent.weight = 1;
	llMainBody.addView(llContent, lpContent);

	// share content editor
	etContent = new EditText(getContext());
	etContent.setGravity(Gravity.LEFT | Gravity.TOP);
	etContent.setBackgroundDrawable(null);
	etContent.setText(String.valueOf(shareParamMap.get("text")));
	etContent.addTextChangedListener(this);
	LayoutParams lpEt = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpEt.weight = 1;
	etContent.setLayoutParams(lpEt);
	llContent.addView(etContent);

	llContent.addView(getThumbView());
	llMainBody.addView(getBodyBottom());

	return llMainBody;
}
 
源代码12 项目: WayHoo   文件: QueryCityActivity.java
private void initViews() {
	mInflater = LayoutInflater.from(this);
	mRootView = (RelativeLayout) findViewById(R.id.city_add_bg);
	mBackBtn = (ImageView) findViewById(R.id.back_image);
	mLocationTV = (TextView) findViewById(R.id.location_text);
	mQueryCityET = (EditText) findViewById(R.id.queryCityText);
	mQueryCityExitBtn = (ImageButton) findViewById(R.id.queryCityExit);

	mQueryCityListView = (ListView) findViewById(R.id.cityList);
	mQueryCityListView.setOnItemClickListener(this);
	mSearchCityAdapter = new QueryCityAdapter(QueryCityActivity.this,
			mCities);
	mQueryCityListView.setAdapter(mSearchCityAdapter);
	mQueryCityListView.setTextFilterEnabled(true);
	mFilter = mSearchCityAdapter.getFilter();

	// mEmptyCityView = (TextView) findViewById(R.id.noCityText);

	mHotCityGridView = (GridView) findViewById(R.id.hotCityGrid);
	mHotCityGridView.setOnItemClickListener(this);
	mHotCityGridView.setAdapter(new HotCityAdapter());

	mBackBtn.setOnClickListener(this);
	mLocationTV.setOnClickListener(this);
	mQueryCityExitBtn.setOnClickListener(this);
	mQueryCityET.addTextChangedListener(this);

	String cityName = getCityName();
	if (TextUtils.isEmpty(cityName)) {
		startLocation(mCityNameStatus);
	} else {
		mLocationTV.setText(formatBigMessage(cityName));
	}
}
 
源代码13 项目: GithubApp   文件: EditPageLand.java
private void initBody(RelativeLayout rlBody, float ratio) {
	svContent = new ScrollView(activity);
	rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	LinearLayout llContent = new LinearLayout(activity);
	llContent.setOrientation(LinearLayout.HORIZONTAL);
	svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	etContent = new EditText(activity);
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	etContent.setPadding(padding, padding, padding, padding);
	etContent.setBackgroundDrawable(null);
	etContent.setTextColor(0xff3b3b3b);
	etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	etContent.setText(sp.getText());
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT);
	lp.weight = 1;
	llContent.addView(etContent, lp);
	etContent.addTextChangedListener(this);

	rlThumb = new RelativeLayout(activity);
	rlThumb.setBackgroundColor(0xff313131);
	int	thumbWidth = (int) (DESIGN_THUMB_HEIGHT_L * ratio);
	int	xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT_L * ratio);
	lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth);
	lp.rightMargin = lp.bottomMargin = lp.topMargin = padding;
	llContent.addView(rlThumb, lp);

	aivThumb = new AsyncImageView(activity) {
		public void onImageGot(String url, Bitmap bm) {
			thumb = bm;
			super.onImageGot(url, bm);
		}
	};
	aivThumb.setScaleToCropCenter(true);
	RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth);
	rlThumb.addView(aivThumb, rllp);
	aivThumb.setOnClickListener(this);
	initThumb(aivThumb);

	xvRemove = new XView(activity);
	xvRemove.setRatio(ratio);
	rllp = new RelativeLayout.LayoutParams(xWidth, xWidth);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	rlThumb.addView(xvRemove, rllp);
	xvRemove.setOnClickListener(this);
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_address);

    toolbar = (Toolbar) findViewById(R.id.toolbar1);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("Add Address");
    toolbar.setTitleTextColor(ContextCompat.getColor(context, R.color.white));

    userAddress = (UserAddress) getIntent().getSerializableExtra(Constant.ADDRESS);

    del_area = (TextView) findViewById(R.id.del_area);
    del_area_selected = (TextView) findViewById(R.id.del_area_selected);

    otherType = (LinearLayout) findViewById(R.id.otherType);
    workType = (LinearLayout) findViewById(R.id.workType);
    homeType = (LinearLayout) findViewById(R.id.homeType);

    otherText = (EditText) findViewById(R.id.otherText);
    otherTextLine = (ImageView) findViewById(R.id.otherTextLine);
    otherTextCancel = (ImageView) findViewById(R.id.otherTextCancel);

    instruction = (EditText) findViewById(R.id.instruction);
    instructionLine = (ImageView) findViewById(R.id.instructionLine);
    instructionCancel = (ImageView) findViewById(R.id.instructionCancel);

    address = (EditText) findViewById(R.id.address);
    addressLine = (ImageView) findViewById(R.id.addressLine);
    addressCancel = (ImageView) findViewById(R.id.addressCancel);

    //For Focus
    otherText.setOnFocusChangeListener(hasFocusListener);
    instruction.setOnFocusChangeListener(hasFocusListener);
    address.setOnFocusChangeListener(hasFocusListener);

    //For TextChange
    otherText.addTextChangedListener(textLengthListener);
    instruction.addTextChangedListener(textLengthListener);
    address.addTextChangedListener(textLengthListener);

    setDefaultDeliveryArea();

    if (userAddress != null) {
        setEditValues();
    }

}
 
源代码15 项目: ShoppingList   文件: AddItemShoppingList.java
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_add_item_shopping_list);

	try {
		shoppingList = ShoppingListDAO.select(this, getIntent().getExtras().getInt((getString(R.string.id_shopping_list))));
	} catch (VansException e) {
		Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
		e.printStackTrace();
	}

	this.setTitle(shoppingList.getName());

	lvItensShoppingList = (ListView) findViewById(R.id.lvItemShoppingList);
	lvItensShoppingList.setOnItemClickListener(this);
	lvItensShoppingList.setOnItemLongClickListener(this);

	headerView = (View) getLayoutInflater().inflate(R.layout.header_list_view_item_shopping_list, null);
	lvItensShoppingList.addHeaderView(headerView, null, false);

	adapter = new ItemShoppingListCursorAdapter(this, shoppingList.getId());
	lvItensShoppingList.setAdapter(adapter);

	edUnitValue = (EditText) findViewById(R.id.edUnitValue);
	edUnitValue.setVisibility(UserPreferences.getShowUnitValue(this) ? View.VISIBLE : View.GONE);
	edUnitValue.setOnKeyListener(this);
	edUnitValue.addTextChangedListener(new CustomEditTextWatcher(edUnitValue, 5));
	edUnitValue.setOnFocusChangeListener(this);

	edQuantity = (EditText) findViewById(R.id.edQuantity);
	edQuantity.addTextChangedListener(new CustomEditTextWatcher(edQuantity, 4));
	edQuantity.setVisibility(UserPreferences.getShowQuantity(this) ? View.VISIBLE : View.GONE);
	edQuantity.setOnFocusChangeListener(this);

	edDescription = (AutoCompleteTextView) findViewById(R.id.edDescription);
	edDescription.setOnItemClickListener(this);
	edDescription.addTextChangedListener(new CustomEditTextWatcher(edDescription, -1));

	if ((!UserPreferences.getShowQuantity(this)) && (!UserPreferences.getShowUnitValue(this))) {
		edDescription.setImeOptions(EditorInfo.IME_ACTION_GO);
		edDescription.setOnKeyListener(this);
	} else if (!UserPreferences.getShowUnitValue(this)) {
		edQuantity.setImeOptions(EditorInfo.IME_ACTION_GO);
		edQuantity.setOnKeyListener(this);
	}

}
 
源代码16 项目: three-things-today   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FirebaseAuth.getInstance().addAuthStateListener(new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            // Required to update the sign-in/sign-out menu item.
            invalidateOptionsMenu();
        }
    });

    mThreeThingsDatabase = new ThreeThingsDatabase(getApplicationContext());

    AlarmSetter.setDailyAlarm(this);

    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    EditText firstThingEditText = (EditText) findViewById(R.id.first_edit_text);
    EditText secondThingEditText = (EditText) findViewById(R.id.second_edit_text);
    EditText thirdThingEditText = (EditText) findViewById(R.id.third_edit_text);

    firstThingEditText.setOnFocusChangeListener(this);
    secondThingEditText.setOnFocusChangeListener(this);
    thirdThingEditText.setOnFocusChangeListener(this);

    firstThingEditText.addTextChangedListener(this);
    secondThingEditText.addTextChangedListener(this);
    thirdThingEditText.addTextChangedListener(this);

    // Default to the current date.
    final Calendar c = Calendar.getInstance();
    mSelectedYear = c.get(Calendar.YEAR);
    mSelectedMonth = c.get(Calendar.MONTH);
    mSelectedDayOfMonth = c.get(Calendar.DAY_OF_MONTH);

    updateDateText();

    updateThreeThingsText();
}
 
源代码17 项目: Walrus   文件: OpaqueElement.java
OpaqueComponent(Context context, BigInteger value, boolean hex, boolean editable) {
    super(context, name);

    this.hex = hex;
    this.editable = editable;

    if (editable) {
        final EditText editText = new EditText(context);
        view = editText;

        if (!hex) {
            editText.setInputType(InputType.TYPE_CLASS_NUMBER);
        }

        editText.addTextChangedListener(new UIUtils.TextChangeWatcher() {
            @Override
            public void onNotIgnoredTextChanged(CharSequence s, int start, int before,
                    int count) {
                @StringRes Integer errorId = validateEditTextString();

                editText.setError(errorId != null ? view.getContext().getString(errorId) :
                        null);

                if (OpaqueComponent.this.onComponentChangeCallback != null) {
                    OpaqueComponent.this.onComponentChangeCallback
                            .onComponentChange(OpaqueComponent.this);
                }
            }
        });
    } else {
        TextView textView = new TextView(context);
        view = textView;

        int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
                context.getResources().getDisplayMetrics());
        textView.setPadding(padding, padding, padding, 0);
        textView.setTextAppearance(context, android.R.style.TextAppearance_Widget_EditText);
    }

    String text = value != null ? extractValue(value).toString(hex ? 16 : 10) : "";
    if (editable) {
        ((EditText) view).setText(text);
    } else {
        ((TextView) view).setText(text);
    }
}
 
@Override
public View onCreateTextInputView(
    @NonNull LayoutInflater layoutInflater,
    @Nullable ViewGroup viewGroup,
    @Nullable Bundle bundle,
    CalendarConstraints constraints,
    final @NonNull OnSelectionChangedListener<Long> listener) {
  View root = layoutInflater.inflate(R.layout.mtrl_picker_text_input_date, viewGroup, false);

  TextInputLayout dateTextInput = root.findViewById(R.id.mtrl_picker_text_input_date);
  EditText dateEditText = dateTextInput.getEditText();
  if (ManufacturerUtils.isDateInputKeyboardMissingSeparatorCharacters()) {
    // Using the URI variation places the '/' and '.' in more prominent positions
    dateEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI);
  }
  SimpleDateFormat format = UtcDates.getTextInputFormat();
  String formatHint = UtcDates.getTextInputHint(root.getResources(), format);

  if (selectedItem != null) {
    dateEditText.setText(format.format(selectedItem));
  }

  dateEditText.addTextChangedListener(
      new DateFormatTextWatcher(formatHint, format, dateTextInput, constraints) {

        @Override
        void onValidDate(@Nullable Long day) {
          if (day == null) {
            clearSelection();
          } else {
            select(day);
          }
          listener.onSelectionChanged(getSelection());
        }

        @Override
        void onInvalidDate() {
          listener.onIncompleteSelectionChanged();
        }
      });

  ViewUtils.requestFocusAndShowKeyboard(dateEditText);

  return root;
}
 
源代码19 项目: Social   文件: EditPagePort.java
private void initBody(RelativeLayout rlBody, float ratio) {
	svContent = new ScrollView(activity);
	rlBody.addView(svContent, new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	LinearLayout llContent = new LinearLayout(activity);
	llContent.setOrientation(LinearLayout.VERTICAL);
	svContent.addView(llContent, new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

	etContent = new EditText(activity);
	int padding = (int) (DESIGN_LEFT_PADDING * ratio);
	etContent.setPadding(padding, padding, padding, padding);
	etContent.setBackgroundDrawable(null);
	etContent.setTextColor(0xff3b3b3b);
	etContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 21);
	etContent.setText(sp.getText());
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	llContent.addView(etContent, lp);
	etContent.addTextChangedListener(this);

	rlThumb = new RelativeLayout(activity);
	rlThumb.setBackgroundColor(0xff313131);
	int	thumbWidth = (int) (DESIGN_THUMB_HEIGHT * ratio);
	int	xWidth = (int) (DESIGN_REMOVE_THUMB_HEIGHT * ratio);
	lp = new LinearLayout.LayoutParams(thumbWidth, thumbWidth);
	lp.leftMargin = lp.rightMargin = lp.bottomMargin = lp.topMargin = padding;
	llContent.addView(rlThumb, lp);

	aivThumb = new AsyncImageView(activity) {
		public void onImageGot(String url, Bitmap bm) {
			thumb = bm;
			super.onImageGot(url, bm);
		}
	};
	aivThumb.setScaleToCropCenter(true);
	RelativeLayout.LayoutParams rllp = new RelativeLayout.LayoutParams(thumbWidth, thumbWidth);
	rlThumb.addView(aivThumb, rllp);
	aivThumb.setOnClickListener(this);
	initThumb(aivThumb);

	xvRemove = new XView(activity);
	xvRemove.setRatio(ratio);
	rllp = new RelativeLayout.LayoutParams(xWidth, xWidth);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
	rllp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	rlThumb.addView(xvRemove, rllp);
	xvRemove.setOnClickListener(this);
}
 
源代码20 项目: mobile-manager-tool   文件: PlaylistDialog.java
@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    setContentView(new LinearLayout(this));

    action = getIntent().getAction();

    mRenameId = icicle != null ? icicle.getLong(INTENT_KEY_RENAME) : getIntent().getLongExtra(
            INTENT_KEY_RENAME, -1);
    mList = icicle != null ? icicle.getLongArray(INTENT_PLAYLIST_LIST) : getIntent()
            .getLongArrayExtra(INTENT_PLAYLIST_LIST);
    if (INTENT_RENAME_PLAYLIST.equals(action)) {
        mOriginalName = nameForId(mRenameId);
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME)
                : mOriginalName;
    } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME)
                : makePlaylistName();
        mOriginalName = mDefaultName;
    }

    DisplayMetrics dm = new DisplayMetrics();
    dm = getResources().getDisplayMetrics();

    mPlaylistDialog = new AlertDialog.Builder(this).create();
    mPlaylistDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (action != null && mRenameId >= 0 && mOriginalName != null || mDefaultName != null) {

        mPlaylist = new EditText(this);
        mPlaylist.setSingleLine(true);
        mPlaylist.setText(mDefaultName);
        mPlaylist.setSelection(mDefaultName.length());
        mPlaylist.addTextChangedListener(this);

        mPlaylistDialog.setIcon(android.R.drawable.ic_dialog_info);
        String promptformat;
        String prompt = "";
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.rename_playlist);
            prompt = String.format(promptformat, mOriginalName, mDefaultName);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.new_playlist);
            prompt = String.format(promptformat, mDefaultName);
        }

        mPlaylistDialog.setTitle(prompt);
        mPlaylistDialog.setView(mPlaylist, (int)(8 * dm.density), (int)(8 * dm.density),
                (int)(8 * dm.density), (int)(4 * dm.density));
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mRenamePlaylistListener);
            mPlaylistDialog.setOnShowListener(this);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mCreatePlaylistListener);
        }
        mPlaylistDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        finish();
                    }
                });
        mPlaylistDialog.setOnCancelListener(this);
        mPlaylistDialog.show();
    } else {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
        finish();
    }

}