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.dvn.vindecoder.ui.seller.AddVehicalAndPayment.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // setContentView( R.layout.activity_add_vehical_and_payment);
    drawChildLayout();/* www  .  j av  a  2s .c o  m*/
    setTitle("Add Vehical");
    Bundle bundle = getIntent().getExtras();

    //  addNewVehicalFragment=new AddNewVehicalFragment(this);

    boolean scanFlag = false;
    if (bundle != null) {
        scanFlag = bundle.getBoolean("boolean");
    }
    if (savedInstanceState == null) {
        // Do first time initialization -- add initial fragment.
        addNewVehicalFragment = AddNewVehicalFragment.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);
    /*   toolbar = (Toolbar) findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);*/

}

From source file:us.shandian.blacklight.ui.main.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (hasSmartBar()) {
        getWindow().setUiOptions(ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW);
    }//from ww w  .j a  v  a2s .  c om

    Utility.initDarkMode(this);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Tint
    Utility.enableTint(this);

    // Detect if the user chose to use right-handed mode
    boolean rightHanded = Settings.getInstance(this).getBoolean(Settings.RIGHT_HANDED, false);
    mDrawerGravity = rightHanded ? Gravity.RIGHT : Gravity.LEFT;

    // Set gravity
    View nav = findViewById(R.id.nav);
    DrawerLayout.LayoutParams p = (DrawerLayout.LayoutParams) nav.getLayoutParams();
    p.gravity = mDrawerGravity;
    nav.setLayoutParams(p);

    // Initialize naviagtion drawer
    mDrawer = (DrawerLayout) findViewById(R.id.drawer);
    mToggle = new ActionBarDrawerToggle(this, mDrawer, R.drawable.ic_drawer_l, 0, 0) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().show();
            invalidateOptionsMenu();
            if (mLastChoice == null) {
                mLastChoice = (TextView) mMy.getChildAt(0);
                mLastChoice.getPaint().setFakeBoldText(true);
                mLastChoice.invalidate();
            }

            ((HomeTimeLineFragment) mFragments[0]).hideFAB();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            invalidateOptionsMenu();

            if (mNext == 0) {
                ((HomeTimeLineFragment) mFragments[0]).showFAB();
            }
        }
    };
    mDrawer.setDrawerListener(mToggle);

    if (mDrawerGravity == Gravity.LEFT) {
        mDrawer.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);
    }

    mMy = (ListView) findViewById(R.id.list_my);
    mAtMe = (ListView) findViewById(R.id.list_at_me);
    mOther = (ListView) findViewById(R.id.list_other);
    mMy.setVerticalScrollBarEnabled(false);
    mMy.setChoiceMode(ListView.CHOICE_MODE_NONE);
    mAtMe.setVerticalScrollBarEnabled(false);
    mAtMe.setChoiceMode(ListView.CHOICE_MODE_NONE);
    mOther.setVerticalScrollBarEnabled(false);
    mOther.setChoiceMode(ListView.CHOICE_MODE_NONE);

    mMy.setOnItemClickListener(this);
    mAtMe.setOnItemClickListener(this);
    mOther.setOnItemClickListener(this);

    // My account
    mName = (TextView) findViewById(R.id.my_name);
    mName.getPaint().setFakeBoldText(true);
    mAvatar = (ImageView) findViewById(R.id.my_avatar);
    mLoginCache = new LoginApiCache(this);
    mUserCache = new UserApiCache(this);
    initList();
    new InitializerTask().execute();
    new GroupsTask().execute();

    findViewById(R.id.my_account).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mUser != null) {
                Intent i = new Intent();
                i.setAction(Intent.ACTION_MAIN);
                i.setClass(MainActivity.this, UserTimeLineActivity.class);
                i.putExtra("user", mUser);
                startActivity(i);
            }
        }

    });

    // Initialize ActionBar Style
    getActionBar().setHomeButtonEnabled(true);

    // Ignore first spinner event
    mIgnore = true;

    // Fragments
    mFragments[0] = new HomeTimeLineFragment();
    mFragments[1] = new CommentTimeLineFragment();
    mFragments[2] = new FavListFragment();
    mFragments[3] = new DirectMessageUserFragment();
    mFragments[4] = new MentionsTimeLineFragment();
    mFragments[5] = new CommentMentionsTimeLineFragment();
    mFragments[6] = new SearchFragment();
    mManager = getFragmentManager();

    FragmentTransaction ft = mManager.beginTransaction();
    for (Fragment f : mFragments) {
        ft.add(R.id.container, f);
        ft.hide(f);
    }
    ft.commit();
    switchTo(0);
}

From source file:itcr.gitsnes.MainActivity.java

/**
 * OnCreate methods do that things://from w  ww  .j a  v  a  2  s .  c o  m
 *      - Inflate Login formulary frame (hide action bar)
 *      - Init Accelerometer intent (onShake)
 *      - Create login method (auth with FB)
 *      - Handle exceptions of previously methods
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* -- Shows action bar and inflate main Listview from JSON (see BackendHandler) --- */
    getActionBar().hide();
    setContentView(R.layout.activity_main);
    FragmentManager fm = getFragmentManager();
    FragmentTransaction transaction = fm.beginTransaction();

    /* Add transaction and login FB intent to mainActivity*/
    Login login = new Login();
    transaction.add(R.id.placeholder, login).commit();

    /* Init shake sensor and create event to get random game from DB (Backend on app-engine)*/
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    mShakeDetector = new ShakeDetector();
    mShakeDetector.setOnShakeListener(new ShakeDetector.OnShakeListener() {

        @Override
        public void onShake(int count) {
            /* Inflate random-game detail */
            Toast.makeText(getApplicationContext(), "Buscando juego aleatorio!!", Toast.LENGTH_SHORT).show();
            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setRandomgame("random");
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

        }
    });

    mSensorManager.registerListener(mShakeDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);

    /*Initialize FB API helper methods and listen callback from fb_loginbutton*/

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);
    authButton = (LoginButton) findViewById(R.id.authButton);
    authButton.setOnErrorListener(new LoginButton.OnErrorListener() {
        @Override
        public void onError(FacebookException error) {
            Log.i(TAG, "Error " + error.getMessage());
        }
    });

    /*Obtaining data from successfully FB API callback using GraphUser*/
    authButton.setReadPermissions(Arrays.asList("email"));
    authButton.setSessionStatusCallback(new Session.StatusCallback() {

        @Override
        public void call(Session session, SessionState state, Exception exception) {
            Log.i(TAG, "Accesssss Token");
            if (session.isOpened()) {
                Log.i(TAG, "Access Token" + session.getAccessToken());
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            Log.i(TAG, "User ID " + user.getId());
                            Log.i(TAG, "Email " + user.asMap().get("email"));
                            /* Inflate main-Listview from JSON (see BackendHandler) and saving current user*/
                            back_stage();
                            getActionBar().show();
                            KS.setCurrent_user(user.asMap().get("email").toString());
                            Toast.makeText(getApplicationContext(), "Welcome!! " + KS.getCurrent_user(),
                                    Toast.LENGTH_SHORT).show();
                            new BackendHandler().sendUser(KS.getCurrent_user(),
                                    user.asMap().get("email").toString());
                            //lblEmail.setText(user.asMap().get("email").toString());
                        }
                    }
                });
            } else
                Log.i(TAG, "Nopes Token");
        }
    });
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //  setContentView(R.layout.activity_get_all_vehical_details);
    // Watch for button clicks.
    /* Button button = (Button)findViewById(R.id.new_fragment);
            //from   w w w  . j a va  2 s .  c  o  m
     button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        addFragmentToStack();
    }
     });*/
    setTitle("Vehical details");
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        v_id = bundle.getString("v_id");
        CommonURL.V_ID = v_id;
        CommonURL.PK_ID = v_id;
        if (bundle.containsKey("user_type")) {
            CommonURL.USER_TYPE = bundle.getInt("user_type");
            ;
        }
    }
    drawChildLayout();
    if (savedInstanceState == null) {
        // Do first time initialization -- add initial fragment.
        newFragment = GetNewVehicalFragment.newInstance(GetAllVehicalSellerDetails.this);
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.fragment1, newFragment).commit();
    } else {
        mStackLevel = savedInstanceState.getInt("level");
    }

    fab = (FloatingActionButton) findViewById(R.id.fab);
    TextView fab_txt = (TextView) findViewById(R.id.textView12);
    if (CommonURL.USER_TYPE == 1) {

        fab.setVisibility(View.GONE);
        fab_txt.setVisibility(View.GONE);
    }
    fab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            //handleCameraForPickingPhoto();
            openDialog();
        }
    });

}

From source file:org.eyeseetea.malariacare.DashboardActivity.java

/**
 * Init the fragments//  w  ww  .java2  s  .  com
 */
private void setFragmentTransaction(int layout, ListFragment fragment) {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.add(layout, fragment);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
}

From source file:com.android.purenexussettings.TinkerActivity.java

private void displayView(int position) {
    // before anything else - check to see if position matches intent-launching "frags" - for example
    // if ( navMenuTitles[position].equals("TARGETNAME") ) { position = 0; do something}
    boolean mKeepStack = checkPosition(position);

    // update the main content by replacing fragments
    Fragment frags = null;//from  www  .ja  v a  2s  .  c  o  m
    String fragname = navMenuFrags[position];
    try {
        frags = (Fragment) Class.forName(mPackageName + "." + fragname).newInstance();
    } catch (Exception e) {
        frags = null;
    }
    if (frags != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        try {
            FragmentTransaction fragtrans = fragmentManager.beginTransaction();
            if (mFromClick || mMenu || mBackPress) {
                fragtrans.setCustomAnimations(R.anim.fadein, R.anim.fadeout, R.anim.fadein, R.anim.fadeout);
            }
            fragtrans.add(R.id.frame_container, frags);
            // The backstack should be cleared if not coming from a fragment flagged as stack keeping or from a backpress
            // After clearing the only entry should be About/main
            if (!mKeepStack && !mBackPress) {
                fragmentStack.clear();
                fragmentStack.push(navMenuFrags[0]);
            }
            // add fragment name to custom stack for backstack tracking
            // only do it if not a backpress, flagged as stack keeping, or dup of last entry
            if (!mBackPress && !mKeepStack
                    && !(fragmentStack.size() >= 1 && fragmentStack.peek().equals(navMenuFrags[position]))) {
                fragmentStack.push(navMenuFrags[position]);
            }

            fragtrans.commit();
        } catch (Exception e) {
        }

        // update selected item and title, then close the drawer
        if (mFromClick || mBackPress) {
            mFromClick = false;
            mBackPress = false;
        } else {
            setTitle(navMenuTitles[position]);
            if (mMenu) {
                mMenu = false;
                mItemPosition = position;
            } else {
                mDrawerLayout.closeDrawer(mNavView);
            }
        }
        invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
    } else {
        // error in creating fragment
        Log.e("TinkerActivity", "Error in creating fragment");
    }
}

From source file:com.dvn.vindecoder.ui.user.GetAllVehicalDetails.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //  setContentView(R.layout.activity_get_all_vehical_details);
    // Watch for button clicks.
    /* Button button = (Button)findViewById(R.id.new_fragment);
            /* w  w w.j  a  v a  2  s.  co  m*/
     button.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        addFragmentToStack();
    }
     });*/
    setTitle("Vehical details");
    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        CommonURL.V_ID = bundle.getString("v_id");
        v_id = bundle.getString("v_id");
        CommonURL.PK_ID = v_id;
        if (bundle.containsKey("user_type")) {
            CommonURL.USER_TYPE = bundle.getInt("user_type");
            ;
        }
    }
    drawChildLayout();
    if (savedInstanceState == null) {
        // Do first time initialization -- add initial fragment.
        /*  newFragment = GetNewVehicalFragment.newInstance(GetAllVehicalDetails.this);
         FragmentTransaction ft = getFragmentManager().beginTransaction();
         ft.add(R.id.fragment1, newFragment).commit();*/

        addVehicalFragment_new_for_user = AddVehicalFragment_New_For_User
                .newInstance(GetAllVehicalDetails.this);
        FragmentTransaction ft = getFragmentManager().beginTransaction();
        ft.add(R.id.fragment1, addVehicalFragment_new_for_user).commit();
    } else {
        mStackLevel = savedInstanceState.getInt("level");
    }

    fab = (FloatingActionButton) findViewById(R.id.fab);
    TextView fab_txt = (TextView) findViewById(R.id.textView12);
    if (CommonURL.USER_TYPE == 1) {

        fab.setVisibility(View.GONE);
        fab_txt.setVisibility(View.GONE);
    }
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //handleCameraForPickingPhoto();
            openDialog();
        }
    });

}

From source file:org.restcomm.android.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, R.style.SimpleAlertStyle).create();

    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.ACTION_OUTGOING_CALL)) {
        btnAnswer.setVisibility(View.INVISIBLE);
        btnAnswerAudio.setVisibility(View.INVISIBLE);
    } else {/*from   w w  w .j a va 2s .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();
}

From source file:de.lespace.apprtc.ConnectActivity.java

@Override
public void onIncomingCall(final String from) {

    // Notify UI that registration has completed, so the progress indicator can be hidden.
    /*//  w  ww .  j a  v a 2 s. co  m
            //Send Broadcast message to Service
            Intent registrationComplete = new Intent(QuickstartPreferences.INCOMING_CALL);
            LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
            
            startActivity(intent);*/

    /* Intent intent = new Intent(this, ConnectActivity.class);
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
     Intent intent = new Intent(this,CallActivity.class);
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);*/
    // r.stop();
    //startActivity(intent);

    roomConnectionParameters.to = from;
    roomConnectionParameters.initiator = false;
    DialogFragment newFragment = new RTCConnection.CallDialogFragment();

    Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

    if (alert == null) {
        // alert is null, using backup
        alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

        // I can't see this ever being null (as always have a default notification)
        // but just incase
        if (alert == null) {
            // alert backup is null, using 2nd backup
            alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALL);
        }
    }
    r = RingtoneManager.getRingtone(getApplicationContext(), alert);
    //  r.play();

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.add(newFragment, "loading");
    transaction.commitAllowingStateLoss();

}

From source file:com.hit.jj.mapshow.RoutingActivity.java

/**
 * Updates the UI after a successful rest response has been received.
 */// w  w w.jav a 2  s  .co m
void updateUI() {
    dialog.dismiss();
    img_cancel.setVisibility(View.VISIBLE);
    FragmentManager fm = getFragmentManager();
    if (fm.findFragmentByTag("Nav Drawer") == null) {
        FragmentTransaction ft = fm.beginTransaction();
        RoutingListFragment frag = new RoutingListFragment(this);
        ft.add(frag, "Nav Drawer");
        ft.commit();
    } else {
        FragmentTransaction ft = fm.beginTransaction();
        ft.remove(fm.findFragmentByTag("Nav Drawer"));
        RoutingListFragment frag = new RoutingListFragment(this);
        ft.add(frag, "Nav Drawer");
        ft.commit();
    }
    //img_showDirections.setVisibility(View.VISIBLE);

}