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));
}
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();
}
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();
}
}
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.");
}
}
}
Aggregations