Search in sources :

Example 56 with IO

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

the class RUIColorPreference method onBindView.

@Override
protected void onBindView(View view) {
    super.onBindView(view);
    RUI rui = new IO(getContext()).loadSettings().getRui();
    TextView titleView = view.findViewById(android.R.id.title);
    titleView.setTextColor(rui.getText());
    TextView subtitle = view.findViewById(android.R.id.summary);
    subtitle.setTextColor(rui.darker(rui.getText(), 0.6f));
}
Also used : IO(com.cpjd.roblu.io.IO) RUI(com.cpjd.roblu.models.RUI) TextView(android.widget.TextView)

Example 57 with IO

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

the class BTServer method run.

/**
 * Starts the sync task
 */
@Override
public void run() {
    /*
         * Load the active Bluetooth event
         */
    IO io = new IO(bluetooth.getActivity());
    REvent[] events = io.loadEvents();
    if (events == null || events.length == 0) {
        bluetooth.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(bluetooth.getActivity(), "No events found. Please create an event to enable Bluetooth syncing.", Toast.LENGTH_LONG).show();
            }
        });
        pd.dismiss();
        return;
    }
    for (REvent event : events) {
        if (event.isBluetoothEnabled()) {
            this.event = event;
            break;
        }
    }
    if (this.event == null) {
        bluetooth.getActivity().runOnUiThread(new Runnable() {

            @Override
            public void run() {
                Toast.makeText(bluetooth.getActivity(), "No active Bluetooth event found. Please enable Bluetooth in event settings to enable Bluetooth syncing.", Toast.LENGTH_LONG).show();
            }
        });
        pd.dismiss();
        return;
    }
    this.syncHelper = new SyncHelper(bluetooth.getActivity(), this.event, SyncHelper.MODES.BLUETOOTH);
    if (bluetooth.isEnabled()) {
        bluetooth.startServer();
    } else
        bluetooth.enable();
}
Also used : IO(com.cpjd.roblu.io.IO) REvent(com.cpjd.roblu.models.REvent) SyncHelper(com.cpjd.roblu.sync.SyncHelper)

Example 58 with IO

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

the class ExportCSVTask method run.

@Override
public void run() {
    if (Build.VERSION.SDK_INT < 21) {
        listener.errorOccurred("Your device does not support CSV exporting.");
        return;
    }
    /*
         * Check to see if the event is null, if it is, we must cancel this task
         */
    if (event == null) {
        listener.errorOccurred("Event could not be loaded.");
        return;
    }
    /*
         * Load teams
         */
    teams = new IO(contextWeakReference.get()).loadTeams(event.getID());
    form = new IO(contextWeakReference.get()).loadForm(event.getID());
    /*
         * Check to see if the teams or forms are null, if they are, cancel the task
         */
    if (teams == null || teams.length == 0 || form == null) {
        listener.errorOccurred("This event doesn't contain any teams");
        return;
    }
    /*
         * Verify all the teams
         */
    for (RTeam team : teams) {
        if (team != null) {
            // also sneak in a line here to tell each team to sort by numerical if a sort request is made
            team.setFilter(TeamsView.SORT_TYPE.NUMERICAL);
            team.verify(form);
            new IO(contextWeakReference.get()).saveTeam(event.getID(), team);
        }
    }
    /*
         * Sort the teams by number
         */
    Collections.sort(Arrays.asList(teams));
    /*
         * Build checkouts array, nice way to store data
         */
    final ArrayList<RCheckout> checkouts = new ArrayList<>();
    for (RTeam team : teams) {
        RTeam temp = team.clone();
        temp.removeAllTabsButPIT();
        RCheckout newCheckout = new RCheckout(temp);
        checkouts.add(newCheckout);
    }
    /*
         * Next, add an assignment for every match, for every team
         */
    for (RTeam team : teams) {
        if (team.getTabs() == null || team.getTabs().size() == 0)
            continue;
        for (int i = 2; i < team.getTabs().size(); i++) {
            RTeam temp = team.clone();
            temp.setPage(0);
            temp.removeAllTabsBut(i);
            RCheckout check = new RCheckout(temp);
            checkouts.add(check);
        }
    }
    Collections.sort(checkouts);
    // Create an IO reference
    final IO io = new IO(contextWeakReference.get());
    /*
         * Start executing all the different CSVSheets generate commands
         */
    for (final CSVSheet s : CSVSheets) {
        new Thread() {

            public void run() {
                if (s.isEnabled()) {
                    try {
                        s.setIo(io);
                        s.setVerboseness(verboseness);
                        s.setWorkbook(workbook);
                        Log.d("RBS", "ExportCSVTask: Generating sheet: " + s.getSheetName());
                        // sets the default, this may get overrided at any point in time by the user
                        s.setCellStyle(BorderStyle.THIN, IndexedColors.WHITE, IndexedColors.BLACK, false);
                        s.generateSheet(sheets.get(s.getSheetName()), event, form, teams, checkouts);
                        for (int i = 0; i < sheets.get(s.getSheetName()).getRow(0).getLastCellNum(); i++) sheets.get(s.getSheetName()).setColumnWidth(i, s.getColumnWidth());
                    } catch (Exception e) {
                        listener.errorOccurred("Failed to execute " + s.getSheetName() + " sheet generation.");
                        Log.d("RBS", "Failed to execute " + s.getSheetName() + " sheet generation. Err: " + e.getMessage());
                    }
                    threadCompleted(s.getSheetName());
                }
            }
        }.start();
    }
}
Also used : RTeam(com.cpjd.roblu.models.RTeam) IO(com.cpjd.roblu.io.IO) ArrayList(java.util.ArrayList) RCheckout(com.cpjd.roblu.models.RCheckout) CSVSheet(com.cpjd.roblu.csv.csvSheets.CSVSheet) IOException(java.io.IOException)

Example 59 with IO

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

the class ExportCSVTask method threadCompleted.

private void threadCompleted(String name) {
    Log.d("RBS", "A CSV Thread completed: " + name);
    threadsComplete++;
    if (threadsComplete == enabledSheets) {
        File file = new IO(contextWeakReference.get()).getNewCSVExportFile(fileName + ".xslx");
        try {
            FileOutputStream out = new FileOutputStream(file);
            workbook.write(out);
            Log.d("RBS", "Successfully generated .xslx file: " + file.getAbsolutePath());
            try {
                if (!isXslx) {
                    new ToCSV().convertExcelToCSV(file.getPath(), file.getParentFile().getPath());
                    // Get the new file reference
                    file = new File(file.getParentFile() + File.separator + fileName + ".csv");
                    Log.d("RBS", "Converted .xslx to .CSV: " + file.getAbsolutePath() + " Check: " + file.exists());
                }
            } catch (Exception e) {
                Log.d("RBS", "Failed to convert the file to .CSV");
                listener.errorOccurred("Failed to generate ");
            }
            // List contents of file
            for (File f : file.getParentFile().listFiles()) {
                Log.d("RBS", "Exports dir contains " + f.getAbsolutePath());
            }
            out.close();
            listener.csvFileGenerated(file);
        } catch (IOException e) {
            e.printStackTrace();
            Log.d("RBS", "ERR: " + e.getMessage());
            listener.errorOccurred("Failed to write file.");
        }
    }
}
Also used : IO(com.cpjd.roblu.io.IO) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

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