Search in sources :

Example 1 with WPViewPager

use of org.wordpress.android.widgets.WPViewPager in project WordPress-Android by wordpress-mobile.

the class ReaderSubsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reader_activity_subs);
    restoreState(savedInstanceState);
    mViewPager = (WPViewPager) findViewById(R.id.viewpager);
    mViewPager.setOffscreenPageLimit(NUM_TABS - 1);
    mViewPager.setAdapter(getPageAdapter());
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    int normalColor = ContextCompat.getColor(this, R.color.blue_light);
    int selectedColor = ContextCompat.getColor(this, R.color.white);
    tabLayout.setTabTextColors(normalColor, selectedColor);
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    tabLayout.setupWithViewPager(mViewPager);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
    }
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Shadow removed on Activities with a tab toolbar
        actionBar.setElevation(0.0f);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    mEditAdd = (EditText) findViewById(R.id.edit_add);
    mEditAdd.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                addCurrentEntry();
            }
            return false;
        }
    });
    mBtnAdd = (ImageButton) findViewById(R.id.btn_add);
    mBtnAdd.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            addCurrentEntry();
        }
    });
    if (savedInstanceState == null) {
        // return to the page the user was on the last time they viewed this activity
        restorePreviousPage();
    }
    // note this listener must be assigned after we've already called restorePreviousPage()
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // remember which page the user last viewed
            String pageTitle = (String) getPageAdapter().getPageTitle(position);
            AppPrefs.setReaderSubsPageTitle(pageTitle);
        }
    });
}
Also used : View(android.view.View) TextView(android.widget.TextView) ViewPager(android.support.v4.view.ViewPager) WPViewPager(org.wordpress.android.widgets.WPViewPager) KeyEvent(android.view.KeyEvent) TabLayout(android.support.design.widget.TabLayout) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with WPViewPager

use of org.wordpress.android.widgets.WPViewPager 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 3 with WPViewPager

use of org.wordpress.android.widgets.WPViewPager in project WordPress-Android by wordpress-mobile.

the class NotificationsDetailActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    AppLog.i(AppLog.T.NOTIFS, "Creating NotificationsDetailActivity");
    setContentView(R.layout.notifications_detail_activity);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    if (savedInstanceState == null) {
        mNoteId = getIntent().getStringExtra(NotificationsListFragment.NOTE_ID_EXTRA);
    } else {
        if (savedInstanceState.containsKey(ARG_TITLE) && getSupportActionBar() != null) {
            getSupportActionBar().setTitle(StringUtils.notNullStr(savedInstanceState.getString(ARG_TITLE)));
        }
        mNoteId = savedInstanceState.getString(NotificationsListFragment.NOTE_ID_EXTRA);
    }
    if (mNoteId == null) {
        showErrorToastAndFinish();
        return;
    }
    final Note note = NotificationsTable.getNoteById(mNoteId);
    if (note == null) {
        showErrorToastAndFinish();
        return;
    }
    // If `note.getTimestamp()` is not the most recent seen note, the server will discard the value.
    NotificationsActions.updateSeenTimestamp(note);
    Map<String, String> properties = new HashMap<>();
    properties.put("notification_type", note.getType());
    AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATIONS_OPENED_NOTIFICATION_DETAILS, properties);
    //set up the viewpager and adapter for lateral navigation
    mViewPager = (WPViewPager) findViewById(R.id.viewpager);
    mViewPager.setPageTransformer(false, new WPViewPagerTransformer(WPViewPagerTransformer.TransformType.SLIDE_OVER));
    NotesAdapter.FILTERS filter = NotesAdapter.FILTERS.FILTER_ALL;
    if (getIntent().hasExtra(NotificationsListFragment.NOTE_CURRENT_LIST_FILTER_EXTRA)) {
        filter = (NotesAdapter.FILTERS) getIntent().getSerializableExtra(NotificationsListFragment.NOTE_CURRENT_LIST_FILTER_EXTRA);
    }
    mAdapter = buildNoteListAdapterAndSetPosition(note, filter);
    //set title
    setActionBarTitleForNote(note);
    markNoteAsRead(note);
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            AnalyticsTracker.track(AnalyticsTracker.Stat.NOTIFICATION_SWIPE_PAGE_CHANGED);
            AppPrefs.setNotificationsSwipeToNavigateShown(true);
            //change the action bar title for the current note
            Note currentNote = mAdapter.getNoteAtPosition(position);
            if (currentNote != null) {
                setActionBarTitleForNote(currentNote);
                markNoteAsRead(currentNote);
            }
        }
    });
    // Hide the keyboard, unless we arrived here from the 'Reply' action in a push notification
    if (!getIntent().getBooleanExtra(NotificationsListFragment.NOTE_INSTANT_REPLY_EXTRA, false)) {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
    }
}
Also used : NotesAdapter(org.wordpress.android.ui.notifications.adapters.NotesAdapter) WPViewPagerTransformer(org.wordpress.android.widgets.WPViewPagerTransformer) HashMap(java.util.HashMap) Note(org.wordpress.android.models.Note) ViewPager(android.support.v4.view.ViewPager) WPViewPager(org.wordpress.android.widgets.WPViewPager) ActionBar(android.support.v7.app.ActionBar)

Example 4 with WPViewPager

use of org.wordpress.android.widgets.WPViewPager in project WordPress-Android by wordpress-mobile.

the class ReaderPhotoViewerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.reader_activity_photo_viewer);
    mViewPager = (WPViewPager) findViewById(R.id.viewpager);
    mTxtTitle = (TextView) findViewById(R.id.text_title);
    // title is hidden until we know we can show it
    mTxtTitle.setVisibility(View.GONE);
    if (savedInstanceState != null) {
        mInitialImageUrl = savedInstanceState.getString(ReaderConstants.ARG_IMAGE_URL);
        mIsPrivate = savedInstanceState.getBoolean(ReaderConstants.ARG_IS_PRIVATE);
        mIsGallery = savedInstanceState.getBoolean(ReaderConstants.ARG_IS_GALLERY);
        mContent = savedInstanceState.getString(ReaderConstants.ARG_CONTENT);
    } else if (getIntent() != null) {
        mInitialImageUrl = getIntent().getStringExtra(ReaderConstants.ARG_IMAGE_URL);
        mIsPrivate = getIntent().getBooleanExtra(ReaderConstants.ARG_IS_PRIVATE, false);
        mIsGallery = getIntent().getBooleanExtra(ReaderConstants.ARG_IS_GALLERY, false);
        mContent = getIntent().getStringExtra(ReaderConstants.ARG_CONTENT);
    }
    mViewPager.setPageTransformer(false, new WPViewPagerTransformer(TransformType.FLOW));
    mViewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            updateTitle(position);
        }
    });
    mViewPager.setAdapter(getAdapter());
    loadImageList();
}
Also used : WPViewPagerTransformer(org.wordpress.android.widgets.WPViewPagerTransformer) ViewPager(android.support.v4.view.ViewPager) WPViewPager(org.wordpress.android.widgets.WPViewPager)

Example 5 with WPViewPager

use of org.wordpress.android.widgets.WPViewPager in project WordPress-Android by wordpress-mobile.

the class EditPostActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    mDispatcher.register(this);
    setContentView(R.layout.new_edit_post_activity);
    if (savedInstanceState == null) {
        mSite = (SiteModel) getIntent().getSerializableExtra(WordPress.SITE);
    } else {
        mSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
    }
    // Check whether to show the visual editor
    PreferenceManager.setDefaultValues(this, R.xml.account_settings, false);
    //AppPrefs.setAztecEditorAvailable(true);
    //AppPrefs.setAztecEditorEnabled(true);
    mShowAztecEditor = AppPrefs.isAztecEditorEnabled();
    mShowNewEditor = AppPrefs.isVisualEditorEnabled();
    // Set up the action bar.
    final ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    FragmentManager fragmentManager = getFragmentManager();
    Bundle extras = getIntent().getExtras();
    String action = getIntent().getAction();
    if (savedInstanceState == null) {
        if (!getIntent().hasExtra(EXTRA_POST) || Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action) || NEW_MEDIA_POST.equals(action) || getIntent().hasExtra(EXTRA_IS_QUICKPRESS)) {
            if (getIntent().hasExtra(EXTRA_QUICKPRESS_BLOG_ID)) {
                // QuickPress might want to use a different blog than the current blog
                int localSiteId = getIntent().getIntExtra(EXTRA_QUICKPRESS_BLOG_ID, -1);
                mSite = mSiteStore.getSiteByLocalId(localSiteId);
            }
            mIsPage = extras.getBoolean(EXTRA_IS_PAGE);
            mIsNewPost = true;
            if (mSite == null) {
                showErrorAndFinish(R.string.blog_not_found);
                return;
            }
            if (!mSite.isVisible()) {
                showErrorAndFinish(R.string.error_blog_hidden);
                return;
            }
            // Create a new post
            List<Long> categories = new ArrayList<>();
            categories.add((long) SiteSettingsInterface.getDefaultCategory(WordPress.getContext()));
            String postFormat = SiteSettingsInterface.getDefaultFormat(WordPress.getContext());
            mPost = mPostStore.instantiatePostModel(mSite, mIsPage, categories, postFormat);
        } else if (extras != null) {
            // Load post passed in extras
            mPost = (PostModel) extras.getSerializable(EXTRA_POST);
            if (mPost != null) {
                mOriginalPost = mPost.clone();
                mIsPage = mPost.isPage();
            }
        } else {
            // A postId extra must be passed to this activity
            showErrorAndFinish(R.string.post_not_found);
            return;
        }
    } else {
        mDroppedMediaUris = savedInstanceState.getParcelable(STATE_KEY_DROPPED_MEDIA_URIS);
        if (savedInstanceState.containsKey(STATE_KEY_ORIGINAL_POST)) {
            try {
                mPost = (PostModel) savedInstanceState.getSerializable(STATE_KEY_CURRENT_POST);
                mOriginalPost = (PostModel) savedInstanceState.getSerializable(STATE_KEY_ORIGINAL_POST);
            } catch (ClassCastException e) {
                mPost = null;
            }
        }
        mEditorFragment = (EditorFragmentAbstract) fragmentManager.getFragment(savedInstanceState, STATE_KEY_EDITOR_FRAGMENT);
        if (mEditorFragment instanceof EditorMediaUploadListener) {
            mEditorMediaUploadListener = (EditorMediaUploadListener) mEditorFragment;
        }
    }
    if (mSite == null) {
        ToastUtils.showToast(this, R.string.blog_not_found, ToastUtils.Duration.SHORT);
        finish();
        return;
    }
    if (mHasSetPostContent = mEditorFragment != null) {
        mEditorFragment.setImageLoader(mImageLoader);
    }
    // Ensure we have a valid post
    if (mPost == null) {
        showErrorAndFinish(R.string.post_not_found);
        return;
    }
    if (mIsNewPost) {
        trackEditorCreatedPost(action, getIntent());
    }
    setTitle(StringUtils.unescapeHTML(SiteUtils.getSiteNameOrHomeURL(mSite)));
    mSectionsPagerAdapter = new SectionsPagerAdapter(fragmentManager);
    // Set up the ViewPager with the sections adapter.
    mViewPager = (WPViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.setPagingEnabled(false);
    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            invalidateOptionsMenu();
            if (position == PAGE_CONTENT) {
                setTitle(StringUtils.unescapeHTML(SiteUtils.getSiteNameOrHomeURL(mSite)));
            } else if (position == PAGE_SETTINGS) {
                setTitle(mPost.isPage() ? R.string.page_settings : R.string.post_settings);
                hidePhotoChooser();
            } else if (position == PAGE_PREVIEW) {
                setTitle(mPost.isPage() ? R.string.preview_page : R.string.preview_post);
                hidePhotoChooser();
                savePostAsync(new AfterSavePostListener() {

                    @Override
                    public void onPostSave() {
                        if (mEditPostPreviewFragment != null) {
                            runOnUiThread(new Runnable() {

                                @Override
                                public void run() {
                                    if (mEditPostPreviewFragment != null) {
                                        mEditPostPreviewFragment.loadPost();
                                    }
                                }
                            });
                        }
                    }
                });
            }
        }
    });
    ActivityId.trackLastActivity(ActivityId.POST_EDITOR);
}
Also used : EditorMediaUploadListener(org.wordpress.android.editor.EditorMediaUploadListener) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) WPViewPager(org.wordpress.android.widgets.WPViewPager) ViewPager(android.support.v4.view.ViewPager) FragmentManager(android.app.FragmentManager) PostModel(org.wordpress.android.fluxc.model.PostModel) ActionBar(android.support.v7.app.ActionBar)

Aggregations

ViewPager (android.support.v4.view.ViewPager)6 WPViewPager (org.wordpress.android.widgets.WPViewPager)6 ActionBar (android.support.v7.app.ActionBar)4 View (android.view.View)3 WPViewPagerTransformer (org.wordpress.android.widgets.WPViewPagerTransformer)3 TabLayout (android.support.design.widget.TabLayout)2 TextView (android.widget.TextView)2 DialogFragment (android.app.DialogFragment)1 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Toolbar (android.support.v7.widget.Toolbar)1 KeyEvent (android.view.KeyEvent)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 EditorMediaUploadListener (org.wordpress.android.editor.EditorMediaUploadListener)1