Commit 58348d54 authored by wanglei's avatar wanglei

...

parent 8de786f3
...@@ -117,6 +117,7 @@ dependencies { ...@@ -117,6 +117,7 @@ dependencies {
implementation("com.google.firebase:firebase-messaging") implementation("com.google.firebase:firebase-messaging")
implementation("com.google.firebase:firebase-analytics-ktx") implementation("com.google.firebase:firebase-analytics-ktx")
implementation("com.google.firebase:firebase-crashlytics") implementation("com.google.firebase:firebase-crashlytics")
implementation("com.google.firebase:firebase-messaging-directboot")
// implementation("com.google.firebase:firebase-database-ktx") // implementation("com.google.firebase:firebase-database-ktx")
// implementation("com.google.firebase:firebase-config-ktx") // implementation("com.google.firebase:firebase-config-ktx")
......
...@@ -140,6 +140,7 @@ ...@@ -140,6 +140,7 @@
<action android:name="com.google.firebase.MESSAGING_EVENT" /> <action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter> </intent-filter>
</service> </service>
<service <service
android:name=".service.StayJobService" android:name=".service.StayJobService"
android:exported="false" android:exported="false"
...@@ -159,6 +160,36 @@ ...@@ -159,6 +160,36 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver
android:name=".fcm.alarm.AlarmJobReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.USER_PRESENT" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<action android:name="android.intent.action.PACKAGE_REPLACED" />
<data android:scheme="package" />
</intent-filter>
<intent-filter>
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MEDIA_EJECT" />
<action android:name="android.intent.action.MEDIA_MOUNTED" />
<data android:scheme="file" />
</intent-filter>
</receiver>
<meta-data <meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID" android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" /> android:value="ca-app-pub-3940256099942544~3347511713" />
......
...@@ -21,7 +21,7 @@ public class MessagingService extends FirebaseMessagingService { ...@@ -21,7 +21,7 @@ public class MessagingService extends FirebaseMessagingService {
LogEx.INSTANCE.logDebug(TAG, "onMessageReceived", false); LogEx.INSTANCE.logDebug(TAG, "onMessageReceived", false);
EventUtils.INSTANCE.event("FCM_Received", null, null, false); EventUtils.INSTANCE.event("FCM_Received", null, null, false);
NotificationUiUtil.INSTANCE.sendNotificationIfCan(this, PopupConstObject.POPUP_WHERE_FCM); NotificationUiUtil.INSTANCE.sendNotificationIfCan(this, PopupConstObject.POPUP_WHERE_FCM, null);
} }
......
...@@ -21,6 +21,7 @@ import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_READ_ ...@@ -21,6 +21,7 @@ import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_READ_
import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_READ_PDF import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_READ_PDF
import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_UN_VIEW_FILES import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_UN_VIEW_FILES
import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_WEATHER import com.base.pdfreaderallpdfreader.bean.ConstObject.NOTIFICATION_ACTION_WEATHER
import com.base.pdfreaderallpdfreader.bean.WeatherBean
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.POPUP_WHERE_FCM import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.POPUP_WHERE_FCM
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.POPUP_WHERE_LOCK import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.POPUP_WHERE_LOCK
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.POPUP_WHERE_TIMBER import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.POPUP_WHERE_TIMBER
...@@ -34,9 +35,12 @@ import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.popup_status ...@@ -34,9 +35,12 @@ import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.popup_status
import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.popup_timer_interval import com.base.pdfreaderallpdfreader.fcm.PopupConstObject.popup_timer_interval
import com.base.pdfreaderallpdfreader.helper.EventUtils import com.base.pdfreaderallpdfreader.helper.EventUtils
import com.base.pdfreaderallpdfreader.helper.MyApplication import com.base.pdfreaderallpdfreader.helper.MyApplication
import com.base.pdfreaderallpdfreader.helper.WeatherUtils
import com.base.pdfreaderallpdfreader.ui.splash.MyStartActivity import com.base.pdfreaderallpdfreader.ui.splash.MyStartActivity
import com.base.pdfreaderallpdfreader.utils.AppPreferences import com.base.pdfreaderallpdfreader.utils.AppPreferences
import com.base.pdfreaderallpdfreader.utils.LogEx import com.base.pdfreaderallpdfreader.utils.LogEx
import com.base.pdfreaderallpdfreader.utils.TimeUtils.formatATime
import com.base.pdfreaderallpdfreader.utils.TimeUtils.isDayOrNight
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.Locale import java.util.Locale
...@@ -128,9 +132,9 @@ object NotificationUiUtil { ...@@ -128,9 +132,9 @@ object NotificationUiUtil {
var hoverActionId = "" var hoverActionId = ""
@SuppressLint("RemoteViewLayout") @SuppressLint("RemoteViewLayout")
fun sendNotificationIfCan(context: Context, where: String = "") { fun sendNotificationIfCan(context: Context, where: String = "", id: String? = null) {
val actionId = getNextActionId() val actionId = id ?: getNextActionId()
if (!canSendNotification(where, actionId)) return if (!canSendNotification(where, actionId)) return
...@@ -241,47 +245,47 @@ object NotificationUiUtil { ...@@ -241,47 +245,47 @@ object NotificationUiUtil {
} }
NOTIFICATION_ACTION_WEATHER -> { NOTIFICATION_ACTION_WEATHER -> {
// val weatherBean: WeatherBean = WeatherUtils.getWeatherEntity() ?: return val weatherBean: WeatherBean = WeatherUtils.getWeatherEntity() ?: return
// if (weatherBean.list.isEmpty()) return if (weatherBean.list.isEmpty()) return
//
// val subBean = weatherBean.list[0] val subBean = weatherBean.list[0]
// val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_small) val smallRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_small)
// smallRemoteViewsVar.setTextViewText(R.id.tv_city, weatherBean.city) smallRemoteViewsVar.setTextViewText(R.id.tv_city, weatherBean.city)
// val min = subBean.tempMin.toInt() val min = subBean.tempMin.toInt()
// val max = subBean.tempMax.toInt() val max = subBean.tempMax.toInt()
// smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString()) smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString())
// val icon = when (WeatherUtils.getWeatherType(subBean.iconDay.toInt())) { val icon = when (WeatherUtils.getWeatherType(subBean.iconDay.toInt())) {
// "Sunny day" -> R.mipmap.d_qing "Sunny day" -> R.mipmap.d_qing
// "Cloudy day" -> R.mipmap.d_yin "Cloudy day" -> R.mipmap.d_yin
// "Rainy day" -> R.mipmap.d_dayu "Rainy day" -> R.mipmap.d_dayu
// "Snowy day" -> R.mipmap.d_xiaxue "Snowy day" -> R.mipmap.d_xiaxue
// "Greasy day" -> R.mipmap.d_wumaishachengbao "Greasy day" -> R.mipmap.d_wumaishachengbao
// "Unknown" -> R.mipmap.d_qing "Unknown" -> R.mipmap.d_qing
// else -> R.mipmap.d_qing else -> R.mipmap.d_qing
// } }
//
// smallRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon) smallRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon)
// smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_range, "$min℃/$max℃") smallRemoteViewsVar.setTextViewText(R.id.tv_wendu_range, "$min℃/$max℃")
//
// val bigRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_big) val bigRemoteViewsVar = RemoteViews(context.packageName, R.layout.notification_weather_big)
// bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_11h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_11h, icon)
// bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_14h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_14h, icon)
// bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_17h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_17h, icon)
// bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_20h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_20h, icon)
// bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_23h, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather_23h, icon)
// bigRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon) bigRemoteViewsVar.setImageViewResource(R.id.iv_weather, icon)
//
// bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_11h, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_11h, Random.nextInt(min, max).toString())
// bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_14h, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_14h, Random.nextInt(min, max).toString())
// bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_17h, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_17h, Random.nextInt(min, max).toString())
// bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_20h, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_20h, Random.nextInt(min, max).toString())
// bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_23h, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_23h, Random.nextInt(min, max).toString())
//
// bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString()) bigRemoteViewsVar.setTextViewText(R.id.tv_wendu_now, Random.nextInt(min, max).toString())
// bigRemoteViewsVar.setTextViewText(R.id.tv_day_desc, if (isDayOrNight()) subBean.textDay else subBean.textNight) bigRemoteViewsVar.setTextViewText(R.id.tv_day_desc, if (isDayOrNight()) subBean.textDay else subBean.textNight)
// bigRemoteViewsVar.setTextViewText(R.id.tv_weather_info, "$min℃/$max℃ ${formatATime()}") bigRemoteViewsVar.setTextViewText(R.id.tv_weather_info, "$min℃/$max℃ ${formatATime()}")
//
// sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar) sendCustomNotification(context, intent, bigRemoteViewsVar, smallRemoteViewsVar)
} }
...@@ -357,8 +361,8 @@ object NotificationUiUtil { ...@@ -357,8 +361,8 @@ object NotificationUiUtil {
NOTIFICATION_ACTION_READ_DOCUMENTS, NOTIFICATION_ACTION_READ_DOCUMENTS,
NOTIFICATION_ACTION_UN_VIEW_FILES, NOTIFICATION_ACTION_UN_VIEW_FILES,
NOTIFICATION_ACTION_IMPORTANT_DOCUMENT, NOTIFICATION_ACTION_IMPORTANT_DOCUMENT,
NOTIFICATION_ACTION_APP_PROCESS, // NOTIFICATION_ACTION_APP_PROCESS,
NOTIFICATION_ACTION_CLEAN_JUNK, // NOTIFICATION_ACTION_CLEAN_JUNK,
NOTIFICATION_ACTION_WEATHER NOTIFICATION_ACTION_WEATHER
) )
......
...@@ -52,7 +52,7 @@ public class ScreenStatusReceiver extends BroadcastReceiver { ...@@ -52,7 +52,7 @@ public class ScreenStatusReceiver extends BroadcastReceiver {
if (isDeviceInteractive() && !isSecureLockActive()) { if (isDeviceInteractive() && !isSecureLockActive()) {
int secureSetting = Integer.parseInt(AppPreferences.getInstance().getString(lockS, "1")); int secureSetting = Integer.parseInt(AppPreferences.getInstance().getString(lockS, "1"));
if (secureSetting == 1) { if (secureSetting == 1) {
NotificationUiUtil.INSTANCE.sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_LOCK); NotificationUiUtil.INSTANCE.sendNotificationIfCan(context, PopupConstObject.POPUP_WHERE_LOCK,null);
} }
} }
break; break;
......
...@@ -38,7 +38,7 @@ public class TimerManager { ...@@ -38,7 +38,7 @@ public class TimerManager {
!ScreenStatusReceiver.isSecureLockActive() && !ScreenStatusReceiver.isSecureLockActive() &&
MyApplication.PAUSED_VALUE != 1) { MyApplication.PAUSED_VALUE != 1) {
Log.d("glc", "Scheduled task conditions are met"); Log.d("glc", "Scheduled task conditions are met");
NotificationUiUtil.INSTANCE.sendNotificationIfCan(MyApplication.context, PopupConstObject.POPUP_WHERE_TIMBER); NotificationUiUtil.INSTANCE.sendNotificationIfCan(MyApplication.context, PopupConstObject.POPUP_WHERE_TIMBER,null);
} }
} }
}; };
......
package com.base.pdfreaderallpdfreader.utils
import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.Calendar
object TimeUtils {
fun isDayOrNight(): Boolean {
val calendar: Calendar = Calendar.getInstance()
val hour: Int = calendar.get(Calendar.HOUR_OF_DAY)
// 假设早上6点到晚上6点是白天
return if (hour in 6..17) {
// "现在是白天。"
true
} else {
// "现在是晚上。"
false
}
}
@SuppressLint("SimpleDateFormat")
fun formatATime(): String {
val calendar = Calendar.getInstance()
// 格式化时间为 "AM 9:50" 格式
val sdf = SimpleDateFormat("a hh:mm")
return sdf.format(calendar.time)
}
//
// fun isTimeBetweenEightAndTenPM(): Boolean {
// val now = Calendar.getInstance()
// val hour = now[Calendar.HOUR_OF_DAY] // 获取当前小时数(24小时制)
//
// // 检查当前时间是否在 8 点到 22 点之间
// return hour in 8..21
// }
//
// fun isTimeBetweenWan17toWan23(): Boolean {
//
// val calendar = Calendar.getInstance()
// val currentHour = calendar.get(Calendar.HOUR_OF_DAY) // 获取当前小时数(24小时制)
//
// val isEvening = currentHour in 17..22 // Kotlin中的in运算符用于判断范围
// return if (isEvening) {
// // 当前时间是晚上17点到23点之间
// true
// } else {
// // 当前时间不是晚上17点到23点之间
// false
// }
// }
//
//
// @SuppressLint("SimpleDateFormat")
// fun Long.formatTimeH(): String {
// val dateFormat = SimpleDateFormat("yyyy-M-d H")
// return dateFormat.format(this)
// }
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<corners android:radius="15dp" />
</shape>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/bg_ffffff_15">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="@mipmap/x_tianqibg"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_wendu_now"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginStart="20dp"
android:textColor="@color/white"
android:textSize="30sp"
tools:text="20" />
<TextView
android:id="@+id/tv_c"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/tv_wendu_now"
android:layout_toEndOf="@id/tv_wendu_now"
android:text="℃"
android:textColor="@color/white"
android:textSize="14sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/iv_weather"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_alignTop="@id/tv_wendu_now"
android:layout_alignBottom="@id/tv_wendu_now"
android:layout_toEndOf="@id/tv_c"
android:src="@mipmap/d_qing"
tools:ignore="ContentDescription" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="22dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@mipmap/tishiicon"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="4dp"
android:textColor="@color/white"
android:textSize="13sp"
tools:text="Cheney" />
</LinearLayout>
<TextView
android:id="@+id/tv_wendu_range"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textSize="15sp"
tools:text="19℃/36℃" />
</LinearLayout>
</RelativeLayout>
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment