FMX.Accelerometer Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the accelerometer in order to obtain information about the acceleration, angular acceleration, motion and speed.

Location

You can find the TabSliding sample project at:

  • Start | Programs | Embarcadero RAD Studio Athens | Samples and then navigate to:
    • Object Pascal\Mobile Snippets\Accelerometer
    • CPP\Mobile Snippets\Accelerometer
  • 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 Accelerometer sample demonstrates how to use the accelerometer in iOS or Android applications. The sample uses TMotionSensor component and TCustomMotionSensor class to offer information about the acceleration, angle, state, and speed of the device motion.

Note: TCustomMotionSensor class supports Android, iOS and Windows platforms. However, each platform provides different motion sensors and each type of sensor supports a different set of properties (see TCustomMotionSensor for a complete list of platform, sensors and supported properties). Some functionalities of this sample could be disabled depending on the target platform.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: Accelerometer.dproj.
    • C++: Accelerometer.cbproj.
  2. Select the target platform, iOS and Android supported.
  3. Press F9 or choose Run > Run.
  4. Interact with the sample. It shows:

Files

File in Delphi File in C++ Contains

Accelerometer.dproj

Accelerometer.cbproj

The project itself.

uMain.fmx

uMain.fmx

The main form where the components are located.

uMain.pas

AccelerometerPCH.h, Accelerometer.cpp

Used to define and implement the sample.

Information.txt

Information.txt

Further information about the sample.

Classes

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

Implementation

  • The sample uses TMotionSensor to offer information about acceleration, angle, state, and speed of the device motion.
  • The sample uses TTimer to repeat specific actions after a given time interval. TTimer specifies the time interval in wich TMotionSensor offers information to the user.
  • The sample uses TSwitch to provide the user with a two-way on-off switch. TSwitch on enables TTimer and TMotionSensor.
  • The sample uses TListBox to display a set of items of TMotionSensor information in a scrollable list.

When you run the application, TMotionSensor and TTimer are disabled. When you switch on the TSwitch object, TMotionSensor and TTimer are enabled and each TListBoxItem shows different information about the acceleration, angle, state, and speed of the device motion. The sample shows the following information of the device motion:

  • The acceleration of the X-axis of the accelerometer.
  • The acceleration of the Y-axis of the accelerometer.
  • The acceleration of the Z-axis of the accelerometer.
  • The angular acceleration of the X-axis of the accelerometer.
  • The angular acceleration of the Y-axis of the accelerometer.
  • The angular acceleration of the Z-axis of the accelerometer.
  • The speed of the accelerometer.
  • The motion property of the accelerometer, which could be set to True or False.
Note: Some functionalities of this sample could be disabled depending on the target platform. See TCustomMotionSensor for a complete list of platform, sensors and supported properties.

Uses

See Also

Samples