Skip to content

Commit

Permalink
Merge pull request #19 from FingerArt/master
Browse files Browse the repository at this point in the history
Add a notification icon of type byte[] for flutter
  • Loading branch information
HBiSoft authored Jul 9, 2020
2 parents fa93687 + 3dd9472 commit 976bd7d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ hbrecorder.isBusyRecording();
// Set notification icon by passing, for example R.drawable.myicon
// Defaults to R.drawable.icon
hbrecorder.setNotificationSmallIcon(int);
// Set notification title
// Set notification icon by byte array
hbrecorder.setNotificationSmallIcon(byte[]);
// Set notification title
// Defaults to "Recording your screen"
hbrecorder.setNotificationTitle(String);
// Set notification description
Expand Down
30 changes: 20 additions & 10 deletions app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.MediaScannerConnection;
import android.media.projection.MediaProjectionManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.os.Environment;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
Expand All @@ -31,9 +25,17 @@
import android.widget.Switch;
import android.widget.Toast;

import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.hbisoft.hbrecorder.HBRecorder;
import com.hbisoft.hbrecorder.HBRecorderListener;

import java.io.ByteArrayOutputStream;
import java.io.File;


Expand Down Expand Up @@ -420,7 +422,7 @@ private void quickSettings() {
hbRecorder.recordHDVideo(wasHDSelected);
hbRecorder.isAudioEnabled(isAudioEnabled);
//Customise Notification
hbRecorder.setNotificationSmallIcon(R.drawable.icon);
hbRecorder.setNotificationSmallIcon(drawable2ByteArray(R.drawable.icon));
hbRecorder.setNotificationTitle("Recording your screen");
hbRecorder.setNotificationDescription("Drag down to stop the recording");

Expand Down Expand Up @@ -502,4 +504,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
private void showLongToast(final String msg) {
Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
}

//drawable to byte[]
private byte[] drawable2ByteArray(@DrawableRes int drawableId) {
Bitmap icon = BitmapFactory.decodeResource(getResources(), drawableId);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
icon.compress(Bitmap.CompressFormat.PNG, 100, stream);
return stream.toByteArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Bundle;
import android.os.Environment;

import androidx.annotation.DrawableRes;
import androidx.annotation.RequiresApi;

import android.os.Handler;
Expand Down Expand Up @@ -182,13 +183,18 @@ public boolean isBusyRecording() {
}

/*Change notification icon*/
public void setNotificationSmallIcon(int 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*/
public void setNotificationSmallIcon(byte[] bytes) {
byteArray = bytes;
}

/*Set notification title*/
public void setNotificationTitle(String Title) {
notificationTitle = Title;
Expand Down

0 comments on commit 976bd7d

Please sign in to comment.