-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.android_webview.shell;
import android.app.Activity;
-import android.content.Intent;
import android.content.Context;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
-import android.util.Log;
+import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
+import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
+import android.webkit.WebChromeClient;
import android.widget.EditText;
+import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
-import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.AwBrowserContext;
+import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwDevToolsServer;
-import org.chromium.android_webview.AwLayoutSizer;
+import org.chromium.android_webview.AwSettings;
import org.chromium.android_webview.test.AwTestContainerView;
import org.chromium.android_webview.test.NullContentsClient;
import org.chromium.content.browser.LoadUrlParams;
-/*
+/**
* This is a lightweight activity for tests that only require WebView functionality.
*/
public class AwShellActivity extends Activity {
- private final static String PREFERENCES_NAME = "AwShellPrefs";
- private final static String INITIAL_URL = "about:blank";
+ private static final String PREFERENCES_NAME = "AwShellPrefs";
+ private static final String INITIAL_URL = "about:blank";
private AwBrowserContext mBrowserContext;
private AwDevToolsServer mDevToolsServer;
private AwTestContainerView mAwTestContainerView;
}
mAwTestContainerView.getAwContents().loadUrl(new LoadUrlParams(startupUrl));
+ AwContents.setShouldDownloadFavicons();
mUrlTextView.setText(startupUrl);
}
private AwTestContainerView createAwTestContainerView() {
+ AwBrowserProcess.start(this);
AwTestContainerView testContainerView = new AwTestContainerView(this);
AwContentsClient awContentsClient = new NullContentsClient() {
+ private View mCustomView;
+
@Override
public void onPageStarted(String url) {
if (mUrlTextView != null) {
mUrlTextView.setText(url);
}
}
+
+ @Override
+ public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
+ getWindow().setFlags(
+ WindowManager.LayoutParams.FLAG_FULLSCREEN,
+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
+
+ getWindow().addContentView(view,
+ new FrameLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ Gravity.CENTER));
+ mCustomView = view;
+ }
+
+ @Override
+ public void onHideCustomView() {
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ FrameLayout decorView = (FrameLayout) getWindow().getDecorView();
+ decorView.removeView(mCustomView);
+ mCustomView = null;
+ }
+
+ @Override
+ public boolean shouldOverrideKeyEvent(KeyEvent event) {
+ if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
+ return true;
+ }
+ return false;
+ }
};
SharedPreferences sharedPreferences =
if (mBrowserContext == null) {
mBrowserContext = new AwBrowserContext(sharedPreferences);
}
+ final AwSettings awSettings = new AwSettings(this /*context*/,
+ false /*isAccessFromFileURLsGrantedByDefault*/, true /*supportsLegacyQuirks*/);
testContainerView.initialize(new AwContents(mBrowserContext, testContainerView,
testContainerView.getInternalAccessDelegate(),
- awContentsClient, false, new AwLayoutSizer(), true));
+ awContentsClient, awSettings));
testContainerView.getAwContents().getSettings().setJavaScriptEnabled(true);
if (mDevToolsServer == null) {
mDevToolsServer = new AwDevToolsServer();
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((actionId != EditorInfo.IME_ACTION_GO) && (event == null ||
event.getKeyCode() != KeyEvent.KEYCODE_ENTER ||
- event.getKeyCode() != KeyEvent.ACTION_DOWN)) {
+ event.getAction() != KeyEvent.ACTION_DOWN)) {
return false;
}
@Override
public void onClick(View v) {
if (mAwTestContainerView.getContentViewCore().canGoForward()) {
- mAwTestContainerView.getContentViewCore().goForward();
+ mAwTestContainerView.getContentViewCore().goForward();
}
}
});
}
+
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ if (mAwTestContainerView.getContentViewCore().canGoBack()) {
+ mAwTestContainerView.getContentViewCore().goBack();
+ return true;
+ }
+ }
+
+ return super.onKeyUp(keyCode, event);
+ }
}