本文整理汇总了Java中com.eveningoutpost.dexdrip.G5Model.Extensions.lastTwoCharactersOfString方法的典型用法代码示例。如果您正苦于以下问题:Java Extensions.lastTwoCharactersOfString方法的具体用法?Java Extensions.lastTwoCharactersOfString怎么用?Java Extensions.lastTwoCharactersOfString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.eveningoutpost.dexdrip.G5Model.Extensions
的用法示例。
在下文中一共展示了Extensions.lastTwoCharactersOfString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupLeScanCallback
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private void setupLeScanCallback() {
if (mLeScanCallback == null) {
mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
// Check if the device has a name, the Dexcom transmitter always should. Match it with the transmitter id that was entered.
// We get the last 2 characters to connect to the correct transmitter if there is more than 1 active or in the room.
// If they match, connect to the device.
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.toUpperCase().equals(deviceNameLastTwo.toUpperCase())) {
connectToDevice(device);
}
}
}
};
}
}
示例2: getTransmitterDetails
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private void getTransmitterDetails() {
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Log.d(TAG, "Transmitter: " + prefs.getString("dex_txid", "ABCDEF"));
defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
isBondedOrBonding = false;
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
isBondedOrBonding = true;
} else {
isIntialScan = true;
}
}
}
}
Log.d(TAG, "Bonded? " + isBondedOrBonding.toString());
}
示例3: getTransmitterDetails
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private synchronized void getTransmitterDetails() {
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Log.d(TAG, "Transmitter: " + prefs.getString("dex_txid", "ABCDEF"));
defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
final boolean previousBondedState = isBonded;
isBondedOrBonding = false;
isBonded = false;
if (mBluetoothAdapter == null) {
Log.wtf(TAG, "No bluetooth adapter");
return;
}
final Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
final String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
final String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
isBondedOrBonding = true;
isBonded=true;
if (!previousBondedState) Log.e(TAG,"Device is now detected as bonded!");
// TODO should we break here for performance?
} else {
isIntialScan = true;
}
}
}
}
if (previousBondedState && !isBonded) Log.e(TAG,"Device is no longer detected as bonded!");
Log.d(TAG, "getTransmitterDetails() result: Bonded? " + isBondedOrBonding.toString()+(isBonded ? " localed bonded" : " not locally bonded"));
}
示例4: setupBluetooth
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
public void setupBluetooth() {
getTransmitterDetails();
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
//First time using the app or bluetooth was turned off?
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
Timer single_timer = new Timer();
single_timer.schedule(new TimerTask() {
@Override
public void run() {
if (mBluetoothAdapter != null) mBluetoothAdapter.enable();
}
}, 1000);
single_timer.schedule(new TimerTask() {
@Override
public void run() {
setupBluetooth();
}
}, 10000);
} else {
if (Build.VERSION.SDK_INT >= 21) {
mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
filters = new ArrayList<>();
//Only look for CGM.
//filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothServices.Advertisement)).build());
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
filters.add(new ScanFilter.Builder().setDeviceName("Dexcom" + transmitterIdLastTwo).build());
}
// unbond here to avoid clashes when we are mid-connection
if (alwaysUnbond()) {
forgetDevice();
}
JoH.ratelimit("G5-timeout",0);//re-init to ensure onStartCommand always executes cycleScan
cycleScan(0);
}
}
示例5: getTransmitterDetails
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private synchronized void getTransmitterDetails() {
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Log.d(TAG, "Transmitter: " + prefs.getString("dex_txid", "ABCDEF"));
defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
final boolean previousBondedState = isBonded;
isBondedOrBonding = false;
isBonded = false;
static_is_bonded = false;
if (mBluetoothAdapter == null) {
Log.wtf(TAG, "No bluetooth adapter");
return;
}
final Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
final String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
final String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
isBondedOrBonding = true;
isBonded=true;
static_is_bonded = true;
if (!previousBondedState) Log.e(TAG,"Device is now detected as bonded!");
// TODO should we break here for performance?
} else {
isIntialScan = true;
}
}
}
}
if (previousBondedState && !isBonded) Log.e(TAG,"Device is no longer detected as bonded!");
Log.d(TAG, "getTransmitterDetails() result: Bonded? " + isBondedOrBonding.toString()+(isBonded ? " localed bonded" : " not locally bonded"));
}
示例6: setCurrentDevice
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
public void setCurrentDevice() {
if (activeBluetoothDevice != null) {
current_device.setText(activeBluetoothDevice.name);
} else {
current_device.setText("None Set");
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if (collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
if (Build.VERSION.SDK_INT >= 18) {
mBluetoothAdapter = mBluetoothManager.getAdapter();
}
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
current_device.setText(defaultTransmitter.transmitterId);
}
}
}
}
} else {
current_device.setText("No Bluetooth");
}
}
}
示例7: setCurrentDevice
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
public void setCurrentDevice() {
if(activeBluetoothDevice != null) {
current_device.setText(activeBluetoothDevice.name);
} else {
current_device.setText("None Set");
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if (collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
mBluetoothAdapter = mBluetoothManager.getAdapter();
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if ((pairedDevices != null) && (pairedDevices.size() > 0)) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
current_device.setText(defaultTransmitter.transmitterId);
}
}
}
}
} else {
current_device.setText("No Bluetooth");
}
}
}
示例8: setupBluetooth
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
public void setupBluetooth() {
getTransmitterDetails();
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
//First time using the app or bluetooth was turned off?
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
Timer single_timer = new Timer();
single_timer.schedule(new TimerTask() {
@Override
public void run() {
mBluetoothAdapter.enable();
}
}, 1000);
single_timer.schedule(new TimerTask() {
@Override
public void run() {
setupBluetooth();
}
}, 10000);
} else {
if (Build.VERSION.SDK_INT >= 21) {
mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
filters = new ArrayList<>();
//Only look for CGM.
//filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothServices.Advertisement)).build());
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
filters.add(new ScanFilter.Builder().setDeviceName("Dexcom" + transmitterIdLastTwo).build());
}
cycleScan(0);
}
}
示例9: setCurrentDevice
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
public void setCurrentDevice() {
if(activeBluetoothDevice != null) {
current_device.setText(activeBluetoothDevice.name);
} else {
current_device.setText("None Set");
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if(collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
mBluetoothAdapter = mBluetoothManager.getAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
current_device.setText(defaultTransmitter.transmitterId);
}
}
}
}
}
}
示例10: setConnectionStatus
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private void setConnectionStatus() {
boolean connected = false;
if (mBluetoothManager != null && activeBluetoothDevice != null) {
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
connected = true;
}
}
}
if(connected) {
connection_status.setText("Connected");
} else {
connection_status.setText("Not Connected");
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if(collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
mBluetoothAdapter = mBluetoothManager.getAdapter();
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
connection_status.setText(device.getName() + "\nAuthenticated");
}
}
}
}
}
}
示例11: setConnectionStatus
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private void setConnectionStatus() {
boolean connected = false;
if (mBluetoothManager != null && activeBluetoothDevice != null) {
for (BluetoothDevice bluetoothDevice : mBluetoothManager.getConnectedDevices(BluetoothProfile.GATT)) {
if (bluetoothDevice.getAddress().compareTo(activeBluetoothDevice.address) == 0) {
connected = true;
}
}
}
if(connected) {
connection_status.setText("Connected");
} else {
connection_status.setText("Not Connected");
}
String collection_method = prefs.getString("dex_collection_method", "BluetoothWixel");
if(collection_method.compareTo("DexcomG5") == 0) {
Transmitter defaultTransmitter = new Transmitter(prefs.getString("dex_txid", "ABCDEF"));
mBluetoothAdapter = mBluetoothManager.getAdapter();
if (mBluetoothAdapter != null) {
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
if (pairedDevices.size() > 0) {
for (BluetoothDevice device : pairedDevices) {
if (device.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(device.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
final String fw = G5CollectionService.getFirmwareVersionString(defaultTransmitter.transmitterId);
connection_status.setText(device.getName() + " Authed" + ((fw != null) ? ("\n" + fw) : ""));
break;
}
}
}
}
} else {
connection_status.setText("No bluetooth");
}
}
}
示例12: setupBluetooth
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
public void setupBluetooth() {
getTransmitterDetails();
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
//First time using the app or bluetooth was turned off?
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
Timer single_timer = new Timer();
single_timer.schedule(new TimerTask() {
@Override
public void run() {
try {
if (mBluetoothAdapter != null) mBluetoothAdapter.enable();
} catch (SecurityException e) {
JoH.static_toast_short("Please enable Bluetooth!");
}
}
}, 1000);
single_timer.schedule(new TimerTask() {
@Override
public void run() {
setupBluetooth();
}
}, 10000);
} else {
if (Build.VERSION.SDK_INT >= 21) {
mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
settings = new ScanSettings.Builder()
.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
.build();
filters = new ArrayList<>();
//Only look for CGM.
//filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothServices.Advertisement)).build());
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
filters.add(new ScanFilter.Builder().setDeviceName("Dexcom" + transmitterIdLastTwo).build());
}
// unbond here to avoid clashes when we are mid-connection
if (alwaysUnbond()) {
forgetDevice();
}
JoH.ratelimit("G5-timeout",0);//re-init to ensure onStartCommand always executes cycleScan
cycleScan(0);
}
}
示例13: initScanCallback
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private void initScanCallback(){
mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
UserError.Log.i(TAG, "result: " + result.toString());
BluetoothDevice btDevice = result.getDevice();
// // Check if the device has a name, the Dexcom transmitter always should. Match it with the transmitter id that was entered.
// // We get the last 2 characters to connect to the correct transmitter if there is more than 1 active or in the room.
// // If they match, connect to the device.
if (btDevice.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(btDevice.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
if (advertiseTimeMS.size() > 0)
if ((new Date().getTime() - advertiseTimeMS.get(advertiseTimeMS.size()-1)) > 2.5*60*1000)
advertiseTimeMS.clear();
advertiseTimeMS.add(new Date().getTime());
isIntialScan = false;
//device = btDevice;
device = mBluetoothAdapter.getRemoteDevice(btDevice.getAddress());
if (fullWake != null) JoH.releaseWakeLock(fullWake);
stopScan();
connectToDevice(btDevice);
} else {
//stopScan(10000);
}
}
}
@Override
public void onScanFailed(int errorCode) {
Log.e(TAG, "Scan Failed Error Code: " + errorCode);
if (fullWake != null) JoH.releaseWakeLock(fullWake);
if (errorCode == 1) {
UserError.Log.e(TAG, "Already Scanning: " + isScanning);
//isScanning = true;
} else if (errorCode == 2){
cycleBT();
}
}
};
}
示例14: getTransmitterBluetoothName
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private String getTransmitterBluetoothName() {
final String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(transmitterID);
// todo check for bad config
return "Dexcom" + transmitterIdLastTwo;
}
示例15: initScanCallback
import com.eveningoutpost.dexdrip.G5Model.Extensions; //导入方法依赖的package包/类
private void initScanCallback(){
mScanCallback = new ScanCallback() {
@Override
public void onScanResult(int callbackType, ScanResult result) {
UserError.Log.i(TAG, "result: " + result.toString());
BluetoothDevice btDevice = result.getDevice();
// // Check if the device has a name, the Dexcom transmitter always should. Match it with the transmitter id that was entered.
// // We get the last 2 characters to connect to the correct transmitter if there is more than 1 active or in the room.
// // If they match, connect to the device.
if (btDevice.getName() != null) {
String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
String deviceNameLastTwo = Extensions.lastTwoCharactersOfString(btDevice.getName());
if (transmitterIdLastTwo.equals(deviceNameLastTwo)) {
if (advertiseTimeMS.size() > 0)
if ((new Date().getTime() - advertiseTimeMS.get(advertiseTimeMS.size()-1)) > 2.5*60*1000)
advertiseTimeMS.clear();
advertiseTimeMS.add(new Date().getTime());
isIntialScan = false;
//device = btDevice;
device = mBluetoothAdapter.getRemoteDevice(btDevice.getAddress());
static_device_address = btDevice.getAddress();
stopScan();
connectToDevice(btDevice);
} else {
//stopScan(10000);
}
}
}
@Override
public void onScanFailed(int errorCode) {
Log.e(TAG, "Scan Failed Error Code: " + errorCode);
if (errorCode == 1) {
UserError.Log.e(TAG, "Already Scanning: " + isScanning);
//isScanning = true;
} else if (errorCode == 2){
cycleBT();
}
}
};
}