android整合好视通sdk经验总结(二)

一、无法正常访问好视通服务接口

当按照android整合好视通sdk经验总结(一)步骤整合完毕后,在这里修改申请的应用id和服务地址在这里插入图片描述
修改完毕后运行发现无法正常初始化sdk,错误码30,对应错误信息为无法连接到网络,经过检查后发现,我这里是用的私有的https请求,被安全拦截,因此无法连接到好视通服务。
解决办法:
在主module的application里作如下改动:
实现 X509TrustManager接口,并在oncreate()方法中加入

public class AppApplication implements X509TrustManager {

    private static TrustManager[] trustManagers;
    private static final X509Certificate[] _AcceptedIssuers = new
            X509Certificate[] {};
    @Override
    public void onCreate() {
        super.onCreate();
        //设置私有https证书信任
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(String arg0, SSLSession arg1) {
                // TODO Auto-generated method stub
                return true;
            }

        });

        SSLContext context = null;
        if (trustManagers == null) {
            trustManagers = new TrustManager[] { this };
        }

        try {
            context = SSLContext.getInstance("SSL");
            context.init(null, trustManagers, new SecureRandom());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }

        HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
        }
        
    @Override
    public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {

    }

    @Override
    public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {

    }

    @Override
    public X509Certificate[] getAcceptedIssuers() {
        return _AcceptedIssuers;
    }
        }

即可正常访问好视通服务,app也可以正常运行。

二、对界面分屏数量进行修改

原有demo对视频人数画面做了限制,最多只能给6个人分配视频画面,超出6人不再分配视频画面,查看相关view的代码发现只对6个人的数据做了处理,因此只能分配6个画面,这里根据人数对画面做分割处理,堆叠最大人数10人
在FspUserViewGroup中对onMeasure()和onLayout()

 @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int w = MeasureSpec.getSize(widthMeasureSpec);
        int h = MeasureSpec.getSize(heightMeasureSpec);

        int childrenCount = getChildCount();
        if (childrenCount <= 0) {
            return;
        }
        if (childrenCount <= 2) { // <=2
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    if (i == 0) {
                        child.measure(widthMeasureSpec, heightMeasureSpec);
                    } else {
                        child.measure(MeasureSpec.makeMeasureSpec(w / 3, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(h / 3, MeasureSpec.EXACTLY));
                    }
                }
            }
        } else if (childrenCount <= 4) { // <=4
            int cw = (w - m_margin) / 2;
            int ch = (h - m_margin - m_marginBottom) / 2;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        } else if (childrenCount <= 6) { // <=6
            int cw = (w - m_margin) / 2;
            int ch = (h - 2 * m_margin - m_marginBottom) / 3;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        } else if (childrenCount <= 8) { // <=8
            int cw = (w - m_margin) / 2;
            int ch = (h - 3 * m_margin - m_marginBottom) / 4;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        } else { // <=10
            int cw = (w - m_margin) / 2;
            int ch = (h - 4 * m_margin - m_marginBottom) / 5;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.measure(widthMeasureSpec, heightMeasureSpec);
                } else {
                    if (m_isMax) {
                        child.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY),
                                MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
                        continue;
                    }
                    child.measure(MeasureSpec.makeMeasureSpec(cw, MeasureSpec.EXACTLY),
                            MeasureSpec.makeMeasureSpec(ch, MeasureSpec.EXACTLY));
                }
            }
        }

        setMeasuredDimension(w, h);
    }


    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int childrenCount = getChildCount();
        if (childrenCount <= 0) {
            return;
        }
        if (childrenCount <= 2) { // <=2
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, r, b);
                    } else {
                        child.layout(r * 2 / 3, t, r, b / 3);
                    }
                }
            }
        } else if (childrenCount <= 4) { // <=4
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin - m_marginBottom) / 2;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, b);
                    } else {
                        child.layout(cw + m_margin, ch + m_margin, r, b);
                    }
                }
            }
        } else if (childrenCount <= 6) { // <=6
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin * 2 - m_marginBottom) / 3;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, 2 * ch + m_margin);
                    } else if (i == 3) {
                        child.layout(cw + m_margin, ch + m_margin, r, 2 * ch + m_margin);
                    } else if (i == 4) {
                        child.layout(l, ch * 2 + m_margin * 2, cw, b);
                    } else if (i == 5) {
                        child.layout(cw + m_margin, ch * 2 + m_margin * 2, r, b);
                    } else {
                        break;
                    }
                }
            }
        } else if (childrenCount <= 8) { // <=8
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin * 3 - m_marginBottom) / 4;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, 2 * ch + m_margin);
                    } else if (i == 3) {
                        child.layout(cw + m_margin, ch + m_margin, r, 2 * ch + m_margin);
                    } else if (i == 4) {
                        child.layout(l, ch * 2 + m_margin * 2, cw, 3 * ch + 2 * m_margin);
                    } else if (i == 5) {
                        child.layout(cw + m_margin, ch * 2 + m_margin * 2, r, 3 * ch + 2 * m_margin);
                    } else if (i == 6) {
                        child.layout(l, ch * 3 + m_margin * 3, cw, b);
                    } else if (i == 7) {
                        child.layout(cw + m_margin, ch * 3 + m_margin * 3, r, b);
                    } else {
                        break;
                    }
                }
            }
        } else { // <=10
            int cw = (r - m_margin) / 2;
            int ch = (b - m_margin * 4 - m_marginBottom) / 5;
            for (int i = 0; i < childrenCount; i++) {
                View child = getChildAt(i);
                if (child.isSelected()) {
                    child.layout(l, t, r, b);
                } else {
                    setChildDoubleClickListener(l, t, r, b, child);
                    if (i == 0) {
                        child.layout(l, t, cw, ch);
                    } else if (i == 1) {
                        child.layout(cw + m_margin, t, r, ch);
                    } else if (i == 2) {
                        child.layout(l, ch + m_margin, cw, 2 * ch + m_margin);
                    } else if (i == 3) {
                        child.layout(cw + m_margin, ch + m_margin, r, 2 * ch + m_margin);
                    } else if (i == 4) {
                        child.layout(l, ch * 2 + m_margin * 2, cw, 3 * ch + m_margin * 2);
                    } else if (i == 5) {
                        child.layout(cw + m_margin, ch * 2 + m_margin * 2, r, 3 * ch + m_margin * 2);
                    } else if (i == 6) {
                        child.layout(l, ch * 3 + m_margin * 3, cw, 4 * ch + m_margin * 3);
                    } else if (i == 7) {
                        child.layout(cw + m_margin, ch * 3 + m_margin * 3, r, 4 * ch + m_margin * 3);
                    } else if (i == 8) {
                        child.layout(l, ch * 4 + m_margin * 4, cw, b);
                    } else if (i == 9) {
                        child.layout(cw + m_margin, ch * 4 + m_margin * 4, r, b);
                    } else {
                        break;
                    }
                }
            }
        }
    }

三、界面显示信息由userid改为username
原代码 登录好视通服务时,传入了userid和username,这里ios传入好视通sdk后的人员信息如果是中文,拿出来后是乱码,怀疑是sdk编码问题,因此为了配合ios这里也做相同的处理:先对人员信息进行URL编码处理,拿出来使用时再进行解码。

boolean result = FspManager.getInstance().login(TextUtils.equals(userid, "") ? "userid" : userid, TextUtils.equals(username, "") ? URLEncoder.encode("username") : URLEncoder.encode(username));

新建一个参会人员信息管理类FspUserInfoManager

public class FspUserInfoManager {
    /**
     * 拍照上传 项目标识id
     */
    private String rowguid = "";
    /**
     * 好视通会议室 人员数据
     */
    private static List<FspUserInfo> my_data = new ArrayList<>();
    private static FspUserInfoManager instance;

    public static synchronized FspUserInfoManager getInstance() {
        if (instance == null) {
            Class var0 = FspUserInfoManager.class;
            synchronized (FspUserInfoManager.class) {
                if (instance == null) {
                    instance = new FspUserInfoManager();
                }
            }
        }

        return instance;
    }

    /**
     * 刷新用户信息数据
     *
     * @param list 用户数据
     */
    public void refreshUserInfo(List<FspUserInfo> list) {
        if (my_data.size() > 0) {
            my_data.clear();
        }
        List<FspUserInfo> newInfoList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            FspUserInfo oldUserInfo = list.get(i);
            FspUserInfo userInfo = new FspUserInfo(oldUserInfo.getUserId(), oldUserInfo.getStatus(), URLDecoder.decode(oldUserInfo.getCustomInfo()));
            newInfoList.add(userInfo);
        }
        my_data.addAll(newInfoList);
    }

    /**
     * 根据用户id获取 用户名
     *
     * @param userId 用户 id
     * @return 用户名
     */
    public String getCustomInfo(String userId) {
        String name = "";
        if (my_data != null && !my_data.isEmpty()) {
            for (int i = 0; i < my_data.size(); i++) {
                if (TextUtils.equals(userId, my_data.get(i).getUserId())) {
                    name = my_data.get(i).getCustomInfo();
                    return name;
                }
            }
        }
        return "";
    }

    public List<FspUserInfo> getMyData() {
        return my_data;
    }

    public String getRowguid() {
        return rowguid;
    }

    public void setRowguid(String rowguid) {
        this.rowguid = rowguid;
    }
}

因为参会期间会有人员中途加入或者退出会议的情况,因此需要及时刷新用户信息,此处在MainActivity中的刷新用户状态的事件中加入refreshUserInfo

@Override
public void onEventRefreshUserStatusFinished(FspEvents.RefreshUserStatusFinished status) {
    if (m_curOperateDialog != null && m_curOperateDialog.isShowing()) {
        m_curOperateDialog.notifyDataSetChanged(status);
    }
    //个性化 更新用户信息
    if (status.isSuccess) {
        FspUserInfoManager.getInstance().refreshUserInfo((Arrays.asList(status.infos)));
    }
}

将界面上相关的需要展示人员信息的数据 从userid换成与userid对应的username即可例如:
发送消息界面userid改成username:

   @OnClick(R2.id.dialog_tv_send_select)
    public void onClickSelectReceivers(View view) {
        SenderSelectDialog senderSelectDialog = new SenderSelectDialog(getContext(), m_remoteUserId);
        senderSelectDialog.setListener(new SenderSelectDialog.onDialogItemSelectedListener() {
            @Override
            public void onItemSelected(String uidSel) {
                m_remoteUserId = uidSel;
//                dialogTvSendSelect.setText(m_remoteUserId == null ? "发送给:所有人" : "发送给:" + m_remoteUserId);
                String name = FspUserInfoManager.getInstance().getCustomInfo(m_remoteUserId);
                dialogTvSendSelect.setText(name == null ? "发送给:所有人" : "发送给:" + name);

                if (m_onDialogItemSenderSelectListener != null) {
                    m_onDialogItemSenderSelectListener.onItemSelected(uidSel);
                }
            }
        });
        senderSelectDialog.show();
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

进击的code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值