/apidoc/Titanium/Platform/DisplayCaps.yml

https://gitlab.com/Rockyspade/titanium_mobile · YAML · 176 lines · 150 code · 26 blank · 0 comment · 0 complexity · a1d23427b2b53430fb8351bf2854ab9d MD5 · raw file

  1. ---
  2. name: Titanium.Platform.DisplayCaps
  3. summary: |
  4. The Display Caps object returned by the <Titanium.Platform.displayCaps> property.
  5. description: |
  6. On iPhone and iPod devices with retina display, the `density` property is `high` and the `dpi`
  7. property is `320`. For other iPhone and iPod devices, `density` is `medium` and `dpi` is `160`.
  8. On iPad devices with retina display, the `density` property is `high` and the `dpi`
  9. property is `260`. For other iPad devices, `density` is `medium` and `dpi` is `130`.
  10. Note that Xcode versions prior to 4.3.1 do not have the correct tools to detect the iPad 3
  11. retina display. Apps must be built with Xcode 4.3.1 or later to detect iPad 3 retina display.
  12. Note that the `displayCaps` property begins with a lowercase letter, which differentiates it
  13. from the `DisplayCaps` object that it returns. Refer to the example to understand how it should
  14. be called.
  15. extends: Titanium.Proxy
  16. since: "0.8"
  17. createable: false
  18. properties:
  19. - name: density
  20. summary: Logical density of the display.
  21. type: String
  22. permission: read-only
  23. - name: dpi
  24. summary: Display density expressed as dots-per-inch.
  25. type: Number
  26. permission: read-only
  27. - name: logicalDensityFactor
  28. summary: |
  29. Logical density of the display, as a scaling factor for the Density Independent Pixel (dip)
  30. unit.
  31. description: |
  32. One dip is one pixel on a 160dpi display, approximately, with a 240x320, 1.5"x2" display
  33. providing a baseline. For example, for a 160dpi display, this value will be 1, and for 120dpi,
  34. it will be .75.
  35. This value does not precisely follow the real display size, as given by `xdpi` and `ydpi`,
  36. but instead is used to scale the size of the overall UI in steps based on changes in the
  37. display dpi. For example, a 240x320 screen will have a density of 1, whether its width is
  38. 1.8" or 1.3". However, if the resolution is increased to 320x480 but the display remains
  39. 1.5"x2" then the density would be increased to about 1.5.
  40. On iOS devices, this property returns 1, 2 and 3 for &#64;1x, &#64;2x and &#64;3x respectively.
  41. Note for iPhone 6+, this value is 3.
  42. type: Number
  43. permission: read-only
  44. platforms: [android, iphone, ipad]
  45. since: {iphone: "3.4.1", ipad: "3.4.1"}
  46. - name: platformHeight
  47. summary: |
  48. Absolute height of the display in relation to UI orientation. Measured in platform-specific
  49. units; pixels on Android and density-independent pixels (dip) on iOS.
  50. description: |
  51. This property depends on the orientation of the UI, rather than the physical orientation of
  52. the device. While these may often be one in the same, it is not necessarily the case when
  53. orientation is restricted by <Titanium.UI.Window.orientationModes>. See example for
  54. clarification.
  55. type: Number
  56. permission: read-only
  57. examples:
  58. - title: Platform Width and Height
  59. example: |
  60. Create a window and limit it to portrait mode. Start the app and observe that the platform
  61. width and height is output to the log. Change the physical orientation of the device and
  62. click the window to test again. Note that the logged information relates to the UI rather
  63. than the physical orientation of the device.
  64. var win = Ti.UI.createWindow({
  65. title: 'Click window to output UI dimensions',
  66. backgroundColor: 'white',
  67. orientationModes: [ Titanium.UI.PORTRAIT ], // UI restricted to portrait mode
  68. fullscreen: false,
  69. exitOnClose: true
  70. });
  71. var label = Ti.UI.createLabel({
  72. text:'Hello world'
  73. });
  74. win.add(label);
  75. function logDisplayCaps(){
  76. Ti.API.info('Width x Height: ' + Ti.Platform.displayCaps.platformWidth + ' x ' + Ti.Platform.displayCaps.platformHeight);
  77. }
  78. win.addEventListener('click',function(e){
  79. // as the UI orientation is restricted by orientationModes, this will only ever
  80. // output the dimensions of the UI in portrait mode. For example, 480 x 800 for the
  81. // Android device tested
  82. logDisplayCaps();
  83. });
  84. win.open();
  85. logDisplayCaps();
  86. - name: platformWidth
  87. summary: |
  88. Absolute width of the display in relation to UI orientation. Measured in platform-specific
  89. units; pixels on Android and density-independent pixels (dip) on iOS.
  90. description: |
  91. This property depends on the orientation of the UI, rather than the physical orientation of
  92. the device. While these may often be one in the same, it is not necessarily the case when
  93. orientation is restricted by <Titanium.UI.Window.orientationModes>. See example for
  94. clarification.
  95. type: Number
  96. permission: read-only
  97. examples:
  98. - title: Platform Width and Height
  99. example: |
  100. Create a window and limit it to portrait mode. Start the app and observe that the platform
  101. width and height is output to the log. Change the physical orientation of the device and
  102. click the window to test again. Note that the logged information relates to the UI rather
  103. than the physical orientation of the device.
  104. var win = Ti.UI.createWindow({
  105. title: 'Click window to output UI dimensions',
  106. backgroundColor: 'white',
  107. orientationModes: [ Titanium.UI.PORTRAIT ], // UI restricted to portrait mode
  108. fullscreen: false,
  109. exitOnClose: true
  110. });
  111. var label = Ti.UI.createLabel({
  112. text:'Hello world'
  113. });
  114. win.add(label);
  115. function logDisplayCaps(){
  116. Ti.API.info('Width x Height: ' + Ti.Platform.displayCaps.platformWidth + ' x ' + Ti.Platform.displayCaps.platformHeight);
  117. }
  118. win.addEventListener('click',function(e){
  119. // as the UI orientation is restricted by orientationModes, this will only ever
  120. // output the dimensions of the UI in portrait mode. For example, 480 x 800 for the
  121. // Android device tested
  122. logDisplayCaps();
  123. });
  124. win.open();
  125. logDisplayCaps();
  126. - name: xdpi
  127. summary: Physical pixels per inch of the display in the X dimension.
  128. type: Number
  129. platforms: [android]
  130. permission: read-only
  131. - name: ydpi
  132. summary: Physical pixels per inch of the display in the Y dimension.
  133. type: Number
  134. platforms: [android]
  135. permission: read-only
  136. examples:
  137. - title: System Display Information
  138. example: |
  139. Output the display properties to the system log.
  140. Ti.API.info('Ti.Platform.displayCaps.density: ' + Ti.Platform.displayCaps.density);
  141. Ti.API.info('Ti.Platform.displayCaps.dpi: ' + Ti.Platform.displayCaps.dpi);
  142. Ti.API.info('Ti.Platform.displayCaps.platformHeight: ' + Ti.Platform.displayCaps.platformHeight);
  143. Ti.API.info('Ti.Platform.displayCaps.platformWidth: ' + Ti.Platform.displayCaps.platformWidth);
  144. if((Ti.Platform.osname === 'iphone')||(Ti.Platform.osname === 'ipad')||(Ti.Platform.osname === 'android')){
  145. Ti.API.info('Ti.Platform.displayCaps.logicalDensityFactor: ' + Ti.Platform.displayCaps.logicalDensityFactor);
  146. }
  147. if(Ti.Platform.osname === 'android'){
  148. Ti.API.info('Ti.Platform.displayCaps.xdpi: ' + Ti.Platform.displayCaps.xdpi);
  149. Ti.API.info('Ti.Platform.displayCaps.ydpi: ' + Ti.Platform.displayCaps.ydpi);
  150. }