Implemented cycle mode
This commit is contained in:
parent
09578200e9
commit
e9e8f9e7ba
|
@ -1,5 +1,32 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<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">
|
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||||
<OptionsSetting value="true" id="Add" />
|
<OptionsSetting value="true" id="Add" />
|
||||||
<OptionsSetting value="true" id="Remove" />
|
<OptionsSetting value="true" id="Remove" />
|
||||||
|
|
|
@ -17,12 +17,15 @@ import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.transition.Explode;
|
import android.transition.Explode;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.Random;
|
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.
|
* 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 final Handler mHideHandler = new Handler();
|
||||||
private View mContentView;
|
private View mContentView;
|
||||||
private FloatingActionButton mFab;
|
private FloatingActionButton mFab;
|
||||||
|
private View mainView;
|
||||||
|
private Timer timer;
|
||||||
|
private TimerTask timerTask;
|
||||||
|
private Random random;
|
||||||
private final Runnable mHidePart2Runnable = new Runnable() {
|
private final Runnable mHidePart2Runnable = new Runnable() {
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,13 +98,16 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
mContentView = findViewById(R.id.fullscreen_content);
|
mContentView = findViewById(R.id.fullscreen_content);
|
||||||
mFab = (FloatingActionButton)findViewById(R.id.fab);
|
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.
|
// Set up the user interaction to manually show or hide the system UI.
|
||||||
mContentView.setOnClickListener(new View.OnClickListener() {
|
mContentView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (!isSwiping) {
|
if (!isSwiping) {
|
||||||
setBackgroundToRandomColour(view);
|
setBackgroundToRandomColour();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -199,19 +209,21 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a random background colour when activity resumes
|
* Sets a random background colour when activity resumes
|
||||||
|
* Adds setting background regularly based on preference
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
setBackgroundToRandomColour(findViewById(R.id.main_layout));
|
setBackgroundToRandomColour();
|
||||||
|
setTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets background colour to a randomly-generated pastel colour
|
* Sets background colour to a randomly-generated pastel colour
|
||||||
*/
|
*/
|
||||||
public void setBackgroundToRandomColour(View view) {
|
private void setBackgroundToRandomColour() {
|
||||||
int randomColour = generateRandomColour();
|
int randomColour = generateRandomColour();
|
||||||
view.setBackgroundColor(randomColour);
|
mainView.setBackgroundColor(randomColour);
|
||||||
((TextView)mContentView).setText(String.format("#%s", Integer.toHexString(randomColour).substring(2)));
|
((TextView)mContentView).setText(String.format("#%s", Integer.toHexString(randomColour).substring(2)));
|
||||||
|
|
||||||
// Set the text colour to something more readable given the colour type
|
// 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
|
* Generates a random pastel colour
|
||||||
*/
|
*/
|
||||||
public int generateRandomColour() {
|
private int generateRandomColour() {
|
||||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
float saturation = Float.parseFloat(preferences.getString("colour_type", "0.3"));
|
float saturation = Float.parseFloat(preferences.getString("colour_type", "0.3"));
|
||||||
|
|
||||||
float phiRecip = Float.parseFloat(getResources().getText(R.string.phiRecip).toString());
|
float phiRecip = Float.parseFloat(getResources().getText(R.string.phiRecip).toString());
|
||||||
float[] hsv = {
|
float[] hsv = {
|
||||||
(new Random().nextFloat() + phiRecip) % 1 * 360, // random, nicely spaced hue
|
(random.nextFloat() + phiRecip) % 1 * 360, // random, nicely spaced hue
|
||||||
saturation,
|
saturation,
|
||||||
1.0f // value
|
1.0f // value
|
||||||
};
|
};
|
||||||
return Color.HSVToColor(hsv);
|
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) {
|
public void openSettings(View view) {
|
||||||
Intent intent = new Intent(this, SettingsActivity.class);
|
Intent intent = new Intent(this, SettingsActivity.class);
|
||||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.PreferencesFragment.class.getName());
|
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, SettingsActivity.PreferencesFragment.class.getName());
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="preferences_mode_values">
|
<string-array name="preferences_mode_values">
|
||||||
<item>tap</item>
|
<item>tap</item>
|
||||||
<item>change</item>
|
<item>cycle</item>
|
||||||
<item>leekspin</item>
|
<item>leekspin</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in New Issue