public class

SearchEditText

extends AppCompatEditText

 java.lang.Object

↳EditText

androidx.appcompat.widget.AppCompatEditText

↳androidx.pdf.widget.SearchEditText

Gradle dependencies

compile group: 'androidx.pdf', name: 'pdf-viewer', version: '1.0.0-alpha02'

  • groupId: androidx.pdf
  • artifactId: pdf-viewer
  • version: 1.0.0-alpha02

Artifact androidx.pdf:pdf-viewer:1.0.0-alpha02 it located at Google repository (https://maven.google.com/)

Overview

EditText for search queries which shows/hides the keyboard on focus change.

Summary

Constructors
publicSearchEditText(Context context)

publicSearchEditText(Context context, AttributeSet attrs)

publicSearchEditText(Context context, AttributeSet attrs, int defStyle)

Methods
protected voidonFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)

from AppCompatEditTextdrawableStateChanged, getCustomSelectionActionModeCallback, getSupportBackgroundTintList, getSupportBackgroundTintMode, getSupportCompoundDrawablesTintList, getSupportCompoundDrawablesTintMode, getText, getTextClassifier, isEmojiCompatEnabled, onCreateInputConnection, onDetachedFromWindow, onDragEvent, onReceiveContent, onTextContextMenuItem, setBackgroundDrawable, setBackgroundResource, setCompoundDrawables, setCompoundDrawablesRelative, setCustomSelectionActionModeCallback, setEmojiCompatEnabled, setKeyListener, setSupportBackgroundTintList, setSupportBackgroundTintMode, setSupportCompoundDrawablesTintList, setSupportCompoundDrawablesTintMode, setTextAppearance, setTextClassifier
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public SearchEditText(Context context)

public SearchEditText(Context context, AttributeSet attrs)

public SearchEditText(Context context, AttributeSet attrs, int defStyle)

Methods

protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)

Source

/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.pdf.widget;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.appcompat.widget.AppCompatEditText;

/**
 * EditText for search queries which shows/hides the keyboard on focus change.
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public class SearchEditText extends AppCompatEditText {
    private static final String TAG = SearchEditText.class.getSimpleName();

    /**
     * Runnable to show the keyboard asynchronously in case the UI is not fully initialized.
     * Based on
     * the platform SearchView.
     */
    private final Runnable mShowImeRunnable =
            () -> {
                InputMethodManager imm =
                        (InputMethodManager) getContext().getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.showSoftInput(SearchEditText.this, 0);
                }
            };

    public SearchEditText(@NonNull Context context) {
        super(context);
    }

    public SearchEditText(@NonNull Context context, @NonNull AttributeSet attrs) {
        super(context, attrs);
    }

    public SearchEditText(@NonNull Context context, @NonNull AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction,
            @NonNull Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        if (focused) {
            post(mShowImeRunnable);
        } else {
            InputMethodManager imm =
                    (InputMethodManager) getContext().getSystemService(
                            Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(getWindowToken(), 0);
            }
        }
    }
}