Search in sources :

Example 21 with IO

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

the class QrReader method onQRCodeRead.

// Called when a QR is decoded
// "text" : the text encoded in QR
// "points" : points where QR control points are placed in View
@Override
public void onQRCodeRead(final String text, PointF[] points) {
    if (syncedAlready)
        return;
    if (!syncedAlready) {
        syncedAlready = true;
    }
    Log.d("RBS", "QR Read: " + text);
    /*
             * Decompress and import the checkout
             */
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                /*
                     * Import the checkout!
                     */
                RCheckout checkout = new CheckoutEncoder().decodeCheckout(text);
                new SyncHelper(getApplicationContext(), event, SyncHelper.MODES.QR).mergeCheckout(checkout);
                // Flag for upload
                // reload the team after merge
                checkout.setTeam(new IO(getApplicationContext()).loadTeam(event.getID(), checkout.getTeam().getID()));
                new IO(getApplicationContext()).savePendingCheckout(checkout);
                Notify.notifyMerged(getApplicationContext(), event.getID(), checkout);
                // close QR scanner
                finish();
            } catch (Exception e) {
                Log.d("RBS", "Failed to import checkout from QR code: " + e.getMessage());
            }
        }
    }).start();
}
Also used : IO(com.cpjd.roblu.io.IO) SyncHelper(com.cpjd.roblu.sync.SyncHelper) RCheckout(com.cpjd.roblu.models.RCheckout)

Example 22 with IO

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

the class Utils method launchEventPickerWithExcludedEvent.

/**
 * For certain things, the user may need to select an event from a list of locally stored event,
 * this method does just that! The EventSelectListener method will trigger when an event is successfully
 * selected.
 * @param context context reference
 * @param listener listener to respond to events
 * @return true if some events exist
 */
public static boolean launchEventPickerWithExcludedEvent(Context context, int eventIDExcluded, final EventDrawerManager.EventSelectListener listener) {
    final Dialog d = new Dialog(context);
    d.setTitle("Pick event:");
    d.setContentView(R.layout.event_import_dialog);
    final Spinner spinner = d.findViewById(R.id.type);
    String[] values;
    final REvent[] events = new IO(context).loadEvents();
    if (events == null || events.length == 0)
        return false;
    final ArrayList<REvent> eventArrayList = new ArrayList<>();
    for (REvent event : events) {
        if (event.getID() != eventIDExcluded)
            eventArrayList.add(event);
    }
    values = new String[eventArrayList.size()];
    for (int i = 0; i < values.length; i++) {
        values[i] = eventArrayList.get(i).getName();
    }
    ArrayAdapter<String> adp = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, values);
    adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adp);
    Button button = d.findViewById(R.id.button7);
    button.setText("Select");
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            listener.eventSelected(eventArrayList.get(spinner.getSelectedItemPosition()));
            d.dismiss();
        }
    });
    if (d.getWindow() != null)
        d.getWindow().getAttributes().windowAnimations = new IO(context).loadSettings().getRui().getAnimation();
    d.show();
    return true;
}
Also used : Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) ArrayList(java.util.ArrayList) View(android.view.View) TextView(android.widget.TextView) Point(android.graphics.Point) Button(android.widget.Button) Dialog(android.app.Dialog) REvent(com.cpjd.roblu.models.REvent) ArrayAdapter(android.widget.ArrayAdapter)

Example 23 with IO

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

the class Utils method launchEventPicker.

/**
 * For certain things, the user may need to select an event from a list of locally stored event,
 * this method does just that! The EventSelectListener method will trigger when an event is successfully
 * selected.
 * @param context context reference
 * @param listener listener to respond to events
 * @return true if some events exist
 */
public static boolean launchEventPicker(Context context, final EventDrawerManager.EventSelectListener listener) {
    final Dialog d = new Dialog(context);
    d.setTitle("Pick event:");
    d.setContentView(R.layout.event_import_dialog);
    final Spinner spinner = d.findViewById(R.id.type);
    String[] values;
    final REvent[] events = new IO(context).loadEvents();
    if (events == null || events.length == 0)
        return false;
    values = new String[events.length];
    for (int i = 0; i < values.length; i++) {
        values[i] = events[i].getName();
    }
    ArrayAdapter<String> adp = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, values);
    adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adp);
    Button button = d.findViewById(R.id.button7);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            listener.eventSelected(events[spinner.getSelectedItemPosition()]);
            d.dismiss();
        }
    });
    if (d.getWindow() != null)
        d.getWindow().getAttributes().windowAnimations = new IO(context).loadSettings().getRui().getAnimation();
    d.show();
    return true;
}
Also used : Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) View(android.view.View) TextView(android.widget.TextView) Point(android.graphics.Point) Button(android.widget.Button) Dialog(android.app.Dialog) REvent(com.cpjd.roblu.models.REvent) ArrayAdapter(android.widget.ArrayAdapter)

Example 24 with IO

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

the class Utils method getMatchTitlesWithinEvent.

/**
 * Returns the match titles within an REvent
 * @return a String[] containing ALL match titles within an REvent, may be null
 */
public static String[] getMatchTitlesWithinEvent(Context context, int eventID) {
    RTeam[] local = new IO(context).loadTeams(eventID);
    // no teams found
    if (local == null || local.length == 0)
        return null;
    ArrayList<RTab> tabs = new ArrayList<>();
    RForm form = new IO(context).loadForm(eventID);
    for (RTeam team : local) {
        team.verify(form);
        // check if the match already exists
        if (team.getTabs() == null || team.getTabs().size() == 0)
            continue;
        for (RTab tab : team.getTabs()) {
            if (tab.getTitle().equalsIgnoreCase("pit") || tab.getTitle().equalsIgnoreCase("predictions"))
                continue;
            boolean found = false;
            for (RTab temp : tabs) {
                if (temp.getTitle().equalsIgnoreCase(tab.getTitle())) {
                    found = true;
                    break;
                }
            }
            if (!found)
                tabs.add(tab);
        }
    }
    if (tabs.size() == 0)
        return null;
    Collections.sort(tabs);
    // Convert to String[]
    String[] values = new String[tabs.size()];
    for (int i = 0; i < tabs.size(); i++) {
        values[i] = tabs.get(i).getTitle();
    }
    return values;
}
Also used : RForm(com.cpjd.roblu.models.RForm) RTeam(com.cpjd.roblu.models.RTeam) RTab(com.cpjd.roblu.models.RTab) IO(com.cpjd.roblu.io.IO) ArrayList(java.util.ArrayList) Point(android.graphics.Point)

Example 25 with IO

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

the class MyMatches method checkoutClicked.

// user tapped on a match, let's load the "jump to team" dialog
public void checkoutClicked(final View v) {
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            // must be run on UI thread since it's a dialog and it's in a callback
            final RCheckout checkout = adapter.getCheckouts().get(rv.getChildAdapterPosition(v));
            final Dialog d = new Dialog(MyMatches.this);
            d.setTitle("Open team ");
            d.setContentView(R.layout.event_import_dialog);
            // load up a chooser with 6 teams into it (3 teammates, 3 opponents)
            final Spinner spinner = d.findViewById(R.id.type);
            String[] values = new String[6];
            for (int i = 0; i < values.length; i++) {
                if (i < 3)
                    values[i] = checkout.getTeam().getTabs().get(0).getTeammates().get(i).getNumber() + " (Teammate)";
                else
                    values[i] = checkout.getTeam().getTabs().get(0).getOpponents().get(i - 3).getNumber() + " (Opponent)";
            }
            TextView t = d.findViewById(R.id.spinner_tip);
            t.setText(R.string.team);
            ArrayAdapter<String> adp = new ArrayAdapter<>(MyMatches.this, android.R.layout.simple_list_item_1, values);
            adp.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adp);
            Button button = d.findViewById(R.id.button7);
            button.setText(R.string.open);
            // launch teamviewer if the user selects a team and taps "open"
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // 0,1,2,3,4,5
                    int pos = spinner.getSelectedItemPosition();
                    int ID;
                    // select the right team to load, since first 3 teams are our teammates, and last 3 are our opponents, we have to choose the correct array to pull from
                    if (pos < 3)
                        ID = checkout.getTeam().getTabs().get(0).getTeammates().get(pos).getID();
                    else
                        ID = checkout.getTeam().getTabs().get(0).getOpponents().get(pos - 3).getID();
                    Intent intent = new Intent(MyMatches.this, TeamViewer.class);
                    intent.putExtra("teamID", ID);
                    intent.putExtra("eventID", eventID);
                    startActivity(intent);
                    d.dismiss();
                }
            });
            // sync animation with ui settings
            if (d.getWindow() != null)
                d.getWindow().getAttributes().windowAnimations = new IO(getApplicationContext()).loadSettings().getRui().getAnimation();
            // show the dialog
            d.show();
        }
    });
}
Also used : Spinner(android.widget.Spinner) IO(com.cpjd.roblu.io.IO) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Button(android.widget.Button) Dialog(android.app.Dialog) RCheckout(com.cpjd.roblu.models.RCheckout) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

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