Android Open Source - AStory pager View






From Project

Back to project page AStory.

License

The source code is released under:

Apache License

If you think the Android project AStory 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.Litterfeldt.AStory;
//from   w ww .j a v a 2s . c  o m
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import com.Litterfeldt.AStory.fragments.LibraryFragment;
import com.Litterfeldt.AStory.fragments.PlayerFragment;
import com.Litterfeldt.AStory.services.AudioplayerService;

public class pagerView extends FragmentActivity {
    public MyFragmentPagerAdapter mAdapter = null;
    public ViewPager mPager = null;
    public AudioplayerService apService = null;
    public boolean serviceConnected = false;

    private void startup(){
        setContentView(R.layout.main);
        mAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
        mPager = (ViewPager) findViewById(R.id.viewpager);
        mPager.setAdapter(mAdapter);
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        doBindService();
        super.onCreate(savedInstanceState);
    }
    @Override
    protected void onPause() {
        doUnbindService();
        finish();
        super.onPause();
    }
    @Override
    protected void onResume(){
        if(serviceConnected){
            startup();
        }else{
            doBindService();
        }
        super.onResume();
    }
    @Override
    protected void onStart(){
        doBindService();
        super.onStart();
     }
    @Override
    protected void onStop() {
        doUnbindService();
        super.onStop();
    }

    //################# SERVICE GLUE AND CONNECTIONS #################
    public AudioplayerService getApService(){
        return apService;
    }

    private ServiceConnection serviceConnection = new ServiceConnection() {

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            if(!serviceConnected){
                apService = ((AudioplayerService.AudioplayerBinder)service).getService();
                serviceConnected = true;
                startup();
            }
        }
        @Override
        public void onServiceDisconnected(ComponentName name) {
            serviceConnected = false;
            apService = null;
        }
    };
    void doBindService(){
        if(!serviceConnected){
            Intent serviceIntent = new Intent(pagerView.this, AudioplayerService.class);
            bindService(serviceIntent,serviceConnection,Context.BIND_ABOVE_CLIENT);
        }
    }
    void doUnbindService() {
        if (serviceConnected) {
            serviceConnected = false;
            unbindService(serviceConnection);
        }
    }

    //################# PRIVATE STATIC CLASSES #################
    public static class MyFragmentPagerAdapter extends FragmentPagerAdapter {
        public static final int NUMBER_OF_PAGES = 2;

        public MyFragmentPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position){
                case 0:
                    return new PlayerFragment();
                case 1:
                    return new LibraryFragment();
                default:
                    return null;
            }
        }

        @Override
        public int getCount() {
            return NUMBER_OF_PAGES;
        }
        @SuppressWarnings("deprecation")
        @Override
        public void destroyItem(View arg0, int arg1, Object arg2){
            ((ViewPager) arg0).removeView((View) arg2);
        }
    }
}




Java Source Code List

com.Litterfeldt.AStory.adapters.LibraryAdapter.java
com.Litterfeldt.AStory.customClasses.CoreApplication.java
com.Litterfeldt.AStory.customClasses.CustomMediaPlayer.java
com.Litterfeldt.AStory.dbConnector.dbBook.java
com.Litterfeldt.AStory.dbConnector.dbConnector.java
com.Litterfeldt.AStory.dbConnector.dbSave.java
com.Litterfeldt.AStory.fragments.LibraryFragment.java
com.Litterfeldt.AStory.fragments.PlayerFragment.java
com.Litterfeldt.AStory.models.Book.java
com.Litterfeldt.AStory.models.Chapter.java
com.Litterfeldt.AStory.models.FileSystem.java
com.Litterfeldt.AStory.models.SaveState.java
com.Litterfeldt.AStory.services.AudioplayerService.java
com.Litterfeldt.AStory.pagerView.java
com.handmark.pulltorefresh.library.ILoadingLayout.java
com.handmark.pulltorefresh.library.IPullToRefresh.java
com.handmark.pulltorefresh.library.LoadingLayoutProxy.java
com.handmark.pulltorefresh.library.OverscrollHelper.java
com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase.java
com.handmark.pulltorefresh.library.PullToRefreshBase.java
com.handmark.pulltorefresh.library.PullToRefreshExpandableListView.java
com.handmark.pulltorefresh.library.PullToRefreshGridView.java
com.handmark.pulltorefresh.library.PullToRefreshHorizontalScrollView.java
com.handmark.pulltorefresh.library.PullToRefreshListView.java
com.handmark.pulltorefresh.library.PullToRefreshScrollView.java
com.handmark.pulltorefresh.library.PullToRefreshWebView.java
com.handmark.pulltorefresh.library.extras.PullToRefreshWebView2.java
com.handmark.pulltorefresh.library.extras.SoundPullEventListener.java
com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor.java
com.handmark.pulltorefresh.library.internal.FlipLoadingLayout.java
com.handmark.pulltorefresh.library.internal.IndicatorLayout.java
com.handmark.pulltorefresh.library.internal.LoadingLayout.java
com.handmark.pulltorefresh.library.internal.RotateLoadingLayout.java
com.handmark.pulltorefresh.library.internal.Utils.java
com.handmark.pulltorefresh.library.internal.ViewCompat.java