package android.support.v7.widget;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.KeyEvent.DispatcherState;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import com.tencent.ttpic.util.VideoFilterUtil;

public class SearchView$SearchAutoComplete extends AppCompatAutoCompleteTextView {
    private SearchView arD;
    private boolean arE;
    final Runnable arF;
    private int mThreshold;

    static /* synthetic */ void b(SearchView$SearchAutoComplete searchView$SearchAutoComplete) {
        if (searchView$SearchAutoComplete.arE) {
            ((InputMethodManager) searchView$SearchAutoComplete.getContext().getSystemService("input_method")).showSoftInput(searchView$SearchAutoComplete, 0);
            searchView$SearchAutoComplete.arE = false;
        }
    }

    public SearchView$SearchAutoComplete(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 2130772219);
    }

    public SearchView$SearchAutoComplete(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.arF = new 1(this);
        this.mThreshold = getThreshold();
    }

    /* Access modifiers changed, original: protected */
    public void onFinishInflate() {
        super.onFinishInflate();
        setMinWidth((int) TypedValue.applyDimension(1, (float) getSearchViewTextMinWidthDp(), getResources().getDisplayMetrics()));
    }

    /* Access modifiers changed, original: 0000 */
    public void setSearchView(SearchView searchView) {
        this.arD = searchView;
    }

    public void setThreshold(int i) {
        super.setThreshold(i);
        this.mThreshold = i;
    }

    /* Access modifiers changed, original: protected */
    public void replaceText(CharSequence charSequence) {
    }

    public void performCompletion() {
    }

    public void onWindowFocusChanged(boolean z) {
        super.onWindowFocusChanged(z);
        if (z && this.arD.hasFocus() && getVisibility() == 0) {
            this.arE = true;
            if (SearchView.ac(getContext())) {
                SearchView.arq.c(this);
            }
        }
    }

    /* Access modifiers changed, original: protected */
    public void onFocusChanged(boolean z, int i, Rect rect) {
        super.onFocusChanged(z, i, rect);
        this.arD.kL();
    }

    public boolean enoughToFilter() {
        return this.mThreshold <= 0 || super.enoughToFilter();
    }

    public boolean onKeyPreIme(int i, KeyEvent keyEvent) {
        if (i == 4) {
            DispatcherState keyDispatcherState;
            if (keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) {
                keyDispatcherState = getKeyDispatcherState();
                if (keyDispatcherState == null) {
                    return true;
                }
                keyDispatcherState.startTracking(keyEvent, this);
                return true;
            } else if (keyEvent.getAction() == 1) {
                keyDispatcherState = getKeyDispatcherState();
                if (keyDispatcherState != null) {
                    keyDispatcherState.handleUpEvent(keyEvent);
                }
                if (keyEvent.isTracking() && !keyEvent.isCanceled()) {
                    this.arD.clearFocus();
                    setImeVisibility(false);
                    return true;
                }
            }
        }
        return super.onKeyPreIme(i, keyEvent);
    }

    private int getSearchViewTextMinWidthDp() {
        Configuration configuration = getResources().getConfiguration();
        int i = configuration.screenWidthDp;
        int i2 = configuration.screenHeightDp;
        if (i >= VideoFilterUtil.IMAGE_HEIGHT && i2 >= 720 && configuration.orientation == 2) {
            return 256;
        }
        if (i >= 600 || (i >= 640 && i2 >= 480)) {
            return 192;
        }
        return 160;
    }

    public InputConnection onCreateInputConnection(EditorInfo editorInfo) {
        InputConnection onCreateInputConnection = super.onCreateInputConnection(editorInfo);
        if (this.arE) {
            removeCallbacks(this.arF);
            post(this.arF);
        }
        return onCreateInputConnection;
    }

    private void setImeVisibility(boolean z) {
        InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService("input_method");
        if (!z) {
            this.arE = false;
            removeCallbacks(this.arF);
            inputMethodManager.hideSoftInputFromWindow(getWindowToken(), 0);
        } else if (inputMethodManager.isActive(this)) {
            this.arE = false;
            removeCallbacks(this.arF);
            inputMethodManager.showSoftInput(this, 0);
        } else {
            this.arE = true;
        }
    }

    static /* synthetic */ boolean a(SearchView$SearchAutoComplete searchView$SearchAutoComplete) {
        return TextUtils.getTrimmedLength(searchView$SearchAutoComplete.getText()) == 0;
    }
}
