mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
Rageshake: vibrate
This commit is contained in:
parent
5c26f66523
commit
96c9293edc
8 changed files with 60 additions and 8 deletions
|
@ -10,6 +10,7 @@ Improvements 🙌:
|
|||
- Fix autocompletion issues and add support for rooms and groups
|
||||
- Introduce developer mode in the settings (#796)
|
||||
- Improve devices list screen
|
||||
- Add settings for rageshake sensibility
|
||||
|
||||
Other changes:
|
||||
-
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
|
||||
<application
|
||||
android:name=".VectorApplication"
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright 2020 New Vector Ltd
|
||||
*
|
||||
* 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 im.vector.riotx.core.hardware
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.VibrationEffect
|
||||
import android.os.Vibrator
|
||||
|
||||
fun vibrate(context: Context, durationMillis: Long = 100) {
|
||||
val vibrator = context.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator? ?: return
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
vibrator.vibrate(VibrationEffect.createOneShot(durationMillis, VibrationEffect.DEFAULT_AMPLITUDE))
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
vibrator.vibrate(durationMillis)
|
||||
}
|
||||
}
|
|
@ -120,8 +120,8 @@ class DefaultNavigator @Inject constructor(
|
|||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun openSettings(context: Context) {
|
||||
val intent = VectorSettingsActivity.getIntent(context)
|
||||
override fun openSettings(context: Context, directAccess: Int) {
|
||||
val intent = VectorSettingsActivity.getIntent(context, directAccess)
|
||||
context.startActivity(intent)
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.riotx.features.navigation
|
|||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.api.session.room.model.roomdirectory.PublicRoom
|
||||
import im.vector.riotx.features.settings.VectorSettingsActivity
|
||||
import im.vector.riotx.features.share.SharedData
|
||||
|
||||
interface Navigator {
|
||||
|
@ -39,7 +40,7 @@ interface Navigator {
|
|||
|
||||
fun openRoomsFiltering(context: Context)
|
||||
|
||||
fun openSettings(context: Context)
|
||||
fun openSettings(context: Context, directAccess: Int = VectorSettingsActivity.EXTRA_DIRECT_ACCESS_ROOT)
|
||||
|
||||
fun openDebug(context: Context)
|
||||
|
||||
|
|
|
@ -23,11 +23,15 @@ import androidx.appcompat.app.AlertDialog
|
|||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.squareup.seismic.ShakeDetector
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.hardware.vibrate
|
||||
import im.vector.riotx.features.navigation.Navigator
|
||||
import im.vector.riotx.features.settings.VectorPreferences
|
||||
import im.vector.riotx.features.settings.VectorSettingsActivity
|
||||
import javax.inject.Inject
|
||||
|
||||
class RageShake @Inject constructor(private val activity: AppCompatActivity,
|
||||
private val bugReporter: BugReporter,
|
||||
private val navigator: Navigator,
|
||||
private val vectorPreferences: VectorPreferences) : ShakeDetector.Listener {
|
||||
|
||||
private var shakeDetector: ShakeDetector? = null
|
||||
|
@ -56,6 +60,7 @@ class RageShake @Inject constructor(private val activity: AppCompatActivity,
|
|||
override fun hearShake() {
|
||||
val i = interceptor
|
||||
if (i != null) {
|
||||
vibrate(activity)
|
||||
i.invoke()
|
||||
} else {
|
||||
if (dialogDisplayed) {
|
||||
|
@ -63,6 +68,7 @@ class RageShake @Inject constructor(private val activity: AppCompatActivity,
|
|||
return
|
||||
}
|
||||
|
||||
vibrate(activity)
|
||||
dialogDisplayed = true
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
|
@ -80,7 +86,7 @@ class RageShake @Inject constructor(private val activity: AppCompatActivity,
|
|||
}
|
||||
|
||||
private fun openSettings() {
|
||||
// TODO
|
||||
navigator.openSettings(activity, VectorSettingsActivity.EXTRA_DIRECT_ACCESS_DEVELOPER)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -54,7 +54,12 @@ class VectorSettingsActivity : VectorBaseActivity(),
|
|||
|
||||
if (isFirstCreation()) {
|
||||
// display the fragment
|
||||
replaceFragment(R.id.vector_settings_page, VectorSettingsRootFragment::class.java, null, FRAGMENT_TAG)
|
||||
when (intent.getIntExtra(EXTRA_DIRECT_ACCESS, EXTRA_DIRECT_ACCESS_ROOT)) {
|
||||
EXTRA_DIRECT_ACCESS_DEVELOPER ->
|
||||
replaceFragment(R.id.vector_settings_page, VectorSettingsDeveloperModeFragment::class.java, null, FRAGMENT_TAG)
|
||||
else ->
|
||||
replaceFragment(R.id.vector_settings_page, VectorSettingsRootFragment::class.java, null, FRAGMENT_TAG)
|
||||
}
|
||||
}
|
||||
|
||||
supportFragmentManager.addOnBackStackChangedListener(this)
|
||||
|
@ -111,7 +116,13 @@ class VectorSettingsActivity : VectorBaseActivity(),
|
|||
}
|
||||
|
||||
companion object {
|
||||
fun getIntent(context: Context) = Intent(context, VectorSettingsActivity::class.java)
|
||||
fun getIntent(context: Context, directAccess: Int) = Intent(context, VectorSettingsActivity::class.java)
|
||||
.apply { putExtra(EXTRA_DIRECT_ACCESS, directAccess) }
|
||||
|
||||
private const val EXTRA_DIRECT_ACCESS = "EXTRA_DIRECT_ACCESS"
|
||||
|
||||
const val EXTRA_DIRECT_ACCESS_ROOT = 0
|
||||
const val EXTRA_DIRECT_ACCESS_DEVELOPER = 1
|
||||
|
||||
private const val FRAGMENT_TAG = "VectorSettingsPreferencesFragment"
|
||||
}
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
android:defaultValue="13"
|
||||
android:dependency="SETTINGS_USE_RAGE_SHAKE_KEY"
|
||||
android:key="SETTINGS_RAGE_SHAKE_DETECTION_THRESHOLD_KEY"
|
||||
android:max="17"
|
||||
android:max="15"
|
||||
android:summary="@string/settings_rageshake_detection_threshold_summary"
|
||||
android:title="@string/settings_rageshake_detection_threshold"
|
||||
app:min="9" />
|
||||
app:min="11" />
|
||||
|
||||
</im.vector.riotx.core.preference.VectorPreferenceCategory>
|
||||
|
||||
|
|
Loading…
Reference in a new issue