Custom classroom UI
Introduction to classrooms and UI components
Data exchange process
In the Agora Classroom SDK, the code of the user interfaces is separated from the code of core business logic. The Classroom SDK contains two libraries, AgoraEduUI and AgoraEduCore. These two libraries connect with each other through Agora Edu Context. Supposing that we want to implement a button for turning on or off the camera, you can call the openLocalDevice
method of MediaContext
in AgoraEduUI
, and listen to the event which indicates the device state change thrown by IMediaHandler
. The data flow is as follows:
The structure of classrooms and UI components
The structure of classrooms is as follows:
The UI of each classroom type is defined in the corresponding .xml
file and contains multiple independent UI components. The structure of UI components is as follows:
Developers can combine UI components as they wish to implement a custom classroom type, and can also customize UI components or modify the existing UI components of Flexible Classroom.
Customize the classroom UI
To customize the classroom UI, follow these steps:
1. Get the source code of Flexible Classroom
If you want to customize the classroom UI based on the default UI of Flexible Classroom, you need to integrate Flexible Classroom by downloading the source code on GitHub. Refer to the following steps:
-
To clone the repository, run the following command:
-
To switch the branch, run the following command. Remember to replace
{VERSION}
with a specified version number:For example, if you want to switch to the branch of v2.1.0, just run the following command:
Agora recommends switching the branch of the latest release. The following image shows how to see the latest release branch in the GitHub repository:
In later steps, you edit the code in the following two folders:
/AgoraClassSDK
: Implements classroom pages./AgoraEduUIKit
: All UI components used in Flexible Classroom.
2. Import the library of UI components
To import the library of UI components, refer to the following steps:
-
Integrate Flexible Classroom into your own project through Maven.
-
Pay special attention to the references of the
AgoraEduUIKit
andAgoraClassSDK
modules. You need to make the following changes in thebuild.gradle
file:
AgoraClassSDK
, we have already made reference to AgoraEduUIKit
.3. Edit the existing UI components
All UI components are in the com.agora.edu.component
directory, you are free to edit the code and change the UI.
Example
The following example shows how to change the height, title, and background color of the top navigation bar in Small Classroom:
-
Find
AgoraClassSmallActivity
under theio.agora.classroom.ui
directory in theAgoraClassSDK
module. -
Find
AgoraEduHeadComponent
inactivity_agora_class_small.xml
corresponding toAgoraClassSmallActivity
.Activity
and.xml
are bound throughviewbinding
. -
Open
agora_edu_head_component.xml
corresponding toAgoraEduHeadComponent
. In this file, you can directly change the height, title, and background color of the navigation bar.
4. Add a UI component
To add a UI component, you must extend AbsAgoraEduComponent
and call initView(agoraUIProvider: IAgoraUIProvider)
.
UI components can obtain the data of the EduCore layer through the IAgoraUIProvider
interface.
Example
The following example shows how to add a component named as AgoraEduMyComponent
in One-to-one Classroom:
-
Define
AgoraEduMyComponent
: -
Use the
AgoraEduMyComponent
that you defined in.xml
: -
Initialize the UI component in
AgoraClass1V1Activity
: