Android Open Source - StrTrainer_android Compute






From Project

Back to project page StrTrainer_android.

License

The source code is released under:

GNU General Public License

If you think the Android project StrTrainer_android 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

/**
 */*  w w  w .j av a  2  s.co m*/
 * StrTrainer /com/davefarinelli/strtrainer/Compute.java
 *
 * Copyright (c) 2011 Dave Farinelli
 *
 * LICENSE:
 *
 * This file is part of StrTrainer, a companion Android app for the Starting Strength weight
 * training program (http://davefarinelli.com/developer/android).
 *
 * StrTrainer is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any
 * later version.
 *
 * StrTrainer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with StrTrainer.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * @author Dave Farinelli <davefarinelli[at]gmail[dot]com>
 * @license http://www.gnu.org/licenses/gpl.html
 * @copyright 2011 Dave Farinelli
 */

package com.davefarinelli.strtrainer;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class Compute extends TabActivity {
  
  /**
   * Lets us know that the user enabled AM using the menu item and we should
   * turn it off when focus is lost. If it was turned on for some other reason
   * prior to this activity then we don's want to disable it when we leave.
   */
  protected Boolean mDisableAirplaneModeOnPause = false;
  
  /** Called when the activity is first created. */
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.compute);

      TabHost tabHost = getTabHost();  // The activity TabHost
      TabHost.TabSpec spec = null;  // Reusable TabSpec for each tab
      Intent intent = null;  // Reusable Intent for each tab
      
      createTab("Squat", 0, tabHost, spec, intent);
      createTab("Bench", 1, tabHost, spec, intent);
      createTab("Press", 2, tabHost, spec, intent);
      createTab("Deadlift", 3, tabHost, spec, intent);
      createTab("Clean", 4, tabHost, spec, intent);
  }
  
  @Override
  protected void onPause() {
    super.onPause();
    if (mDisableAirplaneModeOnPause)
      setAirplaneMode(false);
  }

  private void createTab(String name, int corelift_num, TabHost tabHost, TabSpec spec,
      Intent intent) {
    // Create an Intent to launch an Activity for the tab (to be reused)
      intent = new Intent().setClass(this, ComputeTab.class);
      intent.putExtra("corelift_num", corelift_num);
      
      // Initialize a TabSpec for each tab and add it to the TabHost
      spec = tabHost.newTabSpec(name).setIndicator(name)
                    .setContent(intent);
      tabHost.addTab(spec);
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.compute, menu);
    return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.toggle_airplane:
            toggleAirplaneMode();      
      return true;
    default:
      return super.onOptionsItemSelected(item);
    }
  }
  
  /**
   * Toggles the radio between off and on to minimize distractions and to save
   * battery life while working out.
   */
  protected void toggleAirplaneMode() {
    // get the current state
    boolean isEnabled = Settings.System.getInt(
      this.getContentResolver(), 
      Settings.System.AIRPLANE_MODE_ON, 0) == 1;  
    
    // toggle airplane mode
        setAirplaneMode(!isEnabled);  
    
        // track if we need to revert later
      mDisableAirplaneModeOnPause = !isEnabled;
  }
  
  /**
   * Turns the radio either on or off.
   * 
   * @param state True to enable or false to disable.
   */
  protected void setAirplaneMode(Boolean state) {
    // check to see if Airplane mode is enabled or not
    boolean isEnabled = Settings.System.getInt(
        this.getContentResolver(), 
        Settings.System.AIRPLANE_MODE_ON, 0) == 1;
    
    // check to see if a change is really needed
    if (isEnabled != state) {
      // toggle airplane mode
      Settings.System.putInt(this.getContentResolver(),
          Settings.System.AIRPLANE_MODE_ON, state ? 1 : 0);
      
      // post an intent to to the system to reload
      Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
      intent.putExtra("state", state);
      this.sendBroadcast(intent);
    }
  }
}




Java Source Code List

com.davefarinelli.strtrainer.About.java
com.davefarinelli.strtrainer.AppSettings_InitializeWorkSetValues.java
com.davefarinelli.strtrainer.AppSettings_ModifyIncrementValues.java
com.davefarinelli.strtrainer.AppSettings.java
com.davefarinelli.strtrainer.ComputeTab.java
com.davefarinelli.strtrainer.Compute.java
com.davefarinelli.strtrainer.Records.java
com.davefarinelli.strtrainer.StrTrainer.java
com.davefarinelli.strtrainer.Utilities_Estimate1RM.java
com.davefarinelli.strtrainer.Utilities.java