Java tutorial
/************************************************************************** * Copyright (C) 2012 - 2013 Marcin Kunicki <masel.popowo@gmail.com> * * This file is part of PPS-UnitInfo. * * PPS-UnitInfo 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 2 of the License, or * (at your option) any later version. * * PPS-UnitInfo 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 PPS-UnitInfo; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * Ten plik jest czci PPS-UnitInfo. * * PPS-UnitInfo jest wolnym oprogramowaniem; moesz go rozprowadza dalej * i/lub modyfikowa na warunkach Powszechnej Licencji Publicznej GNU, * wydanej przez Fundacj Wolnego Oprogramowania - wedug wersji 2 tej * Licencji lub (wedug twojego wyboru) ktrej z pniejszych wersji. * * Niniejszy program rozpowszechniany jest z nadziej, i bdzie on * uyteczny - jednak BEZ JAKIEJKOLWIEK GWARANCJI, nawet domylnej * gwarancji PRZYDATNOCI HANDLOWEJ albo PRZYDATNOCI DO OKRELONYCH * ZASTOSOWA. W celu uzyskania bliszych informacji signij do * Powszechnej Licencji Publicznej GNU. * * Z pewnoci wraz z niniejszym programem otrzymae te egzemplarz * Powszechnej Licencji Publicznej GNU (GNU General Public License); * jeli nie - napisz do Free Software Foundation, Inc., 59 Temple * Place, Fifth Floor, Boston, MA 02110-1301 USA **************************************************************************/ package org.ewicom.pps.unitinfo; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager.OnPageChangeListener; import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar.Tab; import android.support.v7.app.ActionBarActivity; import com.google.analytics.tracking.android.EasyTracker; public class UnitDetails extends ActionBarActivity implements ActionBar.TabListener { private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item"; public static final int ADDRESS_TAB_POSITION = 0; public static final int LEADERS_TAB_POSITION = 1; public static final int PHONES_TAB_POSITION = 2; private long unitID; UnitDetailsPageAdapter unitDetailsPageAdapter; ViewPager viewPager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_details); final Intent intent = getIntent(); unitID = intent.getLongExtra("unit_id", -1); unitDetailsPageAdapter = new UnitDetailsPageAdapter(getSupportFragmentManager(), unitID); viewPager = (ViewPager) findViewById(R.id.pager); viewPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int position) { getSupportActionBar().setSelectedNavigationItem(position); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); viewPager.setAdapter(unitDetailsPageAdapter); final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_collections_labels).setTabListener(this)); actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_social_group).setTabListener(this)); actionBar.addTab(actionBar.newTab().setIcon(R.drawable.ic_device_access_end_call).setTabListener(this)); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) { getSupportActionBar() .setSelectedNavigationItem(savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM)); } } @Override protected void onSaveInstanceState(Bundle outState) { outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getSupportActionBar().getSelectedNavigationIndex()); } @Override public void onTabSelected(Tab tab, FragmentTransaction fragmentTransaction) { viewPager.setCurrentItem(tab.getPosition()); switch (tab.getPosition()) { case ADDRESS_TAB_POSITION: getSupportActionBar().setTitle(R.string.tab_title_address); break; case LEADERS_TAB_POSITION: getSupportActionBar().setTitle(R.string.tab_title_leaders); break; case PHONES_TAB_POSITION: getSupportActionBar().setTitle(R.string.tab_title_phones); break; default: break; } } @Override public void onTabReselected(Tab tab, FragmentTransaction fragmentTransaction) { } @Override public void onTabUnselected(Tab tab, FragmentTransaction fragmentTransaction) { } @Override protected void onResume() { super.onResume(); } @Override protected void onPause() { super.onPause(); } @Override public void onStart() { super.onStart(); EasyTracker.getInstance(this).activityStart(this); } @Override public void onStop() { super.onStop(); EasyTracker.getInstance(this).activityStop(this); } }