Search in sources :

Example 11 with RTextfield

use of com.cpjd.roblu.models.metrics.RTextfield in project Roblu by wdavies973.

the class CheckoutEncoder method encodeCheckout.

/**
 * This method will encode a checkout with as little overhead as possible (as opposed to JSON
 * serialization). This method is used for QR serialization to minimize the data transfer, since
 * compression isn't supported well by QR. This could be expanded for the whole project, but isn't really versatile enough yet.
 * @return The encoded string
 */
public String encodeCheckout(String nameTag, RCheckout checkout) {
    StringBuilder builder = new StringBuilder();
    // Checkout components
    builder.append(checkout.getID()).append("\n");
    builder.append(nameTag).append("\n");
    // Team meta
    builder.append(checkout.getTeam().getID()).append("\n");
    builder.append(checkout.getTeam().getLastEdit()).append("\n");
    // Tabs!
    for (RTab tab : checkout.getTeam().getTabs()) {
        builder.append("TAB").append(tab.getTitle()).append("\n");
        builder.append(tab.isWon()).append("\n");
        // Edits
        builder.append("EDITS");
        if (tab.getEdits() != null) {
            for (Object o : tab.getEdits().keySet()) {
                builder.append(",");
                if (o.toString().equals(""))
                    builder.append("Unknown");
                else
                    builder.append(o.toString());
                // EDITS,will:120391823,john,12039123
                builder.append(",").append(tab.getEdits().get(o.toString()));
            }
        }
        builder.append("\n");
        // -RDivider and RCalculation don't need to be encoded since they don't contain any user information
        for (RMetric metric : tab.getMetrics()) {
            builder.append(getMetricType(metric)).append(DELIMITER).append(metric.getID()).append(DELIMITER).append(metric.getTitle()).append(DELIMITER).append(metric.isModified()).append(DELIMITER);
            if (metric instanceof RBoolean)
                builder.append(((RBoolean) metric).isValue());
            else if (metric instanceof RCheckbox) {
                if (((RCheckbox) metric).getValues() != null) {
                    for (Object o : ((RCheckbox) metric).getValues().keySet()) {
                        // :(title,value):(title,value):
                        builder.append("(").append(o.toString()).append(",").append(((RCheckbox) metric).getValues().get(o.toString())).append(")").append(DELIMITER);
                    }
                }
            } else if (metric instanceof RChooser) {
                builder.append(((RChooser) metric).getSelectedIndex()).append(DELIMITER);
                if (((RChooser) metric).getValues() != null) {
                    for (String s : ((RChooser) metric).getValues()) {
                        // :1:option:option:option:
                        builder.append(s).append(DELIMITER);
                    }
                }
            } else if (metric instanceof RCounter)
                builder.append(((RCounter) metric).isVerboseInput()).append(DELIMITER).append(((RCounter) metric).getValue()).append(DELIMITER).append(((RCounter) metric).getIncrement());
            else if (metric instanceof RSlider)
                builder.append(((RSlider) metric).getValue()).append(DELIMITER).append(((RSlider) metric).getMin()).append(DELIMITER).append(((RSlider) metric).getMax());
            else if (metric instanceof RStopwatch) {
                builder.append(((RStopwatch) metric).getTime()).append(DELIMITER);
                if (((RStopwatch) metric).getTimes() != null) {
                    for (Double t : ((RStopwatch) metric).getTimes()) {
                        // :curr:1:2:3:
                        builder.append(t).append(DELIMITER);
                    }
                }
            } else if (metric instanceof RTextfield)
                builder.append(((RTextfield) metric).getText());
            builder.append("\n");
        }
    }
    return builder.toString();
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RChooser(com.cpjd.roblu.models.metrics.RChooser) RTab(com.cpjd.roblu.models.RTab) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RMetric(com.cpjd.roblu.models.metrics.RMetric) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Example 12 with RTextfield

use of com.cpjd.roblu.models.metrics.RTextfield in project Roblu by wdavies973.

the class Utils method createEmpty.

/**
 * Creates an empty form for an event (not technically empty).
 *
 * Makes sure that nothing is null and that we have the required
 * team name and team number fields
 * @return creates an empty RForm
 */
public static RForm createEmpty() {
    ArrayList<RMetric> pit = new ArrayList<>();
    ArrayList<RMetric> matches = new ArrayList<>();
    RTextfield name = new RTextfield(0, "Team name", false, true, "");
    RTextfield number = new RTextfield(1, "Team number", true, true, "");
    pit.add(name);
    pit.add(number);
    return new RForm(pit, matches);
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric)

Aggregations

RTextfield (com.cpjd.roblu.models.metrics.RTextfield)12 RMetric (com.cpjd.roblu.models.metrics.RMetric)10 RCounter (com.cpjd.roblu.models.metrics.RCounter)9 RBoolean (com.cpjd.roblu.models.metrics.RBoolean)8 RCheckbox (com.cpjd.roblu.models.metrics.RCheckbox)8 RChooser (com.cpjd.roblu.models.metrics.RChooser)8 RSlider (com.cpjd.roblu.models.metrics.RSlider)8 RStopwatch (com.cpjd.roblu.models.metrics.RStopwatch)8 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 RForm (com.cpjd.roblu.models.RForm)4 RTab (com.cpjd.roblu.models.RTab)4 RCalculation (com.cpjd.roblu.models.metrics.RCalculation)4 RFieldData (com.cpjd.roblu.models.metrics.RFieldData)4 RGallery (com.cpjd.roblu.models.metrics.RGallery)4 IO (com.cpjd.roblu.io.IO)3 RDivider (com.cpjd.roblu.models.metrics.RDivider)3 Toolbar (android.support.v7.widget.Toolbar)2 TextView (android.widget.TextView)2 RTeam (com.cpjd.roblu.models.RTeam)2