diff options
author | Leon Scroggins III <scroggo@google.com> | 2010-04-19 13:21:13 -0400 |
---|---|---|
committer | Leon Scroggins III <scroggo@google.com> | 2010-05-06 11:42:12 -0400 |
commit | 211ba54a3052f7e68bf8af035ea1ef4e9445130c (patch) | |
tree | 08deedf1efe1dca7626ffec910191a435f968e79 /src/com/android | |
parent | 875dfa2ba28db2d243e44722c69009377377e5b2 (diff) | |
download | packages_apps_browser-211ba54a3052f7e68bf8af035ea1ef4e9445130c.zip packages_apps_browser-211ba54a3052f7e68bf8af035ea1ef4e9445130c.tar.gz packages_apps_browser-211ba54a3052f7e68bf8af035ea1ef4e9445130c.tar.bz2 |
Allow interaction with page while Find is up.
In order to do this, I have changed the FindDialog from
an actual Dialog, which steals all touch events, to
a Linearlayout, which rests below the WebView.
Also dismiss Find when the user opens/closes a subwindow,
or navigates to a new page.
res/layout/browser_subwindow.xml:
Add an id to the holder for the subwindow, so it can be
used to add the FindDialog.
res/values/styles.xml:
Remove the style for FindDialog, as the animations are
now added in code (since FindDialog is now a LinearLayout,
which has no theme).
res/values/themes.xml:
Deleted, as the only theme there was FindDialog, which has
been removed.
src/com/android/browser/BrowserActivity.java:
closeFind is now the starting point for removing the
FindDialog, so that it can be called from Tab.
Close the FindDialog when a new page starts loading.
Call showFind on the current Tab.
src/com/android/browser/FindDialog.java
Change from a Dialog to a LinearLayout, so it can be
inserted into the layout.
Call closeFind directly, which now calls dismiss.
Perform the animations which were previously part
of the theme.
Remove the call to set the height of the find dialog,
which is no longer necessary.
Open and close the IME when opening and closing Find.
src/com/android/browser/Tab.java
Change pointer to mContainer to a LinearLayout, which is
used to add the FindDialog.
Add a pointer to BrowserActivity to SubWindowClient, which
is then used to close the FindDialog in onPageStarted.
Close find when adding/removing a Tab or its subwindow.
Add showFind, which attaches it to the layout for the tab,
and closeFind, which removes it from the layout.
Requires a change to frameworks/base
Change-Id: If6745fb65c5628da827781a7b98061e87b279844
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 16 | ||||
-rw-r--r-- | src/com/android/browser/FindDialog.java | 71 | ||||
-rw-r--r-- | src/com/android/browser/Tab.java | 56 |
3 files changed, 102 insertions, 41 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index 5e55789..8efb18a 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -1367,9 +1367,8 @@ public class BrowserActivity extends Activity if (null == mFindDialog) { mFindDialog = new FindDialog(this); } - mFindDialog.setWebView(getTopWindow()); - mFindDialog.show(); - getTopWindow().setFindIsUp(true); + // Need to do something special for Tablet + mTabControl.getCurrentTab().showFind(mFindDialog); mMenuState = EMPTY_MENU; break; @@ -1450,7 +1449,14 @@ public class BrowserActivity extends Activity return true; } + /* + * Remove the FindDialog. + */ public void closeFind() { + if (mFindDialog != null) { + mTabControl.getCurrentTab().closeFind(mFindDialog); + mFindDialog.dismiss(); + } mMenuState = R.id.MAIN_MENU; } @@ -2462,7 +2468,9 @@ public class BrowserActivity extends Activity onProgressChanged(view, INITIAL_PROGRESS); mDidStopLoad = false; if (!mIsNetworkUp) createAndShowNetworkDialog(); - + if (view.getFindIsUp()) { + closeFind(); + } if (mSettings.isTracing()) { String host; try { diff --git a/src/com/android/browser/FindDialog.java b/src/com/android/browser/FindDialog.java index 45c8016..caff852 100644 --- a/src/com/android/browser/FindDialog.java +++ b/src/com/android/browser/FindDialog.java @@ -16,24 +16,23 @@ package com.android.browser; -import android.app.Dialog; import android.content.Context; -import android.os.Bundle; import android.text.Editable; import android.text.Spannable; import android.text.TextWatcher; import android.view.Gravity; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.Window; -import android.view.WindowManager; +import android.view.animation.AnimationUtils; import android.view.inputmethod.InputMethodManager; import android.webkit.WebView; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.TextView; -/* package */ class FindDialog extends Dialog implements TextWatcher { +/* package */ class FindDialog extends LinearLayout implements TextWatcher { private WebView mWebView; private TextView mMatches; private BrowserActivity mBrowserActivity; @@ -53,7 +52,7 @@ import android.widget.TextView; private View.OnClickListener mFindCancelListener = new View.OnClickListener() { public void onClick(View v) { - dismiss(); + mBrowserActivity.closeFind(); } }; @@ -89,22 +88,11 @@ import android.widget.TextView; } /* package */ FindDialog(BrowserActivity context) { - super(context, R.style.FindDialogTheme); + super(context); mBrowserActivity = context; - setCanceledOnTouchOutside(true); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Window theWindow = getWindow(); - theWindow.setGravity(Gravity.BOTTOM|Gravity.FILL_HORIZONTAL); - setContentView(R.layout.browser_find); - - theWindow.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, - ViewGroup.LayoutParams.WRAP_CONTENT); + LayoutInflater factory = LayoutInflater.from(context); + factory.inflate(R.layout.browser_find, this); mEditText = (EditText) findViewById(R.id.edit); @@ -122,23 +110,38 @@ import android.widget.TextView; mMatches = (TextView) findViewById(R.id.matches); mMatchesView = findViewById(R.id.matches_view); disableButtons(); - theWindow.setSoftInputMode( - WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); + } - + + /** + * Called by BrowserActivity.closeFind. Start the animation to hide + * the dialog, inform the WebView that the dialog is being dismissed, + * and hide the soft keyboard. + */ public void dismiss() { - super.dismiss(); - mBrowserActivity.closeFind(); mWebView.notifyFindDialogDismissed(); + startAnimation(AnimationUtils.loadAnimation(mBrowserActivity, + R.anim.find_dialog_exit)); + InputMethodManager imm = (InputMethodManager) + getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + + imm.hideSoftInputFromWindow(this.getWindowToken(), 0); } @Override public boolean dispatchKeyEvent(KeyEvent event) { - if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER - && event.getAction() == KeyEvent.ACTION_UP - && mEditText.hasFocus()) { - findNext(); - return true; + int keyCode = event.getKeyCode(); + if (keyCode == KeyEvent.KEYCODE_BACK) { + if (event.getAction() == KeyEvent.ACTION_UP) { + mBrowserActivity.closeFind(); + return true; + } + } else if (event.getAction() == KeyEvent.ACTION_UP) { + if (keyCode == KeyEvent.KEYCODE_ENTER + && mEditText.hasFocus()) { + findNext(); + return true; + } } return super.dispatchKeyEvent(event); } @@ -152,7 +155,6 @@ import android.widget.TextView; } public void show() { - super.show(); mEditText.requestFocus(); mEditText.setText(""); Spannable span = (Spannable) mEditText.getText(); @@ -160,6 +162,11 @@ import android.widget.TextView; Spannable.SPAN_INCLUSIVE_INCLUSIVE); setMatchesFound(0); disableButtons(); + startAnimation(AnimationUtils.loadAnimation(mBrowserActivity, + R.anim.find_dialog_enter)); + InputMethodManager imm = (InputMethodManager) + mBrowserActivity.getSystemService(Context.INPUT_METHOD_SERVICE); + imm.showSoftInput(mEditText, 0); } // TextWatcher methods @@ -184,8 +191,6 @@ import android.widget.TextView; mMatchesView.setVisibility(View.INVISIBLE); } else { mMatchesView.setVisibility(View.VISIBLE); - mWebView.setFindDialogHeight( - getWindow().getDecorView().getHeight()); int found = mWebView.findAll(find.toString()); setMatchesFound(found); if (found < 2) { diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java index 2dac050..12f0cf6 100644 --- a/src/com/android/browser/Tab.java +++ b/src/com/android/browser/Tab.java @@ -87,7 +87,7 @@ class Tab { // The Geolocation permissions prompt private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt; // Main WebView wrapper - private View mContainer; + private LinearLayout mContainer; // Main WebView private WebView mMainView; // Subwindow container @@ -1205,9 +1205,18 @@ class Tab { private static class SubWindowClient extends WebViewClient { // The main WebViewClient. private final WebViewClient mClient; + private final BrowserActivity mBrowserActivity; - SubWindowClient(WebViewClient client) { + SubWindowClient(WebViewClient client, BrowserActivity activity) { mClient = client; + mBrowserActivity = activity; + } + @Override + public void onPageStarted(WebView view, String url, Bitmap favicon) { + // Unlike the others, do not call mClient's version, which would + // change the progress bar. However, we do want to remove the + // find dialog. + if (view.getFindIsUp()) mBrowserActivity.closeFind(); } @Override public void doUpdateVisitedHistory(WebView view, String url, @@ -1297,7 +1306,7 @@ class Tab { // The tab consists of a container view, which contains the main // WebView, as well as any other UI elements associated with the tab. - mContainer = mInflateService.inflate(R.layout.tab, null); + mContainer = (LinearLayout) mInflateService.inflate(R.layout.tab, null); mDownloadListener = new DownloadListener() { public void onDownloadStart(String url, String userAgent, @@ -1408,6 +1417,7 @@ class Tab { */ boolean createSubWindow() { if (mSubView == null) { + if (mMainView.getFindIsUp()) mActivity.closeFind(); mSubViewContainer = mInflateService.inflate( R.layout.browser_subwindow, null); mSubView = (WebView) mSubViewContainer.findViewById(R.id.webview); @@ -1416,7 +1426,8 @@ class Tab { mSubView.setMapTrackballToArrowKeys(false); // Enable the built-in zoom mSubView.getSettings().setBuiltInZoomControls(true); - mSubView.setWebViewClient(new SubWindowClient(mWebViewClient)); + mSubView.setWebViewClient(new SubWindowClient(mWebViewClient, + mActivity)); mSubView.setWebChromeClient(new SubWindowChromeClient( mWebChromeClient)); // Set a different DownloadListener for the mSubView, since it will @@ -1454,6 +1465,9 @@ class Tab { */ void dismissSubWindow() { if (mSubView != null) { + if (mSubView.getFindIsUp()) { + mActivity.closeFind(); + } BrowserSettings.getInstance().deleteObserver( mSubView.getSettings()); mSubView.destroy(); @@ -1478,6 +1492,7 @@ class Tab { void removeSubWindow(ViewGroup content) { if (mSubView != null) { content.removeView(mSubViewContainer); + if (mSubView.getFindIsUp()) mActivity.closeFind(); } } @@ -1536,6 +1551,7 @@ class Tab { (FrameLayout) mContainer.findViewById(R.id.webview_wrapper); wrapper.removeView(mMainView); content.removeView(mContainer); + if (mMainView.getFindIsUp()) mActivity.closeFind(); removeSubWindow(content); } @@ -1931,4 +1947,36 @@ class Tab { } return true; } + + /* + * Open the find dialog. Called by BrowserActivity. + */ + void showFind(FindDialog dialog) { + LinearLayout container; + WebView view; + if (mSubView != null) { + view = mSubView; + container = (LinearLayout) mSubViewContainer.findViewById( + R.id.inner_container); + } else { + view = mMainView; + container = mContainer; + } + dialog.show(); + container.addView(dialog, new LinearLayout.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.WRAP_CONTENT)); + dialog.setWebView(view); + view.setFindIsUp(true); + } + + /* + * Close the find dialog. Called by BrowserActivity.closeFind. + */ + void closeFind(FindDialog dialog) { + // The dialog may be attached to the subwindow. Ensure that the + // correct parent has it removed. + LinearLayout parent = (LinearLayout) dialog.getParent(); + if (parent != null) parent.removeView(dialog); + } } |