Implemented cycle mode
This commit is contained in:
parent
09578200e9
commit
e9e8f9e7ba
|
@ -1,5 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
|
|
|
@ -17,12 +17,15 @@ import android.support.v7.app.AppCompatActivity;
|
|||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.transition.Explode;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* An example full-screen activity that shows and hides the system UI (i.e.
|
||||
|
@ -49,6 +52,10 @@ public class MainActivity extends AppCompatActivity {
|
|||
private final Handler mHideHandler = new Handler();
|
||||
private View mContentView;
|
||||
private FloatingActionButton mFab;
|
||||
private View mainView;
|
||||
private Timer timer;
|
||||
private TimerTask timerTask;
|
||||
private Random random;
|
||||
private final Runnable mHidePart2Runnable = new Runnable() {
|
||||
@SuppressLint("InlinedApi")
|
||||
@Override
|
||||
|
@ -91,13 +98,16 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
mContentView = findViewById(R.id.fullscreen_content);
|
||||
mFab = (FloatingActionButton)findViewById(R.id.fab);
|
||||
mainView = findViewById(R.id.main_layout);
|
||||
timer = new Timer();
|
||||
random = new Random();
|
||||
|
||||
// Set up the user interaction to manually show or hide the system UI.
|
||||
mContentView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (!isSwiping) {
|
||||
setBackgroundToRandomColour(view);
|
||||
setBackgroundToRandomColour();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -199,19 +209,21 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
/**
|
||||
* Sets a random background colour when activity resumes
|
||||
* Adds setting background regularly based on preference
|
||||
*/
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setBackgroundToRandomColour(findViewById(R.id.main_layout));
|
||||
setBackgroundToRandomColour();
|
||||
setTimer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets background colour to a randomly-generated pastel colour
|
||||
*/
|
||||
public void setBackgroundToRandomColour(View view) {
|
||||
private void setBackgroundToRandomColour() {
|
||||
int randomColour = generateRandomColour();
|
||||
view.setBackgroundColor(randomColour);
|
||||
mainView.setBackgroundColor(randomColour);
|
||||
((TextView)mContentView).setText(String.format("#%s", Integer.toHexString(randomColour).substring(2)));
|
||||
|
||||
// Set the text colour to something more readable given the colour type
|
||||
|
@ -232,19 +244,48 @@ public class MainActivity extends AppCompatActivity {
|
|||
/**
|
||||
* Generates a random pastel colour
|
||||
*/
|
||||
public int generateRandomColour() {
|
||||
private int generateRandomColour() {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
float saturation = Float.parseFloat(preferences.getString("colour_type", "0.3"));
|
||||
|
||||
float phiRecip = Float.parseFloat(getResources().getText(R.string.phiRecip).toString());
|
||||
float[] hsv = {
|
||||
(new Random().nextFloat() + phiRecip) % 1 * 360, // random, nicely spaced hue
|
||||
(random.nextFloat() + phiRecip) % 1 * 360, // random, nicely spaced hue
|
||||
saturation,
|
||||
1.0f // value
|
||||
};
|
||||
return Color.HSVToColor(hsv);
|
||||
}
|
||||
|
||||
private void setTimer() {
|
||||
if (timerTask != null) {
|
||||
timerTask.cancel();
|
||||
}
|
||||
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String changeMode = preferences.getString("change_mode", "tap");
|
||||
switch (changeMode) {
|
||||
case "tap":
|
||||
break;
|
||||
case "cycle":
|
||||
timerTask = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
setBackgroundToRandomColour();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
timer.schedule(timerTask, 0, 1000);
|
||||
break;
|
||||
case "leekspin":
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void openSettings(View view) {
|
||||
Intent intent = new Intent(this, SettingsActivity.class);
|
||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.PreferencesFragment.class.getName());
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
</string-array>
|
||||
<string-array name="preferences_mode_values">
|
||||
<item>tap</item>
|
||||
<item>change</item>
|
||||
<item>cycle</item>
|
||||
<item>leekspin</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue