Exemple #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      WebView.setWebContentsDebuggingEnabled(true);
    }
    setContentView(R.layout.activity_webview_browser);
    mUrlBar = (EditText) findViewById(R.id.url_field);
    mUrlBar.setOnKeyListener(
        new OnKeyListener() {
          public boolean onKey(View view, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
              loadUrlFromUrlBar(view);
              return true;
            }
            return false;
          }
        });

    createAndInitializeWebView();

    String url = getUrlFromIntent(getIntent());
    if (url == null) {
      // Make sure to load a blank page to make it immediately inspectable with
      // chrome://inspect.
      url = "about:blank";
    }
    setUrlBarText(url);
    setUrlFail(false);
    loadUrlFromUrlBar(mUrlBar);
  }
  /**
   * Convenience method to set some generic defaults for a given WebView
   *
   * @param webView
   */
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private void setUpWebViewDefaults(WebView webView) {
    WebSettings settings = webView.getSettings();

    // Enable Javascript
    settings.setJavaScriptEnabled(true);

    // Use WideViewport and Zoom out if there is no viewport defined
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);

    // Enable pinch to zoom without the zoom buttons
    settings.setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
      // Hide the zoom controls for HONEYCOMB+
      settings.setDisplayZoomControls(false);
    }

    // Enable remote debugging via chrome://inspect
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      WebView.setWebContentsDebuggingEnabled(true);
    }

    // We set the WebViewClient to ensure links are consumed by the WebView rather
    // than passed to a browser if it can
    webView.setWebViewClient(new WebViewClient());
  }
Exemple #3
0
  @SuppressWarnings("deprecation")
  public void init(Object jsWebViewInterface, Object jsHandler) {
    if (JSBridgeInteface.class.isInstance(jsWebViewInterface)) {
      this.jsWebViewInterface = (JSBridgeInteface) jsWebViewInterface;
    }
    if (JSBridgeHandler.class.isInstance(jsHandler)) {
      this.jsBridgeHandler = (JSBridgeHandler) jsHandler;
    }
    CookieManager.getInstance().setAcceptCookie(true);
    if (webView != null) {
      webView.getSettings().setJavaScriptEnabled(true);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
      }

      webView.getSettings().setDomStorageEnabled(true);
      webView.getSettings().setDatabaseEnabled(true);
      if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        webView
            .getSettings()
            .setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
      }

      registerJavaScriptAPI(new AndroidAPI(context, webView));
      webView.setWebViewClient(new JSBridgeWebViewClient());
      webView.loadUrl("javascript: " + getAssetFileContents(JS_BRIDGE_FILE_NAME));
    }
  }
  @Override
  public void onCreate() {
    super.onCreate();
    ACRA.init(this);

    bus = new Bus();

    final Resources resources = getResources();
    ViewAnimations.init(resources);
    screenDensity = resources.getDisplayMetrics().density;

    PrefKeys.initPreferenceKeys(resources);

    // Enable debugging on the webview
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      WebView.setWebContentsDebuggingEnabled(true);
    }

    Api.setConnectionFactory(new OkHttpConnectionFactory(this));

    if (WikipediaApp.isWikipediaZeroDevmodeOn()) {
      IntentFilter connFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
      connChangeReceiver = new ConnectionChangeReceiver();
      this.registerReceiver(connChangeReceiver, connFilter);
    }

    try {
      appVersionString = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
    } catch (PackageManager.NameNotFoundException e) {
      // This will never happen!
      throw new RuntimeException(e);
    }

    new PerformMigrationsTask().execute();
  }
 @SuppressLint("NewApi")
 private void enableWebDebugging(boolean enable) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
     AppLog.i(T.EDITOR, "Enabling web debugging");
     WebView.setWebContentsDebuggingEnabled(enable);
   }
 }
Exemple #6
0
 @TargetApi(Build.VERSION_CODES.KITKAT)
 private void enableRemoteDebugging() {
   try {
     WebView.setWebContentsDebuggingEnabled(true);
   } catch (IllegalArgumentException e) {
     Log.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
     e.printStackTrace();
   }
 }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   super.init();
   // Set by <content src="index.html" /> in config.xml
   super.loadUrl(Config.getStartUrl());
   // super.loadUrl("file:///android_asset/www/index.html");
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
     WebView.setWebContentsDebuggingEnabled(true);
   }
 }
  @Override
  protected View onCreateContentView(int parentId) {
    View root = getLayoutInflater().inflate(R.layout.turtle_content, null);

    mWebBlocklyView = (WebView) root.findViewById(R.id.turtle_runtime);
    mWebBlocklyView.getSettings().setJavaScriptEnabled(true);
    mWebBlocklyView.setWebChromeClient(new WebChromeClient());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      WebView.setWebContentsDebuggingEnabled(true);
    }
    mWebBlocklyView.loadUrl("file:///android_asset/webblockly/index.html");

    return root;
  }
  @SuppressLint("NewApi")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

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

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

    loadFragment();
  }
  public void init(Context context) {
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);

    settings.setAllowFileAccess(true);

    settings.setAppCacheEnabled(true);

    final HybridInterface hybridInterface = new HybridInterface(this);
    this.addJavascriptInterface(hybridInterface, "hybridAndroid");

    HybridWebViewClient hybridWebViewClient = new HybridWebViewClient();
    hybridWebViewClient.setHybridWebView(this);
    this.setWebViewClient(hybridWebViewClient);

    this.setWebChromeClient(new HybridWebChromeClient());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      if (0 != (context.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
        WebView.setWebContentsDebuggingEnabled(true);
      }
    }
  }
  /** Called when the activity is first created. */
  @SuppressLint("NewApi")
  @Override
  public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* pressing volume up/down should cause music volume changes */
    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    /* set samples content view */
    this.setContentView(this.getContentViewId());

    this.setTitle(this.getActivityTitle());

    /*
     *	this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml
     *	If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse.
     *	You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place.
     *	Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging
     */
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
      if (0 != (getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
        WebView.setWebContentsDebuggingEnabled(true);
      }
    }

    /* set AR-view for life-cycle notifications etc. */
    this.architectView = (ArchitectView) this.findViewById(this.getArchitectViewId());

    /* pass SDK key if you have one, this one is only valid for this package identifier and must not be used somewhere else */
    final StartupConfiguration config =
        new StartupConfiguration(
            this.getWikitudeSDKLicenseKey(), this.getFeatures(), this.getCameraPosition());

    try {
      /* first mandatory life-cycle notification */
      this.architectView.onCreate(config);
    } catch (RuntimeException rex) {
      this.architectView = null;
      Toast.makeText(getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT)
          .show();
      Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex);
    }

    // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using
    // this listener
    this.sensorAccuracyListener = this.getSensorAccuracyListener();

    // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'"
    // is forwarded to this listener, use this to interact between JS and native Android
    // activity/fragment
    this.urlListener = this.getUrlListener();

    // register valid urlListener in architectView, ensure this is set before content is loaded to
    // not miss any event
    if (this.urlListener != null && this.architectView != null) {
      this.architectView.registerUrlListener(this.getUrlListener());
    }

    if (hasGeo()) {
      // listener passed over to locationProvider, any location update is handled here
      this.locationListener =
          new LocationListener() {

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {}

            @Override
            public void onProviderEnabled(String provider) {}

            @Override
            public void onProviderDisabled(String provider) {}

            @Override
            public void onLocationChanged(final Location location) {
              // forward location updates fired by LocationProvider to architectView, you can set
              // lat/lon from any location-strategy
              if (location != null) {
                // sore last location as member, in case it is needed somewhere (in e.g. your
                // adjusted project)
                AbstractArchitectCamActivity.this.lastKnownLocaton = location;
                if (AbstractArchitectCamActivity.this.architectView != null) {
                  // check if location has altitude at certain accuracy level & call right architect
                  // method (the one with altitude information)
                  if (location.hasAltitude()
                      && location.hasAccuracy()
                      && location.getAccuracy() < 7) {
                    AbstractArchitectCamActivity.this.architectView.setLocation(
                        location.getLatitude(),
                        location.getLongitude(),
                        location.getAltitude(),
                        location.getAccuracy());
                  } else {
                    AbstractArchitectCamActivity.this.architectView.setLocation(
                        location.getLatitude(),
                        location.getLongitude(),
                        location.hasAccuracy() ? location.getAccuracy() : 1000);
                  }
                }
              }
            }
          };

      // locationProvider used to fetch user position
      this.locationProvider = getLocationProvider(this.locationListener);
    } else {
      this.locationProvider = null;
      this.locationListener = null;
    }
  }
  @Override
  public void onCreate() {
    super.onCreate();
    Fabric.with(this, new Crashlytics());
    FlowManager.init(this);
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    // Disable HTTP keep-alive for our app, as some versions of Android will return an empty
    // response
    System.setProperty("http.keepAlive", "false");

    // Allocate all the shared objects at launch
    conn = NetworkConnection.getInstance();
    ColorFormatter.init();

    if (prefs.contains("notify")) {
      SharedPreferences.Editor editor = prefs.edit();
      editor.putString("notify_type", prefs.getBoolean("notify", true) ? "1" : "0");
      editor.remove("notify");
      editor.commit();
    }

    if (prefs.contains("notify_sound")) {
      SharedPreferences.Editor editor = prefs.edit();
      if (!prefs.getBoolean("notify_sound", true)) editor.putString("notify_ringtone", "");
      editor.remove("notify_sound");
      editor.commit();
    }

    if (prefs.contains("notify_lights")) {
      SharedPreferences.Editor editor = prefs.edit();
      if (!prefs.getBoolean("notify_lights", true)) editor.putString("notify_led_color", "0");
      editor.remove("notify_lights");
      editor.commit();
    }

    if (prefs.getInt("ringtone_version", 0) < RINGTONE_VERSION) {
      File path = getFilesDir();
      File file = new File(path, "IRCCloud.mp3");
      try {
        path.mkdirs();
        InputStream is = getResources().openRawResource(R.raw.digit);
        OutputStream os = new FileOutputStream(file);
        byte[] data = new byte[is.available()];
        is.read(data);
        os.write(data);
        is.close();
        os.close();
        file.setReadable(true, false);
        MediaScannerConnection.scanFile(
            this,
            new String[] {file.toString()},
            null,
            new MediaScannerConnection.OnScanCompletedListener() {
              @Override
              public void onScanCompleted(String path, Uri uri) {
                ContentValues values = new ContentValues();
                values.put(MediaStore.Audio.Media.IS_NOTIFICATION, "1");
                getContentResolver().update(uri, values, null, null);

                SharedPreferences prefs =
                    PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = prefs.edit();
                if (!prefs.contains("notify_ringtone")) {
                  editor.putString("notify_ringtone", uri.toString());
                }
                editor.putInt("ringtone_version", RINGTONE_VERSION);
                editor.commit();
              }
            });
      } catch (IOException e) {
        if (!prefs.contains("notify_ringtone")) {
          SharedPreferences.Editor editor = prefs.edit();
          editor.putString("notify_ringtone", "content://settings/system/notification_sound");
          editor.commit();
        }
      }
    }

    if (prefs.contains("notify_pebble")) {
      try {
        int pebbleVersion =
            getPackageManager().getPackageInfo("com.getpebble.android", 0).versionCode;
        if (pebbleVersion >= 553 && Build.VERSION.SDK_INT >= 18) {
          SharedPreferences.Editor editor = prefs.edit();
          editor.remove("notify_pebble");
          editor.commit();
        }
      } catch (Exception e) {
      }
    }

    if (prefs.contains("acra.enable")) {
      SharedPreferences.Editor editor = prefs.edit();
      editor.remove("acra.enable");
      editor.commit();
    }

    if (prefs.contains("notifications_json")) {
      SharedPreferences.Editor editor = prefs.edit();
      editor.remove("notifications_json");
      editor.remove("networks_json");
      editor.remove("lastseeneids_json");
      editor.remove("dismissedeids_json");
      editor.commit();
    }

    prefs = getSharedPreferences("prefs", 0);
    if (prefs.getString("host", "www.irccloud.com").equals("www.irccloud.com")
        && !prefs.contains("path")
        && prefs.contains("session_key")) {
      Crashlytics.log(Log.INFO, "IRCCloud", "Migrating path from session key");
      SharedPreferences.Editor editor = prefs.edit();
      editor.putString("path", "/websocket/" + prefs.getString("session_key", "").charAt(0));
      editor.commit();
    }
    if (prefs.contains("host") && prefs.getString("host", "").equals("www.irccloud.com")) {
      Crashlytics.log(Log.INFO, "IRCCloud", "Migrating host");
      SharedPreferences.Editor editor = prefs.edit();
      editor.putString("host", "api.irccloud.com");
      editor.commit();
    }
    if (prefs.contains("gcm_app_version")) {
      SharedPreferences.Editor editor = prefs.edit();
      editor.remove("gcm_app_version");
      editor.remove("gcm_app_build");
      editor.remove("gcm_registered");
      editor.remove("gcm_reg_id");
      editor.commit();
    }

    NetworkConnection.IRCCLOUD_HOST = prefs.getString("host", BuildConfig.HOST);
    NetworkConnection.IRCCLOUD_PATH = prefs.getString("path", "/");

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