示例#1
0
  public static void check() {
    HashMap<String, String> old = new HashMap<String, String>(codecs.size());

    for (Codec c : codecs) {
      c.update();
      old.put(c.name(), c.getValue());
      if (!c.isLoaded()) {
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
        SharedPreferences.Editor e = sp.edit();

        e.putString(c.key(), "never");
        e.commit();
      }
    }

    for (Codec c : codecs)
      if (!old.get(c.name()).equals("never")) {
        c.init();
        if (c.isLoaded()) {
          SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
          SharedPreferences.Editor e = sp.edit();

          e.putString(c.key(), old.get(c.name()));
          e.commit();
          c.init();
        } else c.fail();
      }
  }
示例#2
0
  static {
    final int size = codecs.size();
    codecsNumbers = new HashMap<Integer, Codec>(size);
    codecsNames = new HashMap<String, Codec>(size);

    for (Codec c : codecs) {
      codecsNames.put(c.name(), c);
      codecsNumbers.put(c.number(), c);
    }

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
    String prefs = sp.getString(Settings.PREF_CODECS, Settings.DEFAULT_CODECS);
    if (prefs == null) {
      saveCodecPrefs(sp);
    } else {
      String[] vals = prefs.split(" ");
      Vector<Codec> orderedCodecs = new Vector<Codec>();
      for (String v : vals) {
        try {
          int i = Integer.parseInt(v);
          Codec c = codecsNumbers.get(i);
          /* moves the configured codecs to the beginning of the list,
           * and any new codecs will automatically go at the end */
          if (c != null) {
            codecs.remove(c);
            orderedCodecs.add(c);
          }
        } catch (Exception e) {
          // do nothing (expecting
          // NumberFormatException and
          // indexnot found
        }
      }
      orderedCodecs.addAll(codecs);
      codecs.clear();
      for (Codec c : orderedCodecs) {
        if (c.isLicensed()) codecs.add(c);
      }
      saveCodecPrefs(sp);
    }
  }