/**
  * Given a file that the preferences are supposedly stored in, this function will try to load the
  * preferences. If the preferences don't exist, or they are incomplete, this will also fill in the
  * missing values, and store the now complete preferences in the file location specified.
  *
  * @param prefFile
  * @throws Exception
  */
 public void init(File prefFile) throws IOException {
   this.prefFile = prefFile;
   if (prefFile.exists()) {
     Properties userProperties = new Properties();
     FileInputStream in = new FileInputStream(prefFile);
     userProperties.load(in);
     in.close();
     for (String key : userProperties.stringPropertyNames()) {
       String val = userProperties.getProperty(key);
       String value = getObject(val, ((Preference) prefs.get(key))).toString();
       Object ovalue = getObject(val, ((Preference) prefs.get(key)));
       Preference p1 = prefs.get(key);
       Preference p2;
       if (p1 != null) {
         p2 = new Preference(p1.name, value, p1.allowed, p1.description);
       } else {
         p2 = new Preference(key, val, Type.STRING, "");
       }
       p2.objectValue = ovalue;
       prefs.put(key, p2);
     }
   }
   save();
 }
Exemple #2
0
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      addPreferencesFromResource(R.xml.settings_ui_fragment);

      final PreferenceCategory preferenceCategory =
          (PreferenceCategory) findPreference("ui.storage");
      final Preference button_f = (Preference) getPreferenceManager().findPreference("ui.rescan");
      if (button_f != null) {
        button_f.setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference arg0) {
                MainActivity.fullStorageScan();
                preferenceCategory.removePreference(button_f);
                return true;
              }
            });
      }
      final Preference button_u =
          (Preference) getPreferenceManager().findPreference("ui.clear_unavailable");
      if (button_u != null) {
        button_u.setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference arg0) {
                IndexingDB iDB = new IndexingDB(getActivity());
                List<GameInfoStruct> games = iDB.getIndexGISList(MainActivity.SORT_NONE);
                iDB.close();
                for (GameInfoStruct game : games) {
                  if (!game.getFile().exists()) {
                    game.removeIndex(getActivity());
                  }
                }
                MainActivity.prepareFileListView(false);
                preferenceCategory.removePreference(button_u);
                return true;
              }
            });
      }
      final Preference button_c =
          (Preference) getPreferenceManager().findPreference("ui.clearcache");
      if (button_c != null) {
        button_c.setOnPreferenceClickListener(
            new Preference.OnPreferenceClickListener() {
              @Override
              public boolean onPreferenceClick(Preference arg0) {
                MainActivity.clearCache();
                preferenceCategory.removePreference(button_c);
                return true;
              }
            });
      }
    }
 private boolean isValidAddress(String userId, String serviceId) {
   if (userId == null || "".equals(userId) || serviceId == null || "".equals(serviceId)) {
     // System.out.println("Source/dest address NULL --> PDU discarded");
     return false;
   }
   if (!Preference.isValidServiceId(serviceId)) {
     // System.out.println("Invalid dest address:" + serviceId
     // + " --> PDU discarded");
     return false;
   }
   if (userId.startsWith("849") || userId.startsWith("+849") || userId.startsWith("09")) {
     return true;
     // TrungDK EVN -> UNKNOWN
   } else if ("UNKNOWN".equalsIgnoreCase(Preference.mobileOperator)) {
     return true;
   } else {
     // System.out.println("Invalid source address:" + userId + " --> PDU
     // discarded");
     return true;
   }
 }