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 showFragment(final FragmentManager fragmentManager, final Fragment fragment, final boolean addToBackStack, final String tag) { // hide the full screen container hideFullScreenView();//from w w w . j a va 2 s.c om if (fragmentManager.findFragmentByTag(tag) == null) { final int viewId = mContentContainer.addBorderView(this); updateCurrentPresenterClass(fragment, viewId); final FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(viewId, fragment, tag); if (addToBackStack) { transaction.addToBackStack(tag); } transaction.commitAllowingStateLoss(); } else { fragmentManager.beginTransaction().detach(fragment).attach(fragment).commitAllowingStateLoss(); } }
From source file:com.github.chenxiaolong.dualbootpatcher.MainActivity.java
private void showFragment() { FragmentManager fm = getFragmentManager(); Fragment prevRoms = fm.findFragmentByTag(SwitcherListFragment.TAG); Fragment prevPatchFile = fm.findFragmentByTag(PatchFileFragment.TAG); Fragment prevFreeSpace = fm.findFragmentByTag(FreeSpaceFragment.TAG); Fragment prevAbout = fm.findFragmentByTag(AboutFragment.TAG); FragmentTransaction ft = fm.beginTransaction(); ft.setCustomAnimations(R.animator.fragment_in, 0); switch (mFragment) { case FRAGMENT_ROMS: mTitle = R.string.title_roms;//from w w w .j a v a 2 s . c o m updateTitle(); if (prevRoms == null) { Fragment f = SwitcherListFragment.newInstance(); ft.add(R.id.content_frame, f, SwitcherListFragment.TAG); } else { ft.show(prevRoms); } break; case FRAGMENT_PATCH_FILE: mTitle = R.string.title_patch_zip; updateTitle(); if (prevPatchFile == null) { Fragment f = PatchFileFragment.newInstance(); ft.add(R.id.content_frame, f, PatchFileFragment.TAG); } else { ft.show(prevPatchFile); } break; case FRAGMENT_FREE_SPACE: mTitle = R.string.title_free_space; updateTitle(); if (prevFreeSpace == null) { Fragment f = FreeSpaceFragment.newInstance(); ft.add(R.id.content_frame, f, FreeSpaceFragment.TAG); } else { ft.show(prevFreeSpace); } break; case FRAGMENT_ABOUT: mTitle = BuildConfig.APP_NAME_RESOURCE; updateTitle(); if (prevAbout == null) { Fragment f = AboutFragment.newInstance(); ft.add(R.id.content_frame, f, AboutFragment.TAG); } else { ft.show(prevAbout); } break; default: throw new IllegalStateException("Invalid fragment ID"); } ft.commit(); }
From source file:at.alladin.rmbt.android.map.RMBTMapFragment.java
@Override public void onClick(View v) { final FragmentManager fm = getActivity().getFragmentManager(); final FragmentTransaction ft; final GoogleMap map = getMap(); switch (v.getId()) { case R.id.mapChooseButton: ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, new RMBTMapChooseFragment(), "map_choose"); ft.addToBackStack("map_choose"); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit();//from w w w . ja v a 2 s . c o m break; case R.id.mapFilterButton: ft = fm.beginTransaction(); ft.replace(R.id.fragment_content, new RMBTMapFilterFragment(), "map_filter"); ft.addToBackStack("map_filter"); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); ft.commit(); break; case R.id.mapLocateButton: if (map != null) { final Location location = geoLocation.getLastKnownLocation(); if (location != null) { final LatLng latlng = new LatLng(location.getLatitude(), location.getLongitude()); gMap.animateCamera(CameraUpdateFactory.newLatLng(latlng)); } } break; case R.id.mapHelpButton: ((RMBTMainActivity) getActivity()).showHelp("", false, AppConstants.PAGE_TITLE_HELP); // TODO: put correct // help url break; case R.id.mapInfoButton: showInfoToast(); break; case R.id.mapZoomInButton: if (map != null) map.animateCamera(CameraUpdateFactory.zoomIn()); break; case R.id.mapZoomOutButton: if (map != null) map.animateCamera(CameraUpdateFactory.zoomOut()); break; default: break; } }
From source file:com.androidexperiments.sprayscape.androidutils.PermissionRequester.java
public static void requestPermission(final String permission, final String objectName, final String methodName) { Log.i(TAG, "requestPermission() called for permission: " + permission); final Activity currentActivity = UnityPlayer.currentActivity; boolean granted = ActivityCompat.checkSelfPermission(currentActivity, permission) == PackageManager.PERMISSION_GRANTED; if (granted) { Log.i(TAG, "Permission already granted: " + permission); SendPermissionResult(permission, true, objectName, methodName); return;/*from w w w. ja v a 2s .co m*/ } try { // use a fragment here because we wouldn't be able to capture onRequestPermissionsResult() on the main activity unless we sub-classed it... // final values so the fragment inner-class can access them final FragmentManager fragmentManager = currentActivity.getFragmentManager(); final Fragment request = new Fragment() { @Override public void onStart() { super.onStart(); Log.i(TAG, "Permission fragment onStart()"); FragmentCompat.requestPermissions(this, new String[] { permission }, 0); } @SuppressLint("Override") @SuppressWarnings("unused") public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { Log.i(TAG, "onRequestPermissionsResult(" + requestCode + ", " + permissions.toString() + ", " + grantResults.toString() + ")"); if (grantResults.length > 0) { for (int i = 0; i < grantResults.length; i++) { if (grantResults[i] == PackageManager.PERMISSION_GRANTED) { Log.i(TAG, "Permission granted: " + permissions[i]); SendPermissionResult(permissions[i], true, objectName, methodName); } else { Log.i(TAG, "Permission denied: " + permissions[i]); SendPermissionResult(permissions[i], false, objectName, methodName); } } } else { Log.i(TAG, "Permission denied: " + permission); SendPermissionResult(permission, false, objectName, methodName); } FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.remove(this); fragmentTransaction.commit(); } }; FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(0, request); fragmentTransaction.commit(); } catch (Exception error) { Log.e(TAG, "Permission request failed: '" + permission + "'", error); SendPermissionResult(permission, false, objectName, methodName); } }
From source file:com.theoreticsinc.schoolapp.activities.DrawerActivity.java
private void selectItem(int position) { FragmentManager fragmentManager = getFragmentManager(); if (position == 1) { /* Fragment settingsFrag = new SettingsFragment(); Bundle args = new Bundle(); args.putInt("SettingsItem", position); settingsFrag.setArguments(args); fragmentManager.beginTransaction().replace(R.id.content_frame, settingsFrag).commit(); *///from w ww . j a v a 2s. co m } else if (position == 3) { Fragment newpost = new WebsiteFragment(); Bundle args = new Bundle(); args.putInt("SettingsItem", position); newpost.setArguments(args); fragmentManager.beginTransaction().replace(R.id.content_frame, newpost).commit(); } else { Fragment dashFrag = new DashboardFragment(); Bundle args = new Bundle(); args.putInt("SettingsItem", position); dashFrag.setArguments(args); fragmentManager.beginTransaction().replace(R.id.content_frame, dashFrag).commit(); } // update selected item and title, then close the drawer setTitle(settingsName[position]); //position = position + 1; mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.plusapp.pocketbiceps.app.MainActivity.java
@TargetApi(Build.VERSION_CODES.N) @Override/*from w ww . java2s . c om*/ protected void onCreate(Bundle savedInstanceState) { SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String theme_key = getString(R.string.preference_key_darktheme); isSetToDarkTheme = sPrefs.getBoolean(theme_key, false); if (isSetToDarkTheme == true) { setTheme(R.style.DarkTheme); isDarkTheme = true; } // Prueft ob das Coverfoto gesetzt werden soll und speichert es ggfs. in einer Bitmap String cover_key = getString(R.string.preference_key_coverphoto); isSettoCoverPhoto = sPrefs.getBoolean(cover_key, false); //Oeffnet die Datenbank data = new MarkerDataSource(this); data.open(); // data.addMarker(new MyMarkerObj("Test", "Test2", "48.49766 9.19881", 1234234)); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Aenderd den Textfont von der Toolbar for (int i = 0; i < toolbar.getChildCount(); i++) { View view = toolbar.getChildAt(i); if (view instanceof TextView) { TextView tv = (TextView) view; Typeface titleFont = Typeface.createFromAsset(getAssets(), "fonts/Antonio-Light.ttf"); if (tv.getText().equals(toolbar.getTitle())) { // Zum zentrieren // Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.WRAP_CONTENT, Toolbar.LayoutParams.MATCH_PARENT); // params.gravity = Gravity.CENTER_HORIZONTAL; // tv.setLayoutParams(params); // Zum aendern der Schriftart tv.setTypeface(titleFont); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 28); break; } } } sp = getSharedPreferences("prefs_sort", Activity.MODE_PRIVATE); sortOrder = sp.getInt("sort_mode", 0); //Permissions Abfragen isStoragePermissionGranted(); grantLocationPermission(); // Erstellt die RecylerView recList = (RecyclerView) findViewById(R.id.lvMemories); recList.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(this); llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); momentsCount = createList2().size(); fab_Menu = (FloatingActionMenu) findViewById(R.id.fab_menu); fab1 = (FloatingActionButton) findViewById(R.id.fab1); fab2 = (FloatingActionButton) findViewById(R.id.fab2); fab3 = (FloatingActionButton) findViewById(R.id.fab3); // An den MemoryAdapter wird Liste an den Konstruktor weitergegeben this.ca = new MemoryAdapter(createList2(), this); this.recList.setAdapter(ca); final String PREFS_NAME = "MyPrefsFile"; SharedPreferences firstPref = getSharedPreferences(PREFS_NAME, 0); if (firstPref.getBoolean("First_Time", true)) { //Do first operation showMainTutorial(); firstPref.edit().putBoolean("First_Time", false).apply(); } /* Hier wird der clicklListener der weiter unten programmiert ist hinzugefgt damit kann man auf Klick events mit einem Switch reagieren */ fab1.setOnClickListener(clickListener); fab2.setOnClickListener(clickListener); fab3.setOnClickListener(clickListener); /* Gibt an in welcher Geschwindigkeit die normalen Buttons auftauchen sollen */ int delay = 400; for (final FloatingActionMenu menu : fab_Submenus) { mUiHandler.postDelayed(new Runnable() { @Override public void run() { menu.showMenuButton(true); } }, delay); delay += 150; } /* Das toggle sorgt dafr dass der Menbutton aufgeklappt und zugeklappt werden kann */ fab_Menu.setOnMenuButtonClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (fab_Menu.isOpened()) { /* Mit getMenuButtonLabelText() bekommt man den Text der in der XML deklariert ist */ // Toast.makeText(getBaseContext(), fab_Menu.getMenuButtonLabelText(), Toast.LENGTH_SHORT).show(); } fab_Menu.toggle(true); } }); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); drawer.setDrawerListener(toggle); toggle.syncState(); navigationView = (NavigationView) findViewById(R.id.nav_view); // TextView nav_user = (TextView) headNavView.findViewById(R.id.tvNavHeaderTitle); // nav_user.setText("test1231231"); navigationView.setNavigationItemSelectedListener(this); headNavView = navigationView.getHeaderView(0); nav_image_head = (ImageView) headNavView.findViewById(R.id.ivNavHead); if (isDarkTheme) { nav_image_head.setImageResource(R.drawable.headerblack); } else { nav_image_head.setImageResource(R.drawable.headerblue); } if (isSettoCoverPhoto) { // NavDrawer Header manipulieren List<MyMarkerObj> navHeaderGetImage = createList2(); // Falls mind. ein Eintrag existiert, wird das Foto dass als letztes gemacht wurde // in den NavHeader eingefgt if (navHeaderGetImage.size() != 0) { MyMarkerObj mmo = navHeaderGetImage.get(0); // Das Datum und die Zeit dienen als Index um die Bilder zu finden z.B. Moments_10-12-2016-18-24-10 SimpleDateFormat formatterForImageSearch = new SimpleDateFormat("dd-MM-yyyy-HH-mm-SS"); String imageDate = formatterForImageSearch.format(new Date(mmo.getTimestamp())); // Das Bild wird in die Variable f initialisiert File f = new File(mmo.getPath()); memAdapter = new MemoryAdapter(); bmpHeaderTarget = new Target() { @Override public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { bmp = bitmap; // Setzt das Bild in den NavHeader wenn bmp not null ist if (bmp != null) { nav_image_head.setImageBitmap(bmp); } } @Override public void onBitmapFailed(Drawable errorDrawable) { } @Override public void onPrepareLoad(Drawable placeHolderDrawable) { } }; Picasso.with(this).load(f).resize(540, 540).centerCrop().into(bmpHeaderTarget); isCoverPhoto = true; } } momentsCounter = (TextView) MenuItemCompat .getActionView(navigationView.getMenu().findItem(R.id.nav_camera)); // Damit wird der Counter initialisiert initializeCountDrawer(); FragmentManager fm = getFragmentManager(); fm.beginTransaction().replace(R.id.content_main, new MainFragment()).commit(); }
From source file:com.example.pyrkesa.shwc.MainActivity.java
/** * Diplaying fragment view for selected nav drawer list item * *//* w ww . j ava 2 s .c om*/ private void displayView(int position) { Fragment fragment = null; switch (position) { case 0: fragment = new HomeFragment(); mTitle = "SHWC"; break; case 1: fragment = new ScenarioFragment(); mTitle = "Dfinir scnarios"; break; case 2: fragment = new RoomSettingFragment(); mTitle = "Rglage salle"; break; case 3: fragment = new User_Fragment(); mTitle = "Gestion des utilisateurs"; break; default: break; } if (fragment != null) { FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.replace(R.id.test, fragment, ""); transaction.commit(); model.current_page = position; mDrawerList.setItemChecked(position, true); mDrawerList.setSelection(position); //getActionBar().setTitle(mNavigationDrawerItemTitles[position]); // getActionBar().setTitle(position); mDrawerLayout.closeDrawer(mDrawerList); } else { Log.e("MainActivity", "Error in creating fragment"); } }
From source file:at.flack.MainActivity.java
public void drawMailFragment() { MailMainActivity.forceReinstance();/* ww w .j a va2s . com*/ FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.content_frame, MailMainActivity.getInstance()).commit(); }
From source file:com.cgearc.yummy.Act_Main.java
private void selectItem(int position) { String fragment_tag = getResources().getStringArray(R.array.drawer_item_array)[position]; // Google Analytics Tracker t = ((MyApplication) this.getApplication()).getTracker(); t.setScreenName(fragment_tag);/*from w ww . ja v a 2 s .c om*/ t.send(new HitBuilders.AppViewBuilder().build()); if (this.mSlideUpPanel != null) this.mSlideUpPanel.collapsePane(); // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); Bundle args = new Bundle(); Fragment fragment = new Frg_RecipeList(); switch (position) { case 0: // Hot // mProgressBar.setVisibility(View.VISIBLE); fragmentManager.beginTransaction().addToBackStack(null) .replace(R.id.content_frame, fragment, fragment_tag).commit(); break; case 1: // Search Intent intent = new Intent(this, Act_RecipeSearch.class); this.startActivityForResult(intent, 1); break; case 2: // Favorite args.putString("favorite", "fav"); fragment.setArguments(args); fragmentManager.beginTransaction().addToBackStack(null) .replace(R.id.content_frame, fragment, fragment_tag).commit(); break; case 3: String message = "<ol>" + "<li>AppTPixnetlAev@C</li>" + "<li>Yw<a href=\"mailto://cnevinchen@gmail.com>\">gH</a></li>" + "<li>pGoA<a href='https://play.google.com/store/apps/details?id=com.cgearc.yummy'>n</a></li>" + "<li>pGwAiH<a href=\"javascript:alert(injectedObject.unistall())\"> IYummy</a></li>" + "<li>,Jemailiop,<a href=https://docs.google.com/forms/d/1Rviax0Ldl3zWkW5FwOJUYZtFALcgdbqSQdKNG3XtrN4/viewform>iI</a></li>" + "</ol>" + "<iframe src=\"https://docs.google.com/forms/d/1Rviax0Ldl3zWkW5FwOJUYZtFALcgdbqSQdKNG3XtrN4/viewform?embedded=true\" width=100% height=1300 frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\">Loading...</iframe>"; mSUPTitle.setText("App"); mSUPAuthor.setText("PA,AppNzPNHUw"); Frg_RecipeDetail detail = new Frg_RecipeDetail(); args = new Bundle(); args.putString("body", message); detail.setArguments(args); mImageButtonWeb.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("https://play.google.com/store/apps/details?id=com.cgearc.yummy")); startActivity(i);// } }); this.getFragmentManager().beginTransaction().replace(R.id.slideUpPanel_frame, detail) .addToBackStack(null).commit(); new Handler().postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub mSlideUpPanel.expandPane(); } }, 500); break; case 4: Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse("https://play.google.com/store/apps/developer?id=cnevinc")); startActivity(i);// // // Strings to Show In Dialog with Radio Buttons // final CharSequence[] items = { "rY ", " Y ", " " }; // // // Creating and Building the Dialog // AlertDialog.Builder builder = new AlertDialog.Builder(this); // builder.setTitle(""); // builder.setSingleChoiceItems(items, -1, // new DialogInterface.OnClickListener() { // public void onClick(DialogInterface dialog, int item) { // // switch (item) { // case 0: // Setting.GESTURE = 0 ; // break; // case 1: // Setting.GESTURE = 1 ; // break; // case 2: // Setting.GESTURE = 2 ; // break; // } // levelDialog.dismiss(); // } // }); // levelDialog = builder.create(); // levelDialog.show(); break; } // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); // setTitle(mDrawerItems[position]); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.theoreticsinc.brucat.activities.DrawerActivity.java
private void selectItem(int position) { FragmentManager fragmentManager = getFragmentManager(); if (position == 1) { /* Fragment settingsFrag = new SettingsFragment(); Bundle args = new Bundle(); args.putInt("SettingsItem", position); settingsFrag.setArguments(args); fragmentManager.beginTransaction().replace(R.id.content_frame, settingsFrag).commit(); *//*from w ww . j av a2 s. c o m*/ } else if (position == 3) { Fragment newpost = new WebsiteFragment(); Bundle args = new Bundle(); args.putInt("SettingsItem", position); newpost.setArguments(args); fragmentManager.beginTransaction().replace(R.id.content_frame, newpost).addToBackStack(null).commit(); } else { Fragment dashFrag = new DashboardFragment(); Bundle args = new Bundle(); args.putInt("SettingsItem", position); dashFrag.setArguments(args); fragmentManager.beginTransaction().replace(R.id.content_frame, dashFrag) //.addToBackStack(null) .commit(); } // update selected item and title, then close the drawer setTitle(settingsName[position]); //position = position + 1; mDrawerList.setItemChecked(position, true); mDrawerLayout.closeDrawer(mDrawerList); }