mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-22 08:04:22 +01:00
Version 1.17.0
This commit is contained in:
@@ -50,6 +50,7 @@ import android.widget.Toast;
|
||||
import java.util.List;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.adapter.AppAdapter;
|
||||
import no.nordicsemi.android.nrftoolbox.hrs.HRSActivity;
|
||||
|
||||
public class FeaturesActivity extends AppCompatActivity {
|
||||
private static final String NRF_CONNECT_CATEGORY = "no.nordicsemi.android.nrftoolbox.LAUNCHER";
|
||||
@@ -58,6 +59,10 @@ public class FeaturesActivity extends AppCompatActivity {
|
||||
private static final String NRF_CONNECT_CLASS = NRF_CONNECT_PACKAGE + ".DeviceListActivity";
|
||||
private static final String NRF_CONNECT_MARKET_URI = "market://details?id=no.nordicsemi.android.mcp";
|
||||
|
||||
// Extras that can be passed from NFC (see SplashscreenActivity)
|
||||
public static final String EXTRA_APP = "application/vnd.no.nordicsemi.type.app";
|
||||
public static final String EXTRA_ADDRESS = "application/vnd.no.nordicsemi.type.address";
|
||||
|
||||
private DrawerLayout mDrawerLayout;
|
||||
private ActionBarDrawerToggle mDrawerToggle;
|
||||
|
||||
@@ -84,7 +89,7 @@ public class FeaturesActivity extends AppCompatActivity {
|
||||
super.onDrawerSlide(drawerView, 0);
|
||||
}
|
||||
};
|
||||
drawer.setDrawerListener(mDrawerToggle);
|
||||
drawer.addDrawerListener(mDrawerToggle);
|
||||
|
||||
// setup plug-ins in the drawer
|
||||
setupPluginsInDrawer((ViewGroup) drawer.findViewById(R.id.plugin_container));
|
||||
@@ -95,6 +100,22 @@ public class FeaturesActivity extends AppCompatActivity {
|
||||
grid.setEmptyView(findViewById(android.R.id.empty));
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (intent.hasExtra(EXTRA_APP) && intent.hasExtra(EXTRA_ADDRESS)) {
|
||||
final String app = intent.getStringExtra(EXTRA_APP);
|
||||
switch (app) {
|
||||
case "HRM":
|
||||
final Intent newIntent = new Intent(this, HRSActivity.class);
|
||||
newIntent.putExtra(EXTRA_ADDRESS, intent.getByteArrayExtra(EXTRA_ADDRESS));
|
||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
startActivity(newIntent);
|
||||
break;
|
||||
default:
|
||||
// other are not supported yet
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,8 +23,12 @@ package no.nordicsemi.android.nrftoolbox;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.nfc.NdefMessage;
|
||||
import android.nfc.NdefRecord;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class SplashscreenActivity extends Activity {
|
||||
/** Splash screen duration time in milliseconds */
|
||||
@@ -39,9 +43,34 @@ public class SplashscreenActivity extends Activity {
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Intent intent = new Intent(SplashscreenActivity.this, FeaturesActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
startActivity(intent);
|
||||
final Intent newIntent = new Intent(SplashscreenActivity.this, FeaturesActivity.class);
|
||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
|
||||
|
||||
// Handle NFC message, if app was opened using NFC AAR record
|
||||
final Intent intent = getIntent();
|
||||
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
|
||||
final Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
|
||||
if (rawMsgs != null) {
|
||||
for (int i = 0; i < rawMsgs.length; i++) {
|
||||
final NdefMessage msg = (NdefMessage) rawMsgs[i];
|
||||
final NdefRecord[] records = msg.getRecords();
|
||||
|
||||
for (NdefRecord record : records) {
|
||||
if (record.getTnf() == NdefRecord.TNF_MIME_MEDIA) {
|
||||
switch (record.toMimeType()) {
|
||||
case FeaturesActivity.EXTRA_APP:
|
||||
newIntent.putExtra(FeaturesActivity.EXTRA_APP, new String(record.getPayload()));
|
||||
break;
|
||||
case FeaturesActivity.EXTRA_ADDRESS:
|
||||
newIntent.putExtra(FeaturesActivity.EXTRA_ADDRESS, invertEndianness(record.getPayload()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
startActivity(newIntent);
|
||||
finish();
|
||||
}
|
||||
}, DELAY);
|
||||
@@ -52,4 +81,18 @@ public class SplashscreenActivity extends Activity {
|
||||
// do nothing. Protect from exiting the application when splash screen is shown
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts endianness of the byte array.
|
||||
* @param bytes input byte array
|
||||
* @return byte array in opposite order
|
||||
*/
|
||||
private byte[] invertEndianness(final byte[] bytes) {
|
||||
if (bytes == null)
|
||||
return null;
|
||||
final int length = bytes.length;
|
||||
final byte[] result = new byte[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
result[i] = bytes[length - i - 1];
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.hrs;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Point;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -32,6 +35,7 @@ import org.achartengine.GraphicalView;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.FeaturesActivity;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleManager;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileActivity;
|
||||
@@ -83,18 +87,31 @@ public class HRSActivity extends BleProfileActivity implements HRSManagerCallbac
|
||||
layout.addView(mGraphView);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (!isDeviceConnected() && intent.hasExtra(FeaturesActivity.EXTRA_ADDRESS)) {
|
||||
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
final BluetoothDevice device = bluetoothAdapter.getRemoteDevice(getIntent().getByteArrayExtra(FeaturesActivity.EXTRA_ADDRESS));
|
||||
onDeviceSelected(device, device.getName());
|
||||
|
||||
intent.removeExtra(FeaturesActivity.EXTRA_APP);
|
||||
intent.removeExtra(FeaturesActivity.EXTRA_ADDRESS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
isGraphInProgress = savedInstanceState.getBoolean(GRAPH_STATUS);
|
||||
mCounter = savedInstanceState.getInt(GRAPH_COUNTER);
|
||||
mHrmValue = savedInstanceState.getInt(HR_VALUE);
|
||||
isGraphInProgress = savedInstanceState.getBoolean(GRAPH_STATUS);
|
||||
mCounter = savedInstanceState.getInt(GRAPH_COUNTER);
|
||||
mHrmValue = savedInstanceState.getInt(HR_VALUE);
|
||||
|
||||
if (isGraphInProgress)
|
||||
startShowGraph();
|
||||
}
|
||||
if (isGraphInProgress)
|
||||
startShowGraph();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -228,7 +228,8 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
|
||||
mDeviceName = name;
|
||||
mBleManager.setLogger(mLogSession);
|
||||
mDeviceNameView.setText(name != null ? name : getString(R.string.not_available));
|
||||
mConnectButton.setText(R.string.action_disconnect);
|
||||
mConnectButton.setText(R.string.action_connecting);
|
||||
mConnectButton.setEnabled(false);
|
||||
mBleManager.connect(device);
|
||||
}
|
||||
|
||||
@@ -244,6 +245,7 @@ public abstract class BleProfileActivity extends AppCompatActivity implements Bl
|
||||
@Override
|
||||
public void run() {
|
||||
mConnectButton.setText(R.string.action_disconnect);
|
||||
mConnectButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -225,7 +225,8 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
mDeviceName = name;
|
||||
mBleManager.setLogger(mLogSession);
|
||||
mDeviceNameView.setText(name != null ? name : getString(R.string.not_available));
|
||||
mConnectButton.setText(R.string.action_disconnect);
|
||||
mConnectButton.setText(R.string.action_connecting);
|
||||
mConnectButton.setEnabled(false);
|
||||
mBleManager.connect(device);
|
||||
}
|
||||
|
||||
@@ -241,6 +242,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
@Override
|
||||
public void run() {
|
||||
mConnectButton.setText(R.string.action_disconnect);
|
||||
mConnectButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -443,7 +443,8 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
}
|
||||
mDeviceName = name;
|
||||
mDeviceNameView.setText(name != null ? name : getString(R.string.not_available));
|
||||
mConnectButton.setText(R.string.action_disconnect);
|
||||
mConnectButton.setText(R.string.action_connecting);
|
||||
mConnectButton.setEnabled(false);
|
||||
|
||||
// The device may not be in the range but the service will try to connect to it if it reach it
|
||||
Logger.d(mLogSession, "Creating service...");
|
||||
@@ -469,6 +470,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
public void onDeviceConnected() {
|
||||
mDeviceNameView.setText(mDeviceName);
|
||||
mConnectButton.setText(R.string.action_disconnect);
|
||||
mConnectButton.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user