Skip to content

Commit

Permalink
Add typeface option to screensaver
Browse files Browse the repository at this point in the history
  • Loading branch information
tuur29 committed Jan 16, 2019
1 parent dc6e02c commit d22cb69
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 16 deletions.
3 changes: 3 additions & 0 deletions screensaver/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
android:label="@string/settings">
</activity>

<!--Load fonts-->
<meta-data android:name="preloaded_fonts" android:resource="@array/preloaded_fonts"/>

</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class DreamSettingsActivity : FragmentActivity() {
bindPreferenceSummaryToValue(findPreference("maxTranslationDisplacement"))
bindPreferenceSummaryToValue(findPreference("updateSeconds"))
bindPreferenceSummaryToValue(findPreference("language"))
bindPreferenceSummaryToValue(findPreference("fontfamily"))
bindPreferenceSummaryToValue(findPreference("fontSize"))
bindPreferenceSummaryToValue(findPreference("textAlignment"))
bindPreferenceSummaryToValue(findPreference("notifState"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.IntentFilter
import android.content.res.ColorStateList
import android.graphics.Typeface
import android.view.Gravity
import android.widget.ImageView
import android.graphics.drawable.GradientDrawable
import android.os.BatteryManager
import android.util.Log
import androidx.core.content.res.ResourcesCompat
import com.google.android.flexbox.FlexboxLayout
import com.google.android.flexbox.JustifyContent
import net.tuurlievens.fuzzyclock.FuzzyTextGenerator
Expand All @@ -42,6 +44,7 @@ class FuzzyClockDream : DreamService() {
private var maxTranslationDisplacement = 0.0
private var updateSeconds = 60.0
private var language = "default"
private var fontfamily = ""
private var fontSize = 36
private var textAlignment = "center"
private var foregroundColor = "#ffffffff"
Expand Down Expand Up @@ -115,6 +118,7 @@ class FuzzyClockDream : DreamService() {
maxTranslationDisplacement = prefs.getString("maxTranslationDisplacement", maxTranslationDisplacement.toString()).toDouble()
updateSeconds = prefs.getString("updateSeconds", updateSeconds.toString()).toDouble()
language = prefs.getString("language", language)
fontfamily = prefs.getString("fontfamily", fontfamily)
fontSize = prefs.getString("fontSize", fontSize.toString()).toInt()
textAlignment = prefs.getString("textAlignment", textAlignment)
foregroundColor = "#" + Integer.toHexString(prefs.getInt("foregroundColor", 0xFFFFFFFF.toInt()))
Expand Down Expand Up @@ -196,6 +200,11 @@ class FuzzyClockDream : DreamService() {
}
findViewById<TextView>(R.id.clocktext).text = time

val font = applicationContext.resources.getIdentifier(fontfamily, "font", applicationContext.packageName)
if (font != 0) {
findViewById<TextView>(R.id.clocktext).typeface = ResourcesCompat.getFont(applicationContext, font)
}

// update date
if (showDate) {
val loc = Locale(pickedLanguage)
Expand Down
30 changes: 14 additions & 16 deletions screensaver/app/src/main/res/layout/dream.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
>
>

<LinearLayout android:id="@+id/parent"
android:orientation="vertical"
Expand All @@ -21,8 +21,7 @@
android:textColor="#ffffff"
android:ellipsize="none"
android:maxLines="4"
android:scrollHorizontally="false"
/>
android:scrollHorizontally="false"/>

<TextView android:id="@+id/datetext"
android:layout_width="wrap_content"
Expand All @@ -33,18 +32,18 @@
android:singleLine="true"
android:alpha="0.65"
android:scrollHorizontally="false"
/>
/>

<com.google.android.flexbox.FlexboxLayout
android:id="@+id/notifications"
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"
android:layout_marginTop="10dp"
app:justifyContent="center"
app:maxLine="3"
app:flexWrap="wrap">
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/notifications"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
app:justifyContent="center"
app:maxLine="3"
app:flexWrap="wrap">

<TextView android:id="@+id/notificationcount"
android:layout_width="match_parent"
Expand All @@ -53,8 +52,7 @@
android:textColor="#a6a6a6"
android:textAlignment="center"
android:alpha="0.65"
android:scrollHorizontally="false"
/>
android:scrollHorizontally="false"/>

</com.google.android.flexbox.FlexboxLayout>

Expand Down
9 changes: 9 additions & 0 deletions screensaver/app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
android:singleLine="true"
android:maxLines="1"/>

<ListPreference
android:key="fontfamily"
android:title="@string/pref_title_fontfamily"
android:defaultValue=""
android:entries="@array/pref_list_fontfamily_titles"
android:entryValues="@array/pref_list_fontfamily_values"
android:negativeButtonText="@null"
android:positiveButtonText="@null"/>

<ListPreference
android:key="textAlignment"
android:title="@string/pref_title_textAlignment"
Expand Down
7 changes: 7 additions & 0 deletions shared/src/main/res/font/dancing_script.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Dancing Script"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs">
</font-family>
6 changes: 6 additions & 0 deletions shared/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<string name="pref_title_simplerDate">Simpele datum</string>
<string name="pref_title_showStatusbar">Toon statusiconen</string>
<string name="pref_title_showDigitalClock">Toon digitale klok</string>
<string name="pref_title_fontfamily">Lettertype</string>

<string name="msg_notificationaccess">Voor deze functie moet je deze app toegang tot notificaties verlenen</string>
<string name="msg_editbtn">Druk op de rechterbovenhoek van de widget om hem aan te passen</string>
Expand Down Expand Up @@ -91,4 +92,9 @@
<item>Altijd</item>
</string-array>

<string-array name="pref_list_fontfamily_titles">
<item>Normal</item>
<item>Dancing Script</item>
</string-array>

</resources>
5 changes: 5 additions & 0 deletions shared/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@
<item>always</item>
</string-array>

<string-array name="pref_list_fontfamily_values">
<item></item>
<item>dancing_script</item>
</string-array>

</resources>
17 changes: 17 additions & 0 deletions shared/src/main/res/values/font_certs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="com_google_android_gms_fonts_certs">
<item>@array/com_google_android_gms_fonts_certs_dev</item>
<item>@array/com_google_android_gms_fonts_certs_prod</item>
</array>
<string-array name="com_google_android_gms_fonts_certs_dev">
<item>
MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wPPKQmsHxajtWjmQwWfna8mZuSeJS48LIgAZlKkpFeVyxW0qMBujb8X8ETrWy550NaFtI6t9+u7hZeTfHwqNvacKhp1RbE6dBRGWynwMVX8XW8N1+UjFaq6GCJukT4qmpN2afb8sCjUigq0GuMwYXrFVee74bQgLHWGJwPmvmLHC69EH6kWr22ijx4OKXlSIx2xT1AsSHee70w5iDBiK4aph27yH3TxkXy9V89TDdexAcKk/cVHYNnDBapcavl7y0RiQ4biu8ymM8Ga/nmzhRKya6G0cGw8CAQOjgfwwgfkwHQYDVR0OBBYEFI0cxb6VTEM8YYY6FbBMvAPyT+CyMIHJBgNVHSMEgcEwgb6AFI0cxb6VTEM8YYY6FbBMvAPyT+CyoYGapIGXMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbYIJANWFuGx90071MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBABnTDPEF+3iSP0wNfdIjIz1AlnrPzgAIHVvXxunW7SBrDhEglQZBbKJEk5kT0mtKoOD1JMrSu1xuTKEBahWRbqHsXclaXjoBADb0kkjVEJu/Lh5hgYZnOjvlba8Ld7HCKePCVePoTJBdI4fvugnL8TsgK05aIskyY0hKI9L8KfqfGTl1lzOv2KoWD0KWwtAWPoGChZxmQ+nBli+gwYMzM1vAkP+aayLe0a1EQimlOalO762r0GXO0ks+UeXde2Z4e+8S/pf7pITEI/tP+MxJTALw9QUWEv9lKTk+jkbqxbsh8nfBUapfKqYn0eidpwq2AzVp3juYl7//fKnaPhJD9gs=
</item>
</string-array>
<string-array name="com_google_android_gms_fonts_certs_prod">
<item>
MIIEQzCCAyugAwIBAgIJAMLgh0ZkSjCNMA0GCSqGSIb3DQEBBAUAMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYD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exFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions shared/src/main/res/values/preloaded_fonts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<array name="preloaded_fonts" translatable="false">
<item>@font/dancing_script</item>
</array>
</resources>
6 changes: 6 additions & 0 deletions shared/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<string name="pref_title_simplerDate">Simpler date</string>
<string name="pref_title_showStatusbar">Show status icons</string>
<string name="pref_title_showDigitalClock">Show digital clock</string>
<string name="pref_title_fontfamily">Typeface</string>

<string name="msg_notificationaccess">You have to enable Notification Access for this feature to work</string>
<string name="msg_editbtn">Press the top-right corner of the widget to edit it</string>
Expand Down Expand Up @@ -91,4 +92,9 @@
<item>Always</item>
</string-array>

<string-array name="pref_list_fontfamily_titles">
<item>Normal</item>
<item>Dancing Script</item>
</string-array>

</resources>

0 comments on commit d22cb69

Please sign in to comment.