Search in sources :

Example 11 with SDKError

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

the class RoomActivityTest method testSetAndGet_MemberState.

@Test
public void testSetAndGet_MemberState() {
    onIdle();
    MemberState state = new MemberState();
    state.setStrokeColor(new int[] { 99, 99, 99 });
    state.setCurrentApplianceName(Appliance.TEXT);
    state.setStrokeWidth(10);
    state.setTextSize(10);
    mActivity.mRoom.setMemberState(state);
    mActivity.mRoom.getMemberState(new Promise<MemberState>() {

        @Override
        public void then(MemberState memberState) {
            assertEquals(state.getCurrentApplianceName(), memberState.getCurrentApplianceName());
            assertArrayEquals(state.getStrokeColor(), memberState.getStrokeColor());
            assertEquals(state.getStrokeWidth(), memberState.getStrokeWidth(), Constants.DOUBLE_DELTA);
            assertEquals(state.getTextSize(), memberState.getTextSize(), Constants.DOUBLE_DELTA);
        }

        @Override
        public void catchEx(SDKError t) {
        }
    });
}
Also used : MemberState(com.herewhite.sdk.domain.MemberState) SDKError(com.herewhite.sdk.domain.SDKError) Test(org.junit.Test)

Example 12 with SDKError

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

the class PlayerTest method getPlayerTimeInfo.

@Test
public void getPlayerTimeInfo() {
    PlayerTimeInfo playerTimeInfo = mPlayer.getPlayerTimeInfo();
    assertEquals(0, playerTimeInfo.getScheduleTime());
    mPlayer.getPlayerTimeInfo(new Promise<PlayerTimeInfo>() {

        @Override
        public void then(PlayerTimeInfo playerTimeInfo) {
        }

        @Override
        public void catchEx(SDKError t) {
        }
    });
    verify(mockJsBridgeInterface).callHandler(eq("player.state.timeInfo"), any(), any());
}
Also used : PlayerTimeInfo(com.herewhite.sdk.domain.PlayerTimeInfo) SDKError(com.herewhite.sdk.domain.SDKError) Test(org.junit.Test)

Example 13 with SDKError

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

the class Displayer method convertToPointInWorld.

/**
 * 转换白板上点的坐标。
 * <p>
 * 该方法可以将 Android 内部坐标系(以屏幕左上角为原点)中的坐标转换为世界坐标系(以白板初始化时的中点为原点)坐标。
 *
 * @param x       点在 Android 坐标系中的 X 轴坐标,单位为DP。
 * @param y       点在 Android 坐标系中的 Y 轴坐标,单位为DP。
 * @param promise `Promise<Point>` 接口实例,详见 {@link com.herewhite.sdk.domain.Promise Promise}。你可以通过该接口获取 `convertToPointInWorld` 的调用结果:
 *                - 如果方法调用成功,将返回点在世界坐标系上的坐标。详见 {@link com.herewhite.sdk.domain.Point Point}。
 *                - 如果方法调用失败,将返回错误信息。
 */
public void convertToPointInWorld(double x, double y, final Promise<Point> promise) {
    bridge.callHandler("displayer.convertToPointInWorld", new Object[] { x, y }, new OnReturnValue<Object>() {

        @Override
        public void onValue(Object o) {
            try {
                promise.then(gson.fromJson(String.valueOf(o), Point.class));
            } catch (AssertionError a) {
                throw a;
            } catch (JsonSyntaxException e) {
                Logger.error("An JsonSyntaxException occurred while parse json from convertToPointInWorld", e);
                promise.catchEx(new SDKError(e.getMessage()));
            } catch (Throwable e) {
                Logger.error("An exception occurred in convertToPointInWorld promise then method", e);
                promise.catchEx(new SDKError(e.getMessage()));
            }
        }
    });
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) SDKError(com.herewhite.sdk.domain.SDKError) JSONObject(org.json.JSONObject) WhiteObject(com.herewhite.sdk.domain.WhiteObject)

Example 14 with SDKError

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

the class Player method getPhase.

/**
 * 获取白板回放的阶段。
 *
 * 在 `Player` 生命周期内,你可以调用该方法获取白板回放当前所处的阶段。
 *
 * @note
 * - 该方法为异步调用。我们推荐你仅在调试或问题排查时使用。一般情况下可以使用同步方法 {@link #getPlayerPhase() getPlayerPhase} 获取回放阶段。
 * - 成功调用 {@link #stop() stop}、{@link #play() play} 或 {@link #pause() pause} 等方法后,你无法通过 {@link #getPlayerPhase() getPlayerPhase} 立即获取最新的白板回放阶段。
 * 此时,你可以调用 {@link #getPhase(Promise<PlayerPhase>) getPhase}。
 *
 * @param promise `Promise<PlayerPhase>` 接口实例,详见 {@link com.herewhite.sdk.domain.Promise Promise}。你可以通过该接口获取 `getPhase` 方法的调用结果:
 *                - 如果方法调用成功,将返回白板回放的阶段。
 *                - 如果方法调用失败,将返回错误信息。
 */
public void getPhase(final Promise<PlayerPhase> promise) {
    bridge.callHandler("player.getBroadcastState", new Object[] {}, new OnReturnValue<Object>() {

        @Override
        public void onValue(Object o) {
            try {
                promise.then(PlayerPhase.valueOf(String.valueOf(o)));
            } catch (AssertionError a) {
                throw a;
            } catch (JsonSyntaxException e) {
                Logger.error("An JsonSyntaxException occurred while parse json from getPhase", e);
                promise.catchEx(new SDKError(e.getMessage()));
            } catch (Throwable e) {
                Logger.error("An exception occurred in getPhase promise then method", e);
                promise.catchEx(new SDKError(e.getMessage()));
            }
        }
    });
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) SDKError(com.herewhite.sdk.domain.SDKError)

Example 15 with SDKError

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

the class Player method getPlayerState.

/**
 * 获取白板回放的状态。
 *
 * @note
 * - 该方法为异步调用。我们推荐你仅在调试或问题排查时使用。一般情况下可以使用同步方法 {@link #getPlayerState() getPlayerState}[1/2] 获取。
 * - 如果白板回放处于 `waitingFirstFrame` 阶段,则该方法返回 `null`。
 *
 * @param promise `Promise<PlayerState>` 接口实例,详见 {@link com.herewhite.sdk.domain.Promise Promise}。你可以通过该接口获取 `getPlayerState` 方法调用的结果:
 *                - 如果方法调用成功,将返回白板回放状态,详见 {@link com.herewhite.sdk.domain.PlayerState PlayerState}。
 *                - 如果方法调用失败,将返回错误信息。
 */
public void getPlayerState(final Promise<PlayerState> promise) {
    bridge.callHandler("player.state.playerState", new Object[] {}, new OnReturnValue<Object>() {

        @Override
        public void onValue(Object o) {
            try {
                PlayerState playerState = gson.fromJson(String.valueOf(o), PlayerState.class);
                promise.then(playerState);
            } catch (AssertionError a) {
                throw a;
            } catch (JsonSyntaxException e) {
                Logger.error("An JsonSyntaxException occurred while parse json from getPlayerState", e);
                promise.catchEx(new SDKError(e.getMessage()));
            } catch (Throwable e) {
                Logger.error("An exception occurred in getPlayerState promise then method", e);
                promise.catchEx(new SDKError(e.getMessage()));
            }
        }
    });
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) PlayerState(com.herewhite.sdk.domain.PlayerState) SDKError(com.herewhite.sdk.domain.SDKError)

Aggregations

SDKError (com.herewhite.sdk.domain.SDKError)38 JSONObject (org.json.JSONObject)18 JsonSyntaxException (com.google.gson.JsonSyntaxException)13 WhiteSdk (com.herewhite.sdk.WhiteSdk)12 WhiteSdkConfiguration (com.herewhite.sdk.WhiteSdkConfiguration)12 JsonObject (com.google.gson.JsonObject)10 Room (com.herewhite.sdk.Room)10 RoomParams (com.herewhite.sdk.RoomParams)10 RoomPhase (com.herewhite.sdk.domain.RoomPhase)7 RoomState (com.herewhite.sdk.domain.RoomState)7 AbstractRoomCallbacks (com.herewhite.sdk.AbstractRoomCallbacks)5 CommonCallback (com.herewhite.sdk.CommonCallback)5 Test (org.junit.Test)5 RoomCallbacks (com.herewhite.sdk.RoomCallbacks)4 View (android.view.View)3 ConvertException (com.herewhite.sdk.domain.ConvertException)3 FontFace (com.herewhite.sdk.domain.FontFace)3 Scene (com.herewhite.sdk.domain.Scene)3 SceneState (com.herewhite.sdk.domain.SceneState)3 WindowParams (com.herewhite.sdk.domain.WindowParams)3