mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-22 16:14:23 +01:00
Version 1.14.0
Switching to AppCompatActivity, better Navigation drawer, DFU bug fixed.
This commit is contained in:
@@ -21,11 +21,12 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
public class AppHelpFragment extends DialogFragment {
|
||||
private static final String ARG_TEXT = "ARG_TEXT";
|
||||
@@ -54,6 +55,7 @@ public class AppHelpFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final Bundle args = getArguments();
|
||||
final StringBuilder text = new StringBuilder(getString(args.getInt(ARG_TEXT)));
|
||||
|
||||
@@ -34,8 +34,9 @@ import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -50,7 +51,7 @@ import java.util.List;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.adapter.AppAdapter;
|
||||
|
||||
public class FeaturesActivity extends ActionBarActivity {
|
||||
public class FeaturesActivity extends AppCompatActivity {
|
||||
private static final String MCP_CATEGORY = "no.nordicsemi.android.nrftoolbox.LAUNCHER";
|
||||
private static final String UTILS_CATEGORY = "no.nordicsemi.android.nrftoolbox.UTILS";
|
||||
private static final String MCP_PACKAGE = "no.nordicsemi.android.mcp";
|
||||
@@ -65,6 +66,9 @@ public class FeaturesActivity extends ActionBarActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_features);
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
// ensure that Bluetooth exists
|
||||
if (!ensureBLEExists())
|
||||
finish();
|
||||
@@ -73,7 +77,13 @@ public class FeaturesActivity extends ActionBarActivity {
|
||||
drawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
|
||||
|
||||
// Set the drawer toggle as the DrawerListener
|
||||
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
|
||||
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
|
||||
@Override
|
||||
public void onDrawerSlide(final View drawerView, final float slideOffset) {
|
||||
// Disable the Hamburger icon animation
|
||||
super.onDrawerSlide(drawerView, 0);
|
||||
}
|
||||
};
|
||||
drawer.setDrawerListener(mDrawerToggle);
|
||||
|
||||
// setup plug-ins in the drawer
|
||||
@@ -117,7 +127,7 @@ public class FeaturesActivity extends ActionBarActivity {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_about:
|
||||
final AppHelpFragment fragment = AppHelpFragment.getInstance(R.string.about_text, true);
|
||||
fragment.show(getFragmentManager(), null);
|
||||
fragment.show(getSupportFragmentManager(), null);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -19,7 +19,8 @@ package no.nordicsemi.android.nrftoolbox.app;
|
||||
import android.app.Activity;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.View;
|
||||
@@ -132,7 +133,7 @@ import no.nordicsemi.android.nrftoolbox.R;
|
||||
* @see #setListAdapter
|
||||
* @see android.widget.ExpandableListView
|
||||
*/
|
||||
public class ExpandableListActivity extends ActionBarActivity implements
|
||||
public class ExpandableListActivity extends AppCompatActivity implements
|
||||
OnCreateContextMenuListener,
|
||||
ExpandableListView.OnChildClickListener, ExpandableListView.OnGroupCollapseListener,
|
||||
ExpandableListView.OnGroupExpandListener {
|
||||
@@ -182,7 +183,7 @@ public class ExpandableListActivity extends ActionBarActivity implements
|
||||
* @see Activity#onRestoreInstanceState(Bundle)
|
||||
*/
|
||||
@Override
|
||||
protected void onRestoreInstanceState(Bundle state) {
|
||||
protected void onRestoreInstanceState(@NonNull Bundle state) {
|
||||
ensureList();
|
||||
super.onRestoreInstanceState(state);
|
||||
}
|
||||
@@ -190,10 +191,10 @@ public class ExpandableListActivity extends ActionBarActivity implements
|
||||
/**
|
||||
* Updates the screen state (current list and other views) when the content changes.
|
||||
*
|
||||
* @see ActionBarActivity#onSupportContentChanged()
|
||||
* @see android.support.v7.app.AppCompatActivity#onContentChanged()
|
||||
*/
|
||||
@Override
|
||||
public void onSupportContentChanged() {
|
||||
public void onContentChanged() {
|
||||
super.onContentChanged();
|
||||
View emptyView = findViewById(R.id.empty);
|
||||
mList = (ExpandableListView) findViewById(R.id.list);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class BPMActivity extends BleProfileActivity implements BPMManagerCallbac
|
||||
private TextView mTimestampView;
|
||||
|
||||
@Override
|
||||
protected void onCreateView(Bundle savedInstanceState) {
|
||||
protected void onCreateView(final Bundle savedInstanceState) {
|
||||
setContentView(R.layout.activity_feature_bpm);
|
||||
setGUI();
|
||||
}
|
||||
|
||||
@@ -23,19 +23,25 @@
|
||||
package no.nordicsemi.android.nrftoolbox.csc.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class SettingsActivity extends ActionBarActivity {
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
|
||||
getFragmentManager().beginTransaction().replace(R.id.content, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,8 +23,6 @@ package no.nordicsemi.android.nrftoolbox.dfu;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningServiceInfo;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.FragmentManager;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.app.NotificationManager;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
@@ -47,8 +45,9 @@ import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@@ -81,7 +80,7 @@ import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
* DeviceScannerFragment.OnDeviceSelectedListener callback to receive callback when device is selected from scanning dialog The activity supports portrait and
|
||||
* landscape orientations
|
||||
*/
|
||||
public class DfuActivity extends ActionBarActivity implements LoaderCallbacks<Cursor>, ScannerFragment.OnDeviceSelectedListener,
|
||||
public class DfuActivity extends AppCompatActivity implements LoaderCallbacks<Cursor>, ScannerFragment.OnDeviceSelectedListener,
|
||||
UploadCancelFragment.CancelFragmentListener {
|
||||
private static final String TAG = "DfuActivity";
|
||||
|
||||
@@ -197,8 +196,9 @@ public class DfuActivity extends ActionBarActivity implements LoaderCallbacks<Cu
|
||||
}
|
||||
|
||||
private void setGUI() {
|
||||
final ActionBar actionBar = getSupportActionBar();
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
mDeviceNameView = (TextView) findViewById(R.id.device_name);
|
||||
mFileNameView = (TextView) findViewById(R.id.file_name);
|
||||
@@ -270,9 +270,8 @@ public class DfuActivity extends ActionBarActivity implements LoaderCallbacks<Cu
|
||||
}
|
||||
|
||||
private void showDeviceScanningDialog() {
|
||||
final FragmentManager fm = getFragmentManager();
|
||||
final ScannerFragment dialog = ScannerFragment.getInstance(DfuActivity.this, null, false); // Device that is advertising directly does not have the GENERAL_DISCOVERABLE nor LIMITED_DISCOVERABLE flag set.
|
||||
dialog.show(fm, "scan_fragment");
|
||||
dialog.show(getSupportFragmentManager(), "scan_fragment");
|
||||
}
|
||||
|
||||
private void ensureSamplesExist() {
|
||||
@@ -436,7 +435,7 @@ public class DfuActivity extends ActionBarActivity implements LoaderCallbacks<Cu
|
||||
break;
|
||||
case R.id.action_about:
|
||||
final AppHelpFragment fragment = AppHelpFragment.getInstance(R.string.dfu_about_text);
|
||||
fragment.show(getFragmentManager(), "help_fragment");
|
||||
fragment.show(getSupportFragmentManager(), "help_fragment");
|
||||
break;
|
||||
case R.id.action_settings:
|
||||
final Intent intent = new Intent(this, SettingsActivity.class);
|
||||
@@ -676,7 +675,7 @@ public class DfuActivity extends ActionBarActivity implements LoaderCallbacks<Cu
|
||||
@Override
|
||||
public void onClick(final DialogInterface dialog, final int which) {
|
||||
final ZipInfoFragment fragment = new ZipInfoFragment();
|
||||
fragment.show(getFragmentManager(), "help_fragment");
|
||||
fragment.show(getSupportFragmentManager(), "help_fragment");
|
||||
}
|
||||
}).setNegativeButton(R.string.cancel, null).show();
|
||||
}
|
||||
@@ -763,7 +762,7 @@ public class DfuActivity extends ActionBarActivity implements LoaderCallbacks<Cu
|
||||
manager.sendBroadcast(pauseAction);
|
||||
|
||||
final UploadCancelFragment fragment = UploadCancelFragment.getInstance();
|
||||
fragment.show(getFragmentManager(), TAG);
|
||||
fragment.show(getSupportFragmentManager(), TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,10 +22,10 @@
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.dfu;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.scanner.ScannerFragment;
|
||||
|
||||
@@ -33,7 +33,7 @@ import no.nordicsemi.android.nrftoolbox.scanner.ScannerFragment;
|
||||
* The activity is started only by a remote connected computer using ADB. It shows a list of DFU-supported devices in range and allows user to select target device. The HEX file will be uploaded to
|
||||
* selected device using {@link DfuService}.
|
||||
*/
|
||||
public class DfuInitiatorActivity extends Activity implements ScannerFragment.OnDeviceSelectedListener {
|
||||
public class DfuInitiatorActivity extends AppCompatActivity implements ScannerFragment.OnDeviceSelectedListener {
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
@@ -46,7 +46,7 @@ public class DfuInitiatorActivity extends Activity implements ScannerFragment.On
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
final ScannerFragment fragment = ScannerFragment.getInstance(this, null, false); // Device that is advertising directly does not have the GENERAL_DISCOVERABLE nor LIMITED_DISCOVERABLE flag set.
|
||||
fragment.show(getFragmentManager(), null);
|
||||
fragment.show(getSupportFragmentManager(), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,13 +22,14 @@
|
||||
package no.nordicsemi.android.nrftoolbox.dfu.fragment;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.util.Log;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
@@ -61,7 +62,8 @@ public class UploadCancelFragment extends DialogFragment {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
return new AlertDialog.Builder(getActivity()).setTitle(R.string.dfu_confirmation_dialog_title).setMessage(R.string.dfu_upload_dialog_cancel_message).setCancelable(false)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.dfu.fragment;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
@@ -33,6 +34,7 @@ import no.nordicsemi.android.nrftoolbox.R;
|
||||
public class ZipInfoFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_zip_info, null);
|
||||
return new AlertDialog.Builder(getActivity()).setView(view).setTitle(R.string.dfu_file_info).setPositiveButton(R.string.ok, null).create();
|
||||
|
||||
@@ -23,19 +23,25 @@
|
||||
package no.nordicsemi.android.nrftoolbox.dfu.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class SettingsActivity extends ActionBarActivity {
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
|
||||
getFragmentManager().beginTransaction().replace(R.id.content, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,11 +21,12 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.dfu.settings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import no.nordicsemi.android.dfu.DfuSettingsConstants;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
@@ -81,8 +82,13 @@ public class SettingsFragment extends PreferenceFragment implements DfuSettingsC
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
final SharedPreferences preferences = getPreferenceManager().getSharedPreferences();
|
||||
|
||||
final String value = preferences.getString(SETTINGS_NUMBER_OF_PACKETS, String.valueOf(SETTINGS_NUMBER_OF_PACKETS_DEFAULT));
|
||||
screen.findPreference(SETTINGS_NUMBER_OF_PACKETS).setSummary(value);
|
||||
String value = preferences.getString(SETTINGS_NUMBER_OF_PACKETS, String.valueOf(SETTINGS_NUMBER_OF_PACKETS_DEFAULT));
|
||||
// Security check
|
||||
if (TextUtils.isEmpty(value)) {
|
||||
value = String.valueOf(SETTINGS_NUMBER_OF_PACKETS_DEFAULT);
|
||||
preferences.edit().putString(SETTINGS_NUMBER_OF_PACKETS, value).apply();
|
||||
}
|
||||
screen.findPreference(SETTINGS_NUMBER_OF_PACKETS).setSummary(value);
|
||||
|
||||
final int valueInt = Integer.parseInt(value);
|
||||
if (valueInt > 200) {
|
||||
|
||||
@@ -512,7 +512,7 @@ public class GlucoseManager extends BleManager<GlucoseManagerCallbacks> {
|
||||
/**
|
||||
* Sends the request to delete all data from the device. A Record Access Control Point indication with status code ({@link #RESPONSE_SUCCESS} (or other in case of error) will be send.
|
||||
*
|
||||
* @FIXME This method is not supported by Nordic Semiconductor Glucose Service in SDK 4.4.2.
|
||||
* FIXME This method is not supported by Nordic Semiconductor Glucose Service in SDK 4.4.2.
|
||||
*/
|
||||
public void deleteAllRecords() {
|
||||
if (mRecordAccessControlPointCharacteristic == null)
|
||||
|
||||
@@ -24,6 +24,7 @@ package no.nordicsemi.android.nrftoolbox.hrs;
|
||||
import android.graphics.Point;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -83,7 +84,7 @@ public class HRSActivity extends BleProfileActivity implements HRSManagerCallbac
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
|
||||
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
|
||||
@@ -23,19 +23,25 @@
|
||||
package no.nordicsemi.android.nrftoolbox.hts.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class SettingsActivity extends ActionBarActivity {
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
|
||||
getFragmentManager().beginTransaction().replace(R.id.content, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,9 +23,6 @@ package no.nordicsemi.android.nrftoolbox.parser;
|
||||
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// TODO this method may be used for developing purposes to log the data from your device using the nRF Logger application.
|
||||
public class TemplateParser {
|
||||
// TODO add some flags, if needed
|
||||
|
||||
@@ -29,7 +29,9 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -47,7 +49,7 @@ import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.scanner.ScannerFragment;
|
||||
import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
|
||||
public abstract class BleProfileActivity extends ActionBarActivity implements BleManagerCallbacks, ScannerFragment.OnDeviceSelectedListener {
|
||||
public abstract class BleProfileActivity extends AppCompatActivity implements BleManagerCallbacks, ScannerFragment.OnDeviceSelectedListener {
|
||||
private static final String TAG = "BaseProfileActivity";
|
||||
|
||||
private static final String CONNECTION_STATUS = "connection_status";
|
||||
@@ -82,6 +84,10 @@ public abstract class BleProfileActivity extends ActionBarActivity implements Bl
|
||||
mBleManager = initializeManager();
|
||||
onInitialize(savedInstanceState);
|
||||
onCreateView(savedInstanceState);
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
onViewCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
@@ -128,7 +134,7 @@ public abstract class BleProfileActivity extends ActionBarActivity implements Bl
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
|
||||
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
mDeviceConnected = savedInstanceState.getBoolean(CONNECTION_STATUS);
|
||||
mDeviceName = savedInstanceState.getString(DEVICE_NAME);
|
||||
@@ -167,7 +173,7 @@ public abstract class BleProfileActivity extends ActionBarActivity implements Bl
|
||||
break;
|
||||
case R.id.action_about:
|
||||
final AppHelpFragment fragment = AppHelpFragment.getInstance(getAboutTextId());
|
||||
fragment.show(getFragmentManager(), "help_fragment");
|
||||
fragment.show(getSupportFragmentManager(), "help_fragment");
|
||||
break;
|
||||
default:
|
||||
return onOptionsItemSelected(id);
|
||||
@@ -407,7 +413,7 @@ public abstract class BleProfileActivity extends ActionBarActivity implements Bl
|
||||
@Override
|
||||
public void run() {
|
||||
final ScannerFragment dialog = ScannerFragment.getInstance(BleProfileActivity.this, filter, discoverableRequired);
|
||||
dialog.show(getFragmentManager(), "scan_fragment");
|
||||
dialog.show(getSupportFragmentManager(), "scan_fragment");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -82,6 +83,10 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
mBleManager = initializeManager();
|
||||
onInitialize(savedInstanceState);
|
||||
onCreateView(savedInstanceState);
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
onViewCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
@@ -165,7 +170,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
break;
|
||||
case R.id.action_about:
|
||||
final AppHelpFragment fragment = AppHelpFragment.getInstance(getAboutTextId());
|
||||
fragment.show(getFragmentManager(), "help_fragment");
|
||||
fragment.show(getSupportFragmentManager(), "help_fragment");
|
||||
break;
|
||||
default:
|
||||
return onOptionsItemSelected(id);
|
||||
@@ -413,7 +418,7 @@ public abstract class BleProfileExpandableListActivity extends ExpandableListAct
|
||||
@Override
|
||||
public void run() {
|
||||
final ScannerFragment dialog = ScannerFragment.getInstance(BleProfileExpandableListActivity.this, filter, discoverableRequired);
|
||||
dialog.show(getFragmentManager(), "scan_fragment");
|
||||
dialog.show(getSupportFragmentManager(), "scan_fragment");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,8 +36,10 @@ import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -67,7 +69,7 @@ import no.nordicsemi.android.nrftoolbox.utility.DebugLogger;
|
||||
* listens for it. When entering back to the activity, activity will to bind to the service and refresh UI.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class BleProfileServiceReadyActivity<E extends BleProfileService.LocalBinder> extends ActionBarActivity implements
|
||||
public abstract class BleProfileServiceReadyActivity<E extends BleProfileService.LocalBinder> extends AppCompatActivity implements
|
||||
ScannerFragment.OnDeviceSelectedListener, BleManagerCallbacks {
|
||||
private static final String TAG = "BleProfileServiceReadyActivity";
|
||||
|
||||
@@ -213,6 +215,10 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
*/
|
||||
onInitialize(savedInstanceState);
|
||||
onCreateView(savedInstanceState);
|
||||
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
onViewCreated(savedInstanceState);
|
||||
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mCommonBroadcastReceiver, makeIntentFilter());
|
||||
@@ -343,7 +349,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
|
||||
protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
mDeviceName = savedInstanceState.getString(DEVICE_NAME);
|
||||
}
|
||||
@@ -374,7 +380,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
break;
|
||||
case R.id.action_about:
|
||||
final AppHelpFragment fragment = AppHelpFragment.getInstance(getAboutTextId());
|
||||
fragment.show(getFragmentManager(), "help_fragment");
|
||||
fragment.show(getSupportFragmentManager(), "help_fragment");
|
||||
break;
|
||||
default:
|
||||
return onOptionsItemSelected(id);
|
||||
@@ -643,7 +649,7 @@ public abstract class BleProfileServiceReadyActivity<E extends BleProfileService
|
||||
*/
|
||||
private void showDeviceScanningDialog(final UUID filter, final boolean discoverableRequired) {
|
||||
final ScannerFragment dialog = ScannerFragment.getInstance(BleProfileServiceReadyActivity.this, filter, discoverableRequired);
|
||||
dialog.show(getFragmentManager(), "scan_fragment");
|
||||
dialog.show(getSupportFragmentManager(), "scan_fragment");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,10 +21,11 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.proximity;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
@@ -50,7 +51,8 @@ public class LinklossFragment extends DialogFragment {
|
||||
mName = getArguments().getString(ARG_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.app_name)).setMessage(getString(R.string.proximity_notification_linkloss_alert, mName))
|
||||
.setPositiveButton(R.string.ok, null).create();
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
*/
|
||||
package no.nordicsemi.android.nrftoolbox.proximity;
|
||||
|
||||
import android.app.FragmentManager;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
@@ -201,9 +200,8 @@ public class ProximityActivity extends BleProfileServiceReadyActivity<ProximityS
|
||||
|
||||
private void showLinklossDialog(final String name) {
|
||||
try {
|
||||
FragmentManager fm = getFragmentManager();
|
||||
LinklossFragment dialog = LinklossFragment.getInstance(name);
|
||||
dialog.show(fm, "scan_fragment");
|
||||
final LinklossFragment dialog = LinklossFragment.getInstance(name);
|
||||
dialog.show(getSupportFragmentManager(), "scan_fragment");
|
||||
} catch (final Exception e) {
|
||||
// the activity must have been destroyed
|
||||
}
|
||||
|
||||
@@ -105,19 +105,19 @@ public class RSCActivity extends BleProfileServiceReadyActivity<RSCService.RSCBi
|
||||
|
||||
switch (unit) {
|
||||
case SettingsFragment.SETTINGS_UNIT_M_S: // [m/s]
|
||||
mSpeedUnitView.setText(R.string.csc_speed_unit_m_s);
|
||||
mDistanceUnitView.setText(R.string.csc_distance_unit_m);
|
||||
mTotalDistanceUnitView.setText(R.string.csc_total_distance_unit_km);
|
||||
mSpeedUnitView.setText(R.string.rsc_speed_unit_m_s);
|
||||
mDistanceUnitView.setText(R.string.rsc_distance_unit_m);
|
||||
mTotalDistanceUnitView.setText(R.string.rsc_total_distance_unit_km);
|
||||
break;
|
||||
case SettingsFragment.SETTINGS_UNIT_KM_H: // [km/h]
|
||||
mSpeedUnitView.setText(R.string.csc_speed_unit_km_h);
|
||||
mDistanceUnitView.setText(R.string.csc_distance_unit_m);
|
||||
mTotalDistanceUnitView.setText(R.string.csc_total_distance_unit_km);
|
||||
mSpeedUnitView.setText(R.string.rsc_speed_unit_km_h);
|
||||
mDistanceUnitView.setText(R.string.rsc_distance_unit_m);
|
||||
mTotalDistanceUnitView.setText(R.string.rsc_total_distance_unit_km);
|
||||
break;
|
||||
case SettingsFragment.SETTINGS_UNIT_MPH: // [mph]
|
||||
mSpeedUnitView.setText(R.string.csc_speed_unit_mph);
|
||||
mDistanceUnitView.setText(R.string.csc_distance_unit_yd);
|
||||
mTotalDistanceUnitView.setText(R.string.csc_total_distance_unit_mile);
|
||||
mSpeedUnitView.setText(R.string.rsc_speed_unit_mph);
|
||||
mDistanceUnitView.setText(R.string.rsc_distance_unit_yd);
|
||||
mTotalDistanceUnitView.setText(R.string.rsc_total_distance_unit_mile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,19 +23,25 @@
|
||||
package no.nordicsemi.android.nrftoolbox.rsc.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class SettingsActivity extends ActionBarActivity {
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
|
||||
getFragmentManager().beginTransaction().replace(R.id.content, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,9 +22,7 @@
|
||||
package no.nordicsemi.android.nrftoolbox.scanner;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothManager;
|
||||
@@ -33,6 +31,9 @@ import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.ParcelUuid;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
@@ -144,7 +145,8 @@ public class ScannerFragment extends DialogFragment {
|
||||
/**
|
||||
* When dialog is created then set AlertDialog with list and button views.
|
||||
*/
|
||||
@Override
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_device_selection, null);
|
||||
|
||||
@@ -23,19 +23,25 @@
|
||||
package no.nordicsemi.android.nrftoolbox.template.settings;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class SettingsActivity extends ActionBarActivity {
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new SettingsFragment()).commit();
|
||||
getFragmentManager().beginTransaction().replace(R.id.content, new SettingsFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -32,6 +32,7 @@ import android.graphics.drawable.TransitionDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.SlidingPaneLayout;
|
||||
import android.view.View;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
@Override
|
||||
public void onPanelClosed(final View panel) {
|
||||
// Close the keyboard
|
||||
final UARTLogFragment logFragment = (UARTLogFragment) getFragmentManager().findFragmentById(R.id.fragment_log);
|
||||
final UARTLogFragment logFragment = (UARTLogFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_log);
|
||||
logFragment.onFragmentHidden();
|
||||
}
|
||||
});
|
||||
@@ -84,7 +85,7 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRestoreInstanceState(final Bundle savedInstanceState) {
|
||||
protected void onRestoreInstanceState(final @NonNull Bundle savedInstanceState) {
|
||||
super.onRestoreInstanceState(savedInstanceState);
|
||||
|
||||
mEditMode = savedInstanceState.getBoolean(SIS_EDIT_MODE);
|
||||
@@ -134,7 +135,7 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
super.onDeviceSelected(device, name);
|
||||
|
||||
// Notify the log fragment about it
|
||||
final UARTLogFragment logFragment = (UARTLogFragment) getFragmentManager().findFragmentById(R.id.fragment_log);
|
||||
final UARTLogFragment logFragment = (UARTLogFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_log);
|
||||
logFragment.onServiceStarted();
|
||||
}
|
||||
|
||||
@@ -176,7 +177,7 @@ public class UARTActivity extends BleProfileServiceReadyActivity<UARTService.UAR
|
||||
return;
|
||||
}
|
||||
if (mEditMode) {
|
||||
final UARTControlFragment fragment = (UARTControlFragment) getFragmentManager().findFragmentById(R.id.fragment_control);
|
||||
final UARTControlFragment fragment = (UARTControlFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_control);
|
||||
fragment.setEditMode(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
package no.nordicsemi.android.nrftoolbox.uart;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
||||
@@ -22,12 +22,13 @@
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.uart;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -62,7 +63,8 @@ public class UARTEditDialog extends DialogFragment implements View.OnClickListen
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final LayoutInflater inflater = LayoutInflater.from(getActivity());
|
||||
|
||||
@@ -22,19 +22,19 @@
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.uart;
|
||||
|
||||
import android.app.ListFragment;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.CursorLoader;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.Loader;
|
||||
import android.content.ServiceConnection;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.app.LoaderManager;
|
||||
import android.support.v4.content.CursorLoader;
|
||||
import android.support.v4.content.Loader;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -53,7 +53,7 @@ import no.nordicsemi.android.log.LogContract;
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
import no.nordicsemi.android.nrftoolbox.profile.BleProfileService;
|
||||
|
||||
public class UARTLogFragment extends ListFragment implements LoaderCallbacks<Cursor> {
|
||||
public class UARTLogFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
|
||||
private static final String SIS_LOG_SCROLL_POSITION = "sis_scroll_position";
|
||||
private static final int LOG_SCROLL_NULL = -1;
|
||||
private static final int LOG_SCROLLED_TO_BOTTOM = -2;
|
||||
|
||||
@@ -93,6 +93,12 @@ public class UARTManager extends BleManager<UARTManagerCallbacks> {
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected boolean shouldAutoConnect() {
|
||||
// We want the connection to be kept
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the given text to TH characteristic.
|
||||
* @param text the text to be sent
|
||||
|
||||
@@ -192,14 +192,32 @@ public class UARTService extends BleProfileService implements UARTManagerCallbac
|
||||
};
|
||||
|
||||
/**
|
||||
* Broadcast receiver that listens for {@link #ACTION_SEND} from other apps. Sends the String content of the {@link Intent#EXTRA_TEXT} extra to the remote device.
|
||||
* Broadcast receiver that listens for {@link #ACTION_SEND} from other apps. Sends the String or int content of the {@link Intent#EXTRA_TEXT} extra to the remote device.
|
||||
* The integer content will be sent as String (65 -> "65", not 65 -> "A").
|
||||
*/
|
||||
private BroadcastReceiver mIntentBroadcastReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
Logger.i(getLogSession(), "[Broadcast] Disconnect action pressed");
|
||||
final String message = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
mManager.send(message);
|
||||
final boolean hasMessage = intent.hasExtra(Intent.EXTRA_TEXT);
|
||||
if (hasMessage) {
|
||||
String message = intent.getStringExtra(Intent.EXTRA_TEXT);
|
||||
if (message == null) {
|
||||
final int intValue = intent.getIntExtra(Intent.EXTRA_TEXT, Integer.MIN_VALUE); // how big is the chance of such data?
|
||||
if (intValue != Integer.MIN_VALUE)
|
||||
message = String.valueOf(intValue);
|
||||
}
|
||||
|
||||
if (message != null) {
|
||||
Logger.i(getLogSession(), "[Broadcast] " + ACTION_SEND + " broadcast received with data: \"" + message + "\"");
|
||||
mManager.send(message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// No data od incompatible type of EXTRA_TEXT
|
||||
if (!hasMessage)
|
||||
Logger.i(getLogSession(), "[Broadcast] " + ACTION_SEND + " broadcast received no data.");
|
||||
else
|
||||
Logger.i(getLogSession(), "[Broadcast] " + ACTION_SEND + " broadcast received incompatible data type. Only String and int are supported.");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/*************************************************************************************************************************************************
|
||||
* Copyright (c) 2015, Nordic Semiconductor
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************************************************************************************/
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
public class ForegroundLinearLayout extends LinearLayout {
|
||||
|
||||
private Drawable mForegroundSelector;
|
||||
private Rect mRectPadding;
|
||||
private boolean mUseBackgroundPadding = false;
|
||||
|
||||
public ForegroundLinearLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ForegroundLinearLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundRelativeLayout,
|
||||
defStyle, 0);
|
||||
|
||||
final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
|
||||
if (d != null) {
|
||||
setForeground(d);
|
||||
}
|
||||
|
||||
a.recycle();
|
||||
|
||||
if (this.getBackground() instanceof NinePatchDrawable) {
|
||||
final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
|
||||
mRectPadding = new Rect();
|
||||
if (npd.getPadding(mRectPadding)) {
|
||||
mUseBackgroundPadding = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawableStateChanged() {
|
||||
super.drawableStateChanged();
|
||||
|
||||
if (mForegroundSelector != null && mForegroundSelector.isStateful()) {
|
||||
mForegroundSelector.setState(getDrawableState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
|
||||
if (mForegroundSelector != null) {
|
||||
if (mUseBackgroundPadding) {
|
||||
mForegroundSelector.setBounds(mRectPadding.left, mRectPadding.top, w - mRectPadding.right, h - mRectPadding.bottom);
|
||||
} else {
|
||||
mForegroundSelector.setBounds(0, 0, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(@NonNull Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
|
||||
if (mForegroundSelector != null) {
|
||||
mForegroundSelector.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean verifyDrawable(Drawable who) {
|
||||
return super.verifyDrawable(who) || (who == mForegroundSelector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpDrawablesToCurrentState() {
|
||||
super.jumpDrawablesToCurrentState();
|
||||
if (mForegroundSelector != null) mForegroundSelector.jumpToCurrentState();
|
||||
}
|
||||
|
||||
public void setForeground(Drawable drawable) {
|
||||
if (mForegroundSelector != drawable) {
|
||||
if (mForegroundSelector != null) {
|
||||
mForegroundSelector.setCallback(null);
|
||||
unscheduleDrawable(mForegroundSelector);
|
||||
}
|
||||
|
||||
mForegroundSelector = drawable;
|
||||
|
||||
if (drawable != null) {
|
||||
setWillNotDraw(false);
|
||||
drawable.setCallback(this);
|
||||
if (drawable.isStateful()) {
|
||||
drawable.setState(getDrawableState());
|
||||
}
|
||||
} else {
|
||||
setWillNotDraw(true);
|
||||
}
|
||||
requestLayout();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void drawableHotspotChanged(float x, float y) {
|
||||
super.drawableHotspotChanged(x, y);
|
||||
if (mForegroundSelector != null) {
|
||||
mForegroundSelector.setHotspot(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/*************************************************************************************************************************************************
|
||||
* Copyright (c) 2015, Nordic Semiconductor
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
************************************************************************************************************************************************/
|
||||
|
||||
package no.nordicsemi.android.nrftoolbox.widget;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.NinePatchDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import no.nordicsemi.android.nrftoolbox.R;
|
||||
|
||||
public class ForegroundRelativeLayout extends RelativeLayout {
|
||||
|
||||
private Drawable mForegroundSelector;
|
||||
private Rect mRectPadding;
|
||||
private boolean mUseBackgroundPadding = false;
|
||||
|
||||
public ForegroundRelativeLayout(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public ForegroundRelativeLayout(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
|
||||
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundRelativeLayout,
|
||||
defStyle, 0);
|
||||
|
||||
final Drawable d = a.getDrawable(R.styleable.ForegroundRelativeLayout_foreground);
|
||||
if (d != null) {
|
||||
setForeground(d);
|
||||
}
|
||||
|
||||
a.recycle();
|
||||
|
||||
if (this.getBackground() instanceof NinePatchDrawable) {
|
||||
final NinePatchDrawable npd = (NinePatchDrawable) this.getBackground();
|
||||
mRectPadding = new Rect();
|
||||
if (npd.getPadding(mRectPadding)) {
|
||||
mUseBackgroundPadding = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawableStateChanged() {
|
||||
super.drawableStateChanged();
|
||||
|
||||
if (mForegroundSelector != null && mForegroundSelector.isStateful()) {
|
||||
mForegroundSelector.setState(getDrawableState());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
|
||||
if (mForegroundSelector != null) {
|
||||
if (mUseBackgroundPadding) {
|
||||
mForegroundSelector.setBounds(mRectPadding.left, mRectPadding.top, w - mRectPadding.right, h - mRectPadding.bottom);
|
||||
} else {
|
||||
mForegroundSelector.setBounds(0, 0, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(@NonNull Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
|
||||
if (mForegroundSelector != null) {
|
||||
mForegroundSelector.draw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean verifyDrawable(Drawable who) {
|
||||
return super.verifyDrawable(who) || (who == mForegroundSelector);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpDrawablesToCurrentState() {
|
||||
super.jumpDrawablesToCurrentState();
|
||||
if (mForegroundSelector != null) mForegroundSelector.jumpToCurrentState();
|
||||
}
|
||||
|
||||
public void setForeground(Drawable drawable) {
|
||||
if (mForegroundSelector != drawable) {
|
||||
if (mForegroundSelector != null) {
|
||||
mForegroundSelector.setCallback(null);
|
||||
unscheduleDrawable(mForegroundSelector);
|
||||
}
|
||||
|
||||
mForegroundSelector = drawable;
|
||||
|
||||
if (drawable != null) {
|
||||
setWillNotDraw(false);
|
||||
drawable.setCallback(this);
|
||||
if (drawable.isStateful()) {
|
||||
drawable.setState(getDrawableState());
|
||||
}
|
||||
} else {
|
||||
setWillNotDraw(true);
|
||||
}
|
||||
requestLayout();
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void drawableHotspotChanged(float x, float y) {
|
||||
super.drawableHotspotChanged(x, y);
|
||||
if (mForegroundSelector != null) {
|
||||
mForegroundSelector.setHotspot(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user