Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / android_webview / test / shell / src / org / chromium / android_webview / shell / AwShellActivity.java
index b2f79e3..a30a72d 100644 (file)
@@ -10,14 +10,19 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.text.TextUtils;
+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;
@@ -69,6 +74,7 @@ public class AwShellActivity extends Activity {
         }
 
         mAwTestContainerView.getAwContents().loadUrl(new LoadUrlParams(startupUrl));
+        AwContents.setShouldDownloadFavicons();
         mUrlTextView.setText(startupUrl);
     }
 
@@ -76,12 +82,44 @@ public class AwShellActivity extends Activity {
         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 =
@@ -123,7 +161,7 @@ public class AwShellActivity extends Activity {
             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;
                 }
 
@@ -169,4 +207,16 @@ public class AwShellActivity extends Activity {
             }
         });
     }
+
+    @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);
+    }
 }