Exemplo n.º 1
0
 public static void initializeSettings(WebSettings settings, Context context) {
   settings.setJavaScriptEnabled(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   settings.setUserAgentString(settings.getUserAgentString() + DB.USER_AGENT);
   settings.setSupportMultipleWindows(true);
   settings.setSaveFormData(false);
   settings.setSavePassword(false); // 设置为true,系统会弹出AlertDialog确认框
   if (API < 18) {
     settings.setAppCacheMaxSize(Long.MAX_VALUE);
   }
   if (API < 17) {
     settings.setEnableSmoothTransition(true);
   }
   if (API < 19) {
     settings.setDatabasePath(context.getFilesDir().getAbsolutePath() + "/databases");
   }
   settings.setDomStorageEnabled(true);
   settings.setAppCachePath(context.getCacheDir().toString());
   settings.setAppCacheEnabled(true);
   settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
   settings.setGeolocationDatabasePath(context.getCacheDir().getAbsolutePath());
   settings.setAllowFileAccess(true);
   settings.setDatabaseEnabled(true);
   settings.setSupportZoom(true);
   settings.setBuiltInZoomControls(true);
   settings.setDisplayZoomControls(false);
   settings.setAllowContentAccess(true);
   settings.setDefaultTextEncodingName("utf-8");
   /*if (API > 16) {
   	settings.setAllowFileAccessFromFileURLs(false);
   	settings.setAllowUniversalAccessFromFileURLs(false);
   }*/
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String targetURL = "https://m.facebook.com/";

    if (getIntent().getExtras() != null) {
      String url = getIntent().getExtras().getString("url", "");
      if (!"".equals(url)) {
        targetURL = url;
      }
    }

    WakeupManager.updateNotificationSystem(this);

    webview = new WebView(this);
    webview.setWebViewClient(new WebViewClient());
    webview.loadData("<h1>" + getString(R.string.request_pending) + "</h1>", "text/html", "UTF-8");
    webview.setWebViewClient(new WebViewClient());
    WebSettings webSettings = webview.getSettings();
    webSettings.setBlockNetworkImage(false);
    webSettings.setUserAgentString(getString(R.string.app_name));
    webview.loadUrl(targetURL);
    setContentView(webview);
  }
Exemplo n.º 3
0
  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));
  }
Exemplo n.º 4
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.d(TAG, "onCreateView");

    // Inflate layout of the dialog
    View rootView =
        inflater.inflate(
            R.layout.sso_dialog,
            container,
            false); // null parent view because it will go in the dialog layout
    mSsoWebView = (WebView) rootView.findViewById(R.id.sso_webview);

    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);

    if (savedInstanceState == null) {
      Log_OC.d(TAG, "   initWebView start");
      CookieManager cookieManager = CookieManager.getInstance();
      cookieManager.setAcceptCookie(true);
      cookieManager.removeAllCookie();
      mSsoWebView.loadUrl(mInitialUrl);

    } else {
      Log_OC.d(TAG, "   restoreWebView start");
      WebBackForwardList history =
          mSsoWebView.restoreState(savedInstanceState.getBundle(KEY_WEBVIEW_STATE));
      if (history == null) {
        Log_OC.e(TAG, "Error restoring WebView state ; back to starting URL");
        mSsoWebView.loadUrl(mInitialUrl);
      }
    }

    WebSettings webSettings = mSsoWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    webSettings.setBuiltInZoomControls(true);
    webSettings.setLoadWithOverviewMode(false);
    webSettings.setSavePassword(false);
    webSettings.setUserAgentString(WebdavClient.USER_AGENT);
    webSettings.setSaveFormData(false);

    return rootView;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.instagram_demo_login);

    ButterKnife.bind(this);

    String cookieHost = Uri.parse(authInstragramLogin).getHost();
    configureCookies(cookieHost);

    WebViewClient wvClient = new CIAWebViewClient(this);
    webView.setWebViewClient(wvClient);

    final WebSettings settings = webView.getSettings();
    settings.setUserAgentString(BaseClient.USER_AGENT);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);
    settings.setUseWideViewPort(true);
  }
Exemplo n.º 6
0
  /** Initialize the WebView options to the ones define by user. */
  public void initializeOptions() {
    WebSettings settings = getSettings();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());

    settings.setJavaScriptEnabled(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_JAVASCRIPT, true));
    settings.setLoadsImagesAutomatically(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_IMAGES, true));
    settings.setSaveFormData(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_FORM_DATA, true));
    settings.setSavePassword(
        prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_PASSWORDS, true));
    settings.setDefaultZoom(
        ZoomDensity.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_DEFAULT_ZOOM_LEVEL, ZoomDensity.MEDIUM.toString())));
    settings.setUserAgentString(
        prefs.getString(Constants.PREFERENCES_BROWSER_USER_AGENT, Constants.USER_AGENT_DEFAULT));

    settings.setPluginState(
        PluginState.valueOf(
            prefs.getString(
                Constants.PREFERENCES_BROWSER_ENABLE_PLUGINS, PluginState.ON_DEMAND.toString())));

    CookieManager.getInstance()
        .setAcceptCookie(prefs.getBoolean(Constants.PREFERENCES_BROWSER_ENABLE_COOKIES, true));

    // Technical settings
    // settings.setUseWideViewPort(true);
    settings.setSupportMultipleWindows(true);
    setLongClickable(true);
    setScrollbarFadingEnabled(true);
    setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    setDrawingCacheEnabled(true);

    settings.setAppCacheEnabled(true);
    settings.setDatabaseEnabled(true);
    settings.setDomStorageEnabled(true);
  }
Exemplo n.º 7
0
 public ag(@NonNull Context context, String str, String str2) {
   super(context, WebDialog.DEFAULT_THEME);
   getWindow().setLayout(al.m9262a(context), al.m9285b(context));
   getWindow().setWindowAnimations(R.style.dialog_up_down_animation);
   setContentView(R.layout.view_web_dialog);
   findViewById(R.id.view_back_icon).setOnClickListener(this);
   TextView textView = (TextView) findViewById(R.id.view_back_title);
   textView.setText(str2);
   textView.setOnClickListener(this);
   this.f4433a = (WebView) findViewById(R.id.web_dialog_webview);
   if (!al.m9276a()) {
     this.f4433a.setLayerType(1, null);
   }
   this.f4433a.setScrollBarStyle(33554432);
   WebSettings settings = this.f4433a.getSettings();
   settings.setLoadWithOverviewMode(true);
   settings.setJavaScriptEnabled(true);
   settings.setBuiltInZoomControls(true);
   settings.setUserAgentString(C2239e.f3684a);
   this.f4433a.setWebViewClient(new C24621(this));
   this.f4433a.loadUrl(str);
   this.f4434b = Uri.parse(str).getHost();
 }
Exemplo n.º 8
0
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  public View onCreateView(
      final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    final Bundle args = getArguments();

    String url = args.getString(ARG_URL);

    if (url == null || url.length() == 0) url = this.getString(R.string.url_help);

    final Activity activity = getActivity();

    final WebView webview =
        new WebView(activity) {
          @Override
          public boolean onKeyDown(final int keyCode, final KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK && canGoBack()) {
              goBack();
              return true;
            }
            return super.onKeyDown(keyCode, event);
          }
        };

    final WebSettings webSettings = webview.getSettings();
    final String userAgent = AppConstants.getUserAgentString(getActivity());
    if (userAgent != null) {
      webSettings.setUserAgentString(userAgent);
    }
    webSettings.setJavaScriptEnabled(true);

    webview.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onReceivedError(
              final WebView view,
              final int errorCode,
              final String description,
              final String failingUrl) {
            Log.w(getTag(), "error code:" + errorCode);
            Log.d(getTag(), "error desc:" + description);
            Log.d(getTag(), "error url:" + failingUrl);
            webview.loadUrl("file:///android_res/raw/error.html");
            super.onReceivedError(view, errorCode, description, failingUrl);
          }
        });

    webview.setDownloadListener(
        new DownloadListener() {
          public void onDownloadStart(
              String url,
              String userAgent,
              String contentDisposition,
              String mimetype,
              long contentLength) {
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(url));
            startActivity(i);
          }
        });

    if (!url.matches("^https?://.*")) {
      final String protocol = ConfigHelper.isControlSeverSSL(activity) ? "https" : "http";
      url = protocol + "://" + url;
    }

    webview.loadUrl(url);

    return webview;
  }
Exemplo n.º 9
0
  @TargetApi(18)
  protected void init()
  {
    try
    {
      this.webView = new MyWebView(this.mContext);
      WebSettings localWebSettings = this.webView.getSettings();
      if (localWebSettings != null)
      {
        localWebSettings.setJavaScriptEnabled(true);
        localWebSettings.setUserAgentString("Android-QingtingFM Mozilla/5.0 (Linux; U; Android 4.4.0; zh-cn; MB200 Build/GRJ22;) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");
        localWebSettings.setSupportZoom(true);
        localWebSettings.setRenderPriority(WebSettings.RenderPriority.HIGH);
        localWebSettings.setCacheMode(2);
        localWebSettings.setJavaScriptCanOpenWindowsAutomatically(true);
      }
      WebViewPlayer.getInstance().setbackPolicy(null);
      this.webView.addJavascriptInterface(WebViewPlayer.getInstance(), "QTJsPlayer");
      this.webView.addJavascriptInterface(WebViewFunc.getInstance(), "QTJsReserve");
      this.webView.setWebChromeClient(new WebChromeClient()
      {
        public boolean onJsAlert(WebView paramAnonymousWebView, String paramAnonymousString1, String paramAnonymousString2, JsResult paramAnonymousJsResult)
        {
          AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramAnonymousWebView.getContext());
          localBuilder.setTitle("蜻蜓提示").setMessage(paramAnonymousString2).setPositiveButton("确定", null);
          localBuilder.setCancelable(false);
          localBuilder.create().show();
          paramAnonymousJsResult.confirm();
          return true;
        }

        public void onProgressChanged(WebView paramAnonymousWebView, int paramAnonymousInt)
        {
          if (paramAnonymousInt > 70)
            GroupWebView.this.removeLoading();
        }

        public void onReceivedTitle(WebView paramAnonymousWebView, String paramAnonymousString)
        {
        }
      });
      this.webView.setHorizontalScrollBarEnabled(false);
      this.webView.setVerticalScrollBarEnabled(false);
      this.webView.setWebViewClient(this.webViewClient);
      this.webView.loadUrl(getUrl());
      this.webView.setDownloadListener(new DownloadListener()
      {
        public void onDownloadStart(String paramAnonymousString1, String paramAnonymousString2, String paramAnonymousString3, String paramAnonymousString4, long paramAnonymousLong)
        {
          Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramAnonymousString1));
          GroupWebView.this.getContext().startActivity(localIntent);
        }
      });
      WebViewPlayer.getInstance().setWebview(this.webView);
      WebViewFunc.getInstance().setWebview(this.webView);
      LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-1, -1);
      addView(this.webView, localLayoutParams);
      return;
    }
    catch (Exception localException)
    {
    }
  }
Exemplo n.º 10
0
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
    linearLayout.setBackgroundColor(Color.BLACK);

    // Navbar setup

    navbar = (LinearLayout) findViewById(R.id.navbar);
    goButton = (Button) findViewById(R.id.go_button);
    urlField = (EditText) findViewById(R.id.url);

    goButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            doNav();
          }
        });

    urlField.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_GO) {

              doNav();

              handled = true;
            }
            return handled;
          }
        });

    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    String lastUrl = settings.getString("lastUrl", "");

    urlField.setText(lastUrl);

    // Navbar animation settings

    AnimationListener slideListener =
        new AnimationListener() {
          @Override
          public void onAnimationEnd(Animation animation) {
            if (animation.equals(slideUp)) {
              navbar.setVisibility(View.GONE);
            }
          }

          @Override
          public void onAnimationRepeat(Animation animation) {}

          @Override
          public void onAnimationStart(Animation animation) {
            if (animation.equals(slideDown)) {
              navbar.setVisibility(View.VISIBLE);
            }
          }
        };

    slideUp =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f);
    slideUp.setDuration(500);
    slideUp.setAnimationListener(slideListener);

    slideDown =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f,
            Animation.RELATIVE_TO_SELF,
            -1.0f,
            Animation.RELATIVE_TO_SELF,
            0.0f);
    slideDown.setDuration(500);
    slideDown.setAnimationListener(slideListener);

    // WebView setup

    webView = (WebView) findViewById(R.id.webView);

    WebSettings webSettings = webView.getSettings();

    webView.setWebChromeClient(new WebChromeClient());

    webView.setWebViewClient(
        new WebViewClient() {

          @Override
          public void onPageFinished(WebView view, String url) {

            Log.d("scale", view.getScale() + "");

            Log.d("pageFinished", url);

            view.setInitialScale(70);

            if (url.equalsIgnoreCase(HOME_PAGE)) {
              // navbar.setVisibility(View.VISIBLE);
              navbar.startAnimation(slideDown);
            }
          }

          @Override
          public void onScaleChanged(WebView view, float oldScale, float newScale) {

            Log.d("scale changed", oldScale + " - " + newScale);

            if (newScale > 0.7) {

              Log.d("scale", "reset");
              // view.setInitialScale(70);

            }
          }
        });

    webView.setInitialScale(70);

    webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    webView.setVerticalScrollBarEnabled(false);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);

    webSettings.setBuiltInZoomControls(true);
    webSettings.setDisplayZoomControls(false);

    webSettings.setSupportZoom(true);

    webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    webSettings.setPluginState(WebSettings.PluginState.ON);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setDomStorageEnabled(true);
    webSettings.setDatabaseEnabled(true);
    webSettings.setDatabasePath(
        "/data/data/" + webView.getContext().getPackageName() + "/databases/");
    webSettings.setSaveFormData(false);
    webSettings.setLightTouchEnabled(false);
    webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
    webSettings.setRenderPriority(RenderPriority.HIGH);
    webSettings.setUserAgentString(
        "Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV");

    final Intent intent = getIntent();
    if ((intent.getAction() == Intent.ACTION_VIEW) && (intent.getData() != null)) {
      final String url = intent.getDataString();
      urlField.setText(url);
      webView.loadUrl(url);
      navbar.setVisibility(View.GONE);
    } else {
      webView.loadUrl(HOME_PAGE);
    }

    webView.requestFocus();
  }