1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-16 13:44:26 +02:00

use requireContext instead of getContext, see issue #619

This commit is contained in:
oliexdev
2020-08-31 16:52:37 +02:00
parent 2e8e93aa73
commit 1a995be74a

View File

@@ -134,7 +134,7 @@ public class BluetoothSettingsFragment extends Fragment {
deviceListView.removeAllViews(); deviceListView.removeAllViews();
foundDevices.clear(); foundDevices.clear();
central = new BluetoothCentral(getContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper())); central = new BluetoothCentral(requireContext(), bluetoothCentralCallback, new Handler(Looper.getMainLooper()));
central.scanForPeripherals(); central.scanForPeripherals();
txtSearching.setVisibility(View.VISIBLE); txtSearching.setVisibility(View.VISIBLE);
@@ -152,9 +152,9 @@ public class BluetoothSettingsFragment extends Fragment {
txtSearching.setText(R.string.label_bluetooth_searching_finished); txtSearching.setText(R.string.label_bluetooth_searching_finished);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
BluetoothDeviceView notSupported = new BluetoothDeviceView(getContext()); BluetoothDeviceView notSupported = new BluetoothDeviceView(requireContext());
notSupported.setDeviceName(getContext().getString(R.string.label_scale_not_supported)); notSupported.setDeviceName(requireContext().getString(R.string.label_scale_not_supported));
notSupported.setSummaryText(getContext().getString(R.string.label_click_to_help_add_support)); notSupported.setSummaryText(requireContext().getString(R.string.label_click_to_help_add_support));
notSupported.setOnClickListener(new View.OnClickListener() { notSupported.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@@ -188,10 +188,10 @@ public class BluetoothSettingsFragment extends Fragment {
return; return;
} }
BluetoothDeviceView deviceView = new BluetoothDeviceView(getContext()); BluetoothDeviceView deviceView = new BluetoothDeviceView(requireContext());
deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice())); deviceView.setDeviceName(formatDeviceName(bleScanResult.getDevice()));
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(getContext(), device.getName()); BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(requireContext(), device.getName());
if (btDevice != null) { if (btDevice != null) {
Timber.d("Found supported device %s (driver: %s)", Timber.d("Found supported device %s (driver: %s)",
formatDeviceName(device), btDevice.driverName()); formatDeviceName(device), btDevice.driverName());
@@ -203,7 +203,7 @@ public class BluetoothSettingsFragment extends Fragment {
Timber.d("Found unsupported device %s", Timber.d("Found unsupported device %s",
formatDeviceName(device)); formatDeviceName(device));
deviceView.setIcon(R.drawable.ic_bluetooth_device_not_supported); 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); deviceView.setEnabled(false);
if (OpenScale.DEBUG_MODE) { if (OpenScale.DEBUG_MODE) {
@@ -222,7 +222,7 @@ public class BluetoothSettingsFragment extends Fragment {
} }
private void getDebugInfo(final BluetoothDevice device) { private void getDebugInfo(final BluetoothDevice device) {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
builder.setTitle("Fetching info") builder.setTitle("Fetching info")
.setMessage("Please wait while we fetch extended info from your scale...") .setMessage("Please wait while we fetch extended info from your scale...")
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@@ -320,7 +320,7 @@ public class BluetoothSettingsFragment extends Fragment {
public void setIcon(int resId) { public void setIcon(int resId) {
deviceIcon.setImageResource(resId); deviceIcon.setImageResource(resId);
int tintColor = ColorUtil.getTintColor(getContext()); int tintColor = ColorUtil.getTintColor(requireContext());
deviceIcon.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN); deviceIcon.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
} }
@@ -342,7 +342,7 @@ public class BluetoothSettingsFragment extends Fragment {
public void onClick(View view) { public void onClick(View view) {
BluetoothDevice device = foundDevices.get(getDeviceAddress()); BluetoothDevice device = foundDevices.get(getDeviceAddress());
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireContext());
prefs.edit() prefs.edit()
.putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress()) .putString(PREFERENCE_KEY_BLUETOOTH_HW_ADDRESS, device.getAddress())
@@ -379,7 +379,7 @@ public class BluetoothSettingsFragment extends Fragment {
startBluetoothDiscovery(); startBluetoothDiscovery();
} }
} else { } 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; break;
} }