Skip to content

Commit

Permalink
Merge branch 'master' into release-0.5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestguice committed Dec 2, 2022
2 parents 23d43f3 + 23d5a24 commit 115c8cd
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2018-2021 Forrest Guice
Copyright (C) 2018-2022 Forrest Guice
This file is part of SuntimesCalendars.
SuntimesCalendars is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -64,6 +64,7 @@
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.text.Spannable;
import android.text.SpannableString;
Expand Down Expand Up @@ -110,6 +111,7 @@ public class SuntimesCalendarActivity extends AppCompatActivity

public static final String THEME_LIGHT = "light";
public static final String THEME_DARK = "dark";
public static final String THEME_SYSTEM = "system";
public static final int MIN_PROVIDER_VERSION = 1;
public static final String MIN_SUNTIMES_VERSION = "0.10.3";
public static final String MIN_SUNTIMES_VERSION_STRING = "Suntimes v" + MIN_SUNTIMES_VERSION;
Expand Down Expand Up @@ -317,8 +319,13 @@ public void onCreate(Bundle icicle)
setResult(RESULT_OK);
context = this;

if (config_apptheme != null) {
setTheme(config_apptheme.equals(THEME_LIGHT) ? R.style.AppTheme_Light : R.style.AppTheme_Dark);
if (config_apptheme != null)
{
int resId = config_apptheme.startsWith(THEME_SYSTEM) ? R.style.AppTheme_System
: config_apptheme.startsWith(THEME_LIGHT) ? R.style.AppTheme_Light
: config_apptheme.startsWith(THEME_DARK) ? R.style.AppTheme_Dark
: R.style.AppTheme_Dark;
setTheme(this, resId);
}

super.onCreate(icicle);
Expand All @@ -343,6 +350,19 @@ public void onCreate(Bundle icicle)
}
}

private static int setTheme(Activity activity, int themeResID)
{
activity.setTheme(themeResID);
if (themeResID == R.style.AppTheme_System) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else if (themeResID == R.style.AppTheme_Light) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
} else if (themeResID == R.style.AppTheme_Dark) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
return themeResID;
}

private void initFirstLaunchFragment()
{
firstLaunchFragment = new FirstLaunchFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.forrestguice.suntimeswidget.views.Toast;
import com.forrestguice.suntimescalendars.R;

public class SuntimesCalendarErrorActivity extends AppCompatActivity
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/com/forrestguice/suntimeswidget/views/Toast.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
Copyright (C) 2022 Forrest Guice
This file is part of SuntimesCalendars.
SuntimesCalendars is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SuntimesCalendars is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SuntimesCalendars. If not, see <http://www.gnu.org/licenses/>.
*/

package com.forrestguice.suntimeswidget.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.widget.TextView;

import com.forrestguice.suntimescalendars.R;

/**
* Custom toast methods.. applies version specific bug-fixes to Toast messages.
* bug: [Android 13 dark theme toasts white on white](https://issuetracker.google.com/issues/245108402)
*/
public class Toast
{
public static final int LENGTH_LONG = android.widget.Toast.LENGTH_LONG;
public static final int LENGTH_SHORT = android.widget.Toast.LENGTH_SHORT;

/**
* Applies `backgroundResource` and `textAppearance` for api33+ (and targetSdk is under than 30).
*/
@SuppressLint("ShowToast")
public static android.widget.Toast makeText(Context context, CharSequence text, int duration)
{
android.widget.Toast toast = android.widget.Toast.makeText(context, text, duration);
if (context.getApplicationContext().getApplicationInfo().targetSdkVersion < 30)
{
if (Build.VERSION.SDK_INT >= 33)
{
View v = toast.getView(); // Toast.getView will return null for targetApi R+
if (v != null)
{
v.setBackgroundResource(R.drawable.toast_frame);
TextView message = (TextView) v.findViewById(android.R.id.message);
if (message != null) {
message.setTextAppearance(R.style.ToastTextAppearance);
}
}
}
}
return toast;
}
}
20 changes: 20 additions & 0 deletions app/src/main/res/drawable-v21/toast_frame.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--/* Copyright 2017, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="?android:attr/colorControlNormal" />
<corners android:radius="28dp" />
</shape>
4 changes: 4 additions & 0 deletions app/src/main/res/drawable/toast_frame.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="#FF424242" />
<corners android:radius="28dp" />
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="hr">@color/hr_dark</color>
<color name="text_accent">@color/text_accent_dark</color>
<color name="text_disabled">@color/text_disabled_dark</color>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values-night/icons.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="ic_action_calendar_ref">@drawable/ic_action_calendar</drawable>
<drawable name="ic_action_update_ref">@drawable/ic_action_update</drawable>
<drawable name="ic_action_about_ref">@drawable/ic_action_about</drawable>
<drawable name="ic_action_settings_ref">@drawable/ic_action_settings</drawable>
<drawable name="ic_action_help_ref">@drawable/ic_action_help</drawable>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.System" parent="AppTheme.System.Base">
<item name="toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="bottomSheetDialogTheme">@style/Theme.Design.BottomSheetDialog</item>
</style>
</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values-v16/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="ToastTextAppearance">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textSize">14sp</item>
<item name="android:fontFamily">sans-serif</item>
</style>
</resources>
4 changes: 4 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@
<color name="red_800">#c62828</color>
<color name="orange_900">#e65100</color>

<!--- Night overridable -->
<color name="hr">@color/hr_light</color>
<color name="text_accent">@color/text_accent_light</color>
<color name="text_disabled">@color/text_disabled_light</color>

</resources>
8 changes: 8 additions & 0 deletions app/src/main/res/values/icons.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<drawable name="ic_action_calendar_ref">@drawable/ic_action_calendar_light</drawable>
<drawable name="ic_action_update_ref">@drawable/ic_action_update_light</drawable>
<drawable name="ic_action_about_ref">@drawable/ic_action_about_light</drawable>
<drawable name="ic_action_settings_ref">@drawable/ic_action_settings_light</drawable>
<drawable name="ic_action_help_ref">@drawable/ic_action_help_light</drawable>
</resources>
28 changes: 24 additions & 4 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,45 @@
<style name="AppTheme" parent="AppTheme.Dark">
</style>

<style name="AppTheme.Light" parent="Theme.AppCompat.DayNight.NoActionBar">
<style name="AppTheme.System.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
<item name="hrColor">@color/hr</item>
<item name="text_accentColor">@color/text_accent</item>
<item name="text_disabledColor">@color/text_disabled</item>
<item name="icActionCalendar">@drawable/ic_action_calendar_ref</item>
<item name="icActionUpdate">@drawable/ic_action_update_ref</item>
<item name="icActionAbout">@drawable/ic_action_about_ref</item>
<item name="icActionSettings">@drawable/ic_action_settings_ref</item>
<item name="icActionHelp">@drawable/ic_action_help_ref</item>
</style>
<style name="AppTheme.System" parent="AppTheme.System.Base">
<item name="toolbarTheme">@style/ThemeOverlay.AppCompat.ActionBar</item>
<item name="bottomSheetDialogTheme">@style/Theme.Design.Light.BottomSheetDialog</item>
</style>

<style name="AppTheme.Light" parent="Theme.AppCompat.Light.NoActionBar">
<item name="hrColor">@color/hr_light</item>
<item name="toolbarTheme">@style/ThemeOverlay.AppCompat.ActionBar</item>
<item name="text_accentColor">@color/text_accent_light</item>
<item name="text_disabledColor">@color/text_disabled_light</item>
<item name="icActionCalendar">@drawable/ic_action_calendar_light</item>
<item name="icActionUpdate">@drawable/ic_action_update_light</item>
<item name="icActionAbout">@drawable/ic_action_about_light</item>
<item name="icActionSettings">@drawable/ic_action_settings_light</item>
<item name="icActionHelp">@drawable/ic_action_help_light</item>
<item name="bottomSheetDialogTheme">@style/Theme.Design.Light.BottomSheetDialog</item>
<item name="toolbarTheme">@style/ThemeOverlay.AppCompat.ActionBar</item>
</style>

<style name="AppTheme.Dark" parent="Theme.AppCompat.NoActionBar">
<item name="bottomSheetDialogTheme">@style/Theme.Design.BottomSheetDialog</item>
<item name="hrColor">@color/hr_dark</item>
<item name="toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
<item name="text_accentColor">@color/text_accent_dark</item>
<item name="text_disabledColor">@color/text_disabled_dark</item>
<item name="icActionCalendar">@drawable/ic_action_calendar</item>
<item name="icActionUpdate">@drawable/ic_action_update</item>
<item name="icActionAbout">@drawable/ic_action_about</item>
<item name="icActionSettings">@drawable/ic_action_settings</item>
<item name="icActionHelp">@drawable/ic_action_help</item>
<item name="bottomSheetDialogTheme">@style/Theme.Design.BottomSheetDialog</item>
<item name="toolbarTheme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
Expand All @@ -36,4 +51,9 @@

</style>

<style name="ToastTextAppearance">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textSize">14sp</item>
</style>

</resources>
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sun Dec 09 20:25:10 MST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip

0 comments on commit 115c8cd

Please sign in to comment.