mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2024-12-24 22:21:33 +01:00
add optional vibration on button pressing
This commit is contained in:
parent
e5f01155ad
commit
c2c5cd7ca8
@ -40,13 +40,13 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:3.0.3'
|
||||
implementation 'com.simplemobiletools:commons:3.0.9'
|
||||
implementation 'me.grantland:autofittextview:0.2.1'
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
testImplementation 'org.robolectric:robolectric:3.5.1'
|
||||
|
||||
androidTestImplementation 'com.android.support:support-annotations:27.0.1'
|
||||
androidTestImplementation 'com.android.support:support-annotations:27.0.2'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.1'
|
||||
androidTestImplementation 'com.android.support.test:rules:1.0.1'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
|
||||
|
@ -1,18 +1,18 @@
|
||||
package com.simplemobiletools.calculator.activities
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import com.simplemobiletools.calculator.BuildConfig
|
||||
import com.simplemobiletools.calculator.R
|
||||
import com.simplemobiletools.calculator.extensions.config
|
||||
import com.simplemobiletools.calculator.extensions.updateViewColors
|
||||
import com.simplemobiletools.calculator.helpers.*
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.copyToClipboard
|
||||
import com.simplemobiletools.commons.extensions.performHapticFeedback
|
||||
import com.simplemobiletools.commons.extensions.value
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_AUTOFITTEXTVIEW
|
||||
import com.simplemobiletools.commons.helpers.LICENSE_ESPRESSO
|
||||
@ -23,6 +23,8 @@ import me.grantland.widget.AutofitHelper
|
||||
|
||||
class MainActivity : SimpleActivity(), Calculator {
|
||||
private var storedTextColor = 0
|
||||
private var vibrateOnButtonPress = true
|
||||
|
||||
lateinit var calc: CalculatorImpl
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -31,22 +33,22 @@ class MainActivity : SimpleActivity(), Calculator {
|
||||
|
||||
calc = CalculatorImpl(this, applicationContext)
|
||||
|
||||
btn_plus.setOnClickListener { calc.handleOperation(PLUS) }
|
||||
btn_minus.setOnClickListener { calc.handleOperation(MINUS) }
|
||||
btn_multiply.setOnClickListener { calc.handleOperation(MULTIPLY) }
|
||||
btn_divide.setOnClickListener { calc.handleOperation(DIVIDE) }
|
||||
btn_modulo.setOnClickListener { calc.handleOperation(MODULO) }
|
||||
btn_power.setOnClickListener { calc.handleOperation(POWER) }
|
||||
btn_root.setOnClickListener { calc.handleOperation(ROOT) }
|
||||
btn_plus.setOnClickListener { calc.handleOperation(PLUS); checkHaptic(it) }
|
||||
btn_minus.setOnClickListener { calc.handleOperation(MINUS); checkHaptic(it) }
|
||||
btn_multiply.setOnClickListener { calc.handleOperation(MULTIPLY); checkHaptic(it) }
|
||||
btn_divide.setOnClickListener { calc.handleOperation(DIVIDE); checkHaptic(it) }
|
||||
btn_modulo.setOnClickListener { calc.handleOperation(MODULO); checkHaptic(it) }
|
||||
btn_power.setOnClickListener { calc.handleOperation(POWER); checkHaptic(it) }
|
||||
btn_root.setOnClickListener { calc.handleOperation(ROOT); checkHaptic(it) }
|
||||
|
||||
btn_clear.setOnClickListener { calc.handleClear() }
|
||||
btn_clear.setOnClickListener { calc.handleClear(); checkHaptic(it) }
|
||||
btn_clear.setOnLongClickListener { calc.handleReset(); true }
|
||||
|
||||
getButtonIds().forEach {
|
||||
it.setOnClickListener { calc.numpadClicked(it.id) }
|
||||
it.setOnClickListener { calc.numpadClicked(it.id); checkHaptic(it) }
|
||||
}
|
||||
|
||||
btn_equals.setOnClickListener { calc.handleEquals() }
|
||||
btn_equals.setOnClickListener { calc.handleEquals(); checkHaptic(it) }
|
||||
formula.setOnLongClickListener { copyToClipboard(false) }
|
||||
result.setOnLongClickListener { copyToClipboard(true) }
|
||||
|
||||
@ -59,6 +61,7 @@ class MainActivity : SimpleActivity(), Calculator {
|
||||
if (storedTextColor != config.textColor) {
|
||||
updateViewColors(calculator_holder, config.textColor)
|
||||
}
|
||||
vibrateOnButtonPress = config.vibrateOnButtonPress
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
@ -80,6 +83,12 @@ class MainActivity : SimpleActivity(), Calculator {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun checkHaptic(view: View) {
|
||||
if (vibrateOnButtonPress) {
|
||||
view.performHapticFeedback()
|
||||
}
|
||||
}
|
||||
|
||||
private fun launchSettings() {
|
||||
startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
}
|
||||
@ -96,14 +105,12 @@ class MainActivity : SimpleActivity(), Calculator {
|
||||
value = result.value
|
||||
}
|
||||
|
||||
if (value.isEmpty())
|
||||
return false
|
||||
|
||||
val clipboard = getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText(resources.getString(R.string.app_name), value)
|
||||
clipboard.primaryClip = clip
|
||||
toast(R.string.copied_to_clipboard)
|
||||
return true
|
||||
return if (value.isEmpty()) {
|
||||
false
|
||||
} else {
|
||||
copyToClipboard(value)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
override fun setValue(value: String, context: Context) {
|
||||
|
@ -2,6 +2,7 @@ package com.simplemobiletools.calculator.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import com.simplemobiletools.calculator.R
|
||||
import com.simplemobiletools.calculator.extensions.config
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
|
||||
@ -16,6 +17,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
super.onResume()
|
||||
|
||||
setupCustomizeColors()
|
||||
setupVibrate()
|
||||
updateTextColors(settings_scrollview)
|
||||
}
|
||||
|
||||
@ -24,4 +26,12 @@ class SettingsActivity : SimpleActivity() {
|
||||
startCustomizationActivity()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupVibrate() {
|
||||
settings_vibrate.isChecked = config.vibrateOnButtonPress
|
||||
settings_vibrate_holder.setOnClickListener {
|
||||
settings_vibrate.toggle()
|
||||
config.vibrateOnButtonPress = settings_vibrate.isChecked
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import android.widget.Button
|
||||
import android.widget.TextView
|
||||
import com.simplemobiletools.calculator.helpers.Config
|
||||
|
||||
val Context.config: Config get() = Config.newInstance(this)
|
||||
val Context.config: Config get() = Config.newInstance(applicationContext)
|
||||
|
||||
// we are reusing the same layout in the app and widget, but cannot use MyTextView etc in a widget, so color regular view types like this
|
||||
fun Context.updateViewColors(viewGroup: ViewGroup, textColor: Int) {
|
||||
|
@ -7,4 +7,8 @@ class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
fun newInstance(context: Context) = Config(context)
|
||||
}
|
||||
|
||||
var vibrateOnButtonPress: Boolean
|
||||
get() = prefs.getBoolean(VIBRATE_ON_BUTTON_PRESS, true)
|
||||
set(vibrateOnButton) = prefs.edit().putBoolean(VIBRATE_ON_BUTTON_PRESS, vibrateOnButton).apply()
|
||||
}
|
||||
|
@ -23,3 +23,6 @@ val SIX = "six"
|
||||
val SEVEN = "seven"
|
||||
val EIGHT = "eight"
|
||||
val NINE = "nine"
|
||||
|
||||
// shared preferences
|
||||
val VIBRATE_ON_BUTTON_PRESS = "vibrate_on_button_press"
|
||||
|
@ -29,5 +29,26 @@
|
||||
android:text="@string/customize_colors"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
<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:padding="@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>
|
||||
</ScrollView>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Schlichter Rechner</string>
|
||||
<string name="app_launcher_name">Rechner</string>
|
||||
<string name="copied_to_clipboard">Wert in Zwischenablage kopiert</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Ein Taschenrechner mit grundlegenden Funktionen und einem anpassbaren Widget.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Calculator</string>
|
||||
<string name="app_launcher_name">Calculadora</string>
|
||||
<string name="copied_to_clipboard">Valor copiado en el portapapeles</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Una calculadora con funciones básicas y un widget personalizable.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Calculette</string>
|
||||
<string name="app_launcher_name">Calculette</string>
|
||||
<string name="copied_to_clipboard">Valeur copiée dans le presse-papier</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Une calculette avec les fonctions de base et un widget customisable.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Calculator</string>
|
||||
<string name="app_launcher_name">Calculator</string>
|
||||
<string name="copied_to_clipboard">Valore copiato negli appunti</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">A calculator with the basic functions and a customizable widget.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">シンプル電卓</string>
|
||||
<string name="app_launcher_name">電卓</string>
|
||||
<string name="copied_to_clipboard">値をクリップボードにコピーしました</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">基本機能とカスタマイズ可能なウィジェットを備えた電卓。</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Prosty Kalkulator</string>
|
||||
<string name="app_launcher_name">Kalkulator</string>
|
||||
<string name="copied_to_clipboard">Wartość została skopiowana do schowka</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Kalulator z podstawowymi funkcjami oraz konfiguralnym widżetem.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Calculator</string>
|
||||
<string name="app_launcher_name">Calculadora</string>
|
||||
<string name="copied_to_clipboard">Valor copiado para a área de transferência</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Uma calculadora com funções básicas e um widget personalizável.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Calculator</string>
|
||||
<string name="app_launcher_name">Калькулятор</string>
|
||||
<string name="copied_to_clipboard">Значение скопировано в буфер обмена</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Калькулятор с базовым функционалом и настраиваемым виджетом.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Jednoduchá kalkulačka</string>
|
||||
<string name="app_launcher_name">Kalkulačka</string>
|
||||
<string name="copied_to_clipboard">Hodnota bola skopírovaná do schránky</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Kalkulačka so základnými funkciami a prispôsobiteľným widgetom.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Calculator</string>
|
||||
<string name="app_launcher_name">Kalkylator</string>
|
||||
<string name="copied_to_clipboard">Värdet kopierat till urklippet</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">En kalkylator med grundläggande funktioner och en anpassningsbar widget.</string>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Basit Hesap Makinesi</string>
|
||||
<string name="app_launcher_name">Hesap Makinesi</string>
|
||||
<string name="copied_to_clipboard">Panoya kopyalanan değer</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">Temel fonksiyonları ve özelleştirilebilir bir araç\'lı bir hesap makinesi.</string>
|
||||
|
@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="text_grey">#77000000</color>
|
||||
<color name="dark_grey_pressed_mask">#11000000</color>
|
||||
</resources>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<resources>
|
||||
<string name="app_name">Simple Calculator</string>
|
||||
<string name="app_launcher_name">Calculator</string>
|
||||
<string name="copied_to_clipboard">Value copied to clipboard</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="vibrate_on_button_press">Vibrate on button press</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<string name="app_short_description">A calculator with the basic functions and a customizable widget.</string>
|
||||
|
Loading…
Reference in New Issue
Block a user