Ejemplo n.º 1
0
  public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    FitnessExercise fEx = (FitnessExercise) getItem(position);

    if (fEx.isTrainingEntryFinished(fEx.getLastTrainingEntry())) {
      vi = mInflater.inflate(R.layout.list_row_fex_done, null);
    } else {
      vi = mInflater.inflate(R.layout.list_row_fex, null);
      int unfinished = calculateUnfinishedTrainingEntries(fEx);

      TextView textview_remaining_sets = (TextView) vi.findViewById(R.id.textview_remaining_sets);
      textview_remaining_sets.setText(
          mActivity.getString(R.string.remaining_sets) + " " + unfinished);
    }

    final ImageView imageview_ex_image = (ImageView) vi.findViewById(R.id.imageview_ex_image);
    DataHelper data = new DataHelper(mActivity);
    // Images
    if (!fEx.getImagePaths().isEmpty()) {
      String icon = fEx.getImagePaths().get(0).toString();
      icon = icon.replace(".", "_icon.");
      imageview_ex_image.setImageDrawable(data.getDrawable(icon));
    } else {
      // set default image if no image can be found
      imageview_ex_image.setImageResource(R.drawable.ic_launcher);
    }

    TextView textview_exercise_name = (TextView) vi.findViewById(R.id.textview_exercise_name);

    String ex_name = fEx.getLocalizedName();
    textview_exercise_name.setText(ex_name, BufferType.SPANNABLE);

    return vi;
  }
Ejemplo n.º 2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_fex_detail, container, false);

    // show the current exercise
    ImageView imageview = (ImageView) rootView.findViewById(R.id.imageview);

    // set gesture detector
    this.mGestureScanner =
        new GestureDetector(
            this.getActivity(), new ExerciseDetailOnGestureListener(this, imageview, mExercise));

    // Images
    if (!mExercise.getImagePaths().isEmpty()) {
      DataHelper data = new DataHelper(getActivity());
      imageview.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString()));
    } else {
      imageview.setImageResource(R.drawable.ic_launcher);
    }

    imageview.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return mGestureScanner.onTouchEvent(event);
          }
        });

    // set adapter
    ListView listView = (ListView) rootView.findViewById(R.id.list);
    final TrainingEntryListAdapter mAdapter =
        new TrainingEntryListAdapter((FragmentActivity) getActivity(), mExercise, mTrainingEntry);
    listView.setAdapter(mAdapter);

    SwipeDismissListViewTouchListener touchListener =
        new SwipeDismissListViewTouchListener(
            listView,
            new SwipeDismissListViewTouchListener.OnDismissCallback() {
              @Override
              public void onDismiss(ListView listView, int[] reverseSortedPositions) {
                for (int position : reverseSortedPositions) {
                  mAdapter.remove(position);
                }
                mAdapter.notifyDataSetChanged();
              }
            });
    listView.setOnTouchListener(touchListener);
    // Setting this scroll listener is required to ensure that during
    // ListView scrolling,
    // we don't look for swipes.
    listView.setOnScrollListener(touchListener.makeScrollListener());

    return rootView;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_exercisetype_detail, container, false);
    ViewGroup rootLayout =
        (ViewGroup) rootView.findViewById(R.id.fragment_exercisetype_detail_layout);

    // If Image Exists
    if (!mExercise.getImagePaths().isEmpty()) {
      // Create Image View
      ImageView imageView = new ImageView(rootView.getContext());
      imageView.setLayoutParams(
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
      imageView.setPadding(20, 20, 20, 20);
      rootLayout.addView(imageView);
      imageView.setVisibility(View.VISIBLE);

      // set gesture detector
      this.mGestureScanner =
          new GestureDetector(
              this.getActivity(), new ExerciseDetailOnGestureListener(this, imageView, mExercise));

      // Set Image
      DataHelper data = new DataHelper(getActivity());
      imageView.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString()));

      rootView.setOnTouchListener(
          new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
              return mGestureScanner.onTouchEvent(event);
            }
          });
    } else {
      TextView textView = new TextView(rootView.getContext());
      textView.setLayoutParams(
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
      textView.setGravity(Gravity.CENTER);
      textView.setPadding(10, 10, 10, 10);
      textView.setText(Html.fromHtml(mExercise.getDescription()));
      rootLayout.addView(textView);
    }
    return rootView;
  }