/**
   * 消息分发,选择跳转到哪个fragment
   *
   * @param intent
   */
  private void enterFragment(Intent intent) {
    String tag = null;

    if (intent != null) {
      Fragment fragment = null;

      if (intent.getExtras() != null && intent.getExtras().containsKey(RongConst.EXTRA.CONTENT)) {
        String fragmentName = intent.getExtras().getString(RongConst.EXTRA.CONTENT);
        fragment = Fragment.instantiate(this, fragmentName);
      } else if (intent.getData() != null) {

        if (intent.getData().getPathSegments().get(0).equals("conversation")) {
          tag = "conversation";
          String fragmentName = ConversationFragment.class.getCanonicalName();
          fragment = Fragment.instantiate(this, fragmentName);

        } else if (intent.getData().getLastPathSegment().equals("conversationlist")) {
          tag = "conversationlist";
          String fragmentName = ConversationListFragment.class.getCanonicalName();
          fragment = Fragment.instantiate(this, fragmentName);
        } else if (intent.getData().getLastPathSegment().equals("subconversationlist")) {
          tag = "subconversationlist";
          String fragmentName = SubConversationListFragment.class.getCanonicalName();
          fragment = Fragment.instantiate(this, fragmentName);
          SubConversationListFragment sub = (SubConversationListFragment) fragment;
          sub.setAdapter(new SubConversationListAdapterEx(RongContext.getInstance()));
        } else if (intent.getData().getPathSegments().get(0).equals("friend")) {
          tag = "friend";
          String fragmentName = FriendMultiChoiceFragment.class.getCanonicalName();
          fragment = Fragment.instantiate(this, fragmentName);
          ActionBar actionBar = getSupportActionBar();
          actionBar.hide(); // 隐藏ActionBar
        }

        targetId = intent.getData().getQueryParameter("targetId");
        targetIds = intent.getData().getQueryParameter("targetIds");
        mDiscussionId = intent.getData().getQueryParameter("discussionId");

        if (targetId != null) {
          mConversationType =
              Conversation.ConversationType.valueOf(
                  intent.getData().getLastPathSegment().toUpperCase(Locale.getDefault()));
        } else if (targetIds != null) {
          mConversationType =
              Conversation.ConversationType.valueOf(
                  intent.getData().getLastPathSegment().toUpperCase(Locale.getDefault()));
        }
      }

      if ("tag".equals(tag)) {
        showRealTimeLocationBar(null); // RealTimeLocation
      }

      if (fragment != null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.add(R.id.de_content, fragment, tag);
        transaction.addToBackStack(null).commitAllowingStateLoss();
      }
    }
  }
 /**
  * Pop the backstack at the given position until the Fragment with the given fragmentTag is on top
  *
  * @param stackId the position of the backstack which should be used
  * @param fragmentTag the fragmentTag which belongs to the Fragment that should be gone back to
  * @return true if the Fragment with the given fragmentTag is now on top. False if Fragment with
  *     given fragmentTag not found
  */
 public boolean backToFragment(int stackId, String fragmentTag, boolean withBundle) {
   ArrayList<FragmentStateHolder> fragmentsStack = mMapOfStacks.get(stackId);
   for (FragmentStateHolder fpb : fragmentsStack) {
     if (fpb.fragmentTag.equals(fragmentTag)) {
       if (fragmentsStack.size() > 1) {
         while (fragmentsStack.size() > 0
             && !(fragmentsStack.get(fragmentsStack.size() - 1).fragmentTag.equals(fragmentTag))) {
           fragmentsStack.remove(fragmentsStack.get(fragmentsStack.size() - 1));
         }
         FragmentTransaction ft = mFragmentManager.beginTransaction();
         if (withBundle) {
           Bundle bundle = new Bundle();
           bundle.putLong(fpb.tomahawkListItemType, fpb.tomahawkListItemId);
           bundle.putInt(TomahawkFragment.TOMAHAWK_LIST_SCROLL_POSITION, fpb.listScrollPosition);
           bundle.putString(SearchableFragment.SEARCHABLEFRAGMENT_QUERY_STRING, fpb.queryString);
           ft.replace(
               mContentFrameId,
               Fragment.instantiate(mActivity, fpb.clss.getName(), bundle),
               fpb.fragmentTag);
         } else {
           ft.replace(
               mContentFrameId,
               Fragment.instantiate(mActivity, fpb.clss.getName()),
               fpb.fragmentTag);
         }
         ft.commit();
         mActivity.onBackStackChanged();
       }
       return fragmentsStack.get(fragmentsStack.size() - 1).equals(fragmentTag);
     }
   }
   return false;
 }
  @Override
  /** Creates the activity. */
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_artist);

    if (savedInstanceState != null
        && (savedInstanceState.containsKey("name") || savedInstanceState.containsKey("mbid"))) {
      name = savedInstanceState.getString("name");
      mbid = savedInstanceState.getString("mbid");
    } else {
      Bundle b = getIntent().getExtras();
      name = b.getString("name");
      mbid = b.getString("mbid");
    }

    actionBar.setTitle(name);

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    artistInfoFragment =
        (ArtistInfoFragment) Fragment.instantiate(this, ArtistInfoFragment.class.getName());
    artistAlbumsFragment =
        (ArtistAlbumsFragment) Fragment.instantiate(this, ArtistAlbumsFragment.class.getName());
    similarArtistsFragment =
        (SimilarArtistsFragment) Fragment.instantiate(this, SimilarArtistsFragment.class.getName());

    sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());

    sectionsPagerAdapter.addFragment(artistInfoFragment);
    sectionsPagerAdapter.addFragment(artistAlbumsFragment);
    sectionsPagerAdapter.addFragment(similarArtistsFragment);

    viewPager = (ViewPager) findViewById(R.id.pager);
    viewPager.setOffscreenPageLimit(2);
    viewPager.setAdapter(sectionsPagerAdapter);

    viewPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {

          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
          }
        });

    for (int i = 0; i < sectionsPagerAdapter.getCount(); i++) {
      actionBar.addTab(
          actionBar.newTab().setText(sectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    loadArtist();
  }
Esempio n. 4
0
 public Fragment getFrag(Context cx) {
   if (mFrag == null) {
     mFrag = Fragment.instantiate(cx, mFragName, mFragArg);
     mFrag.setTargetFragment(mFragTarget, mTargetFragRequesCode);
   }
   return mFrag;
 }
 /**
  * Start a new fragment containing a preference panel. If the prefences are being displayed in
  * multi-pane mode, the given fragment class will be instantiated and placed in the appropriate
  * pane. If running in single-pane mode, a new activity will be launched in which to show the
  * fragment.
  *
  * @param fragmentClass Full name of the class implementing the fragment.
  * @param args Any desired arguments to supply to the fragment.
  * @param titleRes Optional resource identifier of the title of this fragment.
  * @param titleText Optional text of the title of this fragment.
  * @param resultTo Optional fragment that result data should be sent to. If non-null,
  *     resultTo.onActivityResult() will be called when this preference panel is done. The launched
  *     panel must use {@link #finishPreferencePanel(Fragment, int, Intent)} when done.
  * @param resultRequestCode If resultTo is non-null, this is the caller's request code to be
  *     received with the resut.
  */
 public void startPreferencePanel(
     String fragmentClass,
     Bundle args,
     int titleRes,
     CharSequence titleText,
     Fragment resultTo,
     int resultRequestCode) {
   if (mSinglePane) {
     startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, 0);
   } else {
     Fragment f = Fragment.instantiate(this, fragmentClass, args);
     if (resultTo != null) {
       f.setTargetFragment(resultTo, resultRequestCode);
     }
     FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
     transaction.replace(R.id.prefs, f);
     if (titleRes != 0) {
       transaction.setBreadCrumbTitle(titleRes);
     } else if (titleText != null) {
       transaction.setBreadCrumbTitle(titleText);
     }
     transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
     transaction.addToBackStack(BACK_STACK_PREFS);
     transaction.commitAllowingStateLoss();
   }
 }
 private void onInitContent() {
   mFragment =
       (PCenterHomeFragment) Fragment.instantiate(this, PCenterHomeFragment.class.getName());
   FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
   ft.add(android.R.id.content, mFragment);
   ft.commit();
 }
Esempio n. 7
0
 public Fragment instantiate(FragmentActivity paramFragmentActivity, Fragment paramFragment)
 {
   if (this.mInstance != null);
   for (Fragment localFragment = this.mInstance; ; localFragment = this.mInstance)
   {
     return localFragment;
     if (this.mArguments != null)
       this.mArguments.setClassLoader(paramFragmentActivity.getClassLoader());
     this.mInstance = Fragment.instantiate(paramFragmentActivity, this.mClassName, this.mArguments);
     if (this.mSavedFragmentState != null)
     {
       this.mSavedFragmentState.setClassLoader(paramFragmentActivity.getClassLoader());
       this.mInstance.mSavedFragmentState = this.mSavedFragmentState;
     }
     this.mInstance.setIndex(this.mIndex, paramFragment);
     this.mInstance.mFromLayout = this.mFromLayout;
     this.mInstance.mRestored = true;
     this.mInstance.mFragmentId = this.mFragmentId;
     this.mInstance.mContainerId = this.mContainerId;
     this.mInstance.mTag = this.mTag;
     this.mInstance.mRetainInstance = this.mRetainInstance;
     this.mInstance.mDetached = this.mDetached;
     this.mInstance.mFragmentManager = paramFragmentActivity.mFragments;
     if (!FragmentManagerImpl.DEBUG)
       continue;
     Log.v("FragmentManager", "Instantiated fragment " + this.mInstance);
   }
 }
Esempio n. 8
0
  public static Fragment newInstance(VotingActivity context, int pos, float scale) {
    Bundle bundle = new Bundle();
    bundle.putInt("pos", pos);
    bundle.putFloat("scale", scale);

    return Fragment.instantiate(context, VideoCarouselFragment.class.getName(), bundle);
  }
Esempio n. 9
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);
  }
Esempio n. 10
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) {
          //					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 {
          //					ft.attach(newTab.fragment);
          ft.show(newTab.fragment);
        }
      }

      mLastTab = newTab;
    }
    return ft;
  }
 private FragmentTransaction doTabChanged(String paramString, FragmentTransaction paramFragmentTransaction)
 {
   Object localObject = null;
   for (int i = 0; i < this.mTabs.size(); ++i)
   {
     TabInfo localTabInfo = (TabInfo)this.mTabs.get(i);
     if (!localTabInfo.tag.equals(paramString))
       continue;
     localObject = localTabInfo;
   }
   if (localObject == null)
     throw new IllegalStateException("No tab known for tag " + paramString);
   if (this.mLastTab != localObject)
   {
     if (paramFragmentTransaction == null)
       paramFragmentTransaction = this.mFragmentManager.beginTransaction();
     if ((this.mLastTab != null) && (this.mLastTab.fragment != null))
       paramFragmentTransaction.detach(this.mLastTab.fragment);
     if (localObject != null)
     {
       if (localObject.fragment != null)
         break label190;
       TabInfo.access$102(localObject, Fragment.instantiate(this.mContext, localObject.clss.getName(), localObject.args));
       paramFragmentTransaction.add(this.mContainerId, localObject.fragment, localObject.tag);
     }
   }
   while (true)
   {
     this.mLastTab = localObject;
     return paramFragmentTransaction;
     label190: paramFragmentTransaction.attach(localObject.fragment);
   }
 }
 @Override
 public Fragment getItem(int position) {
   // getItem은 처음!!!! 생성시 한 번만 호출된다.(instantiateItem, destroyItem과 다름)
   // fragment의 생성은 getItem에서만 해야한다!
   IndicatorInfo info = mIndicators.get(position);
   return Fragment.instantiate(mActivity, info.clss.getName(), info.args);
 }
Esempio n. 13
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();
   }
 }
Esempio n. 14
0
 @Override
 public Fragment getItem(int position) {
   currPos = position;
   Bundle b = new Bundle();
   b.putParcelable("news", Utility.getInstance().rssDataMesseges.get(mCategory).get(position));
   return Fragment.instantiate(mContext, PageDetailFragment.class.getName(), b);
 }
  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 Object instantiateItem(ViewGroup container, int position) {
   Fragment fragment;
   // If we already have this item instantiated, there is nothing
   // to do.  This can happen when we are restoring the entire pager
   // from its saved state, where the fragment manager has already
   // taken care of restoring the fragments we previously had instantiated.
   fragment = mFragments.get(position);
   if (fragment != null) {
     return fragment;
   }
   if (mCurTransaction == null) {
     mCurTransaction = mFragmentManager.beginTransaction();
   }
   FragmentState fs = mFragmentStates.get(position);
   if (fs != null) {
     FragmentManager fragmentManager = getFragmentActivity().getSupportFragmentManager();
     if (getParentFragment() != null) {
       fragmentManager = getParentFragment().getChildFragmentManager();
     }
     // Fix Can't change tag of fragment Error
     // http://stackoverflow.com/questions/24355838/cant-change-tag-of-fragment-error-trying-to-use-a-pageradapter-for-switching
     if ((fs.mTag != null && fs.mTag.equals(mFragmentTags.get(position)))
         || (fs.mTag == null && mFragmentTags.get(position) == null)) {
       fragment =
           fs.instantiate(
               FragmentUtils.getFragmentHostCallback(fragmentManager),
               getParentFragment(),
               FragmentUtils.getFragmentManagerNonConfig(fragmentManager));
       // Fix bug
       // http://stackoverflow.com/questions/11381470/classnotfoundexception-when-unmarshalling-android-support-v4-view-viewpagersav
       if (fragment.mSavedFragmentState != null) {
         fragment.mSavedFragmentState.setClassLoader(fragment.getClass().getClassLoader());
       }
     } else {
       Log.e(
           TAG,
           String.format(
               "Fragment tag isn't equal! Origin: %s %s", fs.mTag, mFragmentTags.get(position)));
       mFragmentStates.set(position, null);
     }
   }
   if (fragment == null) {
     fragment =
         Fragment.instantiate(
             getFragmentActivity(),
             mFragmentClassNames.get(position),
             mFragmentArgs.get(position));
   }
   if (DEBUG) {
     Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
   }
   fragment.setMenuVisibility(false);
   fragment.setUserVisibleHint(false);
   mFragments.set(position, fragment);
   mFragmentStates.set(position, null);
   mCurTransaction.add(container.getId(), fragment, mFragmentTags.get(position));
   return fragment;
 }
 private void setupGroupsTab() {
   groupsFragment =
       (ContactSelectionGroupsFragment)
           Fragment.instantiate(this, ContactSelectionGroupsFragment.class.getName());
   ActionBar.Tab groupsTab = constructTab(groupsFragment);
   groupsTab.setIcon(R.drawable.ic_tab_groups);
   this.getSupportActionBar().addTab(groupsTab);
 }
 private void setupContactsTab() {
   contactsFragment =
       (ContactSelectionListFragment)
           Fragment.instantiate(this, ContactSelectionListFragment.class.getName());
   ActionBar.Tab contactsTab = constructTab(contactsFragment);
   contactsTab.setIcon(R.drawable.ic_tab_contacts);
   this.getSupportActionBar().addTab(contactsTab);
 }
Esempio n. 19
0
 @Override
 public void onItemSelected(
     final AdapterView<?> parent, final View view, final int position, final long id) {
   final Fragment fragment = Fragment.instantiate(this, mAdapter.getItem(position).cls.getName());
   final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
   ft.replace(android.R.id.content, fragment);
   ft.commit();
 }
Esempio n. 20
0
 public void onTabSelected(Tab tab, FragmentTransaction ft) {
   if (mFragment == null) {
     mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
     ft.add(android.R.id.content, mFragment, mTag);
   } else {
     ft.attach(mFragment);
   }
 }
Esempio n. 21
0
 /**
  * Creates a new {@link ServerEditFragment} dialog. Results will be delivered to the parent
  * activity via {@link ServerEditListener}.
  *
  * @param server Optional, if set will populate the fragment with data from the server.
  * @param action The action the fragment is performing (i.e. Add, Edit)
  * @param ignoreTitle If true, don't show fields related to the server title (useful for quick
  *     connect dialogs)
  */
 public static DialogFragment createServerEditDialog(
     Context context, Server server, Action action, boolean ignoreTitle) {
   Bundle args = new Bundle();
   args.putParcelable(ARGUMENT_SERVER, server);
   args.putInt(ARGUMENT_ACTION, action.ordinal());
   args.putBoolean(ARGUMENT_IGNORE_TITLE, ignoreTitle);
   return (DialogFragment) Fragment.instantiate(context, ServerEditFragment.class.getName(), args);
 }
 @Override
 public Fragment getItem(int position) {
   Fragment fragment = null;
   switch (position) {
     case 0:
       {
         fragment = Fragment.instantiate(ctx, MyShowsFragment.class.getName());
         break;
       }
     case 1:
       {
         fragment = Fragment.instantiate(ctx, BestShowsFragment.class.getName());
         break;
       }
   }
   return fragment;
 }
Esempio n. 23
0
  @Override
  public Fragment getItem(int position) {
    Bundle args = new Bundle(arguments);
    args.putInt("page", position);
    Fragment f = Fragment.instantiate(mContext, clss.getName(), args);

    return f;
  }
    @Override
    public Fragment getItem(int position) {
      TabInfo info = mTabInfos.get(position);
      if (info.fragment == null)
        info.fragment = Fragment.instantiate(mActivity, info._clss.getName(), info._args);

      return info.fragment;
    }
Esempio n. 25
0
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
   final Fragment fragment = Fragment.instantiate(this, LicenseFragment.class.getName());
   ft.replace(android.R.id.content, fragment);
   ft.commit();
 }
Esempio n. 26
0
 public TakeImageFragment show() {
   TakeImageFragment takeImageCapture =
       (TakeImageFragment)
           Fragment.instantiate(mContext, TakeImageFragment.class.getName(), prepareArguments());
   takeImageCapture.setTakeImageInterface(takeImageInterface);
   takeImageCapture.show(mFragmentManager, mTag);
   return takeImageCapture;
 }
 @Override
 public android.support.v4.app.Fragment getItem(int position) {
   TabInfo info = mTabs.get(position);
   if (info.fragment == null) {
     info.fragment =
         android.support.v4.app.Fragment.instantiate(mContext, info.clss.getName(), info.args);
   }
   return info.fragment;
 }
 private void switchToHeaderInner(String fragmentName, Bundle args, int direction) {
   getSupportFragmentManager()
       .popBackStack(BACK_STACK_PREFS, FragmentManager.POP_BACK_STACK_INCLUSIVE);
   Fragment f = Fragment.instantiate(this, fragmentName, args);
   FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
   transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
   transaction.replace(R.id.prefs, f);
   transaction.commitAllowingStateLoss();
 }
  private void setupRecentTab() {
    recentFragment =
        (ContactSelectionRecentFragment)
            Fragment.instantiate(this, ContactSelectionRecentFragment.class.getName());

    ActionBar.Tab recentTab = constructTab(recentFragment);
    recentTab.setIcon(R.drawable.ic_tab_recent);
    this.getSupportActionBar().addTab(recentTab);
  }
 private void initContent() {
   if (mFragment == null) {
     mFragment =
         (GanxiProductInfoFragment)
             Fragment.instantiate(this, GanxiProductInfoFragment.class.getName());
     FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
     ft.add(android.R.id.content, mFragment);
     ft.commit();
   }
 }