fixed static

This commit is contained in:
Vladimir 2020-08-20 15:09:17 +05:00
parent 4465297f7a
commit b935b3995e
3 changed files with 116 additions and 135 deletions

View File

@ -1,110 +0,0 @@
/*
* Copyright (c) 2016 Touch Instinct
*
* This file is part of RoboSwag library.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package ru.touchin.templates;
import android.content.Context;
import android.net.NetworkInfo;
import androidx.annotation.NonNull;
/**
* Utility class that is providing common methods related to android device.
*/
public final class DeviceUtils {
/**
* Detects active network type.
*
* @param context Application context
* @return Active network type {@link NetworkType}
*/
@Deprecated
@NonNull
public static NetworkType getNetworkType(@NonNull final Context context) {
return DeviceUtilsExtensionsKt.getNetworkType(context);
}
/**
* Detects if some network connected.
*
* @param context Application context
* @return true if network connected, false otherwise.
*/
@Deprecated
public static boolean isNetworkConnected(@NonNull final Context context) {
return DeviceUtilsExtensionsKt.isNetworkConnected(context);
}
@Deprecated
@NonNull
static NetworkType getMobileNetworkType(@NonNull final NetworkInfo info) {
return DeviceUtilsExtensionsKt.getMobileNetworkType(info);
}
private DeviceUtils() {
}
/**
* Available network types.
*/
public enum NetworkType {
/**
* Mobile 2G network.
*/
MOBILE_2G("2g"),
/**
* Mobile 3G network.
*/
MOBILE_3G("3g"),
/**
* Mobile LTE network.
*/
MOBILE_LTE("lte"),
/**
* Wi-Fi network.
*/
WI_FI("Wi-Fi"),
/**
* Unknown network type.
*/
UNKNOWN("unknown"),
/**
* No network.
*/
NONE("none");
@NonNull
private final String name;
NetworkType(@NonNull final String name) {
this.name = name;
}
/**
* @return Network type readable name.
*/
@NonNull
public String getName() {
return name;
}
}
}

View File

@ -0,0 +1,115 @@
/*
* Copyright (c) 2016 Touch Instinct
*
* This file is part of RoboSwag library.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package ru.touchin.templates
import android.content.Context
import android.net.NetworkInfo
import android.telephony.TelephonyManager
/**
* Utility class that is providing common methods related to android device.
*/
object DeviceUtils {
/**
* Detects active network type.
*
* @param context Application context
* @return Active network type [NetworkType]
*/
@Deprecated(
"Use extension instead",
ReplaceWith("context.getNetworkType()")
)
fun getNetworkType(context: Context) = context.getNetworkType()
/**
* Detects if some network connected.
*
* @param context Application context
* @return true if network connected, false otherwise.
*/
@Deprecated(
"Use extension instead",
ReplaceWith("context.isNetworkConnected()")
)
fun isNetworkConnected(context: Context) = context.isNetworkConnected()
fun getMobileNetworkType(info: NetworkInfo): NetworkType =
when (info.subtype) {
TelephonyManager.NETWORK_TYPE_GPRS,
TelephonyManager.NETWORK_TYPE_EDGE,
TelephonyManager.NETWORK_TYPE_CDMA,
TelephonyManager.NETWORK_TYPE_1xRTT,
TelephonyManager.NETWORK_TYPE_IDEN -> NetworkType.MOBILE_2G
TelephonyManager.NETWORK_TYPE_UMTS,
TelephonyManager.NETWORK_TYPE_EVDO_0,
TelephonyManager.NETWORK_TYPE_EVDO_A,
TelephonyManager.NETWORK_TYPE_HSDPA,
TelephonyManager.NETWORK_TYPE_HSUPA,
TelephonyManager.NETWORK_TYPE_HSPA,
TelephonyManager.NETWORK_TYPE_EVDO_B,
TelephonyManager.NETWORK_TYPE_EHRPD,
TelephonyManager.NETWORK_TYPE_HSPAP -> NetworkType.MOBILE_3G
TelephonyManager.NETWORK_TYPE_LTE,
19 -> NetworkType.MOBILE_LTE
TelephonyManager.NETWORK_TYPE_UNKNOWN -> NetworkType.UNKNOWN
else -> NetworkType.UNKNOWN
}
/**
* Available network types.
*/
enum class NetworkType(val networkName: String) {
/**
* Mobile 2G network.
*/
MOBILE_2G("2g"),
/**
* Mobile 3G network.
*/
MOBILE_3G("3g"),
/**
* Mobile LTE network.
*/
MOBILE_LTE("lte"),
/**
* Wi-Fi network.
*/
WI_FI("Wi-Fi"),
/**
* Unknown network type.
*/
UNKNOWN("unknown"),
/**
* No network.
*/
NONE("none");
/**
* @return Network type readable name.
*/
}
}

View File

@ -6,14 +6,13 @@ import android.content.Context
import android.content.pm.PackageManager
import android.hardware.biometrics.BiometricManager
import android.net.ConnectivityManager
import android.net.NetworkInfo
import android.os.Build
import android.os.Process
import android.telephony.TelephonyManager
import androidx.annotation.RequiresApi
import androidx.annotation.RequiresPermission
import androidx.core.hardware.fingerprint.FingerprintManagerCompat
import ru.touchin.templates.DeviceUtils.NetworkType
import ru.touchin.templates.DeviceUtils.getMobileNetworkType
fun Context.isNetworkConnected(): Boolean = getNetworkType() != NetworkType.NONE
@ -34,29 +33,6 @@ fun Context.getNetworkType(): NetworkType {
}
}
fun getMobileNetworkType(info: NetworkInfo): NetworkType =
when (info.subtype) {
TelephonyManager.NETWORK_TYPE_GPRS,
TelephonyManager.NETWORK_TYPE_EDGE,
TelephonyManager.NETWORK_TYPE_CDMA,
TelephonyManager.NETWORK_TYPE_1xRTT,
TelephonyManager.NETWORK_TYPE_IDEN -> NetworkType.MOBILE_2G
TelephonyManager.NETWORK_TYPE_UMTS,
TelephonyManager.NETWORK_TYPE_EVDO_0,
TelephonyManager.NETWORK_TYPE_EVDO_A,
TelephonyManager.NETWORK_TYPE_HSDPA,
TelephonyManager.NETWORK_TYPE_HSUPA,
TelephonyManager.NETWORK_TYPE_HSPA,
TelephonyManager.NETWORK_TYPE_EVDO_B,
TelephonyManager.NETWORK_TYPE_EHRPD,
TelephonyManager.NETWORK_TYPE_HSPAP -> NetworkType.MOBILE_3G
TelephonyManager.NETWORK_TYPE_LTE,
19 -> NetworkType.MOBILE_LTE
TelephonyManager.NETWORK_TYPE_UNKNOWN -> NetworkType.UNKNOWN
else -> NetworkType.UNKNOWN
}
@RequiresApi(Build.VERSION_CODES.M)
@Suppress("InlinedApi")
@RequiresPermission(anyOf = [Manifest.permission.USE_FINGERPRINT, Manifest.permission.USE_BIOMETRIC])