package com.squareup.spoon.model;

/** Device dipslay resolution. */
public class Resolution {
  public int width;
  public int height;

  @Override public String toString() {
    return width + "x" + height;
  }

  public static Resolution parse(String resolution) {
    try {
      String[] parts = resolution.split("x");
      Resolution r = new Resolution();
      r.width = Integer.parseInt(parts[0]);
      r.height = Integer.parseInt(parts[1]);
      return r;
    } catch (Exception e) {
      throw new IllegalArgumentException("Unable to parse resolution.", e);
    }
  }
}

@@ -32,297 +32,1556 @@
 l;%0A%0A
-/** Device dipslay resolution. */%0Apublic class Resolution %7B%0A  public int width;%0A  public int height;%0A%0A  @Override public String toString() %7B%0A    return width + %22x%22 + height;%0A  %7D%0A%0A  public static Resolution parse(String resolution) %7B%0A    try %7B%0A      String%5B%5D parts = resolution.split(%22x%22);%0A
+import java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A/** Device dipslay resolution. */%0Apublic class Resolution %7B%0A  private static final Pattern CUSTOM = Pattern.compile(%22(%5C%5Cd%7B3,%7D)x(%5C%5Cd%7B3,%7D)%22);%0A  private static final List%3CResolution%3E RESOLUTIONS = Arrays.asList(%0A      new Resolution(%22HVGA%22, 320, 480),%0A      new Resolution(%22QVGA%22, 240, 320),%0A      new Resolution(%22WQVGA400%22, 240, 400),%0A      new Resolution(%22WQVGA432%22, 240, 432),%0A      new Resolution(%22WSVGA%22, 1076, 654),%0A      new Resolution(%22WVGA800%22, 480, 800),%0A      new Resolution(%22WVGA850%22, 480, 854),%0A      new Resolution(%22WXGA720%22, 773, 1334),%0A      new Resolution(%22WXGA800%22, 1333, 855),%0A      new Resolution(%22WXGA800-7in%22, 853, 1334),%0A      new Resolution(%22720p%22, 1280, 720),%0A      new Resolution(%221080p%22, 1920, 1080)%0A  );%0A%0A  public String name;%0A  public int width;%0A  public int height;%0A%0A  public Resolution() %7B%0A  %7D%0A%0A  public Resolution(String name, int width, int height) %7B%0A    this.name = name;%0A    this.width = width;%0A    this.height = height;%0A  %7D%0A%0A  @Override public String toString() %7B%0A    StringBuilder builder = new StringBuilder();%0A    boolean hasName = !%22%22.equals(name);%0A    if (hasName) %7B%0A      builder.append(name).append(%22 (%22);%0A    %7D%0A    builder.append(width).append(%22x%22).append(height);%0A    if (hasName) %7B%0A      builder.append(%22)%22);%0A    %7D%0A    return builder.toString();%0A  %7D%0A%0A  public static Resolution parse(String resolution) %7B%0A    Matcher match = CUSTOM.matcher(resolution);%0A    if (match != null) %7B%0A      try %7B%0A  
     
@@ -1621,16 +1621,18 @@
 ;%0A      
+  
 r.width 
@@ -1654,16 +1654,22 @@
 Int(
-parts%5B0%5D
+match.group(1)
 );%0A 
@@ -1673,16 +1673,18 @@
 ;%0A      
+ 
+ 
 r.height
@@ -1707,19 +1707,27 @@
 Int(
-parts%5B1%5D
+match.group(2)
 );%0A
+  
     
@@ -1742,16 +1742,18 @@
  r;%0A    
+  
 %7D catch 
@@ -1753,16 +1753,28 @@
  catch (
+NumberFormat
 Exceptio
@@ -1776,24 +1776,26 @@
 eption e) %7B%0A
+  
       throw 
@@ -1854,21 +1854,232 @@
 tion
-.%22, e);%0A    %7D
+: %22 + resolution, e);%0A      %7D%0A    %7D%0A%0A    for (Resolution r : RESOLUTIONS) %7B%0A      if (r.name.equals(resolution)) %7B%0A        return r;%0A      %7D%0A    %7D%0A%0A    throw new IllegalArgumentException(%22Unknown resolution: %22 + resolution);
 %0A  %7D

Add named resolution support.