@Override protected void onResume() { super.onResume(); // Set "All posts" selected blog.setCurrentPage(1); if (mViewPager != null) { mViewPager.setCurrentItem(1); } // Reset alarm on app start if (MainActivity.newPostAlarm != null) { MainActivity.newPostAlarm.cancelAlarm(this); } else { MainActivity.newPostAlarm = new NewPostAlarm(); } MainActivity.newPostAlarm.setAlarm(this); // Google Analytics track if (Utils.checkPlayServices(this)) { Tracker t = this.getTracker(TrackerName.APP_TRACKER); t.setScreenName("capture"); t.send(new HitBuilders.AppViewBuilder().build()); } // Close the Drawer mNavigationDrawerFragment.getDrawerLayout().closeDrawers(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Refresh icon requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminateVisibility(false); setContentView(R.layout.activity_main); // Initialize blog blog = Blog.getInstance(); blog.initBlog(this.getApplicationContext()); blog.loadFavouritesFromDB(); actionBar = getActionBar(); // Init drawer menu mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer); // Set up the drawer. mNavigationDrawerFragment.setUp( R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout)); // Init view pager mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.getChildAt(0).setBackgroundResource(R.color.red); // Create fragments fragmentList = new ArrayList<Fragment>(); fragmentList.add(new CategoryPostsFragment()); fragmentList.add(new AllPostsFragment()); fragmentList.add(new AuthorPostsFragment()); // Create fragment titles fragmentTitles = new ArrayList<String>(); fragmentTitles.add(getString(R.string.view_pager_section1)); fragmentTitles.add(getString(R.string.view_pager_section2)); fragmentTitles.add(getString(R.string.view_pager_section3)); // Add fragments and titles to the adapter mSectionsPagerAdapter.addFragments(fragmentList, fragmentTitles); }
@Override public void onNavigationDrawerItemSelected(int position) { switch (position) { // SHOW ALL POSTS case 1: if (!blog.getActiveFilter().equals(Blog.FILTER_ALL)) { blog.setActiveFilter(Blog.FILTER_ALL); blog.setCurrentPage(1); } // Force to refresh by changing the title mSectionsPagerAdapter.changeTitle(1, getString(R.string.navigation_drawer_section1)); mViewPager.setCurrentItem(1); actionBar.setTitle(getString(R.string.app_name)); break; // SCROLL TO CATEGORIES case 2: mViewPager.setCurrentItem(0); break; // SCROLL TO AUTHORS case 3: mViewPager.setCurrentItem(2); break; // SHOW FAVOURITES POSTS case 4: if (!blog.getActiveFilter().equals(Blog.FILTER_FAVOURITES)) { blog.setActiveFilter(Blog.FILTER_FAVOURITES); blog.setCurrentPage(1); } // Force to refresh by changing the title mSectionsPagerAdapter.changeTitle(1, getString(R.string.navigation_drawer_section4)); actionBar.setTitle(getString(R.string.navigation_drawer_section4)); mViewPager.setCurrentItem(1); break; // LAUCH DEFAULT EMAIL APP case 5: Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/message"); intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"*****@*****.**"}); intent.putExtra(Intent.EXTRA_SUBJECT, ""); intent.putExtra(Intent.EXTRA_TEXT, ""); Intent mailer = Intent.createChooser(intent, null); startActivity(mailer); break; } }