List of usage examples for android.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:com.vaporwarecorp.mirror.feature.main.MirrorActivity.java
private void showMirrorView(final FragmentManager fragmentManager, final MirrorView mirrorView, final boolean addToBackStack, final String tag) { if (mirrorView.isFullscreen()) { mFullscreenContainer.setVisibility(View.VISIBLE); final FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(getContainerViewId(), (Fragment) mirrorView, tag); if (addToBackStack) { transaction.addToBackStack(tag); }/* ww w . java 2 s . c om*/ transaction.commitAllowingStateLoss(); } else { showFragment(fragmentManager, (Fragment) mirrorView, addToBackStack, tag); } }
From source file:fr.cph.chicago.activity.BusBoundActivity.java
@Override public final void onStart() { super.onStart(); FragmentManager fm = getFragmentManager(); mMapFragment = (MapFragment) fm.findFragmentById(R.id.map); GoogleMapOptions options = new GoogleMapOptions(); CameraPosition camera = new CameraPosition(NearbyFragment.CHICAGO, 7, 0, 0); options.camera(camera);// w w w . j a v a 2s. c om mMapFragment = MapFragment.newInstance(options); mMapFragment.setRetainInstance(true); fm.beginTransaction().replace(R.id.map, mMapFragment).commit(); }
From source file:itcr.gitsnes.MainActivity.java
/** * OnCreate methods do that things:/* w ww . j a v a2 s . co 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.google.samples.apps.sergio.ui.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); Toolbar toolbar = getActionBarToolbar(); toolbar.setTitle(R.string.title_search); toolbar.setNavigationIcon(R.drawable.ic_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override/*w ww .ja v a 2 s.co m*/ public void onClick(View view) { navigateUpToFromChild(SearchActivity.this, IntentCompat .makeMainActivity(new ComponentName(SearchActivity.this, BrowseSessionsActivity.class))); } }); FragmentManager fm = getFragmentManager(); mSessionsFragment = (SessionsFragment) fm.findFragmentById(R.id.fragment_container); String query = getIntent().getStringExtra(SearchManager.QUERY); query = query == null ? "" : query; mQuery = query; if (mSessionsFragment == null) { mSessionsFragment = new SessionsFragment(); Bundle args = intentToFragmentArguments( new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSearchUri(query))); mSessionsFragment.setArguments(args); fm.beginTransaction().add(R.id.fragment_container, mSessionsFragment).commit(); } if (mSearchView != null) { mSearchView.setQuery(query, false); } overridePendingTransition(0, 0); }
From source file:com.example.bhumiputra.FarmerHomeActivity.java
private void selectItem(int position) { // update the main content by replacing fragments Fragment fragment;/*from w w w . j av a 2s .co m*/ Bundle bundle; FragmentManager fragmentManager; switch (position) { case 0: fragment = new FarmerFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 1: fragment = new FarmerBuyFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 2: fragment = new FarmerHireFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 3: fragment = new FarmerSaleFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 4: AlertDialog.Builder bulder = new AlertDialog.Builder(FarmerHomeActivity.this); bulder.setTitle("Are you sure ?...."); bulder.setIcon(R.drawable.ic_launcher); bulder.setMessage("You want to Logout"); bulder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Intent intent = new Intent(FarmerHomeActivity.this, MainActivity.class); startActivity(intent); } }); bulder.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub Toast.makeText(FarmerHomeActivity.this, "Welldone", Toast.LENGTH_LONG).show(); dialog.dismiss(); } }); AlertDialog d = bulder.create(); d.show(); break; default: break; } /* fragment = new FarmerFragmet(); bundle = new Bundle(); // bundle.putInt(PlanetFragment.ARG_PLANET_NUMBER, position); fragment.setArguments(bundle); fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mFarmerTitles[position]); mDrawerLayout.closeDrawer(mDrawerList); break; case 5: */ }
From source file:org.catnut.ui.MainActivity.java
/** * ?fragment/*from ww w . j a va 2s. c o m*/ * * @param fragment * @param tag null?? */ private void pendingFragment(Fragment fragment, String tag) { FragmentManager fragmentManager = getFragmentManager(); Fragment tmp = fragmentManager.findFragmentByTag(tag); if (tmp == null || !tmp.isVisible()) { fragmentManager.beginTransaction() .setCustomAnimations(R.animator.fragment_slide_left_enter, R.animator.fragment_slide_left_exit, R.animator.fragment_slide_right_enter, R.animator.fragment_slide_right_exit) .replace(R.id.fragment_container, fragment, tag).addToBackStack(null).commit(); mScrollSettleHandler.post(new Runnable() { @Override public void run() { invalidateOptionsMenu(); } }); } }
From source file:hu.zelena.guide.MainActivity.java
public void selectDrawerItem(MenuItem menuItem) { Fragment fragment = null;//from w w w . j a v a 2 s. c o m Bundle bundle = new Bundle(); switch (menuItem.getItemId()) { case R.id.alcatel_frag: fragment = new PhonesFragment(); brand = "Alcatel"; analyticINFO = brand; break; case R.id.apple_frag: fragment = new PhonesFragment(); brand = "Apple"; analyticINFO = brand; break; case R.id.balckberry_frag: fragment = new PhonesFragment(); brand = "BlackBerry"; analyticINFO = brand; break; case R.id.cat_frag: fragment = new PhonesFragment(); brand = "CAT"; analyticINFO = brand; break; case R.id.honor_frag: fragment = new PhonesFragment(); brand = "Honor"; analyticINFO = brand; break; case R.id.HTC_frag: fragment = new PhonesFragment(); brand = "HTC"; analyticINFO = brand; break; case R.id.huawei_frag: fragment = new PhonesFragment(); brand = "Huawei"; analyticINFO = brand; break; case R.id.lenovo_frag: fragment = new PhonesFragment(); brand = "Lenovo"; analyticINFO = brand; break; case R.id.lg_frag: fragment = new PhonesFragment(); brand = "LG"; analyticINFO = brand; break; case R.id.samsung_frag: fragment = new PhonesFragment(); brand = "Samsung"; analyticINFO = brand; break; case R.id.sony_frag: fragment = new PhonesFragment(); brand = "Sony"; analyticINFO = brand; break; case R.id.watch_frag: fragment = new WatchFragment(); analyticINFO = "Watch"; break; case R.id.tablet_frag: fragment = new TabletFragment(); analyticINFO = "Tablet"; break; case R.id.postpaid_frag: fragment = new PostPaidFragment(); analyticINFO = "PostPaid"; break; case R.id.prepaid_frag: fragment = new PrePaidFragment(); analyticINFO = "PrePaid"; break; case R.id.net_frag: fragment = new InternetFragment(); analyticINFO = "Net"; break; case R.id.magicbook_frag: fragment = new MagicbookFragment(); analyticINFO = "MagicBook"; break; case R.id.others_frag: fragment = new OthersFragment(); analyticINFO = "Others"; break; default: break; } if (fragment != null) { mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction(analyticINFO + " drawer select").build()); firstFrag = false; bundle.putString("brand", brand); fragment.setArguments(bundle); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); } else { Intent i = new Intent(this, ErrorActivity.class); i.putExtra("error", "Nem sikerlt a FRAGMENT betltse. [Null object]"); startActivity(i); Log.e("MainActivity", "Error in creating fragment"); } // Kivlasztott kijellse menuItem.setChecked(true); // Cm bellts setTitle(menuItem.getTitle()); // Drawer bezrsa mDrawer.closeDrawers(); }
From source file:de.sourcestream.movieDB.controller.MovieList.java
/** * Callback method to be invoked when an item in this AdapterView has been clicked. * * @param parent The AdapterView where the click happened. * @param view The view within the AdapterView that was clicked (this will be a view provided by the adapter) * @param position The position of the view in the adapter. * @param id The row id of the item that was clicked. *///w w w.j av a2 s. c o m @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { activity.setLastVisitedSimMovie(0); activity.resetMovieDetailsBundle(); activity.setRestoreMovieDetailsAdapterState(true); activity.setRestoreMovieDetailsState(false); activity.setOrientationChanged(false); activity.resetCastDetailsBundle(); if (movieDetails != null && lastVisitedMovie == moviesList.get(position).getId() && movieDetails.getTimeOut() == 0) { // Old movie details retrieve info and re-init component else crash movieDetails.onSaveInstanceState(new Bundle()); Bundle bundle = new Bundle(); bundle.putInt("id", moviesList.get(position).getId()); Bundle save = movieDetails.getSave(); movieDetails = new MovieDetails(); movieDetails.setTimeOut(0); movieDetails.setSave(save); movieDetails.setArguments(bundle); } else movieDetails = new MovieDetails(); lastVisitedMovie = moviesList.get(position).getId(); movieDetails.setTitle(moviesList.get(position).getTitle()); FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); Bundle bundle = new Bundle(); bundle.putInt("id", moviesList.get(position).getId()); movieDetails.setArguments(bundle); transaction.replace(R.id.frame_container, movieDetails); // add the current transaction to the back stack: transaction.addToBackStack("movieList"); transaction.commit(); fragmentActive = true; activity.getMovieSlideTab().showInstantToolbar(); /* ValueAnimator anim = ValueAnimator.ofFloat(0, 1); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float slideOffset = (Float) valueAnimator.getAnimatedValue(); activity.getmDrawerToggle().onDrawerSlide(activity.getmDrawerLayout(), slideOffset); } }); anim.setInterpolator(new DecelerateInterpolator()); // You can change this duration to more closely match that of the default animation. anim.setDuration(700); anim.start();*/ }
From source file:com.blue.leaves.util.task.SugarTask.java
private void unregisterHookToContext(@NonNull android.support.v4.app.Fragment fragment) { android.support.v4.app.FragmentManager manager = fragment.getChildFragmentManager(); HookSupportFragment hookSupportFragment = (HookSupportFragment) manager.findFragmentByTag(TAG_HOOK); if (hookSupportFragment != null) { hookSupportFragment.postEnable = false; manager.beginTransaction().remove(hookSupportFragment).commitAllowingStateLoss(); }// w w w . j a v a 2s . com }
From source file:com.blue.leaves.util.task.SugarTask.java
private void unregisterHookToContext(@NonNull FragmentActivity activity) { android.support.v4.app.FragmentManager manager = activity.getSupportFragmentManager(); HookSupportFragment hookSupportFragment = (HookSupportFragment) manager.findFragmentByTag(TAG_HOOK); if (hookSupportFragment != null) { hookSupportFragment.postEnable = false; manager.beginTransaction().remove(hookSupportFragment).commitAllowingStateLoss(); }/*w w w. j a v a 2 s. com*/ }