android.widget.MultiAutoCompleteTextView Java Examples

The following examples show how to use android.widget.MultiAutoCompleteTextView. 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: EditCommentActivity.java    From YiBo with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
       super.onActivityResult(requestCode, resultCode, data);

       switch(requestCode) {
       case Constants.REQUEST_CODE_USER_SELECTOR:
           if (resultCode == Constants.RESULT_CODE_SUCCESS) {
               List<User> userList = (List<User>)data.getSerializableExtra("LIST_USER");
               if (ListUtil.isEmpty(userList)) {
               	userList = new ArrayList<User>();
               }
               MultiAutoCompleteTextView etText  =
               	(MultiAutoCompleteTextView)this.findViewById(R.id.etText);
               StringBuilder mentions = new StringBuilder("");
               for (User user : userList) {
                   mentions.append(user.getMentionName()).append(" ");
               }
               int currentPos = etText.getSelectionStart();
               etText.getText().insert(currentPos, mentions);
           }
           break;
       default:
           break;
       }
   }
 
Example #2
Source File: MicropubAction.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Parse tags response.
 *
 * @param response
 *   Parse tags response.
 * @param tags
 *   The autocomplete field
 * @param saveInAccount
 *   Whether to set the tags list or not.
 * @param user
 *   The user.
 */
private void parseTagsResponse(String response, MultiAutoCompleteTextView tags, boolean saveInAccount, User user) {
    ArrayList<String> items = new ArrayList<>();

    try {
        JSONObject categoryResponse = new JSONObject(response);
        if (categoryResponse.has("categories")) {
            JSONArray tagsList = categoryResponse.getJSONArray("categories");
            if (tagsList.length() > 0) {
                for (int i = 0; i < tagsList.length(); i++) {
                    items.add(tagsList.getString(i));
                }
            }
        }
    }
    catch (JSONException ignored) {}

    if (items.size() > 0) {
        setTagsAutocomplete(tags, items);

        if (saveInAccount) {
            AccountManager am = AccountManager.get(context);
            am.setUserData(user.getAccount(), "tags_list", response);
        }
    }

}
 
Example #3
Source File: PostActivity.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
private void setupTextBody () {
	this.txtBody = (MultiAutoCompleteTextView) findViewById(R.id.txtBody);
	final TextView txtCharRemaining = (TextView) findViewById(R.id.txtCharRemaining);
	this.txtBody.addTextChangedListener(new TextCounterWatcher(txtCharRemaining, this.txtBody));

	if (Intent.ACTION_SEND.equals(getIntent().getAction()) && "text/plain".equals(getIntent().getType())) {
		final String intentText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
		if (intentText != null) {
			this.txtBody.setText(intentText);
			this.txtBody.setSelection(this.txtBody.getText().length());
		}
	}
}
 
Example #4
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 #5
Source File: EditRetweetActivity.java    From YiBo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	super.onActivityResult(requestCode, resultCode, data);

	switch(requestCode) {
	case Constants.REQUEST_CODE_IMG_SELECTOR:
	case Constants.REQUEST_CODE_CAMERA:
		break;
	case Constants.REQUEST_CODE_USER_SELECTOR:
		if (resultCode == Constants.RESULT_CODE_SUCCESS) {
			List<User> userList = (List<User>)data.getSerializableExtra("LIST_USER");
               if (ListUtil.isEmpty(userList)) {
               	userList = new ArrayList<User>();
               }
			MultiAutoCompleteTextView etText = (MultiAutoCompleteTextView)this.findViewById(R.id.etText);
			StringBuilder mentions = new StringBuilder();
			for (User user : userList) {
				mentions.append(user.getMentionName()).append(" ");
			}
			int currentPos = etText.getSelectionStart();
			etText.getText().insert(currentPos, mentions);
		}
		break;
	default:
		break;
	}
}
 
Example #6
Source File: UiUtils.java    From EosCommander with MIT License 5 votes vote down vote up
public static void setupAccountHistory( AutoCompleteTextView... autoTextViewArray ) {
    for ( AutoCompleteTextView actv : autoTextViewArray ) {
        AccountAdapter adapter = new AccountAdapter(actv.getContext(), R.layout.account_suggestion, R.id.eos_account);
        if (actv instanceof MultiAutoCompleteTextView) {
            ((MultiAutoCompleteTextView) actv).setTokenizer(new WhitSpaceTokenizer());
        }
        actv.setThreshold(1);
        actv.setAdapter(adapter);
    }
}
 
Example #7
Source File: ContactPickerFragment.java    From UnifiedContactPicker with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    this.mRecyclerView = (RecyclerView) view.findViewById(R.id.cp_listView);
    this.mNachoTextView = (NachoTextView) view.findViewById(R.id.nachoTextView);

    this.mNachoTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    this.mNachoTextView.setThreshold(3);
    this.mNachoTextView.setMaxLines(2);
    this.mNachoTextView.addChipTerminator(' ', ChipTerminatorHandler.BEHAVIOR_CHIPIFY_TO_TERMINATOR);
    this.mNachoTextView.setChipTokenizer(new SpanChipTokenizer<>(getContext(), new ContactChipCreator(), ChipSpan.class));

}
 
Example #8
Source File: AutoCompleteWrapper.java    From Shaarlier with GNU General Public License v3.0 5 votes vote down vote up
public AutoCompleteWrapper(final MultiAutoCompleteTextView textView, Context context) {
    this.a_textView = textView;
    this.a_context = context;

    this.a_textView.setTokenizer(new AccountsSource.SpaceTokenizer());

    this.adapter = new ArrayAdapter<>(a_context, R.layout.tags_list);
    this.a_textView.setAdapter(this.adapter);
    this.a_textView.setThreshold(1);
    updateTagsView();

    AutoCompleteRetriever task = new AutoCompleteRetriever();
    task.execute();
}
 
Example #9
Source File: ShareActivity.java    From Shaarlier with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Open a dialog for the user to change the description of the share
 */
private void openDialog() {
    setContentView(R.layout.activity_share);

    initAccountSpinner();

    if (NetworkUtils.isUrl(defaults.getUrl())) {
        prefetchLink(defaults);
        autoLoadTitleAndDescription(defaults);
        updateLoadersVisibility();
    }

    ((EditText) findViewById(R.id.url)).setText(defaults.getUrl());


    MultiAutoCompleteTextView textView = findViewById(R.id.tags);
    ((EditText) findViewById(R.id.tags)).setText(defaults.getTags());
    new AutoCompleteWrapper(textView, this);

    ((Checkable) findViewById(R.id.private_share)).setChecked(defaults.isPrivate());

    // Init the tweet button if necessary:
    Switch tweetCheckBox = findViewById(R.id.tweet);
    tweetCheckBox.setChecked(userPrefs.isTweet());
    if (!userPrefs.isTweet()) {
        tweetCheckBox.setVisibility(View.GONE);
    } else {
        tweetCheckBox.setVisibility(View.VISIBLE);
    }

    // Init the toot button if necessary:
    Switch tootCheckBox = findViewById(R.id.toot);
    tootCheckBox.setChecked(userPrefs.isToot());
    if (!userPrefs.isToot()) {
        tootCheckBox.setVisibility(View.GONE);
    } else {
        tootCheckBox.setVisibility(View.VISIBLE);
    }
}
 
Example #10
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 #11
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void tokenizer(MultiAutoCompleteTextView.Tokenizer arg) {
  return BaseDSL.attr("tokenizer", arg);
}
 
Example #12
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void tokenizer(MultiAutoCompleteTextView.Tokenizer arg) {
  return BaseDSL.attr("tokenizer", arg);
}
 
Example #13
Source File: ContactEditText.java    From material with Apache License 2.0 4 votes vote down vote up
@Override
protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super.applyStyle(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ContactEditText, defStyleAttr, defStyleRes);

    String familyName = null;
    int textStyle = 0;
    boolean typefaceDefined = false;

    for(int i = 0, count = a.getIndexCount(); i < count; i++){
        int attr = a.getIndex(i);
        if(attr == R.styleable.ContactEditText_cet_spanHeight)
            mSpanHeight = a.getDimensionPixelSize(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanMaxWidth)
            mSpanMaxWidth = a.getDimensionPixelSize(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanPaddingLeft)
            mSpanPaddingLeft = a.getDimensionPixelOffset(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanPaddingRight)
            mSpanPaddingRight = a.getDimensionPixelOffset(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanTextSize)
            mSpanTextSize = a.getDimensionPixelSize(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanTextColor)
            mSpanTextColor = a.getColor(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanBackgroundColor)
            mSpanBackgroundColor = a.getColor(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanSpacing)
            mSpanSpacing = a.getDimensionPixelOffset(attr, 0);
        else if(attr == R.styleable.ContactEditText_cet_spanFontFamily) {
            familyName = a.getString(attr);
            typefaceDefined = true;
        }
        else if(attr == R.styleable.ContactEditText_cet_spanTextStyle) {
            textStyle = a.getInteger(attr, 0);
            typefaceDefined = true;
        }

    }

    if(typefaceDefined)
        mSpanTypeface = TypefaceUtil.load(context, familyName, textStyle);

    a.recycle();

    setLineSpacing(mSpanSpacing, 1);

    if(mSuggestionAdapter == null){
        mSuggestionAdapter = new ContactSuggestionAdapter();
        setAdapter(mSuggestionAdapter);
    }

    if(mTokenizer == null)
        setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    if(mTextWatcher == null){
        mTextWatcher = new ContactTextWatcher();
        addTextChangedListener(mTextWatcher);
    }

    updateSpanStyle();
}
 
Example #14
Source File: ContactEditText.java    From material with Apache License 2.0 4 votes vote down vote up
@Override
public void setTokenizer(MultiAutoCompleteTextView.Tokenizer t) {
    mTokenizer = t;
    super.setTokenizer(t);
}
 
Example #15
Source File: EditText.java    From material with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the Tokenizer that will be used to determine the relevant
 * range of the text where the user is typing.
 * <p>Only work when autoCompleMode is AUTOCOMPLETE_MODE_MULTI</p>
 */
public void setTokenizer(MultiAutoCompleteTextView.Tokenizer t) {
    if(mAutoCompleteMode != AUTOCOMPLETE_MODE_MULTI)
        return;
    ((MultiAutoCompleteTextView)mInputView).setTokenizer(t);
}
 
Example #16
Source File: EditDirectMessageActivity.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);
	AutoCompleteTextView etDisplayName = (AutoCompleteTextView)this.findViewById(R.id.etDisplayName);
	Button btnUserSelector = (Button)this.findViewById(R.id.btnUserSelector);
	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);
	
	ThemeUtil.setSecondaryHeader(llHeaderBase);
	ThemeUtil.setContentBackground(llContentPanel);
	int padding6 = theme.dip2px(6);
	int padding8 = theme.dip2px(8);
	llContentPanel.setPadding(padding6, padding8, padding6, 0);
	etDisplayName.setBackgroundDrawable(theme.getDrawable("bg_input_frame_left_half"));
	etDisplayName.setTextColor(theme.getColor("content"));
	btnUserSelector.setBackgroundDrawable(theme.getDrawable("selector_btn_message_user"));
	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"));
	
	
	TextView tvTitle = (TextView) this.findViewById(R.id.tvTitle);
	tvTitle.setText(R.string.title_edit_direct_message);
	if (StringUtil.isNotEmpty(displayName)) {
		etDisplayName.setText(displayName);
		etText.requestFocus();
	}
	etDisplayName.setAdapter(new UserSuggestAdapter(this));
	etDisplayName.setOnTouchListener(hideEmotionGridListener);

	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));
       
       emotionViewController = new EmotionViewController(this);
}
 
Example #17
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);
}
 
Example #18
Source File: PopupPositioniner.java    From Onosendai with Apache License 2.0 4 votes vote down vote up
public PopupPositioniner (final MultiAutoCompleteTextView tv) {
	this.tv = tv;
}
 
Example #19
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void multiAutoCompleteTextView(Anvil.Renderable r) {
  return BaseDSL.v(MultiAutoCompleteTextView.class, r);
}
 
Example #20
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static BaseDSL.ViewClassResult multiAutoCompleteTextView() {
  return BaseDSL.v(MultiAutoCompleteTextView.class);
}
 
Example #21
Source File: RecipientsEditor.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
RecipientsEditorTokenizer(Context context, MultiAutoCompleteTextView list) {
    mList = list;
    mContext = context;
}
 
Example #22
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void multiAutoCompleteTextView(Anvil.Renderable r) {
  return BaseDSL.v(MultiAutoCompleteTextView.class, r);
}
 
Example #23
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static BaseDSL.ViewClassResult multiAutoCompleteTextView() {
  return BaseDSL.v(MultiAutoCompleteTextView.class);
}
 
Example #24
Source File: RecipientsEditor.java    From Silence with GNU General Public License v3.0 4 votes vote down vote up
RecipientsEditorTokenizer(Context context, MultiAutoCompleteTextView list) {
    mList = list;
    mContext = context;
}
 
Example #25
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 #26
Source File: MainActivity.java    From journaldev with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    multiAutoCompleteTextView = findViewById(R.id.multiAutoCompleteTextView);
    multiAutoCompleteTextViewCustom = findViewById(R.id.multiAutoCompleteTextViewCustom);

    ArrayAdapter<String> randomArray = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, randomSuggestions);
    multiAutoCompleteTextView.setAdapter(randomArray);
    multiAutoCompleteTextView.setThreshold(1);

    multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());


    ArrayAdapter<String> tagArray = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, tags);
    multiAutoCompleteTextViewCustom.setAdapter(tagArray);
    multiAutoCompleteTextViewCustom.setThreshold(2);

    multiAutoCompleteTextViewCustom.setTokenizer(new SpaceTokenizer());

}
 
Example #27
Source File: EditText.java    From MDPreference with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the Tokenizer that will be used to determine the relevant
 * range of the text where the user is typing.
 * <p>Only work when autoCompleMode is AUTOCOMPLETE_MODE_MULTI</p>
 */
public void setTokenizer(MultiAutoCompleteTextView.Tokenizer t) {
    if(mAutoCompleteMode != AUTOCOMPLETE_MODE_MULTI)
        return;
    ((MultiAutoCompleteTextView)mInputView).setTokenizer(t);
}
 
Example #28
Source File: MnemonicActivity.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
private String getMnemonic() {
    StringBuilder sb = new StringBuilder();
    for (MultiAutoCompleteTextView me : mWordEditTexts)
        sb.append(me.getText()).append(" ");
    return sb.toString().trim();
}
 
Example #29
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 #30
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));
}