Added about dialog in sample app

This commit is contained in:
Alexandros Schillings
2014-03-27 18:31:39 +00:00
parent e483973288
commit e207f1ae73
4 changed files with 52 additions and 13 deletions
+2 -4
View File
@@ -97,7 +97,7 @@ An IBeaconDevice extends BluetoothLeDevice, so you still have access to the same
You can also lookup values and convert them to human friendly strings:
* `BluetoothClassResolver.resolveDeviceClass(int btClass)`: Will try to resolve a Blueotooth Device class
* `CompanyIdentifierResolver.getCompanyName(int companyId, String fallback)`: Will try to resolve a Company identifier to the company name
* GattAttributeResolver.getAttributeName(String uuid, String fallback): Will try to convert a UUID to its name.
* `GattAttributeResolver.getAttributeName(String uuid, String fallback)`: Will try to convert a UUID to its name.
**Note:** The data can be found as ODS (Open Office Spreadsheets) in the documents folder.
@@ -129,12 +129,10 @@ Author: [Alexandros Schillings](https://github.com/alt236).
* The Accuracy calculation algorithm was taken from: http://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing
* The AdRecord parser was taken from: https://github.com/devunwired/accessory-samples
* The sample application has been adapted from
* The sample application has been adapted from Android's Bluetooth LE example
All logos are the property of their respective owners.
The icons used for the example app were downloaded from here: [Android Design](http://developer.android.com/design/downloads/index.htm)
The code in this project is licensed under the Apache Software License 2.0.
Copyright (c) 2014 Alexandros Schillings.
+5
View File
@@ -31,5 +31,10 @@
android:orderInCategory="101"
android:showAsAction="ifRoom|withText"
android:title="@string/menu_stop"/>
<item
android:id="@+id/menu_about"
android:orderInCategory="102"
android:showAsAction="ifRoom|withText"
android:title="@string/menu_about"/>
</menu>
+5 -2
View File
@@ -5,14 +5,13 @@
<string name="app_name">Bluetooth LE Scanner</string>
<string name="connected">Connected</string>
<string name="disconnected">Disconnected</string>
<string name="hello_world">Hello world!</string>
<string name="no_data">No data</string>
<string name="not_supported">Not supported</string>
<string name="off">Off</string>
<string name="on">On</string>
<string name="supported">Supported</string>
<string name="unknown_characteristic">Unknown characteristic</string>
<string name="unknown_device">Unknown Device</string>
<string name="unknown_device">Unknown device</string>
<string name="unknown_service">Unknown service</string>
<!-- Formatters -->
@@ -20,6 +19,7 @@
<string name="formatter_db">%sdb</string>
<!-- Menu items -->
<string name="menu_about">About</string>
<string name="menu_connect">Connect</string>
<string name="menu_disconnect">Disconnect</string>
<string name="menu_scan">Scan</string>
@@ -37,4 +37,7 @@
<string name="label_tx_power">TX Power:</string>
<string name="label_uuid">UUID:</string>
<string name="about_dialog_text">This is a sample application using the Bluetooth LE Library.\n\nGithub: https://github.com/alt236/Bluetooth-LE-Library---Android\n\nCopyright: Alexandros Schillings</string>
</resources>
@@ -6,11 +6,16 @@ import uk.co.alt236.btlescan.adapters.LeDeviceListAdapter;
import uk.co.alt236.btlescan.containers.BluetoothLeDeviceStore;
import uk.co.alt236.btlescan.util.BluetoothLeScanner;
import uk.co.alt236.btlescan.util.BluetoothUtils;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@@ -44,16 +49,29 @@ public class MainActivity extends ListActivity {
}
};
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
final BluetoothLeDevice device = mLeDeviceListAdapter.getItem(position);
if (device == null) return;
private void displayAboutDialog(){
// REALLY REALLY LAZY LIKIFIED DIALOG
final int paddingSizeDp = 5;
final float scale = getResources().getDisplayMetrics().density;
final int dpAsPixels = (int) (paddingSizeDp * scale + 0.5f);
final TextView textView=new TextView(this);
final SpannableString text = new SpannableString(getString(R.string.about_dialog_text));
final Intent intent = new Intent(this, DeviceDetailsActivity.class);
intent.putExtra(DeviceDetailsActivity.EXTRA_DEVICE, device);
textView.setText(text);
textView.setAutoLinkMask(RESULT_OK);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setPadding(dpAsPixels, dpAsPixels, dpAsPixels, dpAsPixels);
startActivity(intent);
Linkify.addLinks(text, Linkify.ALL);
new AlertDialog.Builder(this)
.setTitle(R.string.menu_about)
.setCancelable(false)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {}
})
.setView(textView)
.show();
}
@Override
@@ -82,6 +100,18 @@ public class MainActivity extends ListActivity {
return true;
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
final BluetoothLeDevice device = mLeDeviceListAdapter.getItem(position);
if (device == null) return;
final Intent intent = new Intent(this, DeviceDetailsActivity.class);
intent.putExtra(DeviceDetailsActivity.EXTRA_DEVICE, device);
startActivity(intent);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
@@ -92,6 +122,9 @@ public class MainActivity extends ListActivity {
mScanner.scanLeDevice(-1, false);
invalidateOptionsMenu();
break;
case R.id.menu_about:
displayAboutDialog();
break;
}
return true;
}