Ejemplo n.º 1
0
 // Constructor from a file
 private Remote(Context c, String remoteName) {
   this();
   if (remoteName == null) throw new IllegalArgumentException("Name cannot be null");
   this.name = remoteName;
   final Gson gson = new Gson();
   File optfile = new File(getRemoteDir(c), OPTIONS_FILE);
   options = gson.fromJson(FileUtils.read(optfile), Options.class);
   for (final File f : getRemoteDir(c, remoteName).listFiles()) {
     if (f.getName().endsWith(BUTTON_EXTENSION)) {
       Button b = gson.fromJson(FileUtils.read(f), Button.class);
       addButton(b);
     }
   }
 }
Ejemplo n.º 2
0
 /** Save this remote to the file system */
 public void save(Context c) {
   Gson gson = new GsonBuilder().setPrettyPrinting().create();
   File dir = getRemoteDir(c);
   FileUtils.clear(dir);
   for (Button b : buttons) {
     if (b.id != 0 && b.code != null && !b.code.isEmpty()) {
       // File f = getNextFile(dir, BUTTON_PREFIX, BUTTON_EXTENSION);
       File f = new File(dir, BUTTON_PREFIX + b.id + BUTTON_EXTENSION);
       FileUtils.write(f, gson.toJson(b));
     }
   }
   File f = new File(dir, OPTIONS_FILE);
   FileUtils.write(f, gson.toJson(options));
 }
Ejemplo n.º 3
0
 public static boolean exists(Context c, String name) {
   return FileUtils.exists(getRemoteDir(c, name));
 }
Ejemplo n.º 4
0
 public static void rename(Context c, String oldName, String newName) {
   if (oldName.equals(newName) || newName.trim().isEmpty()) {
     return;
   }
   FileUtils.rename(getRemoteDir(c, oldName), getRemoteDir(c, newName));
 }
Ejemplo n.º 5
0
 public static void remove(Context c, String name) {
   FileUtils.remove(getRemoteDir(c, name));
 }