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

Commit

Permalink
lockscreen notification remix
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewsibigtroth committed Jan 15, 2015
1 parent 0c44323 commit 1773eb2
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.PowerManager;
import android.support.v4.app.NotificationCompat;
Expand Down Expand Up @@ -99,6 +100,9 @@ public void onScanFailed(int errorCode) {
private static final int NON_LOLLIPOP_NOTIFICATION_URL_COLOR = Color.parseColor("#999999");
private static final int NON_LOLLIPOP_NOTIFICATION_SNIPPET_COLOR = Color.parseColor("#999999");
private static final int NOTIFICATION_PRIORITY = NotificationCompat.PRIORITY_LOW;
private static final long NOTIFICATION_UPDATE_GATE_DURATION = 1000;
private boolean mCanUpdateNotifications = false;
private Handler mHandler;
private ScreenBroadcastReceiver mScreenStateBroadcastReceiver;
private RegionResolver mRegionResolver;
private NotificationManagerCompat mNotificationManager;
Expand Down Expand Up @@ -127,6 +131,13 @@ public int compare(String address, String otherAddress) {
return address.compareTo(otherAddress);
}
};
private Runnable mNotificationUpdateGateTimeout = new Runnable() {
@Override
public void run() {
mCanUpdateNotifications = true;
updateNotifications();
}
};

public UriBeaconDiscoveryService() {
}
Expand All @@ -143,6 +154,7 @@ private static String generateMockBluetoothAddress(int hashCode) {
private void initialize() {
mNotificationManager = NotificationManagerCompat.from(this);
mMdnsUrlDiscoverer = new MdnsUrlDiscoverer(this, UriBeaconDiscoveryService.this);
mHandler = new Handler();
initializeScreenStateBroadcastReceiver();
}

Expand Down Expand Up @@ -182,6 +194,8 @@ public int onStartCommand(Intent intent, int flags, int startId) {
// Start scanning only if the screen is on
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (powerManager.isScreenOn()) {
mCanUpdateNotifications = false;
mHandler.postDelayed(mNotificationUpdateGateTimeout, NOTIFICATION_UPDATE_GATE_DURATION);
startSearchingForUriBeacons();
mMdnsUrlDiscoverer.startScanning();
}
Expand All @@ -199,6 +213,7 @@ public IBinder onBind(Intent intent) {
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy: service exiting");
mHandler.removeCallbacks(mNotificationUpdateGateTimeout);
stopSearchingForUriBeacons();
mMdnsUrlDiscoverer.stopScanning();
unregisterReceiver(mScreenStateBroadcastReceiver);
Expand Down Expand Up @@ -286,6 +301,10 @@ private void handleFoundDevice(ScanResult scanResult) {
* Create a new set of notifications or update those existing
*/
private void updateNotifications() {
if (!mCanUpdateNotifications) {
return;
}

mSortedDevices = getSortedBeaconsWithMetadata();

// If no beacons have been found
Expand Down Expand Up @@ -493,9 +512,12 @@ public void onReceive(Context context, Intent intent) {
initializeLists();
mNotificationManager.cancelAll();
if (isScreenOn) {
mCanUpdateNotifications = false;
mHandler.postDelayed(mNotificationUpdateGateTimeout, NOTIFICATION_UPDATE_GATE_DURATION);
startSearchingForUriBeacons();
mMdnsUrlDiscoverer.startScanning();
} else {
mHandler.removeCallbacks(mNotificationUpdateGateTimeout);
stopSearchingForUriBeacons();
mMdnsUrlDiscoverer.stopScanning();
}
Expand Down

0 comments on commit 1773eb2

Please sign in to comment.