Android Open Source - android-play-api-client Main Activity






From Project

Back to project page android-play-api-client.

License

The source code is released under:

Apache License

If you think the Android project android-play-api-client listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ar.com.gmvsoft.play.ui;
/*from   w  w w.  ja v a2s.  c o m*/
import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsItem;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.annotations.SystemService;
import org.androidannotations.annotations.ViewById;
import org.androidannotations.annotations.rest.RestService;

import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import ar.com.gmvsoft.play.Global;
import ar.com.gmvsoft.play.R;
import ar.com.gmvsoft.play.api.ProductsResource;
import ar.com.gmvsoft.play.hardware.ShakeSensorListener;
import ar.com.gmvsoft.play.ui.adapter.ProductsTabsPagerAdapter;

@EActivity(R.layout.activity_main)
@OptionsMenu(R.menu.main)
public class MainActivity extends FragmentActivity implements TabListener {

  private String[] tabs = { "Find All", "Find By Id", "Add New" };

  private ProductsTabsPagerAdapter tabsPagerAdapter;

  @ViewById
  ViewPager pager;

  @SystemService
  SensorManager sensorManager;

  @RestService
  ProductsResource productsResource;

  private ShakeSensorListener sensorListener;

  @AfterViews
  public void setUp() {
    Global.instance().setShakeIt(true);
    sensorListener = new ShakeSensorListener(this);
    registerSensorListener();
    createTabs();
    productsResource.setRootUrl(Global.instance().getApiUrl());
  }

  private void registerSensorListener() {
    sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_NORMAL);
  }

  private void createTabs() {
    tabsPagerAdapter = new ProductsTabsPagerAdapter(getSupportFragmentManager());
    pager.setAdapter(tabsPagerAdapter);
    getActionBar().setHomeButtonEnabled(false);
    getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    for (String tabName : tabs) {
      Tab tab = getActionBar().newTab().setText(tabName).setTabListener(this);
      getActionBar().addTab(tab);
    }

    createViewPagerListener();
  }

  @OptionsItem(R.id.action_debug_options)
  void debugOptionsSelected() {
    Intent intent = new Intent(this, DebugOptionsActivity_.class);
    startActivity(intent);
  }

  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
  }

  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
    pager.setCurrentItem(tab.getPosition());
  }

  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  }

  private void createViewPagerListener() {
    pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

      @Override
      public void onPageSelected(int position) {
        getActionBar().setSelectedNavigationItem(position);
      }

      @Override
      public void onPageScrolled(int arg0, float arg1, int arg2) {
      }

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

  @Override
  protected void onResume() {
    super.onResume();
    registerSensorListener();
  }

  @Override
  protected void onPause() {
    super.onPause();
    sensorManager.unregisterListener(sensorListener);
  }

}




Java Source Code List

ar.com.gmvsoft.play.Global.java
ar.com.gmvsoft.play.api.ProductsResource.java
ar.com.gmvsoft.play.api.dto.BaseProductDTO.java
ar.com.gmvsoft.play.api.dto.ProductDTO.java
ar.com.gmvsoft.play.api.error.APIErrorHandler.java
ar.com.gmvsoft.play.hardware.ShakeSensorListener.java
ar.com.gmvsoft.play.ui.DebugOptionsActivity.java
ar.com.gmvsoft.play.ui.MainActivity.java
ar.com.gmvsoft.play.ui.adapter.ProductsListAdapter.java
ar.com.gmvsoft.play.ui.adapter.ProductsTabsPagerAdapter.java
ar.com.gmvsoft.play.ui.dialog.DialogHelper.java
ar.com.gmvsoft.play.ui.fragment.AddNewFragment.java
ar.com.gmvsoft.play.ui.fragment.FindAllFragment.java
ar.com.gmvsoft.play.ui.fragment.FindByIdFragment.java