@SuppressLint("InflateParams")
  // no other way for AlertDialog
  private Dialog createSignInDialog(
      final HttpAuthHandler handler,
      final String host,
      final String realm,
      final String username,
      final String password) {
    final View v = mIitc.getLayoutInflater().inflate(R.layout.dialog_http_authentication, null);
    final TextView tvUsername = (TextView) v.findViewById(R.id.username);
    final TextView tvPassword = (TextView) v.findViewById(R.id.password);
    final String title = String.format(mIitc.getString(R.string.sign_in_to), host, realm);

    if (username != null) tvUsername.setText(username);
    if (password != null) tvPassword.setText(password);

    return new AlertDialog.Builder(mIitc)
        .setView(v)
        .setTitle(title)
        .setCancelable(true)
        .setPositiveButton(
            R.string.sign_in_action,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(final DialogInterface dialog, final int id) {
                handler.proceed(tvUsername.getText().toString(), tvPassword.getText().toString());
              }
            })
        .setNegativeButton(
            android.R.string.cancel,
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(final DialogInterface dialog, final int id) {
                dialog.cancel();
              }
            })
        .setOnCancelListener(
            new DialogInterface.OnCancelListener() {
              @Override
              public void onCancel(final DialogInterface dialog) {
                handler.cancel();
              }
            })
        .create();
  }
 // start non-ingress-intel-urls in another app...
 @Override
 public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
   if (url.contains("conflogin")
       || url.contains("ServiceLogin")
       || url.contains("appengine.google.com")) {
     Log.d("Google login");
     return false;
   } else if (isIntelUrl(url)) {
     Log.d("intel link requested, reset app and load " + url);
     mIitc.reset();
     mIitc.setLoadingState(true);
     return false;
   } else {
     Log.d("no ingress intel link, start external app to load url: " + url);
     final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
     // make new activity independent from iitcm
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     mIitc.startActivity(intent);
   }
   return true;
 }
  /**
   * Check every external resource if it's okay to load it and maybe replace it with our own
   * content. This is used to block loading Niantic resources which aren’t required and to inject
   * IITC early into the site. via http://stackoverflow.com/a/8274881/1684530
   */
  @Override
  public WebResourceResponse shouldInterceptRequest(final WebView view, final String url) {
    // if any tiles are requested, handle it with IITC_TileManager
    if (url.matches(".*tile.*jpg.*") // mapquest tiles | ovi tiles
        || url.matches(".*tile.*png.*") // cloudmade tiles
        || url.matches(".*mts.*googleapis.*") // google tiles
        || url.matches(".*khms.*googleapis.*") // google satellite tiles
        || url.matches(".*tile.*jpeg.*") // bing tiles
        || url.matches(".*maps.*yandex.*tiles.*") // yandex maps
        || url.matches(".*cartocdn.*png.*") // cartoDB tiles
    ) {
      try {
        return mTileManager.getTile(url);
      } catch (final Exception e) {
        Log.w(e);
        return super.shouldInterceptRequest(view, url);
      }
    }

    if (url.contains("/css/common.css")) {
      // return custom stylesheet
      return new WebResourceResponse("text/css", "UTF-8", STYLE);
    }

    if (url.contains("/css/ap_icons.css")
        || url.contains("/css/map_icons.css")
        || url.contains("/css/common.css")
        || url.contains("/css/misc_icons.css")
        || url.contains("/css/style_full.css")
        || url.contains("/css/style_mobile.css")
        || url.contains("/css/portalrender.css")
        || url.contains("/css/portalrender_mobile.css")
        || url.contains("js/analytics.js")
        || url.contains("google-analytics.com/ga.js")) {
      // don't load stylesheets
      return new WebResourceResponse("text/plain", "UTF-8", EMPTY);
    }

    final Uri uri = Uri.parse(url);
    if (uri.getHost() != null
        && uri.getHost().endsWith(DOMAIN)
        && ("http".equals(uri.getScheme()) || "https".equals(uri.getScheme())))
      return mIitc.getFileManager().getResponse(uri);

    return super.shouldInterceptRequest(view, url);
  }
 @Override
 public void onReceive(final Context context, final Intent intent) {
   ((IITC_Mobile) context).installIitcUpdate();
 }