SDK checking cleanup 2

This commit is contained in:
Milos Kozak 2019-08-03 20:00:56 +02:00
parent c9d1cc6a24
commit 81eeb66538
4 changed files with 30 additions and 42 deletions

View file

@ -11,11 +11,7 @@ class RequestDexcomPermissionActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(arrayOf(SourceDexcomPlugin.PERMISSION), requestCode)
} else {
finish()
}
requestPermissions(arrayOf(SourceDexcomPlugin.PERMISSION), requestCode)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

View file

@ -1,15 +1,5 @@
package info.nightscout.androidaps.plugins.pump.common.dialog;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
@ -21,7 +11,6 @@ import android.bluetooth.le.ScanSettings;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.ParcelUuid;
@ -41,6 +30,16 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
@ -89,7 +88,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
mHandler = new Handler();
mLeDeviceListAdapter = new LeDeviceListAdapter();
listBTScan = (ListView)findViewById(R.id.rileylink_listBTScan);
listBTScan = (ListView) findViewById(R.id.rileylink_listBTScan);
listBTScan.setAdapter(mLeDeviceListAdapter);
listBTScan.setOnItemClickListener((parent, view, position, id) -> {
@ -99,7 +98,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
mLEScanner.stopScan(mScanCallback2);
}
TextView textview = (TextView)view.findViewById(R.id.rileylink_device_address);
TextView textview = (TextView) view.findViewById(R.id.rileylink_device_address);
String bleAddress = textview.getText().toString();
SP.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);
@ -114,7 +113,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
finish();
});
toolbarBTScan = (Toolbar)findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan = (Toolbar) findViewById(R.id.rileylink_toolbarBTScan);
toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
setSupportActionBar(toolbarBTScan);
@ -161,8 +160,8 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
// you can selectively disable BLE-related features.
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// your code that requires permission
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION },
PERMISSION_REQUEST_COARSE_LOCATION);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_COARSE_LOCATION},
PERMISSION_REQUEST_COARSE_LOCATION);
}
// Ensures Bluetooth is available on the device and it is enabled. If not,
@ -171,20 +170,15 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
Toast.makeText(this, R.string.rileylink_scanner_ble_not_enabled, Toast.LENGTH_SHORT).show();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// Will request that GPS be enabled for devices running Marshmallow or newer.
if (!LocationHelper.isLocationEnabled(this)) {
LocationHelper.requestLocationForBluetooth(this);
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
// Will request that GPS be enabled for devices running Marshmallow or newer.
if (!LocationHelper.isLocationEnabled(this)) {
LocationHelper.requestLocationForBluetooth(this);
}
mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
filters = Arrays.asList(new ScanFilter.Builder().setServiceUuid(
ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build());
ParcelUuid.fromString(GattAttributes.SERVICE_RADIO)).build());
}
}
@ -268,7 +262,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
private String getDeviceDebug(BluetoothDevice device) {
return "BluetoothDevice [name=" + device.getName() + ", address=" + device.getAddress() + //
", type=" + device.getType(); // + ", alias=" + device.getAlias();
", type=" + device.getType(); // + ", alias=" + device.getAlias();
}
@ -276,7 +270,7 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
public void onScanFailed(int errorCode) {
Log.e("Scan Failed", "Error Code: " + errorCode);
Toast.makeText(mContext, MainApp.gs(R.string.rileylink_scanner_scanning_error, errorCode),
Toast.LENGTH_LONG).show();
Toast.LENGTH_LONG).show();
}
};
@ -384,11 +378,11 @@ public class RileyLinkBLEScanActivity extends AppCompatActivity {
if (view == null) {
view = mInflator.inflate(R.layout.rileylink_scan_item, null);
viewHolder = new ViewHolder();
viewHolder.deviceAddress = (TextView)view.findViewById(R.id.rileylink_device_address);
viewHolder.deviceName = (TextView)view.findViewById(R.id.rileylink_device_name);
viewHolder.deviceAddress = (TextView) view.findViewById(R.id.rileylink_device_address);
viewHolder.deviceName = (TextView) view.findViewById(R.id.rileylink_device_name);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder)view.getTag();
viewHolder = (ViewHolder) view.getTag();
}
BluetoothDevice device = mLeDevices.get(i);

View file

@ -24,11 +24,11 @@ public class LocationHelper {
* @return true if location is enabled, false otherwise.
*/
public static boolean isLocationEnabled(Context context) {
LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return (locationManager != null && //
(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || //
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)));
(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || //
locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)));
// return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
@ -69,9 +69,7 @@ public class LocationHelper {
*/
public static void requestLocationForBluetooth(Activity activity) {
// Location needs to be enabled for Bluetooth discovery on Marshmallow.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
LocationHelper.requestLocation(activity);
}
LocationHelper.requestLocation(activity);
}
// public static Boolean locationPermission(ActivityWithMenu act) {

View file

@ -44,7 +44,7 @@ object SourceDexcomPlugin : PluginBase(PluginDescription()
override fun onStart() {
super.onStart()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && ContextCompat.checkSelfPermission(MainApp.instance(), PERMISSION) != PackageManager.PERMISSION_GRANTED) {
if (ContextCompat.checkSelfPermission(MainApp.instance(), PERMISSION) != PackageManager.PERMISSION_GRANTED) {
val intent = Intent(MainApp.instance(), RequestDexcomPermissionActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
MainApp.instance().startActivity(intent)