Home | History | Annotate | Download | only in browser
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 package com.android.browser;
     17 
     18 import android.content.Context;
     19 import android.content.pm.PackageManager;
     20 import android.util.AttributeSet;
     21 import android.view.View;
     22 import android.webkit.WebView;
     23 
     24 /**
     25  * Web view factory class for creating {@link BrowserWebView}'s.
     26  */
     27 public class BrowserWebViewFactory implements WebViewFactory {
     28 
     29     private final Context mContext;
     30 
     31     public BrowserWebViewFactory(Context context) {
     32         mContext = context;
     33     }
     34 
     35     protected WebView instantiateWebView(AttributeSet attrs, int defStyle,
     36             boolean privateBrowsing) {
     37         return new BrowserWebView(mContext, attrs, defStyle, privateBrowsing);
     38     }
     39 
     40     @Override
     41     public WebView createSubWebView(boolean privateBrowsing) {
     42         return createWebView(privateBrowsing);
     43     }
     44 
     45     @Override
     46     public WebView createWebView(boolean privateBrowsing) {
     47         WebView w = instantiateWebView(null, android.R.attr.webViewStyle, privateBrowsing);
     48         initWebViewSettings(w);
     49         return w;
     50     }
     51 
     52     protected void initWebViewSettings(WebView w) {
     53         w.setScrollbarFadingEnabled(true);
     54         w.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
     55         w.setMapTrackballToArrowKeys(false); // use trackball directly
     56         // Enable the built-in zoom
     57         w.getSettings().setBuiltInZoomControls(true);
     58         final PackageManager pm = mContext.getPackageManager();
     59         boolean supportsMultiTouch =
     60                 pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)
     61                 || pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT);
     62         w.getSettings().setDisplayZoomControls(!supportsMultiTouch);
     63 
     64         // Add this WebView to the settings observer list and update the
     65         // settings
     66         final BrowserSettings s = BrowserSettings.getInstance();
     67         s.startManagingSettings(w.getSettings());
     68     }
     69 
     70 }
     71