From 33d9032318fc2969fd5b58e75eb7d5cfb773d09f Mon Sep 17 00:00:00 2001 From: HBiSoft Date: Wed, 25 Sep 2019 07:03:31 +0200 Subject: [PATCH] Lower minSdkVersion --- .idea/codeStyles/Project.xml | 116 +++++++++++++ .idea/misc.xml | 8 +- app/build.gradle | 2 +- .../hbrecorderexample/MainActivity.java | 163 +++++++++--------- app/src/main/res/layout/activity_main.xml | 1 - app/src/main/res/values/styles.xml | 6 +- hbrecorder/build.gradle | 2 +- 7 files changed, 210 insertions(+), 88 deletions(-) create mode 100644 .idea/codeStyles/Project.xml diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..681f41a --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 85d6e17..4c54be5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -5,7 +5,7 @@ diff --git a/app/build.gradle b/app/build.gradle index 26c4df3..ece6b77 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,7 +4,7 @@ android { compileSdkVersion 28 defaultConfig { applicationId "com.hbisoft.hbrecorderexample" - minSdkVersion 21 + minSdkVersion 17 targetSdkVersion 28 versionCode 1 versionName "1.0" diff --git a/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java index e190aad..b4296c8 100644 --- a/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java +++ b/app/src/main/java/com/hbisoft/hbrecorderexample/MainActivity.java @@ -4,15 +4,17 @@ 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.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 androidx.appcompat.widget.AppCompatRadioButton; import android.util.Log; import android.view.View; @@ -31,7 +33,7 @@ /** * Created by HBiSoft on 13 Aug 2019 * Copyright (c) 2019 . All rights reserved. - * Last modified 13 Aug 2019 + * Last modified 25 Sep 2019 */ /* @@ -73,14 +75,17 @@ public class MainActivity extends AppCompatActivity implements HBRecorderListene 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; + //Reference to checkboxes and radio buttons + boolean wasHDSelected = true; + boolean isAudioEnabled = true; + boolean isNotificationsEnabled = true; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -90,22 +95,22 @@ protected void onCreate(Bundle savedInstanceState) { 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); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + //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); + } } } @@ -114,8 +119,8 @@ protected void onCreate(Bundle savedInstanceState) { private void createFolder() { File f1 = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), "HBRecorder"); if (!f1.exists()) { - if (f1.mkdirs()){ - Log.i("Folder ","created"); + if (f1.mkdirs()) { + Log.i("Folder ", "created"); } } } @@ -124,8 +129,6 @@ private void createFolder() { 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); } @@ -135,45 +138,30 @@ 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); - + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + //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; } - //else start recording - else { - startRecordingScreen(); + 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>"); } } }); } - //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() { @@ -182,11 +170,11 @@ public void onCheckedChanged(RadioGroup radioGroup, int checkedId) { switch (checkedId) { case R.id.hd_button: //Ser HBRecorder to HD - hbRecorder.recordHDVideo(true); + wasHDSelected = true; break; case R.id.sd_button: //Ser HBRecorder to SD - hbRecorder.recordHDVideo(false); + wasHDSelected = false; break; } } @@ -198,13 +186,8 @@ 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); - } + //Enable/Disable audio + isAudioEnabled = isChecked; } }); } @@ -214,17 +197,8 @@ 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); - } + //Enable/Disable notifications + isNotificationsEnabled = isChecked; } }); } @@ -241,13 +215,38 @@ public void HBRecorderOnComplete() { //Start recording screen //It is important to call it like this //hbRecorder.startScreenRecording(data); should only be called in onActivityResult + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void startRecordingScreen() { + userSettings(); 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); } + //Get/Set the selected settings + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + private void userSettings() { + if (wasHDSelected){ + hbRecorder.recordHDVideo(true); + }else{ + hbRecorder.recordHDVideo(false); + } + if (isAudioEnabled){ + hbRecorder.isAudioEnabled(true); + }else{ + hbRecorder.isAudioEnabled(true); + } + if (isNotificationsEnabled){ + hbRecorder.shouldShowNotification(true); + hbRecorder.setNotificationSmallIcon(R.drawable.icon); + hbRecorder.setNotificationTitle("Recording your screen"); + hbRecorder.setNotificationDescription("Drag down to stop the recording"); + }else{ + hbRecorder.shouldShowNotification(false); + } + } + //Check if permissions was granted private boolean checkSelfPermission(String permission, int requestCode) { if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) { @@ -274,7 +273,9 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis hasPermissions = true; //Permissions was provided //Start screen recording - startRecordingScreen(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + startRecordingScreen(); + } } else { hasPermissions = false; showLongToast("No permission for " + Manifest.permission.WRITE_EXTERNAL_STORAGE); @@ -288,13 +289,15 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis @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); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + 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); + } } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 649c946..3817a03 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -28,7 +28,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/standard_definition" - android:buttonTint="@android:color/white" android:textColor="@android:color/white"/> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index de850c2..9d93cde 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,9 +8,9 @@ @color/colorAccent - diff --git a/hbrecorder/build.gradle b/hbrecorder/build.gradle index 84a05ab..b946f04 100644 --- a/hbrecorder/build.gradle +++ b/hbrecorder/build.gradle @@ -5,7 +5,7 @@ android { defaultConfig { - minSdkVersion 21 + minSdkVersion 17 targetSdkVersion 28 versionCode 1 versionName "1.0"