Skip to content

Commit

Permalink
Implement #101 set small icon using vector drawable
Browse files Browse the repository at this point in the history
  • Loading branch information
HBiSoft committed Dec 2, 2021
1 parent 29ebf6b commit e676a22
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .idea/gradle.xml

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

11 changes: 10 additions & 1 deletion .idea/misc.xml

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

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

Binary file modified app/release/HBRecorderDemo.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ private void quickSettings() {
hbRecorder.recordHDVideo(wasHDSelected);
hbRecorder.isAudioEnabled(isAudioEnabled);
//Customise Notification
hbRecorder.setNotificationSmallIcon(drawable2ByteArray(R.drawable.icon));
hbRecorder.setNotificationSmallIcon(R.drawable.icon);
//hbRecorder.setNotificationSmallIconVector(R.drawable.ic_baseline_videocam_24);
hbRecorder.setNotificationTitle(getString(R.string.stop_recording_notification_title));
hbRecorder.setNotificationDescription(getString(R.string.stop_recording_notification_message));
}
Expand Down
11 changes: 9 additions & 2 deletions hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class HBRecorder implements MyListener {
private FileObserver observer;
private final HBRecorderListener hbRecorderListener;
private byte[] byteArray;
private int vectorDrawable = 0;
private String audioSource = "MIC";
private String videoEncoder = "DEFAULT";
private boolean enableCustomSettings = false;
Expand Down Expand Up @@ -260,15 +261,20 @@ public boolean isBusyRecording() {
return false;
}

/*Change notification icon*/
/*Change notification icon Drawable*/
public void setNotificationSmallIcon(@DrawableRes int drawable) {
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), drawable);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
}

/*Change notification icon*/
/*Change notification icon using Vector Drawable*/
public void setNotificationSmallIconVector(@DrawableRes int VectorDrawable) {
vectorDrawable = VectorDrawable;
}

/*Change notification icon using byte[]*/
public void setNotificationSmallIcon(byte[] bytes) {
byteArray = bytes;
}
Expand Down Expand Up @@ -318,6 +324,7 @@ private void startService(Intent data) {
service.putExtra("audioBitrate", audioBitrate);
service.putExtra("audioSamplingRate", audioSamplingRate);
service.putExtra("notificationSmallBitmap", byteArray);
service.putExtra("notificationSmallVector", vectorDrawable);
service.putExtra("notificationTitle", notificationTitle);
service.putExtra("notificationDescription", notificationDescription);
service.putExtra("notificationButtonText", notificationButtonText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ else if (pauseResumeAction != null && pauseResumeAction.equals("resume")){
mIntent = intent;
maxFileSize = intent.getLongExtra(MAX_FILE_SIZE_KEY, NO_SPECIFIED_MAX_SIZE);
byte[] notificationSmallIcon = intent.getByteArrayExtra("notificationSmallBitmap");
int notificationSmallVector = intent.getIntExtra("notificationSmallVector", 0);
String notificationTitle = intent.getStringExtra("notificationTitle");
String notificationDescription = intent.getStringExtra("notificationDescription");
String notificationButtonText = intent.getStringExtra("notificationButtonText");
Expand Down Expand Up @@ -208,7 +209,11 @@ else if (pauseResumeAction != null && pauseResumeAction.equals("resume")){
//Modify notification badge
notification = new Notification.Builder(getApplicationContext(), channelId).setOngoing(true).setSmallIcon(Icon.createWithBitmap(bmp)).setContentTitle(notificationTitle).setContentText(notificationDescription).addAction(action).build();

} else {
} else if (notificationSmallVector != 0){
notification = new Notification.Builder(getApplicationContext(), channelId).setOngoing(true).setSmallIcon(notificationSmallVector).setContentTitle(notificationTitle).setContentText(notificationDescription).addAction(action).build();
}

else {
//Modify notification badge
notification = new Notification.Builder(getApplicationContext(), channelId).setOngoing(true).setSmallIcon(R.drawable.icon).setContentTitle(notificationTitle).setContentText(notificationDescription).addAction(action).build();
}
Expand Down

0 comments on commit e676a22

Please sign in to comment.