private ExtendedZoomControls mZoomControls;
private Runnable mZoomControlRunnable;
+ // mZoomButtonsController will be lazy initialized in
+ // getZoomButtonsController() to get better performance.
private ZoomButtonsController mZoomButtonsController;
// These keep track of the center point of the zoom. They are used to
mDatabase = WebViewDatabase.getInstance(context);
mScroller = new OverScroller(context);
- mZoomButtonsController = new ZoomButtonsController(this);
- mZoomButtonsController.setOnZoomListener(mZoomListener);
- // ZoomButtonsController positions the buttons at the bottom, but in
- // the middle. Change their layout parameters so they appear on the
- // right.
- View controls = mZoomButtonsController.getZoomControls();
- ViewGroup.LayoutParams params = controls.getLayoutParams();
- if (params instanceof FrameLayout.LayoutParams) {
- FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams)
- params;
- frameParams.gravity = Gravity.RIGHT;
- }
updateMultiTouchSupport(context);
}
private void updateZoomButtonsEnabled() {
boolean canZoomIn = mActualScale < mMaxZoomScale;
boolean canZoomOut = mActualScale > mMinZoomScale && !mInZoomOverview;
+ ZoomButtonsController controller = getZoomButtonsController();
if (!canZoomIn && !canZoomOut) {
// Hide the zoom in and out buttons, as well as the fit to page
// button, if the page cannot zoom
- mZoomButtonsController.getZoomControls().setVisibility(View.GONE);
+ controller.getZoomControls().setVisibility(View.GONE);
} else {
// Set each one individually, as a page may be able to zoom in
// or out.
- mZoomButtonsController.setZoomInEnabled(canZoomIn);
- mZoomButtonsController.setZoomOutEnabled(canZoomOut);
+ controller.setZoomInEnabled(canZoomIn);
+ controller.setZoomOutEnabled(canZoomOut);
}
}
}
clearTextEntry(false);
if (getSettings().getBuiltInZoomControls()) {
- mZoomButtonsController.setVisible(true);
+ getZoomButtonsController().setVisible(true);
} else {
mPrivateHandler.removeCallbacks(mZoomControlRunnable);
mPrivateHandler.postDelayed(mZoomControlRunnable,
// false for the first parameter
}
} else {
- if (getSettings().getBuiltInZoomControls() && !mZoomButtonsController.isVisible()) {
+ if (getSettings().getBuiltInZoomControls() && !getZoomButtonsController().isVisible()) {
/*
* The zoom controls come in their own window, so our window
* loses focus. Our policy is to not draw the cursor ring if
WebSettings settings = getSettings();
if (settings.supportZoom()
&& settings.getBuiltInZoomControls()
- && !mZoomButtonsController.isVisible()
+ && !getZoomButtonsController().isVisible()
&& mMinZoomScale < mMaxZoomScale) {
mZoomButtonsController.setVisible(true);
int count = settings.getDoubleTapToastCount();
* @hide
*/
public ZoomButtonsController getZoomButtonsController() {
+ if (mZoomButtonsController == null) {
+ mZoomButtonsController = new ZoomButtonsController(this);
+ mZoomButtonsController.setOnZoomListener(mZoomListener);
+ // ZoomButtonsController positions the buttons at the bottom, but in
+ // the middle. Change their layout parameters so they appear on the
+ // right.
+ View controls = mZoomButtonsController.getZoomControls();
+ ViewGroup.LayoutParams params = controls.getLayoutParams();
+ if (params instanceof FrameLayout.LayoutParams) {
+ FrameLayout.LayoutParams frameParams = (FrameLayout.LayoutParams) params;
+ frameParams.gravity = Gravity.RIGHT;
+ }
+ }
return mZoomButtonsController;
}
if (mWebViewCore == null) {
// maybe called after WebView's destroy(). As we can't get settings,
// just hide zoom control for both styles.
- mZoomButtonsController.setVisible(false);
+ if (mZoomButtonsController != null) {
+ mZoomButtonsController.setVisible(false);
+ }
if (mZoomControls != null) {
mZoomControls.hide();
}
}
WebSettings settings = getSettings();
if (settings.getBuiltInZoomControls()) {
- if (mZoomButtonsController.isVisible()) {
+ if (getZoomButtonsController().isVisible()) {
mZoomButtonsController.setVisible(false);
}
} else {