Skip to content
This repository has been archived by the owner on Sep 17, 2023. It is now read-only.

Commit

Permalink
Added status bar icon when the app is running.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxieds committed Jan 17, 2018
1 parent d534318 commit 0cd8cfe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.maxieds.chameleonminilivedebugger;

import android.app.DownloadManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
Expand All @@ -22,6 +25,7 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.app.NotificationCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -274,6 +278,29 @@ else if(intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
}
}

@Override
public void onPause() {
super.onPause();
// clear the status icon before the application is abruptly terminated:
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(1);
}

@Override
public void onResume() {
super.onResume();
// setup the system status bar icon:
NotificationCompat.Builder statusBarIconBuilder = new NotificationCompat.Builder(this);
statusBarIconBuilder.setSmallIcon(R.drawable.chameleonstatusbaricon16);
statusBarIconBuilder.setContentTitle(getResources().getString(R.string.app_name));
Intent resultIntent = new Intent(this, LiveLoggerActivity.class);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
statusBarIconBuilder.setContentIntent(resultPendingIntent);
Notification notification = statusBarIconBuilder.build();
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
NotificationManager notifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notifyMgr.notify(1, notification);
}

/**
* Queries the Chameleon device with the query command and returns its response
* (sans the preceeding ascii status code).
Expand Down Expand Up @@ -442,6 +469,7 @@ public void run() {
public void actionButtonExit(View view) {
ChameleonIO.deviceStatus.statsUpdateHandler.removeCallbacks(ChameleonIO.deviceStatus.statsUpdateRunnable);
closeSerialPort(serialPort);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).cancel(1);
finish();
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0cd8cfe

Please sign in to comment.