コード例 #1
0
ファイル: KMMDroidApp.java プロジェクト: EABonney/KMMDroid
  private void writeDeviceState(List<KMMDDeviceItem> deviceState) {
    XmlSerializer serializer = Xml.newSerializer();
    StringWriter writer = new StringWriter();
    try {
      serializer.setOutput(writer);
      serializer.startDocument("UTF-8", true);
      serializer.startTag("", "DeviceState");
      for (KMMDDeviceItem item : deviceState) {
        serializer.startTag("", "item");
        serializer.startTag("", "type");
        serializer.text(item.getType());
        serializer.endTag("", "type");
        serializer.startTag("", "name");
        serializer.text(item.getName());
        serializer.endTag("", "name");
        serializer.startTag("", "path");
        serializer.text(item.getPath());
        serializer.endTag("", "path");
        serializer.startTag("", "dirtyservices");
        serializer.attribute(
            "", "Dropbox", String.valueOf(item.getIsDirty(KMMDDropboxService.CLOUD_DROPBOX)));
        serializer.attribute(
            "",
            "GoogleDrive",
            String.valueOf(item.getIsDirty(KMMDDropboxService.CLOUD_GOOGLEDRIVE)));
        serializer.attribute(
            "", "UbutntoOne", String.valueOf(item.getIsDirty(KMMDDropboxService.CLOUD_UBUNTUONE)));
        serializer.endTag("", "dirtyservices");
        serializer.startTag("", "revcodes");
        serializer.attribute("", "Dropbox", item.getRevCode(KMMDDropboxService.CLOUD_DROPBOX));
        serializer.attribute(
            "", "GoogleDrive", item.getRevCode(KMMDDropboxService.CLOUD_GOOGLEDRIVE));
        serializer.attribute("", "UbuntuOne", item.getRevCode(KMMDDropboxService.CLOUD_UBUNTUONE));
        serializer.endTag("", "revcodes");
        serializer.endTag("", "item");
      }
      serializer.endTag("", "DeviceState");
      serializer.endDocument();
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    // Attempt to write the state file to the private storage area.
    String FILENAME = DEVICE_STATE_FILE;
    try {
      FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
      fos.write(writer.toString().getBytes());
      fos.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
ファイル: KMMDroidApp.java プロジェクト: EABonney/KMMDroid
  public void markFileIsDirty(Boolean dirty, String widgetId) {
    // Need to mark the file as dirty for our cloud services.
    // Read in the saved deviceState from the xml file and put it into a List<>.
    List<KMMDDeviceItem> savedDeviceState = new ArrayList<KMMDDeviceItem>();
    KMMDDeviceItem currentFile = null;
    KMMDDeviceItemParser parser =
        new KMMDDeviceItemParser(KMMDDropboxService.DEVICE_STATE_FILE, this);
    savedDeviceState = parser.parse();

    // Get the correct database
    // If widgetId is 9999, then we are already in the application and need to get the default
    // database.
    // If widgetId is null, then we are coming from a scheduled event for checking schedules of the
    // main app.
    String prefString = null;
    if (widgetId == null) prefString = "Full Path";
    else if (widgetId.equals("9999")) prefString = "currentOpenedDatabase";
    else prefString = "widgetDatabasePath" + String.valueOf(widgetId);

    String path = prefs.getString(prefString, "");
    Log.d(TAG, "Path for the database marked dirty: " + path);

    if (savedDeviceState != null) {
      // Find the correct file in our saved state and mark it as dirty.
      for (KMMDDeviceItem item : savedDeviceState) {
        currentFile = item.findMatch(path);
        if (currentFile != null) break;
        else currentFile = new KMMDDeviceItem(new File(path));
      }
    } else {
      // This is the first time we have run this routine and we only have one file to mark.
      currentFile = new KMMDDeviceItem(new File(path));
    }
    currentFile.setIsDirty(true, KMMDDropboxService.CLOUD_ALL);

    if (savedDeviceState != null) {
      // Replace this in the savedDeviceState list then write it to disk.
      for (int i = 0; i < savedDeviceState.size(); i++) {
        if (savedDeviceState.get(i).equals(currentFile)) {
          savedDeviceState.add(i, currentFile);
          savedDeviceState.remove(i + 1);
          i = savedDeviceState.size() + 1;
        }
      }
    } else {
      savedDeviceState = new ArrayList<KMMDDeviceItem>();
      savedDeviceState.add(currentFile);
    }

    writeDeviceState(savedDeviceState);
  }