Revert "Revert "Resolve merge conflicts of 91f2a6a to nyc-dev""

This reverts commit 9bd6d548b125fdd6b9ad7cf97cf6045a502d52bd.
diff --git a/res/assets/templates/macros.cs b/res/assets/templates/macros.cs
index e897cca..750a31d 100644
--- a/res/assets/templates/macros.cs
+++ b/res/assets/templates/macros.cs
@@ -1,9 +1,11 @@
-<?cs # A link to a package ?><?cs 
+<?cs # A link to a package ?><?cs
 def:package_link(pkg) ?>
-  <a href="<?cs var:toroot ?><?cs var:pkg.link ?>"><?cs var:pkg.name ?></a><?cs 
+  <a href="<?cs var:toroot ?><?cs var:pkg.link ?>"><?cs var:pkg.name ?></a><?cs
 /def ?>
 
-<?cs # A link to a type, or not if it's a primitive type
+
+
+<?cs # A link to a type, or not if it is a primitive type
         link: whether to create a link at the top level, always creates links in
               recursive invocations.
               Overloaded version to support use of 'nav' parameter, which when true,
@@ -15,16 +17,16 @@
             .superBounds.N.(more links)   (... super ... & ...)
             .extendsBounds.N.(more links) (... extends ... & ...)
             .typeArguments.N.(more links) (< ... >)
-?><?cs 
+?><?cs
 def:type_link_impl(type, link) ?><?cs call:type_link_impl2(type, link, "false") ?><?cs /def ?><?cs
 def:type_link_impl2(type, link, nav) ?><?cs
   if:type.link && link=="true" ?><?cs
     if:type.federated ?><a href="<?cs var:type.link ?>"><?cs
-      var:type.label ?></a><?cs 
+      var:type.label ?></a><?cs
     else ?><a href="<?cs var:toroot ?><?cs var:type.link ?>"><?cs var:type.label ?></a><?cs
     /if ?><?cs
   else ?><?cs var:type.label ?><?cs
-  /if ?><?cs 
+  /if ?><?cs
   if:subcount(type.extendsBounds) ?><?cs
       each:t=type.extendsBounds ?><?cs
           if:first(t) ?>&nbsp;extends&nbsp;<?cs else ?>&nbsp;&amp;&nbsp;<?cs /if ?><?cs
@@ -73,7 +75,7 @@
   if:condition ?><a href="<?cs var:root ?><?cs var:path ?>"><?cs /if ?><?cs var:text ?><?cs if:condition ?></a><?cs /if ?><?cs
 /def ?>
 
-<?cs # A comma separated parameter list ?><?cs 
+<?cs # A comma separated parameter list ?><?cs
 def:parameter_list(params) ?><?cs
   each:param = params ?><?cs
       call:simple_type_link(param.type)?> <?cs
@@ -123,7 +125,7 @@
       elif:tag.kind == "@adtZipBytes" ?><?cs var:adt.zip.bytes ?><?cs
       elif:tag.kind == "@adtZipChecksum" ?><?cs var:adt.zip.checksum ?><?cs
       elif:tag.kind == "@inheritDoc" ?><?cs # This is the case when @inheritDoc is in something
-                                              that doesn't inherit from anything?><?cs
+                                              that does not inherit from anything?><?cs
       elif:tag.kind == "@attr" ?><?cs
       else ?>{<?cs var:tag.name?> <?cs var:tag.text ?>}<?cs
       /if ?><?cs
@@ -207,7 +209,7 @@
   call:show_annotations_list(obj, pre, ", ", post) ?><?cs
 /def ?>
 
-<?cs # Show the red box with the deprecated warning ?><?cs 
+<?cs # Show the red box with the deprecated warning ?><?cs
 def:deprecated_warning(obj) ?><?cs
   if:subcount(obj.deprecated) ?><p>
   <p class="caution"><strong><?cs
@@ -222,22 +224,22 @@
   /if ?><?cs
 /def ?>
 
-<?cs # print the See Also: section ?><?cs 
-def:see_also_tags(also) ?><?cs 
+<?cs # print the See Also: section ?><?cs
+def:see_also_tags(also) ?><?cs
   if:subcount(also) ?>
-  <div class="jd-tagdata">
-      <h5 class="jd-tagtitle">See Also</h5>
-      <ul class="nolist"><?cs 
+  <div>
+      <p><b>See also:</b></p>
+      <ul class="nolist"><?cs
         each:tag=also ?><li><?cs
             if:tag.kind == "@see" ?><code><a href="<?cs var:toroot ?><?cs var:tag.href ?>"><?cs
                     var:tag.label ?></a></code><?cs
             elif:tag.kind == "@seeHref" ?><a href="<?cs var:tag.href ?>"><?cs var:tag.label ?></a><?cs
             elif:tag.kind == "@seeJustLabel" ?><?cs var:tag.label ?><?cs
             else ?>[ERROR: Unknown @see kind]<?cs
-            /if ?></li><?cs 
+            /if ?></li><?cs
         /each ?>
       </ul>
-  </div><?cs 
+  </div><?cs
   /if ?>
 <?cs /def ?>
 
@@ -250,127 +252,162 @@
 <?cs def:federated_refs(obj) ?>
   <?cs if:subcount(obj.federated) ?>
     <div>
-    Also: 
+    Also:
     <?cs each:federated=obj.federated ?>
-      <a href="<?cs var:federated.url ?>"><?cs var:federated.name ?></a><?cs 
+      <a href="<?cs var:federated.url ?>"><?cs var:federated.name ?></a><?cs
       if:!last(federated) ?>,<?cs /if ?>
     <?cs /each ?>
     </div>
   <?cs /if ?>
 <?cs /def ?>
-<?cs # Print the long-form description for something.
-       Uses the following fields: deprecated descr seeAlso since ?><?cs
-def:description(obj) ?><?cs 
+<?cs
+#
+# Print the long-form description for something.
+# Uses the following fields: deprecated descr seeAlso since
+#
+?><?cs
+def:description(obj) ?><?cs
   call:deprecated_warning(obj) ?>
-  <div class="jd-tagdata jd-tagdescr"><p><?cs call:tag_list(obj.descr) ?></p></div><?cs 
+  <p><?cs call:tag_list(obj.descr) ?></p><?cs
   if:subcount(obj.annotationdocumentation)?><?cs
     each:annodoc=obj.annotationdocumentation ?>
-    <div class="jd-tagdata" style="display:block"><?cs var:annodoc.text?></div><?cs
+    <div style="display:block"><?cs var:annodoc.text?></div><?cs
     /each?><?cs /if?><?cs
   if:subcount(obj.attrRefs) ?>
-  <div class="jd-tagdata">
-      <h5 class="jd-tagtitle">Related XML Attributes</h5>
-      <ul class="nolist"><?cs 
+      <p><b>Related XML Attributes:</b></p>
+      <ul class="nolist"><?cs
         each:attr=obj.attrRefs ?>
-            <li><a href="<?cs var:toroot ?><?cs var:attr.href ?>"><?cs var:attr.name ?></a></li><?cs 
+            <li><a href="<?cs var:toroot ?><?cs var:attr.href ?>"><?cs var:attr.name ?></a></li><?cs
         /each ?>
-      </ul>
-  </div><?cs 
-  /if ?><?cs 
+      </ul><?cs
+  /if ?><?cs
   if:subcount(obj.blockTags) ?>
     <?cs call:block_tag_list(obj.blockTags) ?><?cs
   /if ?><?cs
+  #
+  # Print the @param tags
+  #
+  ?><?cs
   if:subcount(obj.paramTags) ?>
-  <div class="jd-tagdata">
-      <h5 class="jd-tagtitle">Parameters</h5>
-      <table class="jd-tagtable"><?cs 
-      each:tag=obj.paramTags ?>
-        <tr>
-          <th><?cs if:tag.isTypeParameter ?>&lt;<?cs /if ?><?cs var:tag.name
-                  ?><?cs if:tag.isTypeParameter ?>&gt;<?cs /if ?></td>
-          <td><?cs call:tag_list(tag.comment) ?></td>
-        </tr><?cs 
-      /each ?>
-      </table>
-  </div><?cs 
-  /if ?><?cs 
+    <table class="responsive">
+    <tr><th colspan=2>Parameters</th></tr><?cs
+    each:param=obj.paramTags ?>
+      <tr>
+        <td><code><?cs
+          if:param.isTypeParameter ?>&lt;<?cs
+          /if ?><?cs var:param.name ?><?cs
+          if:param.isTypeParameter ?>&gt;<?cs
+          /if ?></code></td>
+        <td width="100%">
+          <code><?cs var:param.kind ?></code><?cs
+          if:string.find(param.comment.0.text, "<!--") != 0
+            ?>:<?cs # Do not print if param comment is an HTML comment ?><?cs
+          /if ?>
+          <?cs call:tag_list(param.comment) ?></td>
+      </tr><?cs
+    /each ?>
+    </table><?cs
+  /if ?><?cs
+  #
+  # Print the @return value
+  #
+  ?><?cs
   if:subcount(obj.returns) ?>
-  <div class="jd-tagdata">
-      <h5 class="jd-tagtitle">Returns</h5>
-      <ul class="nolist"><li><?cs call:tag_list(obj.returns) ?></li></ul>
-  </div><?cs 
-  /if ?><?cs 
+    <table class="responsive">
+      <tr><th colspan=2>Returns</th></tr>
+      <tr>
+        <td><code><?cs call:type_link(method.returnType) ?></code></td>
+        <td width="100%"><?cs call:tag_list(obj.returns) ?></td>
+      </tr>
+    </table><?cs
+  #
+  # If no return tag found, but there is a return type not 'void', print it
+  #
+  ?><?cs
+  elif:subcount(method.returnType) && method.returnType.label != 'void' ?>
+    <table class="responsive">
+      <tr><th colspan=2>Returns</th></tr>
+      <tr>
+        <td><code><?cs call:type_link(method.returnType) ?></code></td>
+        <td width="100%"><!-- no returns description in source --></td>
+      </tr>
+    </table><?cs
+  /if ?><?cs
+  #
+  # Print the throwables
+  #
+  ?><?cs
   if:subcount(obj.throws) ?>
-  <div class="jd-tagdata">
-      <h5 class="jd-tagtitle">Throws</h5>
-      <table class="jd-tagtable"><?cs 
-      each:tag=obj.throws ?>  
+      <table class="responsive">
+      <tr><th colspan=2>Throws</th></tr><?cs
+      each:tag=obj.throws ?>
         <tr>
-            <th><?cs call:type_link(tag.type) ?></td>
-            <td><?cs call:tag_list(tag.comment) ?></td>
-        </tr><?cs 
+          <td><code><?cs call:type_link(tag.type) ?></code></td>
+          <td width="100%"><?cs call:tag_list(tag.comment) ?></td>
+        </tr><?cs
       /each ?>
       </table>
-  </div><?cs 
-  /if ?><?cs 
+  <?cs
+  /if ?><?cs
   call:see_also_tags(obj.seeAlso) ?><?cs
 /def ?>
 
 <?cs # A table of links to classes with descriptions, as in a package file or the nested classes ?><?cs
-def:class_link_table(classes) ?><?cs 
+def:class_link_table(classes) ?><?cs
   set:count = #1 ?>
   <table class="jd-sumtable-expando"><?cs
       each:cl=classes ?>
         <tr class="<?cs if:count % #2 ?>alt-color<?cs /if ?> api apilevel-<?cs var:cl.type.since ?>" >
-              <td class="jd-linkcol"><?cs call:type_link(cl.type) ?></td>
-              <td class="jd-descrcol" width="100%"><?cs call:short_descr(cl) ?>&nbsp;</td>
+              <td><?cs call:type_link(cl.type) ?></td>
+              <td width="100%"><?cs call:short_descr(cl) ?>&nbsp;</td>
           </tr><?cs set:count = count + #1 ?><?cs
       /each ?>
-  </table><?cs 
+  </table><?cs
 /def ?>
 
-<?cs # A list of links to classes, for use in the side navigation of classes when viewing a package (panel nav) ?><?cs 
-def:class_link_list(label, classes) ?><?cs 
+<?cs # A list of links to classes, for use in the side navigation of classes when viewing a package (panel nav) ?><?cs
+def:class_link_list(label, classes) ?><?cs
   if:subcount(classes) ?>
     <li><h2><?cs var:label ?></h2>
-      <ul><?cs 
+      <ul><?cs
       each:cl=classes ?>
         <li class="api apilevel-<?cs var:cl.type.since ?>"><?cs call:type_link2(cl.type,"true") ?></li><?cs
       /each ?>
       </ul>
-    </li><?cs 
-  /if ?><?cs 
+    </li><?cs
+  /if ?><?cs
 /def ?>
 
-<?cs # A list of links to classes, for use in the side navigation of classes when viewing a class (panel nav) ?><?cs 
-def:list(label, classes) ?><?cs 
+<?cs # A list of links to classes, for use in the side navigation of classes when viewing a class (panel nav) ?><?cs
+def:list(label, classes) ?><?cs
   if:subcount(classes) ?>
     <li><h2><?cs var:label ?></h2>
-      <ul><?cs 
+      <ul><?cs
       each:cl=classes ?>
           <li class="<?cs if:class.name == cl.label?>selected <?cs /if ?>api apilevel-<?cs var:cl.since ?>"><?cs call:type_link2(cl,"true") ?></li><?cs
       /each ?>
       </ul>
-    </li><?cs 
-  /if ?><?cs 
+    </li><?cs
+  /if ?><?cs
 /def ?>
 
-<?cs # A list of links to packages, for use in the side navigation of packages (panel nav) ?><?cs 
-def:package_link_list(packages) ?><?cs 
+<?cs # A list of links to packages, for use in the side navigation of packages (panel nav) ?><?cs
+def:package_link_list(packages) ?><?cs
   each:pkg=packages ?>
-    <li class="<?cs if:(class.package.name == pkg.name) || (package.name == pkg.name)?>selected <?cs /if ?>api apilevel-<?cs var:pkg.since ?>"><?cs call:package_link(pkg) ?></li><?cs 
+    <li class="<?cs if:(class.package.name == pkg.name) || (package.name == pkg.name)?>selected <?cs /if ?>api apilevel-<?cs var:pkg.since ?>"><?cs call:package_link(pkg) ?></li><?cs
   /each ?><?cs
 /def ?>
 
-<?cs # An expando trigger ?><?cs 
+<?cs # An expando trigger ?><?cs
 def:expando_trigger(id, default) ?>
   <a href="#" onclick="return toggleInherited(this, null)" id="<?cs var:id ?>" class="jd-expando-trigger closed"
-          ><img id="<?cs var:id ?>-trigger"
-          src="<?cs var:toroot ?>assets/images/triangle-<?cs var:default ?>.png"
-          class="jd-expando-trigger-img" /></a><?cs 
+          ><img height="34" id="<?cs var:id ?>-trigger"
+          src="<?cs var:toroot ?>assets/images/styles/disclosure_<?cs
+            if:default == 'closed' ?>down<?cs else ?>up<?cs /if ?>.png"
+          class="jd-expando-trigger-img" /></a><?cs
 /def ?>
 
-<?cs # An expandable list of classes ?><?cs 
+<?cs # An expandable list of classes ?><?cs
 def:expandable_class_list(id, classes, default) ?>
   <div id="<?cs var:id ?>">
       <div id="<?cs var:id ?>-list"
@@ -396,11 +433,10 @@
       </div>
       <div id="<?cs var:id ?>-summary"
               <?cs if:default != "summary" ?>style="display: none;"<?cs /if ?>
-              ><?cs 
+              ><?cs
           call:class_link_table(classes) ?>
       </div>
-  </div><?cs 
+  </div><?cs
 /def ?>
 
 <?cs include:"components.cs" ?>
-
diff --git a/src/com/google/doclava/ClearPage.java b/src/com/google/doclava/ClearPage.java
index ed1f069..853e49d 100644
--- a/src/com/google/doclava/ClearPage.java
+++ b/src/com/google/doclava/ClearPage.java
@@ -107,7 +107,9 @@
       }
     }
     data.setValue("toroot", toroot);
-
+    if (Doclava.USE_UPDATED_TEMPLATES) {
+      data.setValue("useUpdatedTemplates", "true");
+    }
     data.setValue("filename", filename);
 
     if (!fullPath) {
@@ -157,7 +159,7 @@
     }
   }
 
-  public static void copyFile(boolean allowExcepted, File from, String toPath) {
+  public static void copyFile(boolean allowExcepted, File from, String toPath, Boolean append) {
     File to = new File(outputDir + "/" + toPath);
     FileInputStream in;
     FileOutputStream out;
@@ -172,9 +174,9 @@
     }
     ensureDirectory(to);
     try {
-      out = new FileOutputStream(to);
+      out = new FileOutputStream(to, append);
     } catch (IOException e) {
-      System.err.println(from.getAbsolutePath() + ": Error opening file");
+      System.err.println(to.getAbsolutePath() + ": Error opening file");
       return;
     }
     if (!isValidContentType(allowExcepted, toPath, DROIDDOC_VALID_CONTENT_TYPES)) {
diff --git a/src/com/google/doclava/DocFile.java b/src/com/google/doclava/DocFile.java
index 9e45bfd..43262d0 100644
--- a/src/com/google/doclava/DocFile.java
+++ b/src/com/google/doclava/DocFile.java
@@ -51,8 +51,8 @@
     }
   }
 
-  public static String[] DEVSITE_VALID_LANGS = {"en", "es","ja", "ko",
-      "ru", "zh-cn", "zh-tw", "pt-br"};
+  public static String[] DEVSITE_VALID_LANGS = {"en", "es", "in", "ja", "ko",
+      "ru", "vi", "zh-cn", "zh-tw", "pt-br"};
 
   public static String getPathRoot(String filename) {
     //look for a valid lang string in the file path. If found,
@@ -183,87 +183,233 @@
       // Strip out the intl and lang id substr and get back just the
       // guide, design, distribute, etc.
       filename = getPathRoot(filename);
-      if (filename.indexOf("design") == 0) {
-        hdf.setValue("design", "true");
-        hdf.setValue("page.type", "design");
-      } else if (filename.indexOf("develop") == 0) {
-        hdf.setValue("develop", "true");
-        hdf.setValue("page.type", "develop");
-      } else if (filename.indexOf("guide") == 0) {
-        hdf.setValue("guide", "true");
-        hdf.setValue("page.type", "guide");
-      } else if (filename.indexOf("training") == 0) {
-        hdf.setValue("training", "true");
-        hdf.setValue("page.type", "training");
-      } else if (filename.indexOf("more") == 0) {
-        hdf.setValue("more", "true");
-      } else if (filename.indexOf("google") == 0) {
-        hdf.setValue("google", "true");
-        hdf.setValue("page.type", "google");
-      } else if (filename.indexOf("samples") == 0) {
-        hdf.setValue("samples", "true");
-        hdf.setValue("page.type", "samples");
-        if (Doclava.samplesNavTree != null) {
-          hdf.setValue("samples_toc_tree", Doclava.samplesNavTree.getValue("samples_toc_tree", ""));
-        }
-      } else if (filename.indexOf("distribute") == 0) {
-        hdf.setValue("distribute", "true");
-        hdf.setValue("page.type", "distribute");
-        if (filename.indexOf("distribute/googleplay") == 0) {
-          hdf.setValue("googleplay", "true");
-        } else if (filename.indexOf("distribute/essentials") == 0) {
-          hdf.setValue("essentials", "true");
-        } else if (filename.indexOf("distribute/users") == 0) {
-          hdf.setValue("users", "true");
-        } else if (filename.indexOf("distribute/engage") == 0) {
-          hdf.setValue("engage", "true");
-        } else if (filename.indexOf("distribute/monetize") == 0) {
-          hdf.setValue("monetize", "true");
-        } else if (filename.indexOf("distribute/analyze") == 0) {
-          hdf.setValue("analyze", "true");
-        } else if (filename.indexOf("distribute/tools") == 0) {
-          hdf.setValue("essentials", "true");
-        } else if (filename.indexOf("distribute/stories") == 0) {
-          hdf.setValue("stories", "true");
-        }
-      } else if (filename.indexOf("about") == 0) {
-        hdf.setValue("about", "true");
-        hdf.setValue("page.type", "about");
-      } else if ((filename.indexOf("tools") == 0) || (filename.indexOf("sdk") == 0)) {
-        hdf.setValue("tools", "true");
-        hdf.setValue("page.type", "tools");
-        fromTemplate = hdf.getValue("page.template", "");
-      } else if (filename.indexOf("devices") == 0) {
-        hdf.setValue("devices", "true");
-        hdf.setValue("page.type", "devices");
-      } else if (filename.indexOf("source") == 0) {
-        hdf.setValue("source", "true");
-      } else if (filename.indexOf("security") == 0) {
-        hdf.setValue("security", "true");
-      } else if (filename.indexOf("compatibility") == 0) {
-        hdf.setValue("compatibility", "true");
-      } else if (filename.indexOf("wear") == 0) {
-        hdf.setValue("wear", "true");
-      } else if (filename.indexOf("preview") == 0) {
-        hdf.setValue("preview", "true");
-        hdf.setValue("page.type", "preview");
-      } else if (filename.indexOf("auto") == 0) {
-        hdf.setValue("auto", "true");
-      } else if (filename.indexOf("tv") == 0) {
-        hdf.setValue("tv", "true");
-      } else if (filename.indexOf("ndk") == 0) {
-        hdf.setValue("ndk", "true");
-        hdf.setValue("page.type", "ndk");
-        if (filename.indexOf("ndk/guides") == 0) {
-          hdf.setValue("guide", "true");
-        } else if (filename.indexOf("ndk/reference") == 0) {
-          hdf.setValue("reference", "true");
-        } else if (filename.indexOf("ndk/samples") == 0) {
-          hdf.setValue("samples", "true");
-        } else if (filename.indexOf("ndk/downloads") == 0) {
-          hdf.setValue("downloads", "true");
-          fromTemplate = hdf.getValue("page.template", "");
 
+      if (Doclava.USE_UPDATED_TEMPLATES) {
+        //remap types to design, dev, distribute etc.
+        if (filename.indexOf("design") == 0) {
+          hdf.setValue("design", "true");
+          hdf.setValue("page.type", "design");
+          hdf.setValue("page.category", "design");
+        } else if (filename.indexOf("develop") == 0) {
+          hdf.setValue("develop", "true");
+          hdf.setValue("page.type", "develop");
+          hdf.setValue("page.category", "develop");
+        } else if (filename.indexOf("guide") == 0) {
+          hdf.setValue("guide", "true");
+          hdf.setValue("page.type", "develop");
+          if (filename.indexOf("guide/topics/manif") == 0) {
+            hdf.setValue("page.category", "app manifest");
+          } else {
+            hdf.setValue("page.category", "guide");
+          }
+        } else if (filename.indexOf("training") == 0) {
+          hdf.setValue("training", "true");
+          hdf.setValue("page.type", "develop");
+          hdf.setValue("page.category", "training");
+        } else if (filename.indexOf("more") == 0) {
+          hdf.setValue("more", "true");
+        } else if (filename.indexOf("google") == 0) {
+          hdf.setValue("google", "true");
+          hdf.setValue("page.type", "develop");
+          hdf.setValue("page.category", "google");
+        } else if (filename.indexOf("samples") == 0) {
+          hdf.setValue("samples", "true");
+          hdf.setValue("page.type", "develop");
+          hdf.setValue("page.category", "samples");
+          if (Doclava.samplesNavTree != null) {
+            hdf.setValue("samples_toc_tree", Doclava.samplesNavTree.getValue("samples_toc_tree", ""));
+          }
+        } else if (filename.indexOf("distribute") == 0) {
+          hdf.setValue("distribute", "true");
+          hdf.setValue("page.type", "distribute");
+          hdf.setValue("page.category", "distribute");
+          if (filename.indexOf("distribute/googleplay") == 0) {
+            hdf.setValue("page.category", "googleplay");
+            hdf.setValue("page.type", "distribute");
+            hdf.setValue("googleplay", "true");
+          } else if (filename.indexOf("distribute/essentials") == 0) {
+            hdf.setValue("page.category", "essentials");
+            hdf.setValue("essentials", "true");
+          } else if (filename.indexOf("distribute/users") == 0) {
+            hdf.setValue("page.category", "users");
+            hdf.setValue("users", "true");
+          } else if (filename.indexOf("distribute/engage") == 0) {
+            hdf.setValue("page.category", "engage");
+            hdf.setValue("engage", "true");
+          } else if (filename.indexOf("distribute/monetize") == 0) {
+            hdf.setValue("page.category", "monetize");
+            hdf.setValue("monetize", "true");
+          } else if (filename.indexOf("distribute/analyze") == 0) {
+            hdf.setValue("page.category", "analyze");
+            hdf.setValue("analyze", "true");
+          } else if (filename.indexOf("distribute/tools") == 0) {
+            hdf.setValue("page.category", "essentials");
+            hdf.setValue("essentials", "true");
+          } else if (filename.indexOf("distribute/stories") == 0) {
+            hdf.setValue("page.category", "stories");
+            hdf.setValue("stories", "true");
+          }
+        } else if (filename.indexOf("about") == 0) {
+          hdf.setValue("about", "true");
+          hdf.setValue("page.type", "about");
+          hdf.setValue("page.category", "about");
+          if ((filename.indexOf("about/versions") == 0)) {
+            hdf.setValue("versions", "true");
+            hdf.setValue("page.category", "versions");
+          } else if ((filename.indexOf("wear") == 0)) {
+            hdf.setValue("wear", "true");
+            hdf.setValue("page.category", "wear");
+          } else if ((filename.indexOf("tv") == 0)) {
+            hdf.setValue("tv", "true");
+            hdf.setValue("page.category", "tv");
+          } else if ((filename.indexOf("auto") == 0)) {
+            hdf.setValue("auto", "true");
+            hdf.setValue("page.category", "auto");
+          }
+        } else if ((filename.indexOf("tools") == 0) || (filename.indexOf("sdk") == 0)) {
+          hdf.setValue("tools", "true");
+          hdf.setValue("page.type", "develop");
+          hdf.setValue("page.category", "tools");
+          fromTemplate = hdf.getValue("page.template", "");
+        } else if (filename.indexOf("devices") == 0) {
+          hdf.setValue("devices", "true");
+          hdf.setValue("page.type", "devices");
+        } else if (filename.indexOf("source") == 0) {
+          hdf.setValue("source", "true");
+        } else if (filename.indexOf("accessories") == 0) {
+          hdf.setValue("accessories", "true");
+        } else if (filename.indexOf("compatibility") == 0) {
+          hdf.setValue("compatibility", "true");
+        } else if (filename.indexOf("wear") == 0) {
+          hdf.setValue("wear", "true");
+          hdf.setValue("about", "true");
+          hdf.setValue("page.type", "about");
+          hdf.setValue("page.category", "wear");
+        } else if (filename.indexOf("preview") == 0) {
+          hdf.setValue("page.type", "develop");
+          hdf.setValue("page.category", "preview");
+          hdf.setValue("preview", "true");
+        } else if (filename.indexOf("auto") == 0) {
+          hdf.setValue("auto", "true");
+          hdf.setValue("about", "true");
+          hdf.setValue("page.type", "about");
+          hdf.setValue("page.category", "auto");
+        } else if (filename.indexOf("tv") == 0) {
+          hdf.setValue("tv", "true");
+          hdf.setValue("about", "true");
+          hdf.setValue("page.type", "about");
+          hdf.setValue("page.category", "tv");
+        } else if (filename.indexOf("ndk") == 0) {
+          hdf.setValue("ndk", "true");
+          hdf.setValue("page.type", "ndk");
+          hdf.setValue("page.category", "ndk");
+          if (filename.indexOf("ndk/guides") == 0) {
+            hdf.setValue("guide", "true");
+            hdf.setValue("page.type", "ndk");
+            hdf.setValue("page.category", "guide");
+          } else if (filename.indexOf("ndk/reference") == 0) {
+            hdf.setValue("reference", "true");
+            hdf.setValue("page.type", "ndk");
+            hdf.setValue("page.category", "reference");
+          } else if (filename.indexOf("ndk/samples") == 0) {
+            hdf.setValue("samples", "true");
+            hdf.setValue("page.type", "ndk");
+            hdf.setValue("page.category", "samples");
+          } else if (filename.indexOf("ndk/downloads") == 0) {
+            hdf.setValue("downloads", "true");
+            hdf.setValue("page.type", "ndk");
+            hdf.setValue("page.category", "downloads");
+            fromTemplate = hdf.getValue("page.template", "");
+          }
+        } else {
+          hdf.setValue("about", "true");
+          hdf.setValue("page.type", "about");
+          hdf.setValue("page.category", "about");
+        }
+      } else {
+        //support the old mappings
+        if (filename.indexOf("design") == 0) {
+          hdf.setValue("design", "true");
+          hdf.setValue("page.type", "design");
+        } else if (filename.indexOf("develop") == 0) {
+          hdf.setValue("develop", "true");
+          hdf.setValue("page.type", "develop");
+        } else if (filename.indexOf("guide") == 0) {
+          hdf.setValue("guide", "true");
+          hdf.setValue("page.type", "guide");
+        } else if (filename.indexOf("training") == 0) {
+          hdf.setValue("training", "true");
+          hdf.setValue("page.type", "training");
+        } else if (filename.indexOf("more") == 0) {
+          hdf.setValue("more", "true");
+        } else if (filename.indexOf("google") == 0) {
+          hdf.setValue("google", "true");
+          hdf.setValue("page.type", "google");
+        } else if (filename.indexOf("samples") == 0) {
+          hdf.setValue("samples", "true");
+          hdf.setValue("page.type", "samples");
+          if (Doclava.samplesNavTree != null) {
+            hdf.setValue("samples_toc_tree", Doclava.samplesNavTree.getValue("samples_toc_tree", ""));
+          }
+        } else if (filename.indexOf("distribute") == 0) {
+          hdf.setValue("distribute", "true");
+          hdf.setValue("page.type", "distribute");
+          if (filename.indexOf("distribute/googleplay") == 0) {
+            hdf.setValue("googleplay", "true");
+          } else if (filename.indexOf("distribute/essentials") == 0) {
+            hdf.setValue("essentials", "true");
+          } else if (filename.indexOf("distribute/users") == 0) {
+            hdf.setValue("users", "true");
+          } else if (filename.indexOf("distribute/engage") == 0) {
+            hdf.setValue("engage", "true");
+          } else if (filename.indexOf("distribute/monetize") == 0) {
+            hdf.setValue("monetize", "true");
+          } else if (filename.indexOf("distribute/analyze") == 0) {
+            hdf.setValue("analyze", "true");
+          } else if (filename.indexOf("distribute/tools") == 0) {
+            hdf.setValue("essentials", "true");
+          } else if (filename.indexOf("distribute/stories") == 0) {
+            hdf.setValue("stories", "true");
+          }
+        } else if (filename.indexOf("about") == 0) {
+          hdf.setValue("about", "true");
+          hdf.setValue("page.type", "about");
+        } else if ((filename.indexOf("tools") == 0) || (filename.indexOf("sdk") == 0)) {
+          hdf.setValue("tools", "true");
+          hdf.setValue("page.type", "tools");
+          fromTemplate = hdf.getValue("page.template", "");
+        } else if (filename.indexOf("devices") == 0) {
+          hdf.setValue("devices", "true");
+          hdf.setValue("page.type", "devices");
+        } else if (filename.indexOf("source") == 0) {
+          hdf.setValue("source", "true");
+        } else if (filename.indexOf("accessories") == 0) {
+          hdf.setValue("accessories", "true");
+        } else if (filename.indexOf("compatibility") == 0) {
+          hdf.setValue("compatibility", "true");
+        } else if (filename.indexOf("wear") == 0) {
+          hdf.setValue("wear", "true");
+        } else if (filename.indexOf("preview") == 0) {
+          hdf.setValue("page.type", "preview");
+          hdf.setValue("page.category", "preview");
+          hdf.setValue("preview", "true");
+        } else if (filename.indexOf("auto") == 0) {
+          hdf.setValue("auto", "true");
+        } else if (filename.indexOf("tv") == 0) {
+          hdf.setValue("tv", "true");
+        } else if (filename.indexOf("ndk") == 0) {
+          hdf.setValue("ndk", "true");
+          hdf.setValue("page.type", "ndk");
+          if (filename.indexOf("ndk/guides") == 0) {
+            hdf.setValue("guide", "true");
+          } else if (filename.indexOf("ndk/reference") == 0) {
+            hdf.setValue("reference", "true");
+          } else if (filename.indexOf("ndk/samples") == 0) {
+            hdf.setValue("samples", "true");
+          } else if (filename.indexOf("ndk/downloads") == 0) {
+            hdf.setValue("downloads", "true");
+            fromTemplate = hdf.getValue("page.template", "");
+          }
         }
       }
       //set metadata for this file in jd_lists_unified
diff --git a/src/com/google/doclava/Doclava.java b/src/com/google/doclava/Doclava.java
index 825c8f8..24dac58 100644
--- a/src/com/google/doclava/Doclava.java
+++ b/src/com/google/doclava/Doclava.java
@@ -68,7 +68,10 @@
   public static final boolean SORT_BY_NAV_GROUPS = true;
   /* Debug output for PageMetadata, format urls from site root */
   public static boolean META_DBG=false;
-
+  /* Remove after updated templates are launched */
+  public static boolean USE_UPDATED_TEMPLATES = false;
+  /* Show Preview navigation and process preview docs */
+  public static boolean INCLUDE_PREVIEW = false;
   public static String outputPathBase = "/";
   public static ArrayList<String> inputPathHtmlDirs = new ArrayList<String>();
   public static ArrayList<String> inputPathHtmlDir2 = new ArrayList<String>();
@@ -167,7 +170,12 @@
       if (a[0].equals("-d")) {
         outputPathBase = outputPathHtmlDirs = ClearPage.outputDir = a[1];
       } else if (a[0].equals("-templatedir")) {
-        ClearPage.addTemplateDir(a[1]);
+        if (USE_UPDATED_TEMPLATES) {
+          /* remove with updated templates are launched */
+          ClearPage.addTemplateDir("build/tools/droiddoc/templates-sdk-dev");
+        } else {
+          ClearPage.addTemplateDir(a[1]);
+        }
       } else if (a[0].equals("-hdf")) {
         mHDFData.add(new String[] {a[1], a[2]});
       } else if (a[0].equals("-knowntags")) {
@@ -261,6 +269,10 @@
         offlineMode = true;
       } else if (a[0].equals("-metadataDebug")) {
         META_DBG = true;
+      } else if (a[0].equals("-useUpdatedTemplates")) {
+        USE_UPDATED_TEMPLATES = true;
+      } else if (a[0].equals("-includePreview")) {
+        INCLUDE_PREVIEW = true;
       } else if (a[0].equals("-federate")) {
         try {
           String name = a[1];
@@ -401,7 +413,11 @@
   }
       // Write metadata for all processed files to jd_lists_unified.js in out dir
       if (!sTaglist.isEmpty()) {
-        PageMetadata.WriteList(sTaglist);
+        if (USE_UPDATED_TEMPLATES) {
+          PageMetadata.WriteListByLang(sTaglist);
+        } else {
+          PageMetadata.WriteList(sTaglist);
+        }
       }
     }
 
@@ -681,6 +697,12 @@
     if (option.equals("-metadataDebug")) {
       return 1;
     }
+    if (option.equals("-useUpdatedTemplates")) {
+      return 1;
+    }
+    if (option.equals("-includePreview")) {
+      return 1;
+    }
     if (option.equals("-documentannotations")) {
       return 2;
     }
@@ -819,7 +841,8 @@
               Data data = makeHDF();
               String hdfValue = data.getValue("sac") == null ? "" : data.getValue("sac");
               boolean allowExcepted = hdfValue.equals("true") ? true : false;
-              ClearPage.copyFile(allowExcepted, f, templ);
+              boolean append = false;
+              ClearPage.copyFile(allowExcepted, f, templ, append);
         }
       } else if (f.isDirectory()) {
         writeDirectory(f, relative + f.getName() + "/", js);
diff --git a/src/com/google/doclava/MethodInfo.java b/src/com/google/doclava/MethodInfo.java
index 0ea8c33..5ceb0e1 100644
--- a/src/com/google/doclava/MethodInfo.java
+++ b/src/com/google/doclava/MethodInfo.java
@@ -227,7 +227,7 @@
     }
     return mIsDeprecated;
   }
-  
+
   public void setDeprecated(boolean deprecated) {
     mDeprecatedKnown = true;
     mIsDeprecated = deprecated;
@@ -331,7 +331,7 @@
   public TypeInfo returnType() {
     return mReturnType;
   }
-  
+
   public String prettySignature() {
     return name() + prettyParameters();
   }
@@ -339,7 +339,7 @@
   public String prettyQualifiedSignature() {
     return qualifiedName() + prettyParameters();
   }
-  
+
   /**
    * Returns a printable version of the parameters of this method's signature.
    */
@@ -351,7 +351,7 @@
       }
       params.append(pInfo.type().simpleTypeName());
     }
-    
+
     params.append(")");
     return params.toString();
   }
@@ -417,80 +417,102 @@
     return mThrowsTags;
   }
 
-  private static int indexOfParam(String name, String[] list) {
+  private static int indexOfParam(String name, ParamTagInfo[] list) {
     final int N = list.length;
     for (int i = 0; i < N; i++) {
-      if (name.equals(list[i])) {
+      if (name.equals(list[i].parameterName())) {
         return i;
       }
     }
     return -1;
   }
 
+  /* Checks whether the name documented with the provided @param tag
+   * actually matches one of the method parameters. */
+  private boolean isParamTagInMethod(ParamTagInfo tag) {
+    for (ParameterInfo paramInfo : mParameters) {
+      if (paramInfo.name().equals(tag.parameterName())) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   public ParamTagInfo[] paramTags() {
     if (mParamTags == null) {
       final int N = mParameters.size();
+      final String DEFAULT_COMMENT = "<!-- no parameter comment -->";
 
       if (N == 0) {
           // Early out for empty case.
           mParamTags = ParamTagInfo.EMPTY_ARRAY;
           return ParamTagInfo.EMPTY_ARRAY;
       }
+      // Where we put each result
+      mParamTags = ParamTagInfo.getArray(N);
 
-      String[] names = new String[N];
-      String[] comments = new String[N];
-      SourcePositionInfo[] positions = new SourcePositionInfo[N];
+      // collect all the @param tag info
+      ParamTagInfo[] paramTags = comment().paramTags();
 
-      // get the right names so we can handle our names being different from
-      // our parent's names.
-      int i = 0;
-      for (ParameterInfo param : mParameters) {
-        names[i] = param.name();
-        comments[i] = "";
-        positions[i] = param.position();
-        i++;
+      // Complain about misnamed @param tags
+      for (ParamTagInfo tag : paramTags) {
+        if (!isParamTagInMethod(tag)){
+          Errors.error(Errors.UNKNOWN_PARAM_TAG_NAME, tag.position(),
+              "@param tag with name that doesn't match the parameter list: '"
+              + tag.parameterName() + "'");
+        }
       }
 
-      // Gather our comments, and complain about misnamed @param tags. Note that we must
-      // exclude type parameter tags (such as "@param <T> foo") from this analysis.
-      for (ParamTagInfo tag : comment().paramTags()) {
-        int index = indexOfParam(tag.parameterName(), names);
+      // Loop the parameters known from the method signature...
+      // Start by getting the known parameter name and data type. Then, if
+      // there's an @param tag that matches the current parameter name, get the
+      // javadoc comments. But if there's no @param comments here, then
+      // check if it's available from the parent class.
+      int i = 0;
+      for (ParameterInfo param : mParameters) {
+        String name = param.name();
+        String type = param.type().simpleTypeName();
+        String comment = DEFAULT_COMMENT;
+        SourcePositionInfo position = param.position();
+
+        // Find the matching param from the @param tags in order to get
+        // the parameter comments
+        int index = indexOfParam(name, paramTags);
         if (index >= 0) {
-          comments[index] = tag.parameterComment();
-          positions[index] = tag.position();
+          comment = paramTags[index].parameterComment();
+          position = paramTags[index].position();
         } else if (!tag.isTypeParameter()) {
+          // Complain about misnamed @param tags. Note that we must exclude type
+          // parameter tags (such as "@param <T> foo") from this analysis.
           Errors.error(Errors.UNKNOWN_PARAM_TAG_NAME, tag.position(),
               "@param tag with name that doesn't match the parameter list: '" + tag.parameterName()
                   + "'");
-        }
-      }
 
-      // get our parent's tags to fill in the blanks
-      MethodInfo overridden = this.findOverriddenMethod(name(), signature());
-      if (overridden != null) {
-        ParamTagInfo[] maternal = overridden.paramTags();
-        for (i = 0; i < N; i++) {
-          if (comments[i].equals("")) {
-            comments[i] = maternal[i].parameterComment();
-            positions[i] = maternal[i].position();
+        // get our parent's tags to fill in the blanks
+        MethodInfo overridden = this.findOverriddenMethod(name(), signature());
+        if (overridden != null) {
+          ParamTagInfo[] maternal = overridden.paramTags();
+          if (comment.equals(DEFAULT_COMMENT)) {
+            comment = maternal[i].parameterComment();
+            position = maternal[i].position();
           }
         }
-      }
 
-      // construct the results, and cache them for next time
-      mParamTags = ParamTagInfo.getArray(N);
-      for (i = 0; i < N; i++) {
+        // Okay, now add the collected parameter information to the method data
         mParamTags[i] =
-            new ParamTagInfo("@param", "@param", names[i] + " " + comments[i], parent(),
-                positions[i]);
+            new ParamTagInfo("@param", type, name + " " + comment, parent(),
+                position);
 
-        // while we're here, if we find any parameters that are still undocumented at this
-        // point, complain. (this warning is off by default, because it's really, really
-        // common; but, it's good to be able to enforce it)
-        if (comments[i].equals("")) {
-          Errors.error(Errors.UNDOCUMENTED_PARAMETER, positions[i], "Undocumented parameter '"
-              + names[i] + "' on method '" + name() + "'");
+        // while we're here, if we find any parameters that are still
+        // undocumented at this point, complain. This warning is off by
+        // default, because it's really, really common;
+        // but, it's good to be able to enforce it.
+        if (comment.equals(DEFAULT_COMMENT)) {
+          Errors.error(Errors.UNDOCUMENTED_PARAMETER, position,
+              "Undocumented parameter '" + name + "' on method '"
+              + name() + "'");
         }
+        i++;
       }
     }
     return mParamTags;
@@ -549,7 +571,7 @@
     }
     return true;
   }
-  
+
   /**
    * Checks to see if a parameter from a method signature is
    * compatible with a parameter given in a {@code @link} tag.
@@ -697,13 +719,13 @@
   public String getReason() {
     return mReasonOpened;
   }
-  
+
   public void addException(String exec) {
     ClassInfo exceptionClass = new ClassInfo(exec);
 
     mThrownExceptions.add(exceptionClass);
   }
-  
+
   public void addParameter(ParameterInfo p) {
     // Name information
     if (mParameters == null) {
@@ -733,8 +755,8 @@
   private AnnotationValueInfo mDefaultAnnotationElementValue;
   private String mReasonOpened;
   private ArrayList<Resolution> mResolutions;
-  
-  // TODO: merge with droiddoc version (above)  
+
+  // TODO: merge with droiddoc version (above)
   public String qualifiedName() {
     String parentQName = (containingClass() != null)
         ? (containingClass().qualifiedName() + ".") : "";
@@ -753,7 +775,7 @@
         }
         params.append(pInfo.type().fullName());
       }
-      
+
       params.append(")");
       mSignature = params.toString();
     }
diff --git a/src/com/google/doclava/PageMetadata.java b/src/com/google/doclava/PageMetadata.java
index 57f27cb..73668e2 100644
--- a/src/com/google/doclava/PageMetadata.java
+++ b/src/com/google/doclava/PageMetadata.java
@@ -109,6 +109,41 @@
   }
 
   /**
+  * Given a list of metadata nodes organized by lang, sort the
+  * root nodes by type name and render the types and their child
+  * metadata nodes to separate lang-specific json files in the out dir.
+  *
+  * @param rootNodesList A list of root metadata nodes, each
+  *        representing a type and it's member child pages.
+  */
+  public static void WriteListByLang(List<Node> rootNodesList) {
+    Collections.sort(rootNodesList, BY_LANG_NAME);
+    for (Node n : rootNodesList) {
+      String langFilename = "";
+      String langname = n.getLang();
+      langFilename = "_" + langname;
+      Collections.sort(n.getChildren(), BY_TYPE_NAME);
+      Node pageMeta = new Node.Builder().setLabel("TOP").setChildren(n.getChildren()).build();
+
+      StringBuilder buf = new StringBuilder();
+      // write the taglist to string format
+      pageMeta.renderLangResources(buf,langname);
+      //pageMeta.renderTypesByTag(buf);
+      // write the taglist to js file
+      Data data = Doclava.makeHDF();
+      data.setValue("reference_tree", buf.toString());
+      data.setValue("metadata.lang", langname);
+      // remove when updated templates are launched
+      String unifiedFilename = "jd_lists_unified" + langFilename + ".js";
+      String extrasFilename = "jd_extras" + langFilename + ".js";
+      // write out jd_lists_unified for each lang
+      ClearPage.write(data, "jd_lists_unified.cs", unifiedFilename);
+      // append jd_extras to jd_lists_unified for each lang, then delete.
+      appendExtrasMetadata(extrasFilename, unifiedFilename);
+    }
+  }
+
+  /**
   * Extract supported metadata values from a page and add them as
   * a child node of a root node based on type. Some metadata values
   * are normalized. Unsupported metadata fields are ignored. See
@@ -137,16 +172,21 @@
     if (!excludeNode) {
       Node pageMeta = new Node.Builder().build();
       pageMeta.setLabel(getTitleNormalized(hdf, "page.title"));
-      pageMeta.setTitleFriendly(hdf.getValue("page.titleFriendly",""));
+      pageMeta.setCategory(hdf.getValue("page.category",""));
       pageMeta.setSummary(hdf.getValue("page.metaDescription",""));
       pageMeta.setLink(getPageUrlNormalized(filename));
       pageMeta.setGroup(getStringValueNormalized(hdf,"sample.group"));
       pageMeta.setKeywords(getPageTagsNormalized(hdf, "page.tags"));
       pageMeta.setTags(getPageTagsNormalized(hdf, "meta.tags"));
       pageMeta.setImage(getImageUrlNormalized(hdf.getValue("page.image", "")));
-      pageMeta.setLang(getLangStringNormalized(filename));
+      pageMeta.setLang(getLangStringNormalized(hdf, filename));
       pageMeta.setType(getStringValueNormalized(hdf, "page.type"));
-      appendMetaNodeByType(pageMeta, tagList);
+      pageMeta.setTimestamp(hdf.getValue("page.timestamp",""));
+      if (Doclava.USE_UPDATED_TEMPLATES) {
+        appendMetaNodeByLang(pageMeta, tagList);
+      } else {
+        appendMetaNodeByType(pageMeta, tagList);
+      }
     }
   }
 
@@ -323,7 +363,9 @@
     StringBuilder outString =  new StringBuilder();
     String tagList = hdf.getValue(tag, "");
     tagList.replaceAll("\"", "");
-    if (!tagList.isEmpty()) {
+    if ("".equals(tagList)) {
+      return tagList;
+    } else {
       int end = tagList.indexOf(",");
       if (end != -1) {
         tagList = tagList.substring(0,end);
@@ -333,8 +375,8 @@
         tagList = tagList.toLowerCase();
       }
       outString.append(tagList.trim());
-    }
-    return outString.toString();
+      return outString.toString();
+    } 
   }
 
   /**
@@ -370,19 +412,24 @@
   * @param filename A path string to the file relative to root.
   * @return A normalized lang value.
   */
-  public static String getLangStringNormalized(String filename) {
-    String[] stripStr = filename.toLowerCase().split("\\/");
+  public static String getLangStringNormalized(Data data, String filename) {
+    String[] stripStr = filename.toLowerCase().split("\\/", 3);
     String outFrag = "en";
+    String pathCanonical = filename;
     if (stripStr.length > 0) {
       for (String t : DocFile.DEVSITE_VALID_LANGS) {
         if ("intl".equals(stripStr[0])) {
           if (t.equals(stripStr[1])) {
             outFrag = stripStr[1];
+            //extract the root url (exclusive of intl/nn)
+            pathCanonical = stripStr[2];
             break;
           }
         }
       }
     }
+    //extract the root url (exclusive of intl/nn)
+    data.setValue("path.canonical", pathCanonical);
     return outFrag;
   }
 
@@ -488,6 +535,37 @@
   * @param rootList The current list of root nodes.
   * @return The updated list of root nodes.
   */
+  public static List<Node> appendMetaNodeByLang(Node gNode, List<Node> rootList) {
+
+    String nodeLang = gNode.getLang();
+    boolean matched = false;
+    for (Node n : rootList) {
+      if (n.getLang().equals(nodeLang)) {  //find any matching lang node
+        appendMetaNodeByType(gNode,n.getChildren());
+        //n.getChildren().add(gNode);
+        matched = true;
+        break; // add to the first root node only
+      } // tag did not match
+    } // end rootnodes matching iterator
+    if (!matched) {
+      List<Node> mlangList = new ArrayList<Node>(); // list of file objects that have a given lang
+      //mlangList.add(gNode);
+      Node tnode = new Node.Builder().setChildren(mlangList).setLang(nodeLang).build();
+      rootList.add(tnode);
+      appendMetaNodeByType(gNode, mlangList);
+    }
+    return rootList;
+  }
+
+  /**
+  * Given a metadata node, add it as a child of a root node based on its
+  * type. If there is no root node that matches the node's type, create one
+  * and add the metadata node as a child node.
+  *
+  * @param gNode The node to attach to a root node or add as a new root node.
+  * @param rootList The current list of root nodes.
+  * @return The updated list of root nodes.
+  */
   public static List<Node> appendMetaNodeByType(Node gNode, List<Node> rootList) {
 
     String nodeTags = gNode.getType();
@@ -543,6 +621,28 @@
     return rootTagNodesList;
   }
 
+  /**
+  * Append the contents of jd_extras to jd_lists_unified for each language.
+  *
+  * @param extrasFilename The lang-specific extras file to append.
+  * @param unifiedFilename The lang-specific unified metadata file.
+  */
+  public static void appendExtrasMetadata (String extrasFilename, String unifiedFilename) {
+    File f = new File(ClearPage.outputDir + "/" + extrasFilename);
+    if (f.exists() && !f.isDirectory()) {
+      ClearPage.copyFile(true, f, unifiedFilename, true);
+      try {
+        if (f.delete()) {
+          if (Doclava.META_DBG) System.out.println("    >>>>> Delete succeeded");
+        } else {
+          if (Doclava.META_DBG) System.out.println("    >>>>> Delete failed");
+        }
+      } catch (Exception e) {
+        if (Doclava.META_DBG) System.out.println("    >>>>> Exception: " + e + "\n");
+      }
+    }
+  }
+
   public static final Comparator<Node> BY_TAG_NAME = new Comparator<Node>() {
     public int compare (Node one, Node other) {
       return one.getLabel().compareTo(other.getLabel());
@@ -555,13 +655,19 @@
     }
   };
 
+    public static final Comparator<Node> BY_LANG_NAME = new Comparator<Node>() {
+    public int compare (Node one, Node other) {
+      return one.getLang().compareTo(other.getLang());
+    }
+  };
+
   /**
   * A node for storing page metadata. Use Builder.build() to instantiate.
   */
   public static class Node {
 
     private String mLabel; // holds page.title or similar identifier
-    private String mTitleFriendly; // title for card or similar use
+    private String mCategory; // subtabs, example 'training' 'guides'
     private String mSummary; // Summary for card or similar use
     private String mLink; //link href for item click
     private String mGroup; // from sample.group in _index.jd
@@ -570,11 +676,12 @@
     private String mImage; // holds an href, fully qualified or relative to root
     private List<Node> mChildren;
     private String mLang;
-    private String mType; // can be file, dir, video show, announcement, etc.
+    private String mType; // design, develop, distribute, youtube, blog, etc
+    private String mTimestamp; // optional timestamp eg 1447452827
 
     private Node(Builder builder) {
       mLabel = builder.mLabel;
-      mTitleFriendly = builder.mTitleFriendly;
+      mCategory = builder.mCategory;
       mSummary = builder.mSummary;
       mLink = builder.mLink;
       mGroup = builder.mGroup;
@@ -584,16 +691,17 @@
       mChildren = builder.mChildren;
       mLang = builder.mLang;
       mType = builder.mType;
+      mTimestamp = builder.mTimestamp;
     }
 
     private static class Builder {
-      private String mLabel, mTitleFriendly, mSummary, mLink, mGroup, mImage, mLang, mType;
+      private String mLabel, mCategory, mSummary, mLink, mGroup, mImage, mLang, mType, mTimestamp;
       private List<String> mKeywords = null;
       private List<String> mTags = null;
       private List<Node> mChildren = null;
       public Builder setLabel(String mLabel) { this.mLabel = mLabel; return this;}
-      public Builder setTitleFriendly(String mTitleFriendly) {
-        this.mTitleFriendly = mTitleFriendly; return this;
+      public Builder setCategory(String mCategory) {
+        this.mCategory = mCategory; return this;
       }
       public Builder setSummary(String mSummary) {this.mSummary = mSummary; return this;}
       public Builder setLink(String mLink) {this.mLink = mLink; return this;}
@@ -606,6 +714,7 @@
       public Builder setChildren(List<Node> mChildren) {this.mChildren = mChildren; return this;}
       public Builder setLang(String mLang) {this.mLang = mLang; return this;}
       public Builder setType(String mType) {this.mType = mType; return this;}
+      public Builder setTimestamp(String mTimestamp) {this.mTimestamp = mTimestamp; return this;}
       public Node build() {return new Node(this);}
     }
 
@@ -626,6 +735,24 @@
         }
       }
     }
+
+    /**
+    * Render a tree of metadata nodes organized by lang.
+    * @param buf Output buffer to render to.
+    */
+    void renderLangResources(StringBuilder buf, String langname) {
+      List<Node> list = mChildren; //list of type rootnodes
+      if (list == null || list.size() == 0) {
+        buf.append("null");
+      } else {
+        final int n = list.size();
+        for (int i = 0; i < n; i++) {
+          buf.append("METADATA['" + langname + "']." + list.get(i).mType + " = [");
+          list.get(i).renderTypes(buf); //render this lang's children
+          buf.append("\n];\n\n");
+        }
+      }
+    }
     /**
     * Render all metadata nodes for a specific type.
     * @param buf Output buffer to render to.
@@ -638,16 +765,33 @@
         final int n = list.size();
         for (int i = 0; i < n; i++) {
           buf.append("\n      {\n");
-          buf.append("        \"title\":\"" + list.get(i).mLabel + "\",\n" );
-          buf.append("        \"titleFriendly\":\"" + list.get(i).mTitleFriendly + "\",\n" );
-          buf.append("        \"summary\":\"" + list.get(i).mSummary + "\",\n" );
+          buf.append("        \"title\":\"");
+          renderStrWithUcs(buf, list.get(i).mLabel);
+          buf.append("\",\n" );
+          buf.append("        \"summary\":\"");
+          renderStrWithUcs(buf, list.get(i).mSummary);
+          buf.append("\",\n" );
           buf.append("        \"url\":\"" + list.get(i).mLink + "\",\n" );
-          buf.append("        \"group\":\"" + list.get(i).mGroup + "\",\n" );
+          if (!"".equals(list.get(i).mImage)) {
+            buf.append("        \"image\":\"" + list.get(i).mImage + "\",\n" );
+          }
+          if (!"".equals(list.get(i).mGroup)) {
+            buf.append("        \"group\":\"");
+            renderStrWithUcs(buf, list.get(i).mGroup);
+            buf.append("\",\n" );
+          }
+          if (!"".equals(list.get(i).mCategory)) {
+            buf.append("        \"category\":\"" + list.get(i).mCategory + "\",\n" );
+          }
+          if ((list.get(i).mType != null) && (list.get(i).mType != "")) {
+            buf.append("        \"type\":\"" + list.get(i).mType + "\",\n");
+          }
           list.get(i).renderArrayType(buf, list.get(i).mKeywords, "keywords");
           list.get(i).renderArrayType(buf, list.get(i).mTags, "tags");
-          buf.append("        \"image\":\"" + list.get(i).mImage + "\",\n" );
-          buf.append("        \"lang\":\"" + list.get(i).mLang + "\",\n" );
-          buf.append("        \"type\":\"" + list.get(i).mType + "\"");
+          if (!"".equals(list.get(i).mTimestamp)) {
+            buf.append("        \"timestamp\":\"" + list.get(i).mTimestamp + "\",\n");
+          }
+          buf.append("        \"lang\":\"" + list.get(i).mLang + "\"" );
           buf.append("\n      }");
           if (i != n - 1) {
             buf.append(", ");
@@ -722,22 +866,7 @@
         final int n = list.size();
         for (int i = 0; i < n; i++) {
           String tagval = list.get(i).toString();
-          final int L = tagval.length();
-          for (int t = 0; t < L; t++) {
-            char c = tagval.charAt(t);
-            if (c >= Character.MIN_HIGH_SURROGATE && c <= Character.MAX_HIGH_SURROGATE ) {
-              // we have a UTF-16 multi-byte character
-              int codePoint = tagval.codePointAt(t);
-              int charSize = Character.charCount(codePoint);
-              t += charSize - 1;
-              buf.append(String.format("\\u%04x",codePoint));
-            } else if (c >= ' ' && c <= '~' && c != '\\') {
-              buf.append(c);
-            } else { 
-              // we are encoding a two byte character
-              buf.append(String.format("\\u%04x", (int) c));
-            }
-          }
+          renderStrWithUcs(buf,tagval);
           if (i != n - 1) {
             buf.append(",");
           }
@@ -745,6 +874,31 @@
       }
     }
 
+    /**
+    * Render a string that can include ucs2 encoded characters.
+    * @param buf Output buffer to render to.
+    * @param chars String to append to buf with any necessary encoding
+    */
+    void renderStrWithUcs(StringBuilder buf, String chars) {
+      String strval = chars;
+      final int L = strval.length();
+      for (int t = 0; t < L; t++) {
+        char c = strval.charAt(t);
+        if (c >= Character.MIN_HIGH_SURROGATE && c <= Character.MAX_HIGH_SURROGATE ) {
+          // we have a UTF-16 multi-byte character
+          int codePoint = strval.codePointAt(t);
+          int charSize = Character.charCount(codePoint);
+          t += charSize - 1;
+          buf.append(String.format("\\u%04x",codePoint));
+        } else if (c >= ' ' && c <= '~' && c != '\\') {
+          buf.append(c);
+        } else { 
+          // we are encoding a two byte character
+          buf.append(String.format("\\u%04x", (int) c));
+        }
+      }
+    }
+
     public String getLabel() {
       return mLabel;
     }
@@ -753,12 +907,12 @@
        mLabel = label;
     }
 
-    public String getTitleFriendly() {
-      return mTitleFriendly;
+    public String getCategory() {
+      return mCategory;
     }
 
-    public void setTitleFriendly(String title) {
-       mTitleFriendly = title;
+    public void setCategory(String title) {
+       mCategory = title;
     }
 
     public String getSummary() {
@@ -849,8 +1003,16 @@
       return mType;
     }
 
+    public String getTimestamp() {
+      return mTimestamp;
+    }
+
     public void setType(String type) {
       mType = type;
     }
+
+    public void setTimestamp(String timestamp) {
+      mTimestamp = timestamp;
+    }
   }
 }
diff --git a/src/com/google/doclava/ParamTagInfo.java b/src/com/google/doclava/ParamTagInfo.java
index 13eb30b..d9353c5 100644
--- a/src/com/google/doclava/ParamTagInfo.java
+++ b/src/com/google/doclava/ParamTagInfo.java
@@ -75,6 +75,7 @@
   @Override
   public void makeHDF(Data data, String base) {
     data.setValue(base + ".name", parameterName());
+    data.setValue(base + ".kind", kind());
     data.setValue(base + ".isTypeParameter", isTypeParameter() ? "1" : "0");
     TagInfo.makeHDF(data, base + ".comment", commentTags());
   }
diff --git a/src/com/google/doclava/SampleCode.java b/src/com/google/doclava/SampleCode.java
index 57f1c54..a16fd09 100644
--- a/src/com/google/doclava/SampleCode.java
+++ b/src/com/google/doclava/SampleCode.java
@@ -206,7 +206,7 @@
         if (inList(path, IMAGES)) {
           type = "img";
           if (f.length() < MAX_FILE_SIZE_BYTES) {
-            ClearPage.copyFile(false, f, path);
+            ClearPage.copyFile(false, f, path, false);
             writeImageVideoPage(f, convertExtension(path, Doclava.htmlExtension),
                 relative, type, true);
           } else {
@@ -220,7 +220,7 @@
         } else if (inList(path, VIDEOS)) {
           type = "video";
           if (f.length() < MAX_FILE_SIZE_BYTES) {
-            ClearPage.copyFile(false, f, path);
+            ClearPage.copyFile(false, f, path, false);
             writeImageVideoPage(f, convertExtension(path, Doclava.htmlExtension),
                 relative, type, true);
           } else {