Android Open Source - Multi-Mania-app Schedules Fragment






From Project

Back to project page Multi-Mania-app.

License

The source code is released under:

MIT License

If you think the Android project Multi-Mania-app 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 be.ana.nmct.multimania.ui;
/*from   w  w w  .j  av  a 2  s.  c  o m*/

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.LoaderManager;
import android.content.CursorLoader;
import android.content.Loader;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import java.util.ArrayList;
import java.util.List;

import be.ana.nmct.multimania.R;
import be.ana.nmct.multimania.data.MultimaniaContract;

/**
 * SchedulesFragment shows all schedules with a viewpager
 */
public class SchedulesFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>/*, ActionBar.OnNavigationListener*/ {
    public static final String TAG = SchedulesFragment.class.getSimpleName();

    public List<String> mDates = new ArrayList<String>();//[]{"2014-05-19","2014-05-20"};
    private SchedulesPagerAdapter mViewPagerAdapter;
    //private List<String> mTags;
    private ArrayAdapter<String> mListAdapter;

    public SchedulesFragment() {}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getLoaderManager().initLoader(MainActivity.LOADER_SCHEDULE_DATES_ID, null, this);
        //getLoaderManager().initLoader(MainActivity.LOADER_TAGS_ID,null,this);
        setRetainInstance(true);
        //mTags = new ArrayList<String>();
        //mListAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_dropdown_item,mTags);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_schedules, container, false);
        ViewPager pager = (ViewPager) v.findViewById(R.id.schedulesPager);
        mViewPagerAdapter = new SchedulesPagerAdapter(getFragmentManager());
        pager.setAdapter(mViewPagerAdapter);
        return v;
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        /*ActionBar bar = getActivity().getActionBar();
        if(bar!=null){
            bar.setListNavigationCallbacks(mListAdapter,this);
            bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        }*/
    }

    @Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {
        switch(id){
            case MainActivity.LOADER_SCHEDULE_DATES_ID:
                return new CursorLoader(getActivity(),MultimaniaContract.TalkEntry.DATE_CONTENT_URI,null,null,null,null);

            /*case MainActivity.LOADER_TAGS_ID:
                return new CursorLoader(getActivity(),MultimaniaContract.TagEntry.CONTENT_URI,null,null,null,null);*/
        }
        return null;
    }

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
        switch(loader.getId()){
            case MainActivity.LOADER_SCHEDULE_DATES_ID:
                addDates(cursor);
                break;
            /*case MainActivity.LOADER_TAGS_ID: {
                addTags(cursor);
                break;
            }*/
        }
        loader.abandon();
    }

    /*private void addTags(Cursor cursor) {
        if(cursor.moveToFirst()){
            final int nameIndex = cursor.getColumnIndex(MultimaniaContract.TagEntry.NAME);
            do{
                mTags.add(cursor.getString(nameIndex));
            }while(cursor.moveToNext());
            mListAdapter.notifyDataSetChanged();
        }
    }*/

    private void addDates(Cursor cursor) {
        int dayIndex = cursor.getColumnIndex(MultimaniaContract.TalkEntry.DAY);
        mDates.clear();
        while(cursor.moveToNext()){
            String date = cursor.getString(dayIndex);
            mDates.add(date);
        }
        mViewPagerAdapter.notifyDataSetChanged();
    }

    @Override
    public void onLoaderReset(Loader<Cursor> loader) {
        mDates.clear();
        mViewPagerAdapter.notifyDataSetChanged();
    }

    /*@Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        for(int i = 0; i < mDates.size();i++){
            ScheduleFragment frag = (ScheduleFragment)  mViewPagerAdapter.getItem(i);
            frag.onFilterChanged(mTags.get(itemPosition));
        }
        return true;
    )*/

    private class SchedulesPagerAdapter extends FragmentStatePagerAdapter {

        private final String mDayString;

        public SchedulesPagerAdapter(FragmentManager fm) {
            super(fm);
            mDayString = getString(R.string.day);
        }

        @Override
        public Fragment getItem(int i) {
            return ScheduleFragment.newInstance(mDates.get(i),i);
        }

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

        @Override
        public CharSequence getPageTitle(int position) {
            return mDayString+ " "+(position+1);
        }
    }
}




Java Source Code List

be.ana.nmct.multimania.ApiTest.java
be.ana.nmct.multimania.ApplicationTest.java
be.ana.nmct.multimania.CalendarTest.java
be.ana.nmct.multimania.DbTest.java
be.ana.nmct.multimania.Import.java
be.ana.nmct.multimania.NotificationImport.java
be.ana.nmct.multimania.ProviderTest.java
be.ana.nmct.multimania.SyncTest.java
be.ana.nmct.multimania.data.ApiActions.java
be.ana.nmct.multimania.data.DbHelper.java
be.ana.nmct.multimania.data.GsonLoader.java
be.ana.nmct.multimania.data.MultimaniaContract.java
be.ana.nmct.multimania.data.MultimaniaProvider.java
be.ana.nmct.multimania.data.NewsItemLoader.java
be.ana.nmct.multimania.data.RoomLoader.java
be.ana.nmct.multimania.data.TagLoader.java
be.ana.nmct.multimania.data.TalkLoader.java
be.ana.nmct.multimania.model.IData.java
be.ana.nmct.multimania.model.NewsItem.java
be.ana.nmct.multimania.model.Room.java
be.ana.nmct.multimania.model.Speaker.java
be.ana.nmct.multimania.model.Tag.java
be.ana.nmct.multimania.model.TalkSpeaker.java
be.ana.nmct.multimania.model.TalkTag.java
be.ana.nmct.multimania.model.Talk.java
be.ana.nmct.multimania.model.User.java
be.ana.nmct.multimania.service.AuthenticatorService.java
be.ana.nmct.multimania.service.Authenticator.java
be.ana.nmct.multimania.service.BootListener.java
be.ana.nmct.multimania.service.NotificationReceiver.java
be.ana.nmct.multimania.service.NotificationSender.java
be.ana.nmct.multimania.service.SyncAdapter.java
be.ana.nmct.multimania.service.SyncService.java
be.ana.nmct.multimania.ui.AboutFragment.java
be.ana.nmct.multimania.ui.LoadActivity.java
be.ana.nmct.multimania.ui.MainActivity.java
be.ana.nmct.multimania.ui.MapFragment.java
be.ana.nmct.multimania.ui.MyScheduleFragment.java
be.ana.nmct.multimania.ui.MySchedulesFragment.java
be.ana.nmct.multimania.ui.NavigationDrawerFragment.java
be.ana.nmct.multimania.ui.NewsFragment.java
be.ana.nmct.multimania.ui.NewsItemActivity.java
be.ana.nmct.multimania.ui.NewsItemFragment.java
be.ana.nmct.multimania.ui.ScheduleFragment.java
be.ana.nmct.multimania.ui.SchedulesFragment.java
be.ana.nmct.multimania.ui.SettingsFragment.java
be.ana.nmct.multimania.ui.SuggestionFragment.java
be.ana.nmct.multimania.ui.TalkActivity.java
be.ana.nmct.multimania.ui.TalkFragment.java
be.ana.nmct.multimania.utils.GoogleCalUtil.java
be.ana.nmct.multimania.utils.SettingsHelper.java
be.ana.nmct.multimania.utils.SettingsUtil.java
be.ana.nmct.multimania.utils.SyncUtils.java
be.ana.nmct.multimania.utils.Utility.java
be.ana.nmct.multimania.vm.NavigationItem.java
be.ana.nmct.multimania.vm.ScheduleTalkVm.java
be.ana.nmct.multimania.widget.StaggeredGridView.java
com.bulletnoid.android.widget.StaggeredGridView.BulletStaggeredGridView.java
com.bulletnoid.android.widget.StaggeredGridView.HeaderFooterListAdapter.java
com.bulletnoid.android.widget.StaggeredGridView.ScrollerCompatIcs.java
com.bulletnoid.android.widget.StaggeredGridView.ScrollerCompat.java