List of usage examples for android.support.v4.app FragmentTransaction replace
public abstract FragmentTransaction replace(int containerViewId, Fragment fragment);
From source file:com.check.v3.ui.main.MainActivity.java
private void selectItem(int position) { // update the main content by replacing fragments SherlockListFragment listFragment;/*from ww w. j a v a 2s . co m*/ SherlockFragment fragment; Log.d(TAG, "drawer item is clicked " + position); Bundle args = new Bundle(); args.putInt(DRAWER_MENU_SELECTED_POSITION, position); FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); if (drawerListItemNames[position].equals(LIST_QUICK_REPORT_ITEM)) { fragment = new QuickReportListFragment(); transaction.replace(R.id.content_frame, fragment); // fragment = new RandomCheckComposeFragment(); // fragment.setArguments(args); // transaction.replace(R.id.content_frame, fragment); } else if (drawerListItemNames[position].equals(COMPOSE_QUICK_REPORT_ITEM)) { Intent intent = new Intent(this, QuickCheckComposeActivity.class); Bundle data = new Bundle(); data.putInt(Constants.WHAT_ACTION, Constants.QUICK_CHECK_EDIT_NEW_ACTION); startActivity(intent); mDrawerList.setItemChecked(position, true); setTitle(mDrawerItemsHashMap.get(drawerListItemNames[position])); mDrawerLayout.closeDrawer(mDrawerList); return; } else { fragment = new CustomFragment(); fragment.setArguments(args); transaction.replace(R.id.content_frame, fragment); } transaction.commit(); // update selected item and title, then close the drawer mDrawerList.setItemChecked(position, true); setTitle(mDrawerItemsHashMap.get(drawerListItemNames[position])); mDrawerLayout.closeDrawer(mDrawerList); }
From source file:com.ayuget.redface.ui.activity.TopicsActivity.java
protected void loadAnonymousTopic(Topic topic, int page, PagePosition pagePosition) { TopicFragment anonymousTopicFragment = new TopicFragmentBuilder(page, topic) .currentPagePosition(pagePosition).build(); int topicFragmentContainer = isTwoPaneMode() ? R.id.details_container : R.id.container; FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(topicFragmentContainer, anonymousTopicFragment); transaction.addToBackStack(null);/* www . j a v a2 s . c om*/ transaction.commit(); }
From source file:com.clemot.julian.easylib.EasyActivity.java
/** * Replace fragment with transition animation * * @param lastFrag fragment//w ww . ja v a 2s. c om * @param frag fragment * @param id which child is loaded * @param transitMode mode */ public void replaceFragment(Fragment lastFrag, Fragment frag, int id, int transitMode) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setTransition(transitMode); fragmentTransaction.replace(id, frag); fragmentTransaction.commit(); fragmentManager.executePendingTransactions(); }
From source file:com.example.d062654.faciliman._1_IncidentLogin.java
@Override public void onClick(View v) { Toast.makeText(this.ll.getContext(), "Das ist das zweite Fragment", Toast.LENGTH_SHORT).show(); final View view = v; if (v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/matloginbutton")) { progressbar.setVisibility(View.VISIBLE); Call<ResponseBody> call = Connection.getApiInterface().getLogin(matnr.getText().toString(), matpassword.getText().toString()); call.enqueue(new Callback<ResponseBody>() { @Override/*from w w w . j a v a2s . c om*/ public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { if (response.isSuccessful()) { // Do awesome stuff FragmentTransaction transaction = fragact.getSupportFragmentManager().beginTransaction(); _2_IncidentPicture newFragment = new _2_IncidentPicture(); newFragment.user = matnr.getText().toString(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); progressbar.setVisibility(GONE); // Commit the transaction transaction.commit(); } else if (response.code() == 401) { // Handle unauthorized progressbar.setVisibility(GONE); } else { // Handle other responses progressbar.setVisibility(GONE); } } @Override public void onFailure(Call<ResponseBody> call, Throwable t) { // Log error here since request failed Log.e(TAG, t.toString()); progressbar.setVisibility(GONE); } }); } }
From source file:com.clemot.julian.easylib.EasyActivity.java
/** * Replace fragment with transition animation * * @param lastFrag fragment//from w w w . jav a2s.c om * @param frag fragment * @param id which child is loaded * @param animation (POP/PUSH LEFT/PUSH RIGHT) */ public void replaceFragment(Fragment lastFrag, Fragment frag, int id, FragmentCustomAnimation animation) { FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); addCustomAnimation(fragmentTransaction, animation); fragmentTransaction.replace(id, frag); fragmentTransaction.commit(); fragmentManager.executePendingTransactions(); }
From source file:com.deliciousdroid.activity.BrowseBookmarks.java
public void onTagSelected(String tag) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); BrowseBookmarksFragment frag = new BrowseBookmarksFragment(); frag.setQuery(username, tag, false); transaction.replace(R.id.listcontent, frag); transaction.commit();/*from w w w. ja v a2 s. c om*/ }
From source file:com.example.d062654.faciliman._1f_FacilityLogin.java
@Override public void onClick(View v) { final View view = v; if (v.getResources().getResourceName(v.getId()).substring(30).contentEquals("id/fac_login")) { Call<ResponseBody> call = Connection.getApiInterface().getLogin(facusername.getText().toString(), facpassword.getText().toString()); call.enqueue(new Callback<ResponseBody>() { @Override//from ww w . j av a 2s . c o m public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) { if (response.isSuccessful()) { // Do awesome stuff Toast.makeText(ll.getContext(), view.getResources().getResourceName(view.getId()), Toast.LENGTH_SHORT).show(); FragmentTransaction transaction = fragact.getSupportFragmentManager().beginTransaction(); _2f_FacilityView newFragment = new _2f_FacilityView(); newFragment.username = facusername.getText().toString(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit(); } else if (response.code() == 401) { // Handle unauthorized } else { // Handle other responses } } @Override public void onFailure(Call<ResponseBody> call, Throwable t) { // Log error here since request failed Log.e(TAG, t.toString()); } }); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack so the user can navigate back //transaction.replace(R.id.fragment_container, newFragment); //transaction.addToBackStack(null); // Commit the transaction //transaction.commit(); } }
From source file:com.elekso.potfix.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PowerManager pm = (PowerManager) getApplicationContext() .getSystemService(getApplicationContext().POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, " POTFIX holding wake lock"); wl.acquire();/*from w w w .jav a2 s .c o m*/ Globals.getInstance().setFlexiblemap(true); // // // new Thread(new Runnable(){ // @Override // public void run() { // try { // LALpotfixservicePortBinding service = new LALpotfixservicePortBinding(); // try { // globaldata_test=service.CheckWS("mandar"); // // } catch (Exception e) { // e.printStackTrace(); // } // } catch (Exception ex) { // ex.printStackTrace(); // } // } // }).start(); String login = ""; // Config.getInstance(getBaseContext(),getCacheDir()).setProfile("df","asd"); login = Config.getInstance(getBaseContext(), getCacheDir()).getProfileName(); if (login == null || login.isEmpty()) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent); return; } //remove // Stetho.initializeWithDefaults(this); // Toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); // Drawer 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(); tusername = (TextView) drawer.findViewById(R.id.tvusername); // tuseremail =(TextView) findViewById(R.id.tvuseremail); // // if(login!=null) // tusername.setText("jhjhjhjh"); // if(Config.getInstance().getProfileEmail()!=null) //tuseremail.setText(Config.getInstance().getProfileEmail()); // FAB fab = (FloatingActionButton) findViewById(R.id.fab); fab.setRippleColor(Color.parseColor("#78D6F3")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC"))); fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { switch (currentFragment) { case 1: //profile Snackbar.make(view, "Updating Information", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); Fragment frg = new ProfileFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.frame_containerone, frg); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.commit(); break; case 2: //map if (Globals.getInstance().getFlexiblemap()) { Snackbar.make(view, "Free to Scroll", Snackbar.LENGTH_LONG).setAction("Action", null) .show(); Globals.getInstance().setFlexiblemap(false); fab.setRippleColor(Color.parseColor("#FFE082")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#FFB300"))); fab.setImageResource(R.drawable.ic_gps_off_white_24dp); } else { Snackbar.make(view, "Follow Potfix", Snackbar.LENGTH_LONG).setAction("Action", null).show(); Globals.getInstance().setFlexiblemap(true); fab.setRippleColor(Color.parseColor("#78D6F3")); fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#039FDC"))); fab.setImageResource(R.drawable.ic_gps_fixed_white_24dp); } break; case 3: //share //Snackbar.make(view, "Some sharing action", Snackbar.LENGTH_LONG).setAction("Action", null).show(); String[] TO = { "aziz@potfix.com" }; String[] CC = { "" }; Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse("mailto:")); emailIntent.setType("text/plain"); emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); emailIntent.putExtra(Intent.EXTRA_CC, CC); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Potfix Communication"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message..."); try { startActivity(Intent.createChooser(emailIntent, "Send mail...")); finish(); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT) .show(); } break; case 4: //legal Snackbar.make(view, "Software License", Snackbar.LENGTH_LONG).setAction("Action", null).show(); drawer.openDrawer(Gravity.LEFT); break; } } }); NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); startService(new Intent(getBaseContext(), BackgroundService.class)); FragmentTransaction mTransaction = getSupportFragmentManager().beginTransaction(); MapsFragment mFRaFragment = new MapsFragment(); mTransaction.add(R.id.frame_containerone, mFRaFragment); mTransaction.commit(); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS is Enabled in your devide", Toast.LENGTH_SHORT).show(); } else { showGPSDisabledAlertToUser(); } // if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){ // Toast.makeText(this, "Network is Enabled in your devide", Toast.LENGTH_SHORT).show(); // }else{ // showNetDisabledAlertToUser(); // } createNotification(); }
From source file:com.android.calendar.EventInfoActivity.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); // Get the info needed for the fragment Intent intent = getIntent();//w w w . j ava 2s.com int attendeeResponse = 0; mEventId = -1; boolean isDialog = false; ArrayList<ReminderEntry> reminders = null; if (icicle != null) { mEventId = icicle.getLong(EventInfoFragment.BUNDLE_KEY_EVENT_ID); mStartMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_START_MILLIS); mEndMillis = icicle.getLong(EventInfoFragment.BUNDLE_KEY_END_MILLIS); attendeeResponse = icicle.getInt(EventInfoFragment.BUNDLE_KEY_ATTENDEE_RESPONSE); isDialog = icicle.getBoolean(EventInfoFragment.BUNDLE_KEY_IS_DIALOG); reminders = Utils.readRemindersFromBundle(icicle); } else if (intent != null && Intent.ACTION_VIEW.equals(intent.getAction())) { mStartMillis = intent.getLongExtra(EXTRA_EVENT_BEGIN_TIME, 0); mEndMillis = intent.getLongExtra(EXTRA_EVENT_END_TIME, 0); attendeeResponse = intent.getIntExtra("attendeeStatus", Attendees.ATTENDEE_STATUS_NONE); Uri data = intent.getData(); if (data != null) { try { List<String> pathSegments = data.getPathSegments(); int size = pathSegments.size(); if (size > 2 && "EventTime".equals(pathSegments.get(2))) { // Support non-standard VIEW intent format: // dat = // content://com.android.calendar/events/[id]/EventTime/[start]/[end] mEventId = Long.parseLong(pathSegments.get(1)); if (size > 4) { mStartMillis = Long.parseLong(pathSegments.get(3)); mEndMillis = Long.parseLong(pathSegments.get(4)); } } else { mEventId = Long.parseLong(data.getLastPathSegment()); } } catch (NumberFormatException e) { if (mEventId == -1) { // do nothing here , deal with it later } else if (mStartMillis == 0 || mEndMillis == 0) { // Parsing failed on the start or end time , make sure // the times were not // pulled from the intent's extras and reset them. mStartMillis = 0; mEndMillis = 0; } } } } if (mEventId == -1) { Log.w(TAG, "No event id"); Toast.makeText(this, R.string.event_not_found, Toast.LENGTH_SHORT).show(); finish(); } // If we do not support showing full screen event info in this // configuration, // close the activity and show the event in AllInOne. Resources res = getResources(); if (!res.getBoolean(R.bool.agenda_show_event_info_full_screen) && !res.getBoolean(R.bool.show_event_info_full_screen)) { CalendarController.getInstance(this).launchViewEvent(mEventId, mStartMillis, mEndMillis, attendeeResponse); finish(); return; } setContentView(R.layout.simple_frame_layout); // Get the fragment if exists mInfoFragment = (EventInfoFragment) getSupportFragmentManager().findFragmentById(R.id.main_frame); // Remove the application title ActionBar bar = getActionBar(); if (bar != null) { bar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP); } // Create a new fragment if none exists if (mInfoFragment == null) { FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); mInfoFragment = new EventInfoFragment(this, mEventId, mStartMillis, mEndMillis, attendeeResponse, isDialog, (isDialog ? EventInfoFragment.DIALOG_WINDOW_STYLE : EventInfoFragment.FULL_WINDOW_STYLE), reminders); ft.replace(R.id.main_frame, mInfoFragment); ft.commit(); } }
From source file:com.asksven.commandcenter.BasicMasterFragment.java
/** * Helper function to show the details of a selected item, either by * displaying a fragment in-place in the current UI, or starting a * whole new activity in which it is displayed. */// w w w .j ava 2 s. c o m void showDetails(int key) { mCurCheckPosition = key; if (mDualPane) { // We can display everything in-place with fragments, so update // the list to highlight the selected item and show the data. getListView().setItemChecked(key, true); // Check what fragment is currently shown, replace if needed. BasicDetailsFragment details = (BasicDetailsFragment) getFragmentManager() .findFragmentById(R.id.details); if ((m_myCommand == null) || (details == null) || (details.getShownKey() != m_myCommand.getId())) { // Make new fragment to show this selection. details = BasicDetailsFragment.newInstance(key, m_strCollectionName); // Execute a transaction, replacing any existing fragment // with this one inside the frame. FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.details, details); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.commit(); } } else { // Otherwise we need to launch a new activity to display // the dialog fragment with selected text. Intent intent = new Intent(); intent.setClass(getActivity(), BasicDetailsActivity.class); intent.putExtra("index", key); intent.putExtra("collection", m_strCollectionName); startActivity(intent); } }