Android Open Source - opentraining La Te X Exporter






From Project

Back to project page opentraining.

License

The source code is released under:

GNU General Public License

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

/**
 * /*from w w w . jav  a  2s  .  c o m*/
 * This is OpenTraining, an Android application for planning your your fitness training.
 * Copyright (C) 2012-2014 Christian Skubich
 * 
 * This program 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 3 of the License, or
 * (at your option) any later version.
 * 
 * This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package de.skubware.opentraining.exporter;

import java.io.*;

import de.skubware.opentraining.basic.*;

import android.content.Context;

/**
 * A LaTeX Exporter class.
 * 
 * @author Christian Skubich
 * 
 */
public class LaTeXExporter extends WorkoutExporter {

  public LaTeXExporter(Context context) {
    super(context);
  }

  /**
   * Creates the PDF File to the Path that was set in the BestandsDaten
   * 
   * @param pdfSettings
   *            The settings for the creation
   * 
   * @throws FileNotFoundException
   *             if the path could not be used
   */
  public String exportWorkoutToString(Workout w) {

    Settings settings = new Settings();

    // public void create(Settings settings) throws FileNotFoundException{
    final String NEW = System.getProperty("line.separator");

    int colums = w.getFitnessExercises().size();
    int rowCount = settings.getRowCount();
    int rowSize = 3;
    int downFactor = settings.getDownFactor();
    int columnWidth = settings.getColumnWidth();
    System.out.println("Creating PDF " + w.getName() + " with the downFactor=" + downFactor + ", rowCount=" + rowCount);

    // build textfile
    StringBuilder tex = new StringBuilder();
    tex.append("\\documentclass[a4paper]{scrartcl}");
    tex.append(NEW);
    tex.append("\\usepackage{rotating}");
    tex.append(NEW);
    tex.append("\\usepackage{multirow}");
    tex.append(NEW);
    tex.append(NEW);

    tex.append("% deutsche Silbentrennung");
    tex.append(NEW);
    tex.append("\\usepackage[ngerman]{babel}");
    tex.append(NEW);

    tex.append("% wegen deutschen Umlauten");
    tex.append(NEW);
    tex.append("\\usepackage[utf8]{inputenc}");
    tex.append(NEW);
    tex.append(NEW);

    tex.append("% fuer zentrierte Tabellenzeilen ?berschriften");
    tex.append(NEW);
    tex.append("\\usepackage{tabularx}");
    tex.append(NEW);
    tex.append("\\newcolumntype{C}[1]{>{\\centering\\arraybackslash}p{#1}} % zentriert mit Breitenangabe");
    tex.append(NEW);
    tex.append(NEW);

    tex.append("\\begin{document}");
    tex.append(NEW);
    tex.append("\\pagestyle{empty}");
    tex.append(NEW);
    tex.append("\\begin{sidewaystable}");
    tex.append(NEW);
    tex.append("\\centering");
    tex.append(NEW);
    tex.append("\\Large");
    tex.append(NEW);
    tex.append(NEW);

    tex.append("%Korrekturfaktor, Verschiebung nach unten");
    tex.append(NEW);
    tex.append("\\begin{addmargin}{-" + downFactor + "cm}");
    tex.append(NEW);
    tex.append(NEW);

    tex.append("%Ab hier beginnt die eigentliche Tabelle");
    tex.append(NEW);
    tex.append("\\begin{tabular}{ |l||");
    for (int i = 0; i < colums; i++) {
      tex.append("C{" + columnWidth + "mm}|");
    }
    tex.append("}");
    tex.append(NEW);
    tex.append(NEW);

    // Erste Zeile
    tex.append("\\hline");
    tex.append(NEW);
    tex.append("Datum ");
    for (FitnessExercise fEx : w.getFitnessExercises()) {
      tex.append("& " + fEx.getExType().getLocalizedName() + " ");
    }
    tex.append("\\\\");
    tex.append(NEW);
    tex.append(NEW);

    // S?tze
    int maxset = 0;
    for (FitnessExercise fEx : w.getFitnessExercises()) {
      if (fEx.getFSetList().size() > maxset)
        maxset = fEx.getFSetList().size();
    }
    tex.append("\\hline");
    tex.append(NEW);
    tex.append("\\hline");
    tex.append(NEW);
    tex.append("\\multirow{" + maxset + "}{14mm}");
    tex.append(NEW);

    // Satz Reihen Strings erzeugen
    String[][] set = new String[colums][maxset];
    int colum = 0;
    for (FitnessExercise fEx : w.getFitnessExercises()) {
      int row = 0;
      for (FSet s : fEx.getFSetList()) {
        set[colum][row] = s.toString();
        row++;
      }
      colum++;
    }

    for (int i = 0; i < maxset; i++) {
      for (int k = 0; k < colums; k++) {
        if (set[k][i] != null) {
          tex.append(" & " + set[k][i]);
        } else {
        }
      }
      tex.append("\\\\");
      tex.append(NEW);

    }
    // if(maxset>0){
    tex.append("\\hline");
    tex.append(NEW);
    // }

    // Freie Zeilen
    StringBuilder b = new StringBuilder();
    for (int i = 0; i < colums; i++) {
      b.append("& ");
    }
    b.append("\\\\");
    b.append(NEW);

    // multiple bs for larger rows
    for (int i = 1; i < rowSize; i++) {
      b.append(b);
    }
    b.append("\\hline");
    b.append(NEW);

    String NEWCOLUM = b.toString();

    for (int i = 0; i < rowCount; i++) {
      tex.append(NEWCOLUM);
    }

    tex.append("\\end{tabular}");
    tex.append("% Tabellen Ende");
    tex.append(NEW);
    tex.append("\\end{addmargin}");
    tex.append(NEW);
    tex.append(NEW);

    tex.append("\\end{sidewaystable}");
    tex.append(NEW);
    tex.append("\\end{document}");
    tex.append(NEW);

    return tex.toString();
  } // end create()

  /**
   * A class for the BestandsDaten of the OSTS
   * 
   * @author Christian Skubich
   */
  public class Settings {

    // PDF settings
    /** How many mm each column of the pdf should be */
    private int columnWidth = 33;
    /** The number of rows for the pdf file */
    private int rowCount = 10;
    /** The size of the empty cells */
    private int cellSize = 3;
    /** A factor to correct the centering of the table on the sheet */
    private int downFactor = 3;

    // other settings
    /** The maximum width of an image of the generated html pages */
    private int maxImageWidth = 450;

    /**
     * Constructor which fills the equipment map.
     */
    public Settings() {
    }

    // Getter and Setter

    /**
     * Setter for columnWidth
     * 
     * @param columnWidth
     *            The columnWidth
     * 
     * @throws IllegalArgumentException
     *             if the argument is negative
     */
    public void setColumnWidth(int columnWidth) {
      if (columnWidth < 0)
        throw new IllegalArgumentException("No negative values allowed");
      this.columnWidth = columnWidth;
    }

    /**
     * Getter for columnWidth
     * 
     * @return The columnWidth
     */
    public int getColumnWidth() {
      return columnWidth;
    }

    /**
     * Setter for rowCount
     * 
     * @param rowCount
     *            The rowCount
     * 
     * @throws IllegalArgumentException
     *             if the argument is negative
     */
    public void setRowCount(int rowCount) {
      if (rowCount < 0)
        throw new IllegalArgumentException("No negative values allowed");
      this.rowCount = rowCount;
    }

    /**
     * Getter for rowCount
     * 
     * @return The rowCount
     */
    public int getRowCount() {
      return rowCount;
    }

    /**
     * Setter for downFactor
     * 
     * @param downFactor
     *            The downFactor
     */
    public void setDownFactor(int downFactor) {
      this.downFactor = downFactor;
    }

    /**
     * Getter for downFactor
     * 
     * @return The downFactor
     */
    public int getDownFactor() {
      return this.downFactor;
    }

    /**
     * Setter for cellSize
     * 
     * @param cellSize
     *            The cellSize
     */
    public void setCellSize(int cellSize) {
      this.cellSize = cellSize;
    }

    /**
     * Getter for cellSize
     * 
     * @return The cellSize
     */
    public int getCellSize() {
      return this.cellSize;
    }

    /**
     * Setter for maxImageWidth
     * 
     * @param maxImageWidth
     *            the maxImageWidth to set
     */
    public void setMaxImageWidth(int maxImageWidth) {
      this.maxImageWidth = maxImageWidth;
    }

    /**
     * Getter for maxImageWidth
     * 
     * @return the maxImageWidth
     */
    public int getMaxImageWidth() {
      return maxImageWidth;
    }

  }
}




Java Source Code List

at.technikum.mti.fancycoverflow.FancyCoverFlowAdapter.java
at.technikum.mti.fancycoverflow.FancyCoverFlowItemWrapper.java
at.technikum.mti.fancycoverflow.FancyCoverFlow.java
de.skubware.opentraining.activity.ChangeLogDialog.java
de.skubware.opentraining.activity.DisclaimerDialog.java
de.skubware.opentraining.activity.MainActivity.java
de.skubware.opentraining.activity.NavigationGalleryAdapter.java
de.skubware.opentraining.activity.SelectWorkoutDialogFragment.java
de.skubware.opentraining.activity.WhatsNewDialog.java
de.skubware.opentraining.activity.acra.ACRACrashReportMailer.java
de.skubware.opentraining.activity.acra.ACRAFeedbackMailer.java
de.skubware.opentraining.activity.acra.OpenTrainingApplication.java
de.skubware.opentraining.activity.acra.RequestExerciseUpdate.java
de.skubware.opentraining.activity.create_exercise.CreateExerciseActivity.java
de.skubware.opentraining.activity.create_exercise.CustomSpinner.java
de.skubware.opentraining.activity.create_exercise.DescriptionFragment.java
de.skubware.opentraining.activity.create_exercise.EditImageMetadataDialog.java
de.skubware.opentraining.activity.create_exercise.EquipmentDataFragment.java
de.skubware.opentraining.activity.create_exercise.ExerciseImageListAdapter.java
de.skubware.opentraining.activity.create_exercise.ImageFragment.java
de.skubware.opentraining.activity.create_exercise.MuscleDataFragment.java
de.skubware.opentraining.activity.create_exercise.NameFragment.java
de.skubware.opentraining.activity.create_exercise.SimpleDataFragment.java
de.skubware.opentraining.activity.create_exercise.SpinnerDataFragment.java
de.skubware.opentraining.activity.create_workout.DialogFilterMusclesAndEquipment.java
de.skubware.opentraining.activity.create_workout.DialogWorkoutOverviewFragment.java
de.skubware.opentraining.activity.create_workout.ExerciseDetailOnGestureListener.java
de.skubware.opentraining.activity.create_workout.ExerciseTypeDetailActivity.java
de.skubware.opentraining.activity.create_workout.ExerciseTypeDetailFragment.java
de.skubware.opentraining.activity.create_workout.ExerciseTypeListActivity.java
de.skubware.opentraining.activity.create_workout.ExerciseTypeListAdapter.java
de.skubware.opentraining.activity.create_workout.ExerciseTypeListFragment.java
de.skubware.opentraining.activity.create_workout.SelectMuscleDialog.java
de.skubware.opentraining.activity.create_workout.SendExerciseFeedbackDialogFragment.java
de.skubware.opentraining.activity.create_workout.upload_exercise.ExerciseImage.java
de.skubware.opentraining.activity.create_workout.upload_exercise.UploadExerciseAsyncTask.java
de.skubware.opentraining.activity.create_workout.upload_exercise.UploadExerciseImagesAsyncTask.java
de.skubware.opentraining.activity.create_workout.upload_exercise.WgerRestService.java
de.skubware.opentraining.activity.manage_workouts.RenameWorkoutDialogFragment.java
de.skubware.opentraining.activity.manage_workouts.WorkoutDetailActivity.java
de.skubware.opentraining.activity.manage_workouts.WorkoutDetailFragment.java
de.skubware.opentraining.activity.manage_workouts.WorkoutListActivity.java
de.skubware.opentraining.activity.manage_workouts.WorkoutListFragment.java
de.skubware.opentraining.activity.settings.LicenseDialog.java
de.skubware.opentraining.activity.settings.SettingsActivity.java
de.skubware.opentraining.activity.settings.sync.OpenTrainingSyncResultReceiver.java
de.skubware.opentraining.activity.settings.sync.OpenTrainingSyncService.java
de.skubware.opentraining.activity.settings.sync.RestClient.java
de.skubware.opentraining.activity.settings.sync.SyncFinishedDialog.java
de.skubware.opentraining.activity.settings.sync.WgerImageDownloader.java
de.skubware.opentraining.activity.settings.sync.WgerJSONParser.java
de.skubware.opentraining.activity.start_training.DialogFragmentAddEntry.java
de.skubware.opentraining.activity.start_training.DialogFragmentTrainingEntryTable.java
de.skubware.opentraining.activity.start_training.FExDetailActivity.java
de.skubware.opentraining.activity.start_training.FExDetailFragment.java
de.skubware.opentraining.activity.start_training.FExListActivity.java
de.skubware.opentraining.activity.start_training.FExListAdapter.java
de.skubware.opentraining.activity.start_training.FExListFragment.java
de.skubware.opentraining.activity.start_training.RecoveryTimerManager.java
de.skubware.opentraining.activity.start_training.SwipeDismissListViewTouchListener.java
de.skubware.opentraining.activity.start_training.SwipeDismissTouchListener.java
de.skubware.opentraining.activity.start_training.TrainingEntryListAdapter.java
de.skubware.opentraining.basic.ActivationLevel.java
de.skubware.opentraining.basic.ExerciseTag.java
de.skubware.opentraining.basic.ExerciseType.java
de.skubware.opentraining.basic.FSet.java
de.skubware.opentraining.basic.FitnessExercise.java
de.skubware.opentraining.basic.IExercise.java
de.skubware.opentraining.basic.License.java
de.skubware.opentraining.basic.Muscle.java
de.skubware.opentraining.basic.SportsEquipment.java
de.skubware.opentraining.basic.TrainingEntry.java
de.skubware.opentraining.basic.Translatable.java
de.skubware.opentraining.basic.Workout.java
de.skubware.opentraining.db.Cache.java
de.skubware.opentraining.db.DataHelper.java
de.skubware.opentraining.db.DataProvider.java
de.skubware.opentraining.db.IDataProvider.java
de.skubware.opentraining.db.parser.AbstractJSONParser.java
de.skubware.opentraining.db.parser.ExerciseTagJSONParser.java
de.skubware.opentraining.db.parser.ExerciseTypeXMLParser.java
de.skubware.opentraining.db.parser.IParser.java
de.skubware.opentraining.db.parser.MuscleJSONParser.java
de.skubware.opentraining.db.parser.SportsEquipmentJSONParser.java
de.skubware.opentraining.db.parser.WorkoutXMLParser.java
de.skubware.opentraining.db.parser.XMLSaver.java
de.skubware.opentraining.db.rest.ExerciseImageGSONSerializer.java
de.skubware.opentraining.db.rest.ExerciseTypeGSONSerializer.java
de.skubware.opentraining.db.rest.LanguageGSONDeserializer.java
de.skubware.opentraining.db.rest.MuscleGSONDeserializer.java
de.skubware.opentraining.db.rest.ServerModel.java
de.skubware.opentraining.db.rest.SportsEquipmentGSONDeserializer.java
de.skubware.opentraining.exporter.HTMLExporter.java
de.skubware.opentraining.exporter.LaTeXExporter.java
de.skubware.opentraining.exporter.WorkoutExporter.java