Skip to content

Commit

Permalink
Merge pull request #992 from divadsn/snow
Browse files Browse the repository at this point in the history
#MoarSnow
  • Loading branch information
divadsn authored Dec 8, 2017
2 parents 2939924 + c549583 commit c051960
Show file tree
Hide file tree
Showing 23 changed files with 148 additions and 66 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: android
dist: precise
dist: trusty
group: edge
jdk: oraclejdk8
branches:
except:
Expand All @@ -10,10 +11,11 @@ android:
components:
- tools
- platform-tools
- build-tools-27.0.1
- build-tools-27.0.2
- android-27
- extra-google-m2repository
before_install:
before_install:
- yes | sdkmanager "platforms;android-27"
- chmod a+x ./scripts/deploy-*.sh
- chmod a+x ./scripts/changelog.sh
- chmod a+x ./scripts/s3-upload.sh
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if (localPropsFile.exists()) {

android {
compileSdkVersion 27
buildToolsVersion '27.0.1'
buildToolsVersion '27.0.2'

signingConfigs {
travis {
Expand Down Expand Up @@ -94,7 +94,7 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
def supportLibVersion = '27.0.1'
def supportLibVersion = '27.0.2'
implementation "com.android.support:support-v4:${supportLibVersion}"
implementation "com.android.support:recyclerview-v7:${supportLibVersion}"
implementation "com.android.support:palette-v7:${supportLibVersion}"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/ch/deletescape/lawnchair/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,11 @@ private void setupViews() {

if (mSnowfallEnabled) {
Log.d(TAG, "inflating snowfall");
getLayoutInflater().inflate(mPlanesEnabled ? R.layout.snowfall_planes : R.layout.snowfall, (ViewGroup) findViewById(R.id.launcher_background), true);
if (!Utilities.isBlacklistedAppInstalled(this)) {
getLayoutInflater().inflate(mPlanesEnabled ? R.layout.snowfall_planes : R.layout.snowfall, (ViewGroup) findViewById(R.id.launcher_background), true);
} else {
getLayoutInflater().inflate(R.layout.snowfall_smiles, (ViewGroup) findViewById(R.id.launcher_background), true);
}
}

if (mPlanesEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ interface IPreferenceProvider {
val hotseatIconScale: Float
val hotseatHeightScale: Float
val enablePhysics: Boolean
val snowflakeSizeScale: Float
val snowflakesNum: String

// -----------------
// GENERAL - BITS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ object PreferenceFlags {
const val KEY_NUM_COLS_DRAWER = "pref_numColsDrawer"
const val KEY_HOTSEAT_ICONS = "pref_numHotseatIcons"
const val KEY_PREF_NUM_ROWS_DRAWER = "pref_numRowsDrawer"
const val KEY_PREF_SNOWFLAKES_NUM = "pref_snowflakesNum"

// Strings
const val KEY_WEATHER_PROVIDER = "pref_weatherProvider"
Expand All @@ -29,6 +30,7 @@ object PreferenceFlags {
const val KEY_PREF_ALL_APPS_ICON_SCALE = "pref_allAppsIconScale"
const val KEY_PREF_ALL_APPS_ICON_TEXT_SCALE = "pref_allAppsIconTextScale"
const val KEY_PREF_ALL_APPS_ICON_PADDING_SCALE = "pref_allAppsIconPaddingScale"
const val KEY_PREF_SNOWFLAKE_SIZE_SCALE = "pref_snowflakeSizeScale"

//Ints
const val KEY_BLUR_MODE = "pref_blurMode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ open class PreferenceImpl(context: Context) : IPreferenceProvider {
override val iconLabelsInTwoLines by BooleanPref(PreferenceFlags.KEY_ICON_LABELS_IN_TWO_LINES, false)
override val animatedClockIconAlternativeClockApps by BooleanPref(PreferenceFlags.KEY_ANIMATED_CLOCK_ICON_ALTERNATIVE_CLOCK_APPS, false)
override val enablePhysics by BooleanPref(PreferenceFlags.KEY_ENABLE_PHYSICS, true)
override val snowflakeSizeScale by FloatPref(PreferenceFlags.KEY_PREF_SNOWFLAKE_SIZE_SCALE, 1f)
override val snowflakesNum by StringPref(PreferenceFlags.KEY_PREF_SNOWFLAKES_NUM, "200")

override fun lightStatusBarKeyCache(default: Boolean): Boolean {
return getBoolean(PreferenceFlags.KEY_LIGHT_STATUS_BAR, default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public void run() {
case PreferenceFlags.KEY_PREF_HOTSEAT_SHOW_PAGE_INDICATOR:
case PreferenceFlags.KEY_TWO_ROW_DOCK:
case PreferenceFlags.KEY_PREF_SNOWFALL:
case PreferenceFlags.KEY_PREF_SNOWFLAKE_SIZE_SCALE:
case PreferenceFlags.KEY_PREF_SNOWFLAKES_NUM:
mLauncher.scheduleKill();
case PreferenceFlags.KEY_BACKPORT_ADAPTIVE_ICONS:
mLauncher.scheduleReloadIcons();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,12 @@ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, l
/**
* This fragment shows the launcher preferences.
*/
public static class LauncherSettingsFragment extends BaseFragment implements Preference.OnPreferenceChangeListener {
public static class LauncherSettingsFragment extends BaseFragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName(LauncherFiles.SHARED_PREFERENCES_KEY);

Preference prefSnowfallEnabled = findPreference(FeatureFlags.KEY_PREF_SNOWFALL);
prefSnowfallEnabled.setOnPreferenceChangeListener(this);
if (Utilities.getPrefs(getActivity()).getEnableSnowfall()) {
prefSnowfallEnabled.setSummary(R.string.snowfall_enabled);
}
}

@Override
Expand All @@ -196,19 +190,6 @@ public void onResume() {
super.onResume();
getActivity().setTitle(R.string.settings_button_text);
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference.getKey() != null) {
switch (preference.getKey()) {
case FeatureFlags.KEY_PREF_SNOWFALL:
findPreference(FeatureFlags.KEY_PREF_SNOWFALL).setSummary((boolean) newValue ? R.string.snowfall_enabled : R.string.snowfall_summary);
break;
}
return true;
}
return false;
}
}

public static class SubSettingsFragment extends BaseFragment implements Preference.OnPreferenceChangeListener {
Expand Down Expand Up @@ -252,6 +233,12 @@ public void onCreate(Bundle savedInstanceState) {
if (BuildConfig.ENABLE_LAWNFEED && enabledState == ILauncherClient.Companion.DISABLED_NO_PROXY_APP) {
getPreferenceScreen().removePreference(findPreference(FeatureFlags.KEY_PREF_SHOW_NOW_TAB));
}
} else if (getContent() == R.xml.launcher_snowfall_preferences) {
Preference prefSnowfallEnabled = findPreference(FeatureFlags.KEY_PREF_SNOWFALL);
prefSnowfallEnabled.setOnPreferenceChangeListener(this);
if (Utilities.getPrefs(getActivity()).getEnableSnowfall()) {
prefSnowfallEnabled.setSummary(R.string.snowfall_enabled);
}
}
}

Expand All @@ -268,6 +255,11 @@ private void updateEnabledState(String weatherProvider) {
prefWeatherApiKey.setEnabled(!awarenessApiEnabled);
}

private void updateSnowfallSummary(boolean enabled) {
Preference prefEnableSnowfall = findPreference(FeatureFlags.KEY_PREF_SNOWFALL);
prefEnableSnowfall.setSummary(enabled ? R.string.snowfall_enabled : R.string.enable_snowfall_summary);
}

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (preference.getKey() != null) {
Expand All @@ -281,6 +273,9 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
checkPermission(Manifest.permission.ACCESS_FINE_LOCATION);
}
break;
case FeatureFlags.KEY_PREF_SNOWFALL:
updateSnowfallSummary((boolean) newValue);
break;
}
return true;
}
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/ch/deletescape/lawnchair/snow/Drawables.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ internal fun Drawable.toBitmap(rotation: Float): Bitmap {
internal fun VectorDrawable.toBitmap(rotation: Float): Bitmap {
val bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.rotate(rotation, intrinsicWidth / 2f, intrinsicHeight / 2f);
if (rotation != 0f) {
canvas.rotate(rotation, intrinsicWidth / 2f, intrinsicHeight / 2f);
}

setBounds(0, 0, canvas.width, canvas.height)
setTint(Color.WHITE)
draw(canvas)
Expand Down
21 changes: 11 additions & 10 deletions app/src/main/java/ch/deletescape/lawnchair/snow/SnowfallView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,56 @@ import android.util.AttributeSet
import android.view.View

import ch.deletescape.lawnchair.R
import java.util.*
import ch.deletescape.lawnchair.Utilities

/**
* Copyright (C) 2016 JetRadar, licensed under Apache License 2.0
* https://github.com/JetradarMobile/android-snowfall/
*/
class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private val DEFAULT_SNOWFLAKES_NUM = 200
private val DEFAULT_SNOWFLAKE_ALPHA_MIN = 150
private val DEFAULT_SNOWFLAKE_ALPHA_MAX = 250
private val DEFAULT_SNOWFLAKE_ANGLE_MAX = 10
private val DEFAULT_SNOWFLAKE_SIZE_MIN_IN_DP = 2
private val DEFAULT_SNOWFLAKE_SIZE_MAX_IN_DP = 8
private val DEFAULT_SNOWFLAKE_SPEED_MIN = 2
private val DEFAULT_SNOWFLAKE_SPEED_MAX = 8
private val DEFAULT_SNOWFLAKE_ROTATION = 45f
private val DEFAULT_SNOWFLAKES_FADING_ENABLED = false
private val DEFAULT_SNOWFLAKES_ALREADY_FALLING = false

private val snowflakesNum: Int
private val snowflakeImage: Bitmap?
private val snowflakeAlphaMin: Int
private val snowflakeAlphaMax: Int
private val snowflakeAngleMax: Int
private val snowflakeSizeMinInPx: Int
private val snowflakeSizeMaxInPx: Int
private val snowflakeSizeScale: Float
private val snowflakeSpeedMin: Int
private val snowflakeSpeedMax: Int
private val snowflakeRotation: Float
private val snowflakeImage: Bitmap?
private val snowflakesFadingEnabled: Boolean
private val snowflakesAlreadyFalling: Boolean

private val updateSnowflakesThread: UpdateSnowflakesThread
private var snowflakes: Array<Snowflake>? = null

private var rotationAngles = floatArrayOf(45f, 135f, 225f, 315f)

init {
val attrs = context.obtainStyledAttributes(attrs, R.styleable.SnowfallView)
val rotation = rotationAngles[Random().nextInt(4)]

try {
snowflakesNum = attrs.getInt(R.styleable.SnowfallView_snowflakesNum, DEFAULT_SNOWFLAKES_NUM)
snowflakeImage = attrs.getDrawable(R.styleable.SnowfallView_snowflakeImage)?.toBitmap(rotation)
snowflakesNum = Utilities.getPrefs(context).snowflakesNum.toInt()
snowflakeAlphaMin = attrs.getInt(R.styleable.SnowfallView_snowflakeAlphaMin, DEFAULT_SNOWFLAKE_ALPHA_MIN)
snowflakeAlphaMax = attrs.getInt(R.styleable.SnowfallView_snowflakeAlphaMax, DEFAULT_SNOWFLAKE_ALPHA_MAX)
snowflakeAngleMax = attrs.getInt(R.styleable.SnowfallView_snowflakeAngleMax, DEFAULT_SNOWFLAKE_ANGLE_MAX)
snowflakeSizeMinInPx = attrs.getDimensionPixelSize(R.styleable.SnowfallView_snowflakeSizeMin, dpToPx(DEFAULT_SNOWFLAKE_SIZE_MIN_IN_DP))
snowflakeSizeMaxInPx = attrs.getDimensionPixelSize(R.styleable.SnowfallView_snowflakeSizeMax, dpToPx(DEFAULT_SNOWFLAKE_SIZE_MAX_IN_DP))
snowflakeSizeScale = Utilities.getPrefs(context).snowflakeSizeScale
snowflakeSpeedMin = attrs.getInt(R.styleable.SnowfallView_snowflakeSpeedMin, DEFAULT_SNOWFLAKE_SPEED_MIN)
snowflakeSpeedMax = attrs.getInt(R.styleable.SnowfallView_snowflakeSpeedMax, DEFAULT_SNOWFLAKE_SPEED_MAX)
snowflakeRotation = attrs.getFloat(R.styleable.SnowfallView_snowflakeRotation, DEFAULT_SNOWFLAKE_ROTATION)
snowflakeImage = attrs.getDrawable(R.styleable.SnowfallView_snowflakeImage)?.toBitmap(snowflakeRotation)
snowflakesFadingEnabled = attrs.getBoolean(R.styleable.SnowfallView_snowflakesFadingEnabled, DEFAULT_SNOWFLAKES_FADING_ENABLED)
snowflakesAlreadyFalling = attrs.getBoolean(R.styleable.SnowfallView_snowflakesAlreadyFalling, DEFAULT_SNOWFLAKES_ALREADY_FALLING)
} finally {
Expand Down Expand Up @@ -101,8 +102,8 @@ class SnowfallView(context: Context, attrs: AttributeSet) : View(context, attrs)
alphaMin = snowflakeAlphaMin,
alphaMax = snowflakeAlphaMax,
angleMax = snowflakeAngleMax,
sizeMinInPx = snowflakeSizeMinInPx,
sizeMaxInPx = snowflakeSizeMaxInPx,
sizeMinInPx = (snowflakeSizeMinInPx * snowflakeSizeScale).toInt(),
sizeMaxInPx = (snowflakeSizeMaxInPx * snowflakeSizeScale).toInt(),
speedMin = snowflakeSpeedMin,
speedMax = snowflakeSpeedMax,
fadingEnabled = snowflakesFadingEnabled,
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/ic_emoticon_dead.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/emoticon_dead.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#000" android:pathData="M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22A10,10 0 0,0 22,12C22,6.47 17.5,2 12,2M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20M16.18,7.76L15.12,8.82L14.06,7.76L13,8.82L14.06,9.88L13,10.94L14.06,12L15.12,10.94L16.18,12L17.24,10.94L16.18,9.88L17.24,8.82L16.18,7.76M7.82,12L8.88,10.94L9.94,12L11,10.94L9.94,9.88L11,8.82L9.94,7.76L8.88,8.82L7.82,7.76L6.76,8.82L7.82,9.88L6.76,10.94L7.82,12M12,14C9.67,14 7.69,15.46 6.89,17.5H17.11C16.31,15.46 14.33,14 12,14Z" />
</vector>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/ic_snowflake.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!-- drawable/snowflake.xml -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="@color/accent_material_light" android:pathData="M20.79,13.95L18.46,14.57L16.46,13.44V10.56L18.46,9.43L20.79,10.05L21.31,8.12L19.54,7.65L20,5.88L18.07,5.36L17.45,7.69L15.45,8.82L13,7.38V5.12L14.71,3.41L13.29,2L12,3.29L10.71,2L9.29,3.41L11,5.12V7.38L8.5,8.82L6.5,7.69L5.92,5.36L4,5.88L4.47,7.65L2.7,8.12L3.22,10.05L5.55,9.43L7.55,10.56V13.45L5.55,14.58L3.22,13.96L2.7,15.89L4.47,16.36L4,18.12L5.93,18.64L6.55,16.31L8.55,15.18L11,16.62V18.88L9.29,20.59L10.71,22L12,20.71L13.29,22L14.7,20.59L13,18.88V16.62L15.5,15.17L17.5,16.3L18.12,18.63L20,18.12L19.53,16.35L21.3,15.88L20.79,13.95M9.5,10.56L12,9.11L14.5,10.56V13.44L12,14.89L9.5,13.44V10.56Z" />
</vector>
4 changes: 1 addition & 3 deletions app/src/main/res/layout/snowfall.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<ch.deletescape.lawnchair.snow.SnowfallView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:snowflakesNum="150" />
android:layout_height="match_parent" />
6 changes: 3 additions & 3 deletions app/src/main/res/layout/snowfall_planes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
app:snowflakeImage="@drawable/plane"
app:snowflakeSizeMin="16dp"
app:snowflakeSizeMax="24dp"
app:snowflakesNum="150" />
app:snowflakeRotation="135.0"
app:snowflakeSizeMin="18dp"
app:snowflakeSizeMax="32dp" />
9 changes: 9 additions & 0 deletions app/src/main/res/layout/snowfall_smiles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<ch.deletescape.lawnchair.snow.SnowfallView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:snowflakeImage="@drawable/ic_emoticon_dead"
app:snowflakeRotation="0"
app:snowflakeSizeMin="18dp"
app:snowflakeSizeMax="32dp" />
4 changes: 2 additions & 2 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@

<!-- SnowfallView snowflake attributes -->
<declare-styleable name="SnowfallView">
<attr name="snowflakesNum" format="integer"/>
<attr name="snowflakeImage" format="reference"/>
<attr name="snowflakeAlphaMin" format="integer"/>
<attr name="snowflakeAlphaMax" format="integer"/>
<attr name="snowflakeAngleMax" format="integer"/>
<attr name="snowflakeSizeMin" format="dimension"/>
<attr name="snowflakeSizeMax" format="dimension"/>
<attr name="snowflakeSpeedMin" format="integer"/>
<attr name="snowflakeSpeedMax" format="integer"/>
<attr name="snowflakeRotation" format="float" />
<attr name="snowflakeImage" format="reference"/>
<attr name="snowflakesFadingEnabled" format="boolean"/>
<attr name="snowflakesAlreadyFalling" format="boolean"/>
</declare-styleable>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/customizations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,13 @@
<item>M50,0A50,50,0,0 1 100,50 L100,85 A15,15,0,0 1 85,100 L50,100 A50,50,0,0 1 50,0z</item>
</array>

<string-array name="snowflakesNumValues">
<item>100</item>
<item>150</item>
<item>200</item>
<item>250</item>
<item>300</item>
</string-array>

<string name="generalDefault" translatable="false">default</string>
</resources>
11 changes: 7 additions & 4 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,14 @@
<string name="reset_alternative_icons_title">Reset alternative app icons?</string>
<string name="reset_alternative_icons">You have %1$d apps with alternative icons, do you want to reset them?</string>
<string name="error_no_browser">No activity found to handle URLs</string>
<string name="pref_cat_special">Special settings</string>
<string name="snowfall_title">Enable Snowfall on home screen</string>
<string name="snowfall_summary">Can cause performance issues.</string>
<string name="snowfall_title">Snowfall</string>
<string name="snowfall_pref_summary" translatable="false">IT\'S WINTER MY DUDES</string>
<string name="enable_snowfall_title">Enable Snowfall on home screen</string>
<string name="enable_snowfall_summary">Can cause performance issues.</string>
<string name="snowfall_enabled">\"Let it snow, let it snow, let it snow!\"</string>

<string name="snowflake_size_scale">Snowflake size scale</string>
<string name="snowflakes_num">Max number of snowflakes</string>

<string name="lawnfeed_outdated_title">Lawnfeed update required</string>
<string name="lawnfeed_outdated">A newer version of Lawnfeed is required in order to work with this version of Lawnchair.\n\nBefore installing the update you will probably need to uninstall the current version of Lawnfeed.\n\nDo you want to download it now?</string>
</resources>
19 changes: 6 additions & 13 deletions app/src/main/res/xml/launcher_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,16 @@
app:content="@xml/launcher_debug_preferences"
app:longClickContent="@xml/launcher_hidden_preferences" />

<ch.deletescape.lawnchair.settings.ui.SubPreference
android:title="@string/snowfall_title"
android:summary="@string/snowfall_pref_summary"
android:icon="@drawable/ic_snowflake"
app:content="@xml/launcher_snowfall_preferences" />

<ch.deletescape.lawnchair.settings.ui.SubPreference
android:title="@string/about_title"
android:summary="@string/about_pref_summary"
android:icon="@drawable/ic_information"
app:content="@xml/launcher_about_preferences" />

<android.support.v7.preference.PreferenceCategory
android:key="prefCat_special"
android:title="@string/pref_cat_special">

<SwitchPreference
android:key="pref_snowfall"
android:title="@string/snowfall_title"
android:summary="@string/snowfall_summary"
android:defaultValue="false"
android:persistent="true" />

</android.support.v7.preference.PreferenceCategory>

</android.support.v7.preference.PreferenceScreen>
Loading

0 comments on commit c051960

Please sign in to comment.