Java Code Examples for android.support.v4.app.Fragment#instantiate()

The following examples show how to use android.support.v4.app.Fragment#instantiate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentBuildUriRequest.java    From WMRouter with Apache License 2.0 6 votes vote down vote up
@Override
protected StartFragmentAction getStartFragmentAction() {
    return new StartFragmentAction() {
        @Override
        public boolean startFragment(@NonNull UriRequest request, @NonNull Bundle bundle) throws ActivityNotFoundException, SecurityException {
            String fragmentClassName = request.getStringField(FragmentTransactionHandler.FRAGMENT_CLASS_NAME);
            if (TextUtils.isEmpty(fragmentClassName)) {
                Debugger.fatal("FragmentBuildUriRequest.handleInternal()应返回的带有ClassName");
                return false;
            }
            try {
                Fragment fragment = Fragment.instantiate(request.getContext(), fragmentClassName, bundle);
                if (fragment == null) {
                    return false;
                }
                //自定义处理不做transaction,直接放在request里面回调
                request.putField(FRAGMENT,fragment);
                return true;
            } catch (Exception e) {
                Debugger.e(e);
                return false;
            }
        }
    };
}
 
Example 2
Source File: PartFileActivity.java    From aMuleRemote with GNU General Public License v3.0 6 votes vote down vote up
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
    
    FragmentTransaction realFT = getFT(ft);
    
    
    // Check if the fragment is already initialized
    if (mFragment == null) {
        // If not, instantiate and add it to the activity
        mFragment = Fragment.instantiate(mActivity, mClass.getName());
        Bundle b = new Bundle();
        b.putByteArray(BUNDLE_PARAM_HASH, mHash);
        mFragment.setArguments(b);
        //realFT.add(R.id.partfile_tabcontent, mFragment, mTag);
        
        // http://stackoverflow.com/questions/9083747/android-ics-actionbar-tabs-orientation-change
        realFT.replace(R.id.partfile_tabcontent, mFragment, mTag);
    } else {
        // If it exists, simply attach it in order to show it
        realFT.attach(mFragment);
    }
    
    if (ft == null) realFT.commit();
}
 
Example 3
Source File: MainActivity.java    From rootvalidator with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    MVPBakery.<MainActivityPresenter.View, MainActivityPresenter>builder()
            .presenterFactory(new InjectedPresenter<>(this))
            .presenterRetainer(new ViewModelRetainer<>(this))
            .addPresenterCallback(new PresenterInjectionCallback<>(this))
            .attach(this);

    setContentView(R.layout.activity_mainactivity_layout);
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(getFragmentClass());
    if (fragment == null) {
        fragment = Fragment.instantiate(this, getFragmentClass());
        getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment, getFragmentClass()).commit();
    }
}
 
Example 4
Source File: FragmentActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle bundle)
{
    super.onCreate(bundle);

    setContentView(R.layout.atom_ui_activity_blank);
    QtNewActionBar actionBar = (QtNewActionBar) findViewById(R.id.my_action_bar);
    setNewActionBar(actionBar);
    Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null) {

        if (intent.getExtras().containsKey(CONTENT)) {
            String fragmentName = intent.getExtras().getString(CONTENT);
            if (fragmentName != null) {
                Fragment fragment = Fragment.instantiate(this, fragmentName, intent.getExtras());

                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                transaction.replace(R.id.layout_blanck_content, fragment);
                transaction.commit();
            }
        }
        String title = getIntent().getStringExtra(TITLE);
        if (!TextUtils.isEmpty(title)) {
            setActionBarTitle(title);
        }
    }
}
 
Example 5
Source File: MainActivity.java    From Androzic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onRouteWaypointEdit(Route route, Waypoint waypoint)
{
	FragmentManager fm = getSupportFragmentManager();
	WaypointProperties waypointProperties = (WaypointProperties) fm.findFragmentByTag("waypoint_properties");
	if (waypointProperties == null)
		waypointProperties = (WaypointProperties) Fragment.instantiate(this, WaypointProperties.class.getName());
	waypointProperties.setWaypoint(waypoint, route);
	addFragment(waypointProperties, "waypoint_properties");
}
 
Example 6
Source File: UserMenu.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
private void showUserComment(final boolean edit) {
    Bundle args = new Bundle();
    args.putInt("session", mUser.getSession());
    args.putString("comment", mUser.getComment());
    args.putBoolean("editing", edit);
    UserCommentFragment fragment = (UserCommentFragment) Fragment.instantiate(mContext, UserCommentFragment.class.getName(), args);
    fragment.show(mFragmentManager, UserCommentFragment.class.getName());
}
 
Example 7
Source File: JamMainTabbedActivity.java    From jam-collaboration-sample with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_jam_main);

    pageAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            Class clss;
            switch(position) {
                case 0:
                    clss = JamFeedWidgetFragment.class;
                    break;
                case 1:
                    clss = JamGroupsListRename.class;
                    break;
                default:
                    throw new RuntimeException("Invalid tab index: " + position);
            }
            return Fragment.instantiate(JamSDKDemoApp.getAppContext(), clss.getName());
        }

        @Override
        public int getCount() {
            return 2;
        }
    };
    viewPager = (ViewPager) findViewById(R.id.viewpager);
    viewPager.setAdapter(pageAdapter);

}
 
Example 8
Source File: ActionSheet.java    From android-ActionSheet with MIT License 5 votes vote down vote up
public ActionSheet show() {
    ActionSheet actionSheet = (ActionSheet) Fragment.instantiate(
            mContext, ActionSheet.class.getName(), prepareArguments());
    actionSheet.setActionSheetListener(mListener);
    actionSheet.show(mFragmentManager, mTag);
    return actionSheet;
}
 
Example 9
Source File: MainActivity.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
private void launchFragmentForSubreddit(String subredditName) {
    disableDrawer();
    Bundle bundle = new Bundle();
    bundle.putString(SubscriptionActivity.RESULT_SUBREDDIT_NAME, subredditName);

    HomeFragment homeFragment = (HomeFragment) Fragment
            .instantiate(getBaseActivity(), Fragments.HOME.getFragment());
    homeFragment.setArguments(bundle);

    openFragmentWithResult(homeFragment, Fragments.HOME.toString());
}
 
Example 10
Source File: ArgumentManager.java    From mv2m with Apache License 2.0 4 votes vote down vote up
public static <ARG, VM extends ViewModel<ARG, ?>, F extends ViewModelFragment<VM>> F instantiateFragment(Activity activity, Class<F> cls, ARG argument) {
    Bundle args = new Bundle();
    writeArgument(args, argument);
    return (F) Fragment.instantiate(activity, cls.getName(), args);
}
 
Example 11
Source File: MusicLibraryPagerAdapter.java    From Orin with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Fragment getItem(final int position) {
    final Holder mCurrentHolder = mHolderList.get(position);
    return Fragment.instantiate(mContext,
            mCurrentHolder.mClassName, mCurrentHolder.mParams);
}
 
Example 12
Source File: ArtistDetailPagerAdapter.java    From Orin with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Fragment getItem(final int position) {
    final Holder mCurrentHolder = mHolderList.get(position);
    return Fragment.instantiate(mContext,
            mCurrentHolder.mClassName, mCurrentHolder.mParams);
}
 
Example 13
Source File: PlumbleActivity.java    From Plumble with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Loads a fragment from the drawer.
 */
private void loadDrawerFragment(int fragmentId) {
    Class<? extends Fragment> fragmentClass = null;
    Bundle args = new Bundle();
    switch (fragmentId) {
        case DrawerAdapter.ITEM_SERVER:
            fragmentClass = ChannelFragment.class;
            break;
        case DrawerAdapter.ITEM_INFO:
            fragmentClass = ServerInfoFragment.class;
            break;
        case DrawerAdapter.ITEM_ACCESS_TOKENS:
            fragmentClass = AccessTokenFragment.class;
            Server connectedServer = getService().getTargetServer();
            args.putLong("server", connectedServer.getId());
            args.putStringArrayList("access_tokens", (ArrayList<String>) mDatabase.getAccessTokens(connectedServer.getId()));
            break;
        case DrawerAdapter.ITEM_PINNED_CHANNELS:
            fragmentClass = ChannelFragment.class;
            args.putBoolean("pinned", true);
            break;
        case DrawerAdapter.ITEM_FAVOURITES:
            fragmentClass = FavouriteServerListFragment.class;
            break;
        case DrawerAdapter.ITEM_PUBLIC:
            fragmentClass = PublicServerListFragment.class;
            break;
        case DrawerAdapter.ITEM_SETTINGS:
            Intent prefIntent = new Intent(this, Preferences.class);
            startActivity(prefIntent);
            return;
        default:
            return;
    }
    Fragment fragment = Fragment.instantiate(this, fragmentClass.getName(), args);
    getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, fragment, fragmentClass.getName())
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                .commit();
    setTitle(mDrawerAdapter.getItemWithId(fragmentId).title);
}
 
Example 14
Source File: TabsAdapter.java    From mytracks with Apache License 2.0 4 votes vote down vote up
@Override
public Fragment getItem(int position) {
  TabInfo info = tabInfos.get(position);
  return Fragment.instantiate(context, info.clss.getName(), info.bundle);
}
 
Example 15
Source File: TabAdapter.java    From AndroidCacheFoundation with Apache License 2.0 4 votes vote down vote up
@Override
public Fragment getItem(int position) {
    TabInfo info = mTabs.get(position);
    return Fragment.instantiate(mContext, info.getFragmentClazz());
}
 
Example 16
Source File: HomeActivity.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unused")
@Override
public void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);

	cacheWord = new CacheWordHandler(this, this);
	cacheWord.connectToService();
	
	informaCam = (InformaCam)getApplication();		
	informaCam.setEventListener(this);
	
	if(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("prefBlockScreenshots", false))
	{
  		getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
  				WindowManager.LayoutParams.FLAG_SECURE);      
	}
	
	setContentView(R.layout.activity_home);

	try
	{
		Iterator<String> i = savedInstanceState.keySet().iterator();
		while (i.hasNext())
		{
			String outState = i.next();
			if (outState.equals(Home.TAG) && savedInstanceState.getBoolean(Home.TAG))
			{
				initGallery = true;
			}
		}
	}
	catch (NullPointerException e)
	{
	}

	toEditor = new Intent(this, EditorActivity.class);
	toCamera = new Intent(this, CameraActivity.class);
	route = null;

	mainFragment = (HomeFragment) Fragment.instantiate(this, HomeFragment.class.getName());
	if (USE_USER_MANAGEMENT_FRAGMENT == 1)
		userManagementFragment = Fragment.instantiate(this, UserManagementFragment.class.getName());
	galleryFragment = (GalleryFragment) Fragment.instantiate(this, GalleryFragment.class.getName());
	cameraFragment = Fragment.instantiate(this, CameraFragment.class.getName());

	fragments.add(mainFragment);
	if (USE_USER_MANAGEMENT_FRAGMENT == 1)
		fragments.add(userManagementFragment);
	fragments.add(galleryFragment);
	fragments.add(cameraFragment);

	init = getIntent();

	initLayout();
	launchMain();
}
 
Example 17
Source File: CompatActivity.java    From NoFragment with Apache License 2.0 4 votes vote down vote up
public final <T extends NoFragment> T fragment(Class<T> fragmentClass, Bundle bundle) {
    //noinspection unchecked
    return (T) Fragment.instantiate(this, fragmentClass.getName(), bundle);
}
 
Example 18
Source File: FragmentViewItem.java    From PrismView with Apache License 2.0 4 votes vote down vote up
public Fragment instantiate(Context context, int position) {
  setPosition(args, position);
  return Fragment.instantiate(context, className, args);
}
 
Example 19
Source File: MainActivity.java    From Androzic with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onOpenMap()
{
       MapList mapList = (MapList) Fragment.instantiate(this, MapList.class.getName());
	addFragment(mapList, "map_list");
}
 
Example 20
Source File: FragmentPagerItem.java    From material-scrolling with Apache License 2.0 4 votes vote down vote up
public Fragment newInstance(final Context context) {
    return Fragment.instantiate(context, mFragmentClass.getName(), mArgs);
}