Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added preference to vibrate when receiving data from scale #1098

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android_app/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<uses-permission android:name="android.permission.VIBRATE" />

<!-- Permission to allow read of data from the database through a ContentProvider.
Marked "dangerous" so that explicit user approval is required to read this data, not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.VibrationEffect;
import android.os.Vibrator;
import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.Editable;
Expand Down Expand Up @@ -116,6 +118,7 @@ public class MainActivity extends AppCompatActivity
private NavigationView navigationView;
private BottomNavigationView navigationBottomView;


private boolean settingsActivityRunning = false;

public static Context createBaseContext(Context context) {
Expand Down Expand Up @@ -715,7 +718,7 @@ public void handleMessage(Message msg) {
case RETRIEVE_SCALE_DATA:
setBluetoothStatusIcon(R.drawable.ic_bluetooth_connection_success);
ScaleMeasurement scaleBtData = (ScaleMeasurement) msg.obj;

Toast.makeText(getApplicationContext(), getResources().getString(R.string.info_bluetooth_retrieve_data_successful), Toast.LENGTH_SHORT).show();
OpenScale openScale = OpenScale.getInstance();

if (prefs.getBoolean("mergeWithLastMeasurement", true)) {
Expand All @@ -725,6 +728,22 @@ public void handleMessage(Message msg) {
}
}


if (prefs.getBoolean("vibrateOnMeasurement", true)) {
Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator != null && vibrator.hasVibrator()) {
// Check Android version
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// New vibrate method for API 26 and above
VibrationEffect effect = VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE);
vibrator.vibrate(effect);
} else {
// Deprecated vibrate method for API 25 and below
vibrator.vibrate(500);
}
}
}

openScale.addScaleMeasurement(scaleBtData, true);
break;
case INIT_PROCESS:
Expand Down
2 changes: 2 additions & 0 deletions android_app/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<string name="info_bluetooth_connection_lost">Bluetooth connection lost</string>
<string name="info_bluetooth_no_device">No Bluetooth device found</string>
<string name="info_bluetooth_no_device_retrying">Could not establish connection, retrying…</string>
<string name="info_bluetooth_retrieve_data_successful">Successfully retrieved data from scale</string>">
<string name="info_bluetooth_no_device_set">Select a Bluetooth device</string>
<string name="info_bluetooth_connection_successful">Connected</string>
<string name="info_bluetooth_init">Initialize Bluetooth device</string>
Expand All @@ -114,6 +115,7 @@
<string name="question_really_delete_user">Delete user?</string>
<string name="label_bluetooth_title">Bluetooth</string>
<string name="label_bluetooth_enable">Connect to scale on startup</string>
<string name="label_vibrate_on_measurement">Vibrate on Measurement</string>
<string name="label_mergeWithLastMeasurement">Merge with last measurement</string>
<string name="label_bluetooth_searching">Searching for your Bluetooth scale</string>
<string name="label_bluetooth_searching_finished">Search finished</string>
Expand Down
6 changes: 6 additions & 0 deletions android_app/app/src/main/res/xml/general_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@
android:summaryOff="@string/info_is_not_enable"
android:summaryOn="@string/info_is_enable"
android:title="@string/label_delete_confirmation" />
<CheckBoxPreference
android:defaultValue="true"
android:key="vibrateOnMeasurement"
android:summaryOff="@string/info_is_not_enable"
android:summaryOn="@string/info_is_enable"
android:title="@string/label_vibrate_on_measurement" />
</PreferenceScreen>