Java tutorial
/* * Instincts 2k17 * Copyright (C) 2017 Adithya J * * This program 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. * * This program 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 this program. If not, see <http://www.gnu.org/licenses/> */ package com.pimp.instincts.activities; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import com.pimp.instincts.R; public class HospitalityActivity extends AppCompatActivity { private SectionsPagerAdapter mSectionsPagerAdapter; private ViewPager mViewPager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hospitality); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.container); mViewPager.setAdapter(mSectionsPagerAdapter); TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs); tabLayout.setupWithViewPager(mViewPager); } public void contactClick1(View view) { startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+91 97 90 088471"))); } public void contactClick2(View view) { startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+91 96 98 406000"))); } public void contactClick3(View view) { startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+91 89 39 619640"))); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: onBackPressed(); break; } return super.onOptionsItemSelected(item); } public static class PlaceholderFragment extends Fragment { private static final String ARG_SECTION_NUMBER = "section_number"; public PlaceholderFragment() { } public static PlaceholderFragment newInstance(int sectionNumber) { PlaceholderFragment fragment = new PlaceholderFragment(); Bundle args = new Bundle(); args.putInt(ARG_SECTION_NUMBER, sectionNumber); fragment.setArguments(args); return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView; switch (getArguments().getInt(ARG_SECTION_NUMBER)) { case 0: rootView = inflater.inflate(R.layout.fragment_general_guidelines, container, false); break; case 1: rootView = inflater.inflate(R.layout.fragment_accommodation_guidelines, container, false); break; case 2: rootView = inflater.inflate(R.layout.fragment_buses, container, false); Button button = (Button) rootView.findViewById(R.id.ssn_bus_routes); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.ssn.edu.in/wp-content/uploads/2016/01/Bus_ciruclar.pdf")); startActivity(browserIntent); } }); break; default: rootView = inflater.inflate(R.layout.fragment_general_guidelines, container, false); } return rootView; } } public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return PlaceholderFragment.newInstance(position); } @Override public int getCount() { return 3; } @Override public CharSequence getPageTitle(int position) { switch (position) { case 0: return "GENERAL"; case 1: return "ACCOMMODATION"; case 2: return "BUSES"; } return null; } } }