summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt/android/QtEmbeddedDelegateFactory.java
blob: 8cf89e5bc3706b8ca96bffba04fa6b4b41988363 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

package org.qtproject.qt.android;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import java.util.HashMap;

class QtEmbeddedDelegateFactory {
    private static final HashMap<Activity, QtEmbeddedDelegate> m_delegates = new HashMap<>();
    private static final Object m_delegateLock = new Object();

    @UsedFromNativeCode
    public static QtActivityDelegateBase getActivityDelegate(Activity activity) {
        synchronized (m_delegateLock) {
            return m_delegates.get(activity);
        }
    }

    public static QtEmbeddedDelegate create(Activity activity) {
        synchronized (m_delegateLock) {
            if (!m_delegates.containsKey(activity))
                m_delegates.put(activity, new QtEmbeddedDelegate(activity));

            return m_delegates.get(activity);
        }
    }

    public static void remove(Activity activity) {
        synchronized (m_delegateLock) {
            m_delegates.remove(activity);
        }
    }
}