blob: f2d5da0a5ba313f6c1e56aa931d2678bef694e14 [file] [log] [blame]
/*
* Copyright (C) 2010 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 com.android.browser;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.widget.FrameLayout;
/**
* Ui for regular phone screen sizes
*/
public class PhoneUi extends BaseUi {
private static final String LOGTAG = "PhoneUi";
private PieControlPhone mPieControl;
private NavScreen mNavScreen;
private NavigationBarPhone mNavigationBar;
boolean mExtendedMenuOpen;
boolean mOptionsMenuOpen;
boolean mAnimating;
/**
* @param browser
* @param controller
*/
public PhoneUi(Activity browser, UiController controller) {
super(browser, controller);
mActivity.getActionBar().hide();
setUseQuickControls(BrowserSettings.getInstance().useQuickControls());
mNavigationBar = (NavigationBarPhone) mTitleBar.getNavigationBar();
}
@Override
public void hideComboView() {
super.hideComboView();
mActivity.getActionBar().hide();
}
@Override
public void onDestroy() {
hideTitleBar();
}
@Override
public void editUrl(boolean clearInput) {
if (mUseQuickControls) {
mTitleBar.setShowProgressOnly(false);
}
super.editUrl(clearInput);
}
@Override
public boolean onBackKey() {
if (mNavScreen != null) {
mNavScreen.close();
return true;
}
return super.onBackKey();
}
@Override
public boolean onMenuKey() {
if (!isComboViewShowing()) {
if (mNavScreen == null) {
showNavScreen();
} else {
mNavScreen.close();
}
return true;
} else {
return false;
}
}
@Override
public boolean dispatchKey(int code, KeyEvent event) {
if (!isComboViewShowing()) {
}
return false;
}
@Override
public void onProgressChanged(Tab tab) {
if (tab.inForeground()) {
int progress = tab.getLoadProgress();
mTitleBar.setProgress(progress);
if (progress == 100) {
if (!mOptionsMenuOpen || !mExtendedMenuOpen) {
suggestHideTitleBar();
if (mUseQuickControls) {
mTitleBar.setShowProgressOnly(false);
}
}
} else {
if (!mOptionsMenuOpen || mExtendedMenuOpen) {
if (mUseQuickControls && !mTitleBar.isEditingUrl()) {
mTitleBar.setShowProgressOnly(true);
setTitleGravity(Gravity.TOP);
}
showTitleBar();
}
}
}
}
@Override
public void setActiveTab(final Tab tab) {
super.setActiveTab(tab);
BrowserWebView view = (BrowserWebView) tab.getWebView();
// TabControl.setCurrentTab has been called before this,
// so the tab is guaranteed to have a webview
if (view == null) {
Log.e(LOGTAG, "active tab with no webview detected");
return;
}
// Request focus on the top window.
if (mUseQuickControls) {
mPieControl.forceToTop(mContentView);
} else {
// check if title bar is already attached by animation
if (mTitleBar.getParent() == null) {
view.setEmbeddedTitleBar(mTitleBar);
}
}
if (tab.isInVoiceSearchMode()) {
showVoiceTitleBar(tab.getVoiceDisplayTitle(), tab.getVoiceSearchResults());
} else {
revertVoiceTitleBar(tab);
}
updateLockIconToLatest(tab);
tab.getTopWindow().requestFocus();
}
/**
* Suggest to the UI that the title bar can be hidden. The UI will then
* decide whether or not to hide based off a number of factors, such
* as if the user is editing the URL bar or if the page is loading
*/
@Override
public void suggestHideTitleBar() {
if (!mNavigationBar.isMenuShowing()) {
super.suggestHideTitleBar();
}
}
@Override
public void showComboView(ComboViews startWith, Bundle extras) {
if (mNavScreen != null) {
hideNavScreen(false);
}
super.showComboView(startWith, extras);
}
// menu handling callbacks
@Override
public void onContextMenuCreated(Menu menu) {
hideTitleBar();
}
@Override
public void onContextMenuClosed(Menu menu, boolean inLoad) {
if (inLoad) {
showTitleBar();
}
}
// action mode callbacks
@Override
public void onActionModeStarted(ActionMode mode) {
hideTitleBar();
}
@Override
public void onActionModeFinished(boolean inLoad) {
if (inLoad) {
if (mUseQuickControls) {
mTitleBar.setShowProgressOnly(true);
}
showTitleBar();
}
mActivity.getActionBar().hide();
}
@Override
protected void setTitleGravity(int gravity) {
if (mUseQuickControls) {
FrameLayout.LayoutParams lp =
(FrameLayout.LayoutParams) mTitleBar.getLayoutParams();
lp.gravity = gravity;
mTitleBar.setLayoutParams(lp);
} else {
super.setTitleGravity(gravity);
}
}
@Override
public void setUseQuickControls(boolean useQuickControls) {
mUseQuickControls = useQuickControls;
mTitleBar.setUseQuickControls(mUseQuickControls);
if (useQuickControls) {
mPieControl = new PieControlPhone(mActivity, mUiController, this);
mPieControl.attachToContainer(mContentView);
WebView web = getWebView();
if (web != null) {
web.setEmbeddedTitleBar(null);
// don't show url bar on scrolling
web.setOnTouchListener(null);
}
} else {
if (mPieControl != null) {
mPieControl.removeFromContainer(mContentView);
}
WebView web = getWebView();
if (web != null) {
web.setEmbeddedTitleBar(mTitleBar);
// show url bar on scrolling
web.setOnTouchListener(this);
}
setTitleGravity(Gravity.NO_GRAVITY);
}
}
void showNavScreen() {
detachTab(mActiveTab);
mNavScreen = new NavScreen(mActivity, mUiController, this);
// Add the custom view to its container.
mCustomViewContainer.addView(mNavScreen, COVER_SCREEN_PARAMS);
mContentView.setVisibility(View.GONE);
mCustomViewContainer.setVisibility(View.VISIBLE);
mCustomViewContainer.bringToFront();
}
void hideNavScreen(boolean animate) {
if (mNavScreen == null) return;
Tab tab = mNavScreen.getSelectedTab();
mCustomViewContainer.removeView(mNavScreen);
mNavScreen = null;
mCustomViewContainer.setVisibility(View.GONE);
mUiController.setActiveTab(tab);
// Show the content view.
mContentView.setVisibility(View.VISIBLE);
}
@Override
public boolean needsRestoreAllTabs() {
return false;
}
}