Search in sources :

Example 1 with SurfaceViewRenderer

use of org.webrtc.SurfaceViewRenderer in project talk-android by nextcloud.

the class CallActivity method removeMediaStream.

private void removeMediaStream(String sessionId) {
    if (remoteRenderersLayout.getChildCount() > 0) {
        RelativeLayout relativeLayout = remoteRenderersLayout.findViewWithTag(sessionId);
        if (relativeLayout != null) {
            SurfaceViewRenderer surfaceViewRenderer = relativeLayout.findViewById(R.id.surface_view);
            surfaceViewRenderer.release();
            remoteRenderersLayout.removeView(relativeLayout);
            remoteRenderersLayout.invalidate();
        }
    }
    callControls.setZ(100.0f);
}
Also used : SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) RelativeLayout(android.widget.RelativeLayout)

Example 2 with SurfaceViewRenderer

use of org.webrtc.SurfaceViewRenderer in project actor-platform by actorapp.

the class CallFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.callId = getArguments().getLong("call_id");
    this.call = messenger().getCall(callId);
    if (call == null) {
        this.peer = Peer.user(myUid());
    } else {
        this.peer = call.getPeer();
    }
    manager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
    FrameLayout cont = (FrameLayout) inflater.inflate(R.layout.fragment_call, container, false);
    v = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
    CallBackgroundAvatarView backgroundAvatarView = (CallBackgroundAvatarView) cont.findViewById(R.id.background);
    // animator = new CallAvatarLayerAnimator(cont.findViewById(R.id.layer),
    // cont.findViewById(R.id.layer1),
    // cont.findViewById(R.id.layer2),
    // cont.findViewById(R.id.layer3),
    // cont.findViewById(R.id.layer4)
    // );
    layer1 = cont.findViewById(R.id.layer1);
    layer2 = cont.findViewById(R.id.layer2);
    layer3 = cont.findViewById(R.id.layer3);
    avatarLayers = new View[] { // cont.findViewById(R.id.layer),
    layer1, layer2, layer3 // cont.findViewById(R.id.layer4)
    };
    for (int i = 0; i < avatarLayers.length; i++) {
        View layer = avatarLayers[i];
        ((GradientDrawable) layer.getBackground()).setColor(Color.WHITE);
        ((GradientDrawable) layer.getBackground()).setAlpha(50);
    }
    endCallContainer = cont.findViewById(R.id.end_call_container);
    answerContainer = cont.findViewById(R.id.answer_container);
    ImageButton answer = (ImageButton) cont.findViewById(R.id.answer);
    answer.setOnClickListener(v1 -> onAnswer());
    ImageButton notAnswer = (ImageButton) cont.findViewById(R.id.notAnswer);
    endCall = (ImageButton) cont.findViewById(R.id.end_call);
    notAnswer.setOnClickListener(v1 -> doEndCall());
    endCall.setOnClickListener(v1 -> doEndCall());
    // 
    // Avatar/Name bind
    // 
    avatarView = (AvatarView) cont.findViewById(R.id.avatar);
    avatarView.init(Screen.dp(130), 50);
    nameTV = (TextView) cont.findViewById(R.id.name);
    nameTV.setTextColor(ActorSDK.sharedActor().style.getProfileTitleColor());
    if (peer.getPeerType() == PeerType.PRIVATE) {
        UserVM user = users().get(peer.getPeerId());
        avatarView.bind(user);
        backgroundAvatarView.bind(user);
        bind(nameTV, user.getName());
    } else if (peer.getPeerType() == PeerType.GROUP) {
        GroupVM g = groups().get(peer.getPeerId());
        avatarView.bind(g);
        backgroundAvatarView.bind(g);
        bind(nameTV, g.getName());
    }
    nameTV.setSelected(true);
    // 
    // Members list
    // 
    membersList = (RecyclerListView) cont.findViewById(R.id.members_list);
    if (call != null) {
        CallMembersAdapter membersAdapter = new CallMembersAdapter(getActivity(), call.getMembers());
        membersList.setAdapter(membersAdapter);
    }
    // 
    // Members list/ avatar switch
    // 
    View.OnClickListener listener = v1 -> switchAvatarMembers();
    avatarView.setOnClickListener(listener);
    // cont.findViewById(R.id.background).setOnClickListener(listener);
    membersList.setOnItemClickListener((parent, view, position, id) -> switchAvatarMembers());
    statusTV = (TextView) cont.findViewById(R.id.status);
    // 
    if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.VIBRATE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.MODIFY_AUDIO_SETTINGS) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WAKE_LOCK) != PackageManager.PERMISSION_GRANTED) {
        Log.d("Permissions", "call - no permission :c");
        CallFragment.this.requestPermissions(new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA, Manifest.permission.VIBRATE, Manifest.permission.MODIFY_AUDIO_SETTINGS, Manifest.permission.WAKE_LOCK }, PERMISSIONS_REQUEST_FOR_CALL);
    }
    audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);
    audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
    speaker = (TintImageView) cont.findViewById(R.id.speaker);
    speaker.setResource(R.drawable.ic_volume_up_white_24dp);
    speakerTV = (TextView) cont.findViewById(R.id.speaker_tv);
    cont.findViewById(R.id.speaker_btn).setOnClickListener(v1 -> toggleSpeaker(speaker, speakerTV));
    checkSpeaker(speaker, speakerTV);
    muteCall = (TintImageView) cont.findViewById(R.id.mute);
    muteCallTv = (TextView) cont.findViewById(R.id.mute_tv);
    muteCall.setResource(R.drawable.ic_mic_off_white_24dp);
    cont.findViewById(R.id.mute_btn).setOnClickListener(v1 -> messenger().toggleCallMute(callId));
    videoIcon = (TintImageView) cont.findViewById(R.id.video);
    videoIcon.setResource(R.drawable.ic_videocam_white_24dp);
    videoTv = (TextView) cont.findViewById(R.id.video_tv);
    videoTv.setTextColor(getResources().getColor(R.color.picker_grey));
    videoIcon.setTint(getResources().getColor(R.color.picker_grey));
    cont.findViewById(R.id.video_btn).setOnClickListener(v1 -> messenger().toggleVideoEnabled(callId));
    final TintImageView back = (TintImageView) cont.findViewById(R.id.back);
    back.setResource(R.drawable.ic_message_white_24dp);
    cont.findViewById(R.id.back_btn).setOnClickListener(v1 -> getActivity().startActivity(Intents.openDialog(peer, false, getActivity())));
    final TintImageView add = (TintImageView) cont.findViewById(R.id.add);
    add.setResource(R.drawable.ic_person_add_white_24dp);
    TextView addTv = (TextView) cont.findViewById(R.id.add_user_tv);
    addTv.setTextColor(getResources().getColor(R.color.picker_grey));
    add.setTint(getResources().getColor(R.color.picker_grey));
    if (peer.getPeerType() == PeerType.PRIVATE) {
        eglContext = EglBase.create();
        remoteVideoView = (SurfaceViewRenderer) cont.findViewById(R.id.remote_renderer);
        localVideoView = new SurfaceViewRenderer(getActivity()) {

            private boolean aspectFixed = false;

            @Override
            public void renderFrame(VideoRenderer.I420Frame frame) {
                if (!aspectFixed) {
                    aspectFixed = true;
                    int maxWH = Screen.getWidth() / 3 - Screen.dp(20);
                    float scale = Math.min(maxWH / (float) frame.width, maxWH / (float) frame.height);
                    int destW = (int) (scale * frame.width);
                    int destH = (int) (scale * frame.height);
                    boolean turned = frame.rotationDegree % 90 % 2 == 0;
                    localVideoView.post(new Runnable() {

                        @Override
                        public void run() {
                            localVideoView.getLayoutParams().height = turned ? destW : destH;
                            localVideoView.getLayoutParams().width = turned ? destH : destW;
                        }
                    });
                }
                super.renderFrame(frame);
            }
        };
        localVideoView.setVisibility(View.INVISIBLE);
        localVideoView.setZOrderMediaOverlay(true);
        localVideoView.setOnTouchListener((v1, event) -> {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    dX = localVideoView.getX() - event.getRawX();
                    dY = localVideoView.getY() - event.getRawY();
                    break;
                case MotionEvent.ACTION_MOVE:
                    localVideoView.animate().x(event.getRawX() + dX).y(event.getRawY() + dY).setDuration(0).start();
                default:
                    return false;
            }
            return true;
        });
        int margin = Screen.dp(20);
        int localVideoWidth = Screen.getWidth() / 3 - margin;
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(localVideoWidth, Math.round(localVideoWidth / 1.5f), Gravity.TOP | Gravity.LEFT);
        int statusBarHeight = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            statusBarHeight = getResources().getDimensionPixelSize(resourceId);
        }
        params.setMargins(margin, margin + statusBarHeight, 0, 0);
        cont.addView(localVideoView, params);
    } else {
        if (call != null) {
            if (call.getIsVideoEnabled().get()) {
                messenger().toggleVideoEnabled(callId);
            }
        }
    }
    return cont;
}
Also used : BaseFragment(im.actor.sdk.controllers.BaseFragment) ImageButton(android.widget.ImageButton) Ringtone(android.media.Ringtone) PoisonPill(im.actor.runtime.actors.messages.PoisonPill) Bundle(android.os.Bundle) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) PackageManager(android.content.pm.PackageManager) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) Date(java.util.Date) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) PendingIntent(android.app.PendingIntent) Screen(im.actor.sdk.util.Screen) CallMember(im.actor.core.viewmodel.CallMember) Manifest(android.Manifest) PowerManager(android.os.PowerManager) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) DateFormat(java.text.DateFormat) Intents(im.actor.sdk.controllers.Intents) NotificationManager(android.app.NotificationManager) TimeZone(java.util.TimeZone) ValueModel(im.actor.runtime.mvvm.ValueModel) ContextCompat(android.support.v4.content.ContextCompat) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) TextView(android.widget.TextView) Peer(im.actor.core.entity.Peer) Props(im.actor.runtime.actors.Props) Notification(android.app.Notification) CallState(im.actor.core.viewmodel.CallState) ViewHolder(im.actor.sdk.view.adapters.ViewHolder) Context(android.content.Context) ActorSDKMessenger.myUid(im.actor.sdk.util.ActorSDKMessenger.myUid) AndroidVideoTrack(im.actor.runtime.android.webrtc.AndroidVideoTrack) TintImageView(im.actor.sdk.view.TintImageView) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) GroupVM(im.actor.core.viewmodel.GroupVM) AudioManager(android.media.AudioManager) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) CallVM(im.actor.core.viewmodel.CallVM) MotionEvent(android.view.MotionEvent) GradientDrawable(android.graphics.drawable.GradientDrawable) ActorSystem(im.actor.runtime.actors.ActorSystem) AvatarView(im.actor.sdk.view.avatar.AvatarView) ActorRef(im.actor.runtime.actors.ActorRef) HolderAdapter(im.actor.sdk.view.adapters.HolderAdapter) PeerType(im.actor.core.entity.PeerType) ActorSDK(im.actor.sdk.ActorSDK) TimerActor(im.actor.sdk.controllers.calls.view.TimerActor) VideoRenderer(org.webrtc.VideoRenderer) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) Color(android.graphics.Color) Gravity(android.view.Gravity) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) CallBackgroundAvatarView(im.actor.sdk.view.avatar.CallBackgroundAvatarView) RingtoneManager(android.media.RingtoneManager) NotificationCompat(android.support.v4.app.NotificationCompat) EglBase(org.webrtc.EglBase) VideoTrack(org.webrtc.VideoTrack) Log(im.actor.runtime.Log) Vibrator(android.os.Vibrator) Activity(android.app.Activity) GroupVM(im.actor.core.viewmodel.GroupVM) VideoRenderer(org.webrtc.VideoRenderer) TintImageView(im.actor.sdk.view.TintImageView) CallBackgroundAvatarView(im.actor.sdk.view.avatar.CallBackgroundAvatarView) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) TextView(android.widget.TextView) TintImageView(im.actor.sdk.view.TintImageView) AvatarView(im.actor.sdk.view.avatar.AvatarView) CallBackgroundAvatarView(im.actor.sdk.view.avatar.CallBackgroundAvatarView) GradientDrawable(android.graphics.drawable.GradientDrawable) ImageButton(android.widget.ImageButton) UserVM(im.actor.core.viewmodel.UserVM) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView)

Example 3 with SurfaceViewRenderer

use of org.webrtc.SurfaceViewRenderer in project matrix-android-sdk by matrix-org.

the class MXWebRtcView method onLayout.

/**
 * {@inheritDoc}
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int height = b - t;
    int width = r - l;
    if (height == 0 || width == 0) {
        l = t = r = b = 0;
    } else {
        int frameHeight;
        int frameRotation;
        int frameWidth;
        ScalingType scalingType;
        synchronized (layoutSyncRoot) {
            frameHeight = this.frameHeight;
            frameRotation = this.frameRotation;
            frameWidth = this.frameWidth;
            scalingType = this.scalingType;
        }
        SurfaceViewRenderer surfaceViewRenderer = getSurfaceViewRenderer();
        switch(scalingType) {
            case SCALE_ASPECT_FILL:
                // Fill this ViewGroup with surfaceViewRenderer and the latter
                // will take care of filling itself with the video similarly to
                // the cover value the CSS property object-fit.
                r = width;
                l = 0;
                b = height;
                t = 0;
                break;
            case SCALE_ASPECT_FIT:
            default:
                // (which will not matter, eventually).
                if (frameHeight == 0 || frameWidth == 0) {
                    l = t = r = b = 0;
                } else {
                    float frameAspectRatio = (frameRotation % 180 == 0) ? frameWidth / (float) frameHeight : frameHeight / (float) frameWidth;
                    Point frameDisplaySize = RendererCommon.getDisplaySize(scalingType, frameAspectRatio, width, height);
                    l = (width - frameDisplaySize.x) / 2;
                    t = (height - frameDisplaySize.y) / 2;
                    r = l + frameDisplaySize.x;
                    b = t + frameDisplaySize.y;
                }
                break;
        }
    }
    surfaceViewRenderer.layout(l, t, r, b);
}
Also used : ScalingType(org.webrtc.RendererCommon.ScalingType) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) Point(android.graphics.Point) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint)

Example 4 with SurfaceViewRenderer

use of org.webrtc.SurfaceViewRenderer in project wcs-android-sdk-samples by flashphoner.

the class VideoChatActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference);
    /**
     * Initialization of the API.
     */
    Flashphoner.init(this);
    mParticipantVolume = (SeekBar) findViewById(R.id.participant_volume);
    mParticipantVolume.setMax(Flashphoner.getMaxVolume());
    mParticipantVolume.setProgress(Flashphoner.getVolume());
    mParticipantVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            Flashphoner.setVolume(i);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    mWcsUrlView = (EditText) findViewById(R.id.wcs_url);
    SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
    mWcsUrlView.setText(sharedPref.getString("wcs_url", getString(R.string.wcs_url)));
    mLoginView = (EditText) findViewById(R.id.login);
    mLoginView.setText(sharedPref.getString("login", ""));
    mConnectStatus = (TextView) findViewById(R.id.connect_status);
    mConnectButton = (Button) findViewById(R.id.connect_button);
    /**
     * Connection to server will be established when Connect button is clicked.
     */
    mConnectButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mConnectButton.getTag() == null || Integer.valueOf(R.string.action_connect).equals(mConnectButton.getTag())) {
                /**
                 * The connection options are set.
                 * WCS server URL and user name are passed when RoomManagerOptions object is created.
                 */
                RoomManagerOptions roomManagerOptions = new RoomManagerOptions(mWcsUrlView.getText().toString(), mLoginView.getText().toString());
                /**
                 * RoomManager object is created with method createRoomManager().
                 * Connection session is created when RoomManager object is created.
                 */
                roomManager = Flashphoner.createRoomManager(roomManagerOptions);
                /**
                 * Callback functions for connection status events are added to make appropriate changes in controls of the interface when connection is established and closed.
                 */
                roomManager.on(new RoomManagerEvent() {

                    @Override
                    public void onConnected(final Connection connection) {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mConnectButton.setText(R.string.action_disconnect);
                                mConnectButton.setTag(R.string.action_disconnect);
                                mConnectButton.setEnabled(true);
                                mConnectStatus.setText(connection.getStatus());
                                mJoinButton.setEnabled(true);
                            }
                        });
                    }

                    @Override
                    public void onDisconnection(final Connection connection) {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mConnectButton.setText(R.string.action_connect);
                                mConnectButton.setTag(R.string.action_connect);
                                mConnectButton.setEnabled(true);
                                mJoinButton.setText(R.string.action_join);
                                mJoinButton.setTag(R.string.action_join);
                                mJoinButton.setEnabled(false);
                                mPublishStatus.setText("");
                                mPublishButton.setText(R.string.action_publish);
                                mPublishButton.setTag(R.string.action_publish);
                                mPublishButton.setEnabled(false);
                                mMuteAudio.setEnabled(false);
                                mMuteAudio.setChecked(false);
                                mMuteVideo.setEnabled(false);
                                mMuteVideo.setChecked(false);
                                stream = null;
                                mConnectStatus.setText(connection.getStatus());
                                Iterator<Map.Entry<String, ParticipantView>> i = busyViews.entrySet().iterator();
                                while (i.hasNext()) {
                                    Map.Entry<String, ParticipantView> e = i.next();
                                    e.getValue().login.setText("NONE");
                                    e.getValue().surfaceViewRenderer.release();
                                    i.remove();
                                    freeViews.add(e.getValue());
                                }
                                mSendButton.setEnabled(false);
                            }
                        });
                    }
                });
                mConnectButton.setEnabled(false);
                SharedPreferences sharedPref = VideoChatActivity.this.getPreferences(Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString("wcs_url", mWcsUrlView.getText().toString());
                editor.putString("login", mLoginView.getText().toString());
                editor.apply();
            } else {
                mConnectButton.setEnabled(false);
                /**
                 * Connection to WCS server is closed with method RoomManager.disconnect().
                 */
                roomManager.disconnect();
            }
            View currentFocus = getCurrentFocus();
            if (currentFocus != null) {
                InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    mJoinRoomView = (EditText) findViewById(R.id.join_room);
    mJoinRoomView.setText(sharedPref.getString("join_room", ""));
    mJoinStatus = (TextView) findViewById(R.id.join_status);
    mJoinButton = (Button) findViewById(R.id.join_button);
    /**
     * The participant will join to video chat room when Join button is clicked.
     */
    mJoinButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            mJoinButton.setEnabled(false);
            if (mJoinButton.getTag() == null || Integer.valueOf(R.string.action_join).equals(mJoinButton.getTag())) {
                /**
                 * Room name is set with method RoomOptions.setName().
                 */
                RoomOptions roomOptions = new RoomOptions();
                roomOptions.setName(mJoinRoomView.getText().toString());
                /**
                 * The participant joins a video chat room with method RoomManager.join().
                 * RoomOptions object is passed to the method.
                 * Room object is created and returned by the method.
                 */
                room = roomManager.join(roomOptions);
                /**
                 * Callback functions for events occurring in video chat room are added.
                 * If the event is related to actions performed by one of the other participants, Participant object with data of that participant is passed to the corresponding function.
                 */
                room.on(new RoomEvent() {

                    @Override
                    public void onState(final Room room) {
                        /**
                         * After joining, Room object with data of the room is received.
                         * Method Room.getParticipants() is used to check the number of already connected participants.
                         * The method returns collection of Participant objects.
                         * The collection size is determined, and, if the maximum allowed number (in this case, three) has already been reached, the user leaves the room with method Room.leave().
                         */
                        if (room.getParticipants().size() >= 2) {
                            room.leave(null);
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    mJoinStatus.setText("Room is full");
                                    mJoinButton.setEnabled(true);
                                }
                            });
                            return;
                        }
                        final StringBuffer chatState = new StringBuffer("participants: ");
                        /**
                         * Iterating through the collection of the other participants returned by method Room.getParticipants().
                         * There is corresponding Participant object for each participant.
                         */
                        for (final Participant participant : room.getParticipants()) {
                            /**
                             * A player view is assigned to each of the other participants in the room.
                             */
                            final ParticipantView participantView = freeViews.poll();
                            if (participantView != null) {
                                chatState.append(participant.getName()).append(",");
                                busyViews.put(participant.getName(), participantView);
                                /**
                                 * Playback of the stream being published by the other participant is started with method Participant.play().
                                 * SurfaceViewRenderer to be used to display the video stream is passed when the method is called.
                                 */
                                participant.play(participantView.surfaceViewRenderer);
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        participantView.login.setText(participant.getName());
                                    }
                                });
                            }
                        }
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mJoinButton.setText(R.string.action_leave);
                                mJoinButton.setTag(R.string.action_leave);
                                mJoinButton.setEnabled(true);
                                mJoinStatus.setText("");
                                mPublishButton.setEnabled(true);
                                mSendButton.setEnabled(true);
                                if (room.getParticipants().size() == 0) {
                                    addMessageHistory("chat", "room is empty");
                                } else {
                                    addMessageHistory("chat", chatState.substring(0, chatState.length() - 1));
                                }
                            }
                        });
                    }

                    @Override
                    public void onJoined(final Participant participant) {
                        /**
                         * When a new participant joins the room, a player view is assigned to that participant.
                         */
                        final ParticipantView participantView = freeViews.poll();
                        if (participantView != null) {
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    participantView.login.setText(participant.getName());
                                    addMessageHistory(participant.getName(), "joined");
                                }
                            });
                            busyViews.put(participant.getName(), participantView);
                        }
                    }

                    @Override
                    public void onLeft(final Participant participant) {
                        /**
                         * When one of the other participants leaves the room, player view assigned to that participant is freed.
                         */
                        final ParticipantView participantView = busyViews.remove(participant.getName());
                        if (participantView != null) {
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    participantView.login.setText("NONE");
                                    addMessageHistory(participant.getName(), "left");
                                    participantView.surfaceViewRenderer.release();
                                }
                            });
                            freeViews.add(participantView);
                        }
                    }

                    @Override
                    public void onPublished(final Participant participant) {
                        /**
                         * When one of the other participants starts publishing, playback of the stream published by that participant is started.
                         */
                        final ParticipantView participantView = busyViews.get(participant.getName());
                        if (participantView != null) {
                            participant.play(participantView.surfaceViewRenderer);
                        }
                    }

                    @Override
                    public void onFailed(Room room, final String info) {
                        room.leave(null);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mJoinStatus.setText(info);
                                mJoinButton.setEnabled(true);
                            }
                        });
                    }

                    @Override
                    public void onMessage(final Message message) {
                        /**
                         * When one of the participants sends a text message, the received message is added to the messages log.
                         */
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                addMessageHistory(message.getFrom(), message.getText());
                            }
                        });
                    }
                });
                SharedPreferences sharedPref = VideoChatActivity.this.getPreferences(Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString("join_room", mJoinRoomView.getText().toString());
                editor.apply();
            } else {
                final Runnable action = new Runnable() {

                    @Override
                    public void run() {
                        mJoinButton.setEnabled(true);
                        mJoinButton.setText(R.string.action_join);
                        mJoinButton.setTag(R.string.action_join);
                        mPublishButton.setEnabled(false);
                        mSendButton.setEnabled(false);
                        /**
                         * The player views assigned to the other participants are freed.
                         */
                        Iterator<Map.Entry<String, ParticipantView>> i = busyViews.entrySet().iterator();
                        while (i.hasNext()) {
                            Map.Entry<String, ParticipantView> e = i.next();
                            e.getValue().login.setText("NONE");
                            e.getValue().surfaceViewRenderer.release();
                            i.remove();
                            freeViews.add(e.getValue());
                        }
                    }
                };
                /**
                 * The participant leaves the video chat room with method Room.leave().
                 */
                room.leave(new RestAppCommunicator.Handler() {

                    @Override
                    public void onAccepted(Data data) {
                        runOnUiThread(action);
                    }

                    @Override
                    public void onRejected(Data data) {
                        runOnUiThread(action);
                    }
                });
            }
            View currentFocus = getCurrentFocus();
            if (currentFocus != null) {
                InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    mPublishStatus = (TextView) findViewById(R.id.publish_status);
    mPublishButton = (Button) findViewById(R.id.publish_button);
    /**
     * The participant starts publishing video stream when Publish button is clicked.
     */
    mPublishButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mPublishButton.getTag() == null || Integer.valueOf(R.string.action_publish).equals(mPublishButton.getTag())) {
                ActivityCompat.requestPermissions(VideoChatActivity.this, new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA }, PUBLISH_REQUEST_CODE);
            } else {
                mPublishButton.setEnabled(false);
                /**
                 * Stream is unpublished with method Room.unpublish().
                 */
                room.unpublish();
            }
            View currentFocus = getCurrentFocus();
            if (currentFocus != null) {
                InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    /**
     * MuteAudio switch is used to mute/unmute audio of the published stream.
     * Audio is muted with method Stream.muteAudio() and unmuted with method Stream.unmuteAudio().
     */
    mMuteAudio = (Switch) findViewById(R.id.mute_audio);
    mMuteAudio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                stream.muteAudio();
            } else {
                stream.unmuteAudio();
            }
        }
    });
    /**
     * MuteVideo switch is used to mute/unmute video of the published stream.
     * Video is muted with method Stream.muteVideo() and unmuted with method Stream.unmuteVideo().
     */
    mMuteVideo = (Switch) findViewById(R.id.mute_video);
    mMuteVideo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                stream.muteVideo();
            } else {
                stream.unmuteVideo();
            }
        }
    });
    localRenderer = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
    PercentFrameLayout localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layout);
    localRenderLayout.setPosition(0, 0, 100, 100);
    localRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    localRenderer.setMirror(true);
    localRenderer.requestLayout();
    SurfaceViewRenderer remote1Render = (SurfaceViewRenderer) findViewById(R.id.remote_video_view);
    PercentFrameLayout remote1RenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_layout);
    remote1RenderLayout.setPosition(0, 0, 100, 100);
    remote1Render.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    remote1Render.setMirror(false);
    remote1Render.requestLayout();
    mParticipantName = (TextView) findViewById(R.id.participant_name);
    freeViews.add(new ParticipantView(remote1Render, mParticipantName));
    mMessageHistory = (TextView) findViewById(R.id.message_history);
    mMessageHistory.setMovementMethod(new ScrollingMovementMethod());
    mMessage = (EditText) findViewById(R.id.message);
    mSendButton = (Button) findViewById(R.id.send_button);
    mSendButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            String text = mMessage.getText().toString();
            if (!"".equals(text)) {
                for (Participant participant : room.getParticipants()) {
                    participant.sendMessage(text);
                }
                addMessageHistory(mLoginView.getText().toString(), text);
                mMessage.setText("");
            }
        }
    });
}
Also used : Message(com.flashphoner.fpwcsapi.room.Message) PercentFrameLayout(com.flashphoner.fpwcsapi.layout.PercentFrameLayout) RoomOptions(com.flashphoner.fpwcsapi.room.RoomOptions) InputMethodManager(android.view.inputmethod.InputMethodManager) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) RoomManagerEvent(com.flashphoner.fpwcsapi.room.RoomManagerEvent) Iterator(java.util.Iterator) Room(com.flashphoner.fpwcsapi.room.Room) SeekBar(android.widget.SeekBar) SharedPreferences(android.content.SharedPreferences) Connection(com.flashphoner.fpwcsapi.bean.Connection) Data(com.flashphoner.fpwcsapi.bean.Data) View(android.view.View) TextView(android.widget.TextView) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod) Participant(com.flashphoner.fpwcsapi.room.Participant) OnClickListener(android.view.View.OnClickListener) RoomManagerOptions(com.flashphoner.fpwcsapi.room.RoomManagerOptions) RoomEvent(com.flashphoner.fpwcsapi.room.RoomEvent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompoundButton(android.widget.CompoundButton)

Example 5 with SurfaceViewRenderer

use of org.webrtc.SurfaceViewRenderer in project wcs-android-sdk-samples by flashphoner.

the class ConferenceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conference);
    /**
     * Initialization of the API.
     */
    Flashphoner.init(this);
    mParticipantVolume = (SeekBar) findViewById(R.id.participant_volume);
    mParticipantVolume.setMax(Flashphoner.getMaxVolume());
    mParticipantVolume.setProgress(Flashphoner.getVolume());
    mParticipantVolume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            Flashphoner.setVolume(i);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    mWcsUrlView = (EditText) findViewById(R.id.wcs_url);
    SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
    mWcsUrlView.setText(sharedPref.getString("wcs_url", getString(R.string.wcs_url)));
    mLoginView = (EditText) findViewById(R.id.login);
    mLoginView.setText(sharedPref.getString("login", ""));
    mConnectStatus = (TextView) findViewById(R.id.connect_status);
    mConnectButton = (Button) findViewById(R.id.connect_button);
    mRecord = (CheckBox) findViewById(R.id.record);
    /**
     * Connection to server will be established when Connect button is clicked.
     */
    mConnectButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mConnectButton.getTag() == null || Integer.valueOf(R.string.action_connect).equals(mConnectButton.getTag())) {
                /**
                 * The connection options are set.
                 * WCS server URL and user name are passed when RoomManagerOptions object is created.
                 */
                RoomManagerOptions roomManagerOptions = new RoomManagerOptions(mWcsUrlView.getText().toString(), mLoginView.getText().toString());
                /**
                 * RoomManager object is created with method createRoomManager().
                 * Connection session is created when RoomManager object is created.
                 */
                roomManager = Flashphoner.createRoomManager(roomManagerOptions);
                /**
                 * Callback functions for connection status events are added to make appropriate changes in controls of the interface when connection is established and closed.
                 */
                roomManager.on(new RoomManagerEvent() {

                    @Override
                    public void onConnected(final Connection connection) {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mConnectButton.setText(R.string.action_disconnect);
                                mConnectButton.setTag(R.string.action_disconnect);
                                mConnectButton.setEnabled(true);
                                mConnectStatus.setText(connection.getStatus());
                                mJoinButton.setEnabled(true);
                            }
                        });
                    }

                    @Override
                    public void onDisconnection(final Connection connection) {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mConnectButton.setText(R.string.action_connect);
                                mConnectButton.setTag(R.string.action_connect);
                                mConnectButton.setEnabled(true);
                                mJoinButton.setText(R.string.action_join);
                                mJoinButton.setTag(R.string.action_join);
                                mJoinButton.setEnabled(false);
                                mPublishStatus.setText("");
                                mPublishButton.setText(R.string.action_publish);
                                mPublishButton.setTag(R.string.action_publish);
                                mPublishButton.setEnabled(false);
                                mMuteAudio.setEnabled(false);
                                mMuteAudio.setChecked(false);
                                mMuteVideo.setEnabled(false);
                                mMuteVideo.setChecked(false);
                                stream = null;
                                mConnectStatus.setText(connection.getStatus());
                                Iterator<Map.Entry<String, ParticipantView>> i = busyViews.entrySet().iterator();
                                while (i.hasNext()) {
                                    Map.Entry<String, ParticipantView> e = i.next();
                                    e.getValue().login.setText("NONE");
                                    e.getValue().surfaceViewRenderer.release();
                                    i.remove();
                                    freeViews.add(e.getValue());
                                }
                                mSendButton.setEnabled(false);
                            }
                        });
                    }
                });
                mConnectButton.setEnabled(false);
                SharedPreferences sharedPref = ConferenceActivity.this.getPreferences(Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString("wcs_url", mWcsUrlView.getText().toString());
                editor.putString("login", mLoginView.getText().toString());
                editor.apply();
            } else {
                mConnectButton.setEnabled(false);
                /**
                 * Connection to WCS server is closed with method RoomManager.disconnect().
                 */
                roomManager.disconnect();
            }
            View currentFocus = getCurrentFocus();
            if (currentFocus != null) {
                InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    mJoinRoomView = (EditText) findViewById(R.id.join_room);
    mJoinRoomView.setText(sharedPref.getString("join_room", ""));
    mJoinStatus = (TextView) findViewById(R.id.join_status);
    mJoinButton = (Button) findViewById(R.id.join_button);
    /**
     * The participant will join to conference room when Join button is clicked.
     */
    mJoinButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            mJoinButton.setEnabled(false);
            if (mJoinButton.getTag() == null || Integer.valueOf(R.string.action_join).equals(mJoinButton.getTag())) {
                /**
                 * Room name is set with method RoomOptions.setName().
                 */
                RoomOptions roomOptions = new RoomOptions();
                roomOptions.setName(mJoinRoomView.getText().toString());
                /**
                 * The participant joins a conference room with method RoomManager.join().
                 * RoomOptions object is passed to the method.
                 * Room object is created and returned by the method.
                 */
                room = roomManager.join(roomOptions);
                /**
                 * Callback functions for events occurring in conference room are added.
                 * If the event is related to actions performed by one of the other participants, Participant object with data of that participant is passed to the corresponding function.
                 */
                room.on(new RoomEvent() {

                    @Override
                    public void onState(final Room room) {
                        /**
                         * After joining, Room object with data of the room is received.
                         * Method Room.getParticipants() is used to check the number of already connected participants.
                         * The method returns collection of Participant objects.
                         * The collection size is determined, and, if the maximum allowed number (in this case, three) has already been reached, the user leaves the room with method Room.leave().
                         */
                        if (room.getParticipants().size() >= 3) {
                            room.leave(null);
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    mJoinStatus.setText("Room is full");
                                    mJoinButton.setEnabled(true);
                                }
                            });
                            return;
                        }
                        final StringBuffer chatState = new StringBuffer("participants: ");
                        /**
                         * Iterating through the collection of the other participants returned by method Room.getParticipants().
                         * There is corresponding Participant object for each participant.
                         */
                        for (final Participant participant : room.getParticipants()) {
                            /**
                             * A player view is assigned to each of the other participants in the room.
                             */
                            final ParticipantView participantView = freeViews.poll();
                            if (participantView != null) {
                                chatState.append(participant.getName()).append(",");
                                busyViews.put(participant.getName(), participantView);
                                /**
                                 * Playback of the stream being published by the other participant is started with method Participant.play().
                                 * SurfaceViewRenderer to be used to display the video stream is passed when the method is called.
                                 */
                                participant.play(participantView.surfaceViewRenderer);
                                runOnUiThread(new Runnable() {

                                    @Override
                                    public void run() {
                                        participantView.login.setText(participant.getName());
                                    }
                                });
                            }
                        }
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mJoinButton.setText(R.string.action_leave);
                                mJoinButton.setTag(R.string.action_leave);
                                mJoinButton.setEnabled(true);
                                mJoinStatus.setText("");
                                mPublishButton.setEnabled(true);
                                mSendButton.setEnabled(true);
                                if (room.getParticipants().size() == 0) {
                                    addMessageHistory("chat", "room is empty");
                                } else {
                                    addMessageHistory("chat", chatState.substring(0, chatState.length() - 1));
                                }
                            }
                        });
                    }

                    @Override
                    public void onJoined(final Participant participant) {
                        /**
                         * When a new participant joins the room, a player view is assigned to that participant.
                         */
                        final ParticipantView participantView = freeViews.poll();
                        if (participantView != null) {
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    participantView.login.setText(participant.getName());
                                    addMessageHistory(participant.getName(), "joined");
                                }
                            });
                            busyViews.put(participant.getName(), participantView);
                        }
                    }

                    @Override
                    public void onLeft(final Participant participant) {
                        /**
                         * When one of the other participants leaves the room, player view assigned to that participant is freed.
                         */
                        final ParticipantView participantView = busyViews.remove(participant.getName());
                        if (participantView != null) {
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    participantView.login.setText("NONE");
                                    addMessageHistory(participant.getName(), "left");
                                    participantView.surfaceViewRenderer.release();
                                }
                            });
                            freeViews.add(participantView);
                        }
                    }

                    @Override
                    public void onPublished(final Participant participant) {
                        /**
                         * When one of the other participants starts publishing, playback of the stream published by that participant is started.
                         */
                        final ParticipantView participantView = busyViews.get(participant.getName());
                        if (participantView != null) {
                            participant.play(participantView.surfaceViewRenderer);
                        }
                    }

                    @Override
                    public void onFailed(Room room, final String info) {
                        room.leave(null);
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mJoinStatus.setText(info);
                                mJoinButton.setEnabled(true);
                            }
                        });
                    }

                    @Override
                    public void onMessage(final Message message) {
                        /**
                         * When one of the participants sends a text message, the received message is added to the messages log.
                         */
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                addMessageHistory(message.getFrom(), message.getText());
                            }
                        });
                    }
                });
                SharedPreferences sharedPref = ConferenceActivity.this.getPreferences(Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sharedPref.edit();
                editor.putString("join_room", mJoinRoomView.getText().toString());
                editor.apply();
            } else {
                final Runnable action = new Runnable() {

                    @Override
                    public void run() {
                        mJoinButton.setEnabled(true);
                        mJoinButton.setText(R.string.action_join);
                        mJoinButton.setTag(R.string.action_join);
                        mPublishButton.setEnabled(false);
                        mSendButton.setEnabled(false);
                        /**
                         * The player views assigned to the other participants are freed.
                         */
                        Iterator<Map.Entry<String, ParticipantView>> i = busyViews.entrySet().iterator();
                        while (i.hasNext()) {
                            Map.Entry<String, ParticipantView> e = i.next();
                            e.getValue().login.setText("NONE");
                            e.getValue().surfaceViewRenderer.release();
                            i.remove();
                            freeViews.add(e.getValue());
                        }
                    }
                };
                /**
                 * The participant leaves the conference room with method Room.leave().
                 */
                room.leave(new RestAppCommunicator.Handler() {

                    @Override
                    public void onAccepted(Data data) {
                        runOnUiThread(action);
                    }

                    @Override
                    public void onRejected(Data data) {
                        runOnUiThread(action);
                    }
                });
            }
            View currentFocus = getCurrentFocus();
            if (currentFocus != null) {
                InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    mPublishStatus = (TextView) findViewById(R.id.publish_status);
    mPublishButton = (Button) findViewById(R.id.publish_button);
    /**
     * The participant starts publishing video stream when Publish button is clicked.
     */
    mPublishButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mPublishButton.getTag() == null || Integer.valueOf(R.string.action_publish).equals(mPublishButton.getTag())) {
                ActivityCompat.requestPermissions(ConferenceActivity.this, new String[] { Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA }, PUBLISH_REQUEST_CODE);
            } else {
                mPublishButton.setEnabled(false);
                /**
                 * Stream is unpublished with method Room.unpublish().
                 */
                room.unpublish();
            }
            View currentFocus = getCurrentFocus();
            if (currentFocus != null) {
                InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(currentFocus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
            }
        }
    });
    /**
     * MuteAudio switch is used to mute/unmute audio of the published stream.
     * Audio is muted with method Stream.muteAudio() and unmuted with method Stream.unmuteAudio().
     */
    mMuteAudio = (Switch) findViewById(R.id.mute_audio);
    mMuteAudio.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                stream.muteAudio();
            } else {
                stream.unmuteAudio();
            }
        }
    });
    /**
     * MuteVideo switch is used to mute/unmute video of the published stream.
     * Video is muted with method Stream.muteVideo() and unmuted with method Stream.unmuteVideo().
     */
    mMuteVideo = (Switch) findViewById(R.id.mute_video);
    mMuteVideo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                stream.muteVideo();
            } else {
                stream.unmuteVideo();
            }
        }
    });
    localRenderer = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
    PercentFrameLayout localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layout);
    localRenderLayout.setPosition(0, 0, 100, 100);
    localRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    localRenderer.setMirror(true);
    localRenderer.requestLayout();
    SurfaceViewRenderer remote1Render = (SurfaceViewRenderer) findViewById(R.id.remote1_video_view);
    PercentFrameLayout remote1RenderLayout = (PercentFrameLayout) findViewById(R.id.remove1_video_layout);
    remote1RenderLayout.setPosition(0, 0, 100, 100);
    remote1Render.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    remote1Render.setMirror(false);
    remote1Render.requestLayout();
    SurfaceViewRenderer remote2Render = (SurfaceViewRenderer) findViewById(R.id.remote2_video_view);
    PercentFrameLayout remote2RenderLayout = (PercentFrameLayout) findViewById(R.id.remote2_video_layout);
    remote2RenderLayout.setPosition(0, 0, 100, 100);
    remote2Render.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
    remote2Render.setMirror(false);
    remote2Render.requestLayout();
    mParticipant1Name = (TextView) findViewById(R.id.participant1_name);
    freeViews.add(new ParticipantView(remote1Render, mParticipant1Name));
    mParticipant2Name = (TextView) findViewById(R.id.participant2_name);
    freeViews.add(new ParticipantView(remote2Render, mParticipant2Name));
    mMessageHistory = (TextView) findViewById(R.id.message_history);
    mMessageHistory.setMovementMethod(new ScrollingMovementMethod());
    mMessage = (EditText) findViewById(R.id.message);
    mSendButton = (Button) findViewById(R.id.send_button);
    mSendButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            String text = mMessage.getText().toString();
            if (!"".equals(text)) {
                for (Participant participant : room.getParticipants()) {
                    participant.sendMessage(text);
                }
                addMessageHistory(mLoginView.getText().toString(), text);
                mMessage.setText("");
            }
        }
    });
}
Also used : Message(com.flashphoner.fpwcsapi.room.Message) PercentFrameLayout(com.flashphoner.fpwcsapi.layout.PercentFrameLayout) RoomOptions(com.flashphoner.fpwcsapi.room.RoomOptions) InputMethodManager(android.view.inputmethod.InputMethodManager) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) RoomManagerEvent(com.flashphoner.fpwcsapi.room.RoomManagerEvent) Iterator(java.util.Iterator) Room(com.flashphoner.fpwcsapi.room.Room) SeekBar(android.widget.SeekBar) SharedPreferences(android.content.SharedPreferences) Connection(com.flashphoner.fpwcsapi.bean.Connection) Data(com.flashphoner.fpwcsapi.bean.Data) View(android.view.View) TextView(android.widget.TextView) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod) Participant(com.flashphoner.fpwcsapi.room.Participant) OnClickListener(android.view.View.OnClickListener) RoomManagerOptions(com.flashphoner.fpwcsapi.room.RoomManagerOptions) RoomEvent(com.flashphoner.fpwcsapi.room.RoomEvent) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) CompoundButton(android.widget.CompoundButton)

Aggregations

SurfaceViewRenderer (org.webrtc.SurfaceViewRenderer)9 View (android.view.View)3 TextView (android.widget.TextView)3 SharedPreferences (android.content.SharedPreferences)2 ScrollingMovementMethod (android.text.method.ScrollingMovementMethod)2 OnClickListener (android.view.View.OnClickListener)2 InputMethodManager (android.view.inputmethod.InputMethodManager)2 CompoundButton (android.widget.CompoundButton)2 RelativeLayout (android.widget.RelativeLayout)2 SeekBar (android.widget.SeekBar)2 Connection (com.flashphoner.fpwcsapi.bean.Connection)2 Data (com.flashphoner.fpwcsapi.bean.Data)2 PercentFrameLayout (com.flashphoner.fpwcsapi.layout.PercentFrameLayout)2 Message (com.flashphoner.fpwcsapi.room.Message)2 Participant (com.flashphoner.fpwcsapi.room.Participant)2 Room (com.flashphoner.fpwcsapi.room.Room)2 RoomEvent (com.flashphoner.fpwcsapi.room.RoomEvent)2 RoomManagerEvent (com.flashphoner.fpwcsapi.room.RoomManagerEvent)2 RoomManagerOptions (com.flashphoner.fpwcsapi.room.RoomManagerOptions)2 RoomOptions (com.flashphoner.fpwcsapi.room.RoomOptions)2