示例#1
0
 @Override
 public int getCount() {
   return ExerciseDao.getSize();
 }
示例#2
0
 @Override
 public CharSequence getPageTitle(int position) {
   int exerciseId = ExerciseDao.getExerciseId(position);
   return ExerciseDao.getExerciseById(exerciseId).getName();
 }
示例#3
0
    @Override
    public View onCreateView(
        final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      final View rootView = inflater.inflate(R.layout.fragment_main, container, false);
      final TextView textView = (TextView) rootView.findViewById(R.id.section_label);
      final VideoView videoView = (VideoView) rootView.findViewById(R.id.videoView);
      int exerciseNumber = getArguments().getInt(ARG_SECTION_NUMBER);
      final int exerciseId = ExerciseDao.getExerciseId(exerciseNumber - 1);
      final Exercise exercise = ExerciseDao.getExerciseById(exerciseId);
      textView.setText(exercise.getDesc());

      Uri uri =
          Uri.parse(
              "android.resource://" + getActivity().getPackageName() + "/" + exercise.getVideoId());
      videoView.setVideoURI(uri);
      videoView.setOnPreparedListener(
          new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
              videoView.start();
            }
          });

      videoView.setOnTouchListener(
          new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent event) {
              changeSettings();

              return false;
            }

            private void changeSettings() {
              View dialogView =
                  getActivity().getLayoutInflater().inflate(R.layout.num_picker, null);
              NumberPicker repeatCountPicker =
                  (NumberPicker) dialogView.findViewById(R.id.repeatCountPicker);
              NumberPicker executionCountPicker =
                  (NumberPicker) dialogView.findViewById(R.id.executionCountPicker);
              NumberPicker weightPicker = (NumberPicker) dialogView.findViewById(R.id.weightPicker);
              Execution execution =
                  ExecutionDao.getLastExecutionByExercise(ExerciseDao.getExerciseById(exerciseId));
              List<String> numbersList = new ArrayList<>();
              for (int i = 1; i < 51; i++) {
                numbersList.add(String.valueOf(i));
              }
              final String[] numbersInt = new String[numbersList.size()];
              numbersList.toArray(numbersInt);
              repeatCountPicker.setDisplayedValues(numbersInt);
              repeatCountPicker.setMaxValue(numbersInt.length - 1);
              repeatCountPicker.setMinValue(0);
              repeatCountPicker.setFormatter(
                  new NumberPicker.Formatter() {
                    @Override
                    public String format(int i) {
                      return String.format("%02d", i);
                    }
                  });
              repeatCountPicker.setValue(execution.getRepeatCount() - 1);

              executionCountPicker.setDisplayedValues(numbersInt);
              executionCountPicker.setMaxValue(numbersInt.length - 1);
              executionCountPicker.setMinValue(0);
              executionCountPicker.setFormatter(
                  new NumberPicker.Formatter() {
                    @Override
                    public String format(int i) {
                      return String.format("%02d", i);
                    }
                  });
              executionCountPicker.setValue(execution.getExecutionCount() - 1);

              numbersList = new ArrayList<>();
              for (double i = .5; i < 50.5; i += .5) {
                numbersList.add(String.valueOf(i));
              }
              final String[] numbersDbl = new String[numbersList.size()];
              numbersList.toArray(numbersDbl);
              weightPicker.setDisplayedValues(numbersDbl);
              weightPicker.setMaxValue(numbersDbl.length - 1);
              weightPicker.setMinValue(0);
              weightPicker.setValue(numbersList.indexOf(String.valueOf(execution.getWeight())));

              AlertDialog.Builder chooseSettings = new AlertDialog.Builder(getActivity());
              chooseSettings.setTitle(getString(R.string.settings));
              chooseSettings.setView(dialogView);
              chooseSettings.setPositiveButton(
                  getString(R.string.ok),
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      AlertDialog alertDialog = (AlertDialog) dialog;
                      sendInfo(alertDialog);
                    }

                    private void sendInfo(AlertDialog alertDialog) {
                      Intent intent = new Intent(getContext(), ExternalActivity.class);
                      NumberPicker repeatCountPicker =
                          (NumberPicker) alertDialog.findViewById(R.id.repeatCountPicker);
                      NumberPicker executionCountPicker =
                          (NumberPicker) alertDialog.findViewById(R.id.executionCountPicker);
                      NumberPicker weightPicker =
                          (NumberPicker) alertDialog.findViewById(R.id.weightPicker);
                      intent.putExtra("EXERCISE_ID", exerciseId);
                      intent.putExtra(
                          "REPEAT_COUNT",
                          Integer.parseInt(numbersInt[repeatCountPicker.getValue()]));
                      intent.putExtra(
                          "EXECUTION_COUNT",
                          Integer.parseInt(numbersInt[executionCountPicker.getValue()]));
                      intent.putExtra(
                          "WEIGHT", Double.parseDouble(numbersDbl[weightPicker.getValue()]));
                      startActivity(intent);
                    }
                  });
              chooseSettings.setNegativeButton(
                  getString(R.string.cancel),
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {}
                  });
              chooseSettings.show();
            }
          });
      return rootView;
    }