Search in sources :

Example 96 with FragmentManager

use of androidx.fragment.app.FragmentManager in project IITB-App by wncc.

the class WebViewFragment method openBody.

private void openBody(Body body) {
    Utils.bodyCache.invalidateCache(body);
    BodyFragment bodyFragment = BodyFragment.newInstance(body);
    FragmentManager manager = getActivity().getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    transaction.setCustomAnimations(R.anim.slide_in_up, R.anim.fade_out, R.anim.fade_in, R.anim.slide_out_down);
    transaction.replace(R.id.framelayout_for_fragment, bodyFragment, bodyFragment.getTag());
    transaction.addToBackStack(bodyFragment.getTag()).commit();
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction)

Example 97 with FragmentManager

use of androidx.fragment.app.FragmentManager in project IITB-App by wncc.

the class FileComplaintFragment method addComplaint.

private void addComplaint() {
    final String complaint = descriptionAutoCompleteTextview.getText().toString();
    final String suggestion;
    final String locationDetails;
    if (!(editTextSuggestions.getText().toString().isEmpty())) {
        suggestion = editTextSuggestions.getText().toString();
    } else {
        suggestion = "";
    }
    if (!(editTextLocationDetails.getText().toString().isEmpty())) {
        locationDetails = editTextLocationDetails.getText().toString();
    } else {
        locationDetails = "";
    }
    if (Location == null) {
        // Show an explanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response!
        new AlertDialog.Builder(getContext()).setTitle("Location Needed").setMessage("You have not specified your location. The app will by default make \"IIT Area\" as your location.").setPositiveButton("OK", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                Location = new LatLng(19.133810, 72.913257);
                Address = "IIT Area";
                ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
                RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
                retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {

                    @Override
                    public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
                        Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
                        Bundle bundle = getArguments();
                        bundle.putString(Constants.USER_ID, userId);
                        ComplaintsFragment complaintsFragment = new ComplaintsFragment();
                        complaintsFragment.setArguments(bundle);
                        FragmentManager manager = getFragmentManager();
                        FragmentTransaction transaction = manager.beginTransaction();
                        transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
                        transaction.addToBackStack(complaintsFragment.getTag());
                        manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
                        transaction.commit();
                    }

                    @Override
                    public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
                        Log.i(TAG, "failure in addComplaint: " + t.toString());
                        Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getContext(), "Submission aborted", Toast.LENGTH_SHORT).show();
                dialog.cancel();
            }
        }).create().show();
    } else {
        ComplaintCreateRequest complaintCreateRequest = new ComplaintCreateRequest(complaint, suggestion, locationDetails, Address, (float) Location.latitude, (float) Location.longitude, Tags, uploadedImagesUrl);
        RetrofitInterface retrofitInterface = Utils.getRetrofitInterface();
        retrofitInterface.postComplaint("sessionid=" + getArguments().getString(Constants.SESSION_ID), complaintCreateRequest).enqueue(new Callback<ComplaintCreateResponse>() {

            @Override
            public void onResponse(Call<ComplaintCreateResponse> call, Response<ComplaintCreateResponse> response) {
                Toast.makeText(getContext(), "Complaint successfully posted", Toast.LENGTH_LONG).show();
                Bundle bundle = getArguments();
                bundle.putString(Constants.USER_ID, userId);
                ComplaintsFragment complaintsFragment = new ComplaintsFragment();
                complaintsFragment.setArguments(bundle);
                FragmentManager manager = getFragmentManager();
                FragmentTransaction transaction = manager.beginTransaction();
                transaction.replace(R.id.framelayout_for_fragment, complaintsFragment, complaintsFragment.getTag());
                transaction.addToBackStack(complaintsFragment.getTag());
                manager.popBackStackImmediate("Complaint Fragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);
                transaction.commit();
            }

            @Override
            public void onFailure(Call<ComplaintCreateResponse> call, Throwable t) {
                Log.i(TAG, "failure in addComplaint: " + t.toString());
                Toast.makeText(getContext(), "Complaint Creation Failed", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
Also used : DialogInterface(android.content.DialogInterface) ComplaintCreateResponse(app.insti.api.response.ComplaintCreateResponse) Bundle(android.os.Bundle) FragmentManager(androidx.fragment.app.FragmentManager) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ComplaintCreateRequest(app.insti.api.request.ComplaintCreateRequest) LatLng(com.google.android.gms.maps.model.LatLng) RetrofitInterface(app.insti.api.RetrofitInterface)

Example 98 with FragmentManager

use of androidx.fragment.app.FragmentManager in project zype-android by zype.

the class VideoCastControllerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cast_activity);
    loadAndSetupViews();
    mCastManager = VideoCastManager.getInstance();
    mVolumeIncrement = mCastManager.getVolumeStep();
    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        finish();
        return;
    }
    Bundle mediaWrapper = extras.getBundle(VideoCastManager.EXTRA_MEDIA);
    String title = mediaWrapper.getString(MediaMetadata.KEY_TITLE);
    setUpActionBar(title);
    FragmentManager fm = getSupportFragmentManager();
    VideoCastControllerFragment videoCastControlleFragment = (VideoCastControllerFragment) fm.findFragmentByTag(TASK_TAG);
    // if fragment is null, it means this is the first time, so create it
    if (videoCastControlleFragment == null) {
        videoCastControlleFragment = VideoCastControllerFragment.newInstance(extras);
        fm.beginTransaction().add(videoCastControlleFragment, TASK_TAG).commit();
        mListener = videoCastControlleFragment;
        setOnVideoCastControllerChangedListener(mListener);
    } else {
        mListener = videoCastControlleFragment;
        mListener.onConfigurationChanged();
    }
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Bundle(android.os.Bundle)

Example 99 with FragmentManager

use of androidx.fragment.app.FragmentManager in project twicalico by moko256.

the class MainActivity method clearAndPrepareFragment.

private void clearAndPrepareFragment() {
    Fragment top = new HomeTimeLineFragment();
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
    fragmentManager.beginTransaction().replace(R.id.mainLayout, top).commit();
    attachFragment(top);
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Fragment(androidx.fragment.app.Fragment)

Example 100 with FragmentManager

use of androidx.fragment.app.FragmentManager in project FlexibleAdapter by davideas.

the class MainActivity method onNavigationItemSelected.

/* =======================================
	 * NAVIGATION DRAWER & FRAGMENT MANAGEMENT
	 * ======================================= */
/**
 * IMPORTANT!! READ THE COMMENT FOR THE FRAGMENT REPLACE
 */
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    hideFabSilently();
    // Handle navigation view item clicks
    int id = item.getItemId();
    if (id == R.id.nav_overall) {
        mFragment = FragmentOverall.newInstance(2);
    } else if (id == R.id.nav_selection_modes) {
        mFragment = FragmentSelectionModes.newInstance(2);
    } else if (id == R.id.nav_filter) {
        mFragment = FragmentAsyncFilter.newInstance(true);
    } else if (id == R.id.nav_animator) {
        mFragment = FragmentAnimators.newInstance();
    } else if (id == R.id.nav_endless_scrolling) {
        mFragment = FragmentEndlessScrolling.newInstance(2);
        showFab();
    } else if (id == R.id.nav_instagram_headers) {
        mFragment = FragmentInstagramHeaders.newInstance();
    } else if (id == R.id.nav_db_headers_and_sections) {
        mFragment = FragmentDataBinding.newInstance(2);
    } else if (id == R.id.nav_headers_and_sections) {
        mFragment = FragmentHeadersSections.newInstance(2);
        showFab();
    } else if (id == R.id.nav_multi_level_expandable) {
        mFragment = FragmentExpandableMultiLevel.newInstance(2);
    } else if (id == R.id.nav_expandable_sections) {
        mFragment = FragmentExpandableSections.newInstance(3);
        showFab();
    } else if (id == R.id.nav_staggered) {
        mFragment = FragmentStaggeredLayout.newInstance(2);
    } else if (id == R.id.nav_model_holders) {
        mFragment = FragmentHolderSections.newInstance();
    } else if (id == R.id.nav_viewpager) {
        Intent intent = new Intent(this, ViewPagerActivity.class);
        ActivityOptionsCompat activityOptionsCompat = ActivityOptionsCompat.makeBasic();
        ActivityCompat.startActivity(this, intent, activityOptionsCompat.toBundle());
        // Close drawer
        mRecyclerView.post(new Runnable() {

            @Override
            public void run() {
                mDrawer.closeDrawer(GravityCompat.START);
            }
        });
        return true;
    } else if (id == R.id.nav_about) {
        MessageDialog.newInstance(R.drawable.ic_info_grey600_24dp, getString(R.string.about_title), getString(R.string.about_body, Utils.getVersionName(this))).show(getFragmentManager(), MessageDialog.TAG);
        return true;
    } else if (id == R.id.nav_github) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://github.com/davideas/FlexibleAdapter"));
        startActivity(Intent.createChooser(intent, getString(R.string.intent_chooser)));
        return true;
    }
    // Insert the fragment by replacing any existing fragment
    if (mFragment != null) {
        // Highlight the selected item has been done by NavigationView
        item.setChecked(true);
        // THIS IS VERY IMPORTANT. Because you are going to inflate a new RecyclerView, its
        // Adapter will be null, therefore the following method cannot be called automatically!
        // If your StickyHeaderContainer is in the main view, you must call this method to clean
        // the previous sticky view. Alternatively you can move the <include> of StickyHeaderLayout
        // in the Fragment view.
        mAdapter.onDetachedFromRecyclerView(mRecyclerView);
        // Inflate the new Fragment with the new RecyclerView and a new Adapter
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.recycler_view_container, mFragment).commit();
        // Close drawer
        mRecyclerView.post(new Runnable() {

            @Override
            public void run() {
                mDrawer.closeDrawer(GravityCompat.START);
            }
        });
        // mToolbar.setSubtitle(item.getTitle());
        mHeaderView.bindTo(getString(R.string.app_name), item.getTitle());
        return true;
    }
    return false;
}
Also used : FragmentManager(androidx.fragment.app.FragmentManager) Intent(android.content.Intent) ActivityOptionsCompat(androidx.core.app.ActivityOptionsCompat)

Aggregations

FragmentManager (androidx.fragment.app.FragmentManager)163 FragmentTransaction (androidx.fragment.app.FragmentTransaction)55 Fragment (androidx.fragment.app.Fragment)42 Bundle (android.os.Bundle)28 Test (org.junit.Test)15 Intent (android.content.Intent)13 FragmentActivity (androidx.fragment.app.FragmentActivity)10 Activity (android.app.Activity)6 View (android.view.View)6 DialogFragment (androidx.fragment.app.DialogFragment)6 TaskRetainerFragment (com.owncloud.android.ui.fragment.TaskRetainerFragment)5 Context (android.content.Context)4 DialogInterface (android.content.DialogInterface)3 LayoutInflater (android.view.LayoutInflater)3 MenuInflater (android.view.MenuInflater)3 Window (android.view.Window)3 TextView (android.widget.TextView)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3