Abstract

Last Updated: February 23, 2014

The article describes how the rotation tracking algorithm tracks rotation of the device when user switches the screen. Code example illustrates rotation tracking algorithm implementation. The article is intended to third–party developers of YotaPhone applications.

1. Rotation algorithm

The phone with two screens with inputs on opposite sides requires a very delicate lock/unlock mechanism to prevent accidental actions. For this reason we have created a triggering algorithm. Triggering algorithm uses sensors to detect device orientation and locks/unlocks touch panels accordingly.

Triggering algorithm is activated on user action, in the moment when application knows for sure what screen user looks at. For example it is started when users presses put-to-back button.There are two main use-cases for the moment:

  1. When the user performs user action on Front Screen;
  2. When the user performs user action on Back Screen;

Algorithm for case 1:

  • User performs action => both Accelerometer and Gyroscope are turned on;
  • If user does not rotate the phone for 4 seconds then Sensors are switched off and nothing happens;
  • If user rotates the phone in these 4 seconds then the algorithm locks the Front Screen and unlocks the Back Screen (Back Screen unlock cannot happen if programmer specified so). Sensors continue to monitor for additional 4 seconds;
  • If the user rotates the phone back in these 4 seconds than the algorithm locks Back Screen, unlocks the Front Screen and Sensors are switched off;
  • If the user does not rotate the phone back in these 4 seconds than Sensors are switched off, the Front Screen is turned off and user continues to use Back Screen.

Algorithm for case 2:

  • User performs an action on Back Screen => both Accelerometer and Gyroscope are turned on;
  • If the user does not rotate the phone for 4 seconds then Sensors are switched off, the Front Screen state unchanged: user continues to use Back Screen;
  • If the user rotates the phone in these 4 seconds then the algorithm locks the Back Screen and turns on and unlocks the Front Screen and Sensors are switched off.

2. Code example

The code below initiates triggering algorithm on button click from front screen. The user is expected to switch to back screen after pressing this button.

mButtonP2B.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        RotationAlgorithm.getInstance(getApplicationContext()
    ).issueStandardToastAndVibration(); //To let the user know that he is expected to rotate the phone now
    RotationAlgorithm.getInstance(getApplicationContext()
    ).turnScreenOffIfRotated(); //Perform drawing on back screen here
    }
});