From 1a995be74aabf267c38b1e5dce9b4f88539b771c Mon Sep 17 00:00:00 2001 From: oliexdev Date: Mon, 31 Aug 2020 16:52:37 +0200 Subject: [PATCH] use requireContext instead of getContext, see issue #619 --- .../BluetoothSettingsFragment.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java index b1870bd7..d536994f 100644 --- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java +++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/BluetoothSettingsFragment.java @@ -134,7 +134,7 @@ public class BluetoothSettingsFragment extends Fragment { deviceListView.removeAllViews(); foundDevices.clear(); - central = new BluetoothCentral(getContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper())); + central = new BluetoothCentral(requireContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper())); central.scanForPeripherals(); txtSearching.setVisibility(View.VISIBLE); @@ -152,9 +152,9 @@ public class BluetoothSettingsFragment extends Fragment { txtSearching.setText(R.string.label_bluetooth_searching_finished); progressBar.setVisibility(View.GONE); - BluetoothDeviceView notSupported = new BluetoothDeviceView(getContext()); - notSupported.setDeviceName(getContext().getString(R.string.label_scale_not_supported)); - notSupported.setSummaryText(getContext().getString(R.string.label_click_to_help_add_support)); + BluetoothDeviceView notSupported = new BluetoothDeviceView(requireContext()); + notSupported.setDeviceName(requireContext().getString(R.string.label_scale_not_supported)); + notSupported.setSummaryText(requireContext().getString(R.string.label_click_to_help_add_support)); notSupported.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -188,10 +188,10 @@ public class BluetoothSettingsFragment extends Fragment { return; } - BluetoothDeviceView deviceView = new BluetoothDeviceView(getContext()); + BluetoothDeviceView deviceView = new BluetoothDeviceView(requireContext()); deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice())); - BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(getContext(), device.getName()); + BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(requireContext(), device.getName()); if (btDevice != null) { Timber.d("Found supported device %s (driver: %s)", formatDeviceName(device), btDevice.driverName()); @@ -203,7 +203,7 @@ public class BluetoothSettingsFragment extends Fragment { Timber.d("Found unsupported device %s", formatDeviceName(device)); deviceView.setIcon(R.drawable.ic_bluetooth_device_not_supported); - deviceView.setSummaryText(getContext().getString(R.string.label_bt_device_no_support)); + deviceView.setSummaryText(requireContext().getString(R.string.label_bt_device_no_support)); deviceView.setEnabled(false); if (OpenScale.DEBUG_MODE) { @@ -222,7 +222,7 @@ public class BluetoothSettingsFragment extends Fragment { } private void getDebugInfo(final BluetoothDevice device) { - AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); + AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()); builder.setTitle("Fetching info") .setMessage("Please wait while we fetch extended info from your scale...") .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @@ -320,7 +320,7 @@ public class BluetoothSettingsFragment extends Fragment { public void setIcon(int resId) { deviceIcon.setImageResource(resId); - int tintColor = ColorUtil.getTintColor(getContext()); + int tintColor = ColorUtil.getTintColor(requireContext()); deviceIcon.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN); } @@ -342,7 +342,7 @@ public class BluetoothSettingsFragment extends Fragment { public void onClick(View view) { BluetoothDevice device = foundDevices.get(getDeviceAddress()); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireContext()); prefs.edit() .putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress()) @@ -379,7 +379,7 @@ public class BluetoothSettingsFragment extends Fragment { startBluetoothDiscovery(); } } else { - Toast.makeText(getContext(), R.string.permission_not_granted, Toast.LENGTH_SHORT).show(); + Toast.makeText(requireContext(), R.string.permission_not_granted, Toast.LENGTH_SHORT).show(); } break; }