Esempio n. 1
0
    @Override
    public Fragment getItem(int position) {
      // getItem is called to instantiate the fragment for the given page.
      // Return a DummySectionFragment (defined as a static inner class
      // below) with the page number as its lone argument.
      Fragment fragment = null;
      Bundle args = new Bundle();

      switch (position) {
        case 0:
          fragment = new CategoriesFragment();
          args.putInt(CategoriesFragment.ARG_SECTION_NUMBER, position + 1);
          fragment.setArguments(args);
          break;
        case 1:
          fragment = new DiscoverFragment();
          args.putInt(DiscoverFragment.ARG_SECTION_NUMBER, position + 1);
          fragment.setArguments(args);
          break;
        case 2:
          fragment = new ExploreFragment();
          args.putInt(ExploreFragment.ARG_SECTION_NUMBER, position + 1);
          fragment.setArguments(args);
          break;
        case 3:
          fragment = new My_ShowsFragment();
          args.putInt(My_ShowsFragment.ARG_SECTION_NUMBER, position + 1);
          fragment.setArguments(args);
          break;
      }

      return fragment;
    }
Esempio n. 2
0
 @Override
 public Fragment getItem(int position) {
   switch (position) {
     case 0:
       Fragment sectionOneFrag = new AddsSectionFragment();
       Bundle args1 = new Bundle();
       args1.putInt(AddsSectionFragment.ARG_SECTION_NUMBER, position + 1);
       sectionOneFrag.setArguments(args1);
       return sectionOneFrag;
     case 1:
       Fragment sectionTwoFrag = new RenewalSectionFragment();
       Bundle args2 = new Bundle();
       args2.putInt(RenewalSectionFragment.ARG_SECTION_NUMBER, position + 1);
       sectionTwoFrag.setArguments(args2);
       return sectionTwoFrag;
     case 2:
       Fragment sectionThreeFrag = new AccessorySectionFragment();
       Bundle args3 = new Bundle();
       args3.putInt(AccessorySectionFragment.ARG_SECTION_NUMBER, position + 1);
       sectionThreeFrag.setArguments(args3);
       return sectionThreeFrag;
     default:
       // The other sections of the app are dummy placeholders.
       Fragment fragment = new AddsSectionFragment();
       Bundle args = new Bundle();
       args.putInt(AddsSectionFragment.ARG_SECTION_NUMBER, position + 1);
       fragment.setArguments(args);
       return fragment;
   }
 }
Esempio n. 3
0
 @Override
 public Fragment getItem(int i) {
   Bundle bundle = new Bundle();
   bundle.putString("institution_name", institution_name);
   bundle.putString("institution_code", institution_code);
   bundle.putString("id", id);
   bundle.putString("classId", classId);
   bundle.putString("classGradeId", classGradeId);
   switch (i) {
     case 0:
       // Fragement for student information
       Fragment student_info = new student_info();
       student_info.setArguments(bundle);
       return student_info;
     case 1:
       // Fragment for attendance
       Fragment student_attendance = new student_attendance();
       student_attendance.setArguments(bundle);
       return student_attendance;
     case 2:
       // Fragment for result
       Fragment student_result = new student_result();
       student_result.setArguments(bundle);
       return student_result;
   }
   return null;
 }
Esempio n. 4
0
  private void updateState(AuthState state) {
    if (this.state != null && this.state == state) {
      return;
    }
    this.state = state;

    switch (state) {
      case AUTH_START:
        Fragment chooseAuthFr = new ChooseAuthTypeFragment();
        Bundle b = new Bundle();
        b.putInt(SIGN_TYPE_KEY, signType);
        chooseAuthFr.setArguments(b);
        showFragment(chooseAuthFr, false, false);
        break;
      case AUTH_EMAIL:
        showFragment(new SignEmailFragment(), false, false);
        authType = AUTH_TYPE_EMAIL;
        break;
      case AUTH_PHONE:
        showFragment(new SignPhoneFragment(), false, false);
        authType = AUTH_TYPE_PHONE;
        break;
      case CODE_VALIDATION_PHONE:
      case CODE_VALIDATION_EMAIL:
        if ((state == AuthState.CODE_VALIDATION_EMAIL && authType == AUTH_TYPE_PHONE)
            || (state == AuthState.CODE_VALIDATION_PHONE && authType == AUTH_TYPE_EMAIL)) {
          updateState(AuthState.AUTH_START);
          break;
        }
        Fragment signInFragment = new SignInFragment();
        Bundle args = new Bundle();
        args.putString(
            "authType",
            state == AuthState.CODE_VALIDATION_EMAIL
                ? SignInFragment.AUTH_TYPE_EMAIL
                : SignInFragment.AUTH_TYPE_PHONE);
        signInFragment.setArguments(args);
        showFragment(signInFragment, false, false);
        break;
      case GET_OAUTH_PARAMS:
        executeAuth(messenger().requestGetOAuthParams(), "get_oauth_params");
        break;
      case COMPLETE_OAUTH:
        if (authType == AUTH_TYPE_PHONE) {
          updateState(AuthState.AUTH_START);
          break;
        }

        showFragment(new OAuthFragment(), false, false);
        break;
      case SIGN_UP:
        showFragment(new SignUpFragment(), false, false);
        break;
      case LOGGED_IN:
        messenger().trackAuthSuccess();
        finish();
        startActivity(new Intent(this, MainActivity.class));
        break;
    }
  }
Esempio n. 5
0
  private void showFragment(String key, @Nullable Bundle args) {

    tvHinweis.setVisibility(View.GONE);

    Fragment fragment = null;
    switch (key) {
      case "hint": // test
        fragment = new HintFragment();
        Bundle bundle = new Bundle();
        bundle.putString("hint", "Hinweis");
        fragment.setArguments(bundle);
        break;

      case "about": // test
        fragment = new AboutFragment();
        break;

      case "list": // ok
        fragment = new ContactListFragment();
        fragment.setArguments(args);
        break;

      default:
        break;
    }
    if (fragment != null) {
      FragmentManager frgManager = getSupportFragmentManager();
      frgManager.beginTransaction().replace(R.id.fragment_container, fragment).commit();
    }
  }
 private void navigateNextPhrase(int phraseIndex) {
   if (phraseIndex >= getStudy().getPhrases().size()) {
     finishInterview();
   } else {
     Bundle args = new Bundle();
     args.putInt(ARG_PHRASE_INDEX, phraseIndex);
     Phrase phrase = getStudy().getPhrases().get(phraseIndex);
     if (!StringUtils.isNullOrEmpty(phrase.getAudio_url())) {
       Fragment fragment = new AudioPlaybackFragment();
       fragment.setArguments(args);
       transactTo(
           getMainFragmentContainerId(), fragment, AudioPlaybackFragment.TAG + "_" + phraseIndex);
     } else if (phrase.getResponse_type() == Phrase.TYPE_AUDIO
         || phrase.getResponse_type() == Phrase.TYPE_TEXT_AUDIO) {
       Fragment fragment = new RecordingAudioFragment();
       fragment.setArguments(args);
       transactTo(
           getMainFragmentContainerId(), fragment, RecordingAudioFragment.TAG + "_" + phraseIndex);
     } else {
       Fragment fragment = new RecordingTextFragment();
       fragment.setArguments(args);
       transactTo(
           getMainFragmentContainerId(), fragment, RecordingTextFragment.TAG + "_" + phraseIndex);
     }
   }
 }
  @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);
    }
  }
 public Fragment getItem(int position) {
   Fragment fragment = new SampleFragment_();
   Bundle bundle = new Bundle();
   bundle.putString("label", locations[position]);
   fragment.setArguments(bundle);
   return fragment;
 }
Esempio n. 9
0
  private void initData(Bundle savedInstanceState) {
    if (savedInstanceState != null) {
      mCurrSelectedTabId = savedInstanceState.getInt(KEY_CURR_SELECTED_TAB_ID);
    } else {
      mCurrSelectedTabId = R.id.stock_button;
    }

    mFragmentManager = getSupportFragmentManager();

    mStockFragment = mFragmentManager.findFragmentByTag(TAG_STOCK_FRAGMENT);
    if (mStockFragment == null) {
      mStockFragment = new StockFragment();
      Bundle args = new Bundle();
      mStockFragment.setArguments(args);

      FragmentTransaction trans = mFragmentManager.beginTransaction();
      trans.add(R.id.fragment_container, mStockFragment, TAG_STOCK_FRAGMENT);
      trans.commitAllowingStateLoss();
    }

    mNoteFragment = mFragmentManager.findFragmentByTag(TAG_NOTE_FRAGMENT);
    if (mNoteFragment == null) {
      mNoteFragment = new NoteFragment();

      FragmentTransaction trans = mFragmentManager.beginTransaction();
      trans.add(R.id.fragment_container, mNoteFragment, TAG_NOTE_FRAGMENT);
      trans.commitAllowingStateLoss();
    }
  }
  @Override
  public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments

    switch (position) {
      case 0:
        fragment = PlaceholderFragment.newInstance(position + 1);
        break;
      case 1:
        fragment = NoticiasFragment.newInstance(position + 1);
        break;
      case 2:
        fragment = CDFragment.newInstance(position + 1);
        break;
      case 3:
        fragment = ParquesFragment.newInstance(position + 1);
        break;
      case 4:
        Bundle bundle = new Bundle();
        bundle.putBoolean("logged", logged);
        fragment = ReporteProblema.newInstance(position + 1);
        fragment.setArguments(bundle);
        break;
      case 5:
        fragment = SolicitudesFragment.newInstance(position + 1);
        break;
    }
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();
  }
 @Override
 public Fragment getItem(int position) {
   Fragment moduleFragment = new ModuleListFragment();
   Bundle bundle = new Bundle();
   bundle.putString(Module.Program.class.getCanonicalName(), Module.Program.BIN);
   String module = null;
   switch (position) {
     case 0:
       module = null;
       break;
     case 1:
       module = Module.Level.ONE;
       break;
     case 2:
       module = Module.Level.TWO;
       break;
     case 3:
       module = Module.Level.THREE;
       break;
     case 4:
       module = Module.Level.FOUR;
       break;
   }
   bundle.putString(Module.Level.class.getCanonicalName(), module);
   moduleFragment.setArguments(bundle);
   return moduleFragment;
 }
Esempio n. 12
0
 @Override
 public Fragment getItem(int position) {
   // getItem is called to instantiate the fragment for the given page.
   // Return a DummySectionFragment (defined as a static inner class
   // below) with the page number as its lone argument.
   String menu = getArguments().getString("Menu");
   String username = getArguments().getString("User");
   String pass = getArguments().getString("Pass");
   String cokie = getArguments().getString("Cook");
   String sub_name[] = getArguments().getStringArray("Array");
   String day[] = getArguments().getStringArray("Array1");
   int rpc[] = getArguments().getIntArray("Array2");
   String cl_time[] = getArguments().getStringArray("Array3");
   String sub_fac[] = getArguments().getStringArray("Array4");
   String block[] = getArguments().getStringArray("Array5");
   Fragment fragment = new DummySectionFragment();
   Bundle args = new Bundle();
   args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
   args.putString("Menu", "He");
   args.putString("User", username);
   args.putString("Pass", pass);
   args.putString("Cook", cokie);
   args.putString("POSS", position + "");
   args.putStringArray("Array", sub_name);
   args.putStringArray("Array1", day);
   args.putIntArray("Array2", rpc);
   args.putStringArray("Array3", cl_time);
   args.putStringArray("Array4", sub_fac);
   args.putStringArray("Array5", block);
   fragment.setArguments(args);
   return fragment;
 }
Esempio n. 13
0
    @Override
    public Fragment getItem(int i) {
      switch (i) {
        case 0:
          // The first section of the app is the most interesting -- it offers
          // a launchpad into the other demonstrations in this example application.
          return new FirstSectionFragment();

        case 1:
          return new SecondSectionFragment();

        default:
          //                    // The other sections of the app are dummy placeholders.
          //                    Fragment fragment = new DummySectionFragment();
          //                    Bundle args = new Bundle();
          //                    args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1);
          //                    fragment.setArguments(args);
          //                    return fragment;

          // TODO ueberhaupt noetig?
          Fragment fragment = new FirstSectionFragment();
          Bundle args = new Bundle();
          args.putInt(FirstSectionFragment.ARG_SECTION_NUMBER, i + 1);
          fragment.setArguments(args);
          return fragment;
      }
    }
  @Override
  public void init(Bundle savedInstanceState) {

    drawer = this;

    // information text for the fragment
    Bundle bundle = new Bundle();
    bundle.putString(
        "instruction",
        "Press on the section 'section title' and see the fragment title bar."
            + " It has another title.");

    Fragment fragmentInstruction = new FragmentInstruction();
    fragmentInstruction.setArguments(bundle);

    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(
        new MaterialItemSectionFragment(
            this, "Instruction", fragmentInstruction, "Section With Custom Fragment Title"));
    menu.add(
        new MaterialItemSectionFragment(
            this, "section title", new FragmentDummy(), "Fragment title 1"));

    // load menu
    this.loadMenu(menu);

    // load the MaterialItemSectionFragment, from the given startIndex
    this.loadStartFragmentFromMenu(menu);
  }
  @Override
  public Fragment getItem(final int position) {
    final Bundle bundle = new Bundle();

    Fragment fragment = null;

    // retrieve the page fragment based on the page position
    switch (position) {
      case PAGE_ARTICLE:
        bundle.putString(ArticleContentFragment.EXTRA_URL, url);
        fragment = new ArticleContentFragment();
        break;
      case PAGE_COMMENTS:
        bundle.putString(ArticleCommentsFragment.EXTRA_URL, url);
        fragment = new ArticleCommentsFragment();
        break;
    }

    if (fragment != null) {
      fragment.setArguments(bundle);
      return fragment;
    }

    return null;
  }
  /** This method will be invoked when a page is requested to create */
  @Override
  public Fragment getItem(int page) {

    // Temporary
    Fragment fragment = null;

    // For each page, create a fragment
    switch (page) {
      case 0:
        fragment = new All();
        all = (All) fragment;
        break;

      case 1:
        fragment = new TopHits();
        topHits = (TopHits) fragment;
        break;
    }

    // Give the fragment an information about which pagenumber it is
    Bundle data = new Bundle();
    data.putInt("current_page", page + 1);
    fragment.setArguments(data);

    return fragment;
  }
 public Fragment enterpriseLoginWithSocial(Connection connection) {
   final Fragment fragment = loginWithSocial();
   Bundle bundle = fragment.getArguments() == null ? new Bundle() : fragment.getArguments();
   bundle.putParcelable(DatabaseLoginFragment.DEFAULT_CONNECTION_ARGUMENT, connection);
   fragment.setArguments(bundle);
   return fragment;
 }
Esempio n. 18
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_note);

    final Intent i = getIntent();
    final int noteIndex = i.getIntExtra(EXTRA_NOTE_INDEX, -1);
    if (noteIndex == -1) {
      Toast.makeText(this, R.string.toast_cant_open_note, Toast.LENGTH_SHORT).show();
      finish();
    }

    final Bundle bundleForFragment = new Bundle();
    bundleForFragment.putInt(BUNDLE_NOTE_INDEX, noteIndex);

    /*
     * TODO:
     * this is temporary. we need to identify the type of note,
     * open the appropriate fragment
     */
    final FragmentManager fm = getSupportFragmentManager();
    Fragment f = new SimpleNoteFragment();
    f.setArguments(bundleForFragment);
    fm.beginTransaction().add(R.id.fragment, f).commit();
  }
 private void init() {
   bundle = getIntent().getExtras();
   if (bundle != null) {
     if (bundle.containsKey("fragmentName")) {
       fragmentName = bundle.getString("fragmentName");
     }
     if (bundle.containsKey("title")) {
       title = bundle.getString("title");
     }
     if (bundle.containsKey("parameters")) {
       parameters = bundle.getBundle("parameters");
     }
   }
   if (fragmentName.length() > 0) {
     try {
       fragment = (Fragment) Class.forName(fragmentName).newInstance();
       if (parameters != null) {
         fragment.setArguments(parameters);
       }
     } catch (InstantiationException e) {
       e.printStackTrace();
     } catch (IllegalAccessException e) {
       e.printStackTrace();
     } catch (ClassNotFoundException e) {
       e.printStackTrace();
     }
   }
 }
Esempio n. 20
0
    @Override
    public void onClick(View v) {
      if (v.getId() == DYNAMIC_IMAGE_ID) {
        Intent intent = new Intent(getActivity().getApplicationContext(), PrototypeActivity.class);

        intent.putExtra(PrototypeActivity.ACTION, "compose");
        intent.putExtra(PrototypeActivity.ORDER, 8);
        startActivity(intent);
      }

      int topic_id = v.getId() - DYNAMIC_TOPIC_ID;

      if (topic_id >= 0) {
        Fragment fragment = new DummySectionFragment();
        Bundle args = new Bundle();
        args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, DummySectionFragment.HOME);

        args.putInt(DummySectionFragment.ARG_MAIN_TAB_NUMBER, topic_id);

        fragment.setArguments(args);
        getActivity()
            .getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.container, fragment)
            .commit();
      }
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_command_man);

    // Get unique command id
    Bundle b = getIntent().getExtras();
    long id = b.getLong(EXTRA_COMMAND_ID);

    // Init cursor
    CommandsDbHelper mDbHelper = new CommandsDbHelper(this);
    SQLiteDatabase db = mDbHelper.getReadableDatabase();
    Cursor c = db.rawQuery("SELECT * FROM commands WHERE _id = " + id, null);
    c.moveToFirst();

    // Get command name
    String name = c.getString(c.getColumnIndex(CommandsDBTableModel.COL_NAME)).toUpperCase();

    // Set name as actionbar title
    setTitle(name);

    Fragment fragment = new CommandManFragment();

    // Add unique command ID for fragment
    fragment.setArguments(b);

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

    fragmentTransaction.replace(R.id.fragment_container, fragment);
    fragmentTransaction.commit();
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Obtain the requested announcement ID.
    Intent intent = getIntent();
    announcementId = intent.getLongExtra("announcementId", -1);
    if (announcementId == -1) {
      throw new IllegalStateException("No announcement ID was passed to ViewAnnouncementActivity");
    }

    // Set up the action bar.
    ActionBar bar = getActionBar();
    bar.setDisplayHomeAsUpEnabled(true);

    // Set up our view.
    setContentView(R.layout.view_announcement_activity);
    if (savedInstanceState == null) {
      // Prepare the fragment.
      Bundle args = new Bundle(intent.getExtras());
      Fragment fragment = new ViewAnnouncementFragment();
      fragment.setArguments(args);

      // Add the fragment.
      FragmentManager manager = getSupportFragmentManager();
      FragmentTransaction transaction = manager.beginTransaction();
      transaction.add(R.id.view_announcement_activity_fragment_container, fragment);
      transaction.commit();
    }
  }
Esempio n. 23
0
 protected void addFragment(String type) {
   Fragment fragment = new AlertsListFragment();
   Bundle args = new Bundle();
   args.putString(AlertsListFragment.ARG_TYPE, type);
   fragment.setArguments(args);
   fragments.add(fragment);
 }
 /**
  * @param fragmentsToInt - integer representation of fragments 0 - ExploreFragment, 1 -
  *     SearchResultFragment, 2 - RunsFragments 3 - LaunchHistoryFragments, 4 - MyWorkflowFragment,
  *     5 - FavouriteWorkflowFragment
  * @param backStackTag
  */
 private void beginFragmentTransaction(int[] fragmentsToInt, String backStackTag) {
   FragmentManager fm = parentActivity.getSupportFragmentManager();
   FragmentTransaction ft = fm.beginTransaction();
   // ft.setCustomAnimations(R.anim.push_left_in, R.anim.push_left_out);
   // boolean successfullypopped = fm.popBackStackImmediate(backStackTag, 1);
   // if(!successfullypopped){
   Fragment newFragment = new FragmentsContainer();
   Bundle args = new Bundle();
   args.putIntArray("fragmentsToInstantiate", fragmentsToInt);
   newFragment.setArguments(args);
   ft.addToBackStack(backStackTag);
   if (previousSelectedFragTag == null) {
     fm.beginTransaction().hide(fm.findFragmentByTag("StarterFragments")).commit();
   } else {
     fm.beginTransaction().hide(fm.findFragmentByTag(previousSelectedFragTag)).commit();
   }
   previousSelectedFragTag = backStackTag;
   ft.replace(R.id.main_panel_root, newFragment, backStackTag).commit();
   // }
   // smooth transaction
   new Handler()
       .postDelayed(
           new Runnable() {
             public void run() {
               // close the menu
               ((MainPanelActivity) parentActivity).getMenu().toggle();
             }
           },
           500);
 }
Esempio n. 25
0
  public void openFragment(
      Class<? extends Fragment> fragmentClazz, Bundle args, boolean addBackStack) {
    FragmentManager manager = getSupportFragmentManager();
    FragmentTransaction transaction = manager.beginTransaction();
    String tag = fragmentClazz.getName();

    try {
      if (!isFragmentAdded(tag)) {
        Fragment fragment = null;

        fragment = fragmentClazz.newInstance();
        if (args != null) {
          fragment.setArguments(args);
        }

        Fragment fragCurr = FragmentUtils.getCurrentFragment(this);
        if (fragCurr != null) transaction.hide(fragCurr);
        transaction.add(R.id.frameContent, fragment, tag);
        if (addBackStack) {
          transaction.addToBackStack(tag);
        }
        transaction.commit();

      } else {
        showFragment(tag, transaction);
      }

    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
  }
  /** {@inheritDoc} */
  @Override
  public void openActivityOrFragment(final Intent intent) {
    final PackageManager pm = getPackageManager();
    List<ResolveInfo> resolveInfoList =
        pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo resolveInfo : resolveInfoList) {
      final FragmentReplaceInfo fri =
          onSubstituteFragmentForActivityLaunch(resolveInfo.activityInfo.name);
      if (fri != null) {
        final Bundle arguments = intentToFragmentArguments(intent);
        final FragmentManager fm = getSupportFragmentManager();

        try {
          Fragment fragment = (Fragment) fri.getFragmentClass().newInstance();
          fragment.setArguments(arguments);

          FragmentTransaction ft = fm.beginTransaction();
          ft.replace(fri.getContainerId(), fragment, fri.getFragmentTag());
          onBeforeCommitReplaceFragment(fm, ft, fragment);
          ft.commit();
        } catch (InstantiationException e) {
          throw new IllegalStateException("Error creating new fragment.", e);
        } catch (IllegalAccessException e) {
          throw new IllegalStateException("Error creating new fragment.", e);
        }
        return;
      }
    }
    super.openActivityOrFragment(intent);
  }
 // TODO: Rename and change types and number of parameters
 public static Fragment newInstance(int pageNumber) {
   Fragment fragment = new WineryAToZFragment();
   Bundle args = new Bundle();
   args.putInt(PAGE_NUMBER, pageNumber);
   fragment.setArguments(args);
   return fragment;
 }
  /**
   * * Swaps fragments in the main content view
   *
   * @param position - Defines the item "position" based on integer value
   */
  public void selectDrawerItem(int position) {
    // Create a new fragment and specify the planet to show based on position
    FragmentNavItem navItem = drawerNavItems.get(position);
    // Initialize fragment variable
    Fragment fragment = null;
    try {
      fragment = navItem.getFragmentClass().newInstance();

      Bundle args = navItem.getFragmentArgs();
      if (args != null) {
        fragment.setArguments(args);
      }
    } catch (Exception e) {
      e.printStackTrace();
      Log.e("MainActivity", "Error in creating fragment");
    }

    // Insert the fragment by replacing any existing fragment
    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(drawerContainerRes, fragment).commit();

    // Highlight the selected item, update the title, and close the drawer
    lvDrawer.setItemChecked(position, true);
    setTitle(navItem.getTitle());
    closeDrawer(lvDrawer);
  }
Esempio n. 29
0
 public static Fragment newInstance(String url) {
   Fragment fragment = new PediaFragment();
   Bundle args = new Bundle();
   args.putString(EXTRA_URL, url);
   fragment.setArguments(args);
   return fragment;
 }
 @Override
 public Fragment getItem(int position) {
   Fragment fragment = new DemoObjectFragment();
   Bundle args = new Bundle();
   args.putInt(DemoObjectFragment.ARG_OBJECT, position);
   fragment.setArguments(args);
   return fragment;
 }