Java tutorial
/******************************************************************************* * Copyright (c) 2014 The Hackerati, Inc. * This project is distributed under the terms of the MIT license. See the file LICENSE or http://opensource.org/licenses/MIT. ******************************************************************************/ package com.hackerati.android.starter_app; import roboguice.activity.RoboActionBarActivity; import roboguice.inject.InjectView; import android.os.Bundle; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.view.Menu; import android.view.MenuItem; import com.google.inject.Inject; import com.hackerati.android.starter_app.settings.SettingsActivity; import com.hackerati.android.starter_app.sign_in.SignInActivity; import com.hackerati.android.user_sdk.sign_in.SignInManager; //RoboGuice library is a snapshot because latest releases don't have RoboActionBarActivity public class ViewPagerActivity extends RoboActionBarActivity { @InjectView(R.id.view_pager) private ViewPager viewPager; @Inject private SignInManager signInManager; @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_pager_activity); final PagerAdapter pagerAdapter = new HPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(pagerAdapter); } @Override public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onPrepareOptionsMenu(final Menu menu) { // Do not show the "sign in" menu item if we're already signed in final boolean signInGroupVisible = !signInManager.isSignedIn(); menu.setGroupVisible(R.id.sign_in_group, signInGroupVisible); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(final MenuItem item) { final int id = item.getItemId(); switch (id) { case R.id.sign_in: SignInActivity.launch(this); return true; case R.id.settings: SettingsActivity.launch(this); return true; } return super.onOptionsItemSelected(item); } }