From fe9cec4576e8f9017e96ba2abb343b74d0102b79 Mon Sep 17 00:00:00 2001 From: tehcneko <7764726+tehcneko@users.noreply.github.com> Date: Wed, 14 Apr 2021 17:14:02 +0800 Subject: [PATCH] [app] Remake holiday headers (#488) --- .../customiuizer/holidays/HolidayHelper.java | 48 ---------- .../mikanoshi/customiuizer/utils/Helpers.java | 25 ------ .../manager/ui/activity/MainActivity.java | 14 ++- .../lsposed/manager/util/holiday/Helpers.java | 48 ++++++++++ .../manager/util/holiday/HolidayHelper.java | 87 +++++++++++++++++++ app/src/main/res/drawable/pride_flag.xml | 24 +++++ app/src/main/res/layout/activity_main.xml | 24 +++-- 7 files changed, 180 insertions(+), 90 deletions(-) delete mode 100644 app/src/main/java/name/mikanoshi/customiuizer/holidays/HolidayHelper.java delete mode 100644 app/src/main/java/name/mikanoshi/customiuizer/utils/Helpers.java create mode 100644 app/src/main/java/org/lsposed/manager/util/holiday/Helpers.java create mode 100644 app/src/main/java/org/lsposed/manager/util/holiday/HolidayHelper.java create mode 100644 app/src/main/res/drawable/pride_flag.xml diff --git a/app/src/main/java/name/mikanoshi/customiuizer/holidays/HolidayHelper.java b/app/src/main/java/name/mikanoshi/customiuizer/holidays/HolidayHelper.java deleted file mode 100644 index c1a308aa..00000000 --- a/app/src/main/java/name/mikanoshi/customiuizer/holidays/HolidayHelper.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This file is part of LSPosed. - * - * LSPosed 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. - * - * LSPosed 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 LSPosed. If not, see . - * - * Copyright (C) 2021 LSPosed Contributors - */ - -package name.mikanoshi.customiuizer.holidays; - -import android.app.Activity; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ImageView; - -import org.lsposed.manager.R; - -import name.mikanoshi.customiuizer.utils.Helpers; - -public class HolidayHelper { - - public static void setup(Activity activity) { - Helpers.detectHoliday(); - - ImageView header = activity.findViewById(R.id.holiday_header); - - if (Helpers.currentHoliday == Helpers.Holidays.NEWYEAR) { - header.setImageResource(R.drawable.newyear_header); - header.setVisibility(View.VISIBLE); - } else if (Helpers.currentHoliday == Helpers.Holidays.LUNARNEWYEAR) { - header.setImageResource(R.drawable.lunar_newyear_header); - header.setVisibility(View.VISIBLE); - } else { - ((ViewGroup) header.getParent()).removeView(header); - } - } -} diff --git a/app/src/main/java/name/mikanoshi/customiuizer/utils/Helpers.java b/app/src/main/java/name/mikanoshi/customiuizer/utils/Helpers.java deleted file mode 100644 index f7d7eed2..00000000 --- a/app/src/main/java/name/mikanoshi/customiuizer/utils/Helpers.java +++ /dev/null @@ -1,25 +0,0 @@ -package name.mikanoshi.customiuizer.utils; - -import java.util.Calendar; - -public class Helpers { - - public static Holidays currentHoliday = Holidays.NONE; - - public enum Holidays { - NONE, NEWYEAR, LUNARNEWYEAR - } - - public static void detectHoliday() { - currentHoliday = Holidays.NONE; - Calendar cal = Calendar.getInstance(); - int month = cal.get(Calendar.MONTH); - int monthDay = cal.get(Calendar.DAY_OF_MONTH); - //int year = cal.get(Calendar.YEAR); - - // Lunar NY - if ((month == 0 && monthDay > 15) || month == 1) currentHoliday = Holidays.LUNARNEWYEAR; - // NY - else if (month == 0 || month == 11) currentHoliday = Holidays.NEWYEAR; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/lsposed/manager/ui/activity/MainActivity.java b/app/src/main/java/org/lsposed/manager/ui/activity/MainActivity.java index 20fcb963..eb6f037b 100644 --- a/app/src/main/java/org/lsposed/manager/ui/activity/MainActivity.java +++ b/app/src/main/java/org/lsposed/manager/ui/activity/MainActivity.java @@ -21,6 +21,7 @@ package org.lsposed.manager.ui.activity; import android.content.Intent; +import android.content.res.ColorStateList; import android.os.Build; import android.os.Bundle; import android.text.method.LinkMovementMethod; @@ -44,11 +45,10 @@ import org.lsposed.manager.util.GlideHelper; import org.lsposed.manager.util.ModuleUtil; import org.lsposed.manager.util.NavUtil; import org.lsposed.manager.util.chrome.LinkTransformationMethod; +import org.lsposed.manager.util.holiday.HolidayHelper; import java.util.Locale; -import name.mikanoshi.customiuizer.holidays.HolidayHelper; -import name.mikanoshi.customiuizer.utils.Helpers; import rikka.core.res.ResourcesKt; public class MainActivity extends BaseActivity { @@ -107,8 +107,14 @@ public class MainActivity extends BaseActivity { binding.statusSummary.setText(R.string.selinux_policy_not_loaded_summary); } else { binding.statusTitle.setText(R.string.activated); - if (Helpers.currentHoliday == Helpers.Holidays.LUNARNEWYEAR) { - cardBackgroundColor = 0xfff05654; + HolidayHelper.CardColors cardColors = HolidayHelper.getHolidayColors(); + if (cardColors.textColor != 0) { + binding.statusIcon.setImageTintList(ColorStateList.valueOf(cardColors.textColor)); + binding.statusTitle.setTextColor(ColorStateList.valueOf(cardColors.textColor)); + binding.statusSummary.setTextColor(ColorStateList.valueOf(cardColors.textColor)); + } + if (cardColors.backgroundColor != 0) { + cardBackgroundColor = cardColors.backgroundColor; } else { cardBackgroundColor = ResourcesKt.resolveColor(getTheme(), R.attr.colorNormal); } diff --git a/app/src/main/java/org/lsposed/manager/util/holiday/Helpers.java b/app/src/main/java/org/lsposed/manager/util/holiday/Helpers.java new file mode 100644 index 00000000..b11c4a56 --- /dev/null +++ b/app/src/main/java/org/lsposed/manager/util/holiday/Helpers.java @@ -0,0 +1,48 @@ +/* + * This file is part of LSPosed. + * + * LSPosed 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. + * + * LSPosed 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 LSPosed. If not, see . + * + * Copyright (C) 2021 LSPosed Contributors + */ + +package org.lsposed.manager.util.holiday; + +import java.util.Calendar; + +public class Helpers { + + public static Holidays currentHoliday = Holidays.NONE; + + public enum Holidays { + NONE, NEWYEAR, LUNARNEWYEAR, PRIDE + } + + public static void detectHoliday() { + currentHoliday = Holidays.NONE; + Calendar cal = Calendar.getInstance(); + int month = cal.get(Calendar.MONTH); + int monthDay = cal.get(Calendar.DAY_OF_MONTH); + //int year = cal.get(Calendar.YEAR); + + // Lunar NY + if ((month == 0 && monthDay > 15) || month == 1) { + currentHoliday = Holidays.LUNARNEWYEAR; + } else if (month == 0 || month == 11) { // NY + currentHoliday = Holidays.NEWYEAR; + } else if (month == 5) { // Pride Month + currentHoliday = Holidays.PRIDE; + } + } +} diff --git a/app/src/main/java/org/lsposed/manager/util/holiday/HolidayHelper.java b/app/src/main/java/org/lsposed/manager/util/holiday/HolidayHelper.java new file mode 100644 index 00000000..2a5324e9 --- /dev/null +++ b/app/src/main/java/org/lsposed/manager/util/holiday/HolidayHelper.java @@ -0,0 +1,87 @@ +/* + * This file is part of LSPosed. + * + * LSPosed 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. + * + * LSPosed 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 LSPosed. If not, see . + * + * Copyright (C) 2021 LSPosed Contributors + */ + +package org.lsposed.manager.util.holiday; + +import android.app.Activity; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.drawable.ColorDrawable; +import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.ImageView; + +import org.lsposed.manager.R; + +public class HolidayHelper { + + public static void setup(Activity activity) { + Helpers.detectHoliday(); + + ImageView header = activity.findViewById(R.id.holiday_header); + + switch (Helpers.currentHoliday) { + case NEWYEAR: + header.setLayoutParams( + new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + header.setImageResource(R.drawable.newyear_header); + header.setVisibility(View.VISIBLE); + break; + case LUNARNEWYEAR: + header.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + header.setImageResource(R.drawable.lunar_newyear_header); + header.setVisibility(View.VISIBLE); + ((FrameLayout) header.getParent()).requestLayout(); + break; + case PRIDE: + header.setForeground(new ColorDrawable(0x15000000)); + header.setImageResource(R.drawable.pride_flag); + header.setVisibility(View.VISIBLE); + break; + case NONE: + default: + ((ViewGroup) header.getParent()).removeView(header); + } + } + + public static CardColors getHolidayColors() { + switch (Helpers.currentHoliday) { + case LUNARNEWYEAR: + return new CardColors(0xfff05654, 0); + case NEWYEAR: + return new CardColors(0xff677a89, 0); + case PRIDE: + return new CardColors(0, 0xffffffff); + case NONE: + default: + return new CardColors(0, 0); + } + } + + public static class CardColors { + public int backgroundColor; + public int textColor; + + public CardColors(int background, int text) { + backgroundColor = background; + textColor = text; + } + } +} diff --git a/app/src/main/res/drawable/pride_flag.xml b/app/src/main/res/drawable/pride_flag.xml new file mode 100644 index 00000000..5f67afe6 --- /dev/null +++ b/app/src/main/res/drawable/pride_flag.xml @@ -0,0 +1,24 @@ + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a1061e38..82570909 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -28,18 +28,6 @@ app:edgeToEdge="true" app:fitSystemWindowsInsets="start|end"> - - + +