Пример #1
0
    @Override
    public Fragment getItem(int position) {
      Fragment fragment = null;
      Bundle args = new Bundle();
      switch (position) {
        case 0:
          fragment = new manualControlPage();
          fragments.add(0, fragment.getTag());
          break;
        case 1:
          fragment = new programPage();
          fragments.add(1, fragment.getTag());
          break;
        case 2:
          fragment = new settingsPage();

          fragments.add(2, fragment.getTag());
          break;
        case 3:
          fragment = new logginPage();
          ((logginPage) fragment).setLogs(logs);
          args.putBoolean("alreadySent", true);
          // fragment.setArguments(args);
          fragments.add(3, fragment.getTag());
          break;
      }
      return fragment;
    }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    if (item.getItemId() == R.id.map_view) {
      category =
          (getArguments() != null) ? getArguments().getString(SearchFragment.ARG_CATEGORY) : null;
      if (category != null) {
        MapManager.switchToMapView(category, HomeFragment.ARG_POI_CATEGORY, this);
      } else {
        ArrayList<BaseDTObject> target = new ArrayList<BaseDTObject>();
        for (int i = 0; i < list.getAdapter().getCount(); i++) {
          BaseDTObject o = (BaseDTObject) list.getAdapter().getItem(i);
          target.add(o);
        }
        MapManager.switchToMapView(target, this);
      }
      return true;
    } else if (item.getItemId() == R.id.menu_item_addpoi) {
      {
        FragmentTransaction fragmentTransaction =
            getSherlockActivity().getSupportFragmentManager().beginTransaction();
        Fragment fragment = new CreatePoiFragment();
        Bundle args = new Bundle();
        args.putString(SearchFragment.ARG_CATEGORY, category);
        fragment.setArguments(args);
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        // fragmentTransaction.detach(this);
        fragmentTransaction.replace(R.id.fragment_container, fragment, "pois");
        fragmentTransaction.addToBackStack(fragment.getTag());
        fragmentTransaction.commit();
        reload = true;
        return true;
      }
    } else if (item.getItemId() == R.id.submenu_search) {
      FragmentTransaction fragmentTransaction;
      Fragment fragment;
      fragmentTransaction = getSherlockActivity().getSupportFragmentManager().beginTransaction();
      fragment = new SearchFragment();
      Bundle args = new Bundle();
      args.putString(SearchFragment.ARG_CATEGORY, category);
      args.putString(CategoryHelper.CATEGORY_TYPE_POIS, CategoryHelper.CATEGORY_TYPE_POIS);
      if (getArguments() != null
          && getArguments().containsKey(SearchFragment.ARG_MY)
          && getArguments().getBoolean(SearchFragment.ARG_MY))
        args.putBoolean(SearchFragment.ARG_MY, getArguments().getBoolean(SearchFragment.ARG_MY));
      fragment.setArguments(args);
      fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
      fragmentTransaction.replace(R.id.fragment_container, fragment, "pois");
      fragmentTransaction.addToBackStack(fragment.getTag());
      fragmentTransaction.commit();
      /* add category to bundle */
      return true;

    } else {
      return super.onOptionsItemSelected(item);
    }
  }
Пример #3
0
  /**
   * Replaces the entire stack with this fragment.
   *
   * @param args Arguments to be set on the fragment using {@link
   *     Fragment#setArguments(android.os.Bundle)}.
   */
  public void replace(Class<?> fragment, String tag, Bundle args) {
    Fragment first = stack.peekFirst();
    if (first != null && tag.equals(first.getTag())) {
      if (stack.size() > 1) {
        ensureTransaction();
        fragmentTransaction.setCustomAnimations(popStackEnterAnimation, popStackExitAnimation);
        while (stack.size() > 1) {
          removeFragment(stack.pollLast());
        }

        attachFragment(stack.peek(), tag);
      }
      return;
    }

    Fragment f = fragmentManager.findFragmentByTag(tag);
    if (f == null) {
      f = Fragment.instantiate(activity, fragment.getName(), args);
    }

    ensureTransaction();
    fragmentTransaction.setCustomAnimations(enterAnimation, exitAnimation);
    clear();
    attachFragment(f, tag);
    stack.add(f);

    topLevelTags.add(tag);
  }
Пример #4
0
 private void selectItem(int pos) {
   if (pos < 0 || pos >= mMainMenu.getEntries().length) {
     pos = 0;
   }
   String titlePrefix = getString(R.string.main_activity_title_prefix);
   getSupportActionBar().setTitle(titlePrefix + mMainMenu.getEntries()[pos]);
   String nextFragmentTag = "FRAGMENT_TAG_" + Integer.toString(pos);
   Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.container);
   if (currentFragment != null && nextFragmentTag.equals(currentFragment.getTag())) {
     return;
   }
   Fragment recycledFragment = getSupportFragmentManager().findFragmentByTag(nextFragmentTag);
   try {
     FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
     if (currentFragment != null) {
       transaction.detach(currentFragment);
     }
     if (recycledFragment != null) {
       transaction.attach(recycledFragment);
     } else {
       transaction.add(R.id.container, mMainMenu.createFragment(pos), nextFragmentTag);
     }
     transaction.commit();
     getSupportFragmentManager().executePendingTransactions();
     // The header takes the first position.
     mDrawerMenu.setItemChecked(pos + 1, true);
     getAppPreferences().edit().putInt(PREF_LAST_SCREEN_ID, pos).apply();
   } catch (InstantiationException e) {
     Log.wtf(TAG, "Error while instantiating the selected fragment", e);
   } catch (IllegalAccessException e) {
     Log.wtf(TAG, "Error while instantiating the selected fragment", e);
   }
 }
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   final Fragment fragment = (Fragment) super.instantiateItem(container, position);
   final TabInfo info = mTabs.get(position);
   info.tag = fragment.getTag(); // set it here
   info.fragment = fragment;
   return fragment;
 }
  @Override
  public void onAttachFragment(Fragment fragment) {
    if (fragment instanceof BaseFragment) {
      // if(((BaseFragment) fragment).isRequesting()) setRefreshActionButtonState(true);

      refreshingFragments.put(fragment.getTag(), ((BaseFragment) fragment).isRequesting());
      updateRefreshActionButtonState();
    }
  }
  public void notifyRefreshing(Fragment fragment, boolean refreshing) {

    if (fragment instanceof BaseFragment) {
      // if(((BaseFragment) fragment).isRequesting()) setRefreshActionButtonState(true);
      // refreshingFragments.put(fragment.getTag(), ((BaseFragment) fragment).isRequesting());
      refreshingFragments.put(fragment.getTag(), refreshing);
      updateRefreshActionButtonState();
    }
  }
Пример #8
0
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   Object obj = super.instantiateItem(container, position);
   if (obj instanceof Fragment) {
     // record the fragment tag here.
     Fragment f = (Fragment) obj;
     String tag = f.getTag();
     mFragmentTags.put(position, tag);
   }
   return obj;
 }
Пример #9
0
  public void saveState(Bundle outState) {
    executePendingTransactions();

    final int stackSize = stack.size();
    String[] stackTags = new String[stackSize];

    int i = 0;
    for (Fragment f : stack) {
      stackTags[i++] = f.getTag();
    }

    outState.putStringArray(STATE_STACK, stackTags);
  }
Пример #10
0
  /**
   * Removes the fragment at the top of the stack and displays the previous one. This will not do
   * anything if there is only one fragment in the stack.
   *
   * @param commit Whether the transaction should be committed.
   * @return Whether a transaction has been enqueued.
   */
  public boolean pop(boolean commit) {
    if (stack.size() > 1) {
      ensureTransaction();
      fragmentTransaction.setCustomAnimations(popStackEnterAnimation, popStackExitAnimation);
      removeFragment(stack.pollLast());
      Fragment f = stack.peekLast();
      attachFragment(f, f.getTag());

      if (commit) {
        commit();
      }

      return true;
    }

    return false;
  }
 @Override
 public int getItemPosition(Object object) {
   TabFragment fragment = (TabFragment) object;
   if (fragment.getTab() == null) {
     return POSITION_NONE;
   }
   String fragmentTag = fragment.getTag();
   for (int i = 0; i < registeredFragments.size(); i++) {
     Fragment registeredFragment = getRegisteredFragment(i);
     if (registeredFragment != null) {
       if (fragmentTag.equals(registeredFragment.getTag())) {
         return i;
       }
     }
   }
   return POSITION_NONE;
 }
  public static void listFragmentRefreshStatic(
      GenericListItemsListFragment fragment, String fragmentTag) {
    AppState.logX(
        TAG,
        String.format(
            "listFragmentRefreshStatic 1: fragmentTag = %s, " + "fragmentMgr = %s",
            fragmentTag, fragmentMgr));

    if (fragmentMgr != null) {
      // XXX
      AppState.logX(
          TAG,
          String.format(
              "XXX listFragmentRefreshStatic 1: backStackEntryCount "
                  + "= %d, fragmentByTag = %s, fragmentById = %s",
              fragmentMgr.getBackStackEntryCount(),
              fragmentMgr.findFragmentByTag(fragmentTag),
              fragmentMgr.findFragmentById(GenericFragmentActivity.DEFAULT_FRAGMENT_CONTAINER_ID)));

      Fragment oldFragment;
      if ((oldFragment =
                  fragmentMgr.findFragmentById(
                      GenericFragmentActivity.DEFAULT_FRAGMENT_CONTAINER_ID))
              != null
          && oldFragment.getTag().equals(fragmentTag)) {
        AppState.logX(TAG, "listFragmentRefreshStatic 1: the fragment was found");

        fragment.setArguments(oldFragment.getArguments());
        fragmentMgr
            .beginTransaction()
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
            .replace(GenericFragmentActivity.DEFAULT_FRAGMENT_CONTAINER_ID, fragment, fragmentTag)
            .commitAllowingStateLoss();
      } else {
        AppState.logX(TAG, "listFragmentRefreshStatic 1: the fragment was not found");

        fragmentMgr.beginTransaction().remove(null);
      }
    }
  }
Пример #13
0
  public void setFragment(String fragmentName) {

    Fragment temp = fragmentManager.findFragmentByTag(fragmentName);

    if (temp != null && temp.isAdded()) {
      // L.t(getApplicationContext(),fragmentName + " is Added already");

      if (currentFrag != null && !currentFrag.getTag().contains(fragmentName)) {
        // L.t(getApplicationContext(), currentFrag.getTag() +" was current");

        fragmentManager
            .beginTransaction()
            .hide(currentFrag)
            .show(temp)
            // .addToBackStack(fragmentName)
            .commit();
      }
      // When rotation a fragment is added, however current fragment is null.
      currentFrag = temp;

      return;

    } else if (temp != null) {
      // when using retainInstance(true) the lifecycle may change.
      // L.t(getApplicationContext(), fragmentName + " not null but is not added");
    }

    try {
      Class cl = Class.forName(fragmentName);
      Constructor con = cl.getConstructor();
      temp = (Fragment) con.newInstance();

      // First Fragment created
      if (currentFrag == null) {
        fragmentManager
            .beginTransaction()
            .add(R.id.mainframe, temp, fragmentName)
            // .addToBackStack(fragmentName)
            .commit();
      } else {
        fragmentManager
            .beginTransaction()
            .hide(currentFrag)
            .add(R.id.mainframe, temp, fragmentName)
            // .addToBackStack(fragmentName)
            .commit();
      }

      currentFrag = temp;
      return;

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (ClassCastException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    }

    Toast.makeText(getApplicationContext(), "Reflection error", Toast.LENGTH_SHORT).show();
  }
Пример #14
0
 public String getTag() {
   return zzadh.getTag();
 }