Java Code Examples for android.widget.MultiAutoCompleteTextView#setTokenizer()

The following examples show how to use android.widget.MultiAutoCompleteTextView#setTokenizer() . 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: RhythmSandbox.java    From Rhythm with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize a presenter for sandbox
 *
 * @param activity        Activity that hosts this sandbox
 * @param rootView        Root view of the sandbox
 * @param overlayInflater Overlay inflater used to inflate rhythm config
 */
public RhythmSandbox(AppCompatActivity activity, View rootView, RhythmOverlayInflater overlayInflater) {
    mActivity = activity;
    mOverlayInflater = overlayInflater;

    // Find and init preview layout
    mPreview = (RhythmFrameLayout) rootView.findViewById(R.id.preview);
    mPreview.setRhythmDrawable(new RhythmDrawable(null));

    // Find and init overlay config text box
    mOverlayConfig = (MultiAutoCompleteTextView) rootView.findViewById(R.id.config);
    mOverlayConfig.setHorizontallyScrolling(true);

    // Fix config text box metrics
    int i4dp = activity.getResources().getDimensionPixelOffset(R.dimen.i4dp);
    Utils.setExactMetrics(mOverlayConfig, i4dp * 6, i4dp * 5, i4dp * 3);

    // Enable auto-complete for config
    ArrayAdapter<String> adapter = new ArrayAdapter<>(activity, android.R.layout.simple_dropdown_item_1line, ALL_CONFIG_WORDS);
    mOverlayConfig.setTokenizer(new ConfigTokenizer());
    mOverlayConfig.setAdapter(adapter);

    // Find and init Apply button
    final Button applyButton = (Button) rootView.findViewById(R.id.apply);
    applyButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            updatePreview();
        }
    });
}
 
Example 2
Source File: AutoComplete6.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.autocomplete_6);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_dropdown_item_1line, COUNTRIES);
    MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(R.id.edit);
    textView.setAdapter(adapter);
    textView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
 
Example 3
Source File: MicropubAction.java    From indigenous-android with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sets tags autcomplete.
 */
private void setTagsAutocomplete(MultiAutoCompleteTextView tags, ArrayList<String> items) {
    tags.setThreshold(1);
    tags.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    tags.setAdapter(new ArrayAdapter<>(context, R.layout.popup_item, items));
}
 
Example 4
Source File: MnemonicActivity.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
private void setUpTable(final int id, final int startWordNum) {
    int wordNum = startWordNum;
    final TableLayout table = UI.find(this, id);

    for (int y = 0; y < table.getChildCount(); ++y) {
        final TableRow row = (TableRow) table.getChildAt(y);

        for (int x = 0; x < row.getChildCount() / 2; ++x) {
            ((TextView) row.getChildAt(x * 2)).setText(String.valueOf(wordNum));

            MultiAutoCompleteTextView me = (MultiAutoCompleteTextView) row.getChildAt(x * 2 + 1);
            me.setAdapter(mWordsAdapter);
            me.setThreshold(3);
            me.setTokenizer(mTokenizer);
            me.setOnEditorActionListener(this);
            me.setOnKeyListener(this);
            me.addTextChangedListener(new UI.TextWatcher() {
                @Override
                public void afterTextChanged(final Editable s) {
                    super.afterTextChanged(s);
                    final String original = s.toString();
                    final String trimmed = original.trim();
                    if (!trimmed.isEmpty() && !trimmed.equals(original)) {
                        me.setText(trimmed);
                        return;
                    }
                    final boolean isInvalid = markInvalidWord(s);
                    if (!isInvalid && (s.length() > 3)) {
                        if (!enableLogin())
                            nextFocus();
                    }
                    enableLogin();
                }
            });
            me.setOnFocusChangeListener((View v, boolean hasFocus) -> {
                if (!hasFocus && v instanceof EditText) {
                    final Editable e = ((EditText)v).getEditableText();
                    final String word = e.toString();
                    if (!MnemonicHelper.mWords.contains(word)) {
                        e.setSpan(new StrikethroughSpan(), 0, word.length(), 0);
                    }
                }
            });
            registerForContextMenu(me);

            mWordEditTexts[wordNum - 1] = me;
            ++wordNum;
        }
    }
}
 
Example 5
Source File: ShareTrackDialogFragment.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
protected Dialog createDialog() {
  FragmentActivity fragmentActivity = getActivity();
  accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);

  if (accounts.length == 0) {
    return new AlertDialog.Builder(fragmentActivity).setMessage(
        R.string.send_google_no_account_message).setTitle(R.string.send_google_no_account_title)
        .setPositiveButton(R.string.generic_ok, null).create();
  }

  // Get all the views
  View view = fragmentActivity.getLayoutInflater().inflate(R.layout.share_track, null);
  publicCheckBox = (CheckBox) view.findViewById(R.id.share_track_public);
  inviteCheckBox = (CheckBox) view.findViewById(R.id.share_track_invite);
  multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(
      R.id.share_track_emails);
  accountSpinner = (Spinner) view.findViewById(R.id.share_track_account);
  
  // Setup publicCheckBox
  publicCheckBox.setChecked(PreferencesUtils.getBoolean(
      fragmentActivity, R.string.share_track_public_key,
      PreferencesUtils.SHARE_TRACK_PUBLIC_DEFAULT));

  // Setup inviteCheckBox
  inviteCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
      @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      multiAutoCompleteTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
    }
  });
  inviteCheckBox.setChecked(PreferencesUtils.getBoolean(
      fragmentActivity, R.string.share_track_invite_key,
      PreferencesUtils.SHARE_TRACK_INVITE_DEFAULT));

  // Setup multiAutoCompleteTextView
  multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
  SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity,
      R.layout.add_emails_item, getAutoCompleteCursor(fragmentActivity, null), new String[] {
          ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA },
      new int[] { android.R.id.text1, android.R.id.text2 }, 0);
  adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
      @Override
    public CharSequence convertToString(Cursor cursor) {
      int index = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
      return cursor.getString(index).trim();
    }
  });
  adapter.setFilterQueryProvider(new FilterQueryProvider() {
      @Override
    public Cursor runQuery(CharSequence constraint) {
      return getAutoCompleteCursor(getActivity(), constraint);
    }
  });
  multiAutoCompleteTextView.setAdapter(adapter);

  // Setup accountSpinner
  accountSpinner.setVisibility(accounts.length > 1 ? View.VISIBLE : View.GONE);
  AccountUtils.setupAccountSpinner(fragmentActivity, accountSpinner, accounts);
  
  return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
      R.string.generic_cancel, null)
      .setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
          @Override
        public void onClick(DialogInterface dialog, int which) {
          FragmentActivity context = getActivity();
          if (!publicCheckBox.isChecked() && !inviteCheckBox.isChecked()) {
            Toast.makeText(context, R.string.share_track_no_selection, Toast.LENGTH_LONG).show();
            return;
          }
          String acl = multiAutoCompleteTextView.getText().toString().trim();
          if (!publicCheckBox.isChecked() && acl.equals("")) {
            Toast.makeText(context, R.string.share_track_no_emails, Toast.LENGTH_LONG).show();
            return;
          }
          PreferencesUtils.setBoolean(
              context, R.string.share_track_public_key, publicCheckBox.isChecked());
          PreferencesUtils.setBoolean(
              context, R.string.share_track_invite_key, inviteCheckBox.isChecked());
          Account account = accounts.length > 1 ? accounts[accountSpinner
              .getSelectedItemPosition()]
              : accounts[0];
          AccountUtils.updateShareTrackAccountPreference(context, account);
          caller.onShareTrackDone(
              getArguments().getLong(KEY_TRACK_ID), publicCheckBox.isChecked(), acl, account);
        }
      }).setTitle(R.string.share_track_title).setView(view).create();
}
 
Example 6
Source File: EditRetweetActivity.java    From YiBo with Apache License 2.0 4 votes vote down vote up
private void initComponents() {
	LinearLayout llHeaderBase = (LinearLayout)findViewById(R.id.llHeaderBase);
	LinearLayout llContentPanel = (LinearLayout)findViewById(R.id.llContentPanel);
	LinearLayout llEditText = (LinearLayout)findViewById(R.id.llEditText);
	MultiAutoCompleteTextView etText  = (MultiAutoCompleteTextView)findViewById(R.id.etText);
	Button btnEmotion = (Button)this.findViewById(R.id.btnEmotion);
	Button btnMention = (Button)this.findViewById(R.id.btnMention);
	Button btnTopic = (Button)this.findViewById(R.id.btnTopic);
	Button btnTextCount = (Button)this.findViewById(R.id.btnTextCount);
	cbComment = (CheckBox) this.findViewById(R.id.cbComment);
	cbCommentToOrigin = (CheckBox)this.findViewById(R.id.cbCommentToOrigin);
	tvText = (TextView)this.findViewById(R.id.tvText);
	
	ThemeUtil.setSecondaryHeader(llHeaderBase);
	ThemeUtil.setContentBackground(llContentPanel);
	int padding6 = theme.dip2px(6);
	int padding8 = theme.dip2px(8);
	llContentPanel.setPadding(padding6, padding8, padding6, 0);
	llEditText.setBackgroundDrawable(theme.getDrawable("bg_input_frame_normal"));
	etText.setTextColor(theme.getColor("content"));
	btnEmotion.setBackgroundDrawable(theme.getDrawable("selector_btn_emotion"));
	btnMention.setBackgroundDrawable(theme.getDrawable("selector_btn_mention"));
	btnTopic.setBackgroundDrawable(theme.getDrawable("selector_btn_topic"));
	btnTextCount.setBackgroundDrawable(theme.getDrawable("selector_btn_text_count"));
	btnTextCount.setPadding(padding6, 0, theme.dip2px(20), 0);
	btnTextCount.setTextColor(theme.getColor("status_capability"));
	cbComment.setButtonDrawable(theme.getDrawable("selector_checkbox"));
	cbComment.setTextColor(theme.getColor("content"));
	cbCommentToOrigin.setButtonDrawable(theme.getDrawable("selector_checkbox"));
	cbCommentToOrigin.setTextColor(theme.getColor("content"));
	tvText.setTextColor(theme.getColor("quote"));
	
	TextView tvTitle = (TextView)this.findViewById(R.id.tvTitle);
	tvTitle.setText(R.string.title_retweet);
        
	MicroBlogTextWatcher textWatcher = new MicroBlogTextWatcher(this); 
	etText.addTextChangedListener(textWatcher);
	etText.setHint(R.string.hint_retweet);
	etText.requestFocus();
	etText.setAdapter(new UserSuggestAdapter(this));
	etText.setTokenizer(new EditMicroBlogTokenizer());
	
	retweetedStatus = status;
	if (status.getServiceProvider() != ServiceProvider.Sohu) {
		if (status.getServiceProvider() == ServiceProvider.Fanfou
			|| status.getRetweetedStatus() != null) {
			etText.setText(
				String.format(
					FeaturePatternUtils.getRetweetFormat(status.getServiceProvider()),
					FeaturePatternUtils.getRetweetSeparator(status.getServiceProvider()),
					status.getUser().getMentionName(),
					status.getText()
				)
			);
		}
		if (!(status.getServiceProvider() == ServiceProvider.Fanfou
			|| status.getRetweetedStatus() == null)) {
			retweetedStatus = status.getRetweetedStatus();
		}
		etText.setSelection(0);
	}

	int length = StringUtil.getLengthByByte(etText.getText().toString());
       int leavings = (int) Math.floor((double) (Constants.STATUS_TEXT_MAX_LENGTH * 2 - length) / 2);
       btnTextCount.setText((leavings < 0 ? "-" : "") + Math.abs(leavings));

	String lableComment = this.getString(R.string.label_retweet_with_comment, 
		status.getUser().getScreenName());
	cbComment.setText(lableComment);

	if (isComment2OriginVisible()) {
		String lableCommentToOrigin = this.getString(
			R.string.label_retweet_with_comment_to_origin,
			retweetedStatus.getUser().getScreenName());
		cbCommentToOrigin.setText(lableCommentToOrigin);
		cbCommentToOrigin.setVisibility(View.VISIBLE);
	}

	String promptText = retweetedStatus.getUser().getMentionTitleName()
		+ ":" + retweetedStatus.getText();
    tvText.setText(promptText);
}