Skip to content

Commit

Permalink
record timer
Browse files Browse the repository at this point in the history
fix sharing last recorded
new icons
  • Loading branch information
Shaji Khan committed Jun 11, 2024
1 parent fb899ef commit 8893b8a
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 17 deletions.
15 changes: 14 additions & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.acoustixaudio.axvoicerecorder"
minSdk 29
targetSdk 34
versionCode 3
versionName '1'
versionCode 4
versionName '1.1'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
Expand Down
Binary file modified app/release/app-release.aab
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class AudioEngine {
public static native boolean togglePlugin (int plugin, boolean state) ;
public static native boolean getActivePluginEnabled (int plugin);
public static native void bypass (boolean state) ;
public static native void pause (boolean state) ;

public static native void setExportFormat (int format);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.FileProvider;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
Expand Down Expand Up @@ -135,6 +136,11 @@ public class MainActivity extends AppCompatActivity {
private PurchasesUpdatedListener purchasesUpdatedListener;
private BillingClient billingClient;
private long elapsed;
private ToggleButton record;
private Runnable r;
private Handler handler;
private ToggleButton pause;
private long ctime;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -188,7 +194,7 @@ protected void onCreate(Bundle savedInstanceState) {
}

Log.d(TAG, String.format ("[dir]: %s", dir));
ToggleButton record = findViewById(R.id.record);
record = findViewById(R.id.record);
lastFilename = findViewById(R.id.last_filename);
ToggleButton lastPlayPause = findViewById(R.id.last_play);

Expand Down Expand Up @@ -263,18 +269,19 @@ public void onPlayerErrorChanged(@Nullable PlaybackException error) {
LinearLayout timer = findViewById(R.id.timer);
TextView clock = findViewById(R.id.clock);

android.os.Handler handler = new Handler();
Runnable r = new Runnable() {
handler = new Handler();
r = new Runnable() {
@Override
public void run() {
if (mainActivity.running) {
Duration d = Duration.ofMillis(System.currentTimeMillis() - elapsed) ;
if (mainActivity.running && ! pause.isChecked()) {
ctime = System.currentTimeMillis() ;
Duration d = Duration.ofMillis(ctime - elapsed) ;
long minutes = d.getSeconds()/60 ;
long seconds = d.getSeconds() ;
if (minutes > 0)
seconds = seconds - minutes * 60;

clock.setText(String.format("%d:%d", minutes, seconds));
clock.setText(String.format("%02d:%02d", minutes, seconds));
handler.postDelayed(this, 1000);
}
}
Expand All @@ -283,16 +290,17 @@ public void run() {
record.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d(TAG, "onCheckedChanged: " + isChecked);
buttonView.setCompoundDrawables(null, null, null, null);
if (isChecked) {
lastPlayPause.setChecked(false);
pause.setEnabled(true);

elapsed = System.currentTimeMillis();
timer.setVisibility(View.VISIBLE);
clock.setText("00:00");
handler.postDelayed(r, 1000);

buttonView.setCompoundDrawablesWithIntrinsicBounds(null,getResources().getDrawable(R.drawable.stop1),null,null);

SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy_HH.mm.ss");
Date date = new Date();
basename = formatter.format(date);
Expand All @@ -306,9 +314,8 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

AudioEngine.toggleRecording(true);
lastRecordedBox.setVisibility(View.GONE);
buttonView.setCompoundDrawablesWithIntrinsicBounds(null,getResources().getDrawable(R.drawable.stop1),null,null);
} else {
buttonView.setCompoundDrawablesWithIntrinsicBounds(null,getResources().getDrawable(R.drawable.record_1),null,null);

if (! preview.isChecked ())
stopEffect();

Expand All @@ -320,6 +327,10 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mediaPlayer.setMediaItem(mediaItem);
mediaPlayer.prepare();

buttonView.setCompoundDrawablesWithIntrinsicBounds(null,getResources().getDrawable(R.drawable.record_1),null,null);
pause.setEnabled(false);
if (pause.isChecked())
pause.setChecked(false);
Log.i(TAG, "onCheckedChanged: set media item " + filename);
}
}
Expand Down Expand Up @@ -364,6 +375,8 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
} else {
buttonView.setButtonDrawable(getResources().getDrawable(R.drawable.baseline_volume_up_24));
AudioEngine.setOutputVolume(0f);
if (! isRecordPermissionGranted())
return;

if (! record.isChecked()) {
stopEffect();
Expand All @@ -372,19 +385,24 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});

ToggleButton pause = findViewById(R.id.pause);
pause = findViewById(R.id.pause);
pause.setEnabled(false);
pause.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
buttonView.setCompoundDrawables(null, null, null, null);
if (isChecked) {
buttonView.setButtonDrawable(getResources().getDrawable(R.drawable.baseline_play_circle_24));
AudioEngine.bypass(true);
AudioEngine.pause(true);
AudioEngine.setInputVolume(0f);
} else {
buttonView.setButtonDrawable(getResources().getDrawable(R.drawable.baseline_pause_circle_outline_24));
AudioEngine.bypass(false);
AudioEngine.pause(false);
AudioEngine.setInputVolume(1f);
if (running) {
handler.postDelayed(r, 1000);
elapsed = System.currentTimeMillis() + elapsed - ctime;
}
}

}
Expand Down Expand Up @@ -1075,5 +1093,16 @@ public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
});
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
== PackageManager.PERMISSION_GRANTED) {
startEffect();
handler.postDelayed(r, 1000);
} else {
// record.setChecked(false);
}
}
}

0 comments on commit 8893b8a

Please sign in to comment.