Example usage for android.app FragmentTransaction add

List of usage examples for android.app FragmentTransaction add

Introduction

In this page you can find the example usage for android.app FragmentTransaction add.

Prototype

public abstract FragmentTransaction add(@IdRes int containerViewId, Fragment fragment);

Source Link

Document

Calls #add(int,Fragment,String) with a null tag.

Usage

From source file:com.google.samples.apps.iosched.ui.BaseActivity.java

/**
 * Adds a {@link com.google.samples.apps.iosched.framework.PresenterFragmentImpl} to the
 * Activity if required, and sets it up with the {@code model}, {@code queries},
 * {@code actions} and the {@link com.google.samples.apps.iosched.framework.UpdatableView}
 * corresponding to the {@code updatableViewResId}.
 *
 * @return the {@link com.google.samples.apps.iosched.framework.PresenterFragmentImpl},
 *//*from   w  w w  .  ja  v a2  s.c o m*/
public PresenterFragmentImpl addPresenterFragment(int updatableViewResId, Model model, QueryEnum[] queries,
        UserActionEnum[] actions) {
    FragmentManager fragmentManager = getFragmentManager();

    //Check if the presenter fragment is already present (ie if the activity is recreated due
    // to orientation change).
    PresenterFragmentImpl presenter = (PresenterFragmentImpl) fragmentManager.findFragmentByTag(PRESENTER_TAG);
    if (presenter == null) {
        //Create, set up and add the presenter.
        presenter = new PresenterFragmentImpl();
        setUpPresenter(presenter, fragmentManager, updatableViewResId, model, queries, actions);
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(presenter, PRESENTER_TAG);
        fragmentTransaction.commit();
    } else {
        //Set up the presenter.
        setUpPresenter(presenter, fragmentManager, updatableViewResId, model, queries, actions);
    }
    return presenter;
}

From source file:com.android.calendar.AllInOneActivity.java

@Override
public void handleEvent(EventInfo event) {
    long displayTime = -1;
    if (event.eventType == EventType.GO_TO) {
        if ((event.extraLong & CalendarController.EXTRA_GOTO_BACK_TO_PREVIOUS) != 0) {
            mBackToPreviousView = true;/*from  www  .  j a  v a2s  .c  om*/
        } else if (event.viewType != mController.getPreviousViewType() && event.viewType != ViewType.EDIT) {
            // Clear the flag is change to a different view type
            mBackToPreviousView = false;
        }

        setMainPane(null, R.id.main_pane, event.viewType, event.startTime.toMillis(false), false);
        if (mSearchView != null) {
            mSearchView.clearFocus();
        }
        if (mShowCalendarControls) {
            int animationSize = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? mControlsAnimateWidth
                    : mControlsAnimateHeight;
            boolean noControlsView = event.viewType == ViewType.MONTH || event.viewType == ViewType.AGENDA;
            if (mControlsMenu != null) {
                mControlsMenu.setVisible(!noControlsView);
                mControlsMenu.setEnabled(!noControlsView);
            }
            if (noControlsView || mHideControls) {
                // hide minimonth and calendar frag
                mShowSideViews = false;
                if (!mHideControls) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset", 0,
                            animationSize);
                    slideAnimation.addListener(mSlideAnimationDoneListener);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                } else {
                    mMiniMonth.setVisibility(View.GONE);
                    mCalendarsList.setVisibility(View.GONE);
                    mMiniMonthContainer.setVisibility(View.GONE);
                }
            } else {
                // show minimonth and calendar frag
                mShowSideViews = true;
                mMiniMonth.setVisibility(View.VISIBLE);
                mCalendarsList.setVisibility(View.VISIBLE);
                mMiniMonthContainer.setVisibility(View.VISIBLE);
                if (!mHideControls && (mController.getPreviousViewType() == ViewType.MONTH
                        || mController.getPreviousViewType() == ViewType.AGENDA)) {
                    final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                            animationSize, 0);
                    slideAnimation.setDuration(mCalendarControlsAnimationTime);
                    ObjectAnimator.setFrameDelay(0);
                    slideAnimation.start();
                }
            }
        }
        displayTime = event.selectedTime != null ? event.selectedTime.toMillis(true)
                : event.startTime.toMillis(true);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(displayTime);
        }
    } else if (event.eventType == EventType.VIEW_EVENT) {

        // If in Agenda view and "show_event_details_with_agenda" is "true",
        // do not create the event info fragment here, it will be created by the Agenda
        // fragment

        if (mCurrentView == ViewType.AGENDA && mShowEventDetailsWithAgenda) {
            if (event.startTime != null && event.endTime != null) {
                // Event is all day , adjust the goto time to local time
                if (event.isAllDay()) {
                    Utils.convertAlldayUtcToLocal(event.startTime, event.startTime.toMillis(false), mTimeZone);
                    Utils.convertAlldayUtcToLocal(event.endTime, event.endTime.toMillis(false), mTimeZone);
                }
                mController.sendEvent(this, EventType.GO_TO, event.startTime, event.endTime, event.selectedTime,
                        event.id, ViewType.AGENDA, CalendarController.EXTRA_GOTO_TIME, null, null);
            } else if (event.selectedTime != null) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, event.id,
                        ViewType.AGENDA);
            }
        } else {
            // TODO Fix the temp hack below: && mCurrentView !=
            // ViewType.AGENDA
            if (event.selectedTime != null && mCurrentView != ViewType.AGENDA) {
                mController.sendEvent(this, EventType.GO_TO, event.selectedTime, event.selectedTime, -1,
                        ViewType.CURRENT);
            }
            int response = event.getResponse();
            if ((mCurrentView == ViewType.AGENDA && mShowEventInfoFullScreenAgenda)
                    || ((mCurrentView == ViewType.DAY || (mCurrentView == ViewType.WEEK)
                            || mCurrentView == ViewType.MONTH) && mShowEventInfoFullScreen)) {
                // start event info as activity
                Intent intent = new Intent(Intent.ACTION_VIEW);
                Uri eventUri = ContentUris.withAppendedId(Events.CONTENT_URI, event.id);
                intent.setData(eventUri);
                intent.setClass(this, EventInfoActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                intent.putExtra(EXTRA_EVENT_BEGIN_TIME, event.startTime.toMillis(false));
                intent.putExtra(EXTRA_EVENT_END_TIME, event.endTime.toMillis(false));
                intent.putExtra(ATTENDEE_STATUS, response);
                startActivity(intent);
            } else {
                // start event info as a dialog
                EventInfoFragment fragment = new EventInfoFragment(this, event.id,
                        event.startTime.toMillis(false), event.endTime.toMillis(false), response, true,
                        EventInfoFragment.DIALOG_WINDOW_STYLE, null /* No reminders to explicitly pass in. */);
                fragment.setDialogParams(event.x, event.y, mActionBar.getHeight());
                FragmentManager fm = getFragmentManager();
                FragmentTransaction ft = fm.beginTransaction();
                // if we have an old popup replace it
                Fragment fOld = fm.findFragmentByTag(EVENT_INFO_FRAGMENT_TAG);
                if (fOld != null && fOld.isAdded()) {
                    ft.remove(fOld);
                }
                ft.add(fragment, EVENT_INFO_FRAGMENT_TAG);
                ft.commit();
            }
        }
        displayTime = event.startTime.toMillis(true);
    } else if (event.eventType == EventType.UPDATE_TITLE) {
        setTitleInActionBar(event);
        if (!mIsTabletConfig) {
            refreshActionbarTitle(mController.getTime());
        }
    }
    updateSecondaryTitleFields(displayTime);
}

From source file:com.android.deskclock.AlarmClockFragment.java

private void showLabelDialog(final Alarm alarm) {
    final FragmentTransaction ft = getFragmentManager().beginTransaction();
    final Fragment prev = getFragmentManager().findFragmentByTag("label_dialog");
    if (prev != null) {
        ft.remove(prev);/*from   w w w .  j  av  a2  s .  c o m*/
    }
    /// M:If the LabelEditDialog Existed,do not create again
    //ft.addToBackStack(null);
    /// M:Don't need use the method ft.commit(), because it may cause IllegalStateException
    final LabelDialogFragment newFragment = LabelDialogFragment.newInstance(alarm, alarm.label, getTag());
    ft.add(newFragment, "label_dialog");
    ft.commitAllowingStateLoss();
    getFragmentManager().executePendingTransactions();
}

From source file:com.android.mms.ui.MessageUtils.java

public static void showErrorDialog(Activity activity, int titleId, int messageId, int mediaTypeIdForTitle,
        int mediaTypeIdForMsg) {
    /** M://from  www.ja va  2  s .  c  om
    the original code is replaced by the following code.
    the original code has a bug, JE may happen.
    the case is when the activity is destoried by some reason(ex:change language),
    when dismiss the dialog, it may be throw a JE. see 298363.
    */
    ErrorDialog errDialog = ErrorDialog.newInstance(titleId, messageId, mediaTypeIdForTitle, mediaTypeIdForMsg);
    try {
        errDialog.show(activity.getFragmentManager(), "errDialog");
    } catch (IllegalStateException e) {
        try {
            MmsLog.d(TAG, "showErrorDialog catch IllegalStateException." + e);
            FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
            transaction.add(errDialog, "errDialog");
            transaction.commitAllowingStateLoss();
        } catch (Exception e2) {
            MmsLog.e(TAG, "showErrorDialog commitAllowingStateLoss catch Exception." + e2);
        }
        return;
    }
}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public boolean showUserList() {

    userListShown = !userListShown;//from  www.  ja  v  a 2  s  .co m

    if (userListShown) {
        // Show in call fragment
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.call_list_fragment_container, callListFragment);
        ft.commit();
    } else {

        // Show in call fragment
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.remove(callListFragment);
        ft.commit();
    }
    return userListShown;
}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public void showChatMessages(String roomName, String fromId, User user) {

    if (!chatFragment.isAdded()) {
        // Show in call fragment
        android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.chat_fragment_container, chatFragment);
        ft.commit();/*w  w w  . j  a v a2 s .  c  o  m*/
    }

}

From source file:org.appspot.apprtc.CallActivity.java

public void showChatMessages(User user) {

    if (!chatFragment.isAdded()) {
        // Show in call fragment
        android.support.v4.app.FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.add(R.id.chat_fragment_container, chatFragment);
        ft.commit();// ww w .  ja v a  2s  .c om
    }

    chatFragment.setAvatarUrl(mService.getAvatarUrl());
    Bundle args = chatFragment.getArguments();
    args.putSerializable(WebsocketService.EXTRA_USER, user);
    chatFragment.setArguments(args);
    chatFragment.setUser(user);
    chatFragment.viewChat(user.Id);

}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public void onAnswerCall() {
    AnswerIncomingCall(mPeerId);//w  w w.  ja v  a2s. c o  m
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    if (!mVideoCallEnabled) {
        ft.add(R.id.call_list_fragment_container, callListFragment);
    }
    ft.replace(R.id.call_fragment_container, callFragment);
    ft.commit();

    if (!mVideoCallEnabled) {
        remoteUserImage.setVisibility(View.VISIBLE);
    }
}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public void onRemoteDescription(final SerializableSessionDescription sdp, final String token, String id,
        String conferenceId, final String fromId, final String roomName, String type) {
    final long delta = System.currentTimeMillis() - callStartedTimeMs;
    runOnUiThread(new Runnable() {
        @Override//  w w  w .ja  v  a 2s.  c  om
        public void run() {
            if (peerConnectionClient == null) {
                Log.e(TAG, "Received remote SDP for non-initilized peer connection.");
                return;
            }
            //logAndToast("Received remote " + sdp.type + ", delay=" + delta + "ms");
            SessionDescription sd = new SessionDescription(sdp.type, sdp.description);
            peerConnectionClient.setRemoteDescription(sd, token);
            if (!initiator) {
                //logAndToast("Creating ANSWER...");
                // Create answer. Answer SDP will be sent to offering client in
                // PeerConnectionEvents.onLocalDescription event.
                peerConnectionClient.createAnswer();
            } else if (sd.type == SessionDescription.Type.OFFER) {
                // tried to call
                SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
                fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
                String time = fmt.format(new Date());
                String missedCall = String.format(getString(R.string.missed_call), mPeerName);

                mService.onChatMessage(missedCall, time, "", mOwnId, mPeerId, roomName);
                sendBye(fromId, "busy");
                onCallHangUp();
            } else {

                // Show in call fragment
                FragmentTransaction ft = getFragmentManager().beginTransaction();
                if (!mVideoCallEnabled) {
                    ft.add(R.id.call_list_fragment_container, callListFragment);
                }
                ft.replace(R.id.call_fragment_container, callFragment);
                ft.commit();

                if (!mVideoCallEnabled) {
                    remoteUserImage.setVisibility(View.VISIBLE);
                }
            }
        }
    });
}

From source file:org.appspot.apprtc.CallActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Thread.setDefaultUncaughtExceptionHandler(new UnhandledExceptionHandler(this));

    // Set window styles for fullscreen-window size. Needs to be done before
    // adding content.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON | LayoutParams.FLAG_DISMISS_KEYGUARD
            | LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_TURN_SCREEN_ON);
    getWindow().getDecorView()//  ww  w  .  j  ava2  s .co  m
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    setContentView(R.layout.activity_call);

    mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(WebsocketService.ACTION_BYE);
    mIntentFilter.addAction(WebsocketService.ACTION_USER_ENTERED);
    mIntentFilter.addAction(WebsocketService.ACTION_USER_LEFT);
    mIntentFilter.addAction(WebsocketService.ACTION_SCREENSHARE);
    mIntentFilter.addAction(CustomPhoneStateListener.ACTION_HOLD_ON);
    mIntentFilter.addAction(CustomPhoneStateListener.ACTION_HOLD_OFF);
    mIntentFilter.addAction(WebsocketService.ACTION_CHAT_MESSAGE);
    mIntentFilter.addAction(WebsocketService.ACTION_FILE_MESSAGE);
    registerReceiver(mReceiver, mIntentFilter);

    // Get setting keys.
    PreferenceManager.setDefaultValues(this, R.xml.webrtc_preferences, false);
    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);

    keyprefVideoCallEnabled = getString(R.string.pref_videocall_key);
    keyprefScreencapture = getString(R.string.pref_screencapture_key);
    keyprefCamera2 = getString(R.string.pref_camera2_key);
    keyprefResolution = getString(R.string.pref_resolution_key);
    keyprefFps = getString(R.string.pref_fps_key);
    keyprefCaptureQualitySlider = getString(R.string.pref_capturequalityslider_key);
    keyprefVideoBitrateType = getString(R.string.pref_maxvideobitrate_key);
    keyprefVideoBitrateValue = getString(R.string.pref_maxvideobitratevalue_key);
    keyprefVideoCodec = getString(R.string.pref_videocodec_key);
    keyprefHwCodecAcceleration = getString(R.string.pref_hwcodec_key);
    keyprefCaptureToTexture = getString(R.string.pref_capturetotexture_key);
    keyprefFlexfec = getString(R.string.pref_flexfec_key);
    keyprefAudioBitrateType = getString(R.string.pref_startaudiobitrate_key);
    keyprefAudioBitrateValue = getString(R.string.pref_startaudiobitratevalue_key);
    keyprefAudioCodec = getString(R.string.pref_audiocodec_key);
    keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key);
    keyprefAecDump = getString(R.string.pref_aecdump_key);
    keyprefOpenSLES = getString(R.string.pref_opensles_key);
    keyprefDisableBuiltInAec = getString(R.string.pref_disable_built_in_aec_key);
    keyprefDisableBuiltInAgc = getString(R.string.pref_disable_built_in_agc_key);
    keyprefDisableBuiltInNs = getString(R.string.pref_disable_built_in_ns_key);
    keyprefEnableLevelControl = getString(R.string.pref_enable_level_control_key);
    keyprefDisplayHud = getString(R.string.pref_displayhud_key);
    keyprefTracing = getString(R.string.pref_tracing_key);
    keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
    keyprefEnableDataChannel = getString(R.string.pref_enable_datachannel_key);
    keyprefOrdered = getString(R.string.pref_ordered_key);
    keyprefMaxRetransmitTimeMs = getString(R.string.pref_max_retransmit_time_ms_key);
    keyprefMaxRetransmits = getString(R.string.pref_max_retransmits_key);
    keyprefDataProtocol = getString(R.string.pref_data_protocol_key);
    keyprefNegotiated = getString(R.string.pref_negotiated_key);
    keyprefDataId = getString(R.string.pref_data_id_key);

    readPrefs();

    final Intent intent = getIntent();

    if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_ICE_CANDIDATE)) {
        finish(); // don't start the activity on this intent
    } else if (intent.getAction().equals(WebsocketService.ACTION_REMOTE_DESCRIPTION)) {
        SerializableSessionDescription sdp = (SerializableSessionDescription) intent
                .getSerializableExtra(WebsocketService.EXTRA_REMOTE_DESCRIPTION);
        mVideoCallEnabled = sdp.description.contains("m=video");
    }

    iceConnected = false;
    signalingParameters = new SignalingParameters(WebsocketService.getIceServers(), initiator, "", "", "", null,
            null);
    scalingType = ScalingType.SCALE_ASPECT_FILL;

    // Create UI controls.

    localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
    screenshareRender = (SurfaceViewRenderer) findViewById(R.id.screenshare_video_view);
    remoteRenderScreen = (SurfaceViewRenderer) findViewById(R.id.remote_video_view);

    remoteRenderScreen2 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view2);
    remoteRenderScreen3 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view3);
    remoteRenderScreen4 = (SurfaceViewRenderer) findViewById(R.id.remote_video_view4);
    remoteVideoLabel = (TextView) findViewById(R.id.remote_video_label);
    remoteVideoLabel2 = (TextView) findViewById(R.id.remote_video_label2);
    remoteVideoLabel3 = (TextView) findViewById(R.id.remote_video_label3);
    remoteVideoLabel4 = (TextView) findViewById(R.id.remote_video_label4);
    remoteUserImage = (ImageView) findViewById(R.id.remote_user_image1);
    remoteUserImage2 = (ImageView) findViewById(R.id.remote_user_image2);
    remoteUserImage3 = (ImageView) findViewById(R.id.remote_user_image3);
    remoteUserImage4 = (ImageView) findViewById(R.id.remote_user_image4);
    remoteUserHoldStatus = (ImageView) findViewById(R.id.remote_user_hold_status);
    remoteUserHoldStatus2 = (ImageView) findViewById(R.id.remote_user_hold_status2);
    remoteUserHoldStatus3 = (ImageView) findViewById(R.id.remote_user_hold_status3);
    remoteUserHoldStatus4 = (ImageView) findViewById(R.id.remote_user_hold_status4);
    localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layout);
    screenshareRenderLayout = (PercentFrameLayout) findViewById(R.id.screenshare_video_layout);
    remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_layout);
    remoteRenderLayout2 = (PercentFrameLayout) findViewById(R.id.remote_video_layout2);
    remoteRenderLayout3 = (PercentFrameLayout) findViewById(R.id.remote_video_layout3);
    remoteRenderLayout4 = (PercentFrameLayout) findViewById(R.id.remote_video_layout4);
    initiateCallFragment = new InitiateCallFragment();
    callListFragment = new CallListFragment();
    callFragment = new CallFragment();
    hudFragment = new HudFragment();
    chatFragment = new ChatFragment();

    screenshareRemoteView = new RemoteConnectionViews("screenshare", screenshareRenderLayout, screenshareRender,
            null, null, null);

    remoteViewsInUseList.add(new RemoteConnectionViews("remote 1", remoteRenderLayout, remoteRenderScreen,
            remoteUserImage, remoteVideoLabel, remoteUserHoldStatus)); // first one is always in use
    remoteViewsList.add(new RemoteConnectionViews("remote 2", remoteRenderLayout2, remoteRenderScreen2,
            remoteUserImage2, remoteVideoLabel2, remoteUserHoldStatus2));
    remoteViewsList.add(new RemoteConnectionViews("remote 3", remoteRenderLayout3, remoteRenderScreen3,
            remoteUserImage3, remoteVideoLabel3, remoteUserHoldStatus3));
    remoteViewsList.add(new RemoteConnectionViews("remote 4", remoteRenderLayout4, remoteRenderScreen4,
            remoteUserImage4, remoteVideoLabel4, remoteUserHoldStatus4));

    // Show/hide call control fragment on view click.
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleCallControlFragmentVisibility();
        }
    };

    View.OnClickListener screenshareListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            maximizeScreenshare = !maximizeScreenshare;
            updateVideoView();
        }
    };

    localRender.setOnClickListener(listener);
    screenshareRender.setOnClickListener(screenshareListener);
    remoteRenderScreen.setOnClickListener(listener);
    remoteRenderScreen2.setOnClickListener(listener);
    remoteRenderScreen3.setOnClickListener(listener);
    remoteRenderScreen4.setOnClickListener(listener);
    remoteRenderers.add(remoteRenderScreen);

    // Create video renderers.
    if (rootEglBase == null) {
        rootEglBase = EglBase.create();
    }
    localRender.init(rootEglBase.getEglBaseContext(), null);
    screenshareRender.init(rootEglBase.getEglBaseContext(), null);
    String saveRemoteVideoToFile = intent.getStringExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE);

    // When saveRemoteVideoToFile is set we save the video from the remote to a file.
    if (saveRemoteVideoToFile != null) {
        int videoOutWidth = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_WIDTH, 0);
        int videoOutHeight = intent.getIntExtra(EXTRA_SAVE_REMOTE_VIDEO_TO_FILE_HEIGHT, 0);
        try {
            videoFileRenderer = new VideoFileRenderer(saveRemoteVideoToFile, videoOutWidth, videoOutHeight,
                    rootEglBase.getEglBaseContext());
            remoteRenderers.add(videoFileRenderer);
        } catch (IOException e) {
            throw new RuntimeException("Failed to open video file for output: " + saveRemoteVideoToFile, e);
        }
    }
    remoteRenderScreen.init(rootEglBase.getEglBaseContext(), null);
    remoteRenderScreen2.init(rootEglBase.getEglBaseContext(), null);
    remoteRenderScreen3.init(rootEglBase.getEglBaseContext(), null);
    remoteRenderScreen4.init(rootEglBase.getEglBaseContext(), null);

    localRender.setZOrderMediaOverlay(true);
    localRender.setEnableHardwareScaler(true /* enabled */);

    screenshareRender.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    screenshareRenderLayout.setVisibility(View.GONE);
    screenshareRender.setVisibility(View.GONE);

    if (intent.getAction().equals(ACTION_RESUME_CALL)) {
        iceConnected = true;
    }

    updateVideoView();

    // If capturing format is not specified for screencapture, use screen resolution.
    if (screencaptureEnabled && mVideoWidth == 0 && mVideoHeight == 0) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        WindowManager windowManager = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            windowManager.getDefaultDisplay().getRealMetrics(displayMetrics);
        }
        mVideoWidth = displayMetrics.widthPixels;
        mVideoHeight = displayMetrics.heightPixels;
    }
    DataChannelParameters dataChannelParameters = null;
    if (mDataChannelEnabled) {
        dataChannelParameters = new DataChannelParameters(mOrdered, mMaxRetrMs, mMaxRetr, mProtocol,
                mNegotiated, mId);
    }
    peerConnectionParameters = new PeerConnectionParameters(mVideoCallEnabled, false, false, mVideoWidth,
            mVideoHeight, mCameraFps, mVideoStartBitrate, mVideoCodec, mHwCodecEnabled, mFlexfecEnabled,
            mAudioStartBitrate, mAudioCodec, mNoAudioProcessing, mAecDump, mUseOpenSLES, mDisableBuiltInAEC,
            mDisableBuiltInAGC, mDisableBuiltInNS, mEnableLevelControl, dataChannelParameters);
    commandLineRun = intent.getBooleanExtra(EXTRA_CMDLINE, false);
    runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0);

    Log.d(TAG, "VIDEO_FILE: '" + intent.getStringExtra(EXTRA_VIDEO_FILE_AS_CAMERA) + "'");

    // Create connection client. Use DirectRTCClient if room name is an IP otherwise use the
    // standard WebSocketRTCClient.
    //if (loopback || !DirectRTCClient.IP_PATTERN.matcher(roomId).matches()) {
    //   appRtcClient = new WebSocketRTCClient(this);
    // } else {
    //   Log.i(TAG, "Using DirectRTCClient because room name looks like an IP.");
    //   appRtcClient = new DirectRTCClient(this);
    // }
    // Create connection parameters.
    //roomConnectionParameters = new RoomConnectionParameters(roomUri.toString(), roomId, loopback);

    // Create CPU monitor
    //cpuMonitor = new CpuMonitor(this);
    //hudFragment.setCpuMonitor(cpuMonitor);
    Bundle extras = intent.getExtras();
    extras.putBoolean(CallActivity.EXTRA_VIDEO_CALL, mVideoCallEnabled);

    // Send intent arguments to fragments.
    chatFragment.setArguments(getIntent().getExtras());
    initiateCallFragment.setArguments(extras);
    callFragment.setArguments(extras);
    callListFragment.setArguments(extras);
    hudFragment.setArguments(intent.getExtras());
    // Activate call and HUD fragments and start the call.
    remoteUserImage.setVisibility(View.INVISIBLE);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    if (intent.getAction().equals(ACTION_RESUME_CALL)) {
        ft.add(R.id.call_fragment_container, callFragment);
    } else {
        ft.add(R.id.call_fragment_container, initiateCallFragment);
    }
    ft.add(R.id.hud_fragment_container, hudFragment);
    ft.commit();

    // For command line execution run connection for <runTimeMs> and exit.
    if (commandLineRun && runTimeMs > 0) {
        (new Handler()).postDelayed(new Runnable() {
            @Override
            public void run() {
                disconnect();
            }
        }, runTimeMs);
    }

    if (!intent.getAction().equals(ACTION_RESUME_CALL)) {
        peerConnectionClient = PeerConnectionClient.getInstance();

        PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
        options.disableNetworkMonitor = true;
        peerConnectionClient.setPeerConnectionFactoryOptions(options);

        if (mForceTurn) {
            peerConnectionParameters.forceTurn = true;
        }

        peerConnectionClient.createPeerConnectionFactory(CallActivity.this, peerConnectionParameters,
                CallActivity.this);

        peerConnectionClient.setDataChannelCallback(this);

        ThumbnailsCacheManager.ThumbnailsCacheManagerInit(this);
        handleIntent(intent);

        if (screencaptureEnabled) {
            /*MediaProjectionManager mediaProjectionManager =
                (MediaProjectionManager) getApplication().getSystemService(
                    Context.MEDIA_PROJECTION_SERVICE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
              startActivityForResult(
                  mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
            }*/
        } else {
            startCall();
        }
    } else {
        mPeerId = intent.getStringExtra(EXTRA_PEER_ID);
        iceConnected = true;
        if (peerConnectionClient != null) {
            peerConnectionClient.updateActivity(this, this);
            peerConnectionClient.updateLocalRenderer(localRender);
            peerConnectionClient.updateRemoteRenderers(remoteRenderers);
        }
    }

    AddRunningIntent();
}