Example usage for android.view.inputmethod EditorInfo IME_FLAG_NO_EXTRACT_UI

List of usage examples for android.view.inputmethod EditorInfo IME_FLAG_NO_EXTRACT_UI

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_FLAG_NO_EXTRACT_UI.

Prototype

int IME_FLAG_NO_EXTRACT_UI

To view the source code for android.view.inputmethod EditorInfo IME_FLAG_NO_EXTRACT_UI.

Click Source Link

Document

Flag of #imeOptions : used to specify that the IME does not need to show its extracted text UI.

Usage

From source file:org.connectbot.TerminalView.java

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_ENTER_ACTION
            | EditorInfo.IME_ACTION_NONE;
    outAttrs.inputType = EditorInfo.TYPE_NULL;
    return new BaseInputConnection(this, false) {
        @Override/* w  ww.  j a v a2  s .  com*/
        public boolean deleteSurroundingText(int leftLength, int rightLength) {
            if (rightLength == 0 && leftLength == 0) {
                return this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            for (int i = 0; i < leftLength; i++) {
                this.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            }
            // TODO: forward delete
            return true;
        }
    };
}

From source file:indrora.atomic.activity.ConversationActivity.java

/**
 * On create//  w w w .j  a  v a  2s  .co m
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    _scheme = App.getColorScheme();

    serverId = getIntent().getExtras().getInt("serverId");
    server = Atomic.getInstance().getServerById(serverId);
    settings = new Settings(this);

    // Finish activity if server does not exist anymore - See #55
    if (server == null) {
        this.finish();
    }

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    setTitle(server.getTitle());

    setContentView(R.layout.conversations);

    boolean isLandscape = (getResources()
            .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);

    EditText input = (EditText) findViewById(R.id.input);
    input.setOnKeyListener(inputKeyListener);

    // Fix from https://groups.google.com/forum/#!topic/yaaic/Z4bXZXvW7UM

    input.setOnClickListener(new EditText.OnClickListener() {
        public void onClick(View v) {
            openSoftKeyboard(v);
        }
    });

    pager = (ViewPager) findViewById(R.id.pager);

    pagerAdapter = new ConversationPagerAdapter(this, server);
    pager.setAdapter(pagerAdapter);

    final float density = getResources().getDisplayMetrics().density;

    indicator = (ConversationIndicator) findViewById(R.id.titleIndicator);
    indicator.setServer(server);
    indicator.setTypeface(Typeface.MONOSPACE);
    indicator.setViewPager(pager);

    indicator.setFooterColor(0xFF31B6E7);
    indicator.setFooterLineHeight(1 * density);
    indicator.setFooterIndicatorHeight(3 * density);
    indicator.setFooterIndicatorStyle(IndicatorStyle.Underline);
    indicator.setSelectedColor(0xFFFFFFFF);
    indicator.setSelectedBold(true);
    indicator.setBackgroundColor(0xFF181818);

    indicator.setVisibility(View.GONE);

    indicator.setOnPageChangeListener(this);

    historySize = settings.getHistorySize();

    if (server.getStatus() == Status.PRE_CONNECTING) {
        server.clearConversations();
        pagerAdapter.clearConversations();
        server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize);
    }

    float fontSize = settings.getFontSize();
    indicator.setTextSize(fontSize * density);

    input.setTextSize(settings.getFontSize());
    input.setTypeface(Typeface.MONOSPACE);

    // Optimization : cache field lookups
    Collection<Conversation> mConversations = server.getConversations();

    for (Conversation conversation : mConversations) {
        // Only scroll to new conversation if it was selected before
        if (conversation.getStatus() == Conversation.STATUS_SELECTED) {
            onNewConversation(conversation.getName());
        } else {
            createNewConversation(conversation.getName());
        }
    }

    int setInputTypeFlags = 0;

    setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT;

    if (settings.autoCapSentences()) {
        setInputTypeFlags |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES;
    }

    if (isLandscape && settings.imeExtract()) {
        setInputTypeFlags |= InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE;
    }

    if (!settings.imeExtract()) {
        input.setImeOptions(input.getImeOptions() | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    }

    input.setInputType(input.getInputType() | setInputTypeFlags);

    // Add handling for tab-completing from the input box.

    int tabCompleteDrawableResource = (settings.getUseDarkColors() ? R.drawable.ic_tabcomplete_light
            : R.drawable.ic_tabcomplete_dark);
    // The drawable that makes up the actual clicky
    final Drawable tabcompleteDrawable = getResources().getDrawable(tabCompleteDrawableResource);
    // Set the bounds to the Intrinsic width
    // We'll resize this later (well, the input box will handle that for us)
    tabcompleteDrawable.setBounds(0, 0, tabcompleteDrawable.getIntrinsicWidth(),
            tabcompleteDrawable.getIntrinsicWidth());
    // Set the input compound drawables.
    input.setCompoundDrawables(null, null, tabcompleteDrawable, null);
    // Magic.
    final EditText tt = input;
    final ConversationActivity cv = this;
    input.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // This is where we handle some things.
            boolean tappedX = event
                    .getX() > (tt.getWidth() - tt.getPaddingRight() - tabcompleteDrawable.getIntrinsicWidth());

            if (event.getAction() == MotionEvent.ACTION_UP && tappedX) {
                cv.doNickCompletion(tt);
            }
            return false;
        }
    });

    setupColors();
    setupIndicator();

    // Create a new scrollback history
    scrollback = new Scrollback();

    if (getIntent().getExtras().containsKey(EXTRA_TARGET)) {
        ShuffleToHighlight(getIntent());
    }
}

From source file:me.philio.pinentry.PinEntryView.java

/**
 * Create views and add them to the view group
 *///from  w  w  w .  jav  a  2 s.c  om
@TargetApi(21)
private void addViews() {
    // Add a digit view for each digit
    for (int i = 0; i < mDigits; i++) {
        DigitView digitView = new DigitView(getContext());
        digitView.setWidth(mDigitWidth);
        digitView.setHeight(mDigitHeight);
        digitView.setBackgroundResource(mDigitBackground);
        digitView.setTextColor(mDigitTextColor);
        digitView.setTextSize(mDigitTextSize);
        digitView.setGravity(Gravity.CENTER);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            digitView.setElevation(mDigitElevation);
        }
        addView(digitView);
    }

    // Add an "invisible" edit text to handle input
    mEditText = new EditText(getContext());
    mEditText.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
    mEditText.setTextColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
    mEditText.setCursorVisible(false);
    mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mDigits) });
    mEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
    mEditText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    mEditText.setPadding(mEditText.getPaddingLeft(), mEditText.getPaddingTop(), mEditText.getPaddingRight(),
            100);
    mEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // Update the selected state of the views
            int length = mEditText.getText().length();
            for (int i = 0; i < mDigits; i++) {
                getChildAt(i)
                        .setSelected(hasFocus && (mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER
                                && (i == length || (i == mDigits - 1 && length == mDigits)))));
            }

            // Make sure the cursor is at the end
            mEditText.setSelection(length);

            // Provide focus change events to any listener
            if (mOnFocusChangeListener != null) {
                mOnFocusChangeListener.onFocusChange(PinEntryView.this, hasFocus);
            }
        }
    });
    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            int length = s.length();
            for (int i = 0; i < mDigits; i++) {
                if (s.length() > i) {
                    String mask = mMask == null || mMask.length() == 0 ? String.valueOf(s.charAt(i)) : mMask;
                    ((TextView) getChildAt(i)).setText(mask);
                } else {
                    ((TextView) getChildAt(i)).setText("");
                }
                if (mEditText.hasFocus()) {
                    getChildAt(i).setSelected(mAccentType == ACCENT_ALL || (mAccentType == ACCENT_CHARACTER
                            && (i == length || (i == mDigits - 1 && length == mDigits))));
                }
            }

            if (length == mDigits && mPinEnteredListener != null) {
                mPinEnteredListener.pinEntered(s.toString());
            }
        }
    });
    addView(mEditText);
}

From source file:org.telegram.ui.Components.ShareAlert.java

public ShareAlert(final Context context, MessageObject messageObject, final String text, boolean publicChannel,
        final String copyLink) {
    super(context, true);

    shadowDrawable = context.getResources().getDrawable(R.drawable.sheet_shadow);

    linkToCopy = copyLink;// w w w. jav  a  2s .c  om
    sendingMessageObject = messageObject;
    searchAdapter = new ShareSearchAdapter(context);
    isPublicChannel = publicChannel;
    sendingText = text;

    if (publicChannel) {
        loadingLink = true;
        TLRPC.TL_channels_exportMessageLink req = new TLRPC.TL_channels_exportMessageLink();
        req.id = messageObject.getId();
        req.channel = MessagesController.getInputChannel(messageObject.messageOwner.to_id.channel_id);
        ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
            @Override
            public void run(final TLObject response, TLRPC.TL_error error) {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        if (response != null) {
                            exportedMessageLink = (TLRPC.TL_exportedMessageLink) response;
                            if (copyLinkOnEnd) {
                                copyLink(context);
                            }
                        }
                        loadingLink = false;
                    }
                });
            }
        });
    }

    containerView = new FrameLayout(context) {

        private boolean ignoreLayout = false;

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (ev.getAction() == MotionEvent.ACTION_DOWN && scrollOffsetY != 0 && ev.getY() < scrollOffsetY) {
                dismiss();
                return true;
            }
            return super.onInterceptTouchEvent(ev);
        }

        @Override
        public boolean onTouchEvent(MotionEvent e) {
            return !isDismissed() && super.onTouchEvent(e);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int height = MeasureSpec.getSize(heightMeasureSpec);
            if (Build.VERSION.SDK_INT >= 21) {
                height -= AndroidUtilities.statusBarHeight;
            }
            int size = Math.max(searchAdapter.getItemCount(), listAdapter.getItemCount());
            int contentSize = AndroidUtilities.dp(48)
                    + Math.max(3, (int) Math.ceil(size / 4.0f)) * AndroidUtilities.dp(100)
                    + backgroundPaddingTop;
            int padding = contentSize < height ? 0 : height - (height / 5 * 3) + AndroidUtilities.dp(8);
            if (gridView.getPaddingTop() != padding) {
                ignoreLayout = true;
                gridView.setPadding(0, padding, 0, AndroidUtilities.dp(8));
                ignoreLayout = false;
            }
            super.onMeasure(widthMeasureSpec,
                    MeasureSpec.makeMeasureSpec(Math.min(contentSize, height), MeasureSpec.EXACTLY));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            updateLayout();
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }

        @Override
        protected void onDraw(Canvas canvas) {
            shadowDrawable.setBounds(0, scrollOffsetY - backgroundPaddingTop, getMeasuredWidth(),
                    getMeasuredHeight());
            shadowDrawable.draw(canvas);
        }
    };
    containerView.setWillNotDraw(false);
    containerView.setPadding(backgroundPaddingLeft, 0, backgroundPaddingLeft, 0);

    frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.background));
    frameLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    doneButton = new LinearLayout(context);
    doneButton.setOrientation(LinearLayout.HORIZONTAL);
    doneButton.setBackgroundDrawable(
            Theme.createBarSelectorDrawable(Theme.ACTION_BAR_AUDIO_SELECTOR_COLOR, false));
    doneButton.setPadding(AndroidUtilities.dp(21), 0, AndroidUtilities.dp(21), 0);
    frameLayout.addView(doneButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT));
    doneButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (selectedDialogs.isEmpty() && (isPublicChannel || linkToCopy != null)) {
                if (linkToCopy == null && loadingLink) {
                    copyLinkOnEnd = true;
                    Toast.makeText(ShareAlert.this.getContext(),
                            LocaleController.getString("Loading", R.string.Loading), Toast.LENGTH_SHORT).show();
                } else {
                    copyLink(ShareAlert.this.getContext());
                }
                dismiss();
            } else {
                if (sendingMessageObject != null) {
                    ArrayList<MessageObject> arrayList = new ArrayList<>();
                    arrayList.add(sendingMessageObject);
                    for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) {
                        SendMessagesHelper.getInstance().sendMessage(arrayList, entry.getKey());
                    }
                } else if (sendingText != null) {
                    for (HashMap.Entry<Long, TLRPC.TL_dialog> entry : selectedDialogs.entrySet()) {
                        SendMessagesHelper.getInstance().sendMessage(sendingText, entry.getKey(), null, null,
                                true, null, null, null);
                    }
                }
                dismiss();
            }
        }
    });

    doneButtonBadgeTextView = new TextView(context);
    doneButtonBadgeTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    doneButtonBadgeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
    doneButtonBadgeTextView.setTextColor(Theme.SHARE_SHEET_BADGE_TEXT_COLOR);
    doneButtonBadgeTextView.setGravity(Gravity.CENTER);
    doneButtonBadgeTextView.setBackgroundResource(R.drawable.bluecounter);
    doneButtonBadgeTextView.setMinWidth(AndroidUtilities.dp(23));
    doneButtonBadgeTextView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8),
            AndroidUtilities.dp(1));
    doneButton.addView(doneButtonBadgeTextView,
            LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 23, Gravity.CENTER_VERTICAL, 0, 0, 10, 0));

    doneButtonTextView = new TextView(context);
    doneButtonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    doneButtonTextView.setGravity(Gravity.CENTER);
    doneButtonTextView.setCompoundDrawablePadding(AndroidUtilities.dp(8));
    doneButtonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    doneButton.addView(doneButtonTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL));

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.search_share);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    imageView.setPadding(0, AndroidUtilities.dp(2), 0, 0);
    imageView.getDrawable().setTint(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR);
    frameLayout.addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.LEFT | Gravity.CENTER_VERTICAL));

    nameTextView = new EditText(context);
    nameTextView.setHint(LocaleController.getString("ShareSendTo", R.string.ShareSendTo));
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    nameTextView.setBackgroundDrawable(null);
    nameTextView.setHintTextColor(Theme.SHARE_SHEET_EDIT_PLACEHOLDER_TEXT_COLOR);
    nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    AndroidUtilities.clearCursorDrawable(nameTextView);
    nameTextView.setTextColor(Theme.SHARE_SHEET_EDIT_TEXT_COLOR);
    frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 48, 2, 96, 0));
    nameTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            String text = nameTextView.getText().toString();
            if (text.length() != 0) {
                if (gridView.getAdapter() != searchAdapter) {
                    topBeforeSwitch = getCurrentTop();
                    gridView.setAdapter(searchAdapter);
                    searchAdapter.notifyDataSetChanged();
                }
                if (searchEmptyView != null) {
                    searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                }
            } else {
                if (gridView.getAdapter() != listAdapter) {
                    int top = getCurrentTop();
                    searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats));
                    gridView.setAdapter(listAdapter);
                    listAdapter.notifyDataSetChanged();
                    if (top > 0) {
                        layoutManager.scrollToPositionWithOffset(0, -top);
                    }
                }
            }
            if (searchAdapter != null) {
                searchAdapter.searchDialogs(text);
            }
        }
    });

    gridView = new RecyclerListView(context);
    gridView.setTag(13);
    gridView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
    gridView.setClipToPadding(false);
    gridView.setLayoutManager(layoutManager = new GridLayoutManager(getContext(), 4));
    gridView.setHorizontalScrollBarEnabled(false);
    gridView.setVerticalScrollBarEnabled(false);
    gridView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(android.graphics.Rect outRect, View view, RecyclerView parent,
                RecyclerView.State state) {
            Holder holder = (Holder) parent.getChildViewHolder(view);
            if (holder != null) {
                int pos = holder.getAdapterPosition();
                outRect.left = pos % 4 == 0 ? 0 : AndroidUtilities.dp(4);
                outRect.right = pos % 4 == 3 ? 0 : AndroidUtilities.dp(4);
            } else {
                outRect.left = AndroidUtilities.dp(4);
                outRect.right = AndroidUtilities.dp(4);
            }
        }
    });
    containerView.addView(gridView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));
    gridView.setAdapter(listAdapter = new ShareDialogsAdapter(context));
    gridView.setGlowColor(0xfff5f6f7);
    gridView.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            if (position < 0) {
                return;
            }
            TLRPC.TL_dialog dialog;
            if (gridView.getAdapter() == listAdapter) {
                dialog = listAdapter.getItem(position);
            } else {
                dialog = searchAdapter.getItem(position);
            }
            if (dialog == null) {
                return;
            }
            ShareDialogCell cell = (ShareDialogCell) view;
            if (selectedDialogs.containsKey(dialog.id)) {
                selectedDialogs.remove(dialog.id);
                cell.setChecked(false, true);
            } else {
                selectedDialogs.put(dialog.id, dialog);
                cell.setChecked(true, true);
            }
            updateSelectedCount();
        }
    });
    gridView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            updateLayout();
        }
    });

    searchEmptyView = new EmptyTextProgressView(context);
    searchEmptyView.setShowAtCenter(true);
    searchEmptyView.showTextView();
    searchEmptyView.setText(LocaleController.getString("NoChats", R.string.NoChats));
    gridView.setEmptyView(searchEmptyView);
    containerView.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
            LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

    containerView.addView(frameLayout,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.TOP));

    shadow = new View(context);
    shadow.setBackgroundResource(R.drawable.header_shadow);
    containerView.addView(shadow,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.TOP | Gravity.LEFT, 0, 48, 0, 0));

    updateSelectedCount();

    if (!DialogsActivity.dialogsLoaded) {
        MessagesController.getInstance().loadDialogs(0, 100, true);
        ContactsController.getInstance().checkInviteText();
        DialogsActivity.dialogsLoaded = true;
    }
    if (listAdapter.dialogs.isEmpty()) {
        NotificationCenter.getInstance().addObserver(this, NotificationCenter.dialogsNeedReload);
    }
}

From source file:us.phyxsi.gameshelf.ui.SearchActivity.java

private void setupSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    // hint, inputType & ime options seem to be ignored from XML! Set in code
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH
            | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*from w  w  w  . j a  v  a2s  .c o m*/
        public boolean onQueryTextSubmit(String query) {
            getByTitle(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (TextUtils.isEmpty(query)) {
                clearResults();
            }
            return true;
        }
    });
}

From source file:com.ruesga.rview.widget.TagEditTextView.java

private void init(Context ctx, AttributeSet attrs, int defStyleAttr) {
    mHandler = new Handler(mTagMessenger);
    mTriggerTagCreationThreshold = CREATE_CHIP_DEFAULT_DELAYED_TIMEOUT;

    Resources.Theme theme = ctx.getTheme();
    TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TagEditTextView, defStyleAttr, 0);

    mReadOnly = a.getBoolean(R.styleable.TagEditTextView_readonly, false);
    mDefaultTagMode = TAG_MODE.HASH;/*www . j a  v a  2  s.  c  o  m*/

    // Create the internal EditText that holds the tag logic
    mTagEdit = mReadOnly ? new TagEditText(ctx, attrs, defStyleAttr) : new TagEditText(ctx, attrs);
    mTagEdit.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0));
    mTagEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    mTagEdit.addTextChangedListener(mEditListener);
    mTagEdit.setTextIsSelectable(false);
    mTagEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE);
    mTagEdit.setOnFocusChangeListener((v, hasFocus) -> {
        // Remove any pending message
        mHandler.removeMessages(MESSAGE_CREATE_CHIP);
    });
    mTagEdit.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {

        }
    });
    addView(mTagEdit);

    // Configure the window mode for landscape orientation, to disallow hide the
    // EditText control, and show characters instead of chips
    int orientation = ctx.getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (ctx instanceof Activity) {
            Window window = ((Activity) ctx).getWindow();
            if (window != null) {
                window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
                mTagEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            }
        }
    }

    // Save the keyListener for later restore
    mEditModeKeyListener = mTagEdit.getKeyListener();

    // Initialize resources for chips
    mChipBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    mChipFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mChipFgPaint.setTextSize(mTagEdit.getTextSize() * (mReadOnly ? 1 : 0.8f));
    if (CHIP_TYPEFACE != null) {
        mChipFgPaint.setTypeface(CHIP_TYPEFACE);
    }
    mChipFgPaint.setTextAlign(Paint.Align.LEFT);

    // Calculate the width area used to remove the tag in the chip
    mChipRemoveAreaWidth = (int) (mChipFgPaint.measureText(CHIP_REMOVE_TEXT) + 0.5f);

    if (ONE_PIXEL <= 0) {
        Resources res = getResources();
        ONE_PIXEL = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics());
    }

    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case R.styleable.TagEditTextView_supportUserTags:
            setSupportsUserTags(a.getBoolean(attr, false));
            break;

        case R.styleable.TagEditTextView_chipBackgroundColor:
            mChipBackgroundColor = a.getColor(attr, mChipBackgroundColor);
            break;

        case R.styleable.TagEditTextView_chipTextColor:
            mChipFgPaint.setColor(a.getColor(attr, Color.WHITE));
            break;
        }
    }
    a.recycle();
}

From source file:org.telegram.ui.ChannelEditActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override/*from   w w  w . jav a2 s .c  o  m*/
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }
                if (nameTextView.length() == 0) {
                    Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                    if (v != null) {
                        v.vibrate(200);
                    }
                    AndroidUtilities.shakeView(nameTextView, 2, 0);
                    return;
                }
                donePressed = true;

                if (avatarUpdater.uploadingAvatar != null) {
                    createAfterUpload = true;
                    progressDialog = new ProgressDialog(getParentActivity());
                    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
                    progressDialog.setCanceledOnTouchOutside(false);
                    progressDialog.setCancelable(false);
                    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
                            LocaleController.getString("Cancel", R.string.Cancel),
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    createAfterUpload = false;
                                    progressDialog = null;
                                    donePressed = false;
                                    try {
                                        dialog.dismiss();
                                    } catch (Exception e) {
                                        FileLog.e("tmessages", e);
                                    }
                                }
                            });
                    progressDialog.show();
                    return;
                }
                if (!currentChat.title.equals(nameTextView.getText().toString())) {
                    MessagesController.getInstance().changeChatTitle(chatId, nameTextView.getText().toString());
                }
                if (info != null && !info.about.equals(descriptionTextView.getText().toString())) {
                    MessagesController.getInstance().updateChannelAbout(chatId,
                            descriptionTextView.getText().toString(), info);
                }
                if (signMessages != currentChat.signatures) {
                    currentChat.signatures = true;
                    MessagesController.getInstance().toogleChannelSignatures(chatId, signMessages);
                }
                if (uploadedAvatar != null) {
                    MessagesController.getInstance().changeChatAvatar(chatId, uploadedAvatar);
                } else if (avatar == null && currentChat.photo instanceof TLRPC.TL_chatPhoto) {
                    MessagesController.getInstance().changeChatAvatar(chatId, null);
                }
                finishFragment();
            }
        }
    });

    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));

    LinearLayout linearLayout;

    fragmentView = new ScrollView(context);
    fragmentView.setBackgroundColor(ContextCompat.getColor(context, R.color.settings_background));
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);
    linearLayout = new LinearLayout(context);
    scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    linearLayout.setOrientation(LinearLayout.VERTICAL);

    actionBar.setTitle(LocaleController.getString("ChannelEdit", R.string.ChannelEdit));

    LinearLayout linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    FrameLayout frameLayout = new FrameLayout(context);
    linearLayout2.addView(frameLayout,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    avatarImage = new BackupImageView(context);
    avatarImage.setRoundRadius(AndroidUtilities.dp(32));
    avatarDrawable.setInfo(5, null, null, false);
    avatarDrawable.setDrawPhoto(true);
    frameLayout.addView(avatarImage,
            LayoutHelper.createFrame(64, 64,
                    Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT),
                    LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
    avatarImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

            CharSequence[] items;

            if (avatar != null) {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley),
                        LocaleController.getString("DeletePhoto", R.string.DeletePhoto) };
            } else {
                items = new CharSequence[] { LocaleController.getString("FromCamera", R.string.FromCamera),
                        LocaleController.getString("FromGalley", R.string.FromGalley) };
            }

            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (i == 0) {
                        avatarUpdater.openCamera();
                    } else if (i == 1) {
                        avatarUpdater.openGallery();
                    } else if (i == 2) {
                        avatar = null;
                        uploadedAvatar = null;
                        avatarImage.setImage(avatar, "50_50", avatarDrawable);
                    }
                }
            });
            showDialog(builder.create());
        }
    });

    nameTextView = new EditText(context);
    if (currentChat.megagroup) {
        nameTextView.setHint(LocaleController.getString("GroupName", R.string.GroupName));
    } else {
        nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
    }
    nameTextView.setMaxLines(4);
    nameTextView.setGravity(Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //nameTextView.setHintTextColor(0xff979797);
    nameTextView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI);
    nameTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    nameTextView.setPadding(0, 0, 0, AndroidUtilities.dp(8));
    InputFilter[] inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(100);
    nameTextView.setFilters(inputFilters);
    AndroidUtilities.clearCursorDrawable(nameTextView);
    nameTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    frameLayout.addView(nameTextView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT,
                    Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 16 : 96, 0,
                    LocaleController.isRTL ? 96 : 16, 0));
    nameTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            avatarDrawable.setInfo(5, nameTextView.length() > 0 ? nameTextView.getText().toString() : null,
                    null, false);
            avatarImage.invalidate();
        }
    });

    View lineView = new View(context);
    lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
    linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

    linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
    linearLayout2.setElevation(AndroidUtilities.dp(2));
    linearLayout.addView(linearLayout2,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    descriptionTextView = new EditText(context);
    descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    //descriptionTextView.setHintTextColor(0xff979797);
    descriptionTextView.setTextColor(ContextCompat.getColor(context, R.color.primary_text));
    descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
    descriptionTextView.setBackgroundDrawable(null);
    descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES
            | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(255);
    descriptionTextView.setFilters(inputFilters);
    descriptionTextView.setHint(LocaleController.getString("DescriptionOptionalPlaceholder",
            R.string.DescriptionOptionalPlaceholder));
    AndroidUtilities.clearCursorDrawable(descriptionTextView);
    linearLayout2.addView(descriptionTextView,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 17, 12, 17, 6));
    descriptionTextView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                doneButton.performClick();
                return true;
            }
            return false;
        }
    });
    descriptionTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {

        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });

    ShadowSectionCell sectionCell = new ShadowSectionCell(context);
    sectionCell.setSize(20);
    linearLayout.addView(sectionCell,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    if (currentChat.megagroup || !currentChat.megagroup) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        typeCell = new TextSettingsCell(context);
        updateTypeCell();
        typeCell.setForeground(R.drawable.list_selector);
        frameLayout.addView(typeCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        lineView = new View(context);
        lineView.setBackgroundColor(ContextCompat.getColor(context, R.color.card_divider));
        linearLayout.addView(lineView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));

        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        if (!currentChat.megagroup) {
            TextCheckCell textCheckCell = new TextCheckCell(context);
            textCheckCell.setForeground(R.drawable.list_selector);
            textCheckCell.setTextAndCheck(
                    LocaleController.getString("ChannelSignMessages", R.string.ChannelSignMessages),
                    signMessages, false);
            frameLayout.addView(textCheckCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            textCheckCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    signMessages = !signMessages;
                    ((TextCheckCell) v).setChecked(signMessages);
                }
            });

            TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
            //infoCell.setBackgroundResource(R.drawable.greydivider);
            infoCell.setText(
                    LocaleController.getString("ChannelSignMessagesInfo", R.string.ChannelSignMessagesInfo));
            linearLayout.addView(infoCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        } else {
            adminCell = new TextSettingsCell(context);
            updateAdminCell();
            adminCell.setForeground(R.drawable.list_selector);
            frameLayout.addView(adminCell,
                    LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            adminCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Bundle args = new Bundle();
                    args.putInt("chat_id", chatId);
                    args.putInt("type", 1);
                    presentFragment(new ChannelUsersActivity(args));
                }
            });

            sectionCell = new ShadowSectionCell(context);
            sectionCell.setSize(20);
            linearLayout.addView(sectionCell,
                    LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            /*if (!currentChat.creator) {
            sectionCell.setBackgroundResource(R.drawable.greydivider_bottom);
            }*/
        }
    }

    if (currentChat.creator) {
        frameLayout = new FrameLayout(context);
        frameLayout.setElevation(AndroidUtilities.dp(2));
        frameLayout.setBackgroundColor(ContextCompat.getColor(context, R.color.card_background));
        linearLayout.addView(frameLayout,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

        TextSettingsCell textCell = new TextSettingsCell(context);
        textCell.setTextColor(0xffed3d39);
        textCell.setBackgroundResource(R.drawable.list_selector);
        if (currentChat.megagroup) {
            textCell.setText(LocaleController.getString("DeleteMega", R.string.DeleteMega), false);
        } else {
            textCell.setText(LocaleController.getString("ChannelDelete", R.string.ChannelDelete), false);
        }
        frameLayout.addView(textCell,
                LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        textCell.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                if (currentChat.megagroup) {
                    builder.setMessage(LocaleController.getString("MegaDeleteAlert", R.string.MegaDeleteAlert));
                } else {
                    builder.setMessage(
                            LocaleController.getString("ChannelDeleteAlert", R.string.ChannelDeleteAlert));
                }
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                NotificationCenter.getInstance().removeObserver(this,
                                        NotificationCenter.closeChats);
                                if (AndroidUtilities.isTablet()) {
                                    NotificationCenter.getInstance().postNotificationName(
                                            NotificationCenter.closeChats, -(long) chatId);
                                } else {
                                    NotificationCenter.getInstance()
                                            .postNotificationName(NotificationCenter.closeChats);
                                }
                                MessagesController.getInstance().deleteUserFromChat(chatId,
                                        MessagesController.getInstance().getUser(UserConfig.getClientUserId()),
                                        info);
                                finishFragment();
                            }
                        });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
        });

        TextInfoPrivacyCell infoCell = new TextInfoPrivacyCell(context);
        //infoCell.setBackgroundResource(R.drawable.greydivider_bottom);
        if (currentChat.megagroup) {
            infoCell.setText(LocaleController.getString("MegaDeleteInfo", R.string.MegaDeleteInfo));
        } else {
            infoCell.setText(LocaleController.getString("ChannelDeleteInfo", R.string.ChannelDeleteInfo));
        }
        linearLayout.addView(infoCell,
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    }

    nameTextView.setText(currentChat.title);
    nameTextView.setSelection(nameTextView.length());
    if (info != null) {
        descriptionTextView.setText(info.about);
    }
    if (currentChat.photo != null) {
        avatar = currentChat.photo.photo_small;
        avatarImage.setImage(avatar, "50_50", avatarDrawable);
    } else {
        avatarImage.setImageDrawable(avatarDrawable);
    }

    return fragmentView;
}

From source file:com.hughes.android.dictionary.DictionaryManagerActivity.java

private void onCreateSetupActionBar() {
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(false);

    filterSearchView = new SearchView(getSupportActionBar().getThemedContext());
    filterSearchView.setIconifiedByDefault(false);
    // filterSearchView.setIconified(false); // puts the magnifying glass in
    // the/* w w  w . ja v a  2 s  . co m*/
    // wrong place.
    filterSearchView.setQueryHint(getString(R.string.searchText));
    filterSearchView.setSubmitButtonEnabled(false);
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    filterSearchView.setLayoutParams(lp);
    filterSearchView.setInputType(InputType.TYPE_CLASS_TEXT);
    filterSearchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI |
    // EditorInfo.IME_FLAG_NO_FULLSCREEN | // Requires API
    // 11
            EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS);

    filterSearchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            filterSearchView.clearFocus();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String filterText) {
            setMyListAdapater();
            return true;
        }
    });
    filterSearchView.setFocusable(true);

    actionBar.setCustomView(filterSearchView);
    actionBar.setDisplayShowCustomEnabled(true);

    // Avoid wasting space on large left inset
    Toolbar tb = (Toolbar) filterSearchView.getParent();
    tb.setContentInsetsRelative(0, 0);
}

From source file:com.farmerbb.taskbar.service.StartMenuService.java

@SuppressLint("RtlHardcoded")
private void drawStartMenu() {
    IconCache.getInstance(this).clearCache();

    final SharedPreferences pref = U.getSharedPreferences(this);
    final boolean hasHardwareKeyboard = getResources()
            .getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;

    switch (pref.getString("show_search_bar", "keyboard")) {
    case "always":
        shouldShowSearchBox = true;//from   w ww . j av  a2s  .c  om
        break;
    case "keyboard":
        shouldShowSearchBox = hasHardwareKeyboard;
        break;
    case "never":
        shouldShowSearchBox = false;
        break;
    }

    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            shouldShowSearchBox ? 0
                    : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);

    // Determine where to show the start menu on screen
    switch (U.getTaskbarPosition(this)) {
    case "bottom_left":
        layoutId = R.layout.start_menu_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        break;
    case "bottom_right":
        layoutId = R.layout.start_menu_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "bottom_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        break;
    case "top_left":
        layoutId = R.layout.start_menu_top_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_vertical_left":
        layoutId = R.layout.start_menu_vertical_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        break;
    case "top_right":
        layoutId = R.layout.start_menu_top_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    case "top_vertical_right":
        layoutId = R.layout.start_menu_vertical_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        break;
    }

    // Initialize views
    int theme = 0;

    switch (pref.getString("theme", "light")) {
    case "light":
        theme = R.style.AppTheme;
        break;
    case "dark":
        theme = R.style.AppTheme_Dark;
        break;
    }

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
    layout = (StartMenuLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
    startMenu = (GridView) layout.findViewById(R.id.start_menu);

    if ((shouldShowSearchBox && !hasHardwareKeyboard)
            || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        layout.viewHandlesBackButton();

    boolean scrollbar = pref.getBoolean("scrollbar", false);
    startMenu.setFastScrollEnabled(scrollbar);
    startMenu.setFastScrollAlwaysVisible(scrollbar);
    startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);

    if (pref.getBoolean("transparent_start_menu", false))
        startMenu.setBackgroundColor(0);

    searchView = (SearchView) layout.findViewById(R.id.search);

    int backgroundTint = U.getBackgroundTint(this);

    FrameLayout startMenuFrame = (FrameLayout) layout.findViewById(R.id.start_menu_frame);
    FrameLayout searchViewLayout = (FrameLayout) layout.findViewById(R.id.search_view_layout);
    startMenuFrame.setBackgroundColor(backgroundTint);
    searchViewLayout.setBackgroundColor(backgroundTint);

    if (shouldShowSearchBox) {
        if (!hasHardwareKeyboard)
            searchView.setIconifiedByDefault(true);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                if (!hasSubmittedQuery) {
                    ListAdapter adapter = startMenu.getAdapter();
                    if (adapter != null) {
                        hasSubmittedQuery = true;

                        if (adapter.getCount() > 0) {
                            View view = adapter.getView(0, null, startMenu);
                            LinearLayout layout = (LinearLayout) view.findViewById(R.id.entry);
                            layout.performClick();
                        } else {
                            if (pref.getBoolean("hide_taskbar", true)
                                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
                            else
                                LocalBroadcastManager.getInstance(StartMenuService.this)
                                        .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));

                            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
                            intent.putExtra(SearchManager.QUERY, query);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            if (intent.resolveActivity(getPackageManager()) != null)
                                startActivity(intent);
                            else {
                                Uri uri = new Uri.Builder().scheme("https").authority("www.google.com")
                                        .path("search").appendQueryParameter("q", query).build();

                                intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(uri);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                                try {
                                    startActivity(intent);
                                } catch (ActivityNotFoundException e) {
                                    /* Gracefully fail */ }
                            }
                        }
                    }
                }
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                searchView.setIconified(false);

                View closeButton = searchView.findViewById(R.id.search_close_btn);
                if (closeButton != null)
                    closeButton.setVisibility(View.GONE);

                refreshApps(newText, false);

                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
                    new Handler().postDelayed(() -> {
                        EditText editText = (EditText) searchView.findViewById(R.id.search_src_text);
                        if (editText != null) {
                            editText.requestFocus();
                            editText.setSelection(editText.getText().length());
                        }
                    }, 50);
                }

                return true;
            }
        });

        searchView.setOnQueryTextFocusChangeListener((view, b) -> {
            if (!hasHardwareKeyboard) {
                ViewGroup.LayoutParams params1 = startMenu.getLayoutParams();
                params1.height = getResources().getDimensionPixelSize(b
                        && !U.isServiceRunning(this, "com.farmerbb.secondscreen.service.DisableKeyboardService")
                                ? R.dimen.start_menu_height_half
                                : R.dimen.start_menu_height);
                startMenu.setLayoutParams(params1);
            }

            if (!b) {
                if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
                    LocalBroadcastManager.getInstance(StartMenuService.this)
                            .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
                else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        });

        searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);

        LinearLayout powerButton = (LinearLayout) layout.findViewById(R.id.power_button);
        powerButton.setOnClickListener(view -> {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(location);
        });

        powerButton.setOnGenericMotionListener((view, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                    && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                int[] location = new int[2];
                view.getLocationOnScreen(location);
                openContextMenu(location);
            }
            return false;
        });

        searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));

        startMenu.setOnItemClickListener((parent, view, position, id) -> {
            hideStartMenu();

            AppEntry entry = (AppEntry) parent.getAdapter().getItem(position);
            U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(),
                    entry.getUserId(StartMenuService.this), null, false, false);
        });

        if (pref.getBoolean("transparent_start_menu", false))
            layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0);
    } else
        searchViewLayout.setVisibility(View.GONE);

    textView = (TextView) layout.findViewById(R.id.no_apps_found);

    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiverAlt);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiver,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU"));
    LocalBroadcastManager.getInstance(this).registerReceiver(toggleReceiverAlt,
            new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU_ALT"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU"));

    handler = new Handler();
    refreshApps(true);

    windowManager.addView(layout, params);
}

From source file:org.goodev.material.SearchActivity.java

private void setupSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    // hint, inputType & ime options seem to be ignored from XML! Set in code
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH
            | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*  w w  w.j  ava2s . c om*/
        public boolean onQueryTextSubmit(String query) {
            searchFor(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (TextUtils.isEmpty(query)) {
                clearResults();
            }
            return true;
        }
    });

}