예제 #1
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;
  }