Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Merge pull request #39 from schilit/EmptyView
Browse files Browse the repository at this point in the history
Empty view
  • Loading branch information
schilit committed Nov 22, 2014
2 parents 89c30b7 + 4ef2f38 commit 7607e84
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.uribeacon.sample;


import android.content.Context;
import android.util.AttributeSet;
import android.widget.ListView;

/**
* Subclass of {@link android.support.v4.widget.SwipeRefreshLayout} that supports containing a
* ViewGroup whose first child is a ListView. The ViewGroup can contain other views.
*
*/
public class SwipeRefreshLayout extends android.support.v4.widget.SwipeRefreshLayout {

public SwipeRefreshLayout(Context context) {
super(context);
}

public SwipeRefreshLayout(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}

@Override public boolean canChildScrollUp() {
// The real child maps cares about is the list, so check if that can scroll.
ListView target = (ListView) findViewById(android.R.id.list);
return target.getChildCount() > 0
&& (target.getFirstVisiblePosition() > 0
|| target.getChildAt(0).getTop() < target.getPaddingTop());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import org.uribeacon.beacon.UriBeacon;
Expand Down Expand Up @@ -65,7 +66,8 @@ public class UriBeaconScanActivity extends ListActivity implements SwipeRefreshL
private DeviceListAdapter mLeDeviceListAdapter;
private BluetoothAdapter mBluetoothAdapter;
private boolean mIsScanRunning;
private SwipeRefreshLayout mSwipeLayout;
private SwipeRefreshLayout mSwipeWidget;
private boolean mIsConfig;
private Parcelable[] mScanFilterUuids;

// Run when the SCAN_TIME_MILLIS has elapsed.
Expand Down Expand Up @@ -99,31 +101,39 @@ private boolean leScanMatches(ScanRecord scanRecord) {
@SuppressWarnings("deprecation")
private void scanLeDevice(final boolean enable) {
if (mIsScanRunning != enable) {
TextView view = (TextView) findViewById(android.R.id.empty);
mIsScanRunning = enable;
setProgressBarIndeterminateVisibility(enable);
if (enable) {
view.setText(mIsConfig ? R.string.empty_config_start : R.string.empty_scan_start);
// Stops scanning after the predefined scan time has elapsed.
mHandler.postDelayed(mScanTimeout, SCAN_TIME_MILLIS);
mLeDeviceListAdapter.clear();
mSwipeLayout.setRefreshing(true);
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
// Cancel the scan timeout callback if still active or else it may fire later.
mHandler.removeCallbacks(mScanTimeout);
mSwipeLayout.setRefreshing(false);
mBluetoothAdapter.stopLeScan(mLeScanCallback);
view.setText(mIsConfig ? R.string.empty_config_end : R.string.empty_scan_end);
}
// update the refresh/stop refresh menu
invalidateOptionsMenu();
}
}


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.uribeacon_scan_layout);

mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
mSwipeLayout.setOnRefreshListener(this);
mSwipeWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget);
mSwipeWidget.setOnRefreshListener(this);

// Initializes list view adapter.
mLeDeviceListAdapter = new DeviceListAdapter(getLayoutInflater());
setListAdapter(mLeDeviceListAdapter);

// Use this check to determine whether BLE is supported on the device. Then you can
// selectively disable BLE-related features.
Expand Down Expand Up @@ -155,6 +165,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_stop_refresh).setVisible(mIsScanRunning);
menu.findItem(R.id.menu_refresh).setVisible(!mIsScanRunning);
menu.findItem(R.id.menu_config).setVisible(!mIsConfig);
return super.onPrepareOptionsMenu(menu);
}

Expand Down Expand Up @@ -188,10 +199,8 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
ScanResultAdapter.DeviceSighting sighting = mLeDeviceListAdapter.getItem(position);
List serviceUuids = sighting.scanResult.getScanRecord().getServiceUuids();
// Only open configuration activity if the selected devices advertises configuration.
if (serviceUuids.contains(ProtocolV1.CONFIG_SERVICE_UUID) ||
serviceUuids.contains(ProtocolV2.CONFIG_SERVICE_UUID)) {
if (mIsConfig) {
ConfigActivity.startConfigureActivity(this, sighting.scanResult);
// On exit from configuration, return to the main scan screen.
finish();
Expand All @@ -201,33 +210,24 @@ protected void onListItemClick(ListView l, View v, int position, long id) {
@Override
protected void onResume() {
super.onResume();

Parcelable configServices[] = getIntent().getParcelableArrayExtra(BluetoothDevice.EXTRA_UUID);
// If we are invoked with EXTRA_UUID then we are configuration mode so set title.
if (configServices != null) {
getActionBar().setTitle(R.string.title_config);
} else {
getActionBar().setTitle(R.string.title_devices);
}
mIsConfig = configServices != null;

// Initializes list view adapter.
mLeDeviceListAdapter = new DeviceListAdapter(getLayoutInflater());
setListAdapter(mLeDeviceListAdapter);
// If we are invoked with EXTRA_UUID then we are configuration mode so set title.
getActionBar().setTitle(mIsConfig ? R.string.title_config : R.string.title_devices);

// Set the scan filter to be one of three filtering modes: all beacons, UriBeacons,
// UriBeacons in config mode.
final String keyUriBeacon = getString(R.string.pref_key_uribeacon);
final SharedPreferences prefs = getDefaultSharedPreferences(this);
boolean filterUriBeacon = prefs.getBoolean(keyUriBeacon, false);
if (configServices != null) {
if (mIsConfig) {
mScanFilterUuids = configServices;
} else if (filterUriBeacon) {
mScanFilterUuids = new ParcelUuid[]{UriBeacon.URI_SERVICE_UUID};
} else {
mScanFilterUuids = null;
}

// Start scanning
scanLeDevice(true);
}

Expand All @@ -246,7 +246,6 @@ protected void onPause() {
super.onPause();
// on Pause stop any scans that are running if not in background mode
scanLeDevice(false);

}

private int getTxPowerLevel(ScanResult scanResult) {
Expand All @@ -264,6 +263,8 @@ private int getTxPowerLevel(ScanResult scanResult) {

@Override
public void onRefresh() {
// This obscures the contents, so keep in the action bar
mSwipeWidget.setRefreshing(false);
scanLeDevice(true);
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,31 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<android.support.v4.widget.SwipeRefreshLayout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swiperefresh"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@android:id/list"
<org.uribeacon.sample.SwipeRefreshLayout
android:id="@+id/swipe_refresh_widget"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent">

</android.support.v4.widget.SwipeRefreshLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"/>
</FrameLayout>
</org.uribeacon.sample.SwipeRefreshLayout>
</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<string name="title_devices">Scan</string>
<string name="title_config">Config</string>
<string name="error_bluetooth_not_supported">Bluetooth not supported.</string>
<string name="empty_scan_start">Searching for devices</string>
<string name="empty_scan_end">No devices found</string>
<string name="empty_config_start">Searching for configurable UriBeacons</string>
<string name="empty_config_end">No configurable UriBeacons found.\nVisit uribeacon.org</string>

<!-- Menu items -->
<string name="menu_refresh">Refresh</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title_activity_config">Beacon Configuration</string>

<string name="beacon_old_value_title">Old value</string>
<string name="beacon_new_value_title">New value</string>
<string name="beacon_new_value_write_title">Write</string>
Expand Down

0 comments on commit 7607e84

Please sign in to comment.