[app] Remake holiday headers (#488)

This commit is contained in:
tehcneko 2021-04-14 17:14:02 +08:00 committed by GitHub
parent 535c6e1b60
commit fe9cec4576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 180 additions and 90 deletions

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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);
}
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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;
}
}
}

View File

@ -0,0 +1,24 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="777dp"
android:height="480dp"
android:viewportWidth="777"
android:viewportHeight="480">
<path
android:pathData="M0,0h777v480h-777z"
android:fillColor="#750787"/>
<path
android:pathData="M0,0h777v400h-777z"
android:fillColor="#004dff"/>
<path
android:pathData="M0,0h777v320h-777z"
android:fillColor="#008026"/>
<path
android:pathData="M0,0h777v240h-777z"
android:fillColor="#ffed00"/>
<path
android:pathData="M0,0h777v160h-777z"
android:fillColor="#ff8c00"/>
<path
android:pathData="M0,0h777v80h-777z"
android:fillColor="#e40303"/>
</vector>

View File

@ -28,18 +28,6 @@
app:edgeToEdge="true"
app:fitSystemWindowsInsets="start|end">
<ImageView
android:id="@+id/holiday_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart"
android:adjustViewBounds="true"
android:translationZ="100dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"
tools:ignore="ContentDescription" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
@ -94,7 +82,7 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="86dp"
android:layout_marginHorizontal="16dp"
android:clickable="true"
android:focusable="true"
@ -104,6 +92,16 @@
app:cardElevation="4dp"
app:cardPreventCornerOverlap="false">
<ImageView
android:id="@+id/holiday_header"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:focusable="false"
android:focusableInTouchMode="false"
android:visibility="gone"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"