Search in sources :

Example 11 with RSlider

use of com.cpjd.roblu.models.metrics.RSlider 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)

Aggregations

RCheckbox (com.cpjd.roblu.models.metrics.RCheckbox)11 RChooser (com.cpjd.roblu.models.metrics.RChooser)11 RCounter (com.cpjd.roblu.models.metrics.RCounter)11 RSlider (com.cpjd.roblu.models.metrics.RSlider)11 RStopwatch (com.cpjd.roblu.models.metrics.RStopwatch)10 RBoolean (com.cpjd.roblu.models.metrics.RBoolean)9 RMetric (com.cpjd.roblu.models.metrics.RMetric)8 RTextfield (com.cpjd.roblu.models.metrics.RTextfield)8 RCalculation (com.cpjd.roblu.models.metrics.RCalculation)7 RGallery (com.cpjd.roblu.models.metrics.RGallery)5 LinkedHashMap (java.util.LinkedHashMap)5 RTab (com.cpjd.roblu.models.RTab)4 RDivider (com.cpjd.roblu.models.metrics.RDivider)4 ArrayList (java.util.ArrayList)4 RFieldData (com.cpjd.roblu.models.metrics.RFieldData)3 TextInputLayout (android.support.design.widget.TextInputLayout)2 View (android.view.View)2 RelativeLayout (android.widget.RelativeLayout)2 TextView (android.widget.TextView)2 IO (com.cpjd.roblu.io.IO)2