10f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck/*
20f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Copyright (C) 2011 The Android Open Source Project
30f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck *
40f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Licensed under the Apache License, Version 2.0 (the "License");
50f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * you may not use this file except in compliance with the License.
60f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * You may obtain a copy of the License at
70f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck *
80f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck *      http://www.apache.org/licenses/LICENSE-2.0
90f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck *
100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * Unless required by applicable law or agreed to in writing, software
110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * distributed under the License is distributed on an "AS IS" BASIS,
120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * See the License for the specific language governing permissions and
140f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck * limitations under the License.
150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck */
160f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckpackage com.android.browser;
170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.app.SearchManager;
190f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.content.Context;
200f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.content.Intent;
210f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.graphics.Bitmap;
220f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.graphics.drawable.Drawable;
230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.os.Bundle;
24f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamathimport android.text.Editable;
25f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamathimport android.text.TextWatcher;
260f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.util.AttributeSet;
270f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.KeyEvent;
280f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.View;
290f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.View.OnClickListener;
300f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.view.View.OnFocusChangeListener;
31fa6177a41a0a2fc4c76173a16af1b0070703e883John Reckimport android.webkit.WebView;
320f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.widget.ImageView;
330f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport android.widget.LinearLayout;
340f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
350f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reckimport com.android.browser.UrlInputView.UrlInputListener;
360f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
3742229bcdea8a1623d9ac3fce099793a3767fb14dJohn Reckpublic class NavigationBarBase extends LinearLayout implements
3842229bcdea8a1623d9ac3fce099793a3767fb14dJohn Reck        OnClickListener, UrlInputListener, OnFocusChangeListener,
39f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath        TextWatcher {
400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
410f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected BaseUi mBaseUi;
420f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected TitleBar mTitleBar;
430f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected UiController mUiController;
440f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected UrlInputView mUrlInput;
450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    private ImageView mFavicon;
470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    private ImageView mLockIcon;
480f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
490f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public NavigationBarBase(Context context) {
500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        super(context);
510f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
520f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
530f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public NavigationBarBase(Context context, AttributeSet attrs) {
540f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        super(context, attrs);
550f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
560f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
570f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public NavigationBarBase(Context context, AttributeSet attrs, int defStyle) {
580f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        super(context, attrs, defStyle);
590f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
600f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
610f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    @Override
620f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected void onFinishInflate() {
630f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        super.onFinishInflate();
640f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mLockIcon = (ImageView) findViewById(R.id.lock);
650f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mFavicon = (ImageView) findViewById(R.id.favicon);
660f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUrlInput = (UrlInputView) findViewById(R.id.url);
670f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUrlInput.setUrlInputListener(this);
680f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUrlInput.setOnFocusChangeListener(this);
690f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUrlInput.setSelectAllOnFocus(true);
70f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath        mUrlInput.addTextChangedListener(this);
710f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
720f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
730f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void setTitleBar(TitleBar titleBar) {
740f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mTitleBar = titleBar;
750f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mBaseUi = mTitleBar.getUi();
760f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUiController = mTitleBar.getUiController();
77b2e91fdb56c13452c6c5e5fd39ce17e7db323bdcMichael Kolb        mUrlInput.setController(mUiController);
780f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
790f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
800f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void setLock(Drawable d) {
810f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (mLockIcon == null) return;
820f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (d == null) {
830f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mLockIcon.setVisibility(View.GONE);
840f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        } else {
850f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mLockIcon.setImageDrawable(d);
860f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mLockIcon.setVisibility(View.VISIBLE);
870f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
880f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
890f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
900f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void setFavicon(Bitmap icon) {
910f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (mFavicon == null) return;
920f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mFavicon.setImageDrawable(mBaseUi.getFaviconDrawable(icon));
930f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
940f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
950f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    @Override
960f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void onClick(View v) {
970f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
980f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
990f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    @Override
1000f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void onFocusChange(View view, boolean hasFocus) {
1010f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        // if losing focus and not in touch mode, leave as is
1020f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (hasFocus || view.isInTouchMode() || mUrlInput.needsUpdate()) {
1030f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            setFocusState(hasFocus);
1040f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
1050f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (hasFocus) {
1060f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mBaseUi.showTitleBar();
1070f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        } else if (!mUrlInput.needsUpdate()) {
1080f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mUrlInput.dismissDropDown();
1090f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mUrlInput.hideIME();
1100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            if (mUrlInput.getText().length() == 0) {
1110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                Tab currentTab = mUiController.getTabControl().getCurrentTab();
1120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                if (currentTab != null) {
113434e9f83e13c0758dcdefe214357fc9cc9f104d5John Reck                    setDisplayTitle(currentTab.getUrl());
1140f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                }
1150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            }
1160f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mBaseUi.suggestHideTitleBar();
1170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
1180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUrlInput.clearNeedsUpdate();
1190f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1200f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1210f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    protected void setFocusState(boolean focus) {
1220f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1240f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public boolean isEditingUrl() {
1250f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        return mUrlInput.hasFocus();
1260f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1270f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1280f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    void stopEditingUrl() {
1290b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb        WebView currentTopWebView = mUiController.getCurrentTopWebView();
1300b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb        if (currentTopWebView != null) {
1310b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb            currentTopWebView.requestFocus();
1320b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb        }
1330f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1340f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1350f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    void setDisplayTitle(String title) {
1360f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (!isEditingUrl()) {
13729aab40c6af8cf34e7c5040725600fd1ee52a35bMichael Kolb            if (!title.equals(mUrlInput.getText().toString())) {
13829aab40c6af8cf34e7c5040725600fd1ee52a35bMichael Kolb                mUrlInput.setText(title, false);
13929aab40c6af8cf34e7c5040725600fd1ee52a35bMichael Kolb            }
1400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
1410f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1420f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1430f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    void setIncognitoMode(boolean incognito) {
1440f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUrlInput.setIncognitoMode(incognito);
1450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    void clearCompletions() {
148f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath        mUrlInput.dismissDropDown();
1490f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1510f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck // UrlInputListener implementation
1520f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1530f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    /**
1540f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     * callback from suggestion dropdown
1550f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     * user selected a suggestion
1560f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     */
1570f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    @Override
1580f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void onAction(String text, String extra, String source) {
1590b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb        stopEditingUrl();
1600f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (UrlInputView.TYPED.equals(source)) {
1610f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            String url = UrlUtils.smartUrlFilter(text, false);
1620f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            Tab t = mBaseUi.getActiveTab();
1630f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            // Only shortcut javascript URIs for now, as there is special
1640f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            // logic in UrlHandler for other schemas
1650f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            if (url != null && t != null && url.startsWith("javascript:")) {
1660f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                mUiController.loadUrl(t, url);
1670f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                setDisplayTitle(text);
1680f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                return;
1690f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            }
1700f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
1710f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        Intent i = new Intent();
1725ff5c8b88968fa794eab4b7a263cae25f05bd4d3Michael Kolb        String action = Intent.ACTION_SEARCH;
1730f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        i.setAction(action);
1740f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        i.putExtra(SearchManager.QUERY, text);
1750f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (extra != null) {
1760f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            i.putExtra(SearchManager.EXTRA_DATA_KEY, extra);
1770f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
1780f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (source != null) {
1790f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            Bundle appData = new Bundle();
1800f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            appData.putString(com.android.common.Search.SOURCE, source);
1810f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            i.putExtra(SearchManager.APP_DATA, appData);
1820f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
1830f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUiController.handleNewIntent(i);
1840f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        setDisplayTitle(text);
1850f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
1860f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
1870f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    @Override
1880f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void onDismiss() {
1890f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        final Tab currentTab = mBaseUi.getActiveTab();
1900f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mBaseUi.hideTitleBar();
1910f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        post(new Runnable() {
1920f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            public void run() {
1930f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                clearFocus();
1945ff5c8b88968fa794eab4b7a263cae25f05bd4d3Michael Kolb                if (currentTab != null) {
1950f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                    setDisplayTitle(currentTab.getUrl());
1960f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck                }
1970f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            }
1980f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        });
1990f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
2000f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
2010f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    /**
2020f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     * callback from the suggestion dropdown
2030f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     * copy text to input field and stay in edit mode
2040f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     */
2050f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    @Override
2060f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void onCopySuggestion(String text) {
2070f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        mUrlInput.setText(text, true);
2080f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (text != null) {
2090f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mUrlInput.setSelection(text.length());
2100f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
2110f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
2120f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
2130f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void setCurrentUrlIsBookmark(boolean isBookmark) {
2140f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
2150f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
2160f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    @Override
2170f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public boolean dispatchKeyEventPreIme(KeyEvent evt) {
2180f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (evt.getKeyCode() == KeyEvent.KEYCODE_BACK) {
2190f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            // catch back key in order to do slightly more cleanup than usual
2200b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb            stopEditingUrl();
2210f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            return true;
2220f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
2230f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        return super.dispatchKeyEventPreIme(evt);
2240f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
2250f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
2260f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    /**
2270f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     * called from the Ui when the user wants to edit
2280f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     * @param clearInput clear the input field
2290f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck     */
2301f9b3565dbd1911dfe4d9bfd8b833a5ac5f2e0c4Michael Kolb    void startEditingUrl(boolean clearInput, boolean forceIME) {
2310f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        // editing takes preference of progress
2320f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        setVisibility(View.VISIBLE);
2330f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (mTitleBar.useQuickControls()) {
2340f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mTitleBar.getProgressView().setVisibility(View.GONE);
2350f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
2360f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (!mUrlInput.hasFocus()) {
2370f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mUrlInput.requestFocus();
2380f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
2390f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        if (clearInput) {
2400f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck            mUrlInput.setText("");
2410f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck        }
2421f9b3565dbd1911dfe4d9bfd8b833a5ac5f2e0c4Michael Kolb        if (forceIME) {
2434bb6fcb473ec4b2ce4cddf573280fd47f21a20c7Michael Kolb            mUrlInput.showIME();
2444bb6fcb473ec4b2ce4cddf573280fd47f21a20c7Michael Kolb        }
2450f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
2460f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
2470f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void onProgressStarted() {
2480f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
2490f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
2500f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    public void onProgressStopped() {
2510f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck    }
2520f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck
25358891907e3cf77b72f1107ef5d9f4c984cb176edJohn Reck    public boolean isMenuShowing() {
25442229bcdea8a1623d9ac3fce099793a3767fb14dJohn Reck        return false;
25558891907e3cf77b72f1107ef5d9f4c984cb176edJohn Reck    }
25658891907e3cf77b72f1107ef5d9f4c984cb176edJohn Reck
257419f6b4136a8fac758e2159f223700b1dfcc20e2John Reck    public void onTabDataChanged(Tab tab) {
258419f6b4136a8fac758e2159f223700b1dfcc20e2John Reck    }
259419f6b4136a8fac758e2159f223700b1dfcc20e2John Reck
2600b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb    public void onVoiceResult(String s) {
2610b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb        startEditingUrl(true, true);
2620b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb        onCopySuggestion(s);
2630b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb    }
2640b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb
265f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath    @Override
266f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath    public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
267f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath
268f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath    @Override
2695ff5c8b88968fa794eab4b7a263cae25f05bd4d3Michael Kolb    public void onTextChanged(CharSequence s, int start, int before, int count) { }
270f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath
271f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath    @Override
272f3174a588cdf63ef59055998c23aad4b36b7856eNarayan Kamath    public void afterTextChanged(Editable s) { }
2730b12912da64ff5b2917d4f50eb91df2e76457d08Michael Kolb
2740f602f3933dcd88702fdb514b6611e3066ca7a2bJohn Reck}
275