use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class Overview method teamRetrieved.
/**
* This method is called when TBA information for the team is successfully downloaded
* @param tbaTeam the TBA team model that contains downloaded information
*/
@Override
public void teamRetrieved(Team tbaTeam) {
Log.d("RBS", "Downloaded TBA information for " + tbaTeam.nickname);
String tbaInfo = "Locality: " + tbaTeam.locality + "\nRegion: " + tbaTeam.region + "\nCountry name: " + tbaTeam.country_name + "\nLocation: " + tbaTeam.location + "\nRookie year: " + tbaTeam.rookie_year + "\nMotto: " + tbaTeam.motto;
TeamViewer.team.setTbaInfo(tbaInfo);
TeamViewer.team.setWebsite(tbaTeam.website);
try {
new IO(getView().getContext()).saveTeam(getArguments().getInt("eventID"), TeamViewer.team);
// TBA info card
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
layout.addView(rMetricToUI.getInfoField("TBA.com information", TeamViewer.team.getTbaInfo(), TeamViewer.team.getWebsite(), TeamViewer.team.getNumber()), 0);
}
});
} catch (Exception e) {
Log.d("RBS", "Failed to download TBA information.");
}
}
use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class TeamTabAdapter method createMatch.
/**
* Creates a new match with the specified parameter,
* this method is used by the manual match creator, however,
* most users will likely just use TBA.com importing.
* @param name the name of the match
* @param isRed true if this team is on the red alliance
* @return the position of the sorted, created match
*/
public int createMatch(String name, boolean isRed) {
RTab tab = new RTab(TeamViewer.team.getNumber(), name, Utils.duplicateRMetricArray(form.getMatch()), isRed, false, 0);
int position = TeamViewer.team.addTab(tab);
TeamViewer.team.setLastEdit(System.currentTimeMillis());
new IO(context).saveTeam(event.getID(), TeamViewer.team);
// If these event is cloud synced, a new checkout needs to be packaged
if (event.isCloudEnabled()) {
RTeam newTeam = new RTeam(TeamViewer.team.getName(), TeamViewer.team.getNumber(), TeamViewer.team.getID());
newTeam.addTab(tab);
RCheckout checkout = new RCheckout(newTeam);
/*
* It would require a lot more code to check all devices and be sure that a new ID is
* valid, so generate a random one. The chances of an error occurring are so low, this is acceptable (somewhat :\)
*/
checkout.setID(new Random().nextInt(Integer.MAX_VALUE - 50_000) + 20_000);
checkout.setStatus(HandoffStatus.AVAILABLE);
new IO(context).savePendingCheckout(checkout);
}
Bundle bundle = new Bundle();
bundle.putSerializable("event", event);
bundle.putSerializable("form", form);
bundle.putBoolean("readOnly", false);
bundle.putInt("position", position);
Match match = new Match();
match.setArguments(bundle);
notifyDataSetChanged();
return position + 1;
}
use of com.cpjd.roblu.io.IO 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;
}
use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class UIHandler method update.
public void update() {
rui = new IO(activity).loadSettings().getRui();
if (rui == null)
rui = new RUI();
// set toolbar colors
if (toolbar != null) {
toolbar.setBackgroundColor(rui.getPrimaryColor());
toolbar.setTitleTextColor(rui.getText());
toolbar.setSubtitleTextColor(rui.getText());
if (!start) {
try {
Drawable drawable = ContextCompat.getDrawable(activity, android.support.design.R.drawable.abc_ic_ab_back_material);
drawable.setColorFilter(rui.getButtons(), PorterDuff.Mode.SRC_ATOP);
if (activity.getSupportActionBar() != null)
activity.getSupportActionBar().setHomeAsUpIndicator(drawable);
} catch (Exception e) {
System.out.println("System does not contain back button");
}
}
}
// set status bar colors
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(RUI.darker(rui.getPrimaryColor(), 0.85f));
if (start && rui.getPrimaryColor() == -12627531)
window.setStatusBarColor(Color.TRANSPARENT);
}
// activity background
View view = activity.getWindow().getDecorView();
view.setBackgroundColor(rui.getBackground());
if (fab != null) {
fab.setBackgroundTintList(ColorStateList.valueOf(rui.getPrimaryColor()));
Drawable d = fab.getDrawable();
d.mutate();
d.setColorFilter(rui.getButtons(), PorterDuff.Mode.SRC_IN);
fab.setImageDrawable(d);
}
}
use of com.cpjd.roblu.io.IO in project Roblu by wdavies973.
the class FastDialogBuilder method build.
public void build(Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setMessage(message);
if (!positiveButtonText.equals("")) {
builder.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (listener != null)
listener.accepted();
dialog.dismiss();
}
});
}
if (!neutralButtonText.equals("")) {
builder.setNeutralButton(neutralButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (listener != null)
listener.neutral();
dialog.dismiss();
}
});
}
if (!negativeButtonText.equals("")) {
builder.setNegativeButton(negativeButtonText, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (listener != null)
listener.denied();
dialog.dismiss();
}
});
}
RUI rui = new IO(context).loadSettings().getRui();
AlertDialog dialog = builder.create();
if (dialog.getWindow() != null) {
dialog.getWindow().getAttributes().windowAnimations = rui.getAnimation();
if (dialog.getButton(Dialog.BUTTON_NEGATIVE) != null)
dialog.getButton(Dialog.BUTTON_NEGATIVE).setTextColor(rui.getAccent());
if (dialog.getButton(Dialog.BUTTON_POSITIVE) != null)
dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(rui.getAccent());
if (dialog.getButton(Dialog.BUTTON_NEUTRAL) != null)
dialog.getButton(Dialog.BUTTON_NEUTRAL).setTextColor(rui.getAccent());
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(rui.getBackground()));
}
dialog.setCancelable(false);
dialog.show();
}
Aggregations