summaryrefslogtreecommitdiffhomepage
path: root/ui/src/main/java/com/wireguard/android/util/FragmentUtils.java
blob: f93fd60d44ca749364321d872e54c455d6893706 (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
/*
 * Copyright © 2017-2019 WireGuard LLC. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */
package com.wireguard.android.util;

import android.content.Context;
import android.view.ContextThemeWrapper;

import com.wireguard.android.activity.SettingsActivity;
import com.wireguard.util.NonNullForAll;

import androidx.preference.Preference;

@NonNullForAll
public final class FragmentUtils {
    private FragmentUtils() {
        // Prevent instantiation
    }

    public static SettingsActivity getPrefActivity(final Preference preference) {
        final Context context = preference.getContext();
        if (context instanceof ContextThemeWrapper) {
            if (context instanceof SettingsActivity) {
                return ((SettingsActivity) context);
            }
        }
        return null;
    }
}