Skip to content

Commit

Permalink
Release of 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
HBiSoft committed Mar 6, 2023
1 parent 70ef72b commit 0b5b45d
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 51 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 31
compileSdkVersion 33
defaultConfig {
applicationId "com.hbisoft.hbrecorderexample"
minSdkVersion 17
targetSdkVersion 31
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Binary file modified app/release/HBRecorderDemo.apk
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"
Expand Down
116 changes: 71 additions & 45 deletions app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class MainActivity extends AppCompatActivity implements HBRecorderListene
//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_POST_NOTIFICATIONS = 33;
private static final int PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE = PERMISSION_REQ_ID_RECORD_AUDIO + 1;
private boolean hasPermissions = false;

Expand Down Expand Up @@ -196,36 +197,38 @@ private void initViews() {

//Start Button OnClickListener
private void setOnClickListeners() {
startbtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//first check if permissions was granted
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
hasPermissions = true;
}
} else {
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;
}
startbtn.setOnClickListener(v -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//first check if permissions was granted
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
if (checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS, PERMISSION_REQ_POST_NOTIFICATIONS) && checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
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();
}
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
hasPermissions = true;
}
} else {
showLongToast("This library requires API 21>");
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();
}
}
} else {
showLongToast("This library requires API 21>");
}
});
}
Expand Down Expand Up @@ -258,6 +261,7 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
});
}

// Called when recording starts
@Override
public void HBRecorderOnStart() {
Log.e("HBRecorder", "HBRecorderOnStart called");
Expand All @@ -284,25 +288,7 @@ public void HBRecorderOnComplete() {

}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void refreshGalleryFile() {
MediaScannerConnection.scanFile(this,
new String[]{hbRecorder.getFilePath()}, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
}

@RequiresApi(api = Build.VERSION_CODES.Q)
private void updateGalleryUri(){
contentValues.clear();
contentValues.put(MediaStore.Video.Media.IS_PENDING, 0);
getContentResolver().update(mUri, contentValues, null, null);
}

// Called when error occurs
@Override
public void HBRecorderOnError(int errorCode, String reason) {
// Error 38 happens when
Expand All @@ -325,6 +311,37 @@ public void HBRecorderOnError(int errorCode, String reason) {

}

// Called when recording has been paused
@Override
public void HBRecorderOnPause() {
// Called when recording was paused
}

// Calld when recording has resumed
@Override
public void HBRecorderOnResume() {
// Called when recording was resumed
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void refreshGalleryFile() {
MediaScannerConnection.scanFile(this,
new String[]{hbRecorder.getFilePath()}, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
}

@RequiresApi(api = Build.VERSION_CODES.Q)
private void updateGalleryUri(){
contentValues.clear();
contentValues.put(MediaStore.Video.Media.IS_PENDING, 0);
getContentResolver().update(mUri, contentValues, null, null);
}

//Start recording screen
//It is important to call it like this
//hbRecorder.startScreenRecording(data); should only be called in onActivityResult
Expand All @@ -347,6 +364,7 @@ private void startRecordingScreen() {
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
// Example of how to set custom settings
private void customSettings() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

Expand Down Expand Up @@ -557,6 +575,14 @@ private boolean checkSelfPermission(String permission, int requestCode) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case PERMISSION_REQ_POST_NOTIFICATIONS:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO);
} else {
hasPermissions = false;
showLongToast("No permission for " + Manifest.permission.POST_NOTIFICATIONS);
}
break;
case PERMISSION_REQ_ID_RECORD_AUDIO:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, PERMISSION_REQ_ID_WRITE_EXTERNAL_STORAGE);
Expand Down
4 changes: 2 additions & 2 deletions hbrecorder/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 31
compileSdkVersion 33

defaultConfig {
minSdkVersion 17
targetSdkVersion 31
targetSdkVersion 33
versionCode 1
versionName "1.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ public class Constants {
public final static String ON_COMPLETE_KEY = "onComplete";
public final static String ON_START_KEY = "onStart";
public final static String ON_COMPLETE = "Uri was passed";
public final static String ON_PAUSE_KEY = "onPause";
public final static String ON_RESUME_KEY = "onResume";
public final static String ON_PAUSE = "Paused";
public final static String ON_RESUME = "Resumed";
public final static int SETTINGS_ERROR = 38;
public final static int MAX_FILE_SIZE_REACHED_ERROR = 48;
public final static int GENERAL_ERROR = 100;
Expand Down
21 changes: 19 additions & 2 deletions hbrecorder/src/main/java/com/hbisoft/hbrecorder/HBRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import static com.hbisoft.hbrecorder.Constants.NO_SPECIFIED_MAX_SIZE;
import static com.hbisoft.hbrecorder.Constants.ON_COMPLETE_KEY;
import static com.hbisoft.hbrecorder.Constants.ON_START_KEY;
import static com.hbisoft.hbrecorder.Constants.ON_PAUSE_KEY;
import static com.hbisoft.hbrecorder.Constants.ON_RESUME_KEY;

/**
* Created by HBiSoft on 13 Aug 2019
Expand Down Expand Up @@ -374,6 +376,7 @@ protected void onReceiveResult(int resultCode, Bundle resultData) {
String onComplete = resultData.getString(ON_COMPLETE_KEY);
int onStartCode = resultData.getInt(ON_START_KEY);
int errorCode = resultData.getInt(ERROR_KEY);
// There was an error
if (errorListener != null) {
//Stop countdown if it was set
stopCountDown();
Expand All @@ -393,21 +396,35 @@ protected void onReceiveResult(int resultCode, Bundle resultData) {
// Can be ignored
}

}else if (onComplete != null){
}
// OnComplete was called
else if (onComplete != null){
//Stop countdown if it was set
stopCountDown();
//OnComplete for when Uri was passed
if (mWasUriSet && !wasOnErrorCalled) {
hbRecorderListener.HBRecorderOnComplete();
}
wasOnErrorCalled = false;
}else if (onStartCode != 0){
}
// OnStart was called
else if (onStartCode != 0){
hbRecorderListener.HBRecorderOnStart();
//Check if max duration was set and start count down
if (isMaxDurationSet){
startCountdown();
}
}
// OnPause/onResume was called
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
String onPause = resultData.getString(ON_PAUSE_KEY);
String onResume = resultData.getString(ON_RESUME_KEY);
if (onPause != null) {
hbRecorderListener.HBRecorderOnPause();
} else if (onResume != null) {
hbRecorderListener.HBRecorderOnResume();
}
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package com.hbisoft.hbrecorder;

import android.os.Build;

import androidx.annotation.RequiresApi;

public interface HBRecorderListener {
void HBRecorderOnStart();
void HBRecorderOnComplete();
void HBRecorderOnError(int errorCode, String reason);
@RequiresApi(api = Build.VERSION_CODES.N)
void HBRecorderOnPause();
@RequiresApi(api = Build.VERSION_CODES.N)
void HBRecorderOnResume();
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
import static com.hbisoft.hbrecorder.Constants.NO_SPECIFIED_MAX_SIZE;
import static com.hbisoft.hbrecorder.Constants.ON_COMPLETE;
import static com.hbisoft.hbrecorder.Constants.ON_COMPLETE_KEY;
import static com.hbisoft.hbrecorder.Constants.ON_PAUSE;
import static com.hbisoft.hbrecorder.Constants.ON_PAUSE_KEY;
import static com.hbisoft.hbrecorder.Constants.ON_RESUME;
import static com.hbisoft.hbrecorder.Constants.ON_RESUME_KEY;
import static com.hbisoft.hbrecorder.Constants.ON_START;
import static com.hbisoft.hbrecorder.Constants.ON_START_KEY;
import static com.hbisoft.hbrecorder.Constants.SETTINGS_ERROR;
Expand Down Expand Up @@ -341,12 +345,24 @@ public void onInfo(MediaRecorder mr, int what, int extra) {
@RequiresApi(api = Build.VERSION_CODES.N)
private void pauseRecording(){
mMediaRecorder.pause();
ResultReceiver receiver = mIntent.getParcelableExtra(ScreenRecordService.BUNDLED_LISTENER);
Bundle bundle = new Bundle();
bundle.putString(ON_PAUSE_KEY, ON_PAUSE);
if (receiver != null) {
receiver.send(Activity.RESULT_OK, bundle);
}
}

//Resume Recording
@RequiresApi(api = Build.VERSION_CODES.N)
private void resumeRecording(){
mMediaRecorder.resume();
ResultReceiver receiver = mIntent.getParcelableExtra(ScreenRecordService.BUNDLED_LISTENER);
Bundle bundle = new Bundle();
bundle.putString(ON_RESUME_KEY, ON_RESUME);
if (receiver != null) {
receiver.send(Activity.RESULT_OK, bundle);
}
}

//Set output format as int based on what developer has provided
Expand Down

0 comments on commit 0b5b45d

Please sign in to comment.