{"id":405,"date":"2020-05-28T13:12:56","date_gmt":"2020-05-28T20:12:56","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=405"},"modified":"2020-05-28T13:12:56","modified_gmt":"2020-05-28T20:12:56","slug":"resource-configuration-for-microsoft-surface-duo","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/resource-configuration-for-microsoft-surface-duo\/","title":{"rendered":"Resource configuration for Microsoft Surface Duo"},"content":{"rendered":"<p>Hello Android dual-screen developers!<\/p>\n<p>As we mentioned in <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/bring-your-app-to-surface-duo\/\">a previous blog post<\/a>, enhancing your app for dual-screen devices is easily done by following this three step process:<\/p>\n<p><img decoding=\"async\" width=\"1484\" height=\"680\" class=\"wp-image-406 alignnone\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/get-your-app-ready-for-dual-screen-devices-in-3-st-1.png\" alt=\"Get your app ready for dual-screen devices in 3 steps\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/get-your-app-ready-for-dual-screen-devices-in-3-st-1.png 1484w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/get-your-app-ready-for-dual-screen-devices-in-3-st-1-300x137.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/get-your-app-ready-for-dual-screen-devices-in-3-st-1-1024x469.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/get-your-app-ready-for-dual-screen-devices-in-3-st-1-768x352.png 768w\" sizes=\"(max-width: 1484px) 100vw, 1484px\" \/><\/p>\n<p style=\"text-align: center;\"><em>Figure 1. Three steps to get your app ready for dual-screen devices<\/em><\/p>\n<p>Today we are going to provide some additional useful tips for embracing new features (Step 3), so your app can take full advantage of both screens when it is spanned.<\/p>\n<h2>Different configurations<\/h2>\n<p>When creating apps, we often have to deal with different screen configurations (dimensions) and make design adjustments so the app adapts to whatever device it is being used on. Surface Duo is no different than other Android devices in that it also has its own <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/duo-dimensions\">device dimensions<\/a> that will need to be considered in your app design. Here are the Surface Duo screen specs to include in your app configuration:<\/p>\n<p>Surface Duo dual-portrait screen specs:<\/p>\n<ul>\n<li>Height: 720dp\/1800px<\/li>\n<li>Width: 540dp\/1350px<\/li>\n<li>Mask: 34dp\/84px<\/li>\n<li>System tray: 24dp\/60px<\/li>\n<li>Handle: 16dp\/40px<\/li>\n<\/ul>\n<p>Surface Duo dual-landscape screen specs:<\/p>\n<ul>\n<li>Single height: 540dp\/1350px<\/li>\n<li>Width: 720dp\/1800px<\/li>\n<li>Mask: 34dp\/84px<\/li>\n<li>System tray: 24dp\/60px<\/li>\n<li>Handle: 20dp\/60px<\/li>\n<\/ul>\n<h2>Creating specific resources for Surface Duo<\/h2>\n<p>When running your app on a Surface Duo device or emulator in single screen mode, you shouldn\u2019t need to make any specific layout changes as your app should work the same way as on any other single screen device. However, when your app is spanned across a dual-screen device, you may see that the layout that you are currently using is not perfectly adapted for this configuration. As an example, you might observe that there is content that is hidden by the hinge, and might consider some layout adjustments so that your app looks and behaves better when used on a dual-screen device. To manage these adjustments, <a href=\"https:\/\/developer.android.com\/guide\/topics\/resources\/providing-resources\">Android provides qualifiers to handle multiple configurations<\/a>, so whether your app is running on a device with a small screen, a tablet with 10\u201d screen in landscape mode, or on Surface Duo, you can use different qualifier values to help you optimize your app for specific device configurations.<\/p>\n<p>By default, your dimens, strings, layouts, and drawables, files go into the (default) <strong>values,<\/strong> <strong>layout <\/strong>and <strong>drawable<\/strong> folders in your app and the values located there are used as the default resources.<\/p>\n<p>When your app is spanned across dual-screens (either in dual-portrait or dual-landscape mode), you can include alternative resources to support multiple device configurations (like dimens, strings, layouts, drawables, etc.) and can create new resource folders with specific qualifier values. For Surface Duo, you can use the qualifier <strong>sw720dp-2784&#215;1800; <\/strong>so, for resource values the specific folder would be <strong>values-sw720dp-2784&#215;1800<\/strong>, for layouts <strong>layout-sw720dp-2784&#215;1800<\/strong>, etc. Surface Duo will take the resources located there and will use them. If no specific resources are available, Surface Duo will apply the existing <a href=\"https:\/\/developer.android.com\/guide\/topics\/resources\/providing-resources#AlternativeResources\">qualifiers in order of precedence<\/a>.<\/p>\n<p>To add a new resource folder, navigate to your <strong>res<\/strong> folder, right click over it and then select <strong>New<\/strong> -&gt; <strong>Android resource Directory<\/strong>.<\/p>\n<p><img decoding=\"async\" class=\"wp-image-407 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/creating-an-new-android-resource-directory-1.png\" alt=\"Creating an new Android resource directory\" width=\"956\" height=\"476\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/creating-an-new-android-resource-directory-1.png 1576w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/creating-an-new-android-resource-directory-1-300x149.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/creating-an-new-android-resource-directory-1-1024x510.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/creating-an-new-android-resource-directory-1-768x383.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/creating-an-new-android-resource-directory-1-1536x765.png 1536w\" sizes=\"(max-width: 956px) 100vw, 956px\" \/><\/p>\n<p style=\"text-align: center;\"><em>Figure 2. Creating a new Android resource directory<\/em><\/p>\n<p>Then in the <strong>New Resource Directory<\/strong>, you just can simply type the <strong>directory name<\/strong> and accept:<\/p>\n<p><img decoding=\"async\" class=\"wp-image-408 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/setting-the-name-for-the-new-resource-directory-1.png\" alt=\"Setting the name for the new resource directory\" width=\"489\" height=\"217\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/setting-the-name-for-the-new-resource-directory-1.png 832w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/setting-the-name-for-the-new-resource-directory-1-300x133.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/setting-the-name-for-the-new-resource-directory-1-768x341.png 768w\" sizes=\"(max-width: 489px) 100vw, 489px\" \/><\/p>\n<p style=\"text-align: center;\"><em>Figure 3. Setting up the directory name<\/em><\/p>\n<p>This is how your app folder structure should look after adding a specific Surface Duo resource folder:<\/p>\n<p><img decoding=\"async\" class=\"wp-image-409 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/project-hierarchy-showing-the-duo-specific-resourc-1.png\" alt=\"Project hierarchy showing the duo specific resource folder\" width=\"402\" height=\"367\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/project-hierarchy-showing-the-duo-specific-resourc-1.png 706w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/project-hierarchy-showing-the-duo-specific-resourc-1-300x274.png 300w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/p>\n<p style=\"text-align: center;\"><em>Figure 4. App project structure with the default and a new specific values-resource folder<\/em><\/p>\n<p>As an important note, remember to always define resources in the default configuration too, otherwise your app might encounter run time exceptions when the configuration changes.<\/p>\n<p>You might be wondering why this strange resource folder qualifier name? If you go up to the Surface Duo dimensions spec we have shared above, you will see how the device in dual-landscape mode has a width of <strong>720dp<\/strong>. This is the value we will use as the devices smallest width and this value doesn\u2019t change when the screen orientation changes, so this value remains constant whether we are in dual-portrait or dual-landscape mode.<\/p>\n<p>The <strong>2784&#215;1800 <\/strong>value provides a more specific configuration. Since sw720dp can be shared with many available tablets on the market, the <strong>2784&#215;1800 <\/strong>value is the specific width and height of the Surface Duo device in pixels. As you can see, Surface Duo has a 1350px width per screen, so 1350 x 2 = 2700px; if we also add the width of the mask\/hinge (84px) we have now have a total width of 2784px (2700 + 84 = <strong>2784px<\/strong>). For height, we simply use the screen height of <strong>1800px, <\/strong>making our total screen value of <strong>2784x1800px.<\/strong><\/p>\n<h2>Sample app running on different devices and configurations<\/h2>\n<p>To help you to visualize what we have covered here, we have created a <a href=\"https:\/\/github.com\/microsoft\/surface-duo-sdk-samples-kotlin\/tree\/master\/Qualifiers\">qualifiers sample app in our Kotlin samples repository<\/a>. Please, have a look and play with the app and the Surface Duo emulator by using just one screen, spanning the app, rotating the emulator, etc. so you can see how the different resource folders are used in different device modes.<\/p>\n<p>In the following figures, you can see how the app, that has specific resource folders for different configurations, behaves when running on a single screen device, a tablet, and on Surface Duo using its different configurations:<\/p>\n<p><img decoding=\"async\" width=\"899\" height=\"493\" class=\"wp-image-410 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-single-screen-device-and-on-surfa-1.png\" alt=\"App running on a single screen device and on Surface Duo on single screen mode where the app looks the same in both, no specific resources needed for Surface Duo, your app should behave on Surface Duo single screen mode as on any single screen device\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-single-screen-device-and-on-surfa-1.png 899w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-single-screen-device-and-on-surfa-1-300x165.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-single-screen-device-and-on-surfa-1-768x421.png 768w\" sizes=\"(max-width: 899px) 100vw, 899px\" \/><\/p>\n<p style=\"text-align: center;\"><em>Figure 5. App running on a single screen device and on Surface Duo in single screen mode<\/em><\/p>\n<p>&nbsp;<\/p>\n<p><em><img decoding=\"async\" width=\"1066\" height=\"874\" class=\"wp-image-411 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-tablet-landscape-and-on-surface-1.png\" alt=\"App running on a tablet (landscape) and on Surface Duo on dual-portrait and dual-landscape mode. For both tablet and Surface Duo specific resources for them are used here.\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-tablet-landscape-and-on-surface-1.png 1066w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-tablet-landscape-and-on-surface-1-300x246.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-tablet-landscape-and-on-surface-1-1024x840.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/05\/app-running-on-a-tablet-landscape-and-on-surface-1-768x630.png 768w\" sizes=\"(max-width: 1066px) 100vw, 1066px\" \/><\/em><\/p>\n<p style=\"text-align: center;\"><em>Figure 6. App running on a tablet (in landscape mode) and on Surface Duo in dual-portrait and dual-landscape modes<\/em><\/p>\n<h2>What\u2019s next?<\/h2>\n<p>We are working on adding an official dual-screen qualifier which isn\u2019t just based on screen sizes so you will be able to define specific resources that Surface Duo will use when running your app on it.<\/p>\n<p>We will share more about this in a future blog post.<\/p>\n<h2>Feedback<\/h2>\n<p>Comments, questions, issues, requests, anything! We\u2019d love to hear from you!<\/p>\n<p>Please leave us feedback using our\u00a0<a href=\"http:\/\/aka.ms\/SurfaceDuoSDK-Feedback\" target=\"_blank\" rel=\"noopener noreferrer\">feedback forum<\/a>, or message me on\u00a0<a href=\"https:\/\/twitter.com\/CesarValiente\" target=\"_blank\" rel=\"noopener noreferrer\">Twitter<\/a>\u00a0or\u00a0<a href=\"https:\/\/github.com\/CesarValiente\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Android dual-screen developers! As we mentioned in a previous blog post, enhancing your app for dual-screen devices is easily done by following this three step process: Figure 1. Three steps to get your app ready for dual-screen devices Today we are going to provide some additional useful tips for embracing new features (Step 3), [&hellip;]<\/p>\n","protected":false},"author":30297,"featured_media":411,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[474,365,471,31,473,470,472,46],"class_list":["post-405","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-sdk","tag-android","tag-android-developer","tag-device-condiguration","tag-dual-screen-development","tag-kotlin","tag-qualifier","tag-sample","tag-surface-duo"],"acf":[],"blog_post_summary":"<p>Hello Android dual-screen developers! As we mentioned in a previous blog post, enhancing your app for dual-screen devices is easily done by following this three step process: Figure 1. Three steps to get your app ready for dual-screen devices Today we are going to provide some additional useful tips for embracing new features (Step 3), [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/users\/30297"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/comments?post=405"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/405\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/411"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}