use of com.cpjd.roblu.models.RUI 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.models.RUI 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();
}
use of com.cpjd.roblu.models.RUI in project Roblu by wdavies973.
the class EventCreateMethodPicker method importPublicRobluCloudEvent.
private void importPublicRobluCloudEvent() {
// check for an internet connection
if (!Utils.hasInternetConnection(getApplicationContext())) {
Utils.showSnackbar(findViewById(R.id.advsettings), getApplicationContext(), "You are not connected to the internet", true, 0);
return;
}
/*
* We need to make sure that this thread has access to the internet
*/
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
final RSettings settings = new IO(getApplicationContext()).loadSettings();
RUI rui = settings.getRui();
AlertDialog.Builder builder = new AlertDialog.Builder(EventCreateMethodPicker.this);
LinearLayout layout = new LinearLayout(EventCreateMethodPicker.this);
layout.setOrientation(LinearLayout.VERTICAL);
// this is the team code input edit text
final AppCompatEditText input = new AppCompatEditText(EventCreateMethodPicker.this);
Utils.setInputTextLayoutColor(rui.getAccent(), null, input);
input.setHighlightColor(rui.getAccent());
input.setHintTextColor(rui.getText());
input.setTextColor(rui.getText());
input.setInputType(InputType.TYPE_CLASS_NUMBER);
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(30);
input.setFilters(FilterArray);
layout.addView(input);
builder.setView(layout);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
importRobluCloudEvent(Integer.parseInt(input.getText().toString()));
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
TextView view = new TextView(EventCreateMethodPicker.this);
view.setTextSize(Utils.DPToPX(getApplicationContext(), 5));
view.setPadding(Utils.DPToPX(getApplicationContext(), 18), Utils.DPToPX(getApplicationContext(), 18), Utils.DPToPX(getApplicationContext(), 18), Utils.DPToPX(getApplicationContext(), 18));
view.setText("FRC team number:");
view.setTextColor(rui.getText());
AlertDialog dialog = builder.create();
dialog.setCustomTitle(view);
if (dialog.getWindow() != null) {
dialog.getWindow().getAttributes().windowAnimations = rui.getAnimation();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(rui.getBackground()));
}
dialog.show();
dialog.getButton(Dialog.BUTTON_NEGATIVE).setTextColor(rui.getAccent());
dialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(rui.getAccent());
}
use of com.cpjd.roblu.models.RUI in project Roblu by wdavies973.
the class EventEditor method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*
* Load dependencies
*/
editing = getIntent().getBooleanExtra("editing", false);
RUI rui = new IO(getApplicationContext()).loadSettings().getRui();
// decide whether to use create event or edit event UI scheme
if (editing)
setContentView(R.layout.activity_edit_event);
else
setContentView(R.layout.activity_create_event);
/*
* Setup UI
*/
// Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setHomeAsUpIndicator(R.drawable.clear);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
if (editing)
getSupportActionBar().setTitle("Edit event");
else
getSupportActionBar().setTitle("Create event");
}
// event name
eventName = findViewById(R.id.event_create_name_edit);
/*
* Bind user color preferences to the UI elements
*/
Utils.setInputTextLayoutColor(rui.getAccent(), (TextInputLayout) findViewById(R.id.name_wrapper), (AppCompatEditText) findViewById(R.id.event_create_name_edit));
/*
* Setup editing/non-editing UI specifics
*/
if (!editing) {
TextView t = findViewById(R.id.event_create_form_label);
t.setTextColor(rui.getAccent());
if (getIntent().getSerializableExtra("tbaEvent") != null) {
/*
* This item will be set if this activity is called form the TBAEventSelector activity, all it's saying is that
* all the data within this Event model should be included when creating the REvent
*/
Event event = (Event) getIntent().getSerializableExtra("tbaEvent");
eventName.setText(event.name);
findViewById(R.id.switch1).setVisibility(View.VISIBLE);
}
} else {
RelativeLayout layout = findViewById(R.id.create_layout);
for (int i = 0; i < layout.getChildCount(); i++) {
if (layout.getChildAt(i).getId() == R.id.form_type || layout.getChildAt(i).getId() == R.id.event_create_form_label) {
layout.removeViewAt(i);
i = 0;
}
}
tbaKeyText = findViewById(R.id.key_edit);
tbaKeyText.setText(getIntent().getStringExtra("key"));
eventName.setText(getIntent().getStringExtra("name"));
}
// General UI syncing
new UIHandler(this, toolbar).update();
}
use of com.cpjd.roblu.models.RUI in project Roblu by wdavies973.
the class Service method loop.
/**
* This is the main background service looper, this should perform any necessary
* Roblu Cloud sync operations
*/
public void loop() {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
if (!Utils.hasInternetConnection(getApplicationContext())) {
Log.d("RBS", "No internet connection detected. Ending loop() early.");
return;
}
/*
* Create all the utilities we need for this loop
*/
IO io = new IO(getApplicationContext());
RSettings settings = io.loadSettings();
RSyncSettings cloudSettings = io.loadCloudSettings();
Request r = new Request(settings.getServerIP());
ObjectMapper mapper = new ObjectMapper().configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
CloudTeamRequest teamRequest = new CloudTeamRequest(r, settings.getCode());
CloudCheckoutRequest checkoutRequest = new CloudCheckoutRequest(r, settings.getCode());
boolean result = r.ping();
if (result)
Utils.requestServerHealthRefresh(getApplicationContext(), "online");
else
Utils.requestServerHealthRefresh(getApplicationContext(), "offline");
if (!result) {
Log.d("RBS", "Roblu server is down. Unable to connect.");
return;
}
// Load the active event
REvent[] events = io.loadEvents();
REvent activeEvent = null;
for (int i = 0; events != null && events.length > 0 && i < events.length; i++) {
if (events[i].isCloudEnabled()) {
activeEvent = events[i];
break;
}
}
if (activeEvent != null && activeEvent.getReadOnlyTeamNumber() != -1) {
teamRequest.setTeamNumber(activeEvent.getReadOnlyTeamNumber());
teamRequest.setCode("");
checkoutRequest.setTeamNumber(activeEvent.getReadOnlyTeamNumber());
checkoutRequest.setTeamCode("");
}
/*
* Check if a purge is requested
*/
if (cloudSettings.isPurgeRequested() && checkoutRequest.purge()) {
cloudSettings.setPurgeRequested(false);
cloudSettings.setTeamSyncID(0);
cloudSettings.getCheckoutSyncIDs().clear();
Log.d("RBS", "Event successfully purged from Roblu Cloud.");
io.saveCloudSettings(cloudSettings);
Notify.notifyNoAction(getApplicationContext(), "Event purged", "Active event successfully removed from Roblu Cloud.");
return;
}
if (activeEvent == null)
return;
// Create the sync helper
SyncHelper syncHelper = new SyncHelper(getApplicationContext(), activeEvent, SyncHelper.MODES.NETWORK);
RForm form = io.loadForm(activeEvent.getID());
/*
* Check to see if the form was modified and needs to be uploaded
*/
if (form.isUploadRequired()) {
try {
teamRequest.pushForm(mapper.writeValueAsString(form));
form.setUploadRequired(false);
io.saveForm(activeEvent.getID(), form);
Notify.notifyNoAction(getApplicationContext(), "Form uploaded", "Successfully uploaded RForm to the server.");
Log.d("RBS-Service", "Successfully uploaded RForm to the server.");
} catch (Exception e) {
Log.d("RBS-Service", "Failed to complete an upload required request for RForm.");
}
}
/*
* Check to see if the UI model should be uploaded
*/
if (settings.getRui().isUploadRequired()) {
try {
teamRequest.pushUI(mapper.writeValueAsString(settings.getRui()));
settings.getRui().setUploadRequired(false);
io.saveSettings(settings);
Log.d("RBS-Service", "Successfully uploaded RUI to the server.");
} catch (Exception e) {
Log.d("RBS-Service", "Failed to complete an upload required request for RUI.");
}
}
/*
* Check for cloud team updates
*/
try {
CloudTeam t = teamRequest.getTeam(cloudSettings.getTeamSyncID());
if (t != null) {
/*
* If a different master app overwrites the cloud app with a different event, run this check to prevent conflicts
* from happening.
*/
if (t.getActiveEventName() != null && !t.getActiveEventName().equals("") && activeEvent.getName() != null && !t.getActiveEventName().equals(activeEvent.getName())) {
activeEvent.setCloudEnabled(false);
cloudSettings.getCheckoutSyncIDs().clear();
io.saveCloudSettings(cloudSettings);
io.saveEvent(activeEvent);
return;
}
// Merge RForm
form = mapper.readValue(t.getForm(), RForm.class);
form.setUploadRequired(false);
io.saveForm(activeEvent.getID(), form);
// Merge RUI
RUI rui = mapper.readValue(t.getUi(), RUI.class);
rui.setUploadRequired(false);
settings.setRui(rui);
// make sure to refresh this
settings = io.loadSettings();
io.saveSettings(settings);
// Update the sync ID
cloudSettings.setTeamSyncID((int) t.getSyncID());
io.saveCloudSettings(cloudSettings);
Log.d("RBS-Service", "Successfully pulled team data from the server.");
}
} catch (Exception e) {
Log.d("RBS-Service", "Failed to pull team data from the server: " + e.getMessage());
}
/*
*
* Alright, into the belly of the beast.
* This code will check for completed checkouts on the server and merge them with the local repository.
* Shall we begin?
*
*/
try {
CloudCheckout[] checkouts = checkoutRequest.pullCompletedCheckouts(syncHelper.packSyncIDs(cloudSettings.getCheckoutSyncIDs()));
syncHelper.unpackCheckouts(checkouts, cloudSettings);
io.saveCloudSettings(cloudSettings);
} catch (Exception e) {
Log.d("RBS-Service", "An error occurred while fetching completed checkouts. " + e.getMessage());
}
/*
* Next, uploading everything from /pending/
*/
try {
Log.d("RBS-Service", "Checking for any checkouts to upload...");
ArrayList<RCheckout> checkouts = new ArrayList<>(Arrays.asList(io.loadPendingCheckouts()));
boolean wasSuccess = checkoutRequest.pushCheckouts(syncHelper.packCheckouts(checkouts));
if (wasSuccess) {
for (RCheckout checkout : checkouts) {
io.deletePendingCheckout(checkout.getID());
}
Notify.notifyNoAction(getApplicationContext(), "Uploaded new checkouts", "Uploaded " + checkouts.size() + " new checkout(s).");
}
Log.d("RBS-Service", "Uploaded " + checkouts.size() + " checkouts.");
} catch (Exception e) {
Log.d("RBS-Service", "An error occurred while attempting to push /pending/ checkouts: " + e.getMessage());
}
io.saveCloudSettings(cloudSettings);
Log.d("RBS-Service", "Sleeping Roblu background service for 10 seconds...");
}
Aggregations