summaryrefslogtreecommitdiffstats
path: root/docs/html/distribute/tools/promote/device-art.jd
blob: 814177bc3ef4f38b91b1a153a22cd98c23699a8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
page.title=Device Art Generator
page.image=/images/device-art-ex-crop.jpg
page.metaDescription=Drag and drop screenshots of your app into device artwork, for better looking promotional images and improved visual context.
meta.tags="disttools, promoting, deviceart, marketing"
page.tags="device, deviceart, nexus, assets"
Xnonavpage=true

@jd:body

<p>The device art generator enables you to quickly wrap app screenshots in device artwork. This provides better visual context for your app screenshots on your website or in other promotional materials</p>

<p class="note"><strong>Note</strong>: Do <em>not</em> use graphics created here in your 1024x500
feature image or screenshots for your Google Play app listing.</p>



<div class="supported-browser">

<div class="layout-content-row">
  <div class="layout-content-col span-3">
    <h4>Step 1</h4>
    <p>Drag a screenshot from your desktop onto a device to the right.</p>
  </div>
  <div class="layout-content-col span-10">
    <ul class="device-list primary"></ul>
    <a href="#" id="archive-expando">Older devices</a>
    <ul class="device-list archive"></ul>
  </div>
</div>



<div class="layout-content-row">
  <div class="layout-content-col span-3">
    <h4>Step 2</h4>
    <p>Customize the generated image and drag it to your desktop to save.</p>
    <p id="frame-customizations">
      <input type="checkbox" id="output-shadow" checked="checked" class="form-field-checkbutton">
      <label for="output-shadow">Shadow</label><br>
      <input type="checkbox" id="output-glare" checked="checked" class="form-field-checkbutton">
      <label for="output-glare">Screen Glare</label><br><br>
      <a class="button" id="rotate-button">Rotate</a>
    </p>
    <p id="wear-customizations">
      <input type="radio" id="output-square" name="output-wear" checked="checked" class="form-field-checkbutton">
      <label for="output-square">Square</label><br>
      <input type="radio" id="output-round" name="output-wear" class="form-field-checkbutton">
      <label for="output-round">Round</label><br><br>
    </p>
  </div>
  <div class="layout-content-col span-10">
    <!-- position:relative fixes an issue where dragging an image out of a inline-block container
         produced no drag feedback image in Chrome 28. -->
    <div id="output" style="position:relative">No input image.</div>
  </div>
</div>

</div>

<div class="unsupported-browser" style="display: none">
  <p class="warning"><strong>Error:</strong> This page requires
    <span id="unsupported-browser-reason">certain features</span>, which your web browser
    doesn't support. To continue, navigate to this page on a supported web browser, such as
    <strong>Google Chrome</strong>.</p>
  <a href="https://www.google.com/chrome/" class="button">Get Google Chrome</a>
  <br><br>
</div>

<style>
  h4 {
    text-transform: uppercase;
  }

  .device-list {
    padding: 1em 0 0 0;
    margin: 0;
  }

  .device-list li {
    display: inline-block;
    vertical-align: bottom;
    margin: 0;
    margin-right: 20px;
    text-align: center;
  }

  .device-list li .thumb-container {
    display: inline-block;
  }

  .device-list li .thumb-container img {
    margin-bottom: 8px;
    opacity: 0.6;

    -webkit-transition: -webkit-transform 0.2s, opacity 0.2s;
       -moz-transition:    -moz-transform 0.2s, opacity 0.2s;
            transition:         transform 0.2s, opacity 0.2s;
  }

  .device-list li.drag-hover .thumb-container img {
    opacity: 1;

    -webkit-transform: scale(1.1);
       -moz-transform: scale(1.1);
            transform: scale(1.1);
  }

  .device-list li .device-details {
    font-size: 13px;
    line-height: 16px;
    color: #888;
  }

  .device-list li .device-url {
    font-weight: bold;
  }

  #archive-expando {
    display: block;
    font-size: 13px;
    font-weight: bold;
    color: #333;
    text-transform: uppercase;
    margin-top: 16px;
    padding-top: 16px;
    padding-left: 28px;
    border-top: 1px solid transparent;
    background: transparent url({@docRoot}assets/images/styles/disclosure_down.png)
                no-repeat scroll 0 8px;
    -webkit-transition: border 0.2s;
       -moz-transition: border 0.2s;
            transition: border 0.2s;
  }

  #archive-expando.expanded {
    background-image: url({@docRoot}assets/images/styles/disclosure_up.png);
    border-top: 1px solid #ccc;
  }

  .device-list.archive {
    max-height: 0;
    overflow: hidden;
    opacity: 0;

    -webkit-transition: max-height 0.2s, opacity 0.2s;
       -moz-transition: max-height 0.2s, opacity 0.2s;
            transition: max-height 0.2s, opacity 0.2s;
  }

  .device-list.archive.expanded {
    opacity: 1;
    max-height: 300px;
  }

  #output {
    color: #f44;
    font-style: italic;
  }

  #output img {
    max-height: 500px;
  }
</style>
<script>
  // Global variables
  var g_currentImage;
  var g_currentDevice;
  var g_currentObjectURL;
  var g_currentBlob;

  // Global constants
  var MSG_INVALID_INPUT_IMAGE = 'Invalid screenshot provided. Screenshots must be PNG files '
      + 'matching the target device\'s screen aspect ratio in either portrait or landscape.';
  var MSG_INVALID_WEAR_IMAGE = 'Invalid screenshot provided. Screenshots must be PNG files '
      + 'matching the target device\'s screen aspect ratio.'
      + ' Capture screenshots from a Wear emulator or device with '
      + '<a href="http://developer.android.com/tools/debugging/debugging-studio.html#screenCap">Android Studio</a>.';
  var MSG_NO_INPUT_IMAGE = 'Drag a screenshot (in PNG format) from your desktop onto a '
      + 'target device above.'
  var MSG_GENERATING_IMAGE = 'Generating device art&hellip;';

  var MAX_DISPLAY_HEIGHT = 126; // XOOM, to fit into 200px wide

  // Device manifest.
  var DEVICES = [
    {
      id: 'nexus_5',
      title: 'Nexus 5',
      url: 'http://www.google.com/nexus/5/',
      physicalSize: 5,
      physicalHeight: 5.43,
      density: 'XXHDPI',
      landRes: ['shadow', 'back', 'fore'],
      landOffset: [436,306],
      portRes: ['shadow', 'back', 'fore'],
      portOffset: [304,436],
      portSize: [1080,1920],
    },
    {
      id: 'nexus_6',
      title: 'Nexus 6',
      url: 'http://www.google.com/nexus/6/',
      physicalSize: 6,
      physicalHeight: 6.27,
      density: '560DPI',
      landRes: ['shadow', 'back', 'fore'],
      landOffset: [489,327],
      portRes: ['shadow', 'back', 'fore'],
      portOffset: [327,489],
      portSize: [1440, 2560],
    },
    {
      id: 'nexus_7',
      title: 'Nexus 7',
      url: 'http://www.google.com/nexus/7/',
      physicalSize: 7,
      physicalHeight: 8,
      actualResolution: [1200,1920],
      density: 'XHDPI',
      landRes: ['shadow', 'back', 'fore'],
      landOffset: [326,245],
      portRes: ['shadow', 'back', 'fore'],
      portOffset: [244,326],
      portSize: [800,1280]
    },
    {
      id: 'nexus_9',
      title: 'Nexus 9',
      url: 'http://www.google.com/nexus/9/',
      physicalSize: 9,
      physicalHeight: 8.98,
      actualResolution: [1536,2048],
      density: 'XHDPI',
      landRes: ['shadow', 'back', 'fore'],
      landOffset: [514,350],
      portRes: ['shadow', 'back', 'fore'],
      portOffset: [348,514],
      portSize: [1536,2048],
    },
    {
      id: 'nexus_10',
      title: 'Nexus 10',
      url: 'http://www.google.com/nexus/10/',
      physicalSize: 10,
      physicalHeight: 7,
      actualResolution: [1600,2560],
      density: 'XHDPI',
      landRes: ['shadow', 'back', 'fore'],
      landOffset: [227,217],
      portRes: ['shadow', 'back', 'fore'],
      portOffset: [217,223],
      portSize: [800,1280],
      archived: true
    },
    {
      id: 'nexus_7_2012',
      title: 'Nexus 7 (2012)',
      url: 'http://www.google.com/nexus/7/',
      physicalSize: 7,
      physicalHeight: 7.81,
      density: '213dpi',
      landRes: ['shadow', 'back', 'fore'],
      landOffset: [315,270],
      portRes: ['shadow', 'back', 'fore'],
      portOffset: [264,311],
      portSize: [800,1280],
      archived: true
    },
    {
      id: 'nexus_4',
      title: 'Nexus 4',
      url: 'http://www.google.com/nexus/4/',
      physicalSize: 4.7,
      physicalHeight: 5.27,
      density: 'XHDPI',
      landRes: ['shadow', 'back', 'fore'],
      landOffset: [349,214],
      portRes: ['shadow', 'back', 'fore'],
      portOffset: [213,350],
      portSize: [768,1280],
      archived: true
    },
    {
      id: 'wear',
      title: 'Android Wear',
      url: 'http://www.android.com/wear/',
      physicalSize: 1.8,
      physicalHeight: 1.8,
      density: 'HDPI',
      landRes: ['back'],
      landOffset: [225,206],
      portRes: ['back'],
      portOffset: [200,214],
      portSize: [320,320],
    },
    {
      id: 'wear_square',
      title: 'Android Wear Square',
      url: 'http://www.android.com/wear/',
      physicalSize: 1.8,
      physicalHeight: 1.8,
      density: 'HDPI',
      landRes: ['back'],
      landOffset: [225,206],
      portRes: ['back'],
      portOffset: [200,214],
      portSize: [320,320],
      hidden: true
    },
    {
      id: 'wear_round',
      title: 'Android Wear Round',
      url: 'http://www.android.com/wear/',
      physicalSize: 1.8,
      physicalHeight: 1.8,
      density: 'HDPI',
      landRes: ['back'],
      landOffset: [161,167],
      portRes: ['back'],
      portOffset: [128,134],
      portSize: [320,320],
      hidden: true
    },
  ];

  DEVICES = DEVICES.sort(function(x, y) { return x.physicalSize - y.physicalSize; });

  var MAX_HEIGHT = 0;
  for (var i = 0; i < DEVICES.length; i++) {
    MAX_HEIGHT = Math.max(MAX_HEIGHT, DEVICES[i].physicalHeight);
  }

  // Setup performed once the DOM is ready.
  $(document).ready(function() {
    if (!checkBrowser()) {
      return;
    }

    polyfillCanvasToBlob();
    setupUI();

    // Set up Chrome drag-out
    $.event.props.push("dataTransfer");
    document.body.addEventListener('dragstart', function(e) {
      var target = e.target;
      if (target.classList.contains('dragout')) {
        e.dataTransfer.setData('DownloadURL', target.dataset.downloadurl);
      }
    }, false);
  });

  /**
   * Returns the device from DEVICES with the given id.
   */
  function getDeviceById(id) {
    for (var i = 0; i < DEVICES.length; i++) {
      if (DEVICES[i].id == id)
        return DEVICES[i];
    }
    return;
  }

  /**
   * Checks to make sure the browser supports this page. If not,
   * updates the UI accordingly and returns false.
   */
  function checkBrowser() {
    // Check for browser support
    var browserSupportError = null;

    // Must have <canvas>
    var elem = document.createElement('canvas');
    if (!elem.getContext || !elem.getContext('2d')) {
      browserSupportError = 'HTML5 canvas.';
    }

    // Must have FileReader
    if (!window.FileReader) {
      browserSupportError = 'desktop file access';
    }

    if (browserSupportError) {
      $('.supported-browser').hide();

      $('#unsupported-browser-reason').html(browserSupportError);
      $('.unsupported-browser').show();
      return false;
    }

    return true;
  }

  function setupUI() {
    $('#output').html(MSG_NO_INPUT_IMAGE);

    $('#frame-customizations').hide();
    $('#wear-customizations').hide();

    $('#output-shadow, #output-glare').click(function() {
      createFrame();
    });

    $('input[name="output-wear"]').change(function() {
      createFrame();
    });

    // Build device list.
    $.each(DEVICES, function() {
      var resolution = this.actualResolution || this.portSize;
      var scaleFactorText = '';
      var deviceList = '.device-list.primary';
      if (resolution[0] != this.portSize[0]) {
        scaleFactorText = '<br>' + (100 * (this.portSize[0] / resolution[0])).toFixed(0) +
            '% size output';
      } else {
        scaleFactorText = '<br>&nbsp;';
      }

      if (this.archived) {
        deviceList = '.device-list.archive';
      } else if (this.hidden) {
        deviceList = '.device-list.hidden';
      }

      $('<li>')
          .append($('<div>')
              .addClass('thumb-container')
              .append($('<img>')
                  .attr('src', 'device-art-resources/' + this.id + '/thumb.png')
                  .attr('height',
                      Math.floor(MAX_DISPLAY_HEIGHT * this.physicalHeight / MAX_HEIGHT))))
          .append($('<div>')
              .addClass('device-details')
              .html((this.url
                  ? ('<a class="device-url" href="' + this.url + '">' + this.title + '</a>')
                  : this.title) +
                  '<br>' +  this.physicalSize + '" @ ' + this.density +
                  '<br>' + (resolution[0] + 'x' + resolution[1]) + scaleFactorText))
          .data('deviceId', this.id)
          .appendTo(deviceList)
    });

    // Set up "older devices" expando.
    $('#archive-expando').click(function() {
      if ($(this).hasClass('expanded')) {
        $(this).removeClass('expanded');
        $('.device-list.archive').removeClass('expanded');
      } else {
        $(this).addClass('expanded');
        $('.device-list.archive').addClass('expanded');
      }
      return false;
    });

    // Set up drag and drop.
    $('.device-list li')
        .live('dragover', function(evt) {
          $(this).addClass('drag-hover');
          evt.dataTransfer.dropEffect = 'link';
          evt.preventDefault();
        })
        .live('dragleave', function(evt) {
          $(this).removeClass('drag-hover');
        })
        .live('drop', function(evt) {
          $('#output').empty().html(MSG_GENERATING_IMAGE);
          $(this).removeClass('drag-hover');
          g_currentDevice = getDeviceById($(this).closest('li').data('deviceId'));
          evt.preventDefault();
          loadImageFromFileList(evt.dataTransfer.files, function(data) {
            if (data == null) {
              if (g_currentDevice.id == 'wear') {
                $('#output').html(MSG_INVALID_WEAR_IMAGE);
              }else {
                $('#output').html(MSG_INVALID_INPUT_IMAGE);
              }
              return;
            }
            loadImageFromUri(data.uri, function(img) {
              g_currentFilename = data.name;
              g_currentImage = img;
              createFrame();
              // Send the event to Analytics
              ga('send', 'event', 'Distribute', 'Create Device Art', g_currentDevice.title);
            });
          });
        });

    // Set up rotate button.
    $('#rotate-button').click(function() {
      if (!g_currentImage) {
        return;
      }

      var w = g_currentImage.naturalHeight;
      var h = g_currentImage.naturalWidth;
      var canvas = $('<canvas>')
          .attr('width', w)
          .attr('height', h)
          .get(0);

      var ctx = canvas.getContext('2d');
      ctx.rotate(-Math.PI / 2);
      ctx.translate(-h, 0);
      ctx.drawImage(g_currentImage, 0, 0);

      loadImageFromUri(canvas.toDataURL('image/png'), function(img) {
        g_currentImage = img;
        createFrame();
      });
    });
  }

  /**
   * Generates the frame from the current selections (g_currentImage and g_currentDevice).
   */
  function createFrame() {
    var port;

    if (g_currentDevice.id == 'wear' || g_currentDevice.id == 'wear_square' || g_currentDevice.id == 'wear_round') {
      if ($('#output-square').is(':checked')) {
        g_currentDevice = getDeviceById('wear_square');
      } else {
        g_currentDevice = getDeviceById('wear_round');
      }
    }

    var aspect1 = g_currentImage.naturalWidth / g_currentImage.naturalHeight;
    var aspect2 = g_currentDevice.portSize[0] / g_currentDevice.portSize[1];

    if (aspect1 == aspect2) {
      port = true;
    } else if (aspect1 == 1 / aspect2) {
      port = false;
    } else {
      if (g_currentDevice.id == 'wear_square' || g_currentDevice.id == 'wear_round') {
        alert('The screenshot must have an aspect ratio of ' +
          aspect2.toFixed(3) +
          ' (ideally ' + g_currentDevice.portSize[0] + 'x' + g_currentDevice.portSize[1] + ').');
        $('#output').html(MSG_INVALID_WEAR_IMAGE);
      }else {
        alert('The screenshot must have an aspect ratio of ' +
          aspect2.toFixed(3) + ' or ' + (1 / aspect2).toFixed(3) +
          ' (ideally ' + g_currentDevice.portSize[0] + 'x' + g_currentDevice.portSize[1] +
          ' or ' + g_currentDevice.portSize[1] + 'x' + g_currentDevice.portSize[0] + ').');
        $('#output').html(MSG_INVALID_INPUT_IMAGE);
      }
      return;
    }

    // Load image resources
    var res = port ? g_currentDevice.portRes : g_currentDevice.landRes;
    var resList = {};
    for (var i = 0; i < res.length; i++) {
      resList[res[i]] = 'device-art-resources/' + g_currentDevice.id + '/' +
          (port ? 'port_' : 'land_') + res[i] + '.png'
    }

    var resourceImages = {};
    loadImageResources(resList, function(r) {
      resourceImages = r;
      continueWithResources_();
    });

    function continueWithResources_() {
      var width = resourceImages['back'].naturalWidth;
      var height = resourceImages['back'].naturalHeight;
      var offset = port ? g_currentDevice.portOffset : g_currentDevice.landOffset;
      var size = port
          ? g_currentDevice.portSize
          : [g_currentDevice.portSize[1], g_currentDevice.portSize[0]];

      var canvas = document.createElement('canvas');
      canvas.width = width;
      canvas.height = height;

      var ctx = canvas.getContext('2d');
      if (resourceImages['shadow'] && $('#output-shadow').is(':checked')) {
        ctx.drawImage(resourceImages['shadow'], 0, 0);
      }
      ctx.drawImage(resourceImages['back'], 0, 0);

      if (g_currentDevice.id == 'wear_round') {
        var scratchCanvas = document.createElement('canvas');
        scratchCanvas.width = width;
        scratchCanvas.height = height;
        var scratchCtx = scratchCanvas.getContext('2d');


        //drawing code
        scratchCtx.clearRect(offset[0], offset[1], scratchCanvas.width, scratchCanvas.height);

        scratchCtx.globalCompositeOperation = 'source-over'; //default

        scratchCtx.drawImage(g_currentImage, offset[0], offset[1], size[0], size[1]);

        scratchCtx.fillStyle = '#fff'; //color doesn't matter, but we want full opacity
        scratchCtx.globalCompositeOperation = 'destination-in';
        scratchCtx.beginPath();
        scratchCtx.arc(288, 294, size[0] / 2, 0, 2 * Math.PI, false);
        scratchCtx.closePath();
        scratchCtx.fill();

        // After tinkering with the offset, the 1 in the x-position drew the image
        // perfectly
        ctx.drawImage(scratchCanvas, 1, 0);
      } else {
        ctx.fillStyle = '#000';
        ctx.fillRect(offset[0], offset[1], size[0], size[1]);
        ctx.drawImage(g_currentImage, offset[0], offset[1], size[0], size[1]);
      }

      if (resourceImages['fore'] && $('#output-glare').is(':checked')) {
        ctx.drawImage(resourceImages['fore'], 0, 0);
      }

      window.URL = window.URL || window.webkitURL;
      if (canvas.toBlob && window.URL.createObjectURL) {
        if (g_currentObjectURL) {
          window.URL.revokeObjectURL(g_currentObjectURL);
          g_currentObjectURL = null;
        }
        if (g_currentBlob) {
          if (g_currentBlob.close) {
            g_currentBlob.close();
          }
          g_currentBlob = null;
        }

        canvas.toBlob(function(blob) {
          if (!blob) {
            continueWithFinalUrl_(canvas.toDataURL('image/png'));
            return;
          }
          g_currentBlob = blob;
          g_currentObjectURL = window.URL.createObjectURL(blob);
          continueWithFinalUrl_(g_currentObjectURL);
        }, 'image/png');
      } else {
        continueWithFinalUrl_(canvas.toDataURL('image/png'));
      }
    }

    function continueWithFinalUrl_(imageUrl) {
      var filename = g_currentFilename
          ? g_currentFilename.replace(/^(.+?)(\.\w+)?$/, '$1_framed.png')
          : 'framed_screenshot.png';

      var $link = $('<a>')
          .attr('download', filename)
          .attr('href', imageUrl)
          .append($('<img>')
              .addClass('dragout')
              .attr('src', imageUrl)
              .attr('draggable', true)
              .attr('data-downloadurl', ['image/png', filename, imageUrl].join(':')))
          .appendTo($('#output').empty());

      if (g_currentDevice.id == 'wear' || g_currentDevice.id == 'wear_round' || g_currentDevice.id == 'wear_square') {
        $('#wear-customizations').show();
        $('#frame-customizations').hide();
      } else {
        $('#frame-customizations').show();
        $('#wear-customizations').hide();
      }
    }
  }

  /**
   * Loads an image from a data URI. The callback will be called with the <img> once
   * it loads.
   */
  function loadImageFromUri(uri, callback) {
    callback = callback || function(){};

    var img = document.createElement('img');
    img.src = uri;
    img.onload = function() {
      callback(img);
    };
    img.onerror = function() {
      callback(null);
    }
  }

  /**
   * Loads a set of images (organized by ID). Once all images are loaded, the callback
   * is triggered with a dictionary of <img>'s, organized by ID.
   */
  function loadImageResources(images, callback) {
    var imageResources = {};

    var checkForCompletion_ = function() {
      for (var id in images) {
        if (!(id in imageResources))
          return;
      }
      (callback || function(){})(imageResources);
      callback = null;
    };

    for (var id in images) {
      var img = document.createElement('img');
      img.src = images[id];
      (function(img, id) {
        img.onload = function() {
          imageResources[id] = img;
          checkForCompletion_();
        };
        img.onerror = function() {
          imageResources[id] = null;
          checkForCompletion_();
        }
      })(img, id);
    }
  }

  /**
   * Loads the first valid image from a FileList (e.g. drag + drop source), as a data URI. This
   * method will throw an alert() in case of errors and call back with null.
   *
   * @param {FileList} fileList The FileList to load.
   * @param {Function} callback The callback to fire once image loading is done (or fails).
   * @return Returns an object containing 'uri' representing the loaded image. There will also be
   *      a 'name' field indicating the file name, if one is available.
   */
  function loadImageFromFileList(fileList, callback) {
    fileList = fileList || [];

    var file = null;
    for (var i = 0; i < fileList.length; i++) {
      if (fileList[i].type.toLowerCase().match(/^image\/(png|jpeg|jpg)/)) {
        file = fileList[i];
        break;
      }
    }

    if (!file) {
      alert('Please use a valid screenshot file (PNG or JPEG format).');
      callback(null);
      return;
    }

    var fileReader = new FileReader();

    // Closure to capture the file information.
    fileReader.onload = function(e) {
      callback({
        uri: e.target.result,
        name: file.name
      });
    };
    fileReader.onerror = function(e) {
      switch(e.target.error.code) {
        case e.target.error.NOT_FOUND_ERR:
          alert('File not found.');
          break;
        case e.target.error.NOT_READABLE_ERR:
          alert('File is not readable.');
          break;
        case e.target.error.ABORT_ERR:
          break; // noop
        default:
          alert('An error occurred reading this file.');
      }
      callback(null);
    };
    fileReader.onabort = function(e) {
      alert('File read cancelled.');
      callback(null);
    };

    fileReader.readAsDataURL(file);
  }

  /**
   * Adds a simple version of Canvas.toBlob if toBlob isn't available.
   */
  function polyfillCanvasToBlob() {
    if (!HTMLCanvasElement.prototype.toBlob && window.Blob) {
      HTMLCanvasElement.prototype.toBlob = function(callback, mimeType, quality) {
        if (typeof callback != 'function') {
          throw new TypeError('Function expected');
        }
        var dataURL = this.toDataURL(mimeType, quality);
        mimeType = dataURL.split(';')[0].split(':')[1];
        var bs = window.atob(dataURL.split(',')[1]);
        if (dataURL == 'data:,' || !bs.length) {
          callback(null);
          return;
        }
        for (var ui8arr = new Uint8Array(bs.length), i = 0; i < bs.length; ++i) {
          ui8arr[i] = bs.charCodeAt(i);
        }
        callback(new Blob([ui8arr.buffer /* req'd for Safari */ || ui8arr], {type: mimeType}));
      };
    }
  }
</script>