Materialized the UI, added runtme permissions support, now compiling against 24
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
<uses-permission android:name="android.permission.BLUETOOTH"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.bluetooth_le"
|
||||
|
||||
+8
-5
@@ -46,8 +46,11 @@ public class DeviceDetailsActivity extends AppCompatActivity {
|
||||
final TextView tvTitle = (TextView) lt.findViewById(R.id.title);
|
||||
|
||||
tvTitle.setText(title);
|
||||
tvString.setText("'" + AdRecordUtils.getRecordDataAsString(record) + "'");
|
||||
tvArray.setText("'" + ByteUtils.byteArrayToHexString(record.getData()) + "'");
|
||||
|
||||
tvString.setText(getString(R.string.formatter_single_quoted_string,
|
||||
AdRecordUtils.getRecordDataAsString(record)));
|
||||
tvArray.setText(getString(R.string.formatter_single_quoted_string,
|
||||
ByteUtils.byteArrayToHexString(record.getData())));
|
||||
|
||||
adapter.addView(lt);
|
||||
}
|
||||
@@ -68,13 +71,13 @@ public class DeviceDetailsActivity extends AppCompatActivity {
|
||||
tvBondingState.setText(device.getBluetoothDeviceBondState());
|
||||
|
||||
final String supportedServices;
|
||||
if(device.getBluetoothDeviceKnownSupportedServices().isEmpty()){
|
||||
if (device.getBluetoothDeviceKnownSupportedServices().isEmpty()) {
|
||||
supportedServices = getString(R.string.no_known_services);
|
||||
} else {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
for(final BluetoothService service : device.getBluetoothDeviceKnownSupportedServices()){
|
||||
if(sb.length() > 0){
|
||||
for (final BluetoothService service : device.getBluetoothDeviceKnownSupportedServices()) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(", ");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package uk.co.alt236.btlescan.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.SpannableString;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import uk.co.alt236.btlescan.R;
|
||||
|
||||
/*package*/ final class DialogFactory {
|
||||
|
||||
private DialogFactory() {
|
||||
// NOOP
|
||||
}
|
||||
|
||||
public static Dialog createAboutDialog(final Context context) {
|
||||
final View view = LayoutInflater.from(context).inflate(R.layout.dialog_textview, null);
|
||||
final TextView textView = (TextView) view.findViewById(R.id.text);
|
||||
|
||||
final SpannableString text = new SpannableString(context.getString(R.string.about_dialog_text));
|
||||
|
||||
textView.setText(text);
|
||||
textView.setAutoLinkMask(Activity.RESULT_OK);
|
||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
Linkify.addLinks(text, Linkify.ALL);
|
||||
|
||||
final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
|
||||
public void onClick(final DialogInterface dialog, final int id) {
|
||||
}
|
||||
};
|
||||
|
||||
return new AlertDialog.Builder(context)
|
||||
.setTitle(R.string.menu_about)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(android.R.string.ok, listener)
|
||||
.setView(view)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,22 @@
|
||||
package uk.co.alt236.btlescan.activities;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.Manifest;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
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;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.anthonycr.grant.PermissionsManager;
|
||||
import com.anthonycr.grant.PermissionsResultAction;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -62,32 +63,6 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
}
|
||||
};
|
||||
|
||||
private void displayAboutDialog() {
|
||||
// REALLY REALLY LAZY LINKIFIED 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));
|
||||
|
||||
textView.setText(text);
|
||||
textView.setAutoLinkMask(RESULT_OK);
|
||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
textView.setPadding(dpAsPixels, dpAsPixels, dpAsPixels, dpAsPixels);
|
||||
|
||||
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(final DialogInterface dialog, final int id) {
|
||||
}
|
||||
})
|
||||
.setView(textView)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -138,14 +113,29 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_scan:
|
||||
startScan();
|
||||
PermissionsManager.getInstance().requestPermissionsIfNecessaryForResult(this,
|
||||
new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, new PermissionsResultAction() {
|
||||
|
||||
@Override
|
||||
public void onGranted() {
|
||||
startScan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDenied(String permission) {
|
||||
Toast.makeText(MainActivity.this,
|
||||
R.string.permission_not_granted_coarse_location,
|
||||
Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
break;
|
||||
case R.id.menu_stop:
|
||||
mScanner.scanLeDevice(-1, false);
|
||||
invalidateOptionsMenu();
|
||||
break;
|
||||
case R.id.menu_about:
|
||||
displayAboutDialog();
|
||||
DialogFactory.createAboutDialog(this).show();
|
||||
break;
|
||||
case R.id.menu_share:
|
||||
mDeviceStore.shareDataAsEmail(this);
|
||||
@@ -203,4 +193,10 @@ public class MainActivity extends AppCompatActivity implements AdapterView.OnIte
|
||||
String.valueOf(count)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode,
|
||||
@NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
PermissionsManager.getInstance().notifyPermissionsChange(permissions, grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_below="@id/deviceInformation"
|
||||
android:background="@android:color/holo_blue_dark"/>
|
||||
android:background="@color/colorSeparator" />
|
||||
|
||||
<GridLayout
|
||||
android:id="@+id/gattInformation"
|
||||
@@ -113,7 +113,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_above="@id/gattInformation"
|
||||
android:background="@android:color/holo_blue_dark"/>
|
||||
android:background="@color/colorSeparator" />
|
||||
|
||||
<ExpandableListView
|
||||
android:id="@+id/gatt_services_list"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".MainActivity">
|
||||
tools:context=".activities.MainActivity">
|
||||
|
||||
<GridLayout
|
||||
android:id="@+id/gridLayout1"
|
||||
@@ -61,7 +61,7 @@
|
||||
android:id="@+id/upperSepparator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/holo_blue_dark"/>
|
||||
android:background="@color/colorSeparator" />
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -79,7 +79,7 @@
|
||||
android:id="@+id/lowerSepparator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/holo_blue_dark"/>
|
||||
android:background="@color/colorSeparator" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvItemCount"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="?dialogPreferredPadding">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
@@ -11,13 +11,13 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@android:color/holo_blue_dark"
|
||||
android:textColor="@color/colorSeparator"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@android:color/holo_blue_dark"/>
|
||||
android:background="@color/colorSeparator" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -1,11 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 11+. This theme completely replaces
|
||||
AppBaseTheme from res/values/styles.xml on API 11+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- API 11 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -1,12 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<!--
|
||||
Base application theme for API 14+. This theme completely replaces
|
||||
AppBaseTheme from BOTH res/values/styles.xml and
|
||||
res/values-v11/styles.xml on API 14+ devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- API 14 theme customizations can go here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="AppTheme" parent="AppTheme.Base">
|
||||
<item name="android:windowContentTransitions">true</item>
|
||||
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
||||
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
||||
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
|
||||
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
|
||||
</style>
|
||||
</resources>
|
||||
@@ -1,3 +1,9 @@
|
||||
<resources>
|
||||
<color name="light_gray">#66e0e0e0</color>
|
||||
<color name="colorPrimary">#0000FF</color>
|
||||
<color name="colorPrimaryDark">#4400FF</color>
|
||||
<color name="colorAccent">#F06292</color>
|
||||
|
||||
|
||||
<color name="colorSeparator">@color/colorAccent</color>
|
||||
</resources>
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
<string name="formatter_meters">%sm</string>
|
||||
<string name="formatter_db">%sdb</string>
|
||||
<string name="formatter_item_count">Items: %s</string>
|
||||
<string name="formatter_single_quoted_string">\'%s\'</string>
|
||||
|
||||
<!-- Menu items -->
|
||||
<string name="menu_about">About</string>
|
||||
@@ -72,4 +73,6 @@
|
||||
<string name="label_uuid">UUID:</string>
|
||||
<string name="label_updated">Updated:</string>
|
||||
<string name="label_decriptor">Descriptor:</string>
|
||||
|
||||
<string name="permission_not_granted_coarse_location">The ACCESS_COARSE_LOCATION permission is needed to receive bluetooth scan results</string>
|
||||
</resources>
|
||||
@@ -1,20 +1,11 @@
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<!--
|
||||
Base application theme, dependent on API level. This theme is replaced
|
||||
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
|
||||
-->
|
||||
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!--
|
||||
Theme customizations available in newer API levels can go in
|
||||
res/values-vXX/styles.xml, while customizations related to
|
||||
backward-compatibility can go here.
|
||||
-->
|
||||
</style>
|
||||
<style name="AppTheme" parent="AppTheme.Base" />
|
||||
|
||||
<!-- Application theme. -->
|
||||
<style name="AppTheme" parent="AppBaseTheme">
|
||||
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
|
||||
<style name="AppTheme.Base" parent="Theme.AppCompat.DayNight.DarkActionBar">
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimary</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="GridLayoutDataTextView">
|
||||
|
||||
Reference in New Issue
Block a user