예제 #1
0
 @Override
 public void onPreRemove(FragmentTransaction transaction) {
   HomeFragment homeFragment = getHomeFragment();
   if (homeFragment != null) transaction.remove(homeFragment);
   PostFragment postFragment = getPostFragment();
   if (postFragment != null) transaction.remove(postFragment);
 }
예제 #2
0
  public void removeCurrent() {
    if (currentFragment != null) {
      currentFragment.setPrimaryFragment(false);
    }
    Fragment oldFrag = currentFragment;

    currentFragment = backStack.remove(backStack.size() - 1);
    currentFragment.setPrimaryFragment(true, false);
    supportInvalidateOptionsMenu();

    if (secondaryContainer == null) {
      FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
      trans.setCustomAnimations(
          R.anim.enter_from_left,
          R.anim.exit_to_right,
          R.anim.enter_from_right,
          R.anim.exit_to_left);
      trans.remove(oldFrag);
      trans.show(currentFragment);
      trans.commit();
    } else {
      FragmentTransaction trans = getSupportFragmentManager().beginTransaction();

      // Remove old right fragment
      trans.setCustomAnimations(
          R.anim.enter_from_left,
          R.anim.exit_to_right,
          R.anim.enter_from_right,
          R.anim.exit_to_left);
      trans.remove(oldFrag);

      // Only switch places if there is a backstack, otherwise primary container is correct
      if (backStack.size() > 0) {
        trans.setCustomAnimations(0, 0, 0, 0);
        // Add current left fragment to right side
        trans.remove(currentFragment);

        // Make sure remove is finished before adding
        trans.commit();
        getSupportFragmentManager().executePendingTransactions();

        trans = getSupportFragmentManager().beginTransaction();
        // trans.setCustomAnimations(R.anim.enter_from_left, R.anim.exit_to_right,
        // R.anim.enter_from_right, R.anim.exit_to_left);
        trans.add(
            R.id.fragment_second_container, currentFragment, currentFragment.getSupportTag() + "");

        SubsonicFragment newLeftFragment = backStack.get(backStack.size() - 1);
        newLeftFragment.setSecondaryFragment(true);
        trans.show(newLeftFragment);
      } else {
        secondaryContainer.startAnimation(AnimationUtils.loadAnimation(this, R.anim.exit_to_right));
        secondaryContainer.setVisibility(View.GONE);
      }

      trans.commit();
    }
    recreateSpinner();
  }
예제 #3
0
  @Override
  public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int size = savedInstanceState.getInt(Constants.MAIN_BACK_STACK_SIZE);
    String[] ids = savedInstanceState.getStringArray(Constants.MAIN_BACK_STACK);
    FragmentManager fm = getSupportFragmentManager();
    currentFragment = (SubsonicFragment) fm.findFragmentByTag(ids[0]);
    currentFragment.setPrimaryFragment(true);
    currentFragment.setSupportTag(ids[0]);
    supportInvalidateOptionsMenu();
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    for (int i = 1; i < size; i++) {
      SubsonicFragment frag = (SubsonicFragment) fm.findFragmentByTag(ids[i]);
      frag.setSupportTag(ids[i]);
      if (secondaryContainer != null) {
        frag.setPrimaryFragment(false, true);
      }
      trans.hide(frag);
      backStack.add(frag);
    }
    trans.commit();

    // Current fragment is hidden in secondaryContainer
    if (secondaryContainer == null && !currentFragment.isVisible()) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_container, currentFragment, ids[0]);
      trans.commit();
    }
    // Current fragment needs to be moved over to secondaryContainer
    else if (secondaryContainer != null
        && secondaryContainer.findViewById(currentFragment.getRootId()) == null
        && backStack.size() > 0) {
      trans = getSupportFragmentManager().beginTransaction();
      trans.remove(currentFragment);
      trans.show(backStack.get(backStack.size() - 1));
      trans.commit();
      getSupportFragmentManager().executePendingTransactions();

      trans = getSupportFragmentManager().beginTransaction();
      trans.add(R.id.fragment_second_container, currentFragment, ids[0]);
      trans.commit();

      secondaryContainer.setVisibility(View.VISIBLE);
    }

    lastSelectedPosition = savedInstanceState.getInt(Constants.FRAGMENT_POSITION);
    if (lastSelectedPosition != 0) {
      MenuItem item = drawerList.getMenu().findItem(lastSelectedPosition);
      if (item != null) {
        item.setChecked(true);
      }
    }
    recreateSpinner();
  }
 @Override
 public void onPostExecute(Object result) {
   FragmentManager m = getSupportFragmentManager();
   FragmentTransaction t = m.beginTransaction();
   t.remove(m.findFragmentByTag("SAVE_TASK"));
   t.remove(m.findFragmentByTag("PROGRESS"));
   t.commitAllowingStateLoss();
 }
  @Override
  public void onEmotionCategorySelected(int category) {
    final FragmentManager fm = getSupportFragmentManager();
    FragmentTransaction ft = fm.beginTransaction();
    final Fragment categoryFragment =
        getSupportFragmentManager().findFragmentByTag(EMOTION_CATEGORY_TAG);
    if (categoryFragment != null) ft.remove(categoryFragment);
    ft.commit();

    ft = fm.beginTransaction();
    final Fragment prev = getSupportFragmentManager().findFragmentByTag(EMOTION_TAG);
    if (prev != null) {
      ft.remove(prev);
    }

    DialogFragment newFragment = null;
    switch (category) {
      case CATEGORY_BASIC:
        newFragment = new EmotionDialogFragment();
        break;
      case CATEGORY_BAOZOU:
      case CATEGORY_XIONGMAO:
      case CATEGORY_TAIJUN:
      case CATEGORY_ALI:
      case CATEGORY_DAYANMAO:
      case CATEGORY_LUOXIAOHEI:
      case CATEGORY_MAJIANGLIAN:
      case CATEGORY_ZHAIYIN:
      case CATEGORY_YANGCONGTOU:
      case CATEGORY_ACNIANG:
      case CATEGORY_BIERDE:
      case CATEGORY_LINDABI:
      case CATEGORY_QUNIANG:
      case CATEGORY_NIWEIHEZHEMEDIAO:
      case CATEGORY_PST:
      case CATEGORY_DT:
        Bundle args = new Bundle();
        args.putInt("index", category - 1);
        newFragment = new ExtensionEmotionFragment();
        newFragment.setArguments(args);
        break;
      default:
    }
    // ft.commit();
    // ft.addToBackStack(null);

    if (newFragment != null) {
      ft.commit();
      newFragment.show(fm, EMOTION_TAG);
    }
  }
예제 #6
0
 public void onClick_btn3(View v) {
   ft = getSupportFragmentManager().beginTransaction();
   ft.remove(btn1_Fragment);
   ft.remove(btn2_Fragment);
   ft.add(R.id.btn1_fragment, btn3_Fragment);
   ft.commit();
 }
예제 #7
0
 private <T extends Fragment> void showFragment(
     FragmentManager manager,
     FragmentTransaction fragmentTransaction,
     String tag,
     Class<T> cl,
     boolean cond) {
   try {
     Fragment frag = manager.findFragmentByTag(tag);
     if (manager.findFragmentByTag(tag) == null) {
       if (cond) {
         T ni = cl.newInstance();
         fragmentTransaction.add(R.id.content, ni, tag);
       }
     } else {
       if (!cond) {
         fragmentTransaction.remove(manager.findFragmentByTag(tag));
       } else if (frag instanceof DashBaseFragment) {
         if (((DashBaseFragment) frag).getView() != null) {
           ((DashBaseFragment) frag).onOpenDash();
         }
       }
     }
   } catch (Exception e) {
     getMyApplication().showToastMessage("Error showing dashboard " + tag);
     e.printStackTrace();
   }
 }
예제 #8
0
  public static void RecreateFragemnt(
      FragmentManager manager, String fragmentName, int containerId, String tag) {
    List<Fragment> fragments = manager.getFragments();
    FragmentTransaction transaction = manager.beginTransaction();
    boolean isexist = false;
    try {
      for (Fragment fragment : fragments) {
        transaction.hide(fragment);
        if (fragment.getClass().toString().contains(fragmentName)) {
          transaction.remove(fragment);
          Class c = Class.forName(fragmentName);
          Fragment newfragment = (Fragment) c.newInstance();
          transaction.add(containerId, newfragment, tag);
          isexist = true;
          transaction.show(newfragment);
        }
      }
      if (!isexist) {
        Class c = Class.forName(fragmentName);
        Fragment newfragment = (Fragment) c.newInstance();
        transaction.add(containerId, newfragment, tag);
        transaction.show(newfragment);
      }
      transaction.commit();
    } catch (Exception ex) {

    }
  }
예제 #9
0
 protected void dismissProgressDialog() {
   FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
   Fragment prev = getExistingDialogFragment();
   if (prev != null) {
     ft.remove(prev).commit();
   }
 }
  private void selectMenuSection(int position) {
    Section section = menuAdapter.getItem(position);
    if (section != currentSection) {
      // Switch to new section
      FragmentManager fm = getSupportFragmentManager();
      FragmentTransaction ft = fm.beginTransaction();
      Fragment f = fm.findFragmentById(R.id.content);
      if (f != null) {
        if (currentSection.shouldKeep()) {
          ft.detach(f);
        } else {
          ft.remove(f);
        }
      }
      String fragmentClassName = section.getFragmentClassName();
      if (section.shouldKeep() && ((f = fm.findFragmentByTag(fragmentClassName)) != null)) {
        ft.attach(f);
      } else {
        f = Fragment.instantiate(MainActivity.this, fragmentClassName);
        ft.add(R.id.content, f, fragmentClassName);
      }
      ft.commit();

      currentSection = section;
      updateActionBar();
      menuAdapter.notifyDataSetChanged();
    }
  }
 @Override
 public void onAbort() {
   setResult(RESULT_CANCELED, null);
   FragmentTransaction ft = getSherlockActivity().getSupportFragmentManager().beginTransaction();
   ft.remove(this);
   ft.commit();
 }
예제 #12
0
  /** Set Design of ActionBar */
  @Override
  protected void onStart() {
    super.onStart();
    ActionBar actionBar = this.getSupportActionBar();
    actionBar.setSubtitle(R.string.app_subtitle);

    // add WebserverFragment when enabled in preferences
    if (PreferenceHelper.getWebserverEnabled(this)) {
      FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

      mWebserverFragment = new WebserverFragment();
      // replace container in view with fragment
      fragmentTransaction.replace(R.id.base_activity_webserver_container, mWebserverFragment);
      fragmentTransaction.commit();
    } else {
      // when disabled in preferences remove fragment if existing
      if (mWebserverFragment != null) {
        FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();

        fragmentTransaction.remove(mWebserverFragment);
        fragmentTransaction.commit();

        mWebserverFragment = null;
      }
    }
  }
  private void displayView(int position) {

    String title = getString(R.string.app_name);
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    switch (position) {
      case 0:
        fragment = new HomeFragment();
        title = getString(R.string.title_home);
        fragmentTransaction.replace(R.id.content_frame, fragment);
        break;
      case 1:
        //                fragment = new FriendsFragment();
        //                title = getString(R.string.title_friends);
        fragmentTransaction.remove(fragment);
        break;
      case 2:
        //                fragment = new MessagesFragment();
        //                title = getString(R.string.title_messages);
        break;
      default:
        break;
    }

    if (fragment != null) {

      fragmentTransaction.commit();

      // set the toolbar title
      getSupportActionBar().setTitle(title);
    }
  }
예제 #14
0
  @Override
  public void onNavigationDrawerItemSelected(int position) {

    FragmentManager fragmentManager = getSupportFragmentManager();
    Fragment nextFragment;

    switch (position) {
      default:
      case 0:
        nextFragment = new ListOfBooks();
        break;
      case 1:
        nextFragment = new AddBook();
        break;
      case 2:
        nextFragment = new About();
        break;
    }

    FragmentTransaction transaction = fragmentManager.beginTransaction();

    Fragment bookDetailsFragment =
        fragmentManager.findFragmentByTag(BookDetail.class.getSimpleName());
    if (bookDetailsFragment != null) transaction.remove(bookDetailsFragment);

    // AlexSt: Nagigation drawer is intended to for switching between fragments
    // 'Back' button should not manage switching ortherwise it would create mess
    // and confusion
    transaction
        .replace(R.id.container, nextFragment)
        /*.addToBackStack((String) title)*/
        .commit();
  }
  /** Instantiate and show the Picker */
  public void show() {
    if (manager == null || styleResId == null) {
      Log.e("NumberPickerBuilder", "setFragmentManager() and setStyleResId() must be called.");
      return;
    }
    final FragmentTransaction ft = manager.beginTransaction();
    final Fragment prev = manager.findFragmentByTag("number_dialog");
    if (prev != null) {
      ft.remove(prev);
    }
    ft.addToBackStack(null);

    final NumberPickerDialogFragment fragment =
        NumberPickerDialogFragment.newInstance(
            mReference,
            styleResId,
            minNumber,
            maxNumber,
            plusMinusVisibility,
            decimalVisibility,
            labelText,
            currentNumberValue,
            currentDecimalValue,
            currentSignValue);
    if (targetFragment != null) {
      fragment.setTargetFragment(targetFragment, 0);
    }
    fragment.setNumberPickerDialogHandlers(mNumberPickerDialogHandlers);
    fragment.setNumberPickerDialogHandlersV2(mNumberPickerDialogHandlersV2);
    fragment.show(ft, "number_dialog");
  }
예제 #16
0
 public void dismissDialog(SherlockFragmentActivity activity) {
   Fragment prev = activity.getSupportFragmentManager().findFragmentByTag(getTag());
   if (prev != null) {
     FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
     ft.remove(prev);
     ft.commit();
   }
 }
예제 #17
0
 public static void RemoveAllFragemnt(FragmentManager manager) {
   List<Fragment> fragments = manager.getFragments();
   FragmentTransaction transaction = manager.beginTransaction();
   for (Fragment fragment : fragments) {
     transaction.remove(fragment);
   }
   transaction.commit();
 }
 public void remove() {
   FragmentElement lastFragment = popInternal();
   if (lastFragment != null) {
     FragmentTransaction transaction = fm.beginTransaction();
     transaction.remove(lastFragment.getFragment());
     transaction.commitAllowingStateLoss();
   }
 }
 public static FragmentTransaction removePrevDialog(FragmentManager fm) {
   FragmentTransaction ft = fm.beginTransaction();
   Fragment prev = fm.findFragmentByTag("dialog");
   if (prev != null) {
     ft.remove(prev);
   }
   ft.addToBackStack(null);
   return ft;
 }
 @Override
 public void handleMessage(Message msg) {
   if (activeDetailsFragment != null) {
     FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
     fragmentTransaction.remove(activeDetailsFragment);
     fragmentTransaction.commit();
     showEmptyDetails();
   }
 }
예제 #21
0
  private void dismiss() {
    if (dismissed) return;

    dismissed = true;
    getFragmentManager().popBackStack();
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.remove(this);
    ft.commit();
  }
예제 #22
0
 public void show(FragmentActivity activity) {
   String tag = getClass().getName();
   FragmentManager fm = activity.getSupportFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   Fragment f = fm.findFragmentByTag(tag);
   if (f != null) {
     ft.remove(f);
   }
   show(ft, tag);
 }
  public static void dismiss(FragmentActivity activity) {
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    Fragment prev = fragmentManager.findFragmentByTag(FRAGMENT_TAG);
    if (prev != null) {
      fragmentTransaction.remove(prev);
    }
    fragmentTransaction.commit();
  }
예제 #24
0
  /** Remove MessageViewFragment if necessary. */
  private void removeMessageViewFragment() {
    if (mMessageViewFragment != null) {
      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      ft.remove(mMessageViewFragment);
      mMessageViewFragment = null;
      ft.commit();

      showDefaultTitleView();
    }
  }
예제 #25
0
  public void replaceExistingFragment(SubsonicFragment fragment, int tag) {
    FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
    trans.remove(currentFragment);
    trans.add(R.id.fragment_container, fragment, tag + "");
    trans.commit();

    currentFragment = fragment;
    currentFragment.setPrimaryFragment(true);
    supportInvalidateOptionsMenu();
  }
예제 #26
0
  public void showDialog(SherlockFragmentActivity activity) {
    Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
    FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
    if (prev != null) {
      ft.remove(prev);
    }
    ft.addToBackStack(null);

    this.show(ft, "dialog");
  }
예제 #27
0
  @Override
  public void destroyItem(ViewGroup container, int position, Object object) {
    super.destroyItem(container, position, object);

    if (position <= getCount()) {
      FragmentManager manager = ((Fragment) object).getFragmentManager();
      FragmentTransaction trans = manager.beginTransaction();
      trans.remove((Fragment) object);
      trans.commit();
    }
  }
예제 #28
0
 /**
  * Remove existing fragment with same tag and add new one.
  *
  * @param context context
  * @param manager fragment manager
  * @param tx existing transaction
  * @param containerId container
  * @param info fragment definition
  */
 public static void addFragment(
     Context context,
     FragmentManager manager,
     FragmentTransaction tx,
     int containerId,
     FragmentElement element) {
   Fragment existing = manager.findFragmentByTag(element.name);
   if (existing != null) tx.remove(existing);
   Log.d("FragmentManager", "Instantiated new Fragment: " + element.name);
   tx.add(containerId, element.instantiate(context), element.name);
 }
  public void performActionWithDialogFragment(
      SherlockFragmentActivity activity, DialogFragment dialogFragment) {

    FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
    Fragment prev = activity.getSupportFragmentManager().findFragmentByTag("dialog");
    if (prev != null) {
      ft.remove(prev);
    }
    ft.addToBackStack(null);
    dialogFragment.show(ft, "dialog");
  }
예제 #30
0
  private void showHideEventsDialog() {
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    Fragment prev = getFragmentManager().findFragmentByTag("dialog");
    if (prev != null) {
      ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = HideEventsDialog.newInstance(adapter.buffer);
    newFragment.show(ft, "dialog");
  }