private void initMap() { PlaceAutocompleteFragment autocompleteFragment = new PlaceAutocompleteFragment(); CustomMapFragment mapFragment = new CustomMapFragment(); autocompleteFragment.setOnPlaceSelectedListener(this); mapFragment.setParent(mBinding.scroll); mapFragment.getMapAsync(this); FragmentManager manager = getActivity().getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.add(R.id.place_autocomplete_fragment, autocompleteFragment); transaction.add(R.id.google_map_fragment, mapFragment); transaction.commit(); mMarkerOptions = new MarkerOptions().icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)); mCircleOptions = new CircleOptions().fillColor(Color.argb(97, 93, 185, 139)).strokeColor(Color.argb(200, 93, 185, 139)); }
public void showDialog(Bundle bundle) { final Activity activity = (Activity) context; FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); Fragment prev = activity.getFragmentManager().findFragmentByTag(fragmentTag); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); newFragment = MyDialogFragment.newInstance(bundle); newFragment.setList(list); newFragment.setContext(context); newFragment.setListener(listener); newFragment.show(ft, fragmentTag); }
@Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.navigation_home: FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.content, ProjectFragment.newInstance()); // newInstance() is a static factory method. transaction.commit(); return true; case R.id.navigation_dashboard: FragmentManager newsManager = getFragmentManager(); FragmentTransaction transaction1 = newsManager.beginTransaction(); transaction1.replace(R.id.content, OrgFragment.newInstance()); // newInstance() is a static factory method. transaction1.commit(); return true; case R.id.navigation_notifications: FragmentManager projectManager = getFragmentManager(); FragmentTransaction transaction2 = projectManager.beginTransaction(); transaction2.replace(R.id.content, MapFragment.newInstance()); // newInstance() is a static factory method. transaction2.commit(); return true; } return false; }
/** * Metodo encargado de la navegacion. Usa item.getTitle para manejar el caso de intentar * navegar hacia la tab en la que ya estamos * @param item * @return true si se marca la tab, false si no */ @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { Fragment newFragment = null; if(!(tabActualTitle == item.getTitle())){ tabActualTitle = item.getTitle(); switch (item.getItemId()) { case R.id.action_sofa: newFragment = Sofa.newInstance(); break; case R.id.action_torneo: newFragment = Torneo.newInstance(); break; case R.id.action_mapas: newFragment = Mapas.newInstance(); break; } FragmentTransaction transaction = context.getFragmentManager().beginTransaction(); transaction.replace(R.id.fragment, newFragment); transaction.addToBackStack(null); transaction.commit(); return true; }else{ return false; } }
/** * Hide list, show details and instruct the details view to show the selected book. */ @Override public void showDetails(Book book, Drawable thumb) { final FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); BookDetailsFragment details = (BookDetailsFragment) fragmentManager.findFragmentById(R.id.book_details); if (book != null) { // If null passed, we only configure fragment transaction here. details.showDetails(book, thumb); } ft.show(details); ft.hide(fragmentManager.findFragmentById(R.id.book_list)); ft.addToBackStack("details"); // Use the back button to return to the search list view. ft.commit(); }
public static void removeFragment(FragmentManager fragmentManager, int containViewId) { if(fragmentManager != null) { Fragment fragment = fragmentManager.findFragmentById(containViewId); if (fragment != null) { fragments.remove(fragment); // TODO: Remove from backStackKeys FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.remove(fragment); transaction.commitAllowingStateLoss(); } } else { Log.e("FragmentHelper", "Fragment Manager = null"); } }
private void hidePreFragment(FragmentTransaction transaction) { Log.d(TAG, "hidePreFragment: mCurrentPageTag = "+mCurrentPageTag); switch (mCurrentPageTag) { case HOME_PAGE_TAG: transaction.hide(mHomeFragment); mHomeBtn.setTextColor(textColor); break; case EXPLORE_PAGE_TAG: transaction.hide(mExploreFragment); mExploreBtn.setTextColor(textColor); break; case MINE_PAGE_TAG: transaction.hide(mMineFragment); mMineBtn.setTextColor(textColor); break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_question); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); QuestionActivityFragment mainActivityFragment = (QuestionActivityFragment) getFragmentManager().findFragmentById(R.id.content_question); if (mainActivityFragment == null) { mainActivityFragment = QuestionActivityFragment.newInstance(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.add(R.id.content_question, mainActivityFragment); transaction.commit(); } RequestFactory requestFactory = new RequestFactory(); TriviaSharedPreferences triviaSharedPreferences = new TriviaSharedPreferences( PreferenceManager.getDefaultSharedPreferences(getApplicationContext())); int amount = getIntent().getIntExtra(AMOUNT, DEFAULT_AMOUNT_OF_QUESTIONS); String categoryId = getIntent().getStringExtra(CATEGORY_ID); String difficulty = getIntent().getStringExtra(DIFFICULTY); String questionType = getIntent().getStringExtra(GAME_TYPE); new QuestionPresenter(mainActivityFragment, requestFactory, triviaSharedPreferences, amount, categoryId, difficulty, questionType); }
public static void reloadFragment(FragmentManager fragmentManager, Fragment fragment) { if (fragment != null){ FragmentTransaction ft = fragmentManager.beginTransaction(); // ft.setTransition(-1); // ft.replace(containViewId, fragment); ft.detach(fragment); ft.attach(fragment); ft.commitAllowingStateLoss(); } }
private void goToRegister(){ FragmentTransaction ft = getFragmentManager().beginTransaction(); RegisterFragment fragment = new RegisterFragment(); ft.replace(R.id.fragmentFrame,fragment,RegisterFragment.TAG); ft.commit(); }
private void showUserFragment(User user){ FragmentTransaction ft = getFragmentManager().beginTransaction(); Fragment prev = getFragmentManager().findFragmentByTag(USER_FRAGMENT_LABEL); if(prev != null){ ft.remove(prev); } ft.addToBackStack(null); UserFragment newFragment = UserFragment.newInstance(user); newFragment.show(ft, USER_FRAGMENT_LABEL); }
private void changeFragment(Fragment newFragment, FragmentsAvailable newFragmentType, boolean withoutAnimation) { FragmentManager fm = getFragmentManager(); FragmentTransaction transaction = fm.beginTransaction(); /*if (!withoutAnimation && !isAnimationDisabled && currentFragment.shouldAnimate()) { if (newFragmentType.isRightOf(currentFragment)) { transaction.setCustomAnimations(R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left, R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right); } else { transaction.setCustomAnimations(R.anim.slide_in_left_to_right, R.anim.slide_out_left_to_right, R.anim.slide_in_right_to_left, R.anim.slide_out_right_to_left); } }*/ if (newFragmentType != FragmentsAvailable.DIALER && newFragmentType != FragmentsAvailable.CONTACTS_LIST && newFragmentType != FragmentsAvailable.CHAT_LIST && newFragmentType != FragmentsAvailable.HISTORY_LIST) { transaction.addToBackStack(newFragmentType.toString()); } else { while (fm.getBackStackEntryCount() > 0) { fm.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); } } transaction.replace(R.id.fragmentContainer, newFragment, newFragmentType.toString()); transaction.commitAllowingStateLoss(); fm.executePendingTransactions(); currentFragment = newFragmentType; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check NightMode On/Off mConfig = getSharedPreferences(getString(R.string.key_config), MODE_PRIVATE); boolean isNightMode = mConfig.getBoolean(getString(R.string.key_is_night_mode), false); if (isNightMode) { setTheme(R.style.DarkTheme); } else { setTheme(R.style.LightTheme); } checkPermission(); mBinding = DataBindingUtil.setContentView(this, R.layout.activity_new_create); //Binding Layout initToolbar(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); mFragment = SettingFragment.newInstance(); transaction.add(R.id.setting_fragment, mFragment); transaction.commit(); mRealm = Realm.getDefaultInstance(); // Initialize Realm // Intent intent = getIntent(); // if (intent.getStringExtra("data") != null) { // Bundle bundle = new Bundle(); // bundle.putString("data", intent.getStringExtra("data")); // mFragment.setArguments(bundle); // if (intent.getStringExtra(getString(R.string.key_title)) != null) { // mFragment.setArguments(intent.getExtras()); // } // } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) public void detach(Fragment fragment, FragmentTransaction currTransaction) { currTransaction.detach(fragment); }
private void summitFragment(String mediaId) { BrowserFragment fragment = getFragment(); if (fragment == null || !TextUtils.equals(fragment.getMediaId(), mediaId)) { fragment = BrowserFragment.newInstance(mediaId); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.replace(R.id.container, fragment, FRAGMENT_TAG); // If this is not the top level media (root), we add it to the fragment back stack, // so that actionbar toggle and Back will work appropriately: if (mediaId != null) { transaction.addToBackStack(null); } transaction.commit(); } }
public void showDialog(Bundle bundle) { final Activity activity = (Activity) context; FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); Fragment prev = activity.getFragmentManager().findFragmentByTag("dialog2"); if (prev != null) { ft.remove(prev); } ft.addToBackStack(null); ArrayList<String> list = (ArrayList<String>) bundle.get("adduid"); MyDialogFragment newFragment = MyDialogFragment.newInstance(bundle); newFragment.setContext(context); newFragment.setListener(listener); newFragment.show(ft, "dialog2"); }
private void switchMainView(AAttachableFragment fragment) { FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.fragment_container, fragment); transaction.commit(); fragment.attach(this); this.lastMainFragment = fragment; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_profile_settings); setSupportActionBar((Toolbar) findViewById(R.id.toolbar_settings)); ActionBar actionBar = getSupportActionBar(); actionBar.setTitle(R.string.activity_settings); manager = getFragmentManager(); ProfileSettingsFragment fragment = (ProfileSettingsFragment) manager.findFragmentByTag(SETTINGS_FRAGMENT); if (fragment == null) { fragment = ProfileSettingsFragment.newInstance(); } FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.cont_settings_fragment, fragment, SETTINGS_FRAGMENT) .commit(); }
public static void openCalendarPicker(YearMonthDay preset, Builder.CalendarPickerOnConfirm calendarPickerOnConfirm) { FragmentCalendarPicker fragmentCalendarPicker = FragmentCalendarPicker.newInstance( preset, calendarPickerOnConfirm); FragmentTransaction ft = activity.getFragmentManager().beginTransaction(); ft.add(android.R.id.content, fragmentCalendarPicker); ft.addToBackStack("com.maxproj.calendarpicker"); ft.commit(); }
/** * Destroys fragment and resets UI after the user either cancels or finishes sending a story. */ public void OnComplete() { FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.remove(manager.findFragmentByTag("AddStoryFragment_1")); transaction.commit(); adapter.setcheck(false); supportInvalidateOptionsMenu(); findViewById(R.id.go_to_map).setVisibility(View.VISIBLE); findViewById(R.id.fab).setVisibility(View.VISIBLE); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); 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); navigationView.setNavigationItemSelectedListener(this); navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); FragmentManager manager = getFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.content, ProjectFragment.newInstance()); // newInstance() is a static factory method. transaction.commit(); shakeSensor = new ShakeSensor(); shakeSensor.setListener(this); shakeSensor.init(this); }
private boolean showCamera(CallbackContext callbackContext) { if(this.hasView(callbackContext) == false){ return true; } FragmentManager fragmentManager = cordova.getActivity().getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.show(fragment); fragmentTransaction.commit(); callbackContext.success(); return true; }
public void dismiss() { if (mDismissed) { return; } mDismissed = true; getFragmentManager().popBackStack(); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.remove(this); ft.commit(); }
@Override public void onItemClick(int i) { FragmentTransaction transaction = getFragmentManager().beginTransaction(); // 隐藏所有的Fragment if (exploreFragment != null) transaction.hide(exploreFragment); if (homeFragment != null) transaction.hide(homeFragment); if (settingsFragment != null) transaction.hide(settingsFragment); // 显示被选中的Fragment switch (i) { case 0: // 动态 if (homeFragment == null) { homeFragment = new HomeFragment(); transaction.add(R.id.container, homeFragment); } else transaction.show(homeFragment); setTitle(R.string.dynamic); break; case 1: // 发现 if (exploreFragment == null) { exploreFragment = new ExploreFragment(); transaction.add(R.id.container, exploreFragment); } else transaction.show(exploreFragment); setTitle(R.string.explore); break; case 3: if (settingsFragment == null) { settingsFragment = new SettingsFragment(); transaction.add(R.id.container, settingsFragment); } else transaction.show(settingsFragment); setTitle("设置"); } transaction.commit(); }
/** * The {@code fragment} is added to the container view with id {@code frameId}. The operation is * performed by the {@code fragmentManager}. */ public static void addFragmentToActivity(@NonNull FragmentManager fragmentManager, @NonNull Fragment fragment, int frameId) { checkNotNull(fragmentManager); checkNotNull(fragment); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.add(frameId, fragment); transaction.commit(); }
@Override public void switchToRegistration() { FragmentTransaction ft = fragmentManager.beginTransaction(); RegistrationFragment registrationFragment = (RegistrationFragment) fragmentManager.findFragmentByTag(REGISTER_FRAGMENT_TAG); if (registrationFragment == null) { registrationFragment = RegistrationFragment.newInstance(); } ft.replace(R.id.fragmentContainer, registrationFragment, REGISTER_FRAGMENT_TAG); ft.addToBackStack(REGISTER_FRAGMENT_TAG); ft.commit(); }
@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { final String key = preference.getKey(); switch (key) { case KEY_CHECK_UPDATE: mTask = CheckUpdateTask.getInstance(false); if (!mTask.getStatus().equals(AsyncTask.Status.RUNNING)) { mTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity()); } return true; case KEY_CHANGELOG: ChangelogFragment changelogFrag = new ChangelogFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); transaction.replace(this.getId(), changelogFrag); transaction.addToBackStack(this.getClass().getName()); transaction.commit(); return true; default: OTALink link = LinkConfig.getInstance().findLink(key, getActivity()); if (link != null) { OTAUtils.launchUrl(link.getUrl(), getActivity()); } break; } return super.onPreferenceTreeClick(preferenceScreen, preference); }
public static void reloadFragment(FragmentManager fragmentManager, Fragment fragment, int containViewId) { if (fragment != null){ FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setTransition(-1); // ft.replace(containViewId, fragment); ft.detach(fragment); ft.attach(fragment); ft.commitAllowingStateLoss(); } }
public void showList() { final FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.show(fragmentManager.findFragmentById(R.id.book_list)); ft.hide(fragmentManager.findFragmentById(R.id.book_details)); ft.commit(); }
@Override public void onBackPressed() { FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { // 백스택이 존재할 떄까지 if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); ft.commit(); } // 백스택이 없는 경우 else { super.onBackPressed(); } } }
/** * 根据tag显示viewId里的一个fragment,其他全部隐藏 */ public void showFragmentOne(int containerViewId, String tag) { FragmentTransaction transaction = getTransaction(); for (Fragment fragment : getFragmentList(containerViewId)) { if (fragment.getTag().equals(tag)) { transaction.show(fragment); } else if (!fragment.isHidden()) { transaction.hide(fragment); } } transaction.commit(); }
@Override public void onScanFinish(Uri uri) { ResultFragment fragment = new ResultFragment(); Bundle bundle = new Bundle(); bundle.putParcelable(ScanConstants.SCANNED_RESULT, uri); fragment.setArguments(bundle); android.app.FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(cordova.getActivity().getResources().getIdentifier("content", "id", cordova.getActivity().getPackageName()) , fragment); fragmentTransaction.addToBackStack(ResultFragment.class.toString()); fragmentTransaction.commit(); }
public static void showChangelog(FragmentManager fm) { FragmentTransaction ft = fm.beginTransaction(); Fragment prev = fm.findFragmentByTag(TAG); if (prev != null) { ft.remove(prev); } try { DialogFragment dialog = DialogFragmentChangelog.newInstance(); dialog.show(ft, TAG); } catch (IllegalArgumentException | IllegalStateException ignored) { } }
public void replaceHasHistory(int containerId, Fragment fragment) { if (currentFragment==fragment) { return; } FragmentTransaction ft = fm.beginTransaction(); ft.replace(containerId, fragment); ft.addToBackStack(null);//添加这个会在按返回键的时候先退出fragment,一些特殊场合可能用到,但效果其实不理想 ft.commitAllowingStateLoss(); currentFragment = fragment; }
public static void show(FragmentManager fm, RootInfo root) { final ServerFragment fragment = new ServerFragment(); final Bundle args = new Bundle(); args.putParcelable(EXTRA_ROOT, root); fragment.setArguments(args); final FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.container_directory, fragment); ft.commitAllowingStateLoss(); }
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { setContentView(R.layout.activity_main_db5); super.onCreate(savedInstanceState); mFragment = TableViewerFragment.newInstance("db5.db", "category"); mFragment.setOnItemClicked(this); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.flFragment, mFragment, "TAG").commit(); }
public void show(FragmentManager manager) { FragmentTransaction ft = manager.beginTransaction(); ft.add(this, getTagName()); ft.addToBackStack(getTagName()); ft.commit(); }
public static void show(FragmentManager fm, ArrayList<DocumentInfo> docs, boolean deleteAfter) { final Bundle args = new Bundle(); args.putParcelableArrayList(EXTRA_DOC_LIST, docs); args.putBoolean(EXTRA_DELETE_AFTER, deleteAfter); final MoveFragment fragment = new MoveFragment(); fragment.setArguments(args); final FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.container_save, fragment, TAG); ft.commitAllowingStateLoss(); }
private void replaceFragment(final Fragment fragment, final boolean addToBackStack) { final FragmentManager fm = getFragmentManager(); final FragmentTransaction transaction = fm.beginTransaction(); final String tag; if (fragment instanceof CurrentFeedFragment) { tag = CurrentFeedFragment.TAG; } else if (fragment instanceof FeedSubscriptionsFragment) { tag = FeedSubscriptionsFragment.TAG; } else if (fragment instanceof SavedEntriesFragment) { tag = SavedEntriesFragment.TAG; } else if (fragment instanceof InitialSetupFragment) { tag = InitialSetupFragment.TAG; } else { tag = LoadCurrentFeedFragment.TAG; } transaction.replace(R.id.FragmentContainer, fragment, tag); if (addToBackStack) { transaction.addToBackStack(tag); } transaction.commit(); fm.executePendingTransactions(); }