Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Clean up constants
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliu2016 committed Sep 5, 2018
1 parent 197e184 commit 0313329
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 61 deletions.
76 changes: 20 additions & 56 deletions app/src/main/java/ca/warp7/android/scouting/ScoutingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
import ca.warp7.android.scouting.model.Specs;
import ca.warp7.android.scouting.resources.ManagedPreferences;

import static ca.warp7.android.scouting.constants.Constants.kAutonomousTime;
import static ca.warp7.android.scouting.constants.Constants.kFadeDuration;
import static ca.warp7.android.scouting.constants.Constants.kTimerLimit;
import static ca.warp7.android.scouting.constants.Constants.kTotalTimerDigits;


/**
* <p>The Scouting Activity -- A generic activity to collect data
Expand Down Expand Up @@ -146,7 +151,7 @@ public void run() {
updateAdjacentTabStates();
mTimer++;

if (mTimer <= kTimerLimit) { // Check if match ended
if (mTimer <= kTimerLimit) {
mTimeHandler.postDelayed(mTimerUpdater, 1000);
} else {
mTimerIsRunning = false;
Expand Down Expand Up @@ -199,7 +204,6 @@ public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.scouting_menu, menu);

return true;
}

Expand Down Expand Up @@ -303,15 +307,11 @@ public void pushStatus(String status) {
*/

public void onStartScouting(View view) {

mStartingTimestamp = getCurrentTime();
mEntry.setStartingTimestamp(mStartingTimestamp);

startActivityState(ScoutingState.SCOUTING);
updateAdjacentTabStates();

pushStatus("Timer Started\n");

}

/**
Expand Down Expand Up @@ -351,10 +351,9 @@ public void onUndoSkipClicked(View view) {
mUndoAndNowImage.setImageResource(R.drawable.ic_undo_ablack);
mUndoAndNowText.setText(R.string.btn_undo);
}

break;

case ScoutingState.PAUSING: // Skip button
case ScoutingState.PAUSING: // Now button

mTimer = calculateCurrentRelativeTime();
startActivityState(ScoutingState.SCOUTING);
Expand Down Expand Up @@ -407,7 +406,6 @@ public void onClick(DialogInterface dialog, int which) {
private void onCommentsAndFlags() {

final EditText input = new EditText(this);

input.setInputType(InputType.TYPE_CLASS_TEXT |
InputType.TYPE_TEXT_FLAG_MULTI_LINE |
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
Expand All @@ -424,9 +422,6 @@ private void onCommentsAndFlags() {
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

// Get the comment and make sure underscore isn't used

mEntry.setComments(input.getText().toString()
.replaceAll("_", ""));
}
Expand Down Expand Up @@ -484,12 +479,10 @@ private boolean isTimerAtCurrentTime() {
private void setupSpecs() {

mSpecs = Specs.getInstance();

if (mSpecs == null) { // Fixes singlet not loaded issue
if (mSpecs == null) {
Specs.setInstance(getIntent().getStringExtra(ID.MSG_SPECS_FILE));
mSpecs = Specs.getInstance();
}

mLayouts = mSpecs.getLayouts();
}

Expand Down Expand Up @@ -565,7 +558,6 @@ public void onStopTrackingTouch(SeekBar seekBar) {

}
});

}

/**
Expand Down Expand Up @@ -593,10 +585,10 @@ private void setupValuesFromIntent() {

String m = "" + matchNumber;
mToolbarMatch.setText(m);

mToolbarTeam.setTextColor(
alliance.equals("R") ? kRedAllianceColour :
(alliance.equals("B") ? kBlueAllianceColour : kNeutralAllianceColour));
getResources().getColor(alliance.equals("R") ? R.color.colorRed :
(alliance.equals("B") ? R.color.colorBlue :
R.color.colorPurple)));

findViewById(R.id.highlight_bar).getBackground()
.setColorFilter(getResources()
Expand All @@ -608,13 +600,12 @@ private void setupValuesFromIntent() {
mToolbarTeam.setTypeface(Typeface.SANS_SERIF,
alliance.equals("R") || alliance.equals("B") ? Typeface.BOLD : Typeface.NORMAL);

mStatusLog = new StringBuilder(); // initialize the log
mStatusLog = new StringBuilder();

pushStatus("\n\n========LOG========");
pushStatus("Board ID: " + mSpecs.getSpecsId());
pushStatus("");

// NOTE Entry uses Specs so must ensure specs instance exists
mEntry = new Entry(matchNumber, teamNumber, scoutName, this);
}

Expand All @@ -625,9 +616,8 @@ private void setupValuesFromIntent() {
private void setupPager() {

mPager = findViewById(R.id.pager);

mPagerAdapter = new ScoutingTabsPagerAdapter(getSupportFragmentManager(),
mSpecs.getLayouts().size(), mPager);
mPagerAdapter = new ScoutingTabsPagerAdapter(
getSupportFragmentManager(), mSpecs.getLayouts().size(), mPager);

mPager.setAdapter(mPagerAdapter);

Expand Down Expand Up @@ -681,36 +671,27 @@ private void initStates(Bundle savedInstanceState) {

private void startActivityState(int state) {

if (state == ScoutingState.SCOUTING &&
(mTimerIsRunning || mTimer >= kTimerLimit)) {
return; // Return if there is a timer running
if (state == ScoutingState.SCOUTING && (mTimerIsRunning || mTimer >= kTimerLimit)) {
return;
}

mActivityState = state;

switch (mActivityState) {

case ScoutingState.STARTING:

setStartingNavToolbox();

break;

case ScoutingState.SCOUTING:

setScoutingNavToolbox();
setBackgroundColour(getResources().getColor(R.color.colorWhite));

getManagedVibrator().vibrateStart(); // Vibrate to signal start
getManagedVibrator().vibrateStart();
mTimerUpdater.run();

break;

case ScoutingState.PAUSING:

setPausingNavToolbox();
setBackgroundColour(getResources().getColor(R.color.colorAlmostYellow));

break;
}
}
Expand All @@ -720,10 +701,8 @@ private void startActivityState(int state) {
*/

private void setStartingNavToolbox() {

mPlayAndPauseView.setVisibility(View.GONE);
mUndoAndNowView.setVisibility(View.GONE);

mTimeSeeker.setVisibility(View.GONE);
mTimeProgress.setVisibility(View.VISIBLE);
}
Expand All @@ -734,8 +713,6 @@ private void setStartingNavToolbox() {

private void setScoutingNavToolbox() {

// mPlayAndPauseImage.setVisibility(View.VISIBLE);

mPlayAndPauseView.setVisibility(mUsingPauseBetaFeature ? View.VISIBLE : View.GONE);

mUndoAndNowView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -885,8 +862,9 @@ private void updateTimerStatusAndProgressBar() {

mTimerStatus.setText(filled_status);

mTimerStatus.setTextColor(mTimer <= kAutonomousTime ?
kAutonomousColour : kTeleOpColour);
mTimerStatus.setTextColor(getResources().getColor(mTimer <= kAutonomousTime ?
R.color.colorAutoYellow :
R.color.colorTeleOpGreen));

mTimeProgress.setProgress(mTimer);
mTimeSeeker.setProgress(mTimer);
Expand All @@ -907,18 +885,4 @@ private void attemptUndo() {
updateAdjacentTabStates();
}
}


// Static Fields

private static final int kTimerLimit = 150;
private static final int kAutonomousTime = 15;
private static final int kFadeDuration = 100;
private static final int kTotalTimerDigits = 3;

private static final int kBlueAllianceColour = 0xFF0000FF;
private static final int kRedAllianceColour = 0xFFFF0000;
private static final int kNeutralAllianceColour = 0xFFFF00FF;
private static final int kAutonomousColour = 0xFFCC9900;
private static final int kTeleOpColour = 0xFF006633;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ca.warp7.android.scouting.constants;

public class Constants {
public static final int kTimerLimit = 150;
public static final int kAutonomousTime = 15;
public static final int kFadeDuration = 100;
public static final int kTotalTimerDigits = 3;
}
13 changes: 8 additions & 5 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#ffffff</color>
<color name="colorWhite">#ffffff</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#3c5c94</color>
<color name="colorAlmostBlack">#404040</color>
<color name="colorDarkAccent">#304976</color>
<color name="colorAccent">#3c5c94</color>
<color name="colorGray">#808080</color>
<color name="colorBlue">#0000ff</color>
<color name="colorRed">#ff0000</color>
<color name="colorPurple">#ff00ff</color>
<color name="colorLightGreen">#009933</color>
<color name="colorAlmostBlack">#404040</color>
<color name="colorTeleOpGreen">#006633</color>
<color name="colorAutoYellow">#cc9900</color>
<color name="colorDarkAlmostWhite">#d4d4d4</color>
<color name="colorAlmostWhite">#e4e4e4</color>
<color name="colorAlmostBlue">#e4e4ff</color>
<color name="colorAlmostRed">#ffe4e4</color>
<color name="colorAlmostYellow">#ffe4a4</color>
<color name="colorGray">#808080</color>
<color name="colorPrimary">#ffffff</color>
<color name="colorWhite">#ffffff</color>
</resources>

0 comments on commit 0313329

Please sign in to comment.