From 610892230b95f783a433f57cf0fd623e28608dc0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 8 Mar 2018 17:16:02 +0100 Subject: [PATCH] add vibrations on button press at the stopwatch tab --- app/build.gradle | 2 +- .../clock/activities/SettingsActivity.kt | 11 ++++- .../clock/fragments/StopwatchFragment.kt | 13 ++++++ app/src/main/res/layout/activity_settings.xml | 40 +++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index ac299e5..31283be 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:3.15.8' + implementation 'com.simplemobiletools:commons:3.15.9' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/SettingsActivity.kt index 3036d1b..7fa2eed 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/SettingsActivity.kt @@ -24,13 +24,14 @@ class SettingsActivity : SimpleActivity() { setupDisplayOtherTimeZones() setupUseSameSnooze() setupSnoozeTime() + setupVibrate() updateTextColors(settings_holder) setupSectionColors() } private fun setupSectionColors() { val adjustedPrimaryColor = getAdjustedPrimaryColor() - arrayListOf(clock_tab_label, alarm_tab_label).forEach { + arrayListOf(clock_tab_label, alarm_tab_label, stopwatch_tab_label).forEach { it.setTextColor(adjustedPrimaryColor) } } @@ -103,6 +104,14 @@ class SettingsActivity : SimpleActivity() { } } + private fun setupVibrate() { + settings_vibrate.isChecked = config.vibrateOnButtonPress + settings_vibrate_holder.setOnClickListener { + settings_vibrate.toggle() + config.vibrateOnButtonPress = settings_vibrate.isChecked + } + } + private fun updateSnoozeText() { settings_snooze_time.text = formatMinutesToTimeString(config.snoozeTime) } diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt index 4af1611..23eaf07 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/fragments/StopwatchFragment.kt @@ -45,26 +45,32 @@ class StopwatchFragment : Fragment() { view = (inflater.inflate(R.layout.fragment_stopwatch, container, false) as ViewGroup).apply { stopwatch_time.setOnClickListener { togglePlayPause() + checkHaptic(this) } stopwatch_play_pause.setOnClickListener { togglePlayPause() + checkHaptic(this) } stopwatch_reset.setOnClickListener { resetStopwatch() + checkHaptic(this) } stopwatch_sorting_indicator_1.setOnClickListener { changeSorting(SORT_BY_LAP) + checkHaptic(this) } stopwatch_sorting_indicator_2.setOnClickListener { changeSorting(SORT_BY_LAP_TIME) + checkHaptic(this) } stopwatch_sorting_indicator_3.setOnClickListener { changeSorting(SORT_BY_TOTAL_TIME) + checkHaptic(this) } stopwatch_lap.setOnClickListener { @@ -73,6 +79,7 @@ class StopwatchFragment : Fragment() { laps.add(0, lap) lapTicks = 0 updateLaps() + checkHaptic(this) } stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) { @@ -204,6 +211,12 @@ class StopwatchFragment : Fragment() { stopwatchAdapter.updateItems(laps) } + private fun checkHaptic(view: View) { + if (context!!.config.vibrateOnButtonPress) { + view.performHapticFeedback() + } + } + private val updateRunnable = object : Runnable { override fun run() { if (isRunning) { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 8969d9c..495b1b1 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -241,5 +241,45 @@ android:clickable="false"/> + + + + + + + + +