Android Open Source - LightControllerApp Main Activity






From Project

Back to project page LightControllerApp.

License

The source code is released under:

GNU General Public License

If you think the Android project LightControllerApp 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 info.androidhive.tabsswipe;
/*from w  w  w .java 2  s .c o  m*/
import info.androidhive.tabsswipe.adapter.TabsPagerAdapter;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.widget.Toast;

public class MainActivity extends FragmentActivity implements
    ActionBar.TabListener {

  private ViewPager viewPager;
  private TabsPagerAdapter mAdapter;
  private ActionBar actionBar;
  // Tab titles
  private String[] tabs = { "Color Picker", "Fancy Color Modes" };

  static Activity mActivity = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mActivity = this;

    // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Adding Tabs
    for (String tab_name : tabs) {
      actionBar.addTab(actionBar.newTab().setText(tab_name)
          .setTabListener(this));
    }

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

      @Override
      public void onPageSelected(int position) {
        // on changing the page
        // make respected tab selected
        actionBar.setSelectedNavigationItem(position);
      }

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

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

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

  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // on tab selected
    // show respected fragment view
    viewPager.setCurrentItem(tab.getPosition());
  }

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

  public static String GetUrl()
  {
    return "http://dloman.noip.me:8080";
  }

   public final static Handler mHandler = new Handler() {
          public void handleMessage(Message msg) {
                if(msg.arg1 == 1)
                      Toast.makeText(mActivity,"Server is Down :(", Toast.LENGTH_SHORT).show();
          }
      };
   public static void showToast()
   {
     Message msg = mHandler.obtainMessage();
     msg.arg1 = 1;
     mHandler.sendMessage(msg);
   }

}




Java Source Code List

info.androidhive.tabsswipe.Fragment1.java
info.androidhive.tabsswipe.Fragment2.java
info.androidhive.tabsswipe.HttpPostWrapper.java
info.androidhive.tabsswipe.MainActivity.java
info.androidhive.tabsswipe.adapter.TabsPagerAdapter.java