feat: поддержка Android 6.0+ (minSdk 23)
This commit is contained in:
1 parent
a6a4361334
commit
ba52490b06
8 files changed
+89
-51
No files matched your search
@@ -3,6 +3,7 @@ package com.freeturn.app
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
|
||||
class ProxyReceiver : BroadcastReceiver() {
|
||||
|
||||
@@ -12,7 +13,11 @@ class ProxyReceiver : BroadcastReceiver() {
|
||||
ProxyServiceState.clearLogs()
|
||||
ProxyServiceState.setStartupResult(null)
|
||||
val serviceIntent = Intent(context, ProxyService::class.java)
|
||||
context.startForegroundService(serviceIntent)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(serviceIntent)
|
||||
} else {
|
||||
context.startService(serviceIntent)
|
||||
}
|
||||
}
|
||||
"com.freeturn.app.STOP_PROXY" -> {
|
||||
val serviceIntent = Intent(context, ProxyService::class.java)
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.freeturn.app.domain
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import com.freeturn.app.ProxyService
|
||||
import com.freeturn.app.ProxyServiceState
|
||||
import com.freeturn.app.StartupResult
|
||||
@@ -87,7 +88,12 @@ class LocalProxyManager(private val context: Context) {
|
||||
|
||||
ProxyServiceState.clearLogs()
|
||||
ProxyServiceState.setStartupResult(null)
|
||||
context.startForegroundService(Intent(context, ProxyService::class.java))
|
||||
val intent = Intent(context, ProxyService::class.java)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(intent)
|
||||
} else {
|
||||
context.startService(intent)
|
||||
}
|
||||
|
||||
val result = withTimeoutOrNull(5_000L) {
|
||||
ProxyServiceState.startupResult.filterNotNull().first()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.freeturn.app.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
|
||||
@@ -28,60 +29,73 @@ object HapticUtil {
|
||||
LAUNCH,
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
fun perform(context: Context, pattern: Pattern) {
|
||||
val vibrator = context.getSystemService(Vibrator::class.java) ?: return
|
||||
val effect = when (pattern) {
|
||||
Pattern.SELECTION -> VibrationEffect.createOneShot(20, 120)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val effect = when (pattern) {
|
||||
Pattern.SELECTION -> VibrationEffect.createOneShot(20, 120)
|
||||
|
||||
Pattern.CLICK -> VibrationEffect.createOneShot(25, 160)
|
||||
Pattern.CLICK -> VibrationEffect.createOneShot(25, 160)
|
||||
|
||||
Pattern.TOGGLE_ON -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 35L, 50L, 20L),
|
||||
intArrayOf(0, 200, 0, 110),
|
||||
-1
|
||||
)
|
||||
Pattern.TOGGLE_ON -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 35L, 50L, 20L),
|
||||
intArrayOf(0, 200, 0, 110),
|
||||
-1
|
||||
)
|
||||
|
||||
Pattern.TOGGLE_OFF -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 28L, 45L, 16L),
|
||||
intArrayOf(0, 140, 0, 70),
|
||||
-1
|
||||
)
|
||||
Pattern.TOGGLE_OFF -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 28L, 45L, 16L),
|
||||
intArrayOf(0, 140, 0, 70),
|
||||
-1
|
||||
)
|
||||
|
||||
Pattern.SUCCESS -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 22L, 40L, 16L, 40L, 12L),
|
||||
intArrayOf(0, 140, 0, 100, 0, 65),
|
||||
-1
|
||||
)
|
||||
Pattern.SUCCESS -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 22L, 40L, 16L, 40L, 12L),
|
||||
intArrayOf(0, 140, 0, 100, 0, 65),
|
||||
-1
|
||||
)
|
||||
|
||||
Pattern.ERROR -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 45L, 25L, 45L, 25L, 30L),
|
||||
intArrayOf(0, 210, 0, 175, 0, 130),
|
||||
-1
|
||||
)
|
||||
Pattern.ERROR -> VibrationEffect.createWaveform(
|
||||
longArrayOf(0L, 45L, 25L, 45L, 25L, 30L),
|
||||
intArrayOf(0, 210, 0, 175, 0, 130),
|
||||
-1
|
||||
)
|
||||
|
||||
// Музыкальная вибрация
|
||||
Pattern.LAUNCH -> VibrationEffect.createWaveform(
|
||||
longArrayOf(
|
||||
0L,
|
||||
18L, 55L,
|
||||
18L, 45L,
|
||||
22L, 35L,
|
||||
30L, 80L,
|
||||
15L, 40L,
|
||||
10L
|
||||
),
|
||||
intArrayOf(
|
||||
0,
|
||||
80, 0,
|
||||
110, 0,
|
||||
150, 0,
|
||||
210, 0,
|
||||
60, 0,
|
||||
30
|
||||
),
|
||||
-1
|
||||
)
|
||||
// Музыкальная вибрация
|
||||
Pattern.LAUNCH -> VibrationEffect.createWaveform(
|
||||
longArrayOf(
|
||||
0L,
|
||||
18L, 55L,
|
||||
18L, 45L,
|
||||
22L, 35L,
|
||||
30L, 80L,
|
||||
15L, 40L,
|
||||
10L
|
||||
),
|
||||
intArrayOf(
|
||||
0,
|
||||
80, 0,
|
||||
110, 0,
|
||||
150, 0,
|
||||
210, 0,
|
||||
60, 0,
|
||||
30
|
||||
),
|
||||
-1
|
||||
)
|
||||
}
|
||||
try { vibrator.vibrate(effect) } catch (_: Exception) {}
|
||||
} else {
|
||||
val duration = when (pattern) {
|
||||
Pattern.SELECTION -> 20L
|
||||
Pattern.CLICK -> 25L
|
||||
Pattern.TOGGLE_ON, Pattern.TOGGLE_OFF -> 50L
|
||||
Pattern.SUCCESS -> 60L
|
||||
Pattern.ERROR -> 100L
|
||||
Pattern.LAUNCH -> 70L
|
||||
}
|
||||
try { vibrator.vibrate(duration) } catch (_: Exception) {}
|
||||
}
|
||||
try { vibrator.vibrate(effect) } catch(_: Exception) {}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user