+
+
@@ -15,7 +25,7 @@
-
+
\ No newline at end of file
diff --git a/UberTrak V2/UberTrak/app/src/main/java/ubertrak/shockleyco/com/ubertrak/MainActivity.java b/UberTrak V2/UberTrak/app/src/main/java/ubertrak/shockleyco/com/ubertrak/MainActivity.java
index baee297..39e614f 100644
--- a/UberTrak V2/UberTrak/app/src/main/java/ubertrak/shockleyco/com/ubertrak/MainActivity.java
+++ b/UberTrak V2/UberTrak/app/src/main/java/ubertrak/shockleyco/com/ubertrak/MainActivity.java
@@ -38,39 +38,49 @@ public class MainActivity extends AppCompatActivity implements RecognitionListen
/*Keyword we are looking for to acvivate reset pop*/
private static final String KEYPHRASE_MOM = "mom get the camera ";
-
+ /* Set wait counters for the drop and pop commands in ms*/
private int popWait= 8000;
private int dropWait= 10000;
+ /* Initialize our speech recognizer*/
private SpeechRecognizer recognizer;
int conteo = 0;
int permiso_flag=0;
Handler a = new Handler();
+ /* Initialize our toolbar */
private Toolbar toolbar;
+ /* Initialize our values for keeping up with uber %'s*/
private int uber = -69;
private int kritz= -69;
+ /* Initialize our strings which will be displayed on their respective cards*/
private static final String UBER = "-69";
private static final String KRITZ= "-69";
+ /* Initialize values for how often we want to update our charges*/
+ /* These are variable because we options for charging slower/ faster based on skill multiplier*/
private int uberMilliDelay= 400;
private int kritzMilliDelay= 320;
-
+ /* These are final because we want to have something to reset them back to if the user chooses to*/
private static final int UBERMILLIDELAY= 400;
private static final int KRITZMILLIDELAY=320;
+ /* These are our multipliers for varying charge rate. They are rough approximations of how
+ * fast someone charges at various skill levels, 1.00 being the most optimized */
private static final double UGCSTEELMULTIPLIER= 1.25;
private static final double BABBYMULTIPLIER= 1.5;
+ /* Initialize text views so we can change them on updates*/
TextView uberCurrent;
TextView kritzCurrent;
+ /* Initialize backgrounds to false, they will change color at 100%*/
private boolean changedUberBackground = false;
private boolean changedKritzBackground = false;
-
+ /* Our cards that will house our textviews*/
private CardView viewUber;
private CardView viewKritz;
@@ -78,9 +88,17 @@ public class MainActivity extends AppCompatActivity implements RecognitionListen
Handler timerUberHandler = new Handler();
Runnable timerUberRunnable = new Runnable() {
+ /* Loop for updating uber */
+ /* Three conditions
+ * 1) uber needs to be incremented and updated
+ * 2) we are at full uber, pause the runnable
+ * 3) we are at full uber and background isn't changed, we change it and record that
+ *
+ * Delay the runnable by the variable delay time
+ *
+ * */
@Override
public void run() {
-
if(uber< 100){
uber++;
updateUber();
@@ -98,9 +116,8 @@ else if(uber == 100){
}
};
-// final CardView viewKritz = (CardView) findViewById(R.id.card_view_main_kritz);
-
//runs without a timer by reposting this handler at the end of the runnable
+ /* This logic is the same as the uber handler above */
Handler timerKritzHandler = new Handler();
Runnable timerKritzRunnable = new Runnable() {
@@ -127,6 +144,8 @@ else if(kritz == 100){
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ /* Inflate our views */
setContentView(R.layout.activity_main);
toolbar= (Toolbar) findViewById(R.id.main_bar);
@@ -135,19 +154,16 @@ protected void onCreate(Bundle savedInstanceState) {
viewUber= (CardView) findViewById(R.id.card_view_main_uber);
viewKritz= (CardView) findViewById(R.id.card_view_main_kritz);
-
+ /* Initialize our values to zero or pick up where we left off */
if(savedInstanceState == null){
-
uber= 0;
kritz= 0;
-
} else {
-
uber= savedInstanceState.getInt(UBER);
kritz= savedInstanceState.getInt(KRITZ);
-
}
+ /* This task allows us to run in the background */
new AsyncTask() {
@Override
protected Exception doInBackground(Void... params) {
@@ -170,20 +186,20 @@ protected void onPostExecute(Exception result) {
}
}.execute();
+ /* This is a backup for our recognizer not picking up on a phrase
+ * the user can tap the screen to reset */
LinearLayout popButton = (LinearLayout) findViewById(R.id.main_linear_layout);
-
popButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- // TODO Auto-generated method stub
-
reset();
}
});
+ /* These are our three buttons for modifying the speed at which the counter fills
+ * OnClick, they update the delay values */
CardView oneButton = (CardView) findViewById(R.id.Card_View_Uber_Multiplier_Hardcore);
-
oneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -192,9 +208,7 @@ public void onClick(View v) {
kritzMilliDelay=KRITZMILLIDELAY;
}
});
-
CardView onePointTwoFiveButton = (CardView) findViewById(R.id.Card_View_Uber_Multiplier_UGC_Steel);
-
onePointTwoFiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -204,9 +218,7 @@ public void onClick(View v) {
}
});
-
CardView onePointFiveButton = (CardView) findViewById(R.id.Card_View_Uber_Multiplier_Babbies);
-
onePointFiveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -217,18 +229,20 @@ public void onClick(View v) {
}
});
+ /* Now, we cast to text view so we can use them to update what the user sees */
uberCurrent= (TextView) findViewById(R.id.uberPercentTextView);
kritzCurrent= (TextView) findViewById(R.id.kritzPercentTextView);
-// timerUberHandler.postDelayed(timerUberRunnable, 0);
-// timerKritzHandler.postDelayed(timerKritzRunnable, 0);
-
}
+ /* This is where we set up our search logic for the keywords we defined */
private void searchReset(String searchName){
+ /* Stop the recognizer, otherwise we'd get multiple triggers if someone repeats the phrase */
recognizer.stop();
+ /* Each statement is triggered by recognizing the keyword
+ * Logic to be triggered by the keyword command can be called prior to restarting the recognizer*/
if(searchName.equals(KWS_SEARCH)){
recognizer.startListening(searchName);
}
@@ -236,19 +250,16 @@ private void searchReset(String searchName){
else if(searchName.equals(KEYPHRASE)){
reset();
recognizer.startListening(KWS_SEARCH);
-
}
else if(searchName.equals(KEYPHRASE_POP)){
medDelay(popWait);
recognizer.startListening(KWS_SEARCH);
-
}
else if(searchName.equals(KEYPHRASE_DOWN)){
medDelay(dropWait);
recognizer.startListening(KWS_SEARCH);
-
}
else if(searchName.equals(KEYPHRASE_MOM)){
@@ -256,8 +267,7 @@ else if(searchName.equals(KEYPHRASE_MOM)){
recognizer.startListening(KWS_SEARCH);
}
-
-
+ /* If we didn't recognize something, just restart the recognizer */
else {
recognizer.startListening(KWS_SEARCH);
@@ -265,12 +275,15 @@ else if(searchName.equals(KEYPHRASE_MOM)){
}
+ /* This is our logic for delaying the counter by a set delay represented in ms*/
private void medDelay(int delay){
reset();
+ /* we need to pause the runnables */
pauseRunnables('k');
pauseRunnables('u');
+ /* create a new handler and delay that by our parameter*/
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
@@ -289,12 +302,8 @@ public void run() {
@Override
protected void onResume(){
super.onResume();
-
resumeRunnables('k');
resumeRunnables('u');
-
-
-
}
@Override
@@ -302,11 +311,9 @@ protected void onPause(){
super.onPause();
pauseRunnables('k');
pauseRunnables('u');
-
-
}
-
+ /* This removes all callbacks to our runnable during pauses */
private void pauseRunnables(char c){
if(c== 'k'){
timerKritzHandler.removeCallbacks(timerKritzRunnable);
@@ -314,9 +321,8 @@ private void pauseRunnables(char c){
else if(c== 'u'){
timerUberHandler.removeCallbacks(timerUberRunnable);
}
-
}
-
+ /* This resumes our runnables after delaying them */
private void resumeRunnables(char c){
if(c=='k'){
timerKritzHandler.postDelayed(timerKritzRunnable, kritzMilliDelay);
@@ -330,22 +336,19 @@ private void resumeRunnables(char c){
@Override
protected void onStop() {
super.onStop();
-
}
+ /* Simple method for updating our Kritz text view, and append a % sign*/
private void updateKritz() {
-
kritzCurrent.setText(kritz + "%");
-
}
-
+ /* Simple method for updating our Uber text view, and append a % sign*/
private void updateUber() {
-
uberCurrent.setText(uber + "%");
-
}
+ /* This saves our state, really the only thing we need to save are current uber/ kritz values*/
@Override
protected void onSaveInstanceState(Bundle outState){
@@ -356,34 +359,32 @@ protected void onSaveInstanceState(Bundle outState){
}
- @Override
- public void onBeginningOfSpeech() {
-
- }
-
+ /* This takes a phrase the user has stated and implements logic to search for it's phonetic makeup*/
+ /* In this case, our logic is that if we got a match for a keyphrase, to call searchReset to
+ * do whatever that command the recognized keyphrase cooresponds to
+ * else we just call searchReset with blank string to begin listening again */
@Override
public void onEndOfSpeech() {
if (!recognizer.getSearchName().equals(KWS_SEARCH)) {
searchReset(KWS_SEARCH);
-
}
-
searchReset("");
}
+ /* Here, we have the ability to re-check partial phonetic matches for keyphrases
+ * This is more efficient than rechecking the entire speech phrase again */
@Override
public void onPartialResult(Hypothesis hypothesis) {
if (hypothesis == null)
return;
-
String text = hypothesis.getHypstr();
if (text.equals(KEYPHRASE)){
searchReset(text);
}
-
}
+ /* If we get a result, then we will show it as a toast message and pass the command to searchReset*/
@Override
public void onResult(Hypothesis hypothesis) {
if (hypothesis != null) {
@@ -394,18 +395,15 @@ public void onResult(Hypothesis hypothesis) {
}
+ //TODO: Add exception handling
@Override
- public void onError(Exception e) {
-
- }
-
+ public void onError(Exception e) {}
+ //TODO: setup timeout logic
@Override
- public void onTimeout() {
-
- }
+ public void onTimeout() {}
/*
- resets the counters
+ logic for resetting the counters
*/
public void reset(){
@@ -438,47 +436,23 @@ private void setupRecognizer(File assetsDir) throws IOException {
.setAcousticModel(new File(assetsDir, "en-us-ptm"))
.setDictionary(new File(assetsDir, "cmudict-en-us.dict"))
- // To disable logging of raw audio comment out this call (takes a lot of space on the device)
- //.setRawLogDir(assetsDir)
+ // To disable logging of raw audio comment out this call, artifact from debugging
+ //.setRawLogDir(assetsDir)
- // Threshold to tune for keyphrase to balance between false alarms and misses
- //changed from 1e-45f to 1e-5f with good results
+ // Threshold to tune for keyphrase to balance between false alarms and misses
+ //changed from 1e-45f to 1e-5f with good results
.setKeywordThreshold(1e-5f)
- // Use context-independent phonetic search, context-dependent is too slow for mobile
+ // Use context-independent phonetic search, context-dependent is too slow for mobile
.setBoolean("-allphone_ci", true)
.getRecognizer();
recognizer.addListener(this);
- // Create keyword-activation search.
-// recognizer.addKeyphraseSearch(KWS_SEARCH, KEYPHRASE);
-
// Create grammar-based search for selection between demos
File menuGrammar = new File(assetsDir, "menu.gram");
recognizer.addKeywordSearch(KWS_SEARCH, menuGrammar);
}
- // @Override
-// public boolean onCreateOptionsMenu(Menu menu) {
-// // Inflate the menu; this adds items to the action bar if it is present.
-// getMenuInflater().inflate(R.menu.menu_main, menu);
-// return true;
-// }
-//
-// @Override
-// public boolean onOptionsItemSelected(MenuItem item) {
-// // Handle action bar item clicks here. The action bar will
-// // automatically handle clicks on the Home/Up button, so long
-// // as you specify a parent activity in AndroidManifest.xml.
-// int id = item.getItemId();
-//
-// //noinspection SimplifiableIfStatement
-// if (id == R.id.action_settings) {
-// return true;
-// }
-//
-// return super.onOptionsItemSelected(item);
-// }
}