Ejemplo n.º 1
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   int id = item.getItemId();
   if (id == R.id.action_refresh) {
     CountryIntentService.start(this, countryReceiver);
     return true;
   }
   return super.onOptionsItemSelected(item);
 }
Ejemplo n.º 2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    tabLayout = (TabLayout) findViewById(R.id.tabLayout);
    pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new PagerAdapter(getFragmentManager()));
    tabLayout.addTab(tabLayout.newTab().setText(R.string.front));
    tabLayout.addTab(tabLayout.newTab().setText(R.string.back));
    if (savedInstanceState == null) {
      CountryIntentService.start(this, countryReceiver);
    }
    pager.setPageTransformer(
        true,
        new ViewPager.PageTransformer() {
          @Override
          public void transformPage(View page, float position) {
            page.setRotationY(180 * position);
          }
        });
    tabLayout.setOnTabSelectedListener(
        new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
            pager.setCurrentItem(tab.getPosition(), false);
          }

          @Override
          public void onTabUnselected(TabLayout.Tab tab) {}

          @Override
          public void onTabReselected(TabLayout.Tab tab) {}
        });
    pager.addOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            tabLayout.getTabAt(position).select();
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
  }