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:la.marsave.fullscreentest.MainActivity.java

/**
 * This method is used to toggle between the two fragment states by
 * calling the appropriate animations between them. The entry and exit
 * animations of the text fragment are specified in R.animator resource
 * files. The entry and exit animations of the image fragment are
 * specified in the slideBack and slideForward methods below. The reason
 * for separating the animation logic in this way is because the translucent
 * dark hover view must fade in at the same time as the image fragment
 * animates into the background, which would be difficult to time
 * properly given that the setCustomAnimations method can only modify the
 * two fragments in the transaction.//from w ww . j  a v a2 s.c  om
 */
private void switchFragments() {
    if (mIsAnimating) {
        return;
    }
    mIsAnimating = true;
    if (mDidSlideOut) {
        mDidSlideOut = false;
        getFragmentManager().popBackStack();
    } else {
        mDidSlideOut = true;

        Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_fragment_in, 0, 0,
                        R.animator.slide_fragment_out);
                transaction.add(R.id.move_to_back_container, mTextFragment);
                transaction.addToBackStack(null);
                transaction.commit();
            }
        };
        slideBack(listener);
    }
}

From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java

private void showDialogFragment(final FragmentManager fragmentManager, final DialogFragment dialogFragment,
        final boolean addToBackStack, final String tag) {
    final FragmentTransaction transaction = fragmentManager.beginTransaction();
    transaction.add(dialogFragment, tag);
    if (addToBackStack) {
        transaction.addToBackStack(tag);
    }/*  w w w  .  j  a  va2s. co m*/
    transaction.commitAllowingStateLoss();
}

From source file:gl.iglou.scenegraph.MatModeInterface.java

@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    snapshotToast = Toast.makeText(this, "", Toast.LENGTH_LONG);

    LayoutInflater inflater = getLayoutInflater();

    arrow_l = getResources().getDrawable(R.drawable.scene_arrow_l);
    arrow_r = getResources().getDrawable(R.drawable.scene_arrow_r);
    arrowListener = new ArrowClickListener();

    currentSceneId = getIntent().getIntExtra("SCENE_ID", 0);
    SharedData.TYPE current_mode = SharedData.GetMode();

    setContentView(R.layout.scene_activity);

    mainLayout = (RelativeLayout) findViewById(R.id.content_frame);
    buttonGroup = findViewById(R.id.scene_button_frame);
    snapshotContainer = (FrameLayout) findViewById(R.id.scene_snapshot_container);
    //drawerStartId = getIdAssignedByR(this,"outliner_container");
    drawerStartId = R.id.outliner_container;
    drawerEndId = getIdAssignedByR(this, "gl_configurator_container");

    GLView = (GL2JNIView) findViewById(R.id.content_view);

    arrowL = (ImageView) findViewById(R.id.arrow_l);
    arrowR = (ImageView) findViewById(R.id.arrow_r);
    arrowL.setOnClickListener(arrowListener);
    arrowR.setOnClickListener(arrowListener);

    targetButton = (ImageButton) findViewById(R.id.scene_target);
    meshButton = (ImageButton) findViewById(R.id.scene_mesh_mode);
    AABBButton = (ImageButton) findViewById(R.id.scene_AABB_mode);

    selection = (TextView) findViewById(R.id.scene_selection);
    UpdateSelection();/* w w  w . j  a v  a 2s  . c om*/

    mDrawerLayout = (SceneDrawer) findViewById(R.id.drawer_layout);

    mDrawerLayout.setDrawerListener(new MyDrawerListener());
    mDrawerLayout.SetDrawerId(drawerStartId, drawerEndId);

    mDrawerLayout.setScrimColor(0x00ffffff);

    decorView = getWindow().getDecorView();

    outlinerFrag = new SceneOutlinerFragment();
    GLConfFrag = new SceneGLConfiguratorFragment();

    matModeView = inflater.inflate(R.layout.scene_mat_mode, null);
    mainLayout.addView(matModeView);
    if (SharedData.TYPE.MAT == current_mode) {
        //matModeView.setVisibility(View.VISIBLE);
        EnableMatMode(true);
    } else {
        EnableMatMode(false);
        //matModeView.setVisibility(View.INVISIBLE);
    }

    snapShot = inflater.inflate(R.layout.scene_snapshot_frame, null);
    snapshotContainer.addView(snapShot);
    photo = (ImageView) snapShot.findViewById(R.id.snapshot);
    snapshotIndicator = (ProgressBar) snapShot.findViewById(R.id.scene_snapshot_progress_bar);
    snapshotContainer.setVisibility(View.INVISIBLE);
    snapshotIndicator.setVisibility(View.INVISIBLE);

    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    ft.add(R.id.outliner_container, outlinerFrag);
    ft.commit();

    FragmentTransaction ft0 = fm.beginTransaction();
    ft0.add(R.id.gl_configurator_container, GLConfFrag);
    ft0.commit();
    Log.v(TAG, "Activity ON_CREATE CALL");

}

From source file:com.battlelancer.seriesguide.ui.SeriesGuidePreferences.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(SeriesGuidePreferences.THEME);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_singlepane);
    setupActionBar();// ww w . java 2s  .  c o m

    if (savedInstanceState == null) {
        Fragment f = new SettingsHeadersFragment();
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.content_frame, f);
        ft.commit();
    }
}

From source file:de.lespace.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(//w  w  w.j a v a2s.co m
            LayoutParams.FLAG_FULLSCREEN | LayoutParams.FLAG_KEEP_SCREEN_ON | LayoutParams.FLAG_DISMISS_KEYGUARD
                    | LayoutParams.FLAG_SHOW_WHEN_LOCKED | LayoutParams.FLAG_TURN_SCREEN_ON);

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

    setContentView(R.layout.activity_call);

    iceConnected = false;

    scalingType = ScalingType.SCALE_ASPECT_FILL;

    callFragment = new CallFragment();
    hudFragment = new HudFragment();

    // Create UI controls.
    localRender = (SurfaceViewRenderer) findViewById(R.id.local_video_view);
    remoteRender = (SurfaceViewRenderer) findViewById(R.id.remote_video_view);
    screenRender = (SurfaceViewRenderer) findViewById(R.id.remote_screen_view);

    localRenderLayout = (PercentFrameLayout) findViewById(R.id.local_video_layout);
    remoteRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_video_layout);

    screenRenderLayout = (PercentFrameLayout) findViewById(R.id.remote_screen_layout);

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

    localRender.setOnClickListener(listener);
    remoteRender.setOnClickListener(listener);
    screenRender.setOnClickListener(listener); //screensharing

    // Create video renderers.
    rootEglBase = EglBase.create();
    localRender.init(rootEglBase.getEglBaseContext(), null);
    remoteRender.init(rootEglBase.getEglBaseContext(), null);
    screenRender.init(rootEglBase.getEglBaseContext(), null);
    localRender.setZOrderMediaOverlay(true);
    screenRender.setZOrderMediaOverlay(true);
    updateVideoView();

    setResult(RESULT_CANCELED);

    if (!broadcastIsRegistered) {
        registerReceiver(broadcast_reciever, new IntentFilter("finish_CallActivity"));
        registerReceiver(broadcast_reciever, new IntentFilter("finish_screensharing"));
        broadcastIsRegistered = true;
    }

    callFragment = new CallFragment();
    hudFragment = new HudFragment();
    // Send intent arguments to fragments.
    callFragment.setArguments(getIntent().getExtras());
    hudFragment.setArguments(getIntent().getExtras());

    // Activate call and HUD fragments and start the call.
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.add(R.id.call_fragment_container, callFragment);
    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(false);
            }
        }, runTimeMs);
    }

    // Create and audio manager that will take care of audio routing,
    // audio modes, audio device enumeration etc.
    audioManager = AppRTCAudioManager.create(this, new Runnable() {
        // This method will be called each time the audio state (number and
        // type of devices) has been changed.
        @Override
        public void run() {
            onAudioManagerChangedState();
        }
    });

    // Store existing audio settings and change audio mode to
    // MODE_IN_COMMUNICATION for best possible VoIP performance.
    Log.d(TAG, "Initializing the audio manager...");
    audioManager.init();

    peerConnectionClient = PeerConnectionClient.getInstance(true);
    peerConnectionClient.createPeerConnectionFactory(CallActivity.this, peerConnectionParameters, this);

    peerConnectionClient.createPeerConnection(rootEglBase.getEglBaseContext(), localRender, remoteRender,
            screenRender, roomConnectionParameters.initiator);

    logAndToast("Creating OFFER...");
    // Create offer. Offer SDP will be sent to answering client in
    // PeerConnectionEvents.onLocalDescription event.
    peerConnectionClient.createOffer();
}

From source file:com.dvn.vindecoder.ui.seller.AddVehicalAndPaymentWithoutScan.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView( R.layout.activity_add_vehical_and_payment);
    drawChildLayout();//w w  w  .  java 2 s  .co  m
    setTitle("Add Vehical");
    Bundle bundle = getIntent().getExtras();

    /*  addNewVehicalFragment=new AddNewVehicalFragmentWithouScan(this);*/
    boolean scanFlag = false;
    if (bundle != null) {
        scanFlag = bundle.getBoolean("boolean");
        vin_number = bundle.getString("vin");
    }
    if (savedInstanceState == null) {
        // Do first time initialization -- add initial fragment.

        //new fragment
        addVehicalFragment_new = AddVehicalFragment_New.newInstance(this, scanFlag, vin_number);
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.add(R.id.fragment1, addVehicalFragment_new).commit();

        //old fragment

        /*  addNewVehicalFragment = AddNewVehicalFragmentWithouScan.newInstance(this,scanFlag);
           FragmentTransaction ft = getFragmentManager().beginTransaction();
           ft.add(R.id.fragment1, addNewVehicalFragment).commit();*/
    } else {
        mStackLevel = savedInstanceState.getInt("level");
    }
    collapsing_toolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);

}

From source file:com.telestax.restcomm_olympus.CallActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Set window styles for fullscreen-window size. Needs to be done before
    // adding content.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
    setContentView(R.layout.activity_call);

    // Initialize UI
    btnHangup = (ImageButton) findViewById(R.id.button_hangup);
    btnHangup.setOnClickListener(this);
    btnAnswer = (ImageButton) findViewById(R.id.button_answer);
    btnAnswer.setOnClickListener(this);
    btnAnswerAudio = (ImageButton) findViewById(R.id.button_answer_audio);
    btnAnswerAudio.setOnClickListener(this);
    btnMuteAudio = (ImageButton) findViewById(R.id.button_mute_audio);
    btnMuteAudio.setOnClickListener(this);
    btnMuteVideo = (ImageButton) findViewById(R.id.button_mute_video);
    btnMuteVideo.setOnClickListener(this);
    btnKeypad = (ImageButton) findViewById(R.id.button_keypad);
    btnKeypad.setOnClickListener(this);
    lblCall = (TextView) findViewById(R.id.label_call);
    lblStatus = (TextView) findViewById(R.id.label_status);
    lblTimer = (TextView) findViewById(R.id.label_timer);

    alertDialog = new AlertDialog.Builder(CallActivity.this).create();

    device = RCClient.listDevices().get(0);

    PreferenceManager.setDefaultValues(this, "preferences.xml", MODE_PRIVATE, R.xml.preferences, false);
    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Get Intent parameters.
    final Intent intent = getIntent();
    if (intent.getAction().equals(RCDevice.OUTGOING_CALL)) {
        btnAnswer.setVisibility(View.INVISIBLE);
        btnAnswerAudio.setVisibility(View.INVISIBLE);
    } else {//from   w w w. jav  a2 s.co  m
        btnAnswer.setVisibility(View.VISIBLE);
        btnAnswerAudio.setVisibility(View.VISIBLE);
    }

    keypadFragment = new KeypadFragment();

    lblTimer.setVisibility(View.INVISIBLE);
    // these might need to be moved to Resume()
    btnMuteAudio.setVisibility(View.INVISIBLE);
    btnMuteVideo.setVisibility(View.INVISIBLE);
    btnKeypad.setVisibility(View.INVISIBLE);

    activityVisible = true;

    // open keypad
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.add(R.id.keypad_fragment_container, keypadFragment);
    ft.hide(keypadFragment);
    ft.commit();

    //handleCall(intent);
}

From source file:de.bigboot.qcircleview.cover.CoverFragment.java

@AfterViews
protected void init() {
    Preferences preferences = new Preferences(getActivity());

    FragmentManager fragMan = getChildFragmentManager();
    FragmentTransaction fragTransaction = fragMan.beginTransaction();

    Clock clock = preferences.getActiveClock();
    if (clock == null) {
        clock = Clock.STATIC_CLOCKS[0];
    }/*from w w  w  . j a  v a  2s  .  c  om*/
    Fragment fragment;
    if (clock instanceof Clock.StaticClock) {
        Clock.StaticClock staticClock = (Clock.StaticClock) clock;
        fragment = staticClock.getFragment();
    } else {
        fragment = CoverAnalogClockFragment_.builder().clock(clock).build();
    }
    fragTransaction.add(R.id.clock_layout, fragment);
    fragTransaction.commit();

    adapter = new CoverAdapter(getActivity());
    mediaSessionListener = new MediaSessionListener();
    mediaSessionManager = (MediaSessionManager) getActivity().getSystemService(Context.MEDIA_SESSION_SERVICE);
    try {
        List<MediaController> mediaControllers = mediaSessionManager
                .getActiveSessions(new ComponentName(getActivity(), NotificationService_.class));
        adapter.onActiveSessionsChanged(mediaControllers);
        mediaSessionManager.addOnActiveSessionsChangedListener(mediaSessionListener,
                new ComponentName(getActivity(), NotificationService_.class));
    } catch (SecurityException ex) {
        // No notification access
    }

    mViewPager.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            if (position == adapter.getDefaultFragmentPosition()) {
                currentNotification = null;
                menuSlide.setPanelHeight(getResources().getDimensionPixelSize(R.dimen.menu_panel_height));
            } else {
                currentNotification = adapter.getNotification(position);
                menuSlide.setPanelHeight(0);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });
    new SwipeDetector(mViewPager, true).setOnSwipeListener(new SwipeDetector.onSwipeEvent() {
        @Override
        public void SwipeEventDetected(View v, SwipeDetector.SwipeTypeEnum SwipeType) {
            if (SwipeType == SwipeDetector.SwipeTypeEnum.TOP_TO_BOTTOM && menuSlide.getPanelHeight() > 0) {
                menuSlide.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
            }
        }
    });
}

From source file:com.greatspeeches.slides.ScreenSlidePageFragment.java

public void playYutubeVideo() {
    fragmentsLayout.setVisibility(View.VISIBLE);
    videoRel.setVisibility(View.VISIBLE);
    if (mPersonObj.getVideourl().length() > 0) {
        int indexPos = mPersonObj.getVideourl().indexOf("=");
        if (indexPos > 0) {
            videoId = mPersonObj.getVideourl().substring(indexPos + 1, mPersonObj.getVideourl().length());
        }//from  w  ww .  j a va  2 s . c om

        android.app.FragmentTransaction fts = getChildFragmentManager().beginTransaction();
        YouTubePlayerFragment youTubePlayerFragment = new YouTubePlayerFragment();
        //         YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
        //         FragmentTransaction fts = myContext.getSupportFragmentManager().beginTransaction();
        fts.add(R.id.video_container, youTubePlayerFragment);
        fts.addToBackStack(null);
        fts.commit();

        myContext.getSupportFragmentManager().executePendingTransactions();

        youTubePlayerFragment.initialize(GreateSpeechesUtil.yOUTUBEdEVELOPERkEY, new OnInitializedListener() {
            @Override
            public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
                    boolean wasRestored) {
                // Play, cue or whatever you want to do with the player
                activePlayer = player;
                activePlayer.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
                activePlayer.setPlayerStateChangeListener(videoListener);
                activePlayer.setFullscreen(false);
                activePlayer.setShowFullscreenButton(false);
                if (!wasRestored) {
                    activePlayer.loadVideo(videoId, 0);
                }
            }

            @Override
            public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
                // TODO Auto-generated method stub
            }
        });
    }
}

From source file:com.grepsound.activities.MainActivity.java

/**
 * This method is used to toggle between the two fragment states by
 * calling the appropriate animations between them. The entry and exit
 * animations of the text fragment are specified in R.animator resource
 * files. The entry and exit animations of the image fragment are
 * specified in the slideBack and slideForward methods below. The reason
 * for separating the animation logic in this way is because the translucent
 * dark hover view must fade in at the same time as the image fragment
 * animates into the background, which would be difficult to time
 * properly given that the setCustomAnimations method can only modify the
 * two fragments in the transaction.//w  w w . j ava  2  s.c  o  m
 */
private void switchFragments() {
    if (mIsAnimating) {
        Log.i(TAG, "IS animating!");
        return;
    }
    mIsAnimating = true;
    if (mDidSlideOut) {
        Log.i(TAG, "Did Slide Out!");
        mDidSlideOut = false;
        getFragmentManager().popBackStack();
    } else {
        mDidSlideOut = true;

        Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                FragmentTransaction transaction = getFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.animator.slide_fragment_left, 0, 0,
                        R.animator.slide_fragment_right);
                transaction.add(R.id.move_to_back_container, mDetailsFragment);
                transaction.addToBackStack(null);
                transaction.commit();
                mDidSlideOut = false;
            }
        };
        slideBack(listener);
    }
}