FMX.OrientationSensor Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the TOrientationSensor component in order to get compass related information such as the tilt on the three axis and the heading on the three axis.

Location

You can find the OrientationSensor sample project at:

  • Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to:
    • Object Pascal\Mobile Snippets\OrientationSensor
    • CPP\Mobile Snippets\OrientationSensor
  • Subversion Repository:
    • You can find Delphi and C++ code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The OrientationSensor sample demonstrates how to use the orientation sensor in iOS or Android applications. The sample uses the TOrientationSensor component and the TCustomOrientationSensor class to offer information about the rotation angle (tilt) and the compass heading relative to the magnetic north (heading).

Note: The TCustomOrientationSensor class supports Android, iOS and Windows platforms. However, each platform provides different orientation sensors and each type of sensor supports a different set of properties (see platform support for a completed list of platform, sensors and supported properties).

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: OrientationSensor.dproj.
    • C++: OrientationSensor.cbproj.
  2. Select the target platform, iOS and Android supported.
  3. Press F9 or choose Run > Run.
  4. Interact with the sample:
    • Press the Tilt button. It shows:
    • Press the Heading button. It shows:
      • The X coordinate of the vector that points to the magnetic North, measured in MicroTeslas.
      • The Y coordinate of the vector that points to the magnetic North, measured in MicroTeslas.
      • The Z coordinate of the vector that points to the magnetic North, measured in MicroTeslas.

Files

File in Delphi File in C++ Contains

OrientationSensor.dproj

OrientationSensor.cbproj

The project itself.

uMain.fmx

uMain.fmx

The main form where the components are located.

uMain.pas

OrientationSensorPCH.h, OrientationSensor.cpp

Used to define and implement the sample.

Information.txt

Information.txt

Further information about the sample.

Classes

TOrientationSensorForm is the main form that represents the main window of the sample. It contains the following components:

Implementation

  • The sample uses TOrientationSensor to give information about the device inclination and compass heading.
  • The sample uses TSwitch to provide the user with a two-way on-off switch. TSwitch on enables TOrientationSensor.
  • The sample uses TTimer to repeat specific actions after a given time interval. TTimer specifies the time interval in which TOrientationSensor offers information to the user.
  • The sample uses TListBox to display a list with a set of items with orientation information.
  • The sample uses TLayout to organize the Tilt and Heading buttons under the same parent.
  • The sample uses TSpeedButton to enable the orientation sensor to offer tilt related information or heading related information.

When you run the application, TOrientationSensor is disabled. You can enable the orientation sensor by switching the swOrientationSensorActive. If TOrientationSensor is enabled, the sample offers some orientation related information depending on which button is pressed. If you press the Tilt button, the sample offers information about the rotation angle. If you press the Heading button, the sample offers information about the compass heading relative to the magnetic north.

Uses

See Also

Samples