Example usage for android.app FragmentTransaction addToBackStack

List of usage examples for android.app FragmentTransaction addToBackStack

Introduction

In this page you can find the example usage for android.app FragmentTransaction addToBackStack.

Prototype

public abstract FragmentTransaction addToBackStack(@Nullable String name);

Source Link

Document

Add this transaction to the back stack.

Usage

From source file:de.sourcestream.movieDB.controller.MovieDetailsInfo.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *///w ww.j  a va  2 s.c o m
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    activity.setRestoreMovieDetailsAdapterState(true);
    activity.setRestoreMovieDetailsState(false);
    if (activity.getMovieDetailsSimFragment() != null
            && activity.getLastVisitedSimMovie() == similarList.get(position).getId()
            && activity.getMovieDetailsSimFragment().getTimeOut() == 0) {
        // Old movie details retrieve info and re-init component else crash
        activity.getMovieDetailsSimFragment().onSaveInstanceState(new Bundle());
        Bundle bundle = new Bundle();
        bundle.putInt("id", similarList.get(position).getId());
        Bundle save = activity.getMovieDetailsSimFragment().getSave();
        // Re-init movie details and set save information
        movieDetails = new MovieDetails();
        movieDetails.setTimeOut(0);
        movieDetails.setSave(save);
        movieDetails.setArguments(bundle);
    } else
        movieDetails = new MovieDetails();

    activity.setLastVisitedSimMovie(similarList.get(position).getId());
    activity.getMovieDetailsFragment().setAddToBackStack(true);
    activity.getMovieDetailsFragment().onSaveInstanceState(new Bundle());
    if (activity.getSearchViewCount())
        activity.incSearchMovieDetails();

    activity.setMovieDetailsFragment(null);
    activity.setSaveInMovieDetailsSimFragment(true);
    movieDetails.setTitle(similarList.get(position).getTitle());
    FragmentManager manager = getActivity().getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle bundle = new Bundle();
    bundle.putInt("id", similarList.get(position).getId());
    movieDetails.setArguments(bundle);
    transaction.replace(R.id.frame_container, movieDetails);
    // add the current transaction to the back stack:
    transaction.addToBackStack("similarDetails");
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

public void advanced_query(MenuItem item) {

    SearchFrame new_fragment = new SearchFrame();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();//from w ww  . j a va  2  s. c o m

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#ff8800"));
    authButton.setVisibility(View.INVISIBLE);

}

From source file:itcr.gitsnes.MainActivity.java

/** Inflates mainFrame/ListView with the next params from advanced_search layout:
 *      - name: if name isn't null// w  ww . j a v  a  2s.c o  m
 *      - category: if category is different to empty
 */
public void searching(View view) {
    EditText name = (EditText) this.findViewById(R.id.src_name);
    EditText category = (EditText) this.findViewById(R.id.src_category);

    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQname(name.getText().toString());
    new_fragment.setQcat(category.getText().toString());

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#009f28"));
    authButton.setVisibility(View.INVISIBLE);

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:by.zatta.pilight.MainActivity.java

@Override
public void onLanguageListener(String language) {
    makeLocale(language);//  w w  w . j ava  2  s. co m
    invalidateOptionsMenu();
    initMenu();
    FragmentManager fm = getFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    fm.popBackStack();
    ft.replace(R.id.fragment_main, new PrefFragment(), "prefs");
    ft.addToBackStack(null);
    ft.commit();
}

From source file:itcr.gitsnes.MainActivity.java

public void goList(MenuItem item) {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);// w w w  .  j a va 2s .  c  o  m
    String input = new BackendHandler().readJSON();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#009f28"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

/**
 *  Method to go mainFrame// w ww .  j ava2 s  .c  o m
 */
public void back_stage() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    String input = new BackendHandler().readJSON();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
        Log.i(TAG, e.toString());
    }

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#009f28"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

public void adminMenu(MenuItem item) {

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);/*from w  w  w  .  ja  v  a  2 s.  c om*/
    String input = new BackendHandler().readJSON();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }

    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#d0ff00"));
    authButton.setVisibility(View.INVISIBLE);

    AdminFrame new_fragment = new AdminFrame(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:itcr.gitsnes.MainActivity.java

/** Create a frame with the favorites games of the user
 * call moreliked GET method *///w  w w . j  a v a  2s  . c  om
public void getFavorites(MenuItem item) {
    /* Async mode*/
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    /* Build json*/
    String input = new BackendHandler().getFavorites();
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }
    /* Commit fragment transaction (master view)*/
    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#70d4b0"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();
}

From source file:itcr.gitsnes.MainActivity.java

/** Create a frame with the favorites games of the user
 * call recomended GET method *///from www  .ja  v a2 s.c  o  m
public void getRecomended(MenuItem item) {
    /* Async mode*/
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    /* Build json*/
    String input = new BackendHandler().get_Recommended(new KeyStore().getCurrent_user());
    try {
        json_arr = new JSONArray(input);
    } catch (JSONException e) {
        Log.i(TAG, e.toString());
    }
    /* Commit fragment transaction (master view)*/
    RelativeLayout rl = (RelativeLayout) this.findViewById(R.id.mainback);
    rl.setBackgroundColor(Color.parseColor("#e7df00"));
    authButton.setVisibility(View.INVISIBLE);
    MasterGames new_fragment = new MasterGames(json_arr);
    new_fragment.setQtype("all");

    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.placeholder, new_fragment);
    transaction.addToBackStack(null);
    transaction.commit();

}

From source file:de.sourcestream.movieDB.controller.TVDetailsInfo.java

/**
 * Callback method to be invoked when an item in this AdapterView has been clicked.
 *
 * @param parent   The AdapterView where the click happened.
 * @param view     The view within the AdapterView that was clicked (this will be a view provided by the adapter)
 * @param position The position of the view in the adapter.
 * @param id       The row id of the item that was clicked.
 *///w  ww  .  j a v  a 2  s . com
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    activity.setRestoreMovieDetailsAdapterState(true);
    activity.setRestoreMovieDetailsState(false);
    if (activity.getTvDetailsSimFragment() != null
            && activity.getLastVisitedSimTV() == similarList.get(position).getId()
            && activity.getTvDetailsSimFragment().getTimeOut() == 0) {
        // Old tv details retrieve info and re-init component else crash
        activity.getTvDetailsSimFragment().onSaveInstanceState(new Bundle());
        Bundle bundle = new Bundle();
        bundle.putInt("id", similarList.get(position).getId());
        Bundle save = activity.getTvDetailsSimFragment().getSave();
        // Re-init movie details and set save information
        tvDetails = new TVDetails();
        tvDetails.setTimeOut(0);
        tvDetails.setSave(save);
        tvDetails.setArguments(bundle);
    } else
        tvDetails = new TVDetails();

    activity.setLastVisitedSimTV(similarList.get(position).getId());
    activity.getTvDetailsFragment().setAddToBackStack(true);
    activity.getTvDetailsFragment().onSaveInstanceState(new Bundle());
    if (activity.getSearchViewCount())
        activity.incSearchTvDetails();

    activity.setTvDetailsFragment(null);
    activity.setSaveInTVDetailsSimFragment(true);
    tvDetails.setTitle(similarList.get(position).getTitle());
    FragmentManager manager = getActivity().getFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    Bundle bundle = new Bundle();
    bundle.putInt("id", similarList.get(position).getId());
    tvDetails.setArguments(bundle);
    transaction.replace(R.id.frame_container, tvDetails);
    // add the current transaction to the back stack:
    transaction.addToBackStack("similarDetails");
    transaction.commit();

}