Search in sources :

Example 71 with Fragment

use of android.app.Fragment in project react-native-navigation by wix.

the class FragmentScreen method addFragment.

private void addFragment() {
    try {
        Fragment fragment = tryGetFragment();
        if (fragment != null) {
            addFragment(fragment);
            return;
        }
        android.support.v4.app.Fragment supportFragment = tryGetSupportFragment();
        if (supportFragment != null) {
            addSupportFragment(supportFragment);
            return;
        }
        throw new RuntimeException("must provide public static method " + CONTRACT_GET_FRAGMENT + " or " + CONTRACT_GET_SUPPORT_FRAGMENT);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Fragment(android.app.Fragment) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 72 with Fragment

use of android.app.Fragment in project WordPress-Android by wordpress-mobile.

the class WPMainActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    ProfilingUtils.split("WPMainActivity.onCreate");
    ((WordPress) getApplication()).component().inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);
    mViewPager = (WPViewPager) findViewById(R.id.viewpager_main);
    mViewPager.setOffscreenPageLimit(WPMainTabAdapter.NUM_TABS - 1);
    mTabAdapter = new WPMainTabAdapter(getFragmentManager());
    mViewPager.setAdapter(mTabAdapter);
    mConnectionBar = (TextView) findViewById(R.id.connection_bar);
    mConnectionBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // slide out the bar on click, then re-check connection after a brief delay
            AniUtils.animateBottomBar(mConnectionBar, false);
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (!isFinishing()) {
                        checkConnection();
                    }
                }
            }, 2000);
        }
    });
    mTabLayout = (WPMainTabLayout) findViewById(R.id.tab_layout);
    mTabLayout.createTabs();
    mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            mViewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        //  nop
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            //scroll the active fragment's contents to the top when user taps the current tab
            Fragment fragment = mTabAdapter.getFragment(tab.getPosition());
            if (fragment instanceof OnScrollToTopListener) {
                ((OnScrollToTopListener) fragment).onScrollToTop();
            }
        }
    });
    mAppBarElevation = getResources().getDimensionPixelSize(R.dimen.appbar_elevation);
    mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout));
    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            AppPrefs.setMainTabIndex(position);
            switch(position) {
                case WPMainTabAdapter.TAB_MY_SITE:
                    setTabLayoutElevation(mAppBarElevation);
                    break;
                case WPMainTabAdapter.TAB_READER:
                    setTabLayoutElevation(0);
                    break;
                case WPMainTabAdapter.TAB_ME:
                    setTabLayoutElevation(mAppBarElevation);
                    break;
                case WPMainTabAdapter.TAB_NOTIFS:
                    setTabLayoutElevation(mAppBarElevation);
                    Fragment fragment = mTabAdapter.getFragment(position);
                    if (fragment instanceof OnScrollToTopListener) {
                        ((OnScrollToTopListener) fragment).onScrollToTop();
                    }
                    break;
            }
            trackLastVisibleTab(position, true);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        // noop
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            // animate its fab to match
            if (position == WPMainTabAdapter.TAB_MY_SITE) {
                EventBus.getDefault().post(new MainViewPagerScrolled(positionOffset));
            }
        }
    });
    if (savedInstanceState == null) {
        if (FluxCUtils.isSignedInWPComOrHasWPOrgSite(mAccountStore, mSiteStore)) {
            // open note detail if activity called from a push, otherwise return to the tab
            // that was showing last time
            boolean openedFromPush = (getIntent() != null && getIntent().getBooleanExtra(ARG_OPENED_FROM_PUSH, false));
            if (openedFromPush) {
                getIntent().putExtra(ARG_OPENED_FROM_PUSH, false);
                if (getIntent().hasExtra(NotificationsPendingDraftsReceiver.POST_ID_EXTRA)) {
                    launchWithPostId(getIntent().getIntExtra(NotificationsPendingDraftsReceiver.POST_ID_EXTRA, 0), getIntent().getBooleanExtra(NotificationsPendingDraftsReceiver.IS_PAGE_EXTRA, false));
                } else {
                    launchWithNoteId();
                }
            } else {
                int position = AppPrefs.getMainTabIndex();
                if (mTabAdapter.isValidPosition(position) && position != mViewPager.getCurrentItem()) {
                    mViewPager.setCurrentItem(position);
                }
                checkMagicLinkSignIn();
            }
        } else {
            ActivityLauncher.showSignInForResult(this);
        }
    }
    startService(new Intent(this, NotificationsScreenLockWatchService.class));
    // ensure the deep linking activity is enabled. It may have been disabled elsewhere and failed to get re-enabled
    WPActivityUtils.enableComponent(this, ReaderPostPagerActivity.class);
    // monitor whether we're not the default app
    trackDefaultApp();
}
Also used : Handler(android.os.Handler) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) SiteSettingsFragment(org.wordpress.android.ui.prefs.SiteSettingsFragment) NotificationsListFragment(org.wordpress.android.ui.notifications.NotificationsListFragment) DialogFragment(android.app.DialogFragment) ReaderPostListFragment(org.wordpress.android.ui.reader.ReaderPostListFragment) Fragment(android.app.Fragment) AppSettingsFragment(org.wordpress.android.ui.prefs.AppSettingsFragment) ViewPager(android.support.v4.view.ViewPager) WPViewPager(org.wordpress.android.widgets.WPViewPager) NotificationsScreenLockWatchService(org.wordpress.android.push.NotificationsScreenLockWatchService) TabLayout(android.support.design.widget.TabLayout) MainViewPagerScrolled(org.wordpress.android.util.CoreEvents.MainViewPagerScrolled)

Example 73 with Fragment

use of android.app.Fragment in project WordPress-Android by wordpress-mobile.

the class PeopleManagementActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        onBackPressed();
        return true;
    } else if (item.getItemId() == R.id.remove_person) {
        confirmRemovePerson();
        return true;
    } else if (item.getItemId() == R.id.invite) {
        FragmentManager fragmentManager = getFragmentManager();
        Fragment peopleInviteFragment = fragmentManager.findFragmentByTag(KEY_PERSON_DETAIL_FRAGMENT);
        if (peopleInviteFragment == null) {
            peopleInviteFragment = PeopleInviteFragment.newInstance(mSite);
        }
        if (peopleInviteFragment != null && !peopleInviteFragment.isAdded()) {
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.replace(R.id.fragment_container, peopleInviteFragment, KEY_PEOPLE_INVITE_FRAGMENT);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    } else if (item.getItemId() == R.id.send_invitation) {
        FragmentManager fragmentManager = getFragmentManager();
        Fragment peopleInviteFragment = fragmentManager.findFragmentByTag(KEY_PEOPLE_INVITE_FRAGMENT);
        if (peopleInviteFragment != null) {
            ((InvitationSender) peopleInviteFragment).send();
        }
    }
    return super.onOptionsItemSelected(item);
}
Also used : FragmentManager(android.app.FragmentManager) FragmentTransaction(android.app.FragmentTransaction) Fragment(android.app.Fragment)

Example 74 with Fragment

use of android.app.Fragment in project WordPress-Android by wordpress-mobile.

the class EditPostActivity method onBackPressed.

@Override
public void onBackPressed() {
    if (isPhotoChooserShowing()) {
        hidePhotoChooser();
        return;
    }
    Fragment imageSettingsFragment = getFragmentManager().findFragmentByTag(ImageSettingsDialogFragment.IMAGE_SETTINGS_DIALOG_TAG);
    if (imageSettingsFragment != null && imageSettingsFragment.isVisible()) {
        ((ImageSettingsDialogFragment) imageSettingsFragment).dismissFragment();
        return;
    }
    if (mViewPager.getCurrentItem() > PAGE_CONTENT) {
        if (mViewPager.getCurrentItem() == PAGE_SETTINGS) {
            mPost.setFeaturedImageId(mEditPostSettingsFragment.getFeaturedImageId());
            mEditorFragment.setFeaturedImageId(mPost.getFeaturedImageId());
        }
        mViewPager.setCurrentItem(PAGE_CONTENT);
        invalidateOptionsMenu();
        return;
    }
    if (mEditorFragment != null && !mEditorFragment.onBackPressed()) {
        saveAndFinish();
    }
}
Also used : ImageSettingsDialogFragment(org.wordpress.android.editor.ImageSettingsDialogFragment) EditorFragment(org.wordpress.android.editor.EditorFragment) PhotoChooserFragment(org.wordpress.android.ui.posts.photochooser.PhotoChooserFragment) LegacyEditorFragment(org.wordpress.android.editor.LegacyEditorFragment) Fragment(android.app.Fragment) ImageSettingsDialogFragment(org.wordpress.android.editor.ImageSettingsDialogFragment) AztecEditorFragment(org.wordpress.android.editor.AztecEditorFragment)

Example 75 with Fragment

use of android.app.Fragment in project WordPress-Android by wordpress-mobile.

the class ReaderPostListActivity method showListFragmentForFeed.

private void showListFragmentForFeed(long feedId) {
    if (isFinishing()) {
        return;
    }
    Fragment fragment = ReaderPostListFragment.newInstanceForFeed(feedId);
    getFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment, getString(R.string.fragment_tag_reader_post_list)).commit();
    String title = ReaderBlogTable.getFeedName(feedId);
    if (title.isEmpty()) {
        title = getString(R.string.reader_title_blog_preview);
    }
    setTitle(title);
}
Also used : Fragment(android.app.Fragment)

Aggregations

Fragment (android.app.Fragment)209 FragmentTransaction (android.app.FragmentTransaction)82 FragmentManager (android.app.FragmentManager)51 DialogFragment (android.app.DialogFragment)44 Bundle (android.os.Bundle)22 Intent (android.content.Intent)13 View (android.view.View)13 PreferenceFragment (android.support.v14.preference.PreferenceFragment)12 TextView (android.widget.TextView)8 BizFragment (org.aisen.weibo.sina.ui.fragment.base.BizFragment)8 Uri (android.net.Uri)6 ABaseFragment (org.aisen.android.ui.fragment.ABaseFragment)6 Activity (android.app.Activity)5 PreferenceFragment (android.preference.PreferenceFragment)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ViewGroup (android.view.ViewGroup)3 FrameLayout (android.widget.FrameLayout)3 ContactVcardViewerFragment (com.xabber.android.ui.fragment.ContactVcardViewerFragment)3 Method (java.lang.reflect.Method)3