LG Wing

SAMPLE CODE

Sample Code

LG WingSample Code

Analyze the code of the sample application included in the LG MultiScreen SDK package to support the development of applications for LG Wing. The LG Wing sample application consists of the following files.

file path

Importing the Package

Import the following class to add a new activity to the Second Screen.

import android.app.ActivityOptions;

import com.lge.display.DisplayManagerHelper;

import com.lge.display.DisplayManagerHelper.SwivelStateCallback;

import android.app.ActivityOptions

import com.lge.display.DisplayManagerHelper

import com.lge.display.DisplayManagerHelper.SwivelStateCallback

Implementing Sample App

It is necessary to obtain the display ID of the LG Wing and pass it as a parameter or set it as a method in the following way to run a new activity on a Second Screen.

1. To check if an app is running in an LG Multi Display environment (LG Wing Device or LG Wing Emulator), use hasSystemFeature(String) of PackageManager to check if the “com.lge.multiscreen” feature.

private boolean hasLGMultiScreenFeature(){

String feature = "com.lge.multiscreen";

PackageManager pm = getPackageManager();

return pm.hasSystemFeature(feature);

}

private fun hasLGMultiScreenFeature(): Boolean {

val feature = "com.lge.multiscreen"

val pm = packageManager

return pm.hasSystemFeature(feature)

}

2. Use the isMultiDisplayDevice() API and getMultiDisplayId() API of the LG MultiScreen SDK package to obtain the display ID of the Second Screen. The following code shows an example.

DisplayManagerHelper mDisplayManagerHelper;

boolean mIsLgMultiDisplayDevice = false;

int mSubScreenId = 0;

if (hasLGMultiScreenFeature()) {

mIsLgMultiDisplayDevice = DisplayManagerHelper.isMultiDisplayDevice();

}

if (mIsLgMultiDisplayDevice) {

mDisplayManagerHelper = new DisplayManagerHelper(this);

mSubScreenId = mDisplayManagerHelper.getMultiDisplayId();

}

var mDisplayManagerHelper: DisplayManagerHelper? = null

var mIsLgMultiDisplayDevice = false

var mSubScreenId = 0

if (hasLGMultiScreenFeature()) {

mIsLgMultiDisplayDevice = DisplayManagerHelper.isMultiDisplayDevice()

}

if (mIsLgMultiDisplayDevice) {

mDisplayManagerHelper = DisplayManagerHelper(context)

mSubScreenId = mDisplayManagerHelper!!.multiDisplayId

}

3. Use the getMultiDisplayType() API to check the type of the Second Screen. The following code shows an example.

if (DisplayManagerHelper.getMultiDisplayType() == DisplayManagerHelper.TYPE_SWIVEL) {

// doing something

}

if (DisplayManagerHelper.getMultiDisplayType() == DisplayManagerHelper.TYPE_SWIVEL) {

// doing something

}

4. Use the setLaunchDisplayId method of ActivityOptions and set the display ID of the Second Screen to add a new activity.

ActivityOptions options = ActivityOptions.makeBasic();

options.setLaunchDisplayId(mSubScreenId);

Intent intent = new Intent(this, Main2Activity.class);

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_MULTIPLE_TASK);

startActivity(intent, options.toBundle());

val options = ActivityOptions.makeBasic()

options.launchDisplayId = mSubScreenId

val intent = new Intent(this, Main2Activity.class)

intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TAS or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)

startActivity(intent, options.toBundle())

5. If you want to know the current Swivel Mode, use getSwivelState() method and the code is as below.

int state = mDisplayManagerHelper.getSwivelState();

var state = mDisplayManagerHelper!!.swivelState

6. Use onSwivelStateChanged() of SwivelStateCallback to check the Swivel Mode change.

6-1. Create the MySwivelStateCallback object that inherits SwivelStateCallback.
6-2. Register the object created in 6-1) in DisplayManagerHelper to use the Swivel Mode.

MySwivelStateCallback mSwivelStateCallback = new MySwivelStateCallback();

mDisplayManagerHelper.registerSwivelStateCallback(mSwivelStateCallback);

val mSwivelStateCallback = MySwivelStateCallback()

mDisplayManagerHelper.registerSwivelStateCallback(mSwivelStateCallback)

6-3. Release the registration of the object registered in 6-2. after the use.

mDisplayManagerHelper.unregisterSwivelStateCallback(mSwivelStateCallback);

mDisplayManagerHelper.unregisterSwivelStateCallback(mSwivelStateCallback)

6-4. The callback is received right after the registration of SwivelStateCallback and then received through onSwivelStateChanged whenever the Swivel Mode is changed.

// callback class

private class MySwivelStateCallback extends SwivelStateCallback {

@Override

public void onSwivelStateChanged(int state) {

switch (state) {

case DisplayManagerHelper.SWIVEL_START:

// swivel start

break;

case DisplayManagerHelper.SWIVEL_END:

// swivel complete

break;

case DisplayManagerHelper.NON_SWIVEL_START:

// Non swivel start

break;

case DisplayManagerHelper.NON_SWIVEL_END:

// Non swivel complete

break;

default:

// default value

break;

}

}

}

// callback class

private inner class MySwivelStateCallback : SwivelStateCallback() {

override fun onSwivelStateChanged(state: Int) {

when (state) {

DisplayManagerHelper.SWIVEL_START -> {

// swivel start

}

DisplayManagerHelper.SWIVEL_END -> {

// swivel complete

}

DisplayManagerHelper.NON_SWIVEL_START -> {

// Non swivel start

}

DisplayManagerHelper.NON_SWIVEL_END -> {

// Non swivel complete

}

else -> {

// default value

}

}

}

}