Search in sources :

Example 1 with RTextfield

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

the class MetricEditor method onItemSelected.

/**
 * Called when the user selects a metric type
 * @param adapterView the adapter containing all the choices
 * @param view the view that was tapped
 * @param i the position of the view
 * @param l id of the view
 */
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
    ((TextView) adapterView.getChildAt(0)).setTextColor(rui.getText());
    /*
         * User selected a new metric, let's create it
         */
    String stringOfSelected = METRIC_TYPES[i];
    if (stringOfSelected.equals(METRIC_TYPES[0])) {
        metric = new RBoolean(0, "Boolean", false);
    } else if (stringOfSelected.equals(METRIC_TYPES[1])) {
        metric = new RCounter(0, "Counter", 1, 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[2])) {
        metric = new RSlider(0, "Slider", 0, 100, 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[3])) {
        metric = new RChooser(0, "Chooser", null, 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[4])) {
        metric = new RCheckbox(0, "Checkbox", null);
    } else if (stringOfSelected.equals(METRIC_TYPES[5])) {
        metric = new RStopwatch(0, "Stopwatch", 0);
    } else if (stringOfSelected.equals(METRIC_TYPES[6])) {
        metric = new RTextfield(0, "Text field", "");
    } else if (stringOfSelected.equals(METRIC_TYPES[7])) {
        metric = new RGallery(0, "Gallery");
    } else if (stringOfSelected.equalsIgnoreCase(METRIC_TYPES[8])) {
        metric = new RDivider(0, "Divider");
    } else if (stringOfSelected.equals(METRIC_TYPES[9])) {
        metric = new RFieldDiagram(0, R.drawable.field2018, null);
    } else if (stringOfSelected.equals(METRIC_TYPES[10])) {
        metric = new RCalculation(0, "Custom calculation");
    } else if (stringOfSelected.equals(METRIC_TYPES[11])) {
        metric = new RFieldData(0, "Match data");
    }
    metric.setModified(true);
    addMetricPreviewToToolbar();
    buildConfigLayout();
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RDivider(com.cpjd.roblu.models.metrics.RDivider) RChooser(com.cpjd.roblu.models.metrics.RChooser) RGallery(com.cpjd.roblu.models.metrics.RGallery) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RFieldDiagram(com.cpjd.roblu.models.metrics.RFieldDiagram) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) TextView(android.widget.TextView) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Example 2 with RTextfield

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

the class Match method changeMade.

/**
 * This method is called when a change is made to a metric
 * @param metric the modified metric
 */
@Override
public void changeMade(RMetric metric) {
    /*
         * Notify any calculation metrics that a change was made
         */
    for (int i = 0; i < layout.getChildCount(); i++) {
        CardView cv = (CardView) layout.getChildAt(i);
        if (cv.getTag() != null && cv.getTag().toString().split(":")[0].equals("CALC")) {
            // We've discovered a calculation metric, we have access to the ID, so acquire a new copy of the view
            int ID = Integer.parseInt(cv.getTag().toString().split(":")[1]);
            for (RMetric m : TeamViewer.team.getTabs().get(position).getMetrics()) {
                if (m.getID() == ID) {
                    // Get the calculation
                    String value = m.getTitle() + "\nValue: " + ((RCalculation) m).getValue(TeamViewer.team.getTabs().get(position).getMetrics());
                    // Set the text
                    RelativeLayout rl = (RelativeLayout) cv.getChildAt(0);
                    TextView tv = (TextView) rl.getChildAt(0);
                    tv.setText(value);
                    break;
                }
            }
        }
    }
    // set the metric as modified - this is a critical line, otherwise scouting data will get deleted
    metric.setModified(true);
    /*
         * Check the team name and team number metrics to see if the action bar needs to be updated
         */
    // since team name and  team number are updated from the team model
    boolean init = false;
    // without the user's control, make sure not to update team's timestamp if it's only the team name or number metric
    if (metric instanceof RTextfield) {
        if (((RTextfield) metric).isOneLine() && ((RTextfield) metric).isNumericalOnly() && !((RTextfield) metric).getText().equals("")) {
            TeamViewer.team.setNumber(Integer.parseInt(((RTextfield) metric).getText()));
            ((TeamViewer) getActivity()).setActionBarSubtitle("#" + TeamViewer.team.getNumber());
            init = true;
        }
        if (((RTextfield) metric).isOneLine() && !((RTextfield) metric).isNumericalOnly() && !((RTextfield) metric).getText().equals("")) {
            TeamViewer.team.setName(((RTextfield) metric).getText());
            ((TeamViewer) getActivity()).setActionBarTitle(TeamViewer.team.getName());
            init = true;
        }
    }
    if (!init) {
        TeamViewer.team.setLastEdit(System.currentTimeMillis());
        // Add local device to edit history list
        if (event.isCloudEnabled()) {
            LinkedHashMap<String, Long> edits = TeamViewer.team.getTabs().get(position).getEdits();
            if (edits == null)
                TeamViewer.team.getTabs().get(position).setEdits(new LinkedHashMap<String, Long>());
            TeamViewer.team.getTabs().get(position).getEdits().put("me", System.currentTimeMillis());
        }
    }
    // save the team
    new IO(view.getContext()).saveTeam(event.getID(), TeamViewer.team);
}
Also used : TeamViewer(com.cpjd.roblu.ui.team.TeamViewer) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) IO(com.cpjd.roblu.io.IO) CardView(android.support.v7.widget.CardView) RMetric(com.cpjd.roblu.models.metrics.RMetric) LinkedHashMap(java.util.LinkedHashMap) RelativeLayout(android.widget.RelativeLayout) TextView(android.widget.TextView)

Example 3 with RTextfield

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

the class UnpackTBAEvent method doInBackground.

protected Void doInBackground(Void... params) {
    /*
         * No teams were contained within the event, so exit, nothing here is relevant
         * to a TBA event that doesn't contain any team models
         */
    if (event.teams == null || event.teams.length == 0)
        return null;
    /*
         * Create an array of team models from the ones contained in the event
         */
    ArrayList<RTeam> teams = new ArrayList<>();
    for (int i = 0; i < event.teams.length; i++) {
        // i can be used as the ID because we are creating a fresh event, io.getNewTeamID is irrelevant
        teams.add(new RTeam(event.teams[i].nickname, (int) event.teams[i].team_number, i));
    }
    /*
         * Sort the matches in the event
         */
    Collections.sort(Arrays.asList(event.matches));
    /*
         * Add the matches to the respective team models
         */
    IO io = new IO(activityWeakReference.get());
    RForm form = io.loadForm(eventID);
    int result;
    for (RTeam t : teams) {
        t.verify(form);
        for (int j = 0; j < event.matches.length; j++) {
            result = event.matches[j].doesMatchContainTeam(t.getNumber());
            if (result > 0) {
                String name = "Match";
                // process the correct match name
                switch(event.matches[j].comp_level) {
                    case "qm":
                        name = "Quals " + event.matches[j].match_number;
                        break;
                    case "qf":
                        name = "Quarters " + event.matches[j].set_number + " Match " + event.matches[j].match_number;
                        break;
                    case "sf":
                        name = "Semis " + event.matches[j].set_number + " Match " + event.matches[j].match_number;
                        break;
                    case "f":
                        name = "Finals " + event.matches[j].match_number;
                }
                boolean isRed = result == com.cpjd.main.Constants.CONTAINS_TEAM_RED;
                // add the match to the team, make sure to multiple the Event model's matches times by 1000 (seconds to milliseconds, Roblu works with milliseconds!)
                RTab tab = new RTab(t.getNumber(), name, Utils.duplicateRMetricArray(form.getMatch()), isRed, event.matches[j].isOnWinningAlliance(t.getNumber()), event.matches[j].time * 1000);
                // set the match position, if possible
                tab.setAlliancePosition(event.matches[j].getTeamPosition(t.getNumber()));
                // Check for FieldData metrics
                if (tab.getMetrics() != null) {
                    for (RMetric metric : tab.getMetrics()) {
                        if (metric instanceof RFieldData) {
                            if (((RFieldData) metric).getData() == null)
                                ((RFieldData) metric).setData(new LinkedHashMap<String, ArrayList<RMetric>>());
                            for (int i = 0; i < event.matches[j].scorableItems.length; i++) {
                                Log.d("RBS", "Metric name: " + event.matches[j].scorableItems[i] + ", " + "Red value: " + event.matches[j].redValues[i] + ", Blue value: " + event.matches[j].blueValues[i]);
                                ArrayList<RMetric> metrics = new ArrayList<>();
                                try {
                                    metrics.add(new RCounter(0, "", 0, Double.parseDouble(event.matches[j].redValues[i])));
                                } catch (Exception e) {
                                    metrics.add(new RTextfield(0, "", (event.matches[j].redValues[i])));
                                }
                                try {
                                    metrics.add(new RCounter(0, "", 0, Double.parseDouble(event.matches[j].blueValues[i])));
                                } catch (Exception e) {
                                    metrics.add(new RTextfield(0, "", (event.matches[j].blueValues[i])));
                                }
                                if (event.matches[j].scorableItems[i] != null && metrics.size() > 0)
                                    ((RFieldData) metric).getData().put(event.matches[j].scorableItems[i], metrics);
                            }
                        }
                    }
                }
                t.addTab(tab);
            }
        }
        /*
             * This is where the merge decision comes into play
             */
        if (randomize) {
            t.setLastEdit(System.currentTimeMillis());
            Utils.randomizeTeamMetrics(t.getTabs());
        }
        io.saveTeam(eventID, t);
    }
    return null;
}
Also used : RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) IO(com.cpjd.roblu.io.IO) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) ArrayList(java.util.ArrayList) RFieldData(com.cpjd.roblu.models.metrics.RFieldData) RMetric(com.cpjd.roblu.models.metrics.RMetric) LinkedHashMap(java.util.LinkedHashMap) RForm(com.cpjd.roblu.models.RForm) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Example 4 with RTextfield

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

the class CheckoutEncoder method decodeCheckout.

/**
 * Decodes a checkout encoded in the CheckoutEncoder format
 * @param string the string to deserialize
 * @return an instantiated checkout from the string
 */
public RCheckout decodeCheckout(String string) {
    try {
        String[] lines = string.split("\n");
        for (String s : lines) {
            Log.d("RBS", "Line: " + s);
        }
        // Meta
        RCheckout checkout = new RCheckout();
        checkout.setID(Integer.parseInt(lines[0]));
        checkout.setNameTag(lines[1]);
        RTeam team = new RTeam();
        team.setID(Integer.parseInt(lines[2]));
        team.setLastEdit(Long.parseLong(lines[3]));
        team.setTabs(new ArrayList<RTab>());
        // Tabs
        for (int i = 0; i < lines.length; i++) {
            if (!lines[i].startsWith("TAB"))
                continue;
            // Tab meta
            RTab tab = new RTab();
            tab.setTitle(lines[i].substring(3));
            tab.setWon(Boolean.parseBoolean(lines[i + 1]));
            tab.setMetrics(new ArrayList<RMetric>());
            String[] tokens = lines[i + 2].split(",");
            LinkedHashMap<String, Long> edits = new LinkedHashMap<>();
            for (int k = 1; k < tokens.length; k++) {
                edits.put(tokens[1], Long.parseLong(tokens[2]));
            }
            tab.setEdits(edits);
            // Metrics
            for (int k = i + 1; k < lines.length; k++) {
                if (lines[k].startsWith("TAB"))
                    break;
                if (lines[i].startsWith("null"))
                    continue;
                String[] mTokens = lines[k].split(String.valueOf(DELIMITER));
                RMetric metric = null;
                switch(mTokens[0]) {
                    case // boolean
                    "B":
                        metric = new RBoolean();
                        ((RBoolean) metric).setValue(Boolean.parseBoolean(mTokens[4]));
                        break;
                    case "CH":
                        {
                            // checkbox
                            metric = new RCheckbox();
                            LinkedHashMap<String, Boolean> values = new LinkedHashMap<>();
                            for (int l = 4; l < mTokens.length; l++) {
                                values.put(mTokens[l].split(",")[0].substring(1), Boolean.parseBoolean(mTokens[l].split(",")[1].replace(")", "")));
                            }
                            ((RCheckbox) metric).setValues(values);
                            break;
                        }
                    case "CO":
                        {
                            // chooser
                            metric = new RChooser();
                            ((RChooser) metric).setSelectedIndex(Integer.parseInt(mTokens[4]));
                            // the amount of values, with the header info removed
                            String[] values = new String[mTokens.length - 6];
                            for (int l = 5; l < mTokens.length - 1; l++) {
                                if (mTokens[l] != null && !mTokens[l].equals(""))
                                    values[l - 5] = mTokens[l];
                            }
                            ((RChooser) metric).setValues(values);
                            break;
                        }
                    case // counter
                    "C":
                        metric = new RCounter();
                        ((RCounter) metric).setVerboseInput(Boolean.parseBoolean(mTokens[4]));
                        ((RCounter) metric).setValue(Double.parseDouble(mTokens[5]));
                        ((RCounter) metric).setIncrement(Double.parseDouble(mTokens[6]));
                        break;
                    case // slider
                    "S":
                        metric = new RSlider();
                        ((RSlider) metric).setValue(Integer.parseInt(mTokens[4]));
                        ((RSlider) metric).setMin(Integer.parseInt(mTokens[5]));
                        ((RSlider) metric).setMax(Integer.parseInt(mTokens[6]));
                        break;
                    case // stopwatch
                    "ST":
                        metric = new RStopwatch();
                        ((RStopwatch) metric).setTime(Double.parseDouble(mTokens[4]));
                        ((RStopwatch) metric).setTimes(new ArrayList<Double>());
                        for (int l = 5; l < mTokens.length; l++) {
                            if (!mTokens[l].equals(""))
                                ((RStopwatch) metric).getTimes().add(Double.parseDouble(mTokens[5]));
                        }
                        break;
                    case // textfield
                    "T":
                        metric = new RTextfield();
                        ((RTextfield) metric).setText((mTokens[4]));
                        break;
                }
                if (metric != null) {
                    metric.setID(Integer.parseInt(mTokens[1]));
                    metric.setTitle(mTokens[2]);
                    metric.setModified(Boolean.parseBoolean(mTokens[3]));
                    tab.getMetrics().add(metric);
                    // Adding metric
                    Log.d("RBS", "Adding metric " + metric.toString());
                }
            }
            team.getTabs().add(tab);
        }
        checkout.setTeam(team);
        return checkout;
    } catch (Exception e) {
        e.printStackTrace();
        Log.d("RBS", "An error occurred while decoding a checkout. " + e.getMessage());
        return null;
    }
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RChooser(com.cpjd.roblu.models.metrics.RChooser) RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) RTextfield(com.cpjd.roblu.models.metrics.RTextfield) RMetric(com.cpjd.roblu.models.metrics.RMetric) LinkedHashMap(java.util.LinkedHashMap) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) RCheckout(com.cpjd.roblu.models.RCheckout) RCounter(com.cpjd.roblu.models.metrics.RCounter)

Example 5 with RTextfield

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

the class Utils method randomizeTeamMetrics.

/**
 * This code will randomize an event with random metric data for the purposes of show casing an app
 * or testing
 */
public static void randomizeTeamMetrics(ArrayList<RTab> tabs) {
    Random r = new Random();
    if (tabs != null) {
        for (RTab tab : tabs) {
            for (RMetric metric : tab.getMetrics()) {
                metric.setModified(true);
                if (metric instanceof RSlider) {
                    ((RSlider) metric).setMax(100);
                    ((RSlider) metric).setValue(r.nextInt(100));
                } else if (metric instanceof RCounter) {
                    ((RCounter) metric).setValue(r.nextDouble() * 100);
                } else if (metric instanceof RStopwatch) {
                    ((RStopwatch) metric).setTime(r.nextDouble() * 10);
                    ((RStopwatch) metric).setTimes(new ArrayList<Double>());
                    for (int i = 0; i < r.nextInt(5); i++) {
                        ((RStopwatch) metric).getTimes().add(Utils.round(r.nextDouble() * 8.2, 2));
                    }
                } else if (metric instanceof RBoolean) {
                    ((RBoolean) metric).setValue(r.nextDouble() <= 0.5);
                } else if (metric instanceof RCheckbox) {
                    for (Object o : ((RCheckbox) metric).getValues().keySet()) {
                        ((RCheckbox) metric).getValues().put(o.toString(), r.nextDouble() <= 0.50);
                    }
                } else if (metric instanceof RChooser) {
                    ((RChooser) metric).setSelectedIndex(r.nextInt(((RChooser) metric).getValues().length - 1));
                } else if (metric instanceof RTextfield) {
                    if (!((RTextfield) metric).isOneLine())
                        ((RTextfield) metric).setText("RTextfield has been randomized to: " + getSaltString());
                }
            }
        }
    }
}
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) Point(android.graphics.Point) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) Random(java.util.Random) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) RCounter(com.cpjd.roblu.models.metrics.RCounter)

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