Skip to content

Commit

Permalink
Added party mode!
Browse files Browse the repository at this point in the history
  • Loading branch information
zackarhino committed Dec 11, 2020
1 parent 4e529ad commit a4d1c87
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.fonts.Font;
import android.media.AudioFormat;
import android.media.AudioManager;
Expand All @@ -25,6 +27,7 @@
import com.google.android.material.navigation.NavigationView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.core.content.res.ResourcesCompat;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
Expand All @@ -42,6 +45,12 @@ public class MainActivity extends AppCompatActivity {

public static FloatingActionButton fab;

// Party settings
static final int partyTime = 500;
static ColorDrawable[] partyColors;
public int colorPos = 0;
static Thread partyThread;
public static boolean partyOn = true;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -53,9 +62,19 @@ protected void onCreate(Bundle savedInstanceState) {
Typeface toolbarTypeface = ResourcesCompat.getFont(this, R.font.gingerly);
toolbarTitle.setTypeface(toolbarTypeface);
toolbarTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.toolbarTitleFontSize));

content = findViewById(R.id.content);

// The colors that will be cycled through in party mode
partyColors = new ColorDrawable[]{
new ColorDrawable(getResources().getColor(R.color.red, getTheme())),
new ColorDrawable(getResources().getColor(R.color.orange, getTheme())),
new ColorDrawable(getResources().getColor(R.color.yellow, getTheme())),
new ColorDrawable(getResources().getColor(R.color.green, getTheme())),
new ColorDrawable(getResources().getColor(R.color.blue, getTheme())),
new ColorDrawable(getResources().getColor(R.color.indigo, getTheme())),
new ColorDrawable(getResources().getColor(R.color.violet, getTheme()))
};

fab = findViewById(R.id.fab);

// Default preferences
Expand Down Expand Up @@ -107,7 +126,6 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
editor.apply();
// Setting fab visibilty to the value that was just written to the SharedPreferences
setFabVisibility(sharedPreferences.getBoolean(getString(R.string.key_show_button), true));
Toast.makeText(this, "Show button: " + sharedPreferences.getBoolean(getString(R.string.key_show_button), false), Toast.LENGTH_SHORT).show();
break;
case R.id.action_play_mode_1:
// Play mode 1: Continuous
Expand All @@ -130,12 +148,44 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
editor.putBoolean(getString(R.string.key_show_button), true); // Showing the button
editor.apply();
ToneFragment.setFabListener(ToneFragment.PLAY_MODES.HOLD);
setFabVisibility(true);
break;
case R.id.action_party_mode:
// Flip the boolean
editor.putBoolean(getString(R.string.key_party_mode), !sharedPreferences.getBoolean(getString(R.string.key_party_mode), false));
editor.apply();
setFabVisibility(true);

Log.d("Thread", "Status of party mode: " + sharedPreferences.getBoolean(getString(R.string.key_party_mode), false));

if(sharedPreferences.getBoolean(getString(R.string.key_party_mode), false)){
partyOn = true;
// Cycling through colors in party mode
partyThread = new Thread("partyThread"){
final ActionBar actionBar = getSupportActionBar();
@Override
public void run() {
while (partyOn){
actionBar.setBackgroundDrawable(partyColors[colorPos]);
try {
Thread.sleep(partyTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(colorPos >= partyColors.length-1){
colorPos = 0;
}else{
colorPos++;
}

}
}
};
partyThread.start();
}else {
partyOn = false;
final ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.licc_blue, getTheme())));
}
break;
default:
Log.d("Menu", "Unrecognized menu item");
Expand All @@ -151,6 +201,10 @@ public boolean onSupportNavigateUp() {
|| super.onSupportNavigateUp();
}

/**
* Sets visibility of fab
* @param isVisible Visibility of fab
*/
public void setFabVisibility(boolean isVisible){
if(isVisible){
fab.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ public boolean onTouch(View v, MotionEvent event) {
}

// Methods

/**
* Sets the fab listener based on the play mode constant that is passed
* @param listenerType The listener type to pass
*/
@SuppressLint("ClickableViewAccessibility")
public static void setFabListener(int listenerType){
// Unsetting any listeners
Expand Down Expand Up @@ -248,7 +253,7 @@ public static void startTone(float frequency){
}

/**
* Stops any tone that is currently playing
* Stops any tone that is currently playings
*/
public static void stopTone(){
// Ending tone if there are any playing
Expand Down
18 changes: 11 additions & 7 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>


<!-- App colors -->
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="licc_dark_blue">#05516A</color>
<color name="licc_blue">#ff0099cc</color>
<color name="eggshell">#FFF0EAD6</color>


<!-- Party Colors -->
<color name="red">#FF0000</color>
<color name="orange">#F57C00</color>
<color name="yellow">#A0AC00</color>
<color name="green">#008700</color>
<color name="blue">#0000FF</color>
<color name="indigo">#303F9F</color>
<color name="violet">#7B1FA2</color>
</resources>

0 comments on commit a4d1c87

Please sign in to comment.