mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-09 23:34:20 +00:00
Android: Refactor lifecycle callbacks to reduce repetition in lifecycle listener registration
This commit is contained in:
parent
11752d061f
commit
1c2eb2d056
7 changed files with 56 additions and 137 deletions
|
|
@ -490,8 +490,7 @@ private:
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
struct CameraDevice::Pimpl
|
||||
: private ActivityLifecycleCallbacks
|
||||
struct CameraDevice::Pimpl : private ActivityLifecycleCallbacks
|
||||
{
|
||||
using InternalOpenCameraResultCallback = std::function<void (const String& /*cameraId*/, const String& /*error*/)>;
|
||||
|
||||
|
|
@ -504,7 +503,6 @@ struct CameraDevice::Pimpl
|
|||
maxWidth (maxWidthToUse),
|
||||
maxHeight (maxHeightToUse),
|
||||
cameraId (cameraIdToUse),
|
||||
activityLifeListener (CreateJavaInterface (this, "android/app/Application$ActivityLifecycleCallbacks")),
|
||||
cameraManager (initialiseCameraManager()),
|
||||
cameraCharacteristics (initialiseCameraCharacteristics (cameraManager, cameraId)),
|
||||
streamConfigurationMap (cameraCharacteristics),
|
||||
|
|
@ -516,10 +514,7 @@ struct CameraDevice::Pimpl
|
|||
|
||||
~Pimpl() override
|
||||
{
|
||||
auto* env = getEnv();
|
||||
|
||||
env->CallVoidMethod (getAppContext().get(), AndroidApplication.unregisterActivityLifecycleCallbacks, activityLifeListener.get());
|
||||
activityLifeListener.clear();
|
||||
callbackForwarder.reset();
|
||||
}
|
||||
|
||||
JUCE_DECLARE_WEAK_REFERENCEABLE (Pimpl)
|
||||
|
|
@ -551,7 +546,7 @@ struct CameraDevice::Pimpl
|
|||
{
|
||||
if (granted)
|
||||
{
|
||||
getEnv()->CallVoidMethod (getAppContext().get(), AndroidApplication.registerActivityLifecycleCallbacks, activityLifeListener.get());
|
||||
callbackForwarder.emplace (GlobalRef { getAppContext() }, static_cast<ActivityLifecycleCallbacks*> (this));
|
||||
scopedCameraDevice.reset (new ScopedCameraDevice (*this, cameraId, cameraManager, handler, getAutoFocusModeToUse()));
|
||||
}
|
||||
else
|
||||
|
|
@ -2809,7 +2804,7 @@ private:
|
|||
String cameraId;
|
||||
InternalOpenCameraResultCallback cameraOpenCallback;
|
||||
|
||||
GlobalRef activityLifeListener;
|
||||
std::optional<ActivityLifecycleCallbackForwarder> callbackForwarder;
|
||||
|
||||
GlobalRef cameraManager;
|
||||
GlobalRef cameraCharacteristics;
|
||||
|
|
|
|||
|
|
@ -344,8 +344,9 @@ private:
|
|||
};
|
||||
|
||||
//==============================================================================
|
||||
struct VideoComponent::Pimpl
|
||||
: public AndroidViewComponent, private ActivityLifecycleCallbacks, private SurfaceHolderCallback
|
||||
struct VideoComponent::Pimpl : public AndroidViewComponent,
|
||||
private ActivityLifecycleCallbacks,
|
||||
private SurfaceHolderCallback
|
||||
{
|
||||
Pimpl (VideoComponent& ownerToUse, bool)
|
||||
: owner (ownerToUse),
|
||||
|
|
@ -360,14 +361,6 @@ struct VideoComponent::Pimpl
|
|||
|
||||
LocalRef<jobject> appContext (getAppContext());
|
||||
|
||||
if (appContext != nullptr)
|
||||
{
|
||||
ActivityLifecycleCallbacks* callbacks = dynamic_cast<ActivityLifecycleCallbacks*> (this);
|
||||
|
||||
activityLifeListener = GlobalRef (CreateJavaInterface (callbacks, "android/app/Application$ActivityLifecycleCallbacks"));
|
||||
env->CallVoidMethod (appContext.get(), AndroidApplication.registerActivityLifecycleCallbacks, activityLifeListener.get());
|
||||
}
|
||||
|
||||
{
|
||||
LocalRef<jobject> surfaceView (env->NewObject (AndroidSurfaceView, AndroidSurfaceView.constructor, getAppContext().get()));
|
||||
LocalRef<jobject> holder (env->CallObjectMethod (surfaceView.get(), AndroidSurfaceView.getHolder));
|
||||
|
|
@ -397,13 +390,6 @@ struct VideoComponent::Pimpl
|
|||
surfaceHolderCallback.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (activityLifeListener != nullptr)
|
||||
{
|
||||
env->CallVoidMethod (getAppContext().get(), AndroidApplication.unregisterActivityLifecycleCallbacks, activityLifeListener.get());
|
||||
ActivityLifecycleCallbacks::clear();
|
||||
activityLifeListener.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void loadAsync (const URL& url, std::function<void (const URL&, Result)> callback)
|
||||
|
|
@ -1696,7 +1682,7 @@ private:
|
|||
VideoComponent& owner;
|
||||
|
||||
MediaSession mediaSession;
|
||||
GlobalRef activityLifeListener;
|
||||
ActivityLifecycleCallbackForwarder forwarder { GlobalRef { getAppContext() }, this };
|
||||
#if JUCE_SYNC_VIDEO_VOLUME_WITH_OS_MEDIA_VOLUME
|
||||
SystemVolumeListener systemVolumeListener;
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue