コード例 #1
0
 @Override
 public void onLowMemory() {
   super.onLowMemory();
   if (!NetworkConnection.getInstance().isVisible()) {
     Crashlytics.log(
         Log.DEBUG,
         "IRCCloud",
         "Received low memory warning in the background, cleaning backlog in all buffers");
     BuffersList buffersList = BuffersList.getInstance();
     EventsList eventsList = EventsList.getInstance();
     for (Buffer b : buffersList.getBuffers()) {
       if (!b.getScrolledUp()) eventsList.pruneEvents(b.getBid());
     }
   }
 }
コード例 #2
0
  @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) {
    }
  }
コード例 #3
0
 @Override
 public void onTerminate() {
   NetworkConnection.getInstance().save(1);
   super.onTerminate();
 }