예제 #1
0
  public LayoutDevice addUserDevice(String name, float xdpi, float ydpi) {
    LayoutDevice d = new LayoutDevice(name);
    d.setXDpi(xdpi);
    d.setYDpi(ydpi);
    mUserLayoutDevices.add(d);
    combineLayoutDevices();

    return d;
  }
예제 #2
0
  public LayoutDevice getUserLayoutDevice(String name) {
    for (LayoutDevice d : mUserLayoutDevices) {
      if (d.getName().equals(name)) {
        return d;
      }
    }

    return null;
  }
예제 #3
0
  /**
   * Replaces a configuration in a given {@link LayoutDevice}.
   *
   * @param device the device to modify
   * @param oldConfigName the name of the config to replace. If null, the new config is simply
   *     added.
   * @param newConfigName the configuration name to add or replace
   * @param config the configuration to set
   */
  public void replaceUserConfiguration(
      LayoutDevice device, String oldConfigName, String newConfigName, FolderConfiguration config) {
    // check that the device does belong to the user list.
    // the main goal is to make sure that this does not belong to the default/addon list.
    if (mUserLayoutDevices.contains(device)) {
      // if the old and new config name are different, remove the old one
      if (oldConfigName != null && oldConfigName.equals(newConfigName) == false) {
        device.removeConfig(oldConfigName);
      }

      // and then add the new one
      device.addConfig(newConfigName, config);
    }
  }
예제 #4
0
 /**
  * Removes a configuration from a given user {@link LayoutDevice}
  *
  * @param device the device to modify
  * @param configName the name of the config to remove
  */
 public void removeUserConfiguration(LayoutDevice device, String configName) {
   // check that the device does belong to the user list.
   // the main goal is to make sure that this does not belong to the default/addon list.
   if (mUserLayoutDevices.contains(device)) {
     device.removeConfig(configName);
   }
 }
예제 #5
0
  /**
   * Writes the given {@link LayoutDevice}s into the given file.
   *
   * @param deviceXml the file to write.
   * @param deviceList the LayoutDevice to write into the file.
   */
  private void write(File deviceXml, List<LayoutDevice> deviceList) {
    try {
      // create a new document
      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
      docFactory.setNamespaceAware(true);
      DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
      Document doc = docBuilder.newDocument();

      // create a base node
      Element baseNode =
          doc.createElementNS(
              LayoutDevicesXsd.NS_LAYOUT_DEVICE_XSD, LayoutDevicesXsd.NODE_LAYOUT_DEVICES);
      // create the prefix for the namespace
      baseNode.setPrefix("d");
      doc.appendChild(baseNode);

      // fill it with the layout devices.
      for (LayoutDevice device : deviceList) {
        device.saveTo(doc, baseNode);
      }

      // save the document to disk
      // Prepare the DOM document for writing
      Source source = new DOMSource(doc);

      // Prepare the output file
      File file = new File(deviceXml.getAbsolutePath());
      Result result = new StreamResult(file);

      // Write the DOM document to the file
      Transformer xformer = TransformerFactory.newInstance().newTransformer();
      xformer.transform(source, result);
    } catch (Exception e) {
      AdtPlugin.log(e, "Failed to write %s", deviceXml.getAbsolutePath());
    }
  }
예제 #6
0
  /**
   * Replaces a device with a new one with new name and/or x/y dpi, and return the new device. If
   * the name and dpi values are identical the given device is returned an nothing is done
   *
   * @param device the {@link LayoutDevice} to replace
   * @param newName the new name.
   * @param newXDpi the new X dpi value
   * @param newYDpi the new Y dpi value.
   * @return the new LayoutDevice
   */
  public LayoutDevice replaceUserDevice(
      LayoutDevice device, String newName, float newXDpi, float newYDpi) {
    if (device.getName().equals(newName)
        && device.getXDpi() == newXDpi
        && device.getYDpi() == newYDpi) {
      return device;
    }

    // else create a new device
    LayoutDevice newDevice = new LayoutDevice(newName);
    newDevice.setXDpi(newXDpi);
    newDevice.setYDpi(newYDpi);

    // and get the Folderconfiguration
    List<DeviceConfig> configs = device.getConfigs();
    newDevice.addConfigs(configs);

    // replace the old device with the new
    mUserLayoutDevices.remove(device);
    mUserLayoutDevices.add(newDevice);
    combineLayoutDevices();

    return newDevice;
  }