Titanium.Platform.DisplayCaps
> Titanium.Platform.DisplayCaps

The Display Caps object returned by the Titanium.Platform.displayCaps property.

On iPhone and iPod devices with retina display, the density property is high and the dpi property is 320. For other iPhone and iPod devices, density is medium and dpi is 160.

On iPad devices with retina display, the density property is high and the dpi property is 260. For other iPad devices, density is medium and dpi is 130.

Note that Xcode versions prior to 4.3.1 do not have the correct tools to detect the iPad 3 retina display. Apps must be built with Xcode 4.3.1 or later to detect iPad 3 retina display.

Note that the displayCaps property begins with a lowercase letter, which differentiates it from the DisplayCaps object that it returns. Refer to the example to understand how it should be called.

Examples

System Display Information

Output the display properties to the system log.

Ti.API.info('Ti.Platform.displayCaps.density: ' + Ti.Platform.displayCaps.density);
Ti.API.info('Ti.Platform.displayCaps.dpi: ' + Ti.Platform.displayCaps.dpi);
Ti.API.info('Ti.Platform.displayCaps.platformHeight: ' + Ti.Platform.displayCaps.platformHeight);
Ti.API.info('Ti.Platform.displayCaps.platformWidth: ' + Ti.Platform.displayCaps.platformWidth);
if((Ti.Platform.osname === 'iphone')||(Ti.Platform.osname === 'ipad')||(Ti.Platform.osname === 'android')){
  Ti.API.info('Ti.Platform.displayCaps.logicalDensityFactor: ' + Ti.Platform.displayCaps.logicalDensityFactor);
}
if(Ti.Platform.osname === 'android'){
  Ti.API.info('Ti.Platform.displayCaps.xdpi: ' + Ti.Platform.displayCaps.xdpi);
  Ti.API.info('Ti.Platform.displayCaps.ydpi: ' + Ti.Platform.displayCaps.ydpi);
}
  • 0.8
  • 0.8
  • 0.8
Defined By

Properties

apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Indicates if the proxy will bubble an event to its parent. ...

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.

Default: true

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.Platform.DisplayCaps
density : Stringreadonly

Logical density of the display.

Logical density of the display.

Titanium.Platform.DisplayCaps
dpi : Numberreadonly

Display density expressed as dots-per-inch.

Display density expressed as dots-per-inch.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Titanium.Platform.DisplayCaps
logicalDensityFactor : Numberreadonly

Logical density of the display, as a scaling factor for the Density Independent Pixel (dip) unit.

Logical density of the display, as a scaling factor for the Density Independent Pixel (dip) unit.

One dip is one pixel on a 160dpi display, approximately, with a 240x320, 1.5"x2" display providing a baseline. For example, for a 160dpi display, this value will be 1, and for 120dpi, it will be .75.

This value does not precisely follow the real display size, as given by xdpi and ydpi, but instead is used to scale the size of the overall UI in steps based on changes in the display dpi. For example, a 240x320 screen will have a density of 1, whether its width is 1.8" or 1.3". However, if the resolution is increased to 320x480 but the display remains 1.5"x2" then the density would be increased to about 1.5.

On iOS devices, this property returns 1, 2 and 3 for @1x, @2x and @3x respectively. Note for iPhone 6+, this value is 3.

  • 0.8
  • 3.4.1
  • 3.4.1
Titanium.Platform.DisplayCaps
: Numberreadonly
Absolute height of the display in relation to UI orientation. ...

Absolute height of the display in relation to UI orientation. Measured in platform-specific units; pixels on Android and density-independent pixels (dip) on iOS.

This property depends on the orientation of the UI, rather than the physical orientation of the device. While these may often be one in the same, it is not necessarily the case when orientation is restricted by Titanium.UI.Window.orientationModes. See example for clarification.

Examples

Platform Width and Height

Create a window and limit it to portrait mode. Start the app and observe that the platform width and height is output to the log. Change the physical orientation of the device and click the window to test again. Note that the logged information relates to the UI rather than the physical orientation of the device.

var win = Ti.UI.createWindow({
  title: 'Click window to output UI dimensions',
  backgroundColor: 'white',
  orientationModes: [ Titanium.UI.PORTRAIT ], // UI restricted to portrait mode
  fullscreen: false,
  exitOnClose: true
});

var label = Ti.UI.createLabel({
  text:'Hello world'
});
win.add(label);

function logDisplayCaps(){
  Ti.API.info('Width x Height: ' + Ti.Platform.displayCaps.platformWidth + ' x ' + Ti.Platform.displayCaps.platformHeight);
}

win.addEventListener('click',function(e){
  // as the UI orientation is restricted by orientationModes, this will only ever 
  // output the dimensions of the UI in portrait mode. For example, 480 x 800 for the 
  // Android device tested
  logDisplayCaps();
});

win.open();

logDisplayCaps();
Titanium.Platform.DisplayCaps
: Numberreadonly
Absolute width of the display in relation to UI orientation. ...

Absolute width of the display in relation to UI orientation. Measured in platform-specific units; pixels on Android and density-independent pixels (dip) on iOS.

This property depends on the orientation of the UI, rather than the physical orientation of the device. While these may often be one in the same, it is not necessarily the case when orientation is restricted by Titanium.UI.Window.orientationModes. See example for clarification.

Examples

Platform Width and Height

Create a window and limit it to portrait mode. Start the app and observe that the platform width and height is output to the log. Change the physical orientation of the device and click the window to test again. Note that the logged information relates to the UI rather than the physical orientation of the device.

var win = Ti.UI.createWindow({
  title: 'Click window to output UI dimensions',
  backgroundColor: 'white',
  orientationModes: [ Titanium.UI.PORTRAIT ], // UI restricted to portrait mode
  fullscreen: false,
  exitOnClose: true
});

var label = Ti.UI.createLabel({
  text:'Hello world'
});
win.add(label);

function logDisplayCaps(){
  Ti.API.info('Width x Height: ' + Ti.Platform.displayCaps.platformWidth + ' x ' + Ti.Platform.displayCaps.platformHeight);
}

win.addEventListener('click',function(e){
  // as the UI orientation is restricted by orientationModes, this will only ever 
  // output the dimensions of the UI in portrait mode. For example, 480 x 800 for the 
  // Android device tested
  logDisplayCaps();
});

win.open();

logDisplayCaps();    
Titanium.Platform.DisplayCaps
xdpi : Numberreadonly

Physical pixels per inch of the display in the X dimension.

Physical pixels per inch of the display in the X dimension.

  • 0.8
Titanium.Platform.DisplayCaps
ydpi : Numberreadonly

Physical pixels per inch of the display in the Y dimension.

Physical pixels per inch of the display in the Y dimension.

  • 0.8
Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Platform.DisplayCaps
( ) : String
Gets the value of the density property. ...

Gets the value of the density property.

Returns

  • String
Titanium.Platform.DisplayCaps
( ) : Number
Gets the value of the dpi property. ...

Gets the value of the dpi property.

Returns

  • Number
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Platform.DisplayCaps
( ) : Number
Gets the value of the logicalDensityFactor property. ...

Gets the value of the logicalDensityFactor property.

  • 0.8
  • 3.4.1
  • 3.4.1

Returns

  • Number
Titanium.Platform.DisplayCaps
( ) : Number
Gets the value of the platformHeight property. ...

Gets the value of the platformHeight property.

Returns

  • Number
Titanium.Platform.DisplayCaps
( ) : Number
Gets the value of the platformWidth property. ...

Gets the value of the platformWidth property.

Returns

  • Number
Titanium.Platform.DisplayCaps
( ) : Number
Gets the value of the xdpi property. ...

Gets the value of the xdpi property.

  • 0.8

Returns

  • Number
Titanium.Platform.DisplayCaps
( ) : Number
Gets the value of the ydpi property. ...

Gets the value of the ydpi property.

  • 0.8

Returns

  • Number
Removes the specified callback as an event listener for the named event. ...

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void