Search in sources :

Example 1 with SceneState

use of com.herewhite.sdk.domain.SceneState in project whiteboard-android by netless-io.

the class ScenesActivity method onClick.

// sample of scenes apis
@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.putScenes:
            // create slides on scenes
            // it should run only once
            mRoom.putScenes(SCENE_DIR, scenes, 0);
            mRoom.setScenePath(SCENE_DIR);
            break;
        case R.id.setScenePath:
            mRoom.setScenePath(SCENE_DIR + "/" + scenes[1].getName());
            break;
        case R.id.setSceneIndex:
            // switch scene by index
            mRoom.setSceneIndex(2, new Promise<Boolean>() {

                @Override
                public void then(Boolean aBoolean) {
                }

                @Override
                public void catchEx(SDKError t) {
                }
            });
            break;
        case R.id.getRoomState:
            // sync SceneState
            SceneState sceneState = mRoom.getSceneState();
            logRoomInfo("current sceneState " + sceneState.toString());
            // get sceneState by async
            mRoom.getSceneState(new Promise<SceneState>() {

                @Override
                public void then(SceneState sceneState) {
                    logRoomInfo("current sceneState " + sceneState.toString());
                }

                @Override
                public void catchEx(SDKError t) {
                }
            });
            break;
    }
}
Also used : SDKError(com.herewhite.sdk.domain.SDKError) SceneState(com.herewhite.sdk.domain.SceneState)

Example 2 with SceneState

use of com.herewhite.sdk.domain.SceneState in project whiteboard-android by netless-io.

the class RoomActivityTest method setScenePath.

@Test
public void setScenePath() {
    onIdle();
    CountingIdlingResource idlingResource = new CountingIdlingResource("getScenePath");
    idlingResource.increment();
    mActivity.mRoom.getSceneState(new Promise<SceneState>() {

        @Override
        public void then(SceneState sceneState) {
            currentSceneState = sceneState;
            idlingResource.decrement();
        }

        @Override
        public void catchEx(SDKError t) {
            idlingResource.decrement();
        }
    });
    IdlingRegistry.getInstance().register(idlingResource);
    SetScenePathResult result = new SetScenePathResult();
    result.register();
    onView(isRoot()).perform(new SimpleViewAction() {

        @Override
        public void perform(UiController uiController, View view) {
            IdlingRegistry.getInstance().unregister(idlingResource);
            if (currentSceneState == null) {
                fail();
            }
            result.start();
            mActivity.mRoom.setScenePath(getNextScenePath(currentSceneState), result);
        }

        private String getNextScenePath(SceneState currentSceneState) {
            String dir = currentSceneState.getScenePath().substring(0, currentSceneState.getScenePath().lastIndexOf('/'));
            int index = currentSceneState.getIndex();
            Scene[] scenes = currentSceneState.getScenes();
            Scene tScene = scenes[(index + 1) % scenes.length];
            return dir + '/' + tScene.getName();
        }
    });
    // wait for idling
    onIdle();
    onView(isRoot()).perform(new SimpleViewAction() {

        @Override
        public void perform(UiController uiController, View view) {
            assertEquals(true, result.success);
            result.unregister();
        }
    });
}
Also used : CountingIdlingResource(androidx.test.espresso.idling.CountingIdlingResource) SDKError(com.herewhite.sdk.domain.SDKError) SimpleViewAction(com.herewhite.demo.utils.SimpleViewAction) SceneState(com.herewhite.sdk.domain.SceneState) UiController(androidx.test.espresso.UiController) Scene(com.herewhite.sdk.domain.Scene) View(android.view.View) Espresso.onView(androidx.test.espresso.Espresso.onView) Test(org.junit.Test)

Example 3 with SceneState

use of com.herewhite.sdk.domain.SceneState in project whiteboard-android by netless-io.

the class ScenesActivity method joinRoom.

// region room
private void joinRoom(String uuid, String token) {
    logRoomInfo("room uuid: " + uuid + "\nroom token: " + token);
    WhiteSdkConfiguration configuration = new WhiteSdkConfiguration(demoAPI.getAppId(), true);
    mWhiteSdk = new WhiteSdk(mWhiteboardView, this, configuration);
    RoomParams roomParams = new RoomParams(uuid, token, DemoAPI.DEFAULT_UID);
    roomParams.setDisableNewPencil(false);
    roomParams.setWritable(true);
    mWhiteSdk.joinRoom(roomParams, new RoomCallbacks() {

        @Override
        public void onCanUndoStepsUpdate(long canUndoSteps) {
        }

        @Override
        public void onCanRedoStepsUpdate(long canRedoSteps) {
        }

        @Override
        public void onCatchErrorWhenAppendFrame(long userId, Exception error) {
        }

        @Override
        public void onPhaseChanged(RoomPhase phase) {
            logRoomInfo("onPhaseChanged: " + phase.name());
            showToast(phase.name());
        }

        @Override
        public void onDisconnectWithError(Exception e) {
            logRoomInfo("onDisconnectWithError: " + e.getMessage());
        }

        @Override
        public void onKickedWithReason(String reason) {
            logRoomInfo("onKickedWithReason: " + reason);
        }

        @Override
        public void onRoomStateChanged(RoomState modifyState) {
            logRoomInfo("onRoomStateChanged: " + modifyState);
            if (modifyState.getSceneState() != null) {
                // callback when sceneState changed
                SceneState sceneState = modifyState.getSceneState();
                logRoomInfo("sceneState changed " + sceneState.toString());
            }
        }
    }, new Promise<Room>() {

        @Override
        public void then(Room room) {
            mRoom = room;
        }

        @Override
        public void catchEx(SDKError t) {
            showToast(t.getMessage());
        }
    });
}
Also used : WhiteSdkConfiguration(com.herewhite.sdk.WhiteSdkConfiguration) SDKError(com.herewhite.sdk.domain.SDKError) SceneState(com.herewhite.sdk.domain.SceneState) RoomParams(com.herewhite.sdk.RoomParams) RoomCallbacks(com.herewhite.sdk.RoomCallbacks) RoomPhase(com.herewhite.sdk.domain.RoomPhase) WhiteSdk(com.herewhite.sdk.WhiteSdk) Room(com.herewhite.sdk.Room) RoomState(com.herewhite.sdk.domain.RoomState)

Aggregations

SDKError (com.herewhite.sdk.domain.SDKError)3 SceneState (com.herewhite.sdk.domain.SceneState)3 View (android.view.View)1 Espresso.onView (androidx.test.espresso.Espresso.onView)1 UiController (androidx.test.espresso.UiController)1 CountingIdlingResource (androidx.test.espresso.idling.CountingIdlingResource)1 SimpleViewAction (com.herewhite.demo.utils.SimpleViewAction)1 Room (com.herewhite.sdk.Room)1 RoomCallbacks (com.herewhite.sdk.RoomCallbacks)1 RoomParams (com.herewhite.sdk.RoomParams)1 WhiteSdk (com.herewhite.sdk.WhiteSdk)1 WhiteSdkConfiguration (com.herewhite.sdk.WhiteSdkConfiguration)1 RoomPhase (com.herewhite.sdk.domain.RoomPhase)1 RoomState (com.herewhite.sdk.domain.RoomState)1 Scene (com.herewhite.sdk.domain.Scene)1 Test (org.junit.Test)1