diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2b75303
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,13 @@
+*.iml
+.gradle
+/local.properties
+/.idea/caches
+/.idea/libraries
+/.idea/modules.xml
+/.idea/workspace.xml
+/.idea/navEditor.xml
+/.idea/assetWizardSettings.xml
+.DS_Store
+/build
+/captures
+.externalNativeBuild
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..15a15b2
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..2996d53
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..85d6e17
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
new file mode 100644
index 0000000..7f68460
--- /dev/null
+++ b/.idea/runConfigurations.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/.gitignore b/app/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/app/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/app/build.gradle b/app/build.gradle
new file mode 100644
index 0000000..26c4df3
--- /dev/null
+++ b/app/build.gradle
@@ -0,0 +1,29 @@
+apply plugin: 'com.android.application'
+
+android {
+ compileSdkVersion 28
+ defaultConfig {
+ applicationId "com.hbisoft.hbrecorderexample"
+ minSdkVersion 21
+ targetSdkVersion 28
+ versionCode 1
+ versionName "1.0"
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+ }
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+ implementation 'androidx.appcompat:appcompat:1.0.2'
+ implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test:runner:1.2.0'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+ implementation project(path: ':hbrecorder')
+}
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
new file mode 100644
index 0000000..f1b4245
--- /dev/null
+++ b/app/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/app/src/androidTest/java/com/hbisoft/hbrecorderexample/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/hbisoft/hbrecorderexample/ExampleInstrumentedTest.java
new file mode 100644
index 0000000..afd80de
--- /dev/null
+++ b/app/src/androidTest/java/com/hbisoft/hbrecorderexample/ExampleInstrumentedTest.java
@@ -0,0 +1,26 @@
+package com.hbisoft.hbrecorderexample;
+
+import android.content.Context;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getTargetContext();
+
+ assertEquals("com.hbisoft.hbrecorderexample", appContext.getPackageName());
+ }
+}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..5a934e0
--- /dev/null
+++ b/app/src/main/AndroidManifest.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java
new file mode 100644
index 0000000..e190aad
--- /dev/null
+++ b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java
@@ -0,0 +1,306 @@
+package com.hbisoft.hbrecorderexample;
+
+import android.Manifest;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.res.ColorStateList;
+import android.media.projection.MediaProjectionManager;
+import android.os.Environment;
+import androidx.annotation.NonNull;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+import androidx.appcompat.app.AppCompatActivity;
+import android.os.Bundle;
+import androidx.appcompat.widget.AppCompatRadioButton;
+
+import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CheckBox;
+import android.widget.CompoundButton;
+import android.widget.RadioGroup;
+import android.widget.Toast;
+
+import com.hbisoft.hbrecorder.HBRecorder;
+import com.hbisoft.hbrecorder.HBRecorderListener;
+
+import java.io.File;
+
+
+/**
+ * Created by HBiSoft on 13 Aug 2019
+ * Copyright (c) 2019 . All rights reserved.
+ * Last modified 13 Aug 2019
+ */
+
+/*
+* Implementation Steps
+*
+* 1. Implement HBRecorderListener by calling implements HBRecorderListener
+* After this you have to implement the methods by pressing (Alt + Enter)
+* This will create a method called HBRecorderOnComplete()
+* This method will be called once the recording is done.
+*
+* 2. Declare HBRecorder
+*
+* 3. Init implements HBRecorderListener by calling hbRecorder = new HBRecorder(this, this);
+*
+* 4. Set adjust provided settings
+*
+* 5. Start recording by first calling:
+* MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
+ Intent permissionIntent = mediaProjectionManager != null ? mediaProjectionManager.createScreenCaptureIntent() : null;
+ startActivityForResult(permissionIntent, SCREEN_RECORD_REQUEST_CODE);
+
+* 6. Then in onActivityResult call hbRecorder.onActivityResult(resultCode, data, this);
+*
+* 7. Then you can start recording by calling hbRecorder.startScreenRecording(data);
+*
+* */
+
+public class MainActivity extends AppCompatActivity implements HBRecorderListener {
+ //Permissions
+ private static final int SCREEN_RECORD_REQUEST_CODE = 777;
+ private static final int PERMISSION_REQ_ID_RECORD_AUDIO = 22;
+ private static final int PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE = PERMISSION_REQ_ID_RECORD_AUDIO + 1;
+ private boolean hasPermissions = false;
+
+ //Declare HBRecorder
+ private HBRecorder hbRecorder;
+
+ //Start/Stop Button
+ private Button startbtn;
+
+ //HD/SD quality
+ private AppCompatRadioButton hdRadio;
+ private AppCompatRadioButton sdRadio;
+ private RadioGroup radioGroup;
+
+ //Should record/show audio/notification
+ private CheckBox recordAudioCheckBox;
+ private CheckBox notificationCheckbox;
+
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+
+ createFolder();
+ initViews();
+ mOnClickListeners();
+ radioButtonColorStates();
+ radioGroupCheckListener();
+ recordAudioCheckBoxListener();
+ notificationCheckboxListener();
+
+ //Init HBRecorder
+ hbRecorder = new HBRecorder(this, this);
+ hbRecorder.setOutputPath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) +"/HBRecorder");
+ hbRecorder.setAudioBitrate(128000);
+ hbRecorder.setAudioSamplingRate(44100);
+
+
+ //When the user returns to the application, some UI changes might be necessary,
+ //check if recording is in progress and make changes accordingly
+ if (hbRecorder.isBusyRecording()) {
+ startbtn.setText(R.string.stop_recording);
+ }
+
+ }
+
+ //Create Folder
+ private void createFolder() {
+ File f1 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "HBRecorder");
+ if (!f1.exists()) {
+ if (f1.mkdirs()){
+ Log.i("Folder ","created");
+ }
+ }
+ }
+
+ //Init Views
+ private void initViews() {
+ startbtn = findViewById(R.id.button_start);
+ radioGroup = findViewById(R.id.radio_group);
+ hdRadio = findViewById(R.id.hd_button);
+ sdRadio = findViewById(R.id.sd_button);
+ recordAudioCheckBox = findViewById(R.id.audio_check_box);
+ notificationCheckbox = findViewById(R.id.notification_check_box);
+ }
+
+ //Start Button OnClickListener
+ private void mOnClickListeners() {
+ startbtn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ //first check if permissions was granted
+ if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO) && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE)) {
+ hasPermissions = true;
+ }
+ if (hasPermissions) {
+ //check if recording is in progress
+ //and stop it if it is
+ if (hbRecorder.isBusyRecording()) {
+ hbRecorder.stopScreenRecording();
+ startbtn.setText(R.string.start_recording);
+
+ }
+ //else start recording
+ else {
+ startRecordingScreen();
+ }
+ }
+ }
+ });
+ }
+
+ //Change color states of radio buttons
+ private void radioButtonColorStates() {
+ ColorStateList colorStateList = new ColorStateList(
+ new int[][]{
+ new int[]{-android.R.attr.state_checked},
+ new int[]{android.R.attr.state_checked}
+ },
+ new int[]{
+ ContextCompat.getColor(this, R.color.white)
+ , ContextCompat.getColor(this, R.color.colorAccent),
+ }
+ );
+
+ hdRadio.setButtonTintList(colorStateList);
+ sdRadio.setButtonTintList(colorStateList);
+
+ }
+
+ //Check if HD/SD Video should be recorded
+ private void radioGroupCheckListener() {
+ radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
+ switch (checkedId) {
+ case R.id.hd_button:
+ //Ser HBRecorder to HD
+ hbRecorder.recordHDVideo(true);
+ break;
+ case R.id.sd_button:
+ //Ser HBRecorder to SD
+ hbRecorder.recordHDVideo(false);
+ break;
+ }
+ }
+ });
+ }
+
+ //Check if audio should be recorded
+ private void recordAudioCheckBoxListener() {
+ recordAudioCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+ if (isChecked) {
+ //Enable audio
+ hbRecorder.isAudioEnabled(true);
+ } else {
+ //Disable audio
+ hbRecorder.isAudioEnabled(false);
+ }
+ }
+ });
+ }
+
+ //Check if notifications should be shown
+ private void notificationCheckboxListener() {
+ notificationCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
+ //Enable notifications
+ if (isChecked) {
+ hbRecorder.shouldShowNotification(true);
+ hbRecorder.setNotificationSmallIcon(R.drawable.icon);
+ hbRecorder.setNotificationTitle("Recording your screen");
+ hbRecorder.setNotificationDescription("Drag down to stop the recording");
+ }
+ //Disable notifications
+ else {
+ hbRecorder.shouldShowNotification(false);
+ }
+ }
+ });
+ }
+
+ //Listener for when the recording is saved successfully
+ //This will be called after the file was created
+ @Override
+ public void HBRecorderOnComplete() {
+ startbtn.setText(R.string.start_recording);
+ showLongToast("Saved Successfully");
+
+ }
+
+ //Start recording screen
+ //It is important to call it like this
+ //hbRecorder.startScreenRecording(data); should only be called in onActivityResult
+ private void startRecordingScreen() {
+ MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
+ Intent permissionIntent = mediaProjectionManager != null ? mediaProjectionManager.createScreenCaptureIntent() : null;
+ startActivityForResult(permissionIntent, SCREEN_RECORD_REQUEST_CODE);
+ startbtn.setText(R.string.stop_recording);
+ }
+
+ //Check if permissions was granted
+ private boolean checkSelfPermission(String permission, int requestCode) {
+ if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
+ ActivityCompat.requestPermissions(this, new String[]{permission}, requestCode);
+ return false;
+ }
+ return true;
+ }
+
+ //Handle permissions
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ switch (requestCode) {
+ case PERMISSION_REQ_ID_RECORD_AUDIO:
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE);
+ } else {
+ hasPermissions = false;
+ showLongToast("No permission for " + Manifest.permission.RECORD_AUDIO);
+ }
+ break;
+ case PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE:
+ if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ hasPermissions = true;
+ //Permissions was provided
+ //Start screen recording
+ startRecordingScreen();
+ } else {
+ hasPermissions = false;
+ showLongToast("No permission for " + Manifest.permission.WRITE_EXTERNAL_STORAGE);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == SCREEN_RECORD_REQUEST_CODE) {
+ if (resultCode == RESULT_OK) {
+ //It is important to call this before starting the recording
+ hbRecorder.onActivityResult(resultCode, data, this);
+ //Start screen recording
+ hbRecorder.startScreenRecording(data);
+
+ }
+ }
+ }
+
+ //Show Toast
+ private void showLongToast(final String msg) {
+ Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();
+ }
+}
diff --git a/app/src/main/res/drawable/icon.png b/app/src/main/res/drawable/icon.png
new file mode 100644
index 0000000..750d96d
Binary files /dev/null and b/app/src/main/res/drawable/icon.png differ
diff --git a/app/src/main/res/drawable/ripple_effect.xml b/app/src/main/res/drawable/ripple_effect.xml
new file mode 100644
index 0000000..8dff928
--- /dev/null
+++ b/app/src/main/res/drawable/ripple_effect.xml
@@ -0,0 +1,11 @@
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..649c946
--- /dev/null
+++ b/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100755
index 0000000..dff21ae
Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100755
index 0000000..29b01d1
Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100755
index 0000000..7d4cfec
Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100755
index 0000000..d6175a8
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100755
index 0000000..efd54ab
Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..a8257f4
--- /dev/null
+++ b/app/src/main/res/values/colors.xml
@@ -0,0 +1,8 @@
+
+
+ #212121
+ #131313
+ #e70041
+ #ffffff
+ #303030
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..dc54752
--- /dev/null
+++ b/app/src/main/res/values/strings.xml
@@ -0,0 +1,9 @@
+
+ HBRecorderExample
+ START
+ STOP
+ Record Audio
+ High Definition
+ Standard Definition
+ Show Notification
+
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..de850c2
--- /dev/null
+++ b/app/src/main/res/values/styles.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
diff --git a/app/src/test/java/com/hbisoft/hbrecorderexample/ExampleUnitTest.java b/app/src/test/java/com/hbisoft/hbrecorderexample/ExampleUnitTest.java
new file mode 100644
index 0000000..ec3433f
--- /dev/null
+++ b/app/src/test/java/com/hbisoft/hbrecorderexample/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.hbisoft.hbrecorderexample;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
new file mode 100644
index 0000000..458d06a
--- /dev/null
+++ b/build.gradle
@@ -0,0 +1,27 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+buildscript {
+ repositories {
+ google()
+ jcenter()
+
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:3.4.2'
+
+ // NOTE: Do not place your application dependencies here; they belong
+ // in the individual module build.gradle files
+ }
+}
+
+allprojects {
+ repositories {
+ google()
+ jcenter()
+
+ }
+}
+
+task clean(type: Delete) {
+ delete rootProject.buildDir
+}
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 0000000..d546dea
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,17 @@
+# Project-wide Gradle settings.
+# IDE (e.g. Android Studio) users:
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
+# For more details on how to configure your build environment visit
+# http://www.gradle.org/docs/current/userguide/build_environment.html
+# Specifies the JVM arguments used for the daemon process.
+# The setting is particularly useful for tweaking memory settings.
+android.enableJetifier=true
+android.useAndroidX=true
+org.gradle.jvmargs=-Xmx1536m
+# When configured, Gradle will run in incubating parallel mode.
+# This option should only be used with decoupled projects. More details, visit
+# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# org.gradle.parallel=true
+
+
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..f6b961f
Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..4a77448
--- /dev/null
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Tue Aug 13 06:59:47 SAST 2019
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
diff --git a/gradlew b/gradlew
new file mode 100755
index 0000000..cccdd3d
--- /dev/null
+++ b/gradlew
@@ -0,0 +1,172 @@
+#!/usr/bin/env sh
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn () {
+ echo "$*"
+}
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+ NONSTOP* )
+ nonstop=true
+ ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Escape application args
+save () {
+ for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
+ echo " "
+}
+APP_ARGS=$(save "$@")
+
+# Collect all arguments for the java command, following the shell quoting and substitution rules
+eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
+
+# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
+if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
+ cd "$(dirname "$0")"
+fi
+
+exec "$JAVACMD" "$@"
diff --git a/gradlew.bat b/gradlew.bat
new file mode 100644
index 0000000..f955316
--- /dev/null
+++ b/gradlew.bat
@@ -0,0 +1,84 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windows variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/hbrecorder/.gitignore b/hbrecorder/.gitignore
new file mode 100644
index 0000000..796b96d
--- /dev/null
+++ b/hbrecorder/.gitignore
@@ -0,0 +1 @@
+/build
diff --git a/hbrecorder/build.gradle b/hbrecorder/build.gradle
new file mode 100644
index 0000000..84a05ab
--- /dev/null
+++ b/hbrecorder/build.gradle
@@ -0,0 +1,33 @@
+apply plugin: 'com.android.library'
+
+android {
+ compileSdkVersion 28
+
+
+ defaultConfig {
+ minSdkVersion 21
+ targetSdkVersion 28
+ versionCode 1
+ versionName "1.0"
+
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ }
+ }
+
+}
+
+dependencies {
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
+
+ implementation 'androidx.appcompat:appcompat:1.0.2'
+ testImplementation 'junit:junit:4.12'
+ androidTestImplementation 'androidx.test:runner:1.2.0'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+}
diff --git a/hbrecorder/proguard-rules.pro b/hbrecorder/proguard-rules.pro
new file mode 100644
index 0000000..f1b4245
--- /dev/null
+++ b/hbrecorder/proguard-rules.pro
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+# http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+# public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/hbrecorder/src/androidTest/java/com/hbisoft/hbrecorder/ExampleInstrumentedTest.java b/hbrecorder/src/androidTest/java/com/hbisoft/hbrecorder/ExampleInstrumentedTest.java
new file mode 100644
index 0000000..8bb7dc4
--- /dev/null
+++ b/hbrecorder/src/androidTest/java/com/hbisoft/hbrecorder/ExampleInstrumentedTest.java
@@ -0,0 +1,26 @@
+package com.hbisoft.hbrecorder;
+
+import android.content.Context;
+import androidx.test.InstrumentationRegistry;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+/**
+ * Instrumented test, which will execute on an Android device.
+ *
+ * @see Testing documentation
+ */
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ // Context of the app under test.
+ Context appContext = InstrumentationRegistry.getTargetContext();
+
+ assertEquals("com.hbisoft.hbrecorder.test", appContext.getPackageName());
+ }
+}
diff --git a/hbrecorder/src/main/AndroidManifest.xml b/hbrecorder/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..6ebdb3d
--- /dev/null
+++ b/hbrecorder/src/main/AndroidManifest.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/FileObserver.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/FileObserver.java
new file mode 100644
index 0000000..ddc88c4
--- /dev/null
+++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/FileObserver.java
@@ -0,0 +1,94 @@
+package com.hbisoft.hbrecorder;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import android.app.Activity;
+
+
+class FileObserver extends android.os.FileObserver {
+
+ private List mObservers;
+ private final String mPath;
+ private final int mMask;
+ private final Activity activity;
+ private final MyListener ml;
+
+ FileObserver(String path, Activity activity, MyListener ml) {
+ super(path, ALL_EVENTS);
+ mPath = path;
+ mMask = ALL_EVENTS;
+
+ this.activity = activity;
+ this.ml = ml;
+
+ }
+
+
+ @Override
+ public void startWatching() {
+ if (mObservers != null) return;
+
+ mObservers = new ArrayList<>();
+ Stack stack = new Stack<>();
+ stack.push(mPath);
+
+ while (!stack.isEmpty()) {
+ String parent = stack.pop();
+ mObservers.add(new SingleFileObserver(parent, mMask));
+ File path = new File(parent);
+ File[] files = path.listFiles();
+ if (null == files) continue;
+
+ for (File f : files) {
+ if (f.isDirectory() && !f.getName().equals(".") && !f.getName().equals("..")) {
+ stack.push(f.getPath());
+ }
+ }
+ }
+
+ for (SingleFileObserver sfo : mObservers) {
+ sfo.startWatching();
+ }
+ }
+
+ @Override
+ public void stopWatching() {
+ if (mObservers == null) return;
+
+ for (SingleFileObserver sfo : mObservers) {
+ sfo.stopWatching();
+ }
+ mObservers.clear();
+ mObservers = null;
+ }
+
+ @Override
+ public void onEvent(int event, final String path) {
+ if (event == android.os.FileObserver.CLOSE_WRITE) {
+ activity.runOnUiThread(new Runnable() {
+ public void run() {
+ ml.callback();
+ }
+ });
+ }
+ }
+
+ class SingleFileObserver extends android.os.FileObserver {
+ final String mPath;
+
+
+ SingleFileObserver(String path, int mask) {
+ super(path, mask);
+ mPath = path;
+ }
+
+ @Override
+ public void onEvent(int event, String path) {
+ String newPath = mPath + "/" + path;
+ FileObserver.this.onEvent(event, newPath);
+ }
+ }
+}
diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java
new file mode 100644
index 0000000..d49c20e
--- /dev/null
+++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java
@@ -0,0 +1,189 @@
+package com.hbisoft.hbrecorder;
+
+import android.app.Activity;
+import android.app.ActivityManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.os.Build;
+import android.os.Environment;
+
+import androidx.annotation.RequiresApi;
+
+import android.util.DisplayMetrics;
+
+import java.io.ByteArrayOutputStream;
+
+@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+public class HBRecorder implements MyListener {
+ private int mScreenWidth;
+ private int mScreenHeight;
+ private int mScreenDensity;
+ private final Context context;
+ private int resultCode;
+ private Intent data;
+ private boolean isAudioEnabled = true;
+ private boolean isVideoHDEnabled = true;
+ private Activity activity;
+ private String outputPath;
+ private String fileName;
+ private String notificationTitle;
+ private String notificationDescription;
+ private String notificationButtonText;
+ private int audioBitrate;
+ private int audioSamplingRate;
+ private FileObserver observer;
+ private final HBRecorderListener hbRecorderListener;
+ private byte[] byteArray;
+ private boolean shouldShowNotification = false;
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ public HBRecorder(Context context, HBRecorderListener listener) {
+ this.context = context.getApplicationContext();
+ this.hbRecorderListener = listener;
+ getScreenDimensions();
+ }
+
+ /*Get resultCode, Intent and Activity from onActivityResult*/
+ public void onActivityResult(int resultCode, Intent data, Activity activity) {
+ this.resultCode = resultCode;
+ this.data = data;
+ this.activity = activity;
+ }
+
+ /*Set output path*/
+ public void setOutputPath(String path) {
+ outputPath = path;
+ }
+
+ /*Set file name*/
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ /*Set audio bitrate*/
+ public void setAudioBitrate(int audioBitrate) {
+ this.audioBitrate = audioBitrate;
+
+ }
+
+ /*Set audio sample rate*/
+ public void setAudioSamplingRate(int audioSamplingRate) {
+ this.audioSamplingRate = audioSamplingRate;
+ }
+
+ /*Enable/Disable audio*/
+ public void isAudioEnabled(boolean bool) {
+ this.isAudioEnabled = bool;
+ }
+
+ /*Enable/Disable HD recording*/
+ public void recordHDVideo(boolean bool) {
+ this.isVideoHDEnabled = bool;
+ }
+
+ /*Get/Set screen dimensions/resolution
+ * This is use to determine video bitrate
+ * */
+ private void getScreenDimensions() {
+ DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
+ mScreenWidth = metrics.widthPixels;
+ mScreenHeight = metrics.heightPixels;
+ mScreenDensity = metrics.densityDpi;
+ }
+
+ /*Get file path including file name and extension*/
+ public String getFilePath() {
+ return ScreenRecordService.getFilePath();
+ }
+
+ /*Get file name and extension*/
+ public String getFileName() {
+ return ScreenRecordService.getFileName();
+ }
+
+ /*Start screen recording*/
+ public void startScreenRecording(Intent data) {
+ startService(data);
+ }
+
+ /*Stop screen recording*/
+ public void stopScreenRecording() {
+ Intent service = new Intent(context, ScreenRecordService.class);
+ context.stopService(service);
+ }
+
+ /*Check if recording is in progress*/
+ @SuppressWarnings("deprecation") //For more on why this is added, see - https://stackoverflow.com/q/45519439/5550161
+ public boolean isBusyRecording() {
+ ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (ScreenRecordService.class.getName().equals(service.service.getClassName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*Change notification icon*/
+ public void setNotificationSmallIcon(int drawable) {
+ Bitmap icon = BitmapFactory.decodeResource(context.getResources(), drawable);
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ icon.compress(Bitmap.CompressFormat.PNG, 100, stream);
+ byteArray = stream.toByteArray();
+ }
+
+ /*Enable/Disable notifications*/
+ public void shouldShowNotification(boolean bool) {
+ shouldShowNotification = bool;
+ }
+
+ /*Set notification title*/
+ public void setNotificationTitle(String Title) {
+ notificationTitle = Title;
+ }
+
+ /*Set notification description*/
+ public void setNotificationDescription(String Description) {
+ notificationDescription = Description;
+ }
+
+ public void setNotificationButtonText(String string){
+ notificationButtonText = string;
+ }
+
+ /*Start recording service*/
+ private void startService(Intent data) {
+ observer = new FileObserver(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)), activity, HBRecorder.this);
+ observer.startWatching();
+
+ Intent service = new Intent(context, ScreenRecordService.class);
+ service.putExtra("code", resultCode);
+ service.putExtra("data", data);
+ service.putExtra("audio", isAudioEnabled);
+ service.putExtra("width", mScreenWidth);
+ service.putExtra("height", mScreenHeight);
+ service.putExtra("density", mScreenDensity);
+ service.putExtra("quality", isVideoHDEnabled);
+ service.putExtra("path", outputPath);
+ service.putExtra("fileName", fileName);
+ service.putExtra("audioBitrate", audioBitrate);
+ service.putExtra("audioSamplingRate", audioSamplingRate);
+ service.putExtra("notificationSmallBitmap", byteArray);
+ service.putExtra("notificationTitle", notificationTitle);
+ service.putExtra("notificationDescription", notificationDescription);
+ service.putExtra("shouldShowNotification", shouldShowNotification);
+ service.putExtra("notificationButtonText", notificationButtonText);
+
+ context.startService(service);
+ }
+
+ /*Complete callback method*/
+ @Override
+ public void callback() {
+ observer.stopWatching();
+ hbRecorderListener.HBRecorderOnComplete();
+ }
+}
diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorderListener.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorderListener.java
new file mode 100644
index 0000000..d6f24ea
--- /dev/null
+++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorderListener.java
@@ -0,0 +1,5 @@
+package com.hbisoft.hbrecorder;
+
+public interface HBRecorderListener {
+ void HBRecorderOnComplete();
+}
diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/MyListener.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/MyListener.java
new file mode 100644
index 0000000..9dce42e
--- /dev/null
+++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/MyListener.java
@@ -0,0 +1,6 @@
+package com.hbisoft.hbrecorder;
+
+interface MyListener {
+ void callback();
+
+}
diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/NotificationReceiver.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/NotificationReceiver.java
new file mode 100644
index 0000000..6871f2f
--- /dev/null
+++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/NotificationReceiver.java
@@ -0,0 +1,14 @@
+package com.hbisoft.hbrecorder;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class NotificationReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Intent service = new Intent(context, ScreenRecordService.class);
+ context.stopService(service);
+ }
+}
diff --git a/hbrecorder/src/main/java/com/hbisoft/hbrecorder/ScreenRecordService.java b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/ScreenRecordService.java
new file mode 100755
index 0000000..93b5456
--- /dev/null
+++ b/hbrecorder/src/main/java/com/hbisoft/hbrecorder/ScreenRecordService.java
@@ -0,0 +1,240 @@
+package com.hbisoft.hbrecorder;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.drawable.Icon;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.VirtualDisplay;
+import android.media.MediaRecorder;
+import android.media.projection.MediaProjection;
+import android.media.projection.MediaProjectionManager;
+import android.os.Build;
+import android.os.Environment;
+import android.os.IBinder;
+
+import androidx.annotation.RequiresApi;
+
+import android.util.Log;
+
+import java.io.IOException;
+import java.sql.Date;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+import java.util.Objects;
+
+public class ScreenRecordService extends Service {
+
+ private static final String TAG = "ScreenRecordService";
+
+ private int mScreenWidth;
+ private int mScreenHeight;
+ private int mScreenDensity;
+ private int mResultCode;
+ private Intent mResultData;
+ private boolean isVideoHD;
+ private boolean isAudioEnabled;
+ private String path;
+
+ private MediaProjection mMediaProjection;
+ private MediaRecorder mMediaRecorder;
+ private VirtualDisplay mVirtualDisplay;
+ private String name;
+ private int audioBitrate;
+ private int audioSamplingRate;
+ private static String filePath;
+ private static String fileName;
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ /*
+ * Notification Start
+ */
+ byte[] notificationSmallIcon = intent.getByteArrayExtra("notificationSmallBitmap");
+ String notificationTitle = intent.getStringExtra("notificationTitle");
+ String notificationDescription = intent.getStringExtra("notificationDescription");
+ boolean shouldShowNotification = intent.getBooleanExtra("shouldShowNotification", true);
+ String notificationButtonText = intent.getStringExtra("notificationButtonText");
+
+ if (notificationButtonText==null){
+ notificationButtonText = "STOP RECORDING";
+ }
+
+ //Check if notification should be shown
+ if (shouldShowNotification) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ String channelId = "001";
+ String channelName = "RecordChannel";
+ NotificationChannel channel = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_NONE);
+ channel.setLightColor(Color.BLUE);
+ channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
+ NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ if (manager != null) {
+ manager.createNotificationChannel(channel);
+ Notification notification;
+
+ Intent myIntent = new Intent(this, NotificationReceiver.class);
+
+ PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, myIntent, 0);
+
+ Notification.Action action = new Notification.Action.Builder(
+ Icon.createWithResource(this, android.R.drawable.presence_video_online),
+ notificationButtonText,
+ pendingIntent).build();
+
+ if (notificationSmallIcon != null) {
+ Bitmap bmp = BitmapFactory.decodeByteArray(notificationSmallIcon, 0, notificationSmallIcon.length);
+ //Modify notification badge
+ notification = new Notification.Builder(getApplicationContext(), channelId).setOngoing(true).setSmallIcon(Icon.createWithBitmap(bmp)).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();
+
+ }
+ startForeground(101, notification);
+ }
+ } else {
+ startForeground(101, new Notification());
+ }
+ }
+ /*
+ * Notification End
+ */
+
+ mResultCode = intent.getIntExtra("code", -1);
+ mResultData = intent.getParcelableExtra("data");
+ mScreenWidth = intent.getIntExtra("width", 720);
+ mScreenHeight = intent.getIntExtra("height", 1280);
+ mScreenDensity = intent.getIntExtra("density", 1);
+ isVideoHD = intent.getBooleanExtra("quality", true);
+ isAudioEnabled = intent.getBooleanExtra("audio", true);
+ path = intent.getStringExtra("path");
+ name = intent.getStringExtra("fileName");
+
+ filePath = name;
+ audioBitrate = intent.getIntExtra("audioBitrate", 128000);
+ audioSamplingRate = intent.getIntExtra("audioSamplingRate", 44100);
+
+ if (path == null) {
+ path = String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES));
+ }
+
+ mMediaProjection = createMediaProjection();
+ mMediaRecorder = createMediaRecorder();
+ mVirtualDisplay = createVirtualDisplay();
+ mMediaRecorder.start();
+
+ return Service.START_STICKY;
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ private MediaProjection createMediaProjection() {
+ return ((MediaProjectionManager) Objects.requireNonNull(getSystemService(Context.MEDIA_PROJECTION_SERVICE))).
+ getMediaProjection(mResultCode, mResultData);
+ }
+
+ public static String getFilePath() {
+ return filePath;
+ }
+
+ public static String getFileName() {
+ return fileName;
+ }
+
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ private MediaRecorder createMediaRecorder() {
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.getDefault());
+ Date curDate = new Date(System.currentTimeMillis());
+ String curTime = formatter.format(curDate).replace(" ", "");
+ String videoQuality = "HD";
+ if (!isVideoHD) {
+ videoQuality = "SD";
+ }
+ if (name == null) {
+ name = videoQuality + curTime;
+ }
+
+ filePath = path + "/" + name + ".mp4";
+
+ fileName = name + ".mp4";
+
+ MediaRecorder mediaRecorder = new MediaRecorder();
+
+
+ if (isAudioEnabled) {
+ mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+ }
+ mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
+ mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
+ if (isAudioEnabled) {
+ mediaRecorder.setAudioEncodingBitRate(audioBitrate);
+ mediaRecorder.setAudioSamplingRate(audioSamplingRate);
+ }
+
+ mediaRecorder.setOutputFile(path + "/" + name + ".mp4");
+ mediaRecorder.setVideoSize(mScreenWidth, mScreenHeight);
+ mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
+ if (isAudioEnabled) {
+ mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
+ }
+ if (!isVideoHD) {
+ mediaRecorder.setVideoEncodingBitRate(5000000);
+ mediaRecorder.setVideoFrameRate(30);
+ Log.e("info - ", String.valueOf(2 * mScreenWidth * mScreenHeight));
+ } else {
+ mediaRecorder.setVideoEncodingBitRate(5 * mScreenWidth * mScreenHeight);
+ mediaRecorder.setVideoFrameRate(60); //after setVideoSource(), setOutFormat()
+ }
+
+
+ try {
+ mediaRecorder.prepare();
+ } catch (IllegalStateException | IOException e) {
+ Log.e(TAG, "createMediaRecorder: e = " + e.toString());
+ }
+
+ return mediaRecorder;
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ private VirtualDisplay createVirtualDisplay() {
+ return mMediaProjection.createVirtualDisplay(TAG, mScreenWidth, mScreenHeight, mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mMediaRecorder.getSurface(), null, null);
+ }
+
+ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ stopForeground(true);
+ if (mVirtualDisplay != null) {
+ mVirtualDisplay.release();
+ mVirtualDisplay = null;
+ }
+ if (mMediaRecorder != null) {
+ mMediaRecorder.setOnErrorListener(null);
+
+ mMediaProjection.stop();
+ mMediaRecorder.reset();
+ }
+ if (mMediaProjection != null) {
+ mMediaProjection.stop();
+ mMediaProjection = null;
+ }
+
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+}
diff --git a/hbrecorder/src/main/res/drawable/icon.png b/hbrecorder/src/main/res/drawable/icon.png
new file mode 100644
index 0000000..750d96d
Binary files /dev/null and b/hbrecorder/src/main/res/drawable/icon.png differ
diff --git a/hbrecorder/src/main/res/values/strings.xml b/hbrecorder/src/main/res/values/strings.xml
new file mode 100644
index 0000000..c23246a
--- /dev/null
+++ b/hbrecorder/src/main/res/values/strings.xml
@@ -0,0 +1,3 @@
+
+ HBRecorder
+
diff --git a/hbrecorder/src/test/java/com/hbisoft/hbrecorder/ExampleUnitTest.java b/hbrecorder/src/test/java/com/hbisoft/hbrecorder/ExampleUnitTest.java
new file mode 100644
index 0000000..ea82c7e
--- /dev/null
+++ b/hbrecorder/src/test/java/com/hbisoft/hbrecorder/ExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.hbisoft.hbrecorder;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ * Example local unit test, which will execute on the development machine (host).
+ *
+ * @see Testing documentation
+ */
+public class ExampleUnitTest {
+ @Test
+ public void addition_isCorrect() {
+ assertEquals(4, 2 + 2);
+ }
+}
\ No newline at end of file
diff --git a/settings.gradle b/settings.gradle
new file mode 100644
index 0000000..aa20108
--- /dev/null
+++ b/settings.gradle
@@ -0,0 +1 @@
+include ':app', ':hbrecorder'