Search in sources :

Example 6 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class TBAEventSelector method manualAdd.

/**
 * This is a dark ages method, it's for users who want to type in the event code manually
 */
private void manualAdd() {
    AlertDialog.Builder builder = new AlertDialog.Builder(TBAEventSelector.this);
    builder.setTitle("Add event manually");
    LinearLayout layout = new LinearLayout(TBAEventSelector.this);
    layout.setOrientation(LinearLayout.VERTICAL);
    final EditText input = new EditText(TBAEventSelector.this);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setHint("year,event code");
    layout.addView(input);
    builder.setView(layout);
    builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            try {
                Utils.showSnackbar(findViewById(R.id.activity_apievent_select), getApplicationContext(), "Downloading event...", false, new IO(getApplicationContext()).loadSettings().getRui().getPrimaryColor());
                new ImportEvent(TBAEventSelector.this, input.getText().toString().replaceFirst(",", "")).start();
            } catch (Exception e) {
                e.printStackTrace();
                Utils.showSnackbar(findViewById(R.id.activity_apievent_select), getApplicationContext(), "Invalid key: " + input.getText().toString() + ".", true, 0);
            }
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) IO(com.cpjd.roblu.io.IO) LinearLayout(android.widget.LinearLayout) ImportEvent(com.cpjd.roblu.tba.ImportEvent)

Example 7 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class TBAEventSelector method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_apievent_select);
    teamNumber = new IO(getApplicationContext()).loadSettings().getTeamNumber();
    /*
         * Setup UI
         */
    // Setup
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Select an event");
    }
    // Progress bar
    bar = findViewById(R.id.progress_bar);
    bar.setVisibility(View.GONE);
    // Recycler view
    rv = findViewById(R.id.events_recycler);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    rv.setLayoutManager(linearLayoutManager);
    ((SimpleItemAnimator) rv.getItemAnimator()).setSupportsChangeAnimations(false);
    // Setup the tbaEventAdapter
    tbaEventAdapter = new TBAEventAdapter(this, this);
    rv.setAdapter(tbaEventAdapter);
    // Setup the gesture listener
    ItemTouchHelper.Callback callback = new TutorialsRecyclerTouchHelper();
    ItemTouchHelper helper = new ItemTouchHelper(callback);
    helper.attachToRecyclerView(rv);
    /*
         * Create the "My Events / All Events" chooser
         */
    Spinner showTeam = findViewById(R.id.show_team);
    ArrayAdapter<String> sAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, new String[] { "My events", "All events" });
    sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    showTeam.setAdapter(sAdapter);
    showTeam.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
            onlyShowMyEvents = parent.getItemAtPosition(position).toString().equals("My events");
            rv.setVisibility(View.INVISIBLE);
            bar.setVisibility(View.VISIBLE);
            if (tbaEventAdapter.getEvents() != null)
                tbaEventAdapter.getEvents().clear();
            tbaEventAdapter.notifyDataSetChanged();
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.execute();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    // If no team number is found, default to "All events"
    if (new IO(getApplicationContext()).loadSettings().getTeamNumber() == 0)
        showTeam.setSelection(1);
    /*
         * Setup the years spinner
         */
    Spinner yearsSpinner = findViewById(R.id.spinner);
    selectedYear = Calendar.getInstance().get(Calendar.YEAR);
    String[] years = new String[selectedYear - 1991];
    for (int i = years.length - 1; i >= 0; i--) years[Math.abs(i - years.length + 1)] = String.valueOf(1992 + i);
    final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, years);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    yearsSpinner.setAdapter(adapter);
    yearsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            selectedYear = Integer.parseInt(adapterView.getItemAtPosition(i).toString());
            rv.setVisibility(View.INVISIBLE);
            bar.setVisibility(View.VISIBLE);
            if (tbaEventAdapter.getEvents() != null)
                tbaEventAdapter.getEvents().clear();
            tbaEventAdapter.notifyDataSetChanged();
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.execute();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
    /*
         * Setup the search view
         */
    searchView = findViewById(R.id.search_view);
    searchView.setHintTextColor(Color.BLACK);
    searchView.setHint("Search events");
    searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {

        @Override
        public void onSearchViewShown() {
        }

        @Override
        public void onSearchViewClosed() {
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.setEvents(events);
            task.execute();
        }
    });
    searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            searchView.closeSearch();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            TBALoadEventsTask task = new TBALoadEventsTask(bar, rv, tbaEventAdapter, TBAEventSelector.this, teamNumber, selectedYear, onlyShowMyEvents);
            task.setEvents(events);
            task.setQuery(newText);
            task.execute();
            return true;
        }
    });
    // Sync UI with user preferences
    new UIHandler(this, toolbar).update();
}
Also used : TutorialsRecyclerTouchHelper(com.cpjd.roblu.ui.tutorials.TutorialsRecyclerTouchHelper) Spinner(android.widget.Spinner) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) TBALoadEventsTask(com.cpjd.roblu.tba.TBALoadEventsTask) Toolbar(android.support.v7.widget.Toolbar) SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) UIHandler(com.cpjd.roblu.ui.UIHandler) IO(com.cpjd.roblu.io.IO) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) MaterialSearchView(com.miguelcatalan.materialsearchview.MaterialSearchView) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 8 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class TeamViewer method onPageSelected.

/**
 * Called when a new page is selected, some UI changes need to be made
 * (such as toolbar color change)
 * @param page the page index to switch to
 */
@Override
public void onPageSelected(int page) {
    if (page < 3)
        setColorScheme(rui.getPrimaryColor(), RUI.darker(rui.getPrimaryColor(), 0.85f));
    else {
        if (tabAdapter.isPageRed(page))
            setColorScheme(ContextCompat.getColor(getApplicationContext(), R.color.red), ContextCompat.getColor(getApplicationContext(), R.color.darkRed));
        else
            setColorScheme(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryDark));
    }
    TeamViewer.team.setPage(page);
    new IO(getApplicationContext()).saveTeam(event.getID(), TeamViewer.team);
}
Also used : IO(com.cpjd.roblu.io.IO)

Example 9 with IO

use of com.cpjd.roblu.io.IO 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 10 with IO

use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.

the class Overview method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.overview_tab, container, false);
    Bundle bundle = this.getArguments();
    layout = view.findViewById(R.id.overview_layout);
    REvent event = (REvent) getArguments().getSerializable("event");
    RTeam team = new IO(getActivity()).loadTeam(event.getID(), TeamViewer.team.getID());
    rMetricToUI = new RMetricToUI(getActivity(), new IO(getActivity()).loadSettings().getRui(), true);
    try {
        /*
         * Do statistics generation, this will generate graphs for certain metrics
         */
        // Stores pie chart values, with the sub linked hash map <item,occurrences>, this will need to be processed later into a percent
        LinkedHashMap<String, LinkedHashMap<String, Double>> pieValues = new LinkedHashMap<>();
        // Stores line chart values, with the sub linked hash map <matchName,value>
        LinkedHashMap<String, LinkedHashMap<String, Double>> lineValues = new LinkedHashMap<>();
        // This isn't directly related, more of a side project
        ArrayList<RGallery> galleries = new ArrayList<>();
        for (RTab tab : team.getTabs()) {
            // Rule out disallowed tabs
            if (tab.getTitle().equalsIgnoreCase("PIT"))
                continue;
            // Start processing metrics
            for (RMetric metric : tab.getMetrics()) {
                if (metric instanceof RGallery) {
                    galleries.add((RGallery) metric);
                }
                if (!metric.isModified())
                    continue;
                // Pie graph metrics, scan these here
                if (metric instanceof RBoolean) {
                    LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
                    if (temp == null)
                        temp = new LinkedHashMap<>();
                    String key = ((RBoolean) metric).isValue() ? "Yes" : "No";
                    if (temp.get(key) == null)
                        temp.put(key, 1.0);
                    else
                        temp.put(key, temp.get(key) + 1);
                    pieValues.put(metric.getTitle(), temp);
                } else if (metric instanceof RCheckbox) {
                    if (((RCheckbox) metric).getValues() != null) {
                        for (Object key : ((RCheckbox) metric).getValues().keySet()) {
                            LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
                            if (temp == null)
                                temp = new LinkedHashMap<>();
                            if (temp.get(key.toString()) == null)
                                temp.put(key.toString(), 1.0);
                            else
                                temp.put(key.toString(), temp.get(key.toString()) + 1);
                            pieValues.put(metric.getTitle(), temp);
                        }
                    }
                } else if (metric instanceof RChooser) {
                    LinkedHashMap<String, Double> temp = pieValues.get(metric.getTitle());
                    if (temp == null)
                        temp = new LinkedHashMap<>();
                    if (temp.get(metric.toString()) == null)
                        temp.put(metric.toString(), 1.0);
                    else
                        temp.put(metric.toString(), temp.get(metric.toString()) + 1);
                    pieValues.put(metric.getTitle(), temp);
                } else // Line chart metrics
                if (metric instanceof RCounter || metric instanceof RSlider || metric instanceof RStopwatch || metric instanceof RCalculation) {
                    LinkedHashMap<String, Double> temp = lineValues.get(metric.getTitle());
                    if (temp == null)
                        temp = new LinkedHashMap<>();
                    temp.put(tab.getTitle(), Double.parseDouble(metric.toString()));
                    lineValues.put(metric.getTitle(), temp);
                }
            }
        }
        // Add the divider metrics by position, -1 if no metric after it, or at the end
        ArrayList<RDivider> addedDividers = new ArrayList<>();
        /*
         * Add the charts!
         */
        for (Object key : lineValues.keySet()) {
            if (lineValues.get(key.toString()).size() >= 2) {
                loop: for (RTab tab : team.getTabs()) {
                    for (int i = 0; i < tab.getMetrics().size(); i++) {
                        if (tab.getMetrics().get(i).getTitle().equals(key.toString())) {
                            // See if there is a RDivider hiding above this metric
                            for (int j = i; j >= 0; j--) {
                                if (tab.getMetrics().get(j) instanceof RDivider && !addedDividers.contains(tab.getMetrics().get(j))) {
                                    layout.addView(rMetricToUI.getDivider((RDivider) tab.getMetrics().get(j)));
                                    addedDividers.add((RDivider) tab.getMetrics().get(j));
                                    break loop;
                                }
                            }
                        }
                    }
                }
                layout.addView(rMetricToUI.generateLineChart(key.toString(), lineValues.get(key.toString())));
            }
        }
        // Process the pie charts
        for (Object key : pieValues.keySet()) {
            if (pieValues.get(key.toString()).size() <= 1)
                continue;
            int metricID = 0;
            loop: for (RTab tab : team.getTabs()) {
                for (int i = 0; i < tab.getMetrics().size(); i++) {
                    if (tab.getMetrics().get(i).getTitle().equals(key.toString())) {
                        metricID = tab.getMetrics().get(i).getID();
                        // See if there is a RDivider hiding above this metric
                        for (int j = i; j >= 0; j--) {
                            if (tab.getMetrics().get(j) instanceof RDivider && !addedDividers.contains(tab.getMetrics().get(j))) {
                                layout.addView(rMetricToUI.getDivider((RDivider) tab.getMetrics().get(j)));
                                addedDividers.add((RDivider) tab.getMetrics().get(j));
                                break loop;
                            }
                        }
                    }
                }
            }
            for (Object key2 : pieValues.get(key.toString()).keySet()) {
                if (numModified(team.getTabs(), metricID) != 0)
                    pieValues.get(key.toString()).put(key2.toString(), pieValues.get(key.toString()).get(key2.toString()) / (double) numModified(team.getTabs(), metricID));
            }
            layout.addView(rMetricToUI.generatePieChart(key.toString(), pieValues.get(key.toString())));
        }
        /*
         * Find the image with the most entropy, and add
         * it as the "featured" image
         */
        galleryLoop: for (int j = galleries.size() - 1; j >= 0; j--) {
            if (galleries.get(j).getImages() != null && galleries.get(j).getImages().size() > 0) {
                for (int i = galleries.get(j).getImages().size() - 1; i >= 0; i--) {
                    try {
                        layout.addView(rMetricToUI.getImageView("Featured image", BitmapFactory.decodeByteArray(galleries.get(j).getImages().get(i), 0, galleries.get(j).getImages().get(i).length)));
                        break galleryLoop;
                    } catch (Exception e) {
                        Log.d("RBS", "Failed to load featured image: " + e.getMessage());
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.d("RBS", "Failed to generate graphs for this team profile.");
    }
    /*
         * Attempt to download TBA info for this team
         */
    if (!team.hasTBAInfo()) {
        if (event.getKey() != null && event.getKey().length() >= 4)
            new TBATeamInfoTask(view.getContext(), team.getNumber(), event.getKey().substring(0, 4), this);
    } else {
        // TBA info card
        layout.addView(rMetricToUI.getInfoField("TBA.com information", TeamViewer.team.getTbaInfo(), TeamViewer.team.getWebsite(), TeamViewer.team.getNumber()), 0);
        if (TeamViewer.team.getImage() != null) {
            // Image view
            Bitmap bitmap = BitmapFactory.decodeByteArray(TeamViewer.team.getImage(), 0, TeamViewer.team.getImage().length);
            layout.addView(rMetricToUI.getImageView("Robot", bitmap));
        }
    }
    /*
         * Add UI cards to the layout
         */
    // "Other" card
    layout.addView(rMetricToUI.getInfoField("Other", "Last edited: " + Utils.convertTime(team.getLastEdit()) + "\nSize on disk: " + new IO(view.getContext()).getTeamSize(bundle.getInt("eventID"), team.getID()) + " KB", "", 0));
    return view;
}
Also used : RBoolean(com.cpjd.roblu.models.metrics.RBoolean) RDivider(com.cpjd.roblu.models.metrics.RDivider) RGallery(com.cpjd.roblu.models.metrics.RGallery) RTab(com.cpjd.roblu.models.RTab) ArrayList(java.util.ArrayList) RMetric(com.cpjd.roblu.models.metrics.RMetric) RCalculation(com.cpjd.roblu.models.metrics.RCalculation) LinkedHashMap(java.util.LinkedHashMap) Bitmap(android.graphics.Bitmap) RCheckbox(com.cpjd.roblu.models.metrics.RCheckbox) RSlider(com.cpjd.roblu.models.metrics.RSlider) REvent(com.cpjd.roblu.models.REvent) TBATeamInfoTask(com.cpjd.roblu.ui.team.TBATeamInfoTask) RChooser(com.cpjd.roblu.models.metrics.RChooser) RTeam(com.cpjd.roblu.models.RTeam) Bundle(android.os.Bundle) IO(com.cpjd.roblu.io.IO) View(android.view.View) RStopwatch(com.cpjd.roblu.models.metrics.RStopwatch) RCounter(com.cpjd.roblu.models.metrics.RCounter) RMetricToUI(com.cpjd.roblu.ui.forms.RMetricToUI)

Aggregations

IO (com.cpjd.roblu.io.IO)59 TextView (android.widget.TextView)18 Intent (android.content.Intent)15 View (android.view.View)14 ArrayList (java.util.ArrayList)13 REvent (com.cpjd.roblu.models.REvent)11 Toolbar (android.support.v7.widget.Toolbar)10 RForm (com.cpjd.roblu.models.RForm)10 RTeam (com.cpjd.roblu.models.RTeam)10 RUI (com.cpjd.roblu.models.RUI)10 RCheckout (com.cpjd.roblu.models.RCheckout)8 RTab (com.cpjd.roblu.models.RTab)8 RMetric (com.cpjd.roblu.models.metrics.RMetric)8 UIHandler (com.cpjd.roblu.ui.UIHandler)8 RecyclerView (android.support.v7.widget.RecyclerView)7 Dialog (android.app.Dialog)6 Bundle (android.os.Bundle)6 Button (android.widget.Button)6 RSettings (com.cpjd.roblu.models.RSettings)6 AlertDialog (android.app.AlertDialog)5