Java 类android.support.v4.app.Fragment 实例源码

项目:mobile-dashboard    文件:TabsPagerAdapter.java   
@Override
public Fragment getItem(int index) {

    switch (index) {
        case 0:
            // System notifications fragment activity
            return new SystemFragment();
        case 1:
            // Application notifications fragment activity
            return new AppsFragment();
        case 2:
            // Stats fragment activity
            return new StatsFragment();
        case 3:
            // Settings fragment activity
            return new StatsFragment();
    }

    return null;
}
项目:RecyclerViewPreferences    文件:SettingsFragment.java   
public void setUseExpandableHeaders(boolean enabled) {
    if (isViewPager()) {
        Collection<Fragment> fragments = mPagerAdapter.getAllCachedFragments();
        for (Fragment f : fragments) {
            ((SettingsFragment) f).setUseExpandableHeaders(enabled);
        }
    } else {
        setup.setUseExpandableHeaders(enabled);
        getArguments().putParcelable("setup", setup);
        if (mItems != null) {
            if (!enabled) {
                FastAdapterUtil.expand(mFastItemAdapter);
            }
            SettingsUtil.updateExpandableHeaders(mItems, enabled);
            SettingsUtil.setExpandedState(mItems, true);
            mFastItemAdapter.notifyAdapterDataSetChanged();
        }
    }
}
项目:PictureShow    文件:PhotoViewFragment.java   
public static Fragment newInstance(Cursor c, int position) {
    final Fragment f = new PhotoViewFragment();
    final Bundle b = new Bundle();

    int photoID = c.getInt(0);
    b.putInt(MediaSetUtils.PHOTO_ID, photoID);

    String path = c.getString(1);
    b.putString(MediaSetUtils.PHOTO_PATH, path);

    String type = c.getString(2);
    b.putInt(TYPE, type == null ? MediaSetUtils.TYPE_IMAGE :
            (type.startsWith("video") ? MediaSetUtils.TYPE_VIDEO : MediaSetUtils.TYPE_IMAGE));

    b.putInt(CURRENT_POSITION, position);
    f.setArguments(b);
    return f;
}
项目:sealtalk-android-master    文件:RecognizePlugin.java   
@Override
public void onClick(Fragment currentFragment, final RongExtension extension) {
    String[] permissions = {Manifest.permission.RECORD_AUDIO};
    if (!PermissionCheckUtil.requestPermissions(currentFragment, permissions)) {
        return;
    }
    if (SpeechUtility.getUtility() == null) {
        SpeechUtility.createUtility(extension.getContext().getApplicationContext(), SpeechConstant.APPID + "=581f2927"); //初始化
    }
    recognizerView = new RecognizerView(extension.getContext());
    recognizerView.setResultCallBack(new IRecognizedResult() {
        @Override
        public void onResult(String data) {
            Editable editable = extension.getInputEditText().getText();
            String str = editable.toString() + data;
            extension.getInputEditText().setText(str);
            extension.getInputEditText().setSelection(str.length());
        }

        @Override
        public void onClearClick() {
            extension.getInputEditText().setText("");
        }
    });
    extension.addPluginPager(recognizerView);
}
项目:CricKotlin    文件:AppInjector.java   
private static void handleActivity(Activity activity) {
    if (activity instanceof HasSupportFragmentInjector) {
        AndroidInjection.inject(activity);
    }
    if (activity instanceof FragmentActivity) {
        ((FragmentActivity) activity).getSupportFragmentManager()
                .registerFragmentLifecycleCallbacks(
                        new FragmentManager.FragmentLifecycleCallbacks() {
                            @Override
                            public void onFragmentCreated(FragmentManager fm, Fragment f,
                                                          Bundle savedInstanceState) {
                                if (f instanceof Injectable) {
                                    AndroidSupportInjection.inject(f);
                                }
                            }
                        }, true);
    }
}
项目:boohee_v5.6    文件:CookSearchActivity.java   
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    if (!ViewUtils.isFastDoubleClick() && this.activity != null) {
        switch (parent.getId()) {
            case R.id.lv_result:
                Fragment addMaterialFragment = AddMaterialFragment.newInstance((
                        (FoodWithUnit) this.mResultAdapter.getItem(position)).code);
                FragmentTransaction transaction = getSupportFragmentManager()
                        .beginTransaction();
                transaction.add(addMaterialFragment, "addMaterialFragment");
                transaction.commitAllowingStateLoss();
                return;
            default:
                return;
        }
    }
}
项目:XinFramework    文件:SupportHelper.java   
public static ISupportFragment getTopFragment(FragmentManager fragmentManager, int containerId) {
    List<Fragment> fragmentList = FragmentationHack.getActiveFragments(fragmentManager);
    if (fragmentList == null) return null;

    for (int i = fragmentList.size() - 1; i >= 0; i--) {
        Fragment fragment = fragmentList.get(i);
        if (fragment instanceof ISupportFragment) {
            ISupportFragment iFragment = (ISupportFragment) fragment;
            if (containerId == 0) return iFragment;

            if (containerId == iFragment.getSupportDelegate().mContainerId) {
                return iFragment;
            }
        }
    }
    return null;
}
项目:USLI2018    文件:AppFragmentPagerAdapter.java   
/**
 * Returns a fragment for the current tab
 * @param position
 * @return a Fragment
 */
@Override
public Fragment getItem(int position) {
    Fragment fragment = null;
    switch(position) {
        case RADIO_FRAGMENT:
            fragment = new RadioFragment();
            break;
        case SENSORS_FRAGMENT:
            fragment = new SensorFragment();
            break;
        case TRACKING_FRAGMENT:
            fragment = new TrackingFragment();
            break;
    }
    return fragment;
}
项目:AndroidProgramming3e    文件:SingleFragmentActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);

    FragmentManager fm = getSupportFragmentManager();
    Fragment fragment = fm.findFragmentById(R.id.fragment_container);

    if (fragment == null) {
        fragment = createFragment();
        fm.beginTransaction()
                .add(R.id.fragment_container, fragment)
                .commit();
    }
}
项目:Android-UtilCode    文件:FragmentUtils.java   
/**
 * 设置背景色
 *
 * @param fragment fragment
 * @param color    背景色
 */
public static void setBackgroundColor(@NonNull Fragment fragment, @ColorInt int color) {
    View view = fragment.getView();
    if (view != null) {
        view.setBackgroundColor(color);
    }
}
项目:Orin    文件:CustomFragmentStatePagerAdapter.java   
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
    Fragment fragment = (Fragment) object;
    if (fragment != mCurrentPrimaryItem) {
        if (mCurrentPrimaryItem != null) {
            mCurrentPrimaryItem.setMenuVisibility(false);
            mCurrentPrimaryItem.setUserVisibleHint(false);
        }
        if (fragment != null) {
            fragment.setMenuVisibility(true);
            fragment.setUserVisibleHint(true);
        }
        mCurrentPrimaryItem = fragment;
    }
}
项目:BuddyBook    文件:MainActivity.java   
public void refreshCurrentFragment(){
    Fragment frag = getSupportFragmentManager().findFragmentById(R.id.fragment_main_container);

    if(frag instanceof BookGridFragment){
        ((BookGridFragment) frag).refresh();
    }else if(frag instanceof ViewPagerFragment){
        ((ViewPagerFragment) frag).refresh();
    }
}
项目:AndroidDigIn    文件:MDMainActivity.java   
private void showFragmentByReplace(Fragment fragment, boolean addToBackStack){
    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (mCurrentFragment != null) {
        fragmentTransaction.remove(mCurrentFragment);
        mCurrentFragment = null;
    }
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.replace(R.id.content_container,fragment).commit();
    mCurrentFragment = fragment;
}
项目:HeroVideo-master    文件:MainActivity.java   
/**
     * 初始化Fragments
     */
    private void initFragments()
    {

        mHomePageFragment = HomePageFragment.newInstance();
//        IFavoritesFragment mFavoritesFragment = IFavoritesFragment.newInstance();
//        HistoryFragment mHistoryFragment = HistoryFragment.newInstance();
//        AttentionPeopleFragment mAttentionPeopleFragment = AttentionPeopleFragment.newInstance();
//        ConsumeHistoryFragment mConsumeHistoryFragment = ConsumeHistoryFragment.newInstance();
//        SettingFragment mSettingFragment = SettingFragment.newInstance();

//        fragments = new Fragment[]{
//                mHomePageFragment,
//                mFavoritesFragment,
//                mHistoryFragment,
//                mAttentionPeopleFragment,
//                mConsumeHistoryFragment,
//                mSettingFragment
//        };
        fragments = new Fragment[]{mHomePageFragment};

        // 添加显示第一个fragment
        getSupportFragmentManager()
                .beginTransaction()
                .add(R.id.container, mHomePageFragment)
                .show(mHomePageFragment).commit();
    }
项目:Android-UtilCode    文件:FragmentUtils.java   
/**
 * 显示fragment
 *
 * @param fragment fragment
 * @return show的Fragment
 */
public static Fragment showFragment(@NonNull Fragment fragment) {
    Args args = getArgs(fragment);
    if (args != null) {
        putArgs(fragment, new Args(args.id, false, args.isAddStack));
    }
    return operateFragment(fragment.getFragmentManager(), null, fragment, TYPE_SHOW_FRAGMENT);
}
项目:Responder-Android    文件:MainActivity.java   
public void refreshFragment() {
    FragmentTransaction ft = mFragmentManager.beginTransaction();
    Fragment currentFragment = mFragmentManager.findFragmentById(R.id.content_frame);
    if (currentFragment.getClass().equals(MapFragment.class)) {
        ((MapFragment) currentFragment).insertMarkersAndCenter();
    } else {
        ft.detach(currentFragment).attach(currentFragment).commit();
    }
}
项目:oma-riista-android    文件:MainActivity.java   
private void displayMorePopupMenu() {
    PopupMenu popupMenu = new PopupMenu(MainActivity.this, mBottomNavigationView.getTabWithId(R.id.menu_more));
    popupMenu.getMenuInflater().inflate(R.menu.main_navigation_more, popupMenu.getMenu());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Fragment innerFragment = null;

            switch (item.getItemId()) {
                case R.id.menu_contact:
                    innerFragment = ContactDetailsFragment.newInstance();
                    break;
                case R.id.menu_settings:
                    innerFragment = SettingsFragment.newInstance();
                    break;
                case R.id.menu_magazine:
                    Intent intent = new Intent(MainActivity.this, MagazineActivity.class);
                    if (AppPreferences.LANGUAGE_CODE_SV.equalsIgnoreCase(AppPreferences.getLanguageCodeSetting(MainActivity.this))) {
                        intent.putExtra(MagazineActivity.EXTRA_URL, AppConfig.MAGAZINE_URL_SV);
                    }
                    else {
                        intent.putExtra(MagazineActivity.EXTRA_URL, AppConfig.MAGAZINE_URL_FI);
                    }
                    startActivity(intent);
                    break;
                case R.id.menu_logout:
                    confirmLogout();
                    break;
            }

            replacePageFragment(innerFragment);
            return true;
        }
    });

    popupMenu.setGravity(Gravity.RIGHT);
    popupMenu.show();
}
项目:Aurora    文件:FragmentLifecycle.java   
@Override
public void onFragmentViewCreated(FragmentManager fm, Fragment f, View v, Bundle savedInstanceState) {
    Timber.w(f.toString() + " - onFragmentViewCreated");
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        fragmentDelegate.onCreateView(v, savedInstanceState);
    }
}
项目:AndroidUtilCode-master    文件:FragmentUtils.java   
/**
 * 设置背景色
 *
 * @param fragment fragment
 * @param color    背景色
 */
public static void setBackgroundColor(@NonNull Fragment fragment, @ColorInt int color) {
    View view = fragment.getView();
    if (view != null) {
        view.setBackgroundColor(color);
    }
}
项目:MVPArmsTest1    文件:ActivityLifecycle.java   
@Override
public void onFragmentViewDestroyed(FragmentManager fm, Fragment f) {
    super.onFragmentViewDestroyed(fm, f);
    Timber.w(f.toString() +"onFragmentViewDestroyed");
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        fragmentDelegate.onDestroyView();
    }
}
项目:MoligyMvpArms    文件:FragmentLifecycle.java   
@Override
public void onFragmentDetached(FragmentManager fm, Fragment f) {
    Timber.w(f.toString() + " - onFragmentDetached");
    FragmentDelegate fragmentDelegate = fetchFragmentDelegate(f);
    if (fragmentDelegate != null) {
        fragmentDelegate.onDetach();
        f.getArguments().clear();
    }
}
项目:AdaptiveTableLayout    文件:PermissionHelper.java   
/**
 * @return true if all permissions is granted
 */
public static boolean checkOrRequest(@NonNull Fragment fragment, int requestCode, String... permissions) {
    if (!check(fragment.getContext(), permissions)) {
        fragment.requestPermissions(permissions, requestCode);
        return false;
    } else return true;
}
项目:EasyEmoji    文件:EmojiStylesFragment.java   
@Override
public Fragment getItem(int position) {
    EmojiFragment fragment = mEmojiStyleWrapperManager.getFragment(position);
    if(mEmojiconEditText != null){
        fragment.setOnEmojiconClickedListener(EmojiStylesFragment.this);
    }
    return fragment;
}
项目:androidadvanced    文件:MainActivity.java   
private void setupAdapter() {
    Fragment[] fragments = new Fragment[]{new ImagesFragment(), new HashtagsFragment()};
    String[] titles = new String[]{getString(R.string.main_header_images), getString(R.string.main_header_hashtags)};
    MainSectionsPagerAdapter adapter =
                        new MainSectionsPagerAdapter(getSupportFragmentManager(),
                                                     titles, fragments);
    viewPager.setAdapter(adapter);
    tabs.setupWithViewPager(viewPager);
}
项目:FinalProject    文件:DiscoverActivityFragmentPagerAdapter.java   
@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0: // Fragment # 0 - This will show latest discover fragment
            return DiscoverLatestFragment.newInstance(1);
        case 1: // Fragment # 0 - This will popular discover fragment
            return DiscoverTrendingFragment.newInstance(2);
        case 2: // Fragment # 1 - This will show Featured
            return DiscoverFeaturedFragment.newInstance(0);
        default:
            return null;
    }
}
项目:WatchIt    文件:WatchLaterActivity.java   
@Override
public Fragment getItem(int position) {
    switch (position) {
        case 0:
            return MoviesWatchLaterFragment.newInstance();
        case 1:
            return TvSeriesWatchLaterFragment.newInstance();
        default:
            return null;
    }
}
项目:BuddyBook    文件:MainActivity.java   
public void checkTabLayout(){
    Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.fragment_main_container);

    if (currentFragment instanceof ViewPagerFragment) {
        mTabLayout.setVisibility(View.VISIBLE);
        mTabLayout.setupWithViewPager(((ViewPagerFragment) currentFragment).getViewPager());
        setupTabIcons(((ViewPagerFragment) currentFragment).getTypeFragment());
    }else{
        mTabLayout.setVisibility(View.GONE);
    }
}
项目:CXJPadProject    文件:BFragment.java   
public void showChildFragment(@IdRes int id_content, Fragment fragment1, Fragment fragment2) {
    FragmentTransaction ft = getChildFragmentManager().beginTransaction();
    if (!fragment1.isAdded()) {
        ft.add(id_content, fragment1);
    }
    if (!fragment2.isAdded()) {
        ft.add(id_content, fragment2);
    }

    ft.hide(fragment1).show(fragment2);
    ft.addToBackStack(null);
    ft.commit();
}
项目:Hotspot-master-devp    文件:HotspotMainActivity.java   
private void initIndicator() {
    mProjectionFragment = ProjectionFragment.newInstance();
    mSpecialFragment = SpecialFragment.newInstance();
    mTitleList.add("投屏");
    mTitleList.add("创富");
    mTitleList.add("生活");
    mTitleList.add("专题");
    mFragmentList.add(mProjectionFragment);
    mFragmentList.add(WealthLifeFragment.getInstance(101));
    mFragmentList.add(WealthLifeFragment.getInstance(102));
    mFragmentList.add(mSpecialFragment);

    Bundle bundle = new Bundle();
    bundle.putString("title", "专题");
    mPagerAdapter = new CategoryPagerAdapter(getSupportFragmentManager());
    mPagerAdapter.setData(mFragmentList,mTitleList);
    mViewPager.setAdapter(mPagerAdapter);
    mTabLayout.setViewPager(mViewPager);
    mViewPager.setOffscreenPageLimit(3);

    List<Fragment> fragmentList = new ArrayList<>();
    List<String> titleList = new ArrayList<>();
    titleList.add("创富");
    titleList.add("生活");
    titleList.add("专题");
    fragmentList.add(WealthLifeFragment.getInstance(101));
    fragmentList.add(WealthLifeFragment.getInstance(102));
    fragmentList.add(SpecialFragment.newInstance());
    mShadePagerAdapter = new CategoryPagerAdapter(getSupportFragmentManager());
    mShadePagerAdapter.setData(fragmentList,titleList);
    mShadeViewPager.setAdapter(mShadePagerAdapter);
    mShadeTabContainer.setViewPager(mShadeViewPager);
    mShadeViewPager.setOffscreenPageLimit(0);
}
项目:quickblox-android    文件:PreviewFragment.java   
public static Fragment newInstance(int imageResourceId) {
    PreviewFragment previewFragment = new PreviewFragment();
    Bundle bundle = new Bundle();
    bundle.putInt(PREVIEW_IMAGE, imageResourceId);
    previewFragment.setArguments(bundle);
    return previewFragment;

}
项目:SampleAppArch    文件:PagerActivity.java   
@Override
public Fragment getItem(int position) {
    switch (position)
    {
        case FRAGMENT_A_POS :
            return BlankFragmentA.newInstance();
        case FRAGMENT_B_POS:
            return BlankFragmentB.newInstance();
        default:
            break;
    }
    return null;
}
项目:android-advanced-light    文件:CoordinatorLayoutActivity.java   
private void initViewPager() {

        mTabLayout = (TabLayout) findViewById(R.id.tabs);
        List<String> titles = new ArrayList<>();
        titles.add("精选");
        titles.add("体育");
        titles.add("巴萨");
        titles.add("购物");
        titles.add("明星");
        titles.add("视频");
        titles.add("健康");
        titles.add("励志");
        titles.add("图文");
        titles.add("本地");
        titles.add("动漫");
        titles.add("搞笑");
        titles.add("精选");
        for (int i = 0; i < titles.size(); i++) {
            mTabLayout.addTab(mTabLayout.newTab().setText(titles.get(i)));
        }
        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < titles.size(); i++) {
            fragments.add(new ListFragment());
        }
        FragmentAdapter mFragmentAdapteradapter =
                new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        mViewPager.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        mTabLayout.setupWithViewPager(mViewPager);
        //给TabLayout设置适配器
        mTabLayout.setTabsFromPagerAdapter(mFragmentAdapteradapter);

    }
项目:API-Example-App    文件:MainActivity.java   
/**
 * Send the callback information from the {@link SaiyListener} to the relevant
 * fragment
 *
 * @param error     one of {@link Defaults.ERROR}
 * @param requestId the unique request id sent with each API request
 */
@Override
public void onError(final Defaults.ERROR error, final String requestId) {

    final int currentTag = Integer.parseInt(getSupportFragmentManager().findFragmentById(
            R.id.fragmentContent).getTag());

    Fragment fragment;

    switch (currentTag) {

        case INDEX_FRAGMENT_DEMO_BASIC:
            fragment = getSupportFragmentManager()
                    .findFragmentByTag(String.valueOf(INDEX_FRAGMENT_DEMO_BASIC));

            if (fragment != null) {
                ((FragmentDemoBasic) fragment).onError(error, requestId);
            }
            break;
        case INDEX_FRAGMENT_DEMO_INTERACTION:
            fragment = getSupportFragmentManager()
                    .findFragmentByTag(String.valueOf(INDEX_FRAGMENT_DEMO_INTERACTION));
            if (fragment != null) {
                ((FragmentDemoInteraction) fragment).onError(error, requestId);
            }
            break;
    }
}
项目:BlackList    文件:MainActivity.java   
private void switchFragment(Fragment fragment, Bundle arguments) {
    // replace the current showed fragment
    Fragment current = getSupportFragmentManager().findFragmentByTag(CURRENT_FRAGMENT);
    if (current != fragment) {
        fragment.setArguments(arguments);
        getSupportFragmentManager().beginTransaction().
                replace(R.id.frame_layout, fragment, CURRENT_FRAGMENT).commit();
    }
}
项目:Ghost-Android    文件:LoginActivity.java   
@Override
public void onGhostV0Error() {
    Fragment fragment = GhostV0ErrorFragment.newInstance();
    getSupportFragmentManager()
            .beginTransaction()
            .replace(R.id.fragment_container, fragment)
            .addToBackStack(null)
            .commit();
}
项目:exciting-app    文件:VoiceMainActivity.java   
private void setupMainFragment(Bundle savedInstanceState) {
    Fragment menuFragment;
    if (savedInstanceState != null) {
        menuFragment = getSupportFragmentManager().findFragmentByTag(FRG_VOICE_MENU);
        if (menuFragment == null) {
            menuFragment = TheHostVoiceMenuFragment.newInstance();
            getSupportFragmentManager().beginTransaction().add(R.id.fl_menu, menuFragment, FRG_VOICE_MENU).commit();
        }
        getSupportFragmentManager().beginTransaction().show(menuFragment).commit();
    } else {
        menuFragment = TheHostVoiceMenuFragment.newInstance();
        getSupportFragmentManager().beginTransaction().add(R.id.fl_menu, menuFragment, FRG_VOICE_MENU).commit();
        getSupportFragmentManager().beginTransaction().show(menuFragment).commitAllowingStateLoss();
    }
}
项目:letv    文件:LetvBaseActivity.java   
public void removeFragment(Fragment fragment) {
    if (fragment != null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.remove(fragment);
        try {
            transaction.commitAllowingStateLoss();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
项目:MVPArms_Fragment-fragment    文件:FragmentUtils.java   
/**
 * 替换fragment
 *
 * @param srcFragment   源fragment
 * @param destFragment  目标fragment
 * @param isAddStack    是否入回退栈
 * @param sharedElement 共享元素
 * @return 目标fragment
 */
public static Fragment replaceFragment(@NonNull Fragment srcFragment,
                                       @NonNull Fragment destFragment,
                                       boolean isAddStack,
                                       SharedElement... sharedElement) {
    if (srcFragment.getArguments() == null)
        return null;
    int containerId = srcFragment.getArguments().getInt(ARGS_ID);
    if (containerId == 0)
        return null;
    return replaceFragment(srcFragment.getFragmentManager(), destFragment, containerId, isAddStack, sharedElement);
}
项目:MusicX-music-player    文件:PagerAdapter.java   
@Override
public Object instantiateItem(ViewGroup container, int position) {
    Object obj = super.instantiateItem(container, position);
    if (obj instanceof Fragment) {
        Fragment f = (Fragment) obj;
        String tag = f.getTag();
        mFragmentTags.put(position, tag);
    }
    return obj;
}
项目:Hotspot-master-devp    文件:GlideImageLoader.java   
public  void loadImageWithNoAnimate(Fragment fragment, String imgPath, ImageView imageView, int placeholderResId, int failedResId) {
    Glide.with(fragment)
            .load(imgPath)
            .placeholder(placeholderResId)
            .error(failedResId)
            .dontAnimate()
            .crossFade()
            .into(imageView);
}