Android Open Source - StrTrainer_android App Settings_ Initialize Work Set Values






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

/**
 *//  ww  w  .ja va  2 s .c  o  m
 * StrTrainer /com/davefarinelli/strtrainer/InitializeValues.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.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AppSettings_InitializeWorkSetValues extends Activity implements OnClickListener {
  /** Declaration of Shared Preference name */
  public static final String PREFS_NAME = "MyPrefsFile";
  
  //Create widget handles
  EditText etSquatWorkSetWeight;
  EditText etBenchWorkSetWeight;
  EditText etPressWorkSetWeight;
  EditText etDeadliftWorkSetWeight;
  EditText etCleanWorkSetWeight;
  
  /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings_init_values);
        
        //Sets click listener for save button
        Button buttonSave = (Button)findViewById(R.id.b_save);
        buttonSave.setOnClickListener(this);
        
        //Sets click listener for quit button
        Button buttonQuit = (Button)findViewById(R.id.b_quit);
        buttonQuit.setOnClickListener(this);
        
        // Initialize handles
        etSquatWorkSetWeight = (EditText)findViewById(R.id.et_squat);
        etBenchWorkSetWeight = (EditText)findViewById(R.id.et_bench);
        etPressWorkSetWeight = (EditText)findViewById(R.id.et_press);
        etDeadliftWorkSetWeight = (EditText)findViewById(R.id.et_deadlift);
        etCleanWorkSetWeight = (EditText)findViewById(R.id.et_clean);
    }

  @Override
  public void onClick(View arg0) {
    switch(arg0.getId()) {
      case R.id.b_save:
        //Save Work Set Value weight into memory
          SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
          SharedPreferences.Editor editor = settings.edit();
          
          // Added try catch to fix bug of program crash when empty values given 8.2.2011
          try
          {
            editor.putFloat("squatWorkSetValue", Float.parseFloat(etSquatWorkSetWeight.getText().toString()));
            editor.putFloat("benchWorkSetValue", Float.parseFloat(etBenchWorkSetWeight.getText().toString()));
            editor.putFloat("pressWorkSetValue", Float.parseFloat(etPressWorkSetWeight.getText().toString()));
            editor.putFloat("deadliftWorkSetValue", Float.parseFloat(etDeadliftWorkSetWeight.getText().toString()));
            editor.putFloat("cleanWorkSetValue", Float.parseFloat(etCleanWorkSetWeight.getText().toString()));
            
            // Commit the edits!
            editor.commit();
          
          finish();
          }
          catch (NumberFormatException ex)
          {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("You need to enter a value for each of the core lifts!")
                   .setCancelable(false)
                   .setPositiveButton("Okay", new DialogInterface.OnClickListener() {
                       public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                       }
                   });
            AlertDialog alert = builder.create();
            alert.show();
          }
          
        break;
      case R.id.b_quit:
        finish();
          
        break;
    }
  }
}




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