You are on page 1of 29

SDK Instructions to FlexPai Developers

Royole Corporation

Confidential and Proprietary - Restricted Distribution


Royole Confidential and Proprietary

Restricted Distribution
Not to be distributed, used, copied, reproduced, or modified in whole or in part, nor its contents
revealed in any manner to others without the express written permission of Royole Corporation.

No Public Disclosure Permitted


Please report postings of this document on any public servers or websites to contact@royole.com.

Copyright ©2019 Royole Corporation.


All Rights Reserved.

Confidential and Proprietary 2 Royole Corporation


Revision History

Version Date Description

A 2019 Initial release

Confidential and Proprietary 3 Royole Corporation


Contents
1 Introduction of FlexPai........................................................... 错误!未定义书签。
2 Integration of FlexPai SDK..................................................................................... 8
2.1 Introduction of SDK................................................................................................................. 8
2.2 Integration of SDK....................................................................................................................8

3 FlexPai API List......................................................................................................10


3.1 Screen Angle........................................................................................................................... 10
3.1.1 Example of acquisition of screen angle agent.............................................................10
3.1.2 Initialization of screen angle agent..............................................................................10
3.1.3 Destruction of screen angle agent................................................................................11
3.1.4 Screen angle monitoring..............................................................................................12
3.1.5 Disabling screen angle monitoring..............................................................................12
3.1.6 Active acquisition of screen angle...............................................................................13
3.2 Two sets of sensors................................................................................................................. 13
3.2.1 Instance of acquisition of sensor agent........................................................................13
3.2.2 Monitoring data of second set of sensors.................................................................... 14
3.2.3 Disabling monitoring data of second set of sensors....................................................14
3.2.4 Acceleration sensor......................................................................................................14
3.2.5 Gyroscopic sensor........................................................................................................15
3.2.6 Geomagnetic sensor.....................................................................................................16
3.2.7 Optical proximity sensor............................................................................................. 16
3.2.8 Ambient light sensor....................................................................................................17
3.2.9 Gravity sensor..............................................................................................................18
3.2.10 Rotation vector sensor............................................................................................... 18
3.3 Screen information..................................................................................................................19
3.3.1 Acquisition of standard screen information.................................................................19
3.3.2 Acquisition of characteristic information on FlexPai screen...................................... 19
3.4 Application adaptation............................................................................................................ 26
3.4.1 Size of screen............................................................................................................... 26
3.4.2 Density of screen......................................................................................................... 27
3.4.3 Screen switching process.............................................................................................28
3.4.4 Simulation and debugging........................................................................................... 29

Confidential and Proprietary 4 Royole Corporation


1 Introduction of FlexPai

FlexPai, based on Android P system, continues using the framework and system applications
with in-depth customization. Combining characteristics of the smartphone, it designs new UI
interface effect, defines new interaction mode, upgrades support for multi-screen application
display from single screen display, and is equipped with two sets of sensors to ensure
accuracy of data in different usage scenarios.

1) Features of multiple screens:

When FlexPai is folded, the screen is divided into four parts – primary screen, primary edge
screen, secondary edge screen and secondary screen. You can choose to show wallpaper on
the other screen or not.

Wallpaper on back on: When the primary screen is facing up, it displays the functional area
while the secondary screen displays the wallpaper; when the secondary screen is facing up, it
displays the functional area while the primary screen displays the wallpaper

Wallpaper on back off: When the primary screen is facing up, it displays the functional area
while the secondary screen turns off; when the secondary screen is facing up, it displays the
functional area while the primary screen turns off. If FlexPai is unfolded, it displays as a full
screen.

If FlexPai is folded to form primary screen and secondary screen, the primary screen displays
with resolution of 1440*810 and screen scale of 16:9, while the secondary screen displays
with resolution of 1440*720 and screen scale of 18:9. If FlexPai is unfolded to a full screen,
the screen displays with resolution of 1920*1440 and screen scale of 4:3.

The phone is in folded screen state in case that the screen angle is [0°, 60°], and in full screen
state in case that the screen angle is (60°, 180°]. In the process of switching of full screen, the
screen with angle (60°, 150°) is in full-screen intermediate state with the wallpaper displayed
across the whole screen and the functional area displayed on the primary or secondary screen
before switching.

In case of primary/secondary screen switching, an application opened on the primary screen


will not automatically display on the secondary screen when you flip the screen over. Only the
application which calls the function of basic camera (a simple function provided by the
system to third-party applications for taking pictures and videos) can switch with the system.
The basic camera and the application switch to the secondary screen at the same time. If the
application is required to display on the other side, it can be done by clicking Send to the
Other Side button on the multi-task card (as shown in the figure below), or clicking the
multi-task card and the icon of the application on the other side.

Confidential and Proprietary 5 Royole Corporation


FlexPai upgrades the support from single screen display to custom multi-screen display and
can automatically adapt to the application. It supports switching of contents on multiple
screens, which can meet the demands of different scenarios such as playing games, leisure
and office.

2) Two sets of sensors:

FlexPai provides monitoring for two sets of sensors (acceleration sensor, gyroscopic sensor,
geomagnetic sensor, optical proximity sensor, ambient light sensor, gravity sensor and
rotation vector sensor).

Confidential and Proprietary 6 Royole Corporation


The system and applications can monitor the type and data of sensors at different locations as
needed. When switching among full screen, primary screen and secondary screen, the full
screen and secondary screen use the value of corresponding types of sensors at the secondary
screen location. The set of sensors is referred to as Secondary Screen Sensor Set, the data of
which are acquired via the standard API of Android. The primary screen uses the value of
corresponding types of sensors at the primary screen location. The set of sensors is referred to
as Primary Screen Sensor Set, the data of which are acquired via the API extended by FlexPai.
They are detailed in section “Two sets of sensors” in “FlexPai API List”.

Confidential and Proprietary 7 Royole Corporation


2 Integration of FlexPai SDK
2.1 Introduction of SDK

FlexPai is the first foldable flexible-screen smartphone. The screen can be bent from 0°to
180°, which provides many new features, including the included angle of screens, the addition
of the second set of sensors for primary screen, display of multiple screens, change and
control of the state. To make a third-party application use these features flexibly and
conveniently, FlexPai provides a set of interfaces, called FlexPai SDK. By integrating FlexPai
SDK and calling relevant interfaces, the third-party application can access these features for
personalized functions.

The SDK interfaces are divided by modules such as screen angle, two sets of sensors and
screen information. Different modules are encapsulated by different packages. See the FlexPai
API List for a detailed description of the interfaces.

2.2 Integration of SDK

First, go to the official website (http://www.royole.com/cn/developer) to download the


FlexPai SDK archive file flexpaideveloperlib-vx.x.aar, where vx.x is the version number.
Then, perform the integration in accordance with the development environment you use.

Integration of Android Studio

Method 1:

a) Copy the library file flexpaideveloperlib-vx.x.aar to the libs directory of the application
module.

b) Modify the file build.gradle of the application module.

android {

repositories {
flatDir {
dirs 'libs'
}
}

dependencies {
compile(name:'flexpaideveloperlib-vx.x', ext:'aar')
Android Gradle Plugin Version 3.0.0 or later
implementation (name:'flexpaideveloperlib-vx.x', ext:'aar')

Confidential and Proprietary 8 Royole Corporation


Method 2:

a) Import the flexpaideveloperlib-vx.x.aar into a project


1. Click File > New Module.
2. Click Import .JAR/.AAR Package and Next.
3. Enter the location of the AAR file and click Finish.

b) Ensure that the library is listed at the top of the file settings.gradle, as shown in the
following library named flexpaideveloperlib-vx.x:

include ':app', ': flexpaideveloperlib-vx.x '

c) Open the file build.gradle of the application module and add a new line of code to the
dependencies block, as shown in the following segment:
dependencies {

compile project(":flexpaideveloperlib-vx.x ")

d) Click Sync Project with Gradle Files.

Integration of Eclipse adt

1. Rename the library file flexpaideveloperlib-vx.x.aar as flexpaideveloperlib-vx.x.rar


2. Unzip to get classes.jar
3. Right click Project>Properties>Java Build Path>Libraries, click Add External JARs…,
select class.jar, and click Apply and Close button.
Note:
Finally modify the configuration file of the application to make the minSdkVersion defined
not less than 21.
Android Studio: build.gradle
android {
defaultConfig {
minSdkVersion 21
}
}

Eclipse adt: AndroidManifest.xml


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="… "
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="21"/>
</manifest>

Confidential and Proprietary 9 Royole Corporation


3 FlexPai API List
3.1 Screen Angle

Screen angle is the included angle of screens when the phone is folded or unfolded. It is 0
degree when the phone is folded and 180 degrees when unfolded fully. (Note: Error exists in
screen angle)

The angle can be acquired with two methods: directly calling an interface, and using listener.
To make it easier to acquire the angle, SDK provides some interfaces through which you can
monitor or acquire the angle to realize some personalized functions. For example, when you
fold a phone for switching between large and half screens, as the angle changes, the icons on
the desktop present an animation effect of linear flow and screen switching is realized
smoothly when the phone reach the screen switching threshold.

3.1.1 Example of acquisition of screen angle agent

Interface: public static AngleAgent getInstance ()


Parameter Meaning
Null No parameter.
Returned result Meaning
AngleAgent Instance object of screen angle agent

Example:
import com.water.flexpaidev.angle.AngleAgent;

AngleAgent.getInstance();

3.1.2 Initialization of screen angle agent

Interface: public void init(Context context)


Parameter Meaning
context Application or Activity Context of current hosting process.
Returned result Meaning
void No return.

Example:
import com.water.flexpaidev.angle.AngleAgent;

public class FlexPaiDemoApplication extends Application

Confidential and Proprietary 10 Royole Corporation


{
/**
* init FlexPaiSDK here(recommend).
*/
@Override
public void onCreate() {
super.onCreate();
AngleAgent.getInstance().init(this);
}
}

Note:

 Make sure to call the initialization interface prior to other angle-related interfaces, or it may
report an error.

 It is recommended to call in Application.onCreate().

3.1.3 Destruction of screen angle agent

Interface: public void destroy ()


Parameter Meaning
Null No parameter.
Returned result Meaning
void No return.

Example:
import com.water.flexpaidev.angle.AngleAgent;

public class FlexPaiDemoApplication extends Application


{
/**
* destroy FlexPaiSDK here(recommend).
*/
@Override
public void onTerminate() {
AngleAgent.getInstance().destroy();
super.onTerminate();
}
}

Note:

 Make sure to call the destruction interface after calling all angle-related interfaces to release the
resource.

Confidential and Proprietary 11 Royole Corporation


 It is recommended to call in Application. onTerminate ().

3.1.4 Screen angle monitoring

Interface: public boolean registerAngleListener (AngleListener listener)


Parameter Meaning
listener A custom screen angle listener.
Returned result Meaning
boolean True for successful registration and false for failed registration.

Example:
import com.water.flexpaidev.angle.AngleAgent;

privae AngleListener mScreenAngleListener = new AngleListener(){


@Override
public void onAngleChanged(float angle) {

}
};
AngleAgent.getInstance().registerAngleListener (mScreenAngleListener);

3.1.5 Disabling screen angle monitoring

Interface: public void unregisterAngleListener (AngleListener listener)


Parameter Meaning
listener A custom listener used when registering.
Returned result Meaning
void No return.

Example:
import com.water.flexpaidev.angle.AngleAgent;

privae AngleListener mScreenAngleListener = new AngleListener(){


@Override
public void onAngleChanged(float angle) {

}
};
AngleAgent.getInstance(). unregisterAngleListener (mScreenAngleListener);

Note: Register and cancel listener need to appear in pairs.

Confidential and Proprietary 12 Royole Corporation


3.1.6 Active acquisition of screen angle

Interface: public float getAngle()


Parameter Meaning
null No parameter.
Returned result Meaning
float The current angle: 0 degree for fully folded screen and 180 degrees for fully
unfolded screen.
(Note: Error exists in screen angle)
Example:
import com.water.flexpaidev.angle.AngleAgent;

AngleAgent.getInstance().getAngle();

3.2 Two sets of sensors

FlexPai has two sets of sensors (see Section 1.1 Introduction of FlexPai). The first is the
sensor set for secondary screen, the data of which are acquired via the native standard
interface of Android. The second is the sensor set for primary screen, the data of which can be
acquired via both the native interface and the extensive API.

When switching among full screen, primary screen and secondary screen, the data of sensors
are acquired via two sets of interfaces with the following corresponding relationship:

Secondary screen
Interface Full screen state Primary screen state
state
Native standard Data of sensor set Data of sensor set for Data of sensor set
interface for for secondary primary screen for secondary
sensors screen screen
Interface for the Data of sensor set Data of sensor set for Data of sensor set
second set of for primary screen primary screen for primary screen
sensors

The use of native standard interface is not described here, and only the interface for the
second set of sensors is described below. As all the sensors at the interfaces used for
registering and deregistering the listener are the same in type, they are introduced here and
will be demonstrated later based on the difference in the type.

3.2.1 Instance of acquisition of sensor agent

Interface: public static SensorAgent getInstance (Context context)


Parameter Meaning

Confidential and Proprietary 13 Royole Corporation


context Application or Activity Context of current hosting process.
Returned result Meaning
SensorAgent Instance object of sensor agent

Example:
import com.water.flexpaidev.sensor.SensorAgent;

SensorAgent.getInstance(this);

3.2.2 Monitoring data of second set of sensors

Interface: public boolean registerSecondListener(SensorEventListener listener,int type)


Parameter Meaning
listener A listener to be registered.
type Type of sensor. Only Sensor.TYPE_MAGNETIC_FIELD, Sensor.TYPE_GYROSCOPE,
Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_PROXIMITY, Sensor.TYPE_LIGHT,

Sensor.TYPE_ROTATION_VECTOR, Sensor.TYPE_GRAVITY are supported currently.


Returned result Meaning
boolean True for successful registration and false for failed registration.

3.2.3 Disabling monitoring data of second set of sensors

Interface: public void unregisterSecondListener(SensorEventListener listener)


Parameter Meaning
listener A listener used when registering.
Returned result Meaning
void No return.

Note:

 Interfaces used for registration and deregistration should appear in pairs.

 It is recommended to call in the life cycle function of an Android component, such as onCreate()
and onDestroy(), or onResume() and onPause() in Activity.

3.2.4 Acceleration sensor

When you register an acceleration sensor, the type imported is


Sensor.TYPE_ACCELEROMETER. The result returned by onSensorChanged() is the value
of the acceleration sensor corresponding to the primary screen.

Confidential and Proprietary 14 Royole Corporation


Example:
import com.water.flexpaidev.sensor.SensorAgent;

private SensorEventListener mAccelerometerSensorEventListener = new SensorEventListener()


{
@Override
public void onSensorChanged(SensorEvent event){

@Override
public void onAccuracyChanged(Sensor arg0,int arg1){

}
};

SensorAgent.getInstance(this).registerSecondListener(mAccelerometerSensorEventListener,Sensor.TYPE_AC
CELEROMETER);

SensorAgent.getInstance(this).unregisterSecondListener(mAccelerometerSensorEventListener);

3.2.5 Gyroscopic sensor

When you register a gyroscopic sensor, the type imported is Sensor.TYPE_GYROSCOPE.


The result returned by onSensorChanged() is the value of the gyroscopic sensor
corresponding to the primary screen.

Example:
import com.water.flexpaidev.sensor.SensorAgent;

private SensorEventListener mGyroscopeSensorEventListener = new SensorEventListener()


{
@Override
public void onSensorChanged(SensorEvent event){

@Override
public void onAccuracyChanged(Sensor arg0,int arg1){

}
};

Confidential and Proprietary 15 Royole Corporation


SensorAgent.getInstance(this).registerSecondListener(mGyroscopeSensorEventListener,
Sensor.TYPE_GYROSCOPE);

SensorAgent.getInstance(this).unregisterSecondListener(mGyroscopeSensorEventListener);

3.2.6 Geomagnetic sensor

When you register a geomagnetic sensor, the type imported is


Sensor.TYPE_MAGNETIC_FIELD. The result returned by onSensorChanged() is the value
of the geomagnetic sensor corresponding to the primary screen.

Example:
import com.water.flexpaidev.sensor.SensorAgent;

private SensorEventListener mMagneticFieldSensorEventListener = new SensorEventListener()


{
@Override
public void onSensorChanged(SensorEvent event){

@Override
public void onAccuracyChanged(Sensor arg0,int arg1){

}
};

SensorAgent.getInstance(this).registerSecondListener(mMagneticFieldSensorEventListener,
Sensor.TYPE_MAGNETIC_FIELD);

SensorAgent.getInstance(this).unregisterSecondListener(mMagneticFieldSensorEventListener);

3.2.7 Optical proximity sensor

When you register an optical proximity sensor, the type imported is


Sensor.TYPE_PROXIMITY. The result returned by onSensorChanged() is the value of the
optical proximity sensor corresponding to the primary screen.

Example:

Confidential and Proprietary 16 Royole Corporation


import com.water.flexpaidev.sensor.SensorAgent;

private SensorEventListener mProximitySensorEventListener = new SensorEventListener()


{
@Override
public void onSensorChanged(SensorEvent event){

@Override
public void onAccuracyChanged(Sensor arg0,int arg1){

}
};

SensorAgent.getInstance(this).registerSecondListener(mProximitySensorEventListener,
Sensor.TYPE_PROXIMITY);

SensorAgent.getInstance(this).unregisterSecondListener(mProximitySensorEventListener);

3.2.8 Ambient light sensor

When you register an ambient light sensor, the type imported is Sensor.TYPE_LIGHT. The
result returned by onSensorChanged() is the value of the ambient light sensor corresponding
to the primary screen.

Example:
import com.water.flexpaidev.sensor.SensorAgent;

private SensorEventListener mLightSensorEventListener = new SensorEventListener()


{
@Override
public void onSensorChanged(SensorEvent event){

@Override
public void onAccuracyChanged(Sensor arg0,int arg1){

}
};

Confidential and Proprietary 17 Royole Corporation


SensorAgent.getInstance(this).registerSecondListener(mLightSensorEventListener, Sensor.TYPE_LIGHT);

SensorAgent.getInstance(this).unregisterSecondListener(mProximitySensorEventListener);

3.2.9 Gravity sensor

When you register a gravity sensor, the type imported is Sensor.TYPE_GRAVITY. The result
returned by onSensorChanged() is the value of the gravity sensor corresponding to the
primary screen.

Example:
import com.water.flexpaidev.sensor.SensorAgent;

private SensorEventListener mGravitySensorEventListener = new SensorEventListener()


{
@Override
public void onSensorChanged(SensorEvent event){

@Override
public void onAccuracyChanged(Sensor arg0,int arg1){

}
};

SensorAgent.getInstance(this).registerSecondListener(mGravitySensorEventListener,
Sensor.TYPE_GRAVITY);

SensorAgent.getInstance(this).unregisterSecondListener(mGravitySensorEventListener);

3.2.10 Rotation vector sensor

When you register a rotation vector sensor, the type imported is


Sensor.TYPE_ROTATION_VECTOR. The result returned by onSensorChanged() is the value
of the rotation vector sensor corresponding to the primary screen.

Example:
import com.water.flexpaidev.sensor.SensorAgent;

Confidential and Proprietary 18 Royole Corporation


private SensorEventListener mRotationvectorSensorEventListener = new SensorEventListener()
{
@Override
public void onSensorChanged(SensorEvent event){

@Override
public void onAccuracyChanged(Sensor arg0,int arg1){

}
};

SensorAgent.getInstance(this).registerSecondListener(mRotationvectorSensorEventListener,
Sensor.TYPE_ROTATION_VECTOR);

SensorAgent.getInstance(this).unregisterSecondListener(mRotationvectorSensorEventListener);

3.3 Screen information

In addition to standard screen information such as resolution, landscape and portrait and pixel
density, FlexPai also includes features such as screen mode (full screen and half screen), half
screen state (primary screen and secondary screen),wallpaper on back switch (other screen on
and other screen off) and half screen flip lock (locked and unlocked) due to screen folding.

In case of switching between full and half screens, when you switch a full landscape to a half
screen, the default state is small portrait, and vice versa; when you switch a full portrait to a
half screen, the default state is small landscape, and vice versa. At the same time, the
application will switch to the corresponding screen position by default unless the application
has set the screen orientation.

3.3.1 Acquisition of standard screen information

The method to acquire standard screen information is also standard. See “Screen information -
standard information” section in Demo for specific information on how to get screen
information.

3.3.2 Acquisition of characteristic information on FlexPai screen

Getting the object of screen information agent


Interface: public static ScreenModeAgent getInstance (Context context)

Confidential and Proprietary 19 Royole Corporation


Parameter Meaning
context Application or Activity Context of current hosting process.
Returned result Meaning
ScreenModeAgent Instance object of screen information agent

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;

ScreenModeAgent.getInstance(this);

Feature 1-Screen mode: Full/half screen

The screen is in Full Screen Mode when it is unfolded and in Half Screen Mode when it is
folded. Please refer to the section “Introduction of FlexPai” for the angle range corresponding
to a specific state. The interfaces can be used to actively get the full/half screen state value,
register and deregister full/half screen state listener.

Interface 1: Actively getting the full/half screen state value


Interface: public int getScreenModeValue() throws Settings.SettingNotFoundException
Parameter Meaning
null No parameter.
Exception Meaning
SettingNotFoundException It appears when the feature name does not exist in settings
Exception Meaning
int Full/half screen state value (0 for full screen and 1 for half screen).

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;

ScreenModeAgent.getInstance(this).getScreenModeValue();

Interface 2: Registering the full/half screen state listener


Interface: public boolean registerScreenModeListener(ScreenFeatureListener screenFeatureListener)

Parameter Meaning
screenFeatureListener A custom interface. When the state value changes, call back the interface.
Returned result Meaning
boolean True for successful registration and false for failed registration.

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.ScreenFeatureListener;

private ScreenFeatureListener mScreenModeListener;

Confidential and Proprietary 20 Royole Corporation


{
mScreenModeListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

}
};
}

ScreenModeAgent.getInstance(this).registerScreenModeListener(mScreenModeListener);

Interface 3: Deregistering the full/half screen state listener


Interface: public void unregisterScreenModeListener(ScreenFeatureListener screenFeatureListener)

Parameter Meaning
screenFeatureListener Listener object used when registering.
Returned result Meaning
void No return.

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.ScreenFeatureListener;

private ScreenFeatureListener mScreenModeListener;


{
mScreenModeListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

}
};
}

ScreenModeAgent.getInstance(this).unregisterScreenModeListener(mScreenModeListener);

Feature 2-Half screen state: Primary/secondary screen

When the screen is folded, it is divided into two half screens. The larger one, which is on the
back side of camera is Primary Screen, and the smaller one, which is on the same side of
camera is Secondary Screen. Please refer to “Introduction of FlexPai” for details. The
interfaces can be used to actively get the primary/secondary screen state value, register and
deregister primary/secondary screen state listener.

Interface 1: Actively getting the primary/secondary screen state value


Interface: public int getScreenActiveValue() throws Settings.SettingNotFoundException

Confidential and Proprietary 21 Royole Corporation


Parameter Meaning
null No parameter.
Exception Meaning
SettingNotFoundException It appears when the feature name does not exist in settings
Returned result Meaning
int Primary/secondary screen state value (0 for primary screen and 1 for secondary screen)

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;

ScreenModeAgent.getInstance(this).getScreenActiveValue();

Interface 2: Registering the primary/secondary screen state listener


Interface: public boolean registerScreenActiveListener(ScreenFeatureListener screenFeatureListener)
Parameter Meaning
screenFeatureListener A custom interface. When the state value changes, call back the interface. It is defined the
same as Feature 1.
Returned result Meaning
boolean True for successful registration and false for failed registration.

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.ScreenFeatureListener;

private ScreenFeatureListener mScreenActiveListener;


{
mScreenActiveListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

}
};
}

ScreenModeAgent.getInstance(this).registerScreenActiveListener(mScreenActiveListener);

Interface 3: Deregistering the primary/secondary screen state listener


Interface: public void unregisterScreenActiveListener(ScreenFeatureListener screenFeatureListener)
Parameter Meaning
screenFeatureListener Listener object used when registering.
Returned result Meaning
void No return.

Example:

Confidential and Proprietary 22 Royole Corporation


import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.ScreenFeatureListener;

private ScreenFeatureListener mScreenActiveListener;


{
mScreenActiveListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

}
};
}

ScreenModeAgent.getInstance(this).unregisterScreenActiveListener(mScreenActiveListener);

Feature 3-Wallpaper on back switch: wallpaper on back on/off

In case that the phone is folded to form half screens, the switching on and off of the wallpaper on the
other screen can be done on the navigation bar. When using virtual navigation, directly tap the
switch icon to turn it on and off. When using gesture navigation, press and hold the gesture
navigation bar to call out the switch menu.
For the other screen, when the primary screen displays, the secondary screen and secondary edge
screen constitute the other screen; when the secondary screen displays, the primary screen and
primary edge screen constitute the other screen. The interfaces can be used to actively get the on/off
state value of wallpaper on back switch, register and deregister state listener of wallpaper on back
switch.
Interface 1: Actively getting the state value of wallpaper on back switch
Interface: public int getWallpaperOnBackSwitchValue() throws Settings.SettingNotFoundException
Parameter Meaning
null No parameter.
Exception Meaning
SettingNotFoundException It appears when the feature name does not exist in settings
Returned result Meaning
int State value of wallpaper on back switch (0 for wallpaper on back on and 1 for wallpaper on
back off)

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;

ScreenModeAgent.getInstance(this).getWallpaperOnBackSwitchValue();

Interface 2: Registering the state listener of wallpaper on back switch


Interface: public boolean registerWallpaperOnBackSwitchListener (ScreenFeatureListener
screenFeatureListener)

Confidential and Proprietary 23 Royole Corporation


Parameter Meaning
screenFeatureListener A custom interface. When the state value changes, call back the interface. It is defined the
same as Feature 1.
Returned result Meaning
boolean True for successful registration and false for failed registration.

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.screenFeatureListener;

private ScreenFeatureListener mScreenWallpaperOnBackSwitchListener;


{
mScreenWallpaperOnBackSwitchListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

}
};
}
ScreenModeAgent.getInstance(this). registerWallpaperOnBackSwitchListener
(mScreenWallpaperOnBackSwitchListener);

Interface 3: Deregistering the state listener of wallpaper on back switch


Interface: public void unregisterWallpaperOnBackSwitchListener (ScreenFeatureListener screenFeatureListener)

Parameter Meaning
screenFeatureListener Listener object used when registering.
Returned result Meaning
void No return.

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.screenFeatureListener;

private ScreenFeatureListener mScreenWallpaperOnBackSwitchListener;


{
mScreenWallpaperOnBackSwitchListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

}
};
}
ScreenModeAgent.getInstance(this). unregisterWallpaperOnBackSwitchListener
(mScreenWallpaperOnBackSwitchListener);

Confidential and Proprietary 24 Royole Corporation


Feature 4-Half screen flip lock: locked/unlocked

In case that the phone is folded to form half screens, the display interface can switch between
primary screen and secondary screen following the flip of the device. If the flip function is
locked, it will not switch after flipping, but always shows on the screen where the flip
function is locked. The locking depends on the Auto Flip button in Control Center. The
interfaces can be used to actively get the lock state value, register and deregister lock state
listener.

Interface 1: Actively getting the lock state value


Interface: public int getScreenActiveLockedValue () throws Settings.SettingNotFoundException
Parameter Meaning
null No parameter.
Exception Meaning
SettingNotFoundException It appears when the feature name does not exist in settings
Returned result Meaning
int Lock state value (0 for unlocked and 1 for locked).

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;

ScreenModeAgent.getInstance(this). getScreenActiveLockedValue();

Interface 2: Registering the lock state listener


Interface: public boolean registerScreenActiveLockedListener (ScreenFeatureListener
screenFeatureListener)
Parameter Meaning
screenFeatureListener A custom interface. When the state value changes, call back the interface. It is defined the
same as Feature 1.
Returned result Meaning
boolean True for successful registration and false for failed registration.

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.screenFeatureListener;

private ScreenFeatureListener mScreenLockedListener;


{
mScreenLockedListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

Confidential and Proprietary 25 Royole Corporation


};
}

ScreenModeAgent.getInstance(this).registerScreenActiveListener(mScreenLockedListener);

Interface 3: Deregistering the lock state listener


Interface: public void unregisterScreenActiveLockedListener (ScreenFeatureListener screenFeatureListener)

Parameter Meaning
screenFeatureListener Listener object used when registering.
Returned result Meaning
void No return.

Example:
import com.water.flexpaidev.screen.ScreenModeAgent;
import com.water.flexpaidev.screen.ScreenFeatureListener;

private ScreenFeatureListener mScreenLockedListener;


{
mScreenLockedListener = new ScreenFeatureListener(){
@Override
public void onValueChanged(int newValue){

}
};
}

ScreenModeAgent.getInstance(this).unregisterScreenActiveListener(mScreenLockedListener);

3.4 Application adaptation

Application adaptation focuses on screen adaptation, enabling the application to display well
on full screen, primary screen and secondary screen. Further, screen adaptation mainly refers
to adaptation of the application to a device with any size and density of the screen. The screen
of FlexPai includes full screen, primary screen and secondary screen (please refer to the
section “Introduction of FlexPai” in “Document Description” for concept of screen) with
resolution of 1920*1440, 1440*810 and 1440*720 in px respectively, and with density of 308.
The application adaptation is detailed in terms of screen size and screen density as below.

3.4.1 Size of screen

1> Ensure that the layout can resize appropriately to fit the size of the screen

Confidential and Proprietary 26 Royole Corporation


For the width of the view component, try to use “wrap_content” and “match_parent”
instead of hard coding, so that the view will use only the space required or will fill the
available space by extension. Try to use the RelativeLayout, which allows you to specify
the layout based on the spatial relationship among components.

2> Provides appropriate UI layout based on screen configuration

The configuration qualifier provides a variety of layout resources, allowing the running
component to automatically select appropriate resources based on the current device
configuration (e.g. different layout designs for different screen sizes).

a. Use a size qualifier

res/layout-1920x1440/main.xml, full screen layout

res/layout-1440x810/main.xml, primary screen layout

res/layout-1440x720/main.xml, secondary screen layout

b. Use a minimum width qualifier

res/layout-sw720dp/main.xml, full screen layout

res/layout-sw405dp/main.xml, primary screen layout

res/layout-sw360dp/main.xml, secondary screen layout

c. Use the screen orientation qualifier

res/layout-land/layouts.xml

res/layout-port/layouts.xml

3> Provide a bitmap that scales normally

Use a nine-rectangle-grid bitmap, which is a bitmap with extension of .9.png. This kind
of picture resource can be created through the SDK's draw9patch utility (located in the
tools/ directory).

3.4.2 Density of screen

1> Use density-independent pixels

Be sure to use dp or sp as a unit when specifying the sizes. The dp is a


density-independent pixel that corresponds to the physical size of the pixel at 160 dpi.
The sp is the same base unit, but it scales to the user's preferred text size (it is a
scaling-independent pixel), thus you should use this unit of measure when defining the
text dimensions (rather than layout dimensions).

2> Provide alternate bitmap

Because the device running Android has multiple screen densities, you should always
provide bitmap resources that can be customized based on a variety of common density

Confidential and Proprietary 27 Royole Corporation


levels (low, medium, high, and ultra-high). With the following scaling, generate the
image corresponding to each screen density:

xhdpi:2.0
hdpi:1.5
mdpi:1.0 (baseline)
ldpi:0.75
Place the resulting picture file in the appropriate subdirectory under res/ and the system
will automatically select the correct file based on the screen density of the device
running the application:
MyProject/
res/
drawable-xhdpi/
awesomeimage.png
drawable-hdpi/
awesomeimage.png
drawable-mdpi/
awesomeimage.png
drawable-ldpi/
awesomeimage.png

The density of full screen, primary screen and secondary screen is 308, thus the
corresponding picture resources are under the drawable-xhdpi directory.

3.4.3 Screen switching process

The switching among full screen, primary screen and secondary screen can cause destruction
and rebuilding of Activity. To avoid loss of data, it can be resolved in the following two ways:

a. Save the state data in onSaveInstanceState(), restore the state data in onCreate() or
onRestoreInstanceState().

b. Configure the Activity as follows in the inventory file to prevent destruction and
rebuilding of Activity:

<activity android:name=" "


android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize">

</activity>
onConfigurationChanged() will be called in case of configuration change due to screen
switching.

Confidential and Proprietary 28 Royole Corporation


3.4.4 Simulation and debugging

Without a foldable-screen smartphone, the developer can perform simulation and debugging
by modifying the screen resolution:

wm commands and usage:

usage: wm [subcommand] [options]

wm size: return or override display size.

wm density: override display density.

a. Fold a full screen to a primary screen with the following method of simulation:

Preset the phone to the full screen resolution: adb shell wm size 1440x1920

Then set the resolution to the primary screen resolution: adb shell wm size 1440x810

b. Unfold the primary screen to the full screen with the following method of simulation:

Preset the phone to the primary screen resolution: adb shell wm size 1440x810

Then set the resolution to the full screen resolution: adb shell wm size 1440x1920

c. Unfold the secondary screen to the full screen with the following method of simulation:

Pre-set the phone to the secondary screen resolution: adb shell wm size 1440x720

Then set the resolution to the full screen resolution: adb shell wm size 1440x1920

Confidential and Proprietary 29 Royole Corporation

You might also like