Ejemplo n.º 1
0
 boolean textZoomOut() {
   WebSettings settings = getSettings();
   int newZoom = settings.getTextZoom() - 20;
   if (newZoom >= 40) {
     settings.setTextZoom(newZoom);
     saveTextZoomPref();
     return true;
   } else {
     return false;
   }
 }
  public static void setTextZoom(Resources resources, WebSettings settings) {
    final float fontScale = resources.getConfiguration().fontScale;
    final int desiredFontSizePx = resources.getInteger(R.integer.conversation_desired_font_size_px);
    final int unstyledFontSizePx =
        resources.getInteger(R.integer.conversation_unstyled_font_size_px);

    int textZoom = settings.getTextZoom();
    // apply a correction to the default body text style to get regular text to the size we want
    textZoom = textZoom * desiredFontSizePx / unstyledFontSizePx;
    // then apply any system font scaling
    textZoom = (int) (textZoom * fontScale);
    settings.setTextZoom(textZoom);
  }
Ejemplo 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));
  }
Ejemplo n.º 4
0
  // @TargetApi(Build.VERSION_CODES.KITKAT)
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_welcome);

    mWebView = (WebView) findViewById(R.id.welcomeWebView);
    username = (EditText) findViewById(R.id.userName);
    password = (EditText) findViewById(R.id.password);
    // welcomeTitle = (TextView)findViewById(R.id.welcomeTitle);

    autoSignIn();

    // String htmlCode = "<h1> <a href=\"#\"> WAFFLE </a> </h1>";

    // welcomeTitle.setText(Html.fromHtml(htmlCode));

    // Force links and redirects to open
    // in the WebView instead of in a browser
    mWebView.setWebViewClient(new WebViewClient());
    // Stop local links and redirects from
    // opening in browser instead of WebView
    mWebView.setWebViewClient(new MyAppWebViewClient());

    mWebView.loadUrl(webUrl);
    // Enable Javascript
    WebSettings webSettings = mWebView.getSettings();

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
      webSettings.setAllowFileAccessFromFileURLs(true);
      webSettings.setAllowUniversalAccessFromFileURLs(true);
      webSettings.setTextZoom(
          webSettings.getTextZoom() + 90); // possibly creates not debuggable error
    }

    webSettings.setJavaScriptEnabled(true);
    //   mWebView.setWebContentsDebuggingEnabled(true);
    mWebView.setWebChromeClient(new WebChromeClient());

    // Log in button click handler
    Button loginButton = (Button) findViewById(R.id.loginBtt);
    loginButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // Starts an intent of the log in activity
            // startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
            login();
          }
        });

    // Sign up button click handler
    Button signupButton = (Button) findViewById(R.id.signUpBttn);
    signupButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            // Starts an intent for the sign up activity
            Intent intent = new Intent(WelcomeActivity.this, SignUpActivity.class);
            intent.putExtra("userName", username.getText().toString().trim());
            intent.putExtra("password", password.getText().toString().trim());
            startActivity(intent);
            finish();
          }
        });

    /*
        @Override
        public void onBackPressed() {
            if(mWebView.canGoBack()) {
                mWebView.goBack();
            } else {
                super.onBackPressed();
            }
    */

  }
Ejemplo n.º 5
0
 void applyTextZoomPref() {
   SharedPreferences prefs = prefs();
   int textZoom = prefs.getInt(PREF_TEXT_ZOOM, 100);
   WebSettings settings = getSettings();
   settings.setTextZoom(textZoom);
 }