android.widget.AutoCompleteTextView#setOnTouchListener ( )源码实例Demo

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

源代码1 项目: BotLibre   文件: CreateBotActivity.java
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_create_bot);
       
       resetView();
       
       final AutoCompleteTextView templateText = (AutoCompleteTextView) findViewById(R.id.templateText);
       templateText.setText(MainActivity.template);
       ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.select_dialog_item, MainActivity.getAllTemplates(this));
       templateText.setThreshold(0);
       templateText.setAdapter(adapter);
       templateText.setOnTouchListener(new View.OnTouchListener() {
    	   @Override
    	   public boolean onTouch(View v, MotionEvent event){
    		   templateText.showDropDown();
    		   return false;
    	   }
    	});
}
 
@Override
public void onEndIconChanged(@NonNull TextInputLayout textInputLayout, int previousIcon) {
  AutoCompleteTextView editText = (AutoCompleteTextView) textInputLayout.getEditText();
  if (editText != null && previousIcon == TextInputLayout.END_ICON_DROPDOWN_MENU) {
    // Remove any listeners set on the edit text.
    editText.removeTextChangedListener(exposedDropdownEndIconTextWatcher);
    if (editText.getOnFocusChangeListener() == onFocusChangeListener) {
      editText.setOnFocusChangeListener(null);
    }
    editText.setOnTouchListener(null);
    if (IS_LOLLIPOP) {
      editText.setOnDismissListener(null);
    }
  }
}
 
@SuppressLint("ClickableViewAccessibility") // There's an accessibility delegate that handles
// interactions with the dropdown menu.
private void setUpDropdownShowHideBehavior(@NonNull final AutoCompleteTextView editText) {
  // Set whole layout clickable.
  editText.setOnTouchListener(
      new OnTouchListener() {
        @Override
        public boolean onTouch(@NonNull View v, @NonNull MotionEvent event) {
          if (event.getAction() == MotionEvent.ACTION_UP) {
            if (isDropdownPopupActive()) {
              dropdownPopupDirty = false;
            }
            showHideDropdown(editText);
          }
          return false;
        }
      });
  editText.setOnFocusChangeListener(onFocusChangeListener);
  if (IS_LOLLIPOP) {
    editText.setOnDismissListener(
        new OnDismissListener() {
          @Override
          public void onDismiss() {
            dropdownPopupDirty = true;
            dropdownPopupActivatedAt = System.currentTimeMillis();
            setEndIconChecked(false);
          }
        });
  }
}
 
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_place_on_map);

    getSupportActionBar().setTitle("Search Places");

    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

    fabAdd= (FloatingActionButton) findViewById(R.id.fab_add);
    fabAdd.setOnClickListener(this);

    mAutocompleteView = (AutoCompleteTextView)
            findViewById(R.id.googleplacesearch);
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this, 0 /* clientId */, this)
            .addApi(Places.GEO_DATA_API)
            .build();
    mAdapter = new PlaceAutocompleteAdapter(this, R.layout.google_places_search_items,
            mGoogleApiClient, null, null);

    //TODO:In order to Restrict search to India uncomment this and comment the above line
    /*
    mAdapter = new PlaceAutocompleteAdapter(this, R.layout.google_places_search_items,
            mGoogleApiClient, BOUNDS_GREATER_INDIA, null);
     */
    mAutocompleteView.setAdapter(mAdapter);
    mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener);

    mAutocompleteView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int DRAWABLE_LEFT = 0;
            final int DRAWABLE_TOP = 1;
            final int DRAWABLE_RIGHT = 2;
            final int DRAWABLE_BOTTOM = 3;

            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getRawX() >= (mAutocompleteView.getRight() - mAutocompleteView.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {

                    mAutocompleteView.setText("");

                    return true;
                }
            }
            if (event.getRawX() <= (mAutocompleteView.getCompoundDrawables()[DRAWABLE_LEFT].getBounds().width())) {

                Intent i = new Intent(SearchPlaceOnMapActivity.this, MainActivity.class);
                startActivity(i);

                finish();
                return true;
            }
            return false;
        }
    });
}
 
源代码5 项目: YiBo   文件: EditDirectMessageActivity.java
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);
}