Skip to content
Snippets Groups Projects
Unverified Commit 08217717 authored by Johannes Mockenhaupt's avatar Johannes Mockenhaupt
Browse files

Clear USB disconnect notification when USB is reconnected.

parent 9600f5b4
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,7 @@ import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper; ...@@ -82,6 +82,7 @@ import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper;
public class MainActivity extends AppCompatActivity implements OnSharedPreferenceChangeListener, OnEulaAgreedTo { public class MainActivity extends AppCompatActivity implements OnSharedPreferenceChangeListener, OnEulaAgreedTo {
private static final String TAG = MainActivity.class.getSimpleName(); private static final String TAG = MainActivity.class.getSimpleName();
public static final int USB_DISCONNECT_NOFICATION_ID = 1;
public static final float MMOLXLFACTOR = 18.016f; public static final float MMOLXLFACTOR = 18.016f;
public static int batLevel = 0; public static int batLevel = 0;
...@@ -461,8 +462,6 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -461,8 +462,6 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
} }
private void showDisconnectionNotification(String title, String message) { private void showDisconnectionNotification(String title, String message) {
int notifyId = 1;
NotificationCompat.Builder mBuilder = NotificationCompat.Builder mBuilder =
(NotificationCompat.Builder) new NotificationCompat.Builder(this) (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setPriority(NotificationCompat.PRIORITY_MAX) .setPriority(NotificationCompat.PRIORITY_MAX)
...@@ -488,7 +487,12 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -488,7 +487,12 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
NotificationManager mNotificationManager = NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// notifyId allows you to update the notification later on. // notifyId allows you to update the notification later on.
mNotificationManager.notify(notifyId, mBuilder.build()); mNotificationManager.notify(USB_DISCONNECT_NOFICATION_ID, mBuilder.build());
}
private void clearUsbDisconnectedNotification() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(MainActivity.USB_DISCONNECT_NOFICATION_ID);
} }
@Override @Override
...@@ -934,6 +938,9 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc ...@@ -934,6 +938,9 @@ public class MainActivity extends AppCompatActivity implements OnSharedPreferenc
} }
} else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) { } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
Log.d(TAG, "USB plugged in"); Log.d(TAG, "USB plugged in");
if (mEnableCgmService) {
clearUsbDisconnectedNotification();
}
if (hasUsbPermission()) { if (hasUsbPermission()) {
// Give the USB a little time to warm up first // Give the USB a little time to warm up first
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment