@Override
  protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "setting selected id from intent");
    setSelectedItemIDFromIntent();
    ActiveUser activeUser = ((GiveOrTakeApplication) getApplication()).getActiveUser();
    if (activeUser == null || activeUser.getUserID() == null) {
      Intent logoutIntent = new Intent(this, LoginActivity.class);
      logoutIntent.putExtra(LoginFragment.EXTRA_LOGIN_ACTION, LoginFragment.LOGOUT);
      logoutIntent.putExtra(MainActivity.EXTRA_ITEM_ID, getSelectedItemID());
      startActivity(logoutIntent);
      finish();
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding
    // tab. We can also use ActionBar.Tab#select() to do this if we have
    // a reference to the Tab.
    mViewPager.setOnPageChangeListener(
        new ViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
          }
        });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
      // Create a tab with text corresponding to the page title defined by
      // the adapter. Also specify this Activity object, which implements
      // the TabListener interface, as the callback (listener) for when
      // this tab is selected.
      actionBar.addTab(
          actionBar
              .newTab()
              .setText(mSectionsPagerAdapter.getPageTitle(i))
              .setIcon(mSectionsPagerAdapter.getPageIcon(i))
              .setTabListener(this));
    }

    actionBar.selectTab(actionBar.getTabAt(DEFAULT_SELECTED_TAB));

    Long itemID = getSelectedItemID();
    if (itemID != null) {
      actionBar.selectTab(actionBar.getTabAt(FREE_ITEMS_TAB));
    }
  }
    @Override
    public void onPageSelected(int position) {
      if (DEBUG) Log.d(TAG, "onPageSelected: " + position);
      final ActionBar actionBar = getActionBar();
      if (mDialpadFragment != null && !mDuringSwipe) {
        if (DEBUG) {
          Log.d(
              TAG,
              "Immediately show/hide fake menu buttons. position: "
                  + position
                  + ", dragging: "
                  + mDuringSwipe);
        }
        mDialpadFragment.updateFakeMenuButtonsVisibility(
            position == TAB_INDEX_DIALER && !mDuringSwipe);
      }

      if (mCurrentPosition == position) {
        Log.w(TAG, "Previous position and next position became same (" + position + ")");
      }

      actionBar.selectTab(actionBar.getTabAt(position));
      mNextPosition = position;
    }
 @Override
 public Tab getTabAt(int index) {
   android.app.ActionBar.Tab selected = mActionBar.getTabAt(index);
   return (selected != null) ? (Tab) selected.getTag() : null;
 }
 public Tab GetTabAtIndex(int _index) {
   ActionBar actionBar = this.controls.activity.getActionBar();
   actionBar.setSelectedNavigationItem(_index);
   return actionBar.getTabAt(_index);
 }
示例#5
0
  @Override
  protected void onResume() {
    super.onResume();

    // initialize our preferences
    tempUomPref = Integer.parseInt(prefs.getString("prefs_uom_temp", "1"));
    afrNotEqualTargetPref = prefs.getBoolean("prefs_afrnottarget_pref", false);
    afrNotEqualTargetTolerance = prefs.getFloat("prefs_afrnottarget_tolerance_pref", 5f);
    waterTempPref = prefs.getBoolean("prefs_watertemp_pref", false);
    remoteName = prefs.getString("prefs_remote_name", "");
    remoteMacAddr = prefs.getString("prefs_remote_mac", "");
    autoConnect = prefs.getBoolean("prefs_auto_connect", false);

    // need to set gauge scale based on uom selected
    switch (tempUomPref) {
      case 0:
        minimumWaterTemp =
            prefs.getFloat("prefs_min_water_temp", AdaptivePreferences.MIN_WATER_TEMP_CELCIUS);
        maximumWaterTemp =
            prefs.getFloat("prefs_max_water_temp", AdaptivePreferences.MAX_WATER_TEMP_CELCIUS);

        iatNeedle.setPivotPoint(.5f);
        iatNeedle.setMinValue(0);
        iatNeedle.setMaxValue(100);
        iatNeedle.setMinDegrees(-180);
        iatNeedle.setMaxDegrees(90);

        imgIat.setImageResource(R.drawable.iatgauge_celcius);
        break;

      case 1:
        minimumWaterTemp =
            prefs.getFloat("prefs_min_water_temp", AdaptivePreferences.MIN_WATER_TEMP_FAHRENHEIT);
        maximumWaterTemp =
            prefs.getFloat("prefs_max_water_temp", AdaptivePreferences.MAX_WATER_TEMP_FAHRENHEIT);

        iatNeedle.setPivotPoint(.5f);
        iatNeedle.setMinValue(0);
        iatNeedle.setMaxValue(200);
        iatNeedle.setMinDegrees(-180);
        iatNeedle.setMaxDegrees(90);

        imgIat.setImageResource(R.drawable.iatgauge);
        break;
    }

    afrAlarmLogging = prefs.getBoolean("prefs_afr_alarm_logging", false);
    if (menuShareLog != null) {
      menuShareLog.setVisible(afrAlarmLogging && !afrAlarmLogItems.getItems().isEmpty());
    }

    // ensure both fragments are hidden
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.hide(adaptiveFragment);
    ft.hide(gaugesFragment);
    ft.hide(fuelFragment);
    ft.commit();

    ActionBar bar = getActionBar();
    bar.selectTab(bar.getTabAt(prefs.getInt("prefs_last_tab", 1)));

    // EVAN
    String action = getIntent().getAction();

    if (Intent.ACTION_MAIN.equals(action) || UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
      if (DEBUG_MODE) Log.d(TAG, "USB Device Attached");

      connected = UsbConnectedThread.checkConnectedUsbDevice(this, connectionHandler);

      if (connected != null) {
        lastUpdateInMillis = System.currentTimeMillis();
      }
    }
    // END EVAN

    if (connected != null && connected.isAlive()) {
      refreshHandler.postDelayed(RefreshRunnable, LONG_PAUSE);
    } else {
      if (autoConnect && remoteMacAddr.length() > 0) {
        disconnect();
        new Handler()
            .postDelayed(
                (new Runnable() {
                  public void run() {
                    connect(remoteName, remoteMacAddr);
                  }
                }),
                1000);
        //        		connect(remoteName,  remoteMacAddr);
      }
    }
  }