Java tutorial
/* * VITacademics * Copyright (C) 2015 Aneesh Neelam <neelam.aneesh@gmail.com> * Copyright (C) 2015 Saurabh Joshi <saurabhjoshi94@outlook.com> * Copyright (C) 2015 Gaurav Agerwala <gauravagerwala@gmail.com> * Copyright (C) 2015 Karthik Balakrishnan <karthikb351@gmail.com> * Copyright (C) 2015 Pulkit Juneja <pulkit.16296@gmail.com> * Copyright (C) 2015 Hemant Jain <hemanham@gmail.com> * Copyright (C) 2015 Darshan Mehta <darshanmehta17@gmail.com> * * This file is part of VITacademics. * * VITacademics is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VITacademics is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VITacademics. If not, see <http://www.gnu.org/licenses/>. */ package com.karthikb351.vitinfo2.fragment.schedule; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.karthikb351.vitinfo2.R; import java.util.Calendar; public class ScheduleFragment extends Fragment { private ViewPager viewpager; private SchedulePagerAdapter pageradapter; public ScheduleFragment() { } public static ScheduleFragment newInstance() { return new ScheduleFragment(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view = inflater.inflate(R.layout.fragment_schedule, container, false); viewpager = (ViewPager) view.findViewById(R.id.view_pager_timetable); pageradapter = new SchedulePagerAdapter(getActivity().getSupportFragmentManager(), getActivity()); viewpager.setAdapter(pageradapter); TabLayout tabLayout = (TabLayout) view.findViewById(R.id.sliding_tabs); tabLayout.setupWithViewPager(viewpager); String title = getActivity().getResources().getString(R.string.fragment_timetable_title); getActivity().setTitle(title); viewpager.setCurrentItem(getEquivalentDay(Calendar.getInstance().get(Calendar.DAY_OF_WEEK)), true); return view; } private int getEquivalentDay(int day) { switch (day) { case Calendar.SUNDAY: day = 6; break; case Calendar.MONDAY: case Calendar.TUESDAY: case Calendar.WEDNESDAY: case Calendar.THURSDAY: case Calendar.FRIDAY: case Calendar.SATURDAY: day -= 2; break; default: day = 0; } return day; } }