add vibrations on button press at the stopwatch tab

This commit is contained in:
tibbi 2018-03-08 17:16:02 +01:00
parent 5570de136e
commit 610892230b
4 changed files with 64 additions and 2 deletions

View file

@ -41,7 +41,7 @@ android {
} }
dependencies { 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.facebook.stetho:stetho:1.5.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.android.support.constraint:constraint-layout:1.0.2'
} }

View file

@ -24,13 +24,14 @@ class SettingsActivity : SimpleActivity() {
setupDisplayOtherTimeZones() setupDisplayOtherTimeZones()
setupUseSameSnooze() setupUseSameSnooze()
setupSnoozeTime() setupSnoozeTime()
setupVibrate()
updateTextColors(settings_holder) updateTextColors(settings_holder)
setupSectionColors() setupSectionColors()
} }
private fun setupSectionColors() { private fun setupSectionColors() {
val adjustedPrimaryColor = getAdjustedPrimaryColor() 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) 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() { private fun updateSnoozeText() {
settings_snooze_time.text = formatMinutesToTimeString(config.snoozeTime) settings_snooze_time.text = formatMinutesToTimeString(config.snoozeTime)
} }

View file

@ -45,26 +45,32 @@ class StopwatchFragment : Fragment() {
view = (inflater.inflate(R.layout.fragment_stopwatch, container, false) as ViewGroup).apply { view = (inflater.inflate(R.layout.fragment_stopwatch, container, false) as ViewGroup).apply {
stopwatch_time.setOnClickListener { stopwatch_time.setOnClickListener {
togglePlayPause() togglePlayPause()
checkHaptic(this)
} }
stopwatch_play_pause.setOnClickListener { stopwatch_play_pause.setOnClickListener {
togglePlayPause() togglePlayPause()
checkHaptic(this)
} }
stopwatch_reset.setOnClickListener { stopwatch_reset.setOnClickListener {
resetStopwatch() resetStopwatch()
checkHaptic(this)
} }
stopwatch_sorting_indicator_1.setOnClickListener { stopwatch_sorting_indicator_1.setOnClickListener {
changeSorting(SORT_BY_LAP) changeSorting(SORT_BY_LAP)
checkHaptic(this)
} }
stopwatch_sorting_indicator_2.setOnClickListener { stopwatch_sorting_indicator_2.setOnClickListener {
changeSorting(SORT_BY_LAP_TIME) changeSorting(SORT_BY_LAP_TIME)
checkHaptic(this)
} }
stopwatch_sorting_indicator_3.setOnClickListener { stopwatch_sorting_indicator_3.setOnClickListener {
changeSorting(SORT_BY_TOTAL_TIME) changeSorting(SORT_BY_TOTAL_TIME)
checkHaptic(this)
} }
stopwatch_lap.setOnClickListener { stopwatch_lap.setOnClickListener {
@ -73,6 +79,7 @@ class StopwatchFragment : Fragment() {
laps.add(0, lap) laps.add(0, lap)
lapTicks = 0 lapTicks = 0
updateLaps() updateLaps()
checkHaptic(this)
} }
stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) { stopwatchAdapter = StopwatchAdapter(activity as SimpleActivity, ArrayList(), stopwatch_list) {
@ -204,6 +211,12 @@ class StopwatchFragment : Fragment() {
stopwatchAdapter.updateItems(laps) stopwatchAdapter.updateItems(laps)
} }
private fun checkHaptic(view: View) {
if (context!!.config.vibrateOnButtonPress) {
view.performHapticFeedback()
}
}
private val updateRunnable = object : Runnable { private val updateRunnable = object : Runnable {
override fun run() { override fun run() {
if (isRunning) { if (isRunning) {

View file

@ -241,5 +241,45 @@
android:clickable="false"/> android:clickable="false"/>
</RelativeLayout> </RelativeLayout>
<View
android:id="@+id/stopwatch_tab_divider"
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider_grey"
android:importantForAccessibility="no"/>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/stopwatch_tab_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/bigger_margin"
android:layout_marginStart="@dimen/bigger_margin"
android:layout_marginTop="@dimen/activity_margin"
android:text="@string/stopwatch_tab"
android:textAllCaps="true"
android:textSize="@dimen/smaller_text_size"/>
<RelativeLayout
android:id="@+id/settings_vibrate_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_vibrate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/vibrate_on_button_press"/>
</RelativeLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>