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

The following examples show how to use android.webkit.WebSettings#setSaveFormData() . 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: LoveVideoView.java    From gank with GNU General Public License v3.0 6 votes vote down vote up
void init() {
    setWebViewClient(new LoveClient());
    setWebChromeClient(new Chrome());
    WebSettings webSettings = getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setAllowFileAccess(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setSaveFormData(false);
    webSettings.setAppCacheEnabled(true);
    webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setUseWideViewPort(true);

   /* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        if (BuildConfig.DEBUG) {
            WebView.setWebContentsDebuggingEnabled(true);
        }
    }*/
}
 
Example 2
Source File: GSIDWebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);

    mInjectJS = new InjectJS(mWebView);

    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 3
Source File: WebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 4
Source File: WebViewActivity.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public void initView() {
    mWebView = (WebView) findViewById(R.id.webview);
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.requestFocus();

    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setSaveFormData(true);
    webSettings.setSupportZoom(true);
    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);

    progressBar = findViewById(R.id.show_request_progress_bar);

}
 
Example 5
Source File: JSAutoLogin.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public JSAutoLogin(Context context, AccountBean ab) {

        this.mContext = context;
        this.mAccountBean = ab;

        this.mWebView = new WebView(mContext);
        mWeiboWebViewClient = new WeiboWebViewClient();
        mWebView.setWebViewClient(mWeiboWebViewClient);

        mInjectJS = new InjectJS(mWebView);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setSaveFormData(true);
        webSettings.setSupportZoom(true);
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    }
 
Example 6
Source File: WebViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initWebView() {
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());
    WebSettings settings = mWebView.getSettings();
    settings.setSavePassword(true);
    settings.setSaveFormData(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setDomStorageEnabled(true);
    settings.setSupportMultipleWindows(false);


    mWebView.loadUrl("http://developer.android.com");
}
 
Example 7
Source File: ByWebView.java    From ByWebView with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
    private void handleSetting() {
        WebSettings ws = mWebView.getSettings();
        // 保存表单数据
        ws.setSaveFormData(true);
        // 是否应该支持使用其屏幕缩放控件和手势缩放
        ws.setSupportZoom(true);
        ws.setBuiltInZoomControls(true);
        ws.setDisplayZoomControls(false);
        // 启动应用缓存
        ws.setAppCacheEnabled(true);
        // 设置缓存模式
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);
        // setDefaultZoom  api19被弃用
        // 网页内容的宽度自适应屏幕
        ws.setLoadWithOverviewMode(true);
        ws.setUseWideViewPort(true);
        // 告诉WebView启用JavaScript执行。默认的是false。
        ws.setJavaScriptEnabled(true);
        //  页面加载好以后,再放开图片
        ws.setBlockNetworkImage(false);
        // 使用localStorage则必须打开
        ws.setDomStorageEnabled(true);
        // 排版适应屏幕
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        } else {
            ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        }
        // WebView是否新窗口打开(加了后可能打不开网页)
//        ws.setSupportMultipleWindows(true);

        // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        /** 设置字体默认缩放大小(改变网页字体大小,setTextSize  api14被弃用)*/
        ws.setTextZoom(100);
    }
 
Example 8
Source File: WebViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initWebView() {
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());
    WebSettings settings = mWebView.getSettings();
    settings.setSavePassword(true);
    settings.setSaveFormData(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportZoom(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setDomStorageEnabled(true);
    settings.setSupportMultipleWindows(false);


    mWebView.loadUrl("http://developer.android.com");
}
 
Example 9
Source File: HTMLViewerActivity.java    From BonjourBrowser with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_html_viewer);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mWebView = findViewById(R.id.webview);
    mLoading = findViewById(R.id.loading);

    mWebView.setWebChromeClient(new ChromeClient());
    mWebView.setWebViewClient(new ViewClient());

    WebSettings s = mWebView.getSettings();
    s.setUseWideViewPort(true);
    s.setSupportZoom(true);
    s.setBuiltInZoomControls(true);
    s.setDisplayZoomControls(false);
    s.setSavePassword(false);
    s.setSaveFormData(false);
    s.setBlockNetworkLoads(true);

    // Javascript is purposely disabled, so that nothing can be
    // automatically run.
    s.setJavaScriptEnabled(false);
    s.setDefaultTextEncodingName("utf-8");

    final Intent intent = getIntent();
    if (intent.hasExtra(Intent.EXTRA_TITLE)) {
        setTitle(intent.getStringExtra(Intent.EXTRA_TITLE));
    }

    mWebView.loadUrl(String.valueOf(intent.getData()));
}
 
Example 10
Source File: OAuthController.java    From twitter-kit-android with Apache License 2.0 5 votes vote down vote up
/**
 * Package private for testing.
 */
void setUpWebView(WebView webView, WebViewClient webViewClient, String url,
                  WebChromeClient webChromeClient) {
    final WebSettings webSettings = webView.getSettings();
    webSettings.setAllowFileAccess(false);
    webSettings.setJavaScriptEnabled(false);
    webSettings.setSaveFormData(false);
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(webViewClient);
    webView.loadUrl(url);
    webView.setVisibility(View.INVISIBLE);
    webView.setWebChromeClient(webChromeClient);
}
 
Example 11
Source File: NinjaWebView.java    From Ninja with Apache License 2.0 4 votes vote down vote up
public synchronized void initPreferences() {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    WebSettings webSettings = getSettings();

    webSettings.setLoadWithOverviewMode(true);
    webSettings.setTextZoom(100);
    webSettings.setUseWideViewPort(true);

    webSettings.setBlockNetworkImage(!sp.getBoolean(context.getString(R.string.sp_images), true));
    webSettings.setJavaScriptEnabled(sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setJavaScriptCanOpenWindowsAutomatically(sp.getBoolean(context.getString(R.string.sp_javascript), true));
    webSettings.setGeolocationEnabled(sp.getBoolean(context.getString(R.string.sp_location), true));
    webSettings.setSupportMultipleWindows(sp.getBoolean(context.getString(R.string.sp_multiple_windows), false));
    webSettings.setSaveFormData(sp.getBoolean(context.getString(R.string.sp_passwords), true));

    boolean textReflow = sp.getBoolean(context.getString(R.string.sp_text_reflow), true);
    if (textReflow) {
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            try {
                webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
            } catch (Exception e) {}
        }
    } else {
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
    }

    int userAgent = Integer.valueOf(sp.getString(context.getString(R.string.sp_user_agent), "0"));
    if (userAgent == 1) {
        webSettings.setUserAgentString(BrowserUnit.UA_DESKTOP);
    } else if (userAgent == 2) {
        webSettings.setUserAgentString(sp.getString(context.getString(R.string.sp_user_agent_custom), userAgentOriginal));
    } else {
        webSettings.setUserAgentString(userAgentOriginal);
    }

    int mode = Integer.valueOf(sp.getString(context.getString(R.string.sp_rendering), "0"));
    initRendering(mode);

    webViewClient.enableAdBlock(sp.getBoolean(context.getString(R.string.sp_ad_block), true));
}
 
Example 12
Source File: WebSettingsCompat.java    From Android_Skin_2.0 with Apache License 2.0 4 votes vote down vote up
@Override
public void setSaveFormData(WebSettings settings, boolean save) {
	settings.setSaveFormData(save);
}
 
Example 13
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 14
Source File: OAuthActivity.java    From iBeebo with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauth_activity_layout);

    this.mIsAuthPro = getIntent().getBooleanExtra(Ext.KEY_IS_HACK, false);
    this.mAccountBean = getIntent().getParcelableExtra(Ext.KEY_ACCOUNT);

    Toolbar mToolbar = ViewUtility.findViewById(this, R.id.oauthToolbar);

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbar.setNavigationOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });

    getSupportActionBar().setTitle(mIsAuthPro ? R.string.oauth_senior_title : R.string.oauth_normal_title);

    mWebView = (WebView) findViewById(R.id.webView);
    mInjectJS = new InjectJS(mWebView);

    mWebView.setWebViewClient(new WeiboWebViewClient());

    mCircleProgressBar = (CircleProgressBar) findViewById(R.id.oauthProgress);

    WebSettings settings = mWebView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSaveFormData(true);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    refresh();
}
 
Example 15
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 16
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 17
Source File: WebViewActivity.java    From CloudReader with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
    private void initWebView() {
        WebSettings ws = webView.getSettings();
        // 网页内容的宽度适配
        ws.setLoadWithOverviewMode(true);
        ws.setUseWideViewPort(true);
        // 保存表单数据
        ws.setSaveFormData(true);
        // 是否应该支持使用其屏幕缩放控件和手势缩放
        ws.setSupportZoom(true);
        ws.setBuiltInZoomControls(true);
        ws.setDisplayZoomControls(false);
        // 启动应用缓存
        ws.setAppCacheEnabled(true);
        // 设置缓存模式
        ws.setCacheMode(WebSettings.LOAD_DEFAULT);
        // 告诉WebView启用JavaScript执行。默认的是false。
        ws.setJavaScriptEnabled(true);
        //  页面加载好以后,再放开图片
        ws.setBlockNetworkImage(false);
        // 使用localStorage则必须打开
        ws.setDomStorageEnabled(true);
        // 排版适应屏幕
        ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
        // WebView是否新窗口打开(加了后可能打不开网页)
//        ws.setSupportMultipleWindows(true);

        // webview从5.0开始默认不允许混合模式,https中不能加载http资源,需要设置开启。
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            ws.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        /** 设置字体默认缩放大小(改变网页字体大小,setTextSize  api14被弃用)*/
        ws.setTextZoom(100);

        mWebChromeClient = new MyWebChromeClient(this);
        webView.setWebChromeClient(mWebChromeClient);
        // 与js交互
        webView.addJavascriptInterface(new ImageClickInterface(this), "injectedObject");
        webView.setWebViewClient(new MyWebViewClient(this));
        webView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                return handleLongImage();
            }
        });
    }
 
Example 18
Source File: BaseWebFragment.java    From Android-Application-ZJB with Apache License 2.0 4 votes vote down vote up
protected void initialize() {
    //添加H5的基本参数
    UrlParserManager.getInstance().addParams(UrlParserManager.METHOD_CHANNEL, "app");
    mParamBuilder = getParams();
    mUrl = UrlParserManager.getInstance().parsePlaceholderUrl(mParamBuilder.getUrl());

    mWebView.setProgressbar(mProgressBar);
    WebSettings ws = mWebView.getSettings();
    ws.setBuiltInZoomControls(false); // 缩放
    ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    ws.setUseWideViewPort(true);
    ws.setLoadWithOverviewMode(true);
    ws.setSaveFormData(true);
    ws.setDomStorageEnabled(true);//开启 database storage API 功能
    //设置自定义UserAgent
    String agent = ws.getUserAgentString();
    ws.setUserAgentString(createUserAgent(agent));
    mWebView.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) -> {
        if (url != null && url.startsWith("http://"))
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    });
    mWebView.loadUrl(mUrl);
    mWebView.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            //表示按返回键时的操作
            if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
                mWebView.goBack();   //后退
                return true;    //已处理
            }
        }
        return false;
    });

    mWebView.setDefaultHandler(new DefaultHandler());
    //注册分享方法
    mWebView.registerHandler("shareJs", (data, function) -> {
        try {
            if (!TextUtils.isEmpty(data)) {
                WebShareBean shareBean = GsonUtil.fromJson(data, WebShareBean.class);
                shareJs(shareBean);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

    //注册设置标题方法
    mWebView.registerHandler("webTitleJs", ((data, function) -> webTitleJs(data)));
    //注册设置分享按钮方法
    mWebView.registerHandler("disableShareJs", ((data, function) -> {
        if ("true".equals(data)) {
            disableShareJs(true);
        } else {
            disableShareJs(false);
        }

    }));

    //注册微信支付
    mWebView.registerHandler("wxPayJs", ((data, function) -> wxPayJs(data)));
}
 
Example 19
Source File: AbsWebActivity.java    From Android-Application-ZJB with Apache License 2.0 4 votes vote down vote up
protected void initView() {
    //添加H5的基本参数
    UrlParserManager.getInstance().addParams(UrlParserManager.METHOD_CHANNEL, "app");
    mParamBuilder = getParams();
    mUrl = UrlParserManager.getInstance().parsePlaceholderUrl(mParamBuilder.getUrl());

    mWebView.setProgressbar(mProgressBar);
    WebSettings ws = mWebView.getSettings();
    ws.setBuiltInZoomControls(false); // 缩放
    ws.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    ws.setUseWideViewPort(true);
    ws.setLoadWithOverviewMode(true);
    ws.setSaveFormData(true);
    ws.setDomStorageEnabled(true);//开启 database storage API 功能
    //设置自定义UserAgent
    String agent = ws.getUserAgentString();
    ws.setUserAgentString(createUserAgent(agent));
    mWebView.setDownloadListener((url, userAgent, contentDisposition, mimeType, contentLength) -> {
        if (url != null && url.startsWith("http://"))
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    });
    mWebView.loadUrl(mUrl);
    mWebView.setOnKeyListener((v, keyCode, event) -> {
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            //表示按返回键时的操作
            if (keyCode == KeyEvent.KEYCODE_BACK && mWebView.canGoBack()) {
                mWebView.goBack();   //后退
                return true;    //已处理
            }
        }
        return false;
    });

    mWebView.setDefaultHandler(new DefaultHandler());
    //注册分享方法
    mWebView.registerHandler("shareJs", (data, function) -> {
        try {
            if (!TextUtils.isEmpty(data)) {
                WebShareBean shareBean = GsonUtil.fromJson(data, WebShareBean.class);
                shareJs(shareBean);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

    //注册设置标题方法
    mWebView.registerHandler("webTitleJs", ((data, function) -> webTitleJs(data)));
    //注册设置分享按钮方法
    mWebView.registerHandler("disableShareJs", ((data, function) -> {
        if ("true".equals(data)) {
            disableShareJs(true);
        } else {
            disableShareJs(false);
        }

    }));

    //注册微信支付
    mWebView.registerHandler("wxPayJs", ((data, function) -> wxPayJs(data)));
}
 
Example 20
Source File: SamlWebViewDialog.java    From Cirrus_depricated with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);
    
    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog,
            container, false);  // null parent view because it will go in the dialog layout
    
    if (mSsoWebView == null) {
        // initialize the WebView
        mSsoWebView = new SsoWebView(getActivity().getApplicationContext());
        mSsoWebView.setFocusable(true);
        mSsoWebView.setFocusableInTouchMode(true);
        mSsoWebView.setClickable(true);
        
        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setLoadWithOverviewMode(false);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(MainApp.getUserAgent());
        webSettings.setSaveFormData(false);
        
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();
        
        mSsoWebView.loadUrl(mInitialUrl);
    }
    
    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);
    
    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, 
            RelativeLayout.LayoutParams.WRAP_CONTENT
            );
    ssoRootView.addView(mSsoWebView, layoutParams);
    ssoRootView.requestLayout();
    
    return ssoRootView;
}