1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Platform: Remove compatibility checks for Android 20 and earlier

This commit is contained in:
reuk 2024-07-01 18:49:16 +01:00
parent 483429f432
commit 8ba2dc2ae2
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
12 changed files with 167 additions and 321 deletions

View file

@ -383,7 +383,7 @@ struct PushNotifications::Pimpl
owner.listeners.call ([&] (Listener& l) { l.handleNotificationAction (true, notification, actionTitle, {}); });
}
else if (getAndroidSDKVersion() >= 20 && actionString.contains (notificationTextInputActionString))
else if (actionString.contains (notificationTextInputActionString))
{
auto prefix = notificationTextInputActionString + notification.identifier + ".";
@ -613,10 +613,7 @@ struct PushNotifications::Pimpl
if (n.actions.size() > 0)
setupActions (n, notificationBuilder);
if (getAndroidSDKVersion() >= 16)
return LocalRef<jobject> (env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.build));
return LocalRef<jobject> (env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.getNotification));
return LocalRef<jobject> (env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.build));
}
static LocalRef<jobject> createNotificationBuilder (const PushNotifications::Notification& n)
@ -684,7 +681,7 @@ struct PushNotifications::Pimpl
env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setSmallIcon, iconId);
if (getAndroidSDKVersion() >= 21 && n.publicVersion != nullptr)
if (n.publicVersion != nullptr)
{
// Public version of a notification is not expected to have another public one!
jassert (n.publicVersion->publicVersion == nullptr);
@ -814,61 +811,49 @@ struct PushNotifications::Pimpl
env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setOngoing, n.ongoing);
env->CallObjectMethod (notificationBuilder, NotificationBuilderBase.setOnlyAlertOnce, n.alertOnlyOnce);
if (getAndroidSDKVersion() >= 16)
if (n.subtitle.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setSubText, javaString (n.subtitle).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setPriority, n.priority);
if (getAndroidSDKVersion() < 24)
{
if (n.subtitle.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setSubText, javaString (n.subtitle).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setPriority, n.priority);
if (getAndroidSDKVersion() < 24)
{
const bool useChronometer = n.timestampVisibility == PushNotifications::Notification::chronometer;
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setUsesChronometer, useChronometer);
}
const bool useChronometer = n.timestampVisibility == PushNotifications::Notification::chronometer;
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.setUsesChronometer, useChronometer);
}
if (getAndroidSDKVersion() >= 17)
const bool showTimeStamp = n.timestampVisibility != PushNotifications::Notification::off;
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi17.setShowWhen, showTimeStamp);
if (n.groupId.isNotEmpty())
{
const bool showTimeStamp = n.timestampVisibility != PushNotifications::Notification::off;
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi17.setShowWhen, showTimeStamp);
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroup, javaString (n.groupId).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroupSummary, n.groupSummary);
}
if (getAndroidSDKVersion() >= 20)
{
if (n.groupId.isNotEmpty())
{
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroup, javaString (n.groupId).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setGroupSummary, n.groupSummary);
}
if (n.groupSortKey.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setSortKey, javaString (n.groupSortKey).get());
if (n.groupSortKey.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setSortKey, javaString (n.groupSortKey).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setLocalOnly, n.localOnly);
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.setLocalOnly, n.localOnly);
auto extras = LocalRef<jobject> (env->NewObject (AndroidBundle, AndroidBundle.constructor));
auto extras = LocalRef<jobject> (env->NewObject (AndroidBundle, AndroidBundle.constructor));
env->CallVoidMethod (extras, AndroidBundle.putBundle, javaString ("notificationData").get(),
juceNotificationToBundle (n).get());
env->CallVoidMethod (extras, AndroidBundle.putBundle, javaString ("notificationData").get(),
juceNotificationToBundle (n).get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addExtras, extras.get());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addExtras, extras.get());
}
if (n.person.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.addPerson, javaString (n.person).get());
if (getAndroidSDKVersion() >= 21)
{
if (n.person.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.addPerson, javaString (n.person).get());
auto categoryString = typeToCategory (n.type);
if (categoryString.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setCategory, javaString (categoryString).get());
auto categoryString = typeToCategory (n.type);
if (categoryString.isNotEmpty())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setCategory, javaString (categoryString).get());
if (n.accentColour != Colour())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setColor, n.accentColour.getARGB());
if (n.accentColour != Colour())
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setColor, n.accentColour.getARGB());
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setVisibility, n.lockScreenAppearance);
}
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi21.setVisibility, n.lockScreenAppearance);
if (getAndroidSDKVersion() >= 24)
{
@ -917,9 +902,6 @@ struct PushNotifications::Pimpl
static void setupActions (const PushNotifications::Notification& n, LocalRef<jobject>& notificationBuilder)
{
if (getAndroidSDKVersion() < 16)
return;
auto* env = getEnv();
LocalRef<jobject> context (getMainActivity());
@ -956,59 +938,51 @@ struct PushNotifications::Pimpl
iconId = env->CallIntMethod (resources, AndroidResources.getIdentifier, javaString (n.icon).get(),
javaString ("raw").get(), packageNameString.get());
if (getAndroidSDKVersion() >= 20)
auto actionBuilder = LocalRef<jobject> (env->NewObject (NotificationActionBuilder,
NotificationActionBuilder.constructor,
iconId,
javaString (action.title).get(),
notifyPendingIntent.get()));
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addExtras,
varToBundleWithPropertiesString (action.parameters).get());
if (isTextStyle)
{
auto actionBuilder = LocalRef<jobject> (env->NewObject (NotificationActionBuilder,
NotificationActionBuilder.constructor,
iconId,
javaString (action.title).get(),
notifyPendingIntent.get()));
auto resultKey = javaString (action.title + String (actionIndex));
auto remoteInputBuilder = LocalRef<jobject> (env->NewObject (RemoteInputBuilder,
RemoteInputBuilder.constructor,
resultKey.get()));
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addExtras,
varToBundleWithPropertiesString (action.parameters).get());
if (! action.textInputPlaceholder.isEmpty())
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setLabel, javaString (action.textInputPlaceholder).get());
if (isTextStyle)
if (! action.allowedResponses.isEmpty())
{
auto resultKey = javaString (action.title + String (actionIndex));
auto remoteInputBuilder = LocalRef<jobject> (env->NewObject (RemoteInputBuilder,
RemoteInputBuilder.constructor,
resultKey.get()));
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setAllowFreeFormInput, false);
if (! action.textInputPlaceholder.isEmpty())
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setLabel, javaString (action.textInputPlaceholder).get());
const int size = action.allowedResponses.size();
if (! action.allowedResponses.isEmpty())
auto array = LocalRef<jobjectArray> (env->NewObjectArray (size, env->FindClass ("java/lang/String"), nullptr));
for (int i = 0; i < size; ++i)
{
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setAllowFreeFormInput, false);
const auto& response = action.allowedResponses[i];
auto responseString = javaString (response);
const int size = action.allowedResponses.size();
auto array = LocalRef<jobjectArray> (env->NewObjectArray (size, env->FindClass ("java/lang/String"), nullptr));
for (int i = 0; i < size; ++i)
{
const auto& response = action.allowedResponses[i];
auto responseString = javaString (response);
env->SetObjectArrayElement (array, i, responseString.get());
}
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setChoices, array.get());
env->SetObjectArrayElement (array, i, responseString.get());
}
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addRemoteInput,
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.build));
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.setChoices, array.get());
}
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addAction,
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.build));
}
else
{
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi16.addAction,
iconId, javaString (action.title).get(), notifyPendingIntent.get());
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.addRemoteInput,
env->CallObjectMethod (remoteInputBuilder, RemoteInputBuilder.build));
}
env->CallObjectMethod (notificationBuilder, NotificationBuilderApi20.addAction,
env->CallObjectMethod (actionBuilder, NotificationActionBuilder.build));
++actionIndex;
}
}
@ -1244,9 +1218,6 @@ struct PushNotifications::Pimpl
static PushNotifications::Notification javaNotificationToJuceNotification (const LocalRef<jobject>& notification)
{
if (getAndroidSDKVersion() < 20)
return {};
auto* env = getEnv();
auto extras = LocalRef<jobject> (env->GetObjectField (notification, AndroidNotification.extras));