Beispiel #1
0
  @AfterViews
  public void listAllAmbassadorsByPagination() {

    Typeface typeFace =
        Typeface.createFromAsset(getActivity().getAssets(), "fonts/OpenSans-Regular.ttf");
    thousand.setTypeface(null, typeFace.BOLD);
    hubName.setTypeface(typeFace);
    ambassadorsTitle.setTypeface(typeFace);
    eventsButton.setTypeface(typeFace);
    membersButton.setTypeface(typeFace);
    newsButton.setTypeface(typeFace);

    headerHub.getBackground().setAlpha(100);
    android.support.v4.app.FragmentManager fragmentManager =
        getActivity().getSupportFragmentManager();
    OneHubNewsFragment_ newsFragment =
        (OneHubNewsFragment_) fragmentManager.findFragmentByTag("news");
    OneHubEventsFragment_ eventsFragment =
        (OneHubEventsFragment_) fragmentManager.findFragmentByTag("events");
    OneHubMembersFragment_ membersFragment =
        (OneHubMembersFragment_) fragmentManager.findFragmentByTag("members");
    android.support.v4.app.FragmentTransaction fragmentTransaction =
        fragmentManager.beginTransaction();

    if (newsFragment != null) {
      fragmentTransaction.detach(newsFragment);
    }

    if (eventsFragment != null) {
      fragmentTransaction.detach(eventsFragment);
    }

    if (membersFragment != null) {
      fragmentTransaction.detach(membersFragment);
    }

    fragmentTransaction.add(R.id.realtabcontent, new OneHubNewsFragment_(), "news");
    eventsButtonLight.setBackgroundDrawable(
        getResources().getDrawable(R.drawable.buttonline_nonselected_407x9));
    membersButtonLight.setBackgroundDrawable(
        getResources().getDrawable(R.drawable.buttonline_nonselected_407x9));
    newsButtonLight.setBackgroundDrawable(
        getResources().getDrawable(R.drawable.buttonline_selected_407x9));
    membersSelected = false;
    eventsSelected = false;
    newsSelected = true;
    fragmentTransaction.commit();

    listAllAmbassadorsOfHubService();
  }
  @Override
  public void onConfigurationChanged(Configuration newConfig) {

    super.onConfigurationChanged(newConfig);

    if (getResources().getBoolean(R.bool.portrait_only)) {
      // do not rotate for phones
      //noinspection ResourceType
      setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT);
    } else {

      // use layout for tablets - landscape or portrait.
      // save fragments for re-use in new layout!

      FragmentManager fragmentManager = getSupportFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

      CategoryList attackFragment =
          (CategoryList)
              fragmentManager.findFragmentByTag(getResources().getString(R.string.items_attack));
      CategoryList defenseFragment =
          (CategoryList)
              fragmentManager.findFragmentByTag(getResources().getString(R.string.items_defense));
      HeroList heroFragment =
          (HeroList)
              fragmentManager.findFragmentByTag(getResources().getString(R.string.items_hero));

      fragmentTransaction.detach(attackFragment);
      fragmentTransaction.detach(defenseFragment);
      fragmentTransaction.detach(heroFragment);

      fragmentTransaction.commitAllowingStateLoss();
      fragmentManager.executePendingTransactions();

      // load appropriate layout
      Log.v(getClass().getCanonicalName(), "re-load layout for tablets");
      setContentView(R.layout.main);

      Log.v(getClass().getCanonicalName(), "re-use fragments");
      fragmentTransaction = fragmentManager.beginTransaction();
      fragmentTransaction.attach(defenseFragment);
      fragmentTransaction.attach(attackFragment);
      fragmentTransaction.attach(heroFragment);

      fragmentTransaction.commitAllowingStateLoss();
      fragmentManager.executePendingTransactions();
    }
  }
 public void fragmentFinish() {
   FragmentTransaction ft = mFragmentManager.beginTransaction();
   for (MyFragment fragment : mFragmentList) {
     ft.detach(fragment);
   }
   ft.commitAllowingStateLoss();
 }
  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();
    }
  }
Beispiel #5
0
 protected void popBackQuestionFragment() {
   FragmentManager fm = getActivity().getSupportFragmentManager();
   fm.popBackStack();
   FragmentTransaction transaction = fm.beginTransaction();
   transaction.detach(CameraFragment.this);
   transaction.commit();
 }
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
   super.onActivityResult(requestCode, resultCode, intent);
   //        if (resultCode == Activity.RESULT_OK && requestCode == Contains.REQUEST_EDIT_INFO) {
   //            Log.i(TAG, "Back from Edit profile...");
   //            setInfo(null);
   //            // redraw the view
   //            FragmentTransaction ft = getFragmentManager().beginTransaction();
   //            ft.detach(this).attach(this).commit();
   //        }
   if (resultCode == Activity.RESULT_OK) {
     switch (requestCode) {
       case Contains.REQUEST_EDIT_INFO:
         // update user's profile
         setInfo(null);
         // redraw the view
         FragmentTransaction ft = getFragmentManager().beginTransaction();
         ft.detach(this).attach(this).commit();
         // update Navigation profile menu
         sendBroadcastUpdateProfile();
         break;
       case PICK_PHOTO:
         if (intent != null) {
           beginCrop(intent.getData());
         }
         break;
       case PICK_CAMERA:
         onCamera(intent);
         break;
       case Crop.REQUEST_CROP:
         onPhoto(Crop.getOutput(intent));
         break;
     }
   }
 }
  @Override
  public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (currentFragment != null) {
      transaction.detach(currentFragment);
    }

    String newFragmentTag = FRAGMENT_TAGS.get(position);
    currentFragment = fragmentManager.findFragmentByTag(newFragmentTag);

    if (currentFragment == null) {
      try {
        currentFragment = FRAGMENT_CLASSES.get(newFragmentTag).getConstructor().newInstance();
      } catch (Exception e) {
        throw new RuntimeException("Cannot instantiate fragment", e);
      }

      transaction.add(R.id.container, currentFragment, newFragmentTag);
    }
    mTitle = newFragmentTag;
    restoreActionBar();
    transaction.attach(currentFragment).commit();
  }
Beispiel #8
0
 @Override
 public void onCheckedChanged(RadioGroup group, int checkedId) {
   TabInfo newTab = mTabs.get("" + checkedId);
   if (mLastTab != newTab) {
     FragmentTransaction ft = mFragmentManager.beginTransaction();
     if (mLastTab != null) {
       if (mLastTab.fragment != null) {
         ft.detach(mLastTab.fragment);
       }
     }
     if (newTab != null) {
       if (newTab.fragment == null) {
         newTab.fragment =
             (BaseFragment)
                 Fragment.instantiate(group.getContext(), newTab.clss.getName(), newTab.args);
         ft.add(mContainerId, newTab.fragment, newTab.tag);
       } else {
         ft.attach(newTab.fragment);
       }
     }
     mLastTab = newTab;
     ft.commit();
     mFragmentManager.executePendingTransactions();
   }
 }
 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);
   }
 }
Beispiel #10
0
	@Override
	public void onDestroyView() {
		FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.detach(listFragment);
        fragmentTransaction.commit();
        super.onDestroyView();
	}
 @Override
 public void onTabUnselected(CompatTab tab, FragmentTransaction ft) {
   Fragment fragment = tab.getFragment();
   if (fragment != null) {
     // Detach the fragment, because another one is being attached
     ft.detach(fragment);
   }
 }
  public void onTabUnselected(Tab tab, FragmentTransaction unused) {
    if (mFragment != null) {
      FragmentManager fm = mActivity.getSupportFragmentManager();
      FragmentTransaction ft = fm.beginTransaction();

      ft.detach(mFragment);

      ft.commit();
    }
  }
Beispiel #13
0
 public static void detachAndAdd(
     FragmentManager paramFragmentManager,
     Fragment paramFragment1,
     Fragment paramFragment2,
     Bundle paramBundle) {
   FragmentTransaction localFragmentTransaction = paramFragmentManager.beginTransaction();
   paramFragment2.setArguments(paramBundle);
   localFragmentTransaction.detach(paramFragment1);
   localFragmentTransaction.add(android.R.id.content, paramFragment2);
   localFragmentTransaction.commit();
   paramFragmentManager.executePendingTransactions();
 }
Beispiel #14
0
  public void addTab(int radioButtonId, Class<?> clss, String tag, Bundle args) {
    String tabId = "" + radioButtonId;

    TabInfo info = new TabInfo(tag, clss, args);
    info.fragment = (BaseFragment) mFragmentManager.findFragmentByTag(tag);
    if (info.fragment != null && !info.fragment.isDetached()) {
      FragmentTransaction ft = mFragmentManager.beginTransaction();
      ft.detach(info.fragment);
      ft.commit();
    }
    mTabs.put(tabId, info);
  }
Beispiel #15
0
 @Override
 public boolean onNavigationItemSelected(MenuItem item) {
   FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
   switch (item.getItemId()) {
     case R.id.nav_chapter:
       transaction.detach(forum).detach(game).attach(chapter);
       break;
     case R.id.nav_forum:
       transaction.detach(chapter).detach(game).attach(forum);
       break;
     case R.id.nav_game:
       transaction.detach(forum).detach(chapter).attach(game);
       break;
     case R.id.nav_setting:
       break;
     case R.id.nav_exit:
       ActivityCompat.finishAffinity(this);
       break;
   }
   transaction.commit();
   drawer.closeDrawer(GravityCompat.START);
   return true;
 }
Beispiel #16
0
  public TabListener(SherlockFragmentActivity activity, String tag, Class<T> clz, Bundle args) {
    mActivity = activity;
    mTag = tag;
    mClass = clz;
    mArgs = args;

    // Check to see if we already have a fragment for this tab, probably
    // from a previously saved state.  If so, deactivate it, because our
    // initial state is that a tab isn't shown.
    mFragment = mActivity.getSupportFragmentManager().findFragmentByTag(mTag);
    if (mFragment != null && !mFragment.isDetached()) {
      FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
      ft.detach(mFragment);
      ft.commit();
    }
  }
Beispiel #17
0
 public void removeFrag(FragOpt fo) {
   if (fo == null) {
     fo = new FragOpt(mFragCur, 0);
   }
   Fragment fg = fo == null ? null : mFragMger.findFragmentByTag(fo.getTag());
   FragmentTransaction ft = mFragMger.beginTransaction();
   fo.addTransAnim(ft);
   if (fg != null) {
     if (fo.hasCache()) {
       ft.hide(fg);
       ft.detach(fg);
     } else {
       ft.remove(fg);
     }
     fo.commit(ft);
   }
 }
  /**
   * Ajout d'une tab au conteneur
   *
   * @param activity activit� concern�e
   * @param tabHost Hote des Tabs
   * @param tabSpec nouvelle spec de la tab
   * @param tabInfo infos de la � cr�er
   */
  private static void addTab(
      DiffusionTabActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) {

    // On Attache une factory � la spec de la tab
    tabSpec.setContent(activity.new TabFactory(activity));
    String tag = tabSpec.getTag();

    // On v�rifie si un fragment est d�j� li� � cette spec au quel cas
    // on le d�sactive afin de garantir l'�tat initial cach�
    tabInfo.fragment = activity.getSupportFragmentManager().findFragmentByTag(tag);
    if (tabInfo.fragment != null && !tabInfo.fragment.isDetached()) {
      FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
      ft.detach(tabInfo.fragment);
      ft.commit();
      activity.getSupportFragmentManager().executePendingTransactions();
    }
    tabHost.addTab(tabSpec);
  }
Beispiel #19
0
  public void addTab(final TabHost.TabSpec tabSpec, final Class<?> clss, final Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mActivity));
    final String tag = tabSpec.getTag();

    final TabInfo info = new TabInfo(tag, clss, args);

    // Check to see if we already have a fragment for this tab, probably
    // from a previously saved state. If so, deactivate it, because our
    // initial state is that a tab isn't shown.
    info.fragment = mActivity.getSupportFragmentManager().findFragmentByTag(tag);
    if (info.fragment != null && !info.fragment.isDetached()) {
      final FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
      ft.detach(info.fragment);
      ft.commit();
    }

    mTabs.put(tag, info);
    mTabHost.addTab(tabSpec);
  }
Beispiel #20
0
  public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {
    tabSpec.setContent(new DummyTabFactory(mContext));
    String tag = tabSpec.getTag();

    TabInfo info = new TabInfo(tag, clss, args);

    if (mAttached) {
      // If we are already attached to the window, then check to make
      // sure this tab's fragment is inactive if it exists.  This shouldn't
      // normally happen.
      info.fragment = mFragmentManager.findFragmentByTag(tag);
      if (info.fragment != null && !info.fragment.isDetached()) {
        FragmentTransaction ft = mFragmentManager.beginTransaction();
        ft.detach(info.fragment);
        ft.commit();
      }
    }

    mTabs.add(info);
    addTab(tabSpec);
  }
Beispiel #21
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getSupportFragmentManager().findFragmentById(android.R.id.content) != null) {
      FragmentManager fragMgr = getSupportFragmentManager();
      FragmentTransaction ft = fragMgr.beginTransaction();
      ft.detach(getSupportFragmentManager().findFragmentById(android.R.id.content));
      ft.commit();
    }

    tracker = GoogleAnalyticsTracker.getInstance();

    // Start the tracker in manual dispatch mode...
    tracker.startNewSession(Keys.ANALYTICS_KEY, this);
    // setup action bar for tabs
    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    Tab friendsTab =
        actionBar
            .newTab()
            .setText(R.string.friends_tabtitle)
            .setTabListener(
                new TabListenerList<FriendListFragment>(this, "friends", FriendListFragment.class));
    actionBar.addTab(friendsTab, true);

    Tab groupsTab =
        actionBar
            .newTab()
            .setText(R.string.groups_tabtitle)
            .setTabListener(
                new TabListenerList<GroupListFragment>(this, "groups", GroupListFragment.class));
    actionBar.addTab(groupsTab, true);

    actionBar.setSelectedNavigationItem(0);
  }
Beispiel #22
0
  @Override
  protected void onAttachedToWindow() {
    super.onAttachedToWindow();

    String currentTab = getCurrentTabTag();

    // Go through all tabs and make sure their fragments match
    // the correct state.
    FragmentTransaction ft = null;
    for (int i = 0; i < mTabs.size(); i++) {
      TabInfo tab = mTabs.get(i);
      tab.fragment = mFragmentManager.findFragmentByTag(tab.tag);
      if (tab.fragment != null && !tab.fragment.isDetached()) {
        if (tab.tag.equals(currentTab)) {
          // The fragment for this tab is already there and
          // active, and it is what we really want to have
          // as the current tab.  Nothing to do.
          mLastTab = tab;
        } else {
          // This fragment was restored in the active state,
          // but is not the current tab.  Deactivate it.
          if (ft == null) {
            ft = mFragmentManager.beginTransaction();
          }
          ft.detach(tab.fragment);
        }
      }
    }

    // We are now ready to go.  Make sure we are switched to the
    // correct tab.
    mAttached = true;
    ft = doTabChanged(currentTab, ft);
    if (ft != null) {
      ft.commit();
      mFragmentManager.executePendingTransactions();
    }
  }
  /**
   * Changement de Tabs
   *
   * @see android.widget.TabHost.OnTabChangeListener#onTabChanged(java.lang.String)
   */
  public void onTabChanged(String tag) {
    TabInfo newTab = (TabInfo) this.mapTabInfo.get(tag);
    if (mLastTab != newTab) {
      FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
      if (mLastTab != null) {
        if (mLastTab.fragment != null) {
          ft.detach(mLastTab.fragment);
        }
      }
      if (newTab != null) {
        if (newTab.fragment == null) {
          newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args);
          ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
        } else {
          ft.attach(newTab.fragment);
        }
      }

      mLastTab = newTab;
      ft.commit();
      this.getSupportFragmentManager().executePendingTransactions();
    }
  }
Beispiel #24
0
    public void onTabChanged(String tabId) {
      TabInfo newTab = mTabs.get(tabId);
      if (mLastTab != newTab) {
        FragmentTransaction ft = mActivity.getSupportFragmentManager().beginTransaction();
        if (mLastTab != null) {
          if (mLastTab.fragment != null) {
            ft.detach(mLastTab.fragment);
          }
        }
        if (newTab != null) {
          if (newTab.fragment == null) {
            newTab.fragment = Fragment.instantiate(mActivity, newTab.clss.getName(), newTab.args);
            ft.add(mContainerId, newTab.fragment, newTab.tag);
          } else {
            ft.attach(newTab.fragment);
          }
        }

        mLastTab = newTab;
        ft.commit();
        mActivity.getSupportFragmentManager().executePendingTransactions();
      }
    }
Beispiel #25
0
  private FragmentTransaction doTabChanged(String tabId, FragmentTransaction ft) {
    TabInfo newTab = null;
    for (int i = 0; i < mTabs.size(); i++) {
      TabInfo tab = mTabs.get(i);
      if (tab.tag.equals(tabId)) {
        newTab = tab;
      }
    }
    if (newTab == null) {
      throw new IllegalStateException("No tab known for tag " + tabId);
    }
    if (mLastTab != newTab) {
      if (ft == null) {
        ft = mFragmentManager.beginTransaction();
      }
      if (mLastTab != null) {
        if (mLastTab.fragment != null) {
          // 将detach替换为hide,隐藏Fragment
          ft.detach(mLastTab.fragment);
          // ft.hide(mLastTab.fragment);
        }
      }
      if (newTab != null) {
        if (newTab.fragment == null) {
          newTab.fragment = Fragment.instantiate(mContext, newTab.clss.getName(), newTab.args);
          ft.add(mContainerId, newTab.fragment, newTab.tag);
        } else {
          // 将attach替换为show,显示Fragment
          ft.attach(newTab.fragment);
          // ft.show(newTab.fragment);
        }
      }

      mLastTab = newTab;
    }
    return ft;
  }
Beispiel #26
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (AppMain.isphone) {

      if (Fragment_Ebook.isChoice) {
        ProgressDialog dialog = new ProgressDialog(ebook.getActivity());
        dialog.show();
        Fragment_Ebook.isChoice = false;
        Adapter_List_Ebook_MasterDetail.phoneToDetail = false;
        Fragment_Ebook.sCatIDs = "";
        Fragment_Ebook.bCode = "";

        if (ebook != null) {
          ebook.setListViewMaster(AppMain.pList_default_ebook_master, dialog);
          return false;
        }
        return true;
      } else {

        if (event.getAction() == KeyEvent.ACTION_DOWN) {
          switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
              if (mLastTab.tag.equals("Tab3")) {
                if (AppMain.pList_Subcategories != null
                    && AppMain.pList_Subcategories_ebook != null) {
                  Fragment_Category.category.setListView_SubCategory(
                      AppMain.pList_Subcategories, null);
                  AppMain.pList_Subcategories_ebook = null;

                  return true;
                }
                if (AppMain.pList_Subcategories != null) {
                  Fragment_Category.category.setListViewCategory(AppMain.pList_categories, null);
                  AppMain.pList_Subcategories = null;

                  return true;
                }
              }
              try {

                if (mLastTab.tag.equals("Tab1")) {

                  if (Fragment_Ebook.fragment_ebook.HaveFragment) {
                    FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();

                    if (Fragment_Ebook.fragment_ebook.frag_search != null) {
                      ft.detach(Fragment_Ebook.fragment_ebook.frag_search);
                    }
                    if (Activity_Tab.mLastTab.fragment != null) {
                      ft.attach(mLastTab.fragment);
                    }
                    ft.commit();
                    this.getSupportFragmentManager().executePendingTransactions();

                    Fragment_Ebook.fragment_ebook.HaveFragment = false;
                    return true;
                  }
                }
              } catch (Exception e) {
                // TODO: handle exception
              }
              if (mLastTab.tag.equals("Tab2")) {
                if (Fragment_Publisher.fragment_Publisher.HaveFragment) {
                  FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();

                  if (Fragment_Publisher.fragment_Publisher.frag_searchpublisher != null) {
                    ft.detach(Fragment_Publisher.fragment_Publisher.frag_searchpublisher);
                  }
                  if (Activity_Tab.mLastTab.fragment != null) {
                    ft.attach(mLastTab.fragment);
                  }
                  ft.commit();
                  this.getSupportFragmentManager().executePendingTransactions();

                  Fragment_Publisher.fragment_Publisher.HaveFragment = false;
                  return true;
                }
              }
          }
        }
      }
    } else {
      if (Fragment_Ebook.isTabletChoose) {

        Fragment_Ebook.isTabletChoose = false;
        Adapter_List_Ebook_MasterDetail.phoneToDetail = false;
        Fragment_Ebook.sCatIDs = "";
        Fragment_Ebook.bCode = "";

        if (ebook != null) {
          ebook.setViewPagerMaster(AppMain.pList_default_ebook_master, null);
          return false;
        }
        return true;
      }
      // tablet
    }

    return super.onKeyDown(keyCode, event);
  }
Beispiel #27
0
  @Override
  public void onTabChanged(String tag) {
    AppMain.isShelf = false;

    if (AppMain.isphone) {

      TabInfo newTab = mapTabInfo.get(tag);
      if (mLastTab != newTab) {
        FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
        // pause
        if (mLastTab != null) {
          if (mLastTab.fragment != null) {
            ft.detach(mLastTab.fragment);
          }
          if (mLastTab.tag.equals("Tab1")) {
            if (Fragment_Ebook.isChoice) {

              Fragment_Ebook.isChoice = false;
              Adapter_List_Ebook_MasterDetail.phoneToDetail = false;
              Fragment_Ebook.sCatIDs = "";
              Fragment_Ebook.bCode = "";
            }
            if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
              getSupportFragmentManager().popBackStack();
            }
            if (Fragment_Ebook.fragment_ebook != null) {
              if (Fragment_Ebook.fragment_ebook.HaveFragment) {
                if (Fragment_Ebook.fragment_ebook.frag_search != null) {
                  ft.detach(Fragment_Ebook.fragment_ebook.frag_search);
                }
              }
            }
          }
          if (mLastTab.tag.equals("Tab2")) {
            if (Fragment_Publisher.fragment_Publisher != null) {
              if (Fragment_Publisher.fragment_Publisher.HaveFragment) {
                if (Fragment_Publisher.fragment_Publisher.frag_searchpublisher != null) {
                  ft.detach(Fragment_Publisher.fragment_Publisher.frag_searchpublisher);
                }
              }
            }
          }
        }
        // resume
        if (newTab != null) {
          if (newTab.tag.equals("Tab1")) {
            if (Fragment_Ebook.fragment_ebook != null) {
              if (Fragment_Ebook.fragment_ebook.HaveFragment) {
                if (Fragment_Ebook.fragment_ebook.frag_search != null) {
                  ft.attach(Fragment_Ebook.fragment_ebook.frag_search);
                }
                mLastTab = newTab;
                ft.commit();
                this.getSupportFragmentManager().executePendingTransactions();

                return;
              }
            }
          }
          if (newTab.tag.equals("Tab2")) {
            if (Fragment_Publisher.fragment_Publisher != null) {
              if (Fragment_Publisher.fragment_Publisher.HaveFragment) {
                if (Fragment_Publisher.fragment_Publisher.frag_searchpublisher != null) {
                  ft.attach(Fragment_Publisher.fragment_Publisher.frag_searchpublisher);
                }
                mLastTab = newTab;
                ft.commit();
                this.getSupportFragmentManager().executePendingTransactions();

                return;
              }
            }
          }
          if (newTab.fragment == null) {
            newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args);
            ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
          } else {
            ft.attach(newTab.fragment);
          }
        }

        mLastTab = newTab;
        ft.commit();
        this.getSupportFragmentManager().executePendingTransactions();
      }
    } else {
      if (Fragment_Ebook.isTabletChoose) {

        Fragment_Ebook.isTabletChoose = false;
        Adapter_List_Ebook_MasterDetail.phoneToDetail = false;
        Fragment_Ebook.sCatIDs = "";
        Fragment_Ebook.bCode = "";
      }

      if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
        getSupportFragmentManager().popBackStack();
      }
      // tablet
      TabInfo newTab = mapTabInfo.get(tag);
      if (mLastTab != newTab) {
        FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
        // pause
        if (mLastTab != null) {
          if (mLastTab.fragment != null) {
            ft.detach(mLastTab.fragment);
          }
        }
        // resume
        if (newTab != null) {
          if (newTab.fragment == null) {
            newTab.fragment = Fragment.instantiate(this, newTab.clss.getName(), newTab.args);
            ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
          } else {
            ft.attach(newTab.fragment);
          }
        }

        mLastTab = newTab;
        ft.commit();
        this.getSupportFragmentManager().executePendingTransactions();
      }
    }
  }
  /**
   * Callback method from {@link
   * com.metric.skava.assessment.fragment.AssessmentStageListFragment.StageSelectionCallback}
   * indicating that the item with the given ID was selected.
   */
  @Override
  public void onItemSelected(String id) {
    if (mTwoPane) {
      // In two-pane mode, show the detail view in this activity by
      // adding or replacing the detail fragment using a
      // fragment transaction.
      if (id.equalsIgnoreCase(AssesmentStageDataProvider.GRAL_INFO)) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fx = fragmentManager.beginTransaction();
        // whats the current fragment
        Fragment previous = fragmentManager.findFragmentById(R.id.stage_detail_container);
        if (previous != null) {
          fx.detach(previous);
        }
        // use the previous fragment if there is one
        Fragment fragment = fragmentManager.findFragmentByTag(FRAGMENT_GRAL_INFO_STAGE_TAG);
        IdentificationMainFragment gralInfoFragment;
        if (fragment != null) {
          gralInfoFragment = (IdentificationMainFragment) fragment;
          fx.attach(gralInfoFragment);
        } else {
          gralInfoFragment = new IdentificationMainFragment();
          Bundle arguments = new Bundle();
          arguments.putString(IdentificationMainFragment.ARG_BASKET_ID, id);
          gralInfoFragment.setArguments(arguments);
          fx.add(R.id.stage_detail_container, gralInfoFragment, FRAGMENT_GRAL_INFO_STAGE_TAG);
        }
        fx.commit();
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.DISCONTINUITIES)) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fx = fragmentManager.beginTransaction();
        Fragment previous =
            getSupportFragmentManager().findFragmentById(R.id.stage_detail_container);
        if (previous != null) {
          fx.detach(previous);
        }
        // use the previous fragment if there is one
        Fragment fragment =
            getSupportFragmentManager().findFragmentByTag(FRAGMENT_DISCONTINUITIES_STAGE_TAG);
        DiscontinuitiesMainFragment discontinuitiesFragment;
        if (fragment != null) {
          discontinuitiesFragment = (DiscontinuitiesMainFragment) fragment;
          fx.attach(discontinuitiesFragment);
        } else {
          discontinuitiesFragment = new DiscontinuitiesMainFragment();
          Bundle arguments = new Bundle();
          arguments.putString(DiscontinuitiesMainFragment.ARG_BASKET_ID, id);
          discontinuitiesFragment.setArguments(arguments);
          fx.add(
              R.id.stage_detail_container,
              discontinuitiesFragment,
              FRAGMENT_DISCONTINUITIES_STAGE_TAG);
        }
        fx.commit();
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.Q)) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fx = fragmentManager.beginTransaction();
        Fragment previous =
            getSupportFragmentManager().findFragmentById(R.id.stage_detail_container);
        if (previous != null) {
          fx.detach(previous);
        }
        Fragment fragment = fragmentManager.findFragmentByTag(FRAGMENT_Q_STAGE_TAG);
        QBartonCalculatorMainFragment qBartonFragment;
        // use the previous fragment if there is one
        if (fragment != null) {
          qBartonFragment = (QBartonCalculatorMainFragment) fragment;
          fx.attach(qBartonFragment);
        } else {
          Bundle arguments = new Bundle();
          arguments.putString(QBartonCalculatorMainFragment.ARG_BASKET_ID, id);
          qBartonFragment = new QBartonCalculatorMainFragment();
          qBartonFragment.setArguments(arguments);
          fx.add(R.id.stage_detail_container, qBartonFragment, FRAGMENT_Q_STAGE_TAG);
        }
        fx.commit();
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.RMR)) {
        FragmentTransaction fx = getSupportFragmentManager().beginTransaction();
        Fragment previous =
            getSupportFragmentManager().findFragmentById(R.id.stage_detail_container);
        if (previous != null) {
          fx.detach(previous);
        }
        // use the previous fragment if there is one
        Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_RMR_STAGE_TAG);
        RMRCalculatorMainFragment rmrFragment;
        if (fragment != null) {
          rmrFragment = (RMRCalculatorMainFragment) fragment;
          fx.attach(rmrFragment);
        } else {
          rmrFragment = new RMRCalculatorMainFragment();
          Bundle arguments = new Bundle();
          arguments.putString(RMRCalculatorMainFragment.ARG_BASKET_ID, id);
          rmrFragment.setArguments(arguments);
          fx.add(R.id.stage_detail_container, rmrFragment, FRAGMENT_RMR_STAGE_TAG);
        }
        fx.commit();
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.PICS)) {
        FragmentTransaction fx = getSupportFragmentManager().beginTransaction();
        Fragment previous =
            getSupportFragmentManager().findFragmentById(R.id.stage_detail_container);
        if (previous != null) {
          fx.detach(previous);
        }
        // use the previous fragment if there is one
        Fragment fragment =
            getSupportFragmentManager().findFragmentByTag(FRAGMENT_PICTURES_STAGE_TAG);
        PicturesMainFragment picturesFragment;
        if (fragment != null) {
          picturesFragment = (PicturesMainFragment) fragment;
          fx.attach(picturesFragment);
        } else {
          picturesFragment = new PicturesMainFragment();
          Bundle arguments = new Bundle();
          arguments.putString(PicturesMainFragment.ARG_BASKET_ID, id);
          picturesFragment.setArguments(arguments);
          fx.add(R.id.stage_detail_container, picturesFragment, FRAGMENT_PICTURES_STAGE_TAG);
        }
        fx.commit();
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.DESC)) {
        FragmentTransaction fx = getSupportFragmentManager().beginTransaction();
        Fragment previous =
            getSupportFragmentManager().findFragmentById(R.id.stage_detail_container);
        if (previous != null) {
          fx.detach(previous);
        }
        // use the previous fragment if there is one
        Fragment fragment =
            getSupportFragmentManager().findFragmentByTag(FRAGMENT_DESCRIPTION_STAGE_TAG);
        RockMassDescriptionMainFragment rockMassDescriptionFragment;
        if (fragment != null) {
          rockMassDescriptionFragment = (RockMassDescriptionMainFragment) fragment;
          fx.attach(rockMassDescriptionFragment);
        } else {
          rockMassDescriptionFragment = new RockMassDescriptionMainFragment();
          Bundle arguments = new Bundle();
          arguments.putString(RockMassDescriptionMainFragment.ARG_BASKET_ID, id);
          rockMassDescriptionFragment.setArguments(arguments);
          fx.add(
              R.id.stage_detail_container,
              rockMassDescriptionFragment,
              FRAGMENT_DESCRIPTION_STAGE_TAG);
        }
        fx.commit();
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.INSTRUCTIONS)) {
        FragmentTransaction fx = getSupportFragmentManager().beginTransaction();
        Fragment previous =
            getSupportFragmentManager().findFragmentById(R.id.stage_detail_container);
        if (previous != null) {
          fx.detach(previous);
        }
        // use the previous fragment if there is one
        Fragment fragment =
            getSupportFragmentManager().findFragmentByTag(FRAGMENT_RECOMENDATION_STAGE_TAG);
        InstructionsMainFragment supportRecomendationFragment;
        if (fragment != null) {
          supportRecomendationFragment = (InstructionsMainFragment) fragment;
          fx.attach(supportRecomendationFragment);
        } else {
          supportRecomendationFragment = new InstructionsMainFragment();
          Bundle arguments = new Bundle();
          arguments.putString(InstructionsMainFragment.ARG_BASKET_ID, id);
          supportRecomendationFragment.setArguments(arguments);
          fx.add(
              R.id.stage_detail_container,
              supportRecomendationFragment,
              FRAGMENT_RECOMENDATION_STAGE_TAG);
        }
        fx.commit();
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.REPORT)) {
        // To make it full screen size launh it as an activity instead of as a fragment
        Intent detailIntent = new Intent(this, MappingReportMainActivity.class);
        detailIntent.putExtra(MappingReportMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
        //                Bundle arguments = new Bundle();
        //                arguments.putString(MappingReportMainFragment.ARG_BASKET_ID, id);
        //                MappingReportMainFragment fragment = new MappingReportMainFragment();
        //                fragment.setArguments(arguments);
        //                getSupportFragmentManager().beginTransaction()
        //                        .replace(R.id.stage_detail_container, fragment)
        //                        .commit();
        //                return;
      }

    } else {
      // In single-pane mode, simply start the detail activity
      // for the selected item ID.
      if (id.equalsIgnoreCase(AssesmentStageDataProvider.GRAL_INFO)) {
        Intent detailIntent = new Intent(this, IdentificationMainActivity.class);
        detailIntent.putExtra(IdentificationMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.DISCONTINUITIES)) {
        Intent detailIntent = new Intent(this, DiscontinuitiesMainActivity.class);
        detailIntent.putExtra(DiscontinuitiesMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.Q)) {
        Intent detailIntent = new Intent(this, QBartonCalculatorDetailActivity.class);
        detailIntent.putExtra(QBartonCalculatorMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.RMR)) {
        Intent detailIntent = new Intent(this, RMRCalculatorDetailActivity.class);
        detailIntent.putExtra(RMRCalculatorMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.PICS)) {
        Intent detailIntent = new Intent(this, PicturesMainActivity.class);
        detailIntent.putExtra(PicturesMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.DESC)) {
        Intent detailIntent = new Intent(this, RockMassDescriptionMainActivity.class);
        detailIntent.putExtra(RMRCalculatorMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.INSTRUCTIONS)) {
        Intent detailIntent = new Intent(this, InstructionsMainActivity.class);
        detailIntent.putExtra(InstructionsMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }

      if (id.equalsIgnoreCase(AssesmentStageDataProvider.REPORT)) {
        Intent detailIntent = new Intent(this, MappingReportMainActivity.class);
        detailIntent.putExtra(MappingReportMainFragment.ARG_BASKET_ID, id);
        startActivity(detailIntent);
        return;
      }
    }
  }
 private void detachFragment(Fragment fragment) {
   if (fragment != null && !fragment.isDetached()) {
     ensureTransaction();
     fragmentTransaction.detach(fragment);
   }
 }
Beispiel #30
0
 public void onTabUnselected(Tab tab, FragmentTransaction ft) {
   if (mFragment != null) {
     ft.detach(mFragment);
   }
 }