Ejemplo n.º 1
0
  @Override
  public void onAlbumListCellClicked(Album album) {

    // setFragment(FragmentDetail.TAG);

    Fragment temp = fragmentManager.findFragmentByTag(FragmentDetail.TAG);
    if (temp == null) {
      fragmentAlbumDetail = FragmentDetail.create(this);
      fragmentAlbumDetail.setAlbum(album);
      fragmentManager
          .beginTransaction()
          .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
          // .setCustomAnimations(R.anim.slide_right_in, R.anim.slide_right_out)
          .hide(currentFrag)
          .add(R.id.mainframe, fragmentAlbumDetail, FragmentDetail.TAG)
          .addToBackStack(FragmentDetail.TAG)
          .commit();

    } else {
      fragmentAlbumDetail = (FragmentDetail) temp;
      fragmentAlbumDetail.setAlbum(album);
      fragmentManager
          .beginTransaction()
          .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out)
          // .setCustomAnimations(R.anim.slide_right_in, R.anim.slide_right_out)
          .hide(currentFrag)
          .show(fragmentAlbumDetail)
          .commit();
    }
    // getSupportActionBar().setSubtitle("Albums");
    TextView tv =
        (TextView) getSupportActionBar().getCustomView().findViewById(R.id.action_bar_title);
    tv.setText(album.getAlbumName());
  }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.custom_action_bar);

    fragmentManager = getSupportFragmentManager();
    fragmentManager.addOnBackStackChangedListener(this);

    if (savedInstanceState == null) {
      Log.d("", "SavedInstance = null");
      // setFragment(FragmentList.TAG);
      fragmentAlbumList = FragmentList.create(this);
      fragmentManager = getSupportFragmentManager();
      fragmentManager
          .beginTransaction()
          .add(R.id.mainframe, fragmentAlbumList, FragmentList.TAG)
          .commit();

      currentFrag = fragmentAlbumList;

    } else {
      Log.d("", "SavedInstance != null");
      Fragment temp = fragmentManager.findFragmentByTag(FragmentList.TAG);
      if (temp != null) ((FragmentList) temp).setListener(this);

      temp = fragmentManager.findFragmentByTag(FragmentDetail.TAG);
      if (temp != null) ((FragmentDetail) temp).setListener(this);

      currentFrag = fragmentManager.getFragments().get(0);
    }
  }