@Override
  public void onEdit(Exercise exercise, int position) {
    if (position == -1) {
      for (Exercise e : workout.getExercises()) {
        String name = e.getName();
        if (name.equals(exercise.getName())) {
          Toast toast = Toast.makeText(this, "Exercise already exists!", Toast.LENGTH_SHORT);
          toast.setGravity(Gravity.CENTER, 0, 0);
          toast.show();
          return;
        }
      }
    }
    ArrayList<Integer> positions = adapter.getCursorPositions();
    MatrixCursor newcursor = new MatrixCursor(new String[] {"_id", "name"});
    // int lastCursorPosition = cursor.getPosition();
    // copy over old cursor items to the new one.
    if (cursor != null) {
      cursor.moveToFirst();
      for (int i = 0; i < positions.size(); i++) {
        int cursorPosition = positions.get(i);
        int listPosition = adapter.getListPosition(positions.get(i));
        // dont add to new cursor if item has been removed.
        if (listPosition == DragSortCursorAdapter.REMOVED) continue;
        cursor.moveToPosition(cursorPosition);
        String c = cursor.getString(1);
        // if its not a new exercise, check to see if the current cursor list position mapping
        // matches the one we are working with. If yes, set c to be the new exercise.
        if (position >= 0) {
          if (position == listPosition) {
            c = exercise.getName();
          }
        }
        newcursor.newRow().add(listPosition).add(c);
      }
    }
    // add the new row
    if (position < 0 && exercise != null) {
      newcursor.newRow().add(newcursor.getCount()).add(exercise.getName());
    }

    ArrayList<Exercise> newExercises = new ArrayList<Exercise>();
    newcursor.moveToFirst();
    for (int i = 0; i < newcursor.getCount(); i++) {
      String ename = newcursor.getString(1);
      Exercise e = workout.getExercise(ename);
      if (e != null) newExercises.add(e);
      else if (i == newcursor.getCount() - 1) newExercises.add(exercise);
      if (!newcursor.moveToNext()) break;
    }

    adapter.changeCursor(newcursor);
    cursor = newcursor;

    // modify workout to reflect the change
    workout.setExercises(newExercises);
  }
 @Override
 public void onStart() {
   super.onStart();
   View view = getView();
   if (view != null) {
     TextView title = (TextView) view.findViewById(R.id.textTitle);
     Workout workout = Workout.workouts[(int) workoutId];
     title.setText(workout.getName());
     TextView description = (TextView) view.findViewById(R.id.textDescription);
     description.setText(workout.getDescription());
   }
 }
 // checks if any exercises have been removed and updates the global list accordingly
 // also rewrites the workouts file on the device
 private void checkRemoved() {
   ArrayList<Integer> positions = adapter.getCursorPositions();
   ArrayList<Exercise> newExercises = new ArrayList<Exercise>();
   if (cursor != null) {
     cursor.moveToFirst();
     for (int i = 0; i < positions.size(); i++) {
       int cursorPosition = positions.get(i);
       cursor.moveToPosition(cursorPosition);
       String c = cursor.getString(1);
       newExercises.add(workout.getExercise(c));
     }
     workout.setExercises(newExercises);
   }
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // Handle presses on the action bar items
   switch (item.getItemId()) {
     case R.id.action_exit:
       // EXIT
       setResult(WorkoutObjects.BAD_RESULT);
       finish();
       return true;
     case R.id.action_save:
       // SAVE
       checkRemoved();
       if (WorkoutObjects.workoutList.hasWorkout(workout.getName()) && position == -1) {
         Toast.makeText(this, "Workout name already exists!", Toast.LENGTH_SHORT).show();
       } else {
         if (position == -1) FileManagement.addGlobalWorkout(workout);
         MainActivity.onEdit(workout, position);
         FileManagement.writeWorkoutFile();
         setResult(WorkoutObjects.OK_RESULT);
         finish();
       }
       return true;
     case R.id.action_create_exercise:
       android.app.FragmentManager fm = CustomizeWorkout.this.getFragmentManager();
       CreateExercise f = new CreateExercise();
       Bundle bundle = new Bundle();
       bundle.putInt("caller", WorkoutObjects.CUSTOMIZE_WORKOUT);
       f.setArguments(bundle);
       f.show(fm, "dialog");
       return true;
     default:
       return super.onOptionsItemSelected(item);
   }
 }
示例#5
0
 @Override
 public void onComplete(Scope what, Workout s) {
   if (this.scope == what && this.event == Event.COMPLETED) {
     s.log("fire onComplete");
     fire(s);
   }
 }
示例#6
0
 @Override
 public void onResume(Workout s) {
   if (this.event == Event.RESUMED) {
     s.log("fire onResume");
     fire(s);
   }
 }
示例#7
0
 @Override
 public void onStop(Workout s) {
   if (this.event == Event.STOPPED) {
     s.log("fire onStop");
     fire(s);
   }
 }
示例#8
0
 @Override
 public void onPause(Workout s) {
   if (this.event == Event.PAUSED) {
     s.log("fire onPause");
     fire(s);
   }
 }
示例#9
0
 @Override
 public void onStart(Scope what, Workout s) {
   if (this.scope == what && this.event == Event.STARTED) {
     s.log("fire onStart");
     fire(s);
   }
 }
  private boolean saveDataToCsvFile() {

    String csv = "/mnt/sdcard/DanceForHealthLog.csv";

    try {
      CSVWriter writer = new CSVWriter(new FileWriter(csv), ',');
      String[] header = {
        "Date", "Type", "Weight", "Post-Dance HR", "Post-Dance Pedometer", "PACE Score(strain)"
      };
      writer.writeNext(header);
      for (Workout w : workoutDataStore) {
        String[] entries = {
          w.getDate(),
          w.getType(),
          "" + w.getWeight(),
          "" + w.getHR(),
          "" + w.getSteps(),
          "" + w.getStrain()
        };
        writer.writeNext(entries);
      }
      writer.close();
      return true;

    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
  }
示例#11
0
 public WorkoutPageData fetchWorkoutPageData(
     final User currentUser,
     final Long workoutId,
     final int similarPage,
     final int workoutStartIndex,
     final int messagesStartIndex,
     final int privateMessagesPageIndex)
     throws WorkoutNotFoundException {
   final Workout workout = workoutStore.fetchWorkout(workoutId);
   final PaginatedCollection<PrivateMessage> emptyPage = emptyPage();
   final PaginatedCollection<PrivateMessage> privateConversation =
       currentUser == null
           ? emptyPage
           : fetchPrivateConversation(
               currentUser, workout.getUser().getId(), privateMessagesPageIndex);
   return new WorkoutPageData(
       workout,
       fetchPublicMessages(Topic.Kind.WORKOUT, workoutId, 5, messagesStartIndex),
       getSimilarWorkouts(workout, similarPage),
       workoutStore.getWorkouts(workout.getUser(), EMPTY_STRING_LIST, workoutStartIndex, 10),
       privateConversation);
 }
示例#12
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_workout);

    Bundle bundle = this.getIntent().getExtras();
    position = bundle.getInt("position");

    editNameField = (EditText) findViewById(R.id.workoutNameField);
    addExerciseButton = (Button) findViewById(R.id.addExerciseButton);

    if (position >= 0) {
      workout = WorkoutList.getInstance().getWorkout(position);
      editNameField.setText(workout.getName());
    } else {
      workout = new Workout();
    }

    dslv = (DragSortListView) findViewById(R.id.exerciseList);

    String[] cols = {"name"};
    int[] ids = {R.id.text};
    adapter = new MyAdapter(this, R.layout.list_item_click_remove, null, cols, ids, 0);
    dslv.setAdapter(adapter);

    if (workout != null) {
      // populate the list of exercises
      cursor = new MatrixCursor(new String[] {"_id", "name"});
      int size = workout.getExercises().size();
      for (int i = 0; i < size; i++) {
        cursor.newRow().add(i).add(workout.getExercises().get(i).getName());
      }
      adapter.changeCursor(cursor);
    }

    setUpButtonListeners();
    setUpTextWatcher();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_workout);
    Workout loadedWorkout = null;

    try {
      FileInputStream fis = openFileInput("WorkoutPage");
      ObjectInputStream is = new ObjectInputStream(fis);
      loadedWorkout = (Workout) is.readObject();
      is.close();
      fis.close();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    } catch (OptionalDataException e) {
      e.printStackTrace();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (StreamCorruptedException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    String s = loadedWorkout.getName();
    setTitle(s);

    /*
    Intent intent = getIntent();
    String message = intent.getStringExtra("asdf");
    name = message;
    //setTitle(name);
    */

  }