Skip to content

Commit

Permalink
Merge pull request HBiSoft#62 from tfrysinger/master
Browse files Browse the repository at this point in the history
Updates to allow setting a max file size, begin consolidating constants into a central file, consolidating strings into a strings.xml file
  • Loading branch information
HBiSoft authored Apr 7, 2021
2 parents fd07085 + 3fcae54 commit dedf95f
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 78 deletions.
14 changes: 7 additions & 7 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 29
compileSdkVersion 30
defaultConfig {
applicationId "com.hbisoft.hbrecorderexample"
minSdkVersion 17
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -20,12 +20,12 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.legacy:legacy-support-core-utils:1.0.0'
implementation 'androidx.preference:preference:1.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation project(path: ':hbrecorder')
}
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28"
tools:ignore="ScopedStorage" />

<application
android:allowBackup="true"
android:allowBackup="false"
android:fullBackupContent="@xml/backup_descriptor"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
Expand Down
68 changes: 47 additions & 21 deletions app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Switch;
import androidx.appcompat.widget.SwitchCompat;
import android.widget.Toast;

import androidx.annotation.DrawableRes;
Expand All @@ -49,6 +50,8 @@
import java.util.Map;

import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static com.hbisoft.hbrecorder.Constants.MAX_FILE_SIZE_REACHED_ERROR;
import static com.hbisoft.hbrecorder.Constants.SETTINGS_ERROR;


/**
Expand Down Expand Up @@ -79,7 +82,7 @@
*
* */

@SuppressWarnings({"deprecation", "SameParameterValue"})
@SuppressWarnings({"SameParameterValue"})
public class MainActivity extends AppCompatActivity implements HBRecorderListener {
//Permissions
private static final int SCREEN_RECORD_REQUEST_CODE = 777;
Expand All @@ -104,7 +107,10 @@ public class MainActivity extends AppCompatActivity implements HBRecorderListene
boolean isAudioEnabled = true;

//Should custom settings be used
Switch custom_settings_switch;
SwitchCompat custom_settings_switch;

// Max file size in K
private EditText maxFileSizeInK;


@Override
Expand Down Expand Up @@ -186,6 +192,7 @@ private void initViews() {
radioGroup = findViewById(R.id.radio_group);
recordAudioCheckBox = findViewById(R.id.audio_check_box);
custom_settings_switch = findViewById(R.id.custom_settings_switch);
maxFileSizeInK = findViewById(R.id.max_file_size);
}

//Start Button OnClickListener
Expand Down Expand Up @@ -222,16 +229,13 @@ private void setRadioGroupCheckListener() {
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
switch (checkedId) {
case R.id.hd_button:
//Ser HBRecorder to HD
wasHDSelected = true;

break;
case R.id.sd_button:
//Ser HBRecorder to SD
wasHDSelected = false;
break;

if (checkedId == R.id.hd_button) {
//Ser HBRecorder to HD
wasHDSelected = true;
} else if (checkedId == R.id.sd_button) {
//Ser HBRecorder to SD
wasHDSelected = false;
}
}
});
Expand Down Expand Up @@ -262,7 +266,11 @@ public void HBRecorderOnComplete() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//Update gallery depending on SDK Level
if (hbRecorder.wasUriSet()) {
updateGalleryUri();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ) {
updateGalleryUri();
} else {
refreshGalleryFile();
}
}else{
refreshGalleryFile();
}
Expand All @@ -282,6 +290,7 @@ public void onScanCompleted(String path, Uri uri) {
});
}

@RequiresApi(api = Build.VERSION_CODES.Q)
private void updateGalleryUri(){
contentValues.clear();
contentValues.put(MediaStore.Video.Media.IS_PENDING, 0);
Expand All @@ -297,10 +306,12 @@ public void HBRecorderOnError(int errorCode, String reason) {

//It is best to use device default

if (errorCode == 38) {
showLongToast("Some settings are not supported by your device");
if (errorCode == SETTINGS_ERROR) {
showLongToast(getString(R.string.settings_not_supported_message));
} else if ( errorCode == MAX_FILE_SIZE_REACHED_ERROR) {
showLongToast(getString(R.string.max_file_size_reached_message));
} else {
showLongToast("HBRecorderOnError - See Log");
showLongToast(getString(R.string.general_recording_error_message));
Log.e("HBRecorderOnError", reason);
}

Expand All @@ -320,14 +331,13 @@ 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);
} else {
quickSettings();
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);
}
startbtn.setText(R.string.stop_recording);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
Expand Down Expand Up @@ -477,6 +487,9 @@ private void customSettings() {
}
}

// Max File Size
setRecorderMaxFileSize();

}

//Get/Set the selected settings
Expand All @@ -488,8 +501,21 @@ private void quickSettings() {
hbRecorder.isAudioEnabled(isAudioEnabled);
//Customise Notification
hbRecorder.setNotificationSmallIcon(drawable2ByteArray(R.drawable.icon));
hbRecorder.setNotificationTitle("Recording your screen");
hbRecorder.setNotificationDescription("Drag down to stop the recording");
hbRecorder.setNotificationTitle(getString(R.string.stop_recording_notification_title));
hbRecorder.setNotificationDescription(getString(R.string.stop_recording_notification_message));
setRecorderMaxFileSize();
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setRecorderMaxFileSize() {
String s = maxFileSizeInK.getText().toString();
long maxFileSizeInKilobytes;
try {
maxFileSizeInKilobytes = Long.parseLong(s);
} catch (NumberFormatException e) {
maxFileSizeInKilobytes = 0;
}
hbRecorder.setMaxFileSize(maxFileSizeInKilobytes * 1024); // Convert to bytes

}

Expand Down
44 changes: 35 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:ignore="Overdraw">

<LinearLayout
android:id="@+id/max_filesize_linear_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true">

<EditText
android:id="@+id/max_file_size"
android:inputType="numberSigned"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/max_file_hint"
android:importantForAutofill="no" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/max_file_label"
android:layout_marginTop="10dp"/>

</LinearLayout>

<ImageView
android:layout_width="300dp"
android:layout_height="1dp"
android:layout_below="@+id/max_filesize_linear_layout"
android:layout_centerHorizontal="true"
android:background="#b1b1b1"
android:layout_marginTop="40dp"
android:id="@+id/hl"
android:alpha="0.5"/>
android:alpha="0.5"
tools:ignore="ContentDescription" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="QUICK SETTINGS"
android:text="@string/quick_settings_title"
android:layout_below="@+id/hl"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
Expand Down Expand Up @@ -61,8 +87,7 @@
android:layout_marginTop="30dp"
android:checked="true"
android:text="@string/record_audio"
app:theme="@style/CheckboxStyle"
/>
app:theme="@style/CheckboxStyle"/>

<ImageView
android:layout_width="300dp"
Expand All @@ -72,12 +97,13 @@
android:background="#b1b1b1"
android:layout_marginTop="40dp"
android:id="@+id/hl1"
android:alpha="0.5"/>
android:alpha="0.5"
tools:ignore="ContentDescription" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="or"
android:text="@string/or_title"
android:gravity="center"
android:textStyle="bold"
android:layout_below="@+id/hl1"
Expand All @@ -95,13 +121,13 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USE CUSTOM SETTINGS"
android:text="@string/custom_settings_title"
android:textStyle="bold"
android:gravity="center"
android:layout_centerVertical="true"
android:id="@+id/tvCustom"/>

<Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/custom_settings_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<string name="record_audio">Record Audio</string>
<string name="high_definition">High Definition</string>
<string name="standard_definition">Standard Definition</string>
<string name="max_file_label">Max File Size (k)</string>

<string name="action_settings">Settings</string>
<string name="title_activity_settings">Settings</string>
Expand All @@ -23,4 +24,13 @@
<string name="key_video_encoder">key_video_encoder</string>
<string name="key_audio_source">key_audio_source</string>
<string name="key_output_format">key_output_format</string>
<string name="quick_settings_title">QUICK SETTINGS</string>
<string name="custom_settings_title">USE CUSTOM SETTINGS</string>
<string name="or_title">or</string>
<string name="max_file_hint">Blank == no max</string>
<string name="stop_recording_notification_message">Drag down to stop the recording</string>
<string name="stop_recording_notification_title">Recording your screen</string>
<string name="settings_not_supported_message">Some settings are not supported by your device</string>
<string name="max_file_size_reached_message">The file reached the designated max size</string>
<string name="general_recording_error_message">HBRecorderOnError - See Log</string>
</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/xml/backup_descriptor.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<full-backup-content>
<!-- Exclude specific shared preferences that contain GCM registration Id -->

</full-backup-content>
12 changes: 6 additions & 6 deletions hbrecorder/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
compileSdkVersion 30


defaultConfig {
minSdkVersion 17
targetSdkVersion 29
targetSdkVersion 30
versionCode 1
versionName "1.0"

Expand All @@ -26,8 +26,8 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
15 changes: 15 additions & 0 deletions hbrecorder/src/main/java/com/hbisoft/hbrecorder/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hbisoft.hbrecorder;

public class Constants {
public final static String MAX_FILE_SIZE_KEY = "maxFileSize";
public final static String ERROR_REASON_KEY = "errorReason";
public final static String ERROR_KEY = "error";
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 int SETTINGS_ERROR = 38;
public final static int MAX_FILE_SIZE_REACHED_ERROR = 48;
public final static int GENERAL_ERROR = 100;
public final static int ON_START = 111;
public final static int NO_SPECIFIED_MAX_SIZE = 0;
}
Loading

0 comments on commit dedf95f

Please sign in to comment.