Back to project page Wardrobe_app.
The source code is released under:
Apache License
If you think the Android project Wardrobe_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.
package com.android.busolo.apps.wardrobe.engine; /* w w w .j av a2 s . c o m*/ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.MenuItemCompat; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.android.busolo.apps.wardrobe.utils.AccountUtils; import java.util.Locale; public class HomeActivity extends BaseActivity implements ActionBar.TabListener, ViewPager.OnPageChangeListener { public static final String EXTRA_DEFAULT_TAB = "com.android.busolo.apps.wardrobe.extra.DEFAULT_TAB"; public static final String TAB_EXPLORE = "explore"; SectionsPagerAdapter mSectionsPagerAdapter; ViewPager mViewPager; private PublicStreamFragment mPublicStreamFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (isFinishing()) { return; } setContentView(R.layout.activity_home); // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter( getSupportFragmentManager()); FragmentManager fm = getSupportFragmentManager(); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); String homeScreenLabel; if (mViewPager != null) { // Phone setup mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(this); mViewPager.setPageMarginDrawable(R.drawable.grey_border_inset_lr); mViewPager.setPageMargin(getResources() .getDimensionPixelSize(R.dimen.page_margin_width)); final ActionBar actionBar = getSupportActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); actionBar.addTab(actionBar.newTab() // .setText(R.string.title_public_feeds) .setIcon(R.drawable.ic_tab_public) .setTabListener(this)); actionBar.addTab(actionBar.newTab() // .setText(R.string.title_private_feeds) .setIcon(R.drawable.ic_tab_private) .setTabListener(this)); actionBar.addTab(actionBar.newTab() // .setText(R.string.title_match_photos) .setIcon(R.drawable.ic_tab_match) .setTabListener(this)); actionBar.addTab(actionBar.newTab() // .setText(R.string.title_user_profile) .setIcon(R.drawable.ic_tab_profile) .setTabListener(this)); setHasTabs();// From Base activity if (getIntent() != null && TAB_EXPLORE.equals(getIntent().getStringExtra(EXTRA_DEFAULT_TAB)) && savedInstanceState == null) { mViewPager.setCurrentItem(1); } homeScreenLabel = getString(R.string.title_public_feeds); } else { mPublicStreamFragment = (PublicStreamFragment) fm.findFragmentById(R.id.fragment_public_stream); homeScreenLabel = "Home"; } getSupportActionBar().setHomeButtonEnabled(false); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.home, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. switch (item.getItemId()){ case R.id.menu_sign_out: AccountUtils.signOut(this); startActivity(new Intent(this, BaseActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)); finish(); break; case R.id.menu_refresh: LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.menu_refreshing, null); // item.setActionView(view); MenuItemCompat.setActionView(item, view); break; case R.id.menu_add_item: startActivity(new Intent(HomeActivity.this, NewPostActivity.class)); break; } return super.onOptionsItemSelected(item); } @Override protected void onPause() { super.onPause(); } @Override protected void onResume() { super.onResume(); // Refresh options menu. Menu item visibility could be altered by user preferences. supportInvalidateOptionsMenu(); } @Override protected void onDestroy() { super.onDestroy(); } @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } @Override public void onPageScrolled(int i, float v, int i1) { // TODO Auto-generated method stub } @Override public void onPageSelected(int position) { getSupportActionBar().setSelectedNavigationItem(position); int titleId = -1; switch (position) { case 0: titleId = R.string.title_public_feeds; break; case 1: titleId = R.string.title_private_feeds; break; case 2: titleId = R.string.title_match_photos; break; case 3: titleId = R.string.title_user_profile; break; } String title = getString(titleId); } @Override public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // TODO Auto-generated method stub } @Override public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { mViewPager.setCurrentItem(tab.getPosition()); switch(tab.getPosition()){ case 0: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_public_selected)); break; case 1: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_private_selected)); break; case 2: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_match_selected)); break; case 3: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_profile_selected)); break; default: break; } } @Override public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { // TODO Auto-generated method stub switch(tab.getPosition()){ case 0: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_public)); break; case 1: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_private)); break; case 2: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_match)); break; case 3: tab.setIcon(getResources().getDrawable(R.drawable.ic_tab_profile)); break; default: break; } } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // The outcome of all this is that the "Refresh" menu button refreshes the stream across // orientation changes. if (mPublicStreamFragment != null) { getSupportFragmentManager().putFragment(outState, "public_stream_fragment", mPublicStreamFragment); } } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (mPublicStreamFragment == null) { mPublicStreamFragment = (PublicStreamFragment) getSupportFragmentManager() .getFragment(savedInstanceState, "public_stream_fragment"); } } /** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */ public class SectionsPagerAdapter extends FragmentPagerAdapter { public SectionsPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { PublicStreamFragment publicStreamFragment = PublicStreamFragment. newInstance(PublicStreamFragment.STREAM_TYPE_PUBLIC); PublicStreamFragment privateStreamFragment = PublicStreamFragment. newInstance(PublicStreamFragment.STREAM_TYPE_PRIVATE); MatchFragment matchFragment = new MatchFragment(); ProfileFragment profileFragment = new ProfileFragment(); switch (position) { case 0: //public stream frag //TODO remove this badass shortcut return publicStreamFragment; //return (mPublicStreamFragment = new PublicStreamFragment()); case 1: //show private stream frag return privateStreamFragment; case 2: //show match frag return matchFragment; case 3: //show profile frag return profileFragment; } return null; } @Override public int getCount() { // Show 4 total pages. return 4; } @Override public CharSequence getPageTitle(int position) { Locale l = Locale.getDefault(); switch (position) { case 0: return getString(R.string.title_public_feeds).toUpperCase(l); case 1: return getString(R.string.title_private_feeds).toUpperCase(l); case 2: return getString(R.string.title_match_photos).toUpperCase(l); case 3: return getString(R.string.title_user_profile).toUpperCase(l); } return null; } } }