Android Open Source - notes Note Pager Activity






From Project

Back to project page notes.

License

The source code is released under:

Apache License

If you think the Android project notes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.donnemartin.android.notes.notes;
// www . j a va2  s .co m
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;

import java.util.ArrayList;
import java.util.UUID;

public class NotePagerActivity extends FragmentActivity
{
    private ViewPager mViewPager;
    private ArrayList<Note> mNotes;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // FragmentManager requires that any view used as a fragment container
        // must have an Id.  ViewPager is a fragment container.
        // Since this is just a simple single view,
        // Create it in code rather than XML
        mViewPager = new ViewPager(this);
        mViewPager.setId(R.id.viewPager);
        setContentView(mViewPager);

        mNotes = Notebook.getInstance(this).getNotes();

        FragmentManager fm = getSupportFragmentManager();

        // FragmentStatePagerAdapter is the agent managing the conversation
        // with ViewPager.  It adds the fragments returned to the activity
        // and helps ViewPager id the fragments' views for placement.
        mViewPager.setAdapter(new FragmentStatePagerAdapter(fm) {
            @Override
            public Fragment getItem(int position) {
                Note note = mNotes.get(position);
                return NoteFragment.newInstance((note.getId()));
            }

            @Override
            public int getCount() {
                return mNotes.size();
            }
        });

        // By default, ViewPager shows the first item in its PagerAdapter.
        // We have to loop through to find a matching index to show
        // the selected item
        UUID noteId = (UUID)getIntent()
            .getSerializableExtra(NoteFragment.EXTRA_NOTE_ID);

        int numNotes = mNotes.size();
        Note note;

        for (int i = 0; i < numNotes; ++i) {
            note = mNotes.get(i);

            if (note.getId().equals(noteId)) {
                mViewPager.setCurrentItem(i);
                setTitle(note.getTitle());
                break;
            }
        }

        // Replace the activity's title that appears on the action bar
        // with the title of the current Note
        // OnPageChangeListener is how you listen for changes in the page
        // currently being displayed by ViewPager
        mViewPager.setOnPageChangeListener
            (new ViewPager.OnPageChangeListener() {
            public void onPageScrollStateChanged(int state) {
                // This space intentionally left blank
            }

            public void onPageScrolled(int pos,
                                       float posOffset,
                                       int posOffsetPixels) {
                // This space intentionally left blank
            }

            public void onPageSelected(int pos) {
                Note note = mNotes.get(pos);

                if (note.getTitle() != null) {
                    setTitle(note.getTitle());
                }
            }
        });
    }
}




Java Source Code List

com.donnemartin.android.notes.notes.AudioPlayer.java
com.donnemartin.android.notes.notes.AudioRecorder.java
com.donnemartin.android.notes.notes.DatePickerFragment.java
com.donnemartin.android.notes.notes.ImageFragment.java
com.donnemartin.android.notes.notes.NoteCameraActivity.java
com.donnemartin.android.notes.notes.NoteCameraFragment.java
com.donnemartin.android.notes.notes.NoteFragment.java
com.donnemartin.android.notes.notes.NoteIntentJSONSerializer.java
com.donnemartin.android.notes.notes.NoteListActivity.java
com.donnemartin.android.notes.notes.NoteListFragment.java
com.donnemartin.android.notes.notes.NotePagerActivity.java
com.donnemartin.android.notes.notes.Note.java
com.donnemartin.android.notes.notes.Notebook.java
com.donnemartin.android.notes.notes.Photo.java
com.donnemartin.android.notes.notes.PictureUtils.java
com.donnemartin.android.notes.notes.SingleFragmentActivity.java