Java Code Examples for android.webkit.WebSettings#setMediaPlaybackRequiresUserGesture()

The following examples show how to use android.webkit.WebSettings#setMediaPlaybackRequiresUserGesture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SumerianConnector.java    From amazon-sumerian-arcore-starter-app with Apache License 2.0 6 votes vote down vote up
SumerianConnector(WebView webView, Session session, GLSurfaceView surfaceView) {
    mWebView = webView;
    mSession = session;
    mSurfaceView = surfaceView;

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setMediaPlaybackRequiresUserGesture(false);
    mWebView.addJavascriptInterface(new BridgeInterface(), "Android");

    this.mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            view.setBackgroundColor(0x00000000);
        }
    });
}
 
Example 2
Source File: YouTubePlayerWebView.java    From android-inline-youtube-view with Apache License 2.0 6 votes vote down vote up
/**
 * Initialises YoutubeWebView with given videoId and youtubeListener
 */
@SuppressLint("SetJavaScriptEnabled")
private void initWebView(String webViewUrl) {
    WebSettings set = this.getSettings();
    set.setJavaScriptEnabled(true);
    set.setUseWideViewPort(true);
    set.setLoadWithOverviewMode(true);
    set.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    set.setCacheMode(WebSettings.LOAD_DEFAULT);
    set.setPluginState(WebSettings.PluginState.ON_DEMAND);
    set.setAllowContentAccess(true);
    set.setAllowFileAccess(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        set.setMediaPlaybackRequiresUserGesture(false);
    }
    this.setLayerType(View.LAYER_TYPE_NONE, null);
    this.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
    this.loadUrl(webViewUrl);

    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        setWebContentsDebuggingEnabled(true);
    }

    this.setWebViewClient(initWebViewClient());
}
 
Example 3
Source File: MainFragment.java    From traccar-manager-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    if ((getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }

    getWebView().setWebViewClient(webViewClient);
    getWebView().setWebChromeClient(webChromeClient);
    getWebView().addJavascriptInterface(new AppInterface(), "appInterface");

    WebSettings webSettings = getWebView().getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setMediaPlaybackRequiresUserGesture(false);

    String url = PreferenceManager.getDefaultSharedPreferences(
            getActivity()).getString(MainActivity.PREFERENCE_URL, null);

    getWebView().loadUrl(url);
}
 
Example 4
Source File: WebViewActivity.java    From mattermost-android-classic with Apache License 2.0 5 votes vote down vote up
protected void initWebView(WebView view) {
    webView = view;
    setProgressBarVisibility(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }

    WebSettings settings = view.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setUserAgentString(settings.getUserAgentString() + " Web-Atoms-Mobile-WebView");
    settings.setDatabaseEnabled(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    final File dir = this.getExternalCacheDir();
    settings.setAppCacheMaxSize(1024*1024*20);
    settings.setAppCachePath(dir.getAbsolutePath());
    settings.setAllowFileAccess(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    view.setDownloadListener(getDownloadListener());

    CookieManager cookies = CookieManager.getInstance();
    cookies.setAcceptCookie(true);

    setWebViewClient(view);
    setWebChromeClient(view);
}
 
Example 5
Source File: MainActivity.java    From chappiecast with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    // Set by <content src="index.html" /> in config.xml
    loadUrl(launchUrl);
    WebSettings ws = ((SystemWebView)super.appView.getView()).getSettings();
    ws.setMediaPlaybackRequiresUserGesture(false);
}
 
Example 6
Source File: JSWebView.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint({"SetJavaScriptEnabled", "NewApi", "ObsoleteSdkInt"})
public void initializeSettings(WebSettings settings) {
    settings.setJavaScriptEnabled(true);
    addJavascriptInterface(new JavaScriptUtil(), "DappJsBridge");
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        settings.setAppCacheMaxSize(Long.MAX_VALUE);
    }
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        settings.setEnableSmoothTransition(true);
    }
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN) {
        settings.setMediaPlaybackRequiresUserGesture(true);
    }

    WebView.setWebContentsDebuggingEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setAppCacheEnabled(true);
    settings.setCacheMode(WebSettings.LOAD_DEFAULT);
    settings.setLoadsImagesAutomatically(true);
    settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
    settings.setDatabaseEnabled(true);
    settings.setDisplayZoomControls(false);
    settings.setAllowContentAccess(true);
    settings.setAllowFileAccess(false);
    settings.setRenderPriority(WebSettings.RenderPriority.LOW);
    setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    settings.setDefaultTextEncodingName("utf-8");
    settings.setAllowFileAccessFromFileURLs(false);
    settings.setAllowUniversalAccessFromFileURLs(false);
    // 特别注意:5.1以上默认禁止了https和http混用,以下方式是开启
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
    }
}
 
Example 7
Source File: Bridge.java    From OsmGo with MIT License 5 votes vote down vote up
/**
 * Initialize the WebView, setting required flags
 */
private void initWebView() {
  WebSettings settings = webView.getSettings();
  settings.setJavaScriptEnabled(true);
  settings.setDomStorageEnabled(true);
  settings.setGeolocationEnabled(true);
  settings.setDatabaseEnabled(true);
  settings.setAppCacheEnabled(true);
  settings.setMediaPlaybackRequiresUserGesture(false);
  settings.setJavaScriptCanOpenWindowsAutomatically(true);
  if (Config.getBoolean("android.allowMixedContent", false)) {
    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
  }
  String backgroundColor = Config.getString("android.backgroundColor" , Config.getString("backgroundColor", null));
  try {
    if (backgroundColor != null) {
      webView.setBackgroundColor(Color.parseColor(backgroundColor));
    }
  } catch (IllegalArgumentException ex) {
    Log.d(LogUtils.getCoreTag(), "WebView background color not applied");
  }
  boolean defaultDebuggable = false;
  if (isDevMode()) {
    defaultDebuggable = true;
  }

  WebView.setWebContentsDebuggingEnabled(Config.getBoolean("android.webContentsDebuggingEnabled", defaultDebuggable));
}
 
Example 8
Source File: WebPlayerView.java    From mv-android-client with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    mPlayer = new WebPlayer(this);

    setBackgroundColor(Color.BLACK);

    enableJavascript();

    WebSettings webSettings = getSettings();
    webSettings.setAllowContentAccess(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setAppCacheEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(context.getDir("database", Context.MODE_PRIVATE).getPath());
    webSettings.setDomStorageEnabled(true);
    webSettings.setLoadsImagesAutomatically(true);
    webSettings.setSupportMultipleWindows(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        webSettings.setAllowFileAccessFromFileURLs(true);
        webSettings.setAllowUniversalAccessFromFileURLs(true);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            webSettings.setMediaPlaybackRequiresUserGesture(false);
        }
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
        webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
    }

    setWebChromeClient(new ChromeClient());
    setWebViewClient(new ViewClient());
}
 
Example 9
Source File: AjaxWebView.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
private static WebView createAjaxWebView(AjaxParams params, Handler handler) {
    WebView webView = new WebView(params.context.getApplicationContext());
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setBlockNetworkImage(true);
    settings .setMediaPlaybackRequiresUserGesture(false);
    settings.setUserAgentString(params.getUserAgent());
    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    if (params.isSniff()) {
        webView.setWebViewClient(new SnifferWebClient(params, handler));
    } else {
        webView.setWebViewClient(new HtmlWebViewClient(handler));
        webView.addJavascriptInterface(new JavaInjectMethod(handler), "OUTHTML");
    }
    switch (params.getRequestMethod()) {
        case POST:
            webView.postUrl(params.url, params.postData);
            break;
        case GET:
        case DEFAULT:
            webView.loadUrl(params.url, params.headerMap);
            break;
    }
    return webView;
}
 
Example 10
Source File: SystemWebViewEngine.java    From keemob with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 11
Source File: SystemWebViewEngine.java    From keemob with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 12
Source File: ClientWebView.java    From habpanelviewer with GNU General Public License v3.0 4 votes vote down vote up
void updateFromPreferences(SharedPreferences prefs) {
    String theme = prefs.getString(Constants.PREF_THEME, "dark");
    mDarkTheme = "dark".equals(theme);
    mImmersive = prefs.getBoolean(Constants.PREF_IMMERSIVE, false);
    mTrackBrowserConnection = prefs.getBoolean(Constants.PREF_TRACK_BROWSER_CONNECTION, false);
    mLogBrowserMsg = prefs.getBoolean(Constants.PREF_LOG_BROWSER_MESSAGES, false);
    mAllowWebRTC = prefs.getBoolean(Constants.PREF_ALLOW_WEBRTC, false);

    boolean isDesktop = prefs.getBoolean(Constants.PREF_DESKTOP_MODE, false);
    boolean isJavascript = prefs.getBoolean(Constants.PREF_JAVASCRIPT, false);
    boolean isAutoplay = prefs.getBoolean(Constants.PREF_AUTOPLAY_VIDEO, false);
    boolean cacheDeactivated = prefs.getBoolean(Constants.PREF_DISABLE_CACHE, false);

    mDraggingPrevented = prefs.getBoolean(Constants.PREF_PREVENT_DRAGGING, false);

    WebSettings webSettings = getSettings();
    webSettings.setUseWideViewPort(isDesktop);
    webSettings.setLoadWithOverviewMode(isDesktop);
    webSettings.setJavaScriptEnabled(isJavascript);
    webSettings.setCacheMode(cacheDeactivated ? WebSettings.LOAD_NO_CACHE : WebSettings.LOAD_DEFAULT);
    webSettings.setMediaPlaybackRequiresUserGesture(!isAutoplay);

    boolean loadStartUrl = false;
    boolean reloadUrl = false;
    if (mStartPage == null || !mStartPage.equalsIgnoreCase(prefs.getString(Constants.PREF_START_URL, ""))) {
        mStartPage = prefs.getString(Constants.PREF_START_URL, "");
        loadStartUrl = true;
    }
    loadStartUrl = loadStartUrl || isShowingErrorPage();

    if (mServerURL == null || !mServerURL.equalsIgnoreCase(prefs.getString(Constants.PREF_SERVER_URL, "!$%"))) {
        mServerURL = prefs.getString(Constants.PREF_SERVER_URL, "");
        loadStartUrl = loadStartUrl || mStartPage == null || mStartPage.isEmpty();
    }
    if (mAllowMixedContent != prefs.getBoolean(Constants.PREF_ALLOW_MIXED_CONTENT, false)) {
        mAllowMixedContent = !mAllowMixedContent;
        reloadUrl = true;
    }

    if (mHwAccelerated != prefs.getBoolean(Constants.PREF_HW_ACCELERATED, false)) {
        mHwAccelerated = !mHwAccelerated;

        if (mHwAccelerated) {
            setLayerType(LAYER_TYPE_HARDWARE, null);
        } else {
            setLayerType(LAYER_TYPE_SOFTWARE, null);
        }
    }


    webSettings.setMixedContentMode(mAllowMixedContent ? WebSettings.MIXED_CONTENT_ALWAYS_ALLOW : WebSettings.MIXED_CONTENT_NEVER_ALLOW);

    if (mNetworkTracker.isConnected()) {
        if (loadStartUrl) {
            loadStartUrl();
        } else if (reloadUrl) {
            reload();
        }
    } else {
        showHtml(getContext().getString(R.string.waitingNetwork),
                getContext().getString(R.string.notConnectedReloadPendingHTML));
    }
}
 
Example 13
Source File: WebView.java    From unity-ads-android with Apache License 2.0 4 votes vote down vote up
public WebView(Context context) {
	super(context);
	WebSettings settings = getSettings();

	if(Build.VERSION.SDK_INT >= 16) {
		settings.setAllowFileAccessFromFileURLs(true);
		settings.setAllowUniversalAccessFromFileURLs(true);
	}

	if (Build.VERSION.SDK_INT >= 19) {
		try {
			_evaluateJavascript = android.webkit.WebView.class.getMethod("evaluateJavascript", String.class, ValueCallback.class);
		} catch(NoSuchMethodException e) {
			DeviceLog.exception("Method evaluateJavascript not found", e);
			_evaluateJavascript = null;
		}
	}

	settings.setAppCacheEnabled(false);
	settings.setBlockNetworkImage(false);
	settings.setBlockNetworkLoads(false);
	settings.setBuiltInZoomControls(false);
	settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
	settings.setDatabaseEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setDisplayZoomControls(false);
	}

	settings.setDomStorageEnabled(false);

	if(Build.VERSION.SDK_INT >= 11) {
		settings.setEnableSmoothTransition(false);
	}

	settings.setGeolocationEnabled(false);
	settings.setJavaScriptCanOpenWindowsAutomatically(false);
	settings.setJavaScriptEnabled(true);
	settings.setLightTouchEnabled(false);
	settings.setLoadWithOverviewMode(false);
	settings.setLoadsImagesAutomatically(true);

	if(Build.VERSION.SDK_INT >= 17) {
		settings.setMediaPlaybackRequiresUserGesture(false);
	}

	if(Build.VERSION.SDK_INT >= 21) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}

	settings.setNeedInitialFocus(true);
	settings.setPluginState(WebSettings.PluginState.OFF);
	settings.setRenderPriority(WebSettings.RenderPriority.NORMAL);
	settings.setSaveFormData(false);
	settings.setSavePassword(false);
	settings.setSupportMultipleWindows(false);
	settings.setSupportZoom(false);
	settings.setUseWideViewPort(true);

	setHorizontalScrollBarEnabled(false);
	setVerticalScrollBarEnabled(false);
	setInitialScale(0);
	setBackgroundColor(Color.TRANSPARENT);
	ViewUtilities.setBackground(this, new ColorDrawable(Color.TRANSPARENT));
	setBackgroundResource(0);

	addJavascriptInterface(new WebViewBridgeInterface(), "webviewbridge");
}
 
Example 14
Source File: NestedWebview.java    From SimplicityBrowser with MIT License 4 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled"})
public void initializeSettings(){
    boolean isTablet = getResources().getBoolean(R.bool.isTablet);
    String lang = Locale.getDefault().getDisplayLanguage();
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(true);
    cookieManager.setAcceptThirdPartyCookies(NestedWebview.this, true);
    WebSettings mWebSettings = getSettings();
    mWebSettings.setJavaScriptEnabled(true);
    mWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    mWebSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    mWebSettings.setBuiltInZoomControls(true);
    mWebSettings.setDisplayZoomControls(false);
    mWebSettings.setMediaPlaybackRequiresUserGesture(false);
    if(isTablet){
        mWebSettings.setUserAgentString("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Simplicity/57.0.3098.116");
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setUseWideViewPort(true);
    }else{
        mWebSettings.setUserAgentString(null);
        mWebSettings.setLoadWithOverviewMode(true);
        mWebSettings.setUseWideViewPort(true);
    }
    mWebSettings.setAppCacheEnabled(true);
    mWebSettings.setDatabaseEnabled(true);
    if (UserPreferences.getBoolean("enable_location", false)) {
        mWebSettings.setGeolocationEnabled(true);
    } else {
        mWebSettings.setGeolocationEnabled(false);
    }
    if(UserPreferences.getBoolean("lite_mode", false)){
        mWebSettings.setLoadsImagesAutomatically(false);
    }else{
        mWebSettings.setLoadsImagesAutomatically(true);
    }
    mWebSettings.setAllowFileAccessFromFileURLs(true);
    mWebSettings.setAllowUniversalAccessFromFileURLs(true);
    mWebSettings.setDomStorageEnabled(true);
    mWebSettings.setTextZoom(Integer.parseInt(UserPreferences.getInstance(WEB_ACTIVITY).getFont()));
    addJavascriptInterface(new ReaderHandler(SimplicityApplication.getContextOfApplication(), MainActivity.getMainActivity()), "simplicity_reader");
    if(UserPreferences.getBoolean("facebook_photos", false)){
        addJavascriptInterface(new ImageInterface(WEB_ACTIVITY), "Photos");
    }

}
 
Example 15
Source File: CordovaWebView.java    From L.TileLayer.Cordova with MIT License 4 votes vote down vote up
static void setMediaPlaybackRequiresUserGesture(WebSettings settings, boolean value) {
    settings.setMediaPlaybackRequiresUserGesture(value);
}
 
Example 16
Source File: LightningView.java    From browser with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
public void initializeSettings(WebSettings settings, Context context) {
	//setPageCacheCapacity2(settings);
	if (API < 18) {
		settings.setAppCacheMaxSize(Long.MAX_VALUE);
	}
	if (API < 17) {
		settings.setEnableSmoothTransition(true);
	}
	if (API > 16) {
		settings.setMediaPlaybackRequiresUserGesture(true);
	}
	if (API >= Build.VERSION_CODES.LOLLIPOP && !mBrowserController.isIncognito()) {
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
	} else if (API >= Build.VERSION_CODES.LOLLIPOP) {
		// We're in Incognito mode, reject
		settings.setMixedContentMode(WebSettings.MIXED_CONTENT_NEVER_ALLOW);
	}
	settings.setDomStorageEnabled(true);
	settings.setAppCacheEnabled(true);
	settings.setCacheMode(WebSettings.LOAD_DEFAULT);
	settings.setDatabaseEnabled(true);
	settings.setSupportZoom(true);
	settings.setBuiltInZoomControls(true);
	settings.setDisplayZoomControls(false);
	settings.setAllowContentAccess(true);
	settings.setAllowFileAccess(true);
	settings.setDefaultTextEncodingName("utf-8");
	if (API > 16) {
		settings.setAllowFileAccessFromFileURLs(false);
		settings.setAllowUniversalAccessFromFileURLs(false);
	}

	settings.setAppCachePath(context.getDir("appcache", 0).getPath());
	settings.setGeolocationDatabasePath(context.getDir("geolocation", 0).getPath());
	if (API < Build.VERSION_CODES.KITKAT) {
		settings.setDatabasePath(context.getDir("databases", 0).getPath());
	}


}
 
Example 17
Source File: CordovaWebView.java    From bluemix-parking-meter with MIT License 4 votes vote down vote up
static void setMediaPlaybackRequiresUserGesture(WebSettings settings, boolean value) {
    settings.setMediaPlaybackRequiresUserGesture(value);
}
 
Example 18
Source File: SystemWebViewEngine.java    From pychat with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 19
Source File: SystemWebViewEngine.java    From lona with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}
 
Example 20
Source File: SystemWebViewEngine.java    From countly-sdk-cordova with MIT License 4 votes vote down vote up
@SuppressLint({"NewApi", "SetJavaScriptEnabled"})
@SuppressWarnings("deprecation")
private void initWebViewSettings() {
    webView.setInitialScale(0);
    webView.setVerticalScrollBarEnabled(false);
    // Enable JavaScript
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    String manufacturer = android.os.Build.MANUFACTURER;
    LOG.d(TAG, "CordovaWebView is running on device made by: " + manufacturer);

    //We don't save any form data in the application
    settings.setSaveFormData(false);
    settings.setSavePassword(false);

    // Jellybean rightfully tried to lock this down. Too bad they didn't give us a whitelist
    // while we do this
    settings.setAllowUniversalAccessFromFileURLs(true);
    settings.setMediaPlaybackRequiresUserGesture(false);

    // Enable database
    // We keep this disabled because we use or shim to get around DOM_EXCEPTION_ERROR_16
    String databasePath = webView.getContext().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    settings.setDatabaseEnabled(true);
    settings.setDatabasePath(databasePath);


    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        enableRemoteDebugging();
    }

    settings.setGeolocationDatabasePath(databasePath);

    // Enable DOM storage
    settings.setDomStorageEnabled(true);

    // Enable built-in geolocation
    settings.setGeolocationEnabled(true);

    // Enable AppCache
    // Fix for CB-2282
    settings.setAppCacheMaxSize(5 * 1048576);
    settings.setAppCachePath(databasePath);
    settings.setAppCacheEnabled(true);

    // Fix for CB-1405
    // Google issue 4641
    String defaultUserAgent = settings.getUserAgentString();

    // Fix for CB-3360
    String overrideUserAgent = preferences.getString("OverrideUserAgent", null);
    if (overrideUserAgent != null) {
        settings.setUserAgentString(overrideUserAgent);
    } else {
        String appendUserAgent = preferences.getString("AppendUserAgent", null);
        if (appendUserAgent != null) {
            settings.setUserAgentString(defaultUserAgent + " " + appendUserAgent);
        }
    }
    // End CB-3360

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                settings.getUserAgentString();
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }
    // end CB-1405
}