List of usage examples for android.support.v4.app FragmentManager beginTransaction
public abstract FragmentTransaction beginTransaction();
From source file:HeaderGridView.java
/** added by Ahmed Basyouni * this method take supported fragment and fragment activity to add that * fragment as a banner to listView it create a layout at runtime then when * view is added to list we replace it with fragment otherwise it will crash * since view is not on screen to be replaced * * @param fragment//from ww w . j a v a2s . co m * @param activity */ public void addBannerFragment(final Fragment fragment, final FragmentActivity activity) { RelativeLayout layout = new RelativeLayout(activity); AbsListView.LayoutParams param = new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); layout.setLayoutParams(param); // please don't ever remove that view otherwise application will crash and I mean it :D View view = new View(activity); view.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, 300)); view.setVisibility(View.INVISIBLE); layout.addView(view); layout.setId(CONTAINER_ID); addHeaderView(layout); this.addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { HeaderGridView.this.removeOnLayoutChangeListener(this); FragmentManager manager = activity.getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(CONTAINER_ID, fragment).commit(); } }); }
From source file:com.digitalarx.android.ui.activity.FileActivity.java
/** * Show loading dialog // w ww.j a va 2s .c o m */ public void showLoadingDialog() { // Construct dialog LoadingDialog loading = new LoadingDialog(getResources().getString(R.string.wait_a_moment)); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); loading.show(ft, DIALOG_WAIT_TAG); }
From source file:com.akalizakeza.apps.ishusho.activity.NewPostActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_post_new); // find the retained fragment on activity restarts FragmentManager fm = getSupportFragmentManager(); mTaskFragment = (NewPostUploadTaskFragment) fm.findFragmentByTag(TAG_TASK_FRAGMENT); // create the fragment and data the first time if (mTaskFragment == null) { // add the fragment mTaskFragment = new NewPostUploadTaskFragment(); fm.beginTransaction().add(mTaskFragment, TAG_TASK_FRAGMENT).commit(); }/*from ww w. j av a 2 s .c o m*/ mImageView = (ImageView) findViewById(R.id.new_post_picture); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showImagePicker(); } }); Bitmap selectedBitmap = mTaskFragment.getSelectedBitmap(); Bitmap thumbnail = mTaskFragment.getThumbnail(); if (selectedBitmap != null) { mImageView.setImageBitmap(selectedBitmap); mResizedBitmap = selectedBitmap; } if (thumbnail != null) { mThumbnail = thumbnail; } final EditText descriptionText = (EditText) findViewById(R.id.new_post_text); mSubmitButton = (Button) findViewById(R.id.new_post_submit); mSubmitButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (mResizedBitmap == null) { Toast.makeText(NewPostActivity.this, "Select an image first.", Toast.LENGTH_SHORT).show(); return; } String postText = descriptionText.getText().toString(); if (TextUtils.isEmpty(postText)) { descriptionText.setError(getString(R.string.error_required_field)); return; } showProgressDialog(getString(R.string.post_upload_progress_message)); mSubmitButton.setEnabled(false); Long timestamp = System.currentTimeMillis(); String bitmapPath = "/" + FirebaseUtil.getCurrentUserId() + "/full/" + timestamp.toString() + "/"; String thumbnailPath = "/" + FirebaseUtil.getCurrentUserId() + "/thumb/" + timestamp.toString() + "/"; mTaskFragment.uploadPost(mResizedBitmap, bitmapPath, mThumbnail, thumbnailPath, mFileUri.getLastPathSegment(), postText); } }); }
From source file:com.codyy.rx.permissions.RxPermissions.java
private RxPermissionsFragment getRxPermissionsFragment( @NonNull android.support.v4.app.FragmentManager fragmentManager) { RxPermissionsFragment rxPermissionsFragment = findRxPermissionsFragment(fragmentManager); boolean isNewInstance = rxPermissionsFragment == null; if (isNewInstance) { rxPermissionsFragment = new RxPermissionsFragment(); fragmentManager.beginTransaction().add(rxPermissionsFragment, TAG).commitAllowingStateLoss(); fragmentManager.executePendingTransactions(); }//from w w w . j a va 2 s . c o m return rxPermissionsFragment; }
From source file:com.android.test.uibench.ShadowGridActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentById(android.R.id.content) == null) { ListFragment listFragment = new ListFragment() { @Override// w ww . j av a 2s. c o m public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getListView().setDivider(null); } }; listFragment.setListAdapter( new ArrayAdapter<>(this, R.layout.card_row, R.id.card_text, TextUtils.buildSimpleStringList())); fm.beginTransaction().add(android.R.id.content, listFragment).commit(); } }
From source file:com.chess.genesis.util.FragmentIntent.java
public void loadFrag(final FragmentManager fragMan) { final MenuBarFrag menuBar; final int menuLayout; switch (layoutId) { case R.id.panel01: menuLayout = R.id.topbar01;/*from ww w.j a va 2s.c o m*/ menuBar = new MenuBarFrag(act); break; case R.id.panel02: default: menuBar = new MenuBarFrag(); menuLayout = R.id.topbar02; break; case R.id.panel03: menuBar = new MenuBarFrag(); menuLayout = R.id.topbar03; break; } frag.setMenuBarFrag(menuBar); fragMan.beginTransaction().replace(menuLayout, menuBar, menuBar.getBTag()).replace(layoutId, frag, tag) .addToBackStack(tag).commit(); }
From source file:com.alivenet.dmvtaxi.fragment.FragmentRateYourRide.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.trip_completed, container, false); ratingBar = (RatingBar) view.findViewById(R.id.ratingbar); Text_tripcomplete_pickuplocation = (TextView) view.findViewById(R.id.tripcomplete_pickuplocation); Text_tripcomplete_dropoff_location = (TextView) view.findViewById(R.id.tripcomplete_dropoff_location); mname = (TextView) view.findViewById(R.id.tv_name); Text_tripcharged = (TextView) view.findViewById(R.id.tripcharged); mlicenceplate = (TextView) view.findViewById(R.id.tv_licenceplate); mtaname = (TextView) view.findViewById(R.id.tv_taname); mcommentbox = (EditText) view.findViewById(R.id.et_commentbox); btntip = (Button) view.findViewById(R.id.btntip); btnsubmit = (Button) view.findViewById(R.id.btnsubmit); icon = (ImageView) view.findViewById(R.id.tripcompltd_icons); mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE); mUserId = mPref.getString("userId", null); prgDialog = new ProgressDialog(getActivity()); prgDialog.setMessage("Please wait..."); prgDialog.setCancelable(false);//from w w w . j av a 2 s. c o m btntip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (MyApplication.RateyourRide == false) { LayoutInflater li = LayoutInflater.from(getContext()); View promptsView = li.inflate(R.layout.prompts, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(promptsView); tipValue = (EditText) promptsView.findViewById(R.id.edittip_value); // set dialog message alertDialogBuilder.setCancelable(false) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // get user input and set it to result // edit text if (tipValue.getText().toString().trim().length() == 0) { } else { btntip.setText(String.format("Tip: $ %.2f", Double.valueOf(tipValue.getText().toString()))); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); // create alert dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); getToken(mUserId); } } }); rideDriverComplete = sharedPreference.getDriverRidercompleate(getActivity()); String rideId = MyApplication.RideId; if (rideDriverComplete == null && rideId != null) { ValidateRidecomplet(mUserId, rideId); } if (MyApplication.RateyourRide == true) { btnsubmit.setVisibility(View.GONE); mcommentbox.setVisibility(View.GONE); } if (rideDriverComplete != null) { if (rideDriverComplete.getPickupaddress() != null && rideDriverComplete.getPickupaddress() != " " && rideDriverComplete.getDestinationaddress() != null && rideDriverComplete.getDestinationaddress() != " ") { Text_tripcomplete_pickuplocation.setText(rideDriverComplete.getPickupaddress()); Text_tripcomplete_dropoff_location.setText(rideDriverComplete.getDestinationaddress()); } try { Picasso.with(getActivity()).load(MyPreferences.getActiveInstance(getActivity()).getImageUrl()) .error(R.mipmap.avtar).placeholder(R.mipmap.avtar).into(icon); } catch (Exception e) { e.printStackTrace(); } mname.setText(rideDriverComplete.driverNameride); mlicenceplate.setText(rideDriverComplete.licenseId); mtaname.setText(rideDriverComplete.vehicle); Text_tripcharged .setText("$" + rideDriverComplete.getTotalfare() + " HAS BEEN CHARGED TO YOUR CREDIT CARD"); btnsubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String totalStars = "Total Stars:: " + ratingBar.getNumStars(); String rating = "Rating :: " + ratingBar.getRating(); String tip = ""; if (rideDriverComplete != null) { String driverid = rideDriverComplete.getDriverIdride(); String rideId = rideDriverComplete.getRideId(); if (tipValue != null) tip = tipValue.getText().toString(); String comment = mcommentbox.getText().toString(); if (driverid != null && rideId != null && totalStars != null && tip != null) { validateRideRating(mUserId, driverid, rideId, totalStars, tip, comment); } } } }); } view.setFocusableInTouchMode(true); view.requestFocus(); view.setOnKeyListener(new View.OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { // handle back button's click listener if (keyCode == KeyEvent.KEYCODE_BACK) { Fragment homeFragment = new FragmentMainScreen(); FragmentManager frgManager; frgManager = getFragmentManager(); frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit(); return true; } return true; } return false; } }); return view; }
From source file:com.app.blockydemo.ui.fragment.ScriptFragment.java
@Override public void onCategorySelected(String category) { AddBrickFragment addBrickFragment = AddBrickFragment.newInstance(category, this); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.script_fragment_container, addBrickFragment, AddBrickFragment.ADD_BRICK_FRAGMENT_TAG); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit();//w w w . j a va 2s. co m adapter.notifyDataSetChanged(); }
From source file:com.app.blockydemo.ui.fragment.ScriptFragment.java
private void showCategoryFragment() { BrickCategoryFragment brickCategoryFragment = new BrickCategoryFragment(); brickCategoryFragment.setOnCategorySelectedListener(this); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.script_fragment_container, brickCategoryFragment, BrickCategoryFragment.BRICK_CATEGORY_FRAGMENT_TAG); fragmentTransaction.addToBackStack(BrickCategoryFragment.BRICK_CATEGORY_FRAGMENT_TAG); fragmentTransaction.commit();//from w w w . j a v a 2s . co m adapter.notifyDataSetChanged(); }
From source file:cc.softwarefactory.lokki.android.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case R.id.add_people: // In Contacts (to add new ones) FragmentManager fragmentManager = getSupportFragmentManager(); AddContactsFragment acf = new AddContactsFragment(); acf.setContactUtils(mContactDataSource); fragmentManager.beginTransaction().replace(R.id.container, acf).commit(); selectedOption = -10;/*from w w w . j a va 2 s . c om*/ supportInvalidateOptionsMenu(); break; case R.id.allow_people: // In list of ALL contacts, when adding new ones. DialogUtils.addContact(this); break; case R.id.action_visibility: toggleVisibility(); break; case R.id.action_logout: logout(); break; } return super.onOptionsItemSelected(item); }