android.support.v4.app.Fragment Java Examples

The following examples show how to use android.support.v4.app.Fragment. 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: WallpaperBoardBrowserActivity.java    From wallpaperboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onBackPressed() {
    if (mFragmentId == Extras.ID_WALLPAPER_SEARCH) {
        Fragment fragment = mFragManager.findFragmentByTag(Extras.TAG_WALLPAPER_SEARCH);
        if (fragment != null) {
            WallpaperSearchFragment wallpaperSearchFragment = (WallpaperSearchFragment) fragment;
            if (!wallpaperSearchFragment.isSearchQueryEmpty()) {
                wallpaperSearchFragment.filterSearch("");
                return;
            }
        }

        super.onBackPressed();
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        return;
    }

    super.onBackPressed();
}
 
Example #2
Source File: RxLoaderBackendNestedFragmentCompat.java    From rxloader with Apache License 2.0 6 votes vote down vote up
private String getStateId() {
    if (stateId != null) {
        return stateId;
    }

    Fragment parentFragment = getParentFragment();
    stateId = parentFragment.getTag();
    if (stateId == null) {
        int id = parentFragment.getId();
        if (id > 0) {
            stateId = Integer.toString(id);
        }
    }

    if (stateId == null) {
        throw new IllegalStateException("Fragment dose not have a valid id");
    }

    return stateId;
}
 
Example #3
Source File: MainActivity.java    From Cashew with Apache License 2.0 6 votes vote down vote up
@Override
public void initView(Bundle savedInstanceState) {
    SwipeBackHelper.getCurrentPage(this)
            .setSwipeBackEnable(false);
    SwipeBackHelper.getCurrentPage(this).setDisallowInterceptTouchEvent(true);
    getBinding().bnve.enableAnimation(false);
    getBinding().bnve.enableShiftingMode(false);
    getBinding().bnve.enableItemShiftingMode(false);
    List<Fragment> fragments = new ArrayList<>();
    fragments.add(new DailyFragment());
    fragments.add(new ClassifyFragment());
    fragments.add(new GirlFragment());
    getBinding().viewpagerMain.setOffscreenPageLimit(fragments.size());
    NoTouchNoAnimPagerAdapter noTouchNoAnimPagerAdapter = new NoTouchNoAnimPagerAdapter(getSupportFragmentManager(), fragments);
    getBinding().viewpagerMain.setAdapter(noTouchNoAnimPagerAdapter);
    setFrag(R.id.b_i_day);
    getBinding().bnve.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            setFrag(item.getItemId());
            return true;
        }
    });
}
 
Example #4
Source File: ViewPagerTabFragmentRecyclerViewFragment.java    From Android-ObservableScrollView with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_recyclerview, container, false);

    final ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setHasFixedSize(false);
    setDummyData(recyclerView);

    Fragment parentFragment = getParentFragment();
    ViewGroup viewGroup = (ViewGroup) parentFragment.getView();
    if (viewGroup != null) {
        recyclerView.setTouchInterceptionViewGroup((ViewGroup) viewGroup.findViewById(R.id.container));
        if (parentFragment instanceof ObservableScrollViewCallbacks) {
            recyclerView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentFragment);
        }
    }
    return view;
}
 
Example #5
Source File: MainActivity.java    From find-client-android with MIT License 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    Fragment fragment;
    if (id == R.id.nav_settings) {
        fragment = new SettingsFragment();
    } else if (id == R.id.nav_track) {
        fragment = new TrackFragment();
    } else {
        // Anything else is home
        fragment = new LearnFragment();
    }

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

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #6
Source File: VideoLoadAsync.java    From MediaChooser with Apache License 2.0 6 votes vote down vote up
public VideoLoadAsync(Fragment fragment, ImageView imageView, boolean isScrolling, int width) {
	mImageView    = imageView;
	this.fragment = fragment;
	mWidth        = width;
	mIsScrolling  = isScrolling;

	final int memClass = ((ActivityManager) fragment.getActivity().getSystemService(Context.ACTIVITY_SERVICE))
			.getMemoryClass();
	final int size = 1024 * 1024 * memClass / 8;

	// Handle orientation change.
	GalleryRetainCache c = GalleryRetainCache.getOrCreateRetainableCache();
	mCache = c.mRetainedCache;

	if (mCache == null) {
		// The maximum bitmap pixels allowed in respective direction.
		// If exceeding, the cache will automatically scale the
		// bitmaps.
		/*	final int MAX_PIXELS_WIDTH  = 100;
		final int MAX_PIXELS_HEIGHT = 100;*/
		mCache = new GalleryCache(size, mWidth, mWidth);
		c.mRetainedCache = mCache;
	}
}
 
Example #7
Source File: NewsFragment.java    From xmpp with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化数据
 */
private void initialData() {
    {

        childFragments = new ArrayList<Fragment>();


        for (int i = 0; i < list.size(); i++) {
            childFragments.add(titleFragment.newInstance(list.get(i)));
        }

        mPageAdapter = new MainFragmentPagerAdapter(getChildFragmentManager(), list, childFragments);
        mViewpager.setAdapter(mPageAdapter);
        lauout.setupWithViewPager(mViewpager);
        lauout.setTabMode(TabLayout.MODE_FIXED);
        DialogView.dismiss();


    }
}
 
Example #8
Source File: OnlyIconsActivity.java    From AdvancedMaterialDrawer with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Bundle savedInstanceState) {

    drawer = this;

    // information text for the fragment
    Bundle bundle = new Bundle();
    bundle.putString("instruction", "The Menu has Only Icons");

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

    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.app_drawer_icon) , true, new FragmentDummy(), "Fragment Section Icon Banner"));
    menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_extension_black_36dp) , true, new FragmentDummy(), "Extension"));
    menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_list_black_36dp) , true, new FragmentDummy(), "List"));
    menu.add(new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_favorite_black_36dp) , true, new FragmentDummy(), "Favorite").setSectionColor(Color.parseColor("#ff0858")));


    // load menu
    this.loadMenu(menu);

    // load the MaterialItemSectionFragment, from the given startIndex
    this.loadStartFragmentFromMenu(menu);
}
 
Example #9
Source File: EZ.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Return the callbacks for a fragment or throw an exception.
 * <p/>
 * Inspired by: https://gist.github.com/keyboardr/5455206
 */
@SuppressWarnings("unchecked")
public static <T> T getCallbacksOrThrow(Fragment frag, Class<T> callbacks) {
    Fragment parent = frag.getParentFragment();

    if (parent != null && callbacks.isInstance(parent)) {
        return (T) parent;

    } else {
        FragmentActivity activity = frag.getActivity();
        if (activity != null && callbacks.isInstance(activity)) {
            return (T) activity;
        }
    }

    // We haven't actually failed a class cast thanks to the checks above, but that's the
    // idiomatic approach for this pattern with fragments.
    throw new ClassCastException("This fragment's activity or parent fragment must implement "
            + callbacks.getCanonicalName());
}
 
Example #10
Source File: MainActivity.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
@Override
public Fragment getItem(int position) {
	if (position == 0) {
		if (tabProfiles == null) tabProfiles = new ProfilesFragment();
		return tabProfiles;
	} else if (position == 1) {
		if (tabLogs == null) tabLogs = new LogsFragment();
		return tabLogs;
	} else if (position == 2) {
		if (tabSettings == null) tabSettings = new SettingsFragment();
		return tabSettings;				
	}
	return null;
}
 
Example #11
Source File: EasyPermissions.java    From AndroidBasicProject with MIT License 5 votes vote down vote up
@TargetApi(11)
private static Activity getActivity(Object object) {
    if (object instanceof Activity) {
        return ((Activity) object);
    } else if (object instanceof Fragment) {
        return ((Fragment) object).getActivity();
    } else if (object instanceof android.app.Fragment) {
        return ((android.app.Fragment) object).getActivity();
    } else {
        return null;
    }
}
 
Example #12
Source File: AppDetailsPagerAdapter.java    From Kernel-Tuner with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Fragment getItem(int position)
{
    switch (position)
    {
        case 0:
            return AppDetailsFragment.newInstance();
    }
    return null;
}
 
Example #13
Source File: ToolPagerAdapter.java    From auid2 with Apache License 2.0 5 votes vote down vote up
@Override
public Fragment getItem(int position) {
    if (position == 0) {
        return ToolAboutFragment.newInstance(mToolType);
    }
    return ToolListFragment.newInstance(mToolTabs.get(position));
}
 
Example #14
Source File: SafetyWarningFragment.java    From carstream-android-auto with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);
    Fragment parentFragment = getParentFragment();
    if (parentFragment instanceof FragmentInteractionListener) {
        listener = (FragmentInteractionListener) parentFragment;
    }
}
 
Example #15
Source File: BusFragment.java    From FakeWeather with Apache License 2.0 5 votes vote down vote up
private void setupViewPager(ViewPager viewPager) {
    ViewPagerAdapter adapter = new ViewPagerAdapter(getChildFragmentManager());
    Fragment fragment = new NearbyLineFragment();
    adapter.addFrag(fragment, getString(R.string.bus_nearby_line));

    fragment = new NearbyStationFragment();
    adapter.addFrag(fragment, getString(R.string.bus_nearby_station));

    fragment = new FavoritesFragment();
    adapter.addFrag(fragment, getString(R.string.bus_favorites));

    viewPager.setAdapter(adapter);

}
 
Example #16
Source File: LifecycleDispatcher.java    From AndroidLifecyle with Apache License 2.0 5 votes vote down vote up
public void onFragmentCreateView(Fragment fragment,
                                 LayoutInflater inflater,
                                 ViewGroup container,
                                 Bundle savedInstanceState) {
    Object[] callbacks = collectFragmentLifecycleCallbacks();
    if (callbacks != null) {
        for (int i = 0; i < callbacks.length; i++) {
            ((FragmentLifecycleCallbacks) callbacks[i]).onFragmentCreateView(fragment, inflater, container, savedInstanceState);
        }
    }
}
 
Example #17
Source File: DialogsFragment.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
protected boolean onItemLongClick(Dialog dialog) {
    Fragment parent = getParentFragment();
    if (parent != null && parent instanceof DialogsFragmentDelegate) {
        return ((DialogsFragmentDelegate) parent).onPeerLongClicked(dialog.getPeer());
    }
    return false;
}
 
Example #18
Source File: MainActivity.java    From android-sensor-example with Apache License 2.0 5 votes vote down vote up
/**
 * public method that allows switching the content fragment. This way fragments can
 * request switching to another fragments (= perform navigation)
 *
 * @param fragment
 */
public void switchFragment(Fragment fragment) {
    // update the main content by replacing fragments
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.container, fragment)
            .addToBackStack(fragment.getClass().getSimpleName())
            .commit();
    mContentFragment = fragment;
}
 
Example #19
Source File: CollectionFragment.java    From wallpaperboard with Apache License 2.0 5 votes vote down vote up
public void refreshWallpapers() {
    if (mAdapter == null) return;

    int index = 1;
    if (index > mAdapter.getCount()) return;
    Fragment fragment = mAdapter.getItem(index);
    if (fragment != null && fragment instanceof WallpapersFragment) {
        ((WallpapersFragment) fragment).getWallpapers();
    }
}
 
Example #20
Source File: FileListPagerFragment.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
public static Fragment newFragment(JecFile path) {
    FileListPagerFragment f = new FileListPagerFragment();
    Bundle b = new Bundle();
    b.putParcelable("path", path);
    f.setArguments(b);
    return f;
}
 
Example #21
Source File: NovelFragment.java    From fingerpoetry-android with Apache License 2.0 5 votes vote down vote up
@Override
public Fragment getItem(int position) {
    if(position == 0){
        return new UpdateFragment<Chapter>();
    } else {
        return new SubscribFragment<User2Novel>();
    }
}
 
Example #22
Source File: MainActivity.java    From AndroidHttpCapture with MIT License 5 votes vote down vote up
/**
     * 修改显示的内容 不会重新加载
     **/
    public void switchContent(Fragment to) {
        Boolean isAdded = false;
        try {
            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            if (getSupportFragmentManager().getFragments() != null) {
                for (Fragment f : getSupportFragmentManager().getFragments()) {
                    if (to.getClass().isAssignableFrom(f.getClass())) {
                        if (!f.isAdded()) {
                            transaction.add(R.id.fl_contain, f, f.getClass().getName());
                        } else {
                            transaction.show(f);
                        }
                        isAdded = true;
                    } else {
                        transaction.hide(f);
                        f.setUserVisibleHint(false);
                    }
                }
            }
            if (!isAdded) {
                if (!to.isAdded()) { // 先判断是否被add过
                    transaction.add(R.id.fl_contain, to, to.getClass().getName()).commitNow();
                } else {
                    transaction.show(to).commitNow(); // 隐藏当前的fragment,显示下一个
                }
            } else {
                transaction.commitNow();
            }
            if (getSupportFragmentManager().findFragmentByTag(to.getClass().getName()) != null) {
                getSupportFragmentManager().findFragmentByTag(to.getClass().getName()).setUserVisibleHint(true);
            }
//            setSelectedFragment((BaseFragment) to);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
Example #23
Source File: ArticleActivity.java    From Yuan-WanAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 给其他需要传入数据的碎片使用
 *
 * @param activity
 * @param fragment
 * @param url
 * @param title
 */
public static void startActivityForResultByFragment(Activity activity,
                                                    Fragment fragment,
                                                    String url,
                                                    String title,
                                                    int id,
                                                    boolean isCollect,
                                                    int request) {
    Intent intent = new Intent(activity, ArticleActivity.class);
    intent.putExtra(Constant.KEY_ARTICLE_URL, url);
    intent.putExtra(Constant.KEY_ARTICLE_TITLE, title);
    intent.putExtra(Constant.KEY_ARTICLE_ID, id);
    intent.putExtra(Constant.KEY_ARTICLE_COLLECT, isCollect);
    fragment.startActivityForResult(intent,request);
}
 
Example #24
Source File: AuthAgent.java    From letv with Apache License 2.0 5 votes vote down vote up
public int doLogin(Activity activity, String str, IUiListener iUiListener, boolean z, Fragment fragment) {
    this.b = str;
    this.c = activity;
    this.a = iUiListener;
    if (a(activity, fragment, z)) {
        f.c(f.d, "OpenUi, showUi, return Constants.UI_ACTIVITY");
        d.a().a(this.mToken.getOpenId(), this.mToken.getAppId(), "2", "1", "5", "0", "0", "0");
        return 1;
    }
    d.a().a(this.mToken.getOpenId(), this.mToken.getAppId(), "2", "1", "5", "1", "0", "0");
    f.d(f.d, "startActivity fail show dialog.");
    this.a = new FeedConfirmListener(this, this.a);
    return a(z, this.a);
}
 
Example #25
Source File: Flow.java    From Flow with Apache License 2.0 5 votes vote down vote up
private void fromFragment() {
    Fragment fragment = ((Fragment) src);
    if (forResult) {
        fragment.startActivityForResult(intent(fragment.getActivity()), requestCode);
    } else {
        fragment.startActivity(intent(fragment.getActivity()));
    }
}
 
Example #26
Source File: HomeActivity.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
public HomeActivity()
{
    importFileName = null;
    if (VisibilityFilter.hideDappBrowser()) dappBrowserFragment = new Fragment();
    else dappBrowserFragment = new DappBrowserFragment();
    transactionsFragment = new TransactionsFragment();
    settingsFragment = new NewSettingsFragment();
    walletFragment = new WalletFragment();
    lifeCycle = new LifecycleObserver()
    {
        @OnLifecycleEvent(Lifecycle.Event.ON_START)
        private void onMoveToForeground()
        {
            Log.d("LIFE", "AlphaWallet into foreground");
            ((WalletFragment)walletFragment).walletInFocus();
        }

        @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
        private void onMoveToBackground()
        {
            Log.d("LIFE", "AlphaWallet into background");
            ((WalletFragment)walletFragment).walletOutOfFocus();
        }

        @Override
        public int hashCode()
        {
            return super.hashCode();
        }
    };

    ProcessLifecycleOwner.get().getLifecycle().addObserver(lifeCycle);
}
 
Example #27
Source File: BaseActivity.java    From Android-Pull-To-Refresh with Apache License 2.0 5 votes vote down vote up
public void replaceFragment(Fragment fragment, boolean addToBackStack) {
    FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
    fragmentTransaction.setCustomAnimations(R.anim.right_in, R.anim.left_out, R.anim.left_in, R.anim.right_out);
    fragmentTransaction.replace(R.id.fl_container, fragment);
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(null);
    }
    fragmentTransaction.commitAllowingStateLoss();
}
 
Example #28
Source File: FragmentUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * 隐藏同级别fragment
 *
 * @param fragmentManager fragment管理器
 */
public static void hideFragments(@NonNull FragmentManager fragmentManager) {
    List<Fragment> fragments = getFragments(fragmentManager);
    if (fragments.isEmpty()) return;
    for (int i = fragments.size() - 1; i >= 0; --i) {
        Fragment fragment = fragments.get(i);
        if (fragment != null) hideFragment(fragment);
    }
}
 
Example #29
Source File: MainTimeLineActivity.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
private void initFragments() {
    Fragment timeLineFragment = getMainTimeLineFragment();
    Fragment favFragment = getFavFragment();

    Fragment hotWeiboFragment = getHotWeiboViewPagerFragment();

    Fragment hotHuatiFragment = getHotHuaTiViewPagerFragment();

    FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
    if (!timeLineFragment.isAdded()) {
        fragmentTransaction.add(R.id.center_frame_layout, timeLineFragment, MainTimeLineFragment.class.getName());
        fragmentTransaction.hide(timeLineFragment);
    }

    if (!favFragment.isAdded()) {
        fragmentTransaction.add(R.id.center_frame_layout, favFragment, MyFavListFragment.class.getName());
        fragmentTransaction.hide(favFragment);
    }

    if (!hotWeiboFragment.isAdded()) {
        fragmentTransaction.add(R.id.center_frame_layout, hotWeiboFragment, HotWeiboViewPagerFragment.class.getName());
        fragmentTransaction.hide(hotWeiboFragment);
    }

    if (!hotHuatiFragment.isAdded()) {
        fragmentTransaction.add(R.id.center_frame_layout, hotHuatiFragment, HotHuaTiViewPagerFragment.class.getName());
        fragmentTransaction.hide(hotHuatiFragment);
    }

    if (!fragmentTransaction.isEmpty()) {
        fragmentTransaction.commit();
        getSupportFragmentManager().executePendingTransactions();
    }
}
 
Example #30
Source File: RMBTMainActivity.java    From open-rmbt with Apache License 2.0 5 votes vote down vote up
public void showMapFromPager() {
	try {
		Fragment f = getCurrentFragment();
		if (f != null) {
			((RMBTResultPagerFragment) f).getPagerAdapter().showMap();
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
}