Merge branch 'audiorecorder-1.1.22'
This commit is contained in:
commit
d585f37763
5 changed files with 197 additions and 92 deletions
|
|
@ -8,8 +8,8 @@ android {
|
|||
applicationId "com.github.axet.audiorecorder"
|
||||
minSdkVersion 16
|
||||
targetSdkVersion 23
|
||||
versionCode 42
|
||||
versionName "1.1.21"
|
||||
versionCode 43
|
||||
versionName "1.1.22"
|
||||
}
|
||||
signingConfigs {
|
||||
release {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<service android:name=".services.RecordingService" />
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:label="@string/app_name" />
|
||||
|
|
|
|||
|
|
@ -75,6 +75,13 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
|
|||
ListView list;
|
||||
Handler handler;
|
||||
|
||||
public static void startActivity(Context context) {
|
||||
Intent i = new Intent(context, MainActivity.class);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
static class SortFiles implements Comparator<File> {
|
||||
@Override
|
||||
public int compare(File file, File file2) {
|
||||
|
|
@ -444,8 +451,7 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
|
|||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(MainActivity.this, RecordingActivity.class);
|
||||
startActivity(intent);
|
||||
RecordingActivity.startActivity(MainActivity.this, false);
|
||||
// Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
// .setAction("Action", null).show();
|
||||
}
|
||||
|
|
@ -465,9 +471,7 @@ public class MainActivity extends AppCompatActivity implements AbsListView.OnScr
|
|||
|
||||
void checkPending() {
|
||||
if (storage.recordingPending()) {
|
||||
Intent intent = new Intent(this, RecordingActivity.class);
|
||||
intent.setAction(RecordingActivity.START_PAUSE);
|
||||
startActivity(intent);
|
||||
RecordingActivity.startActivity(MainActivity.this, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ import com.github.axet.audiorecorder.encoders.FileEncoder;
|
|||
import com.github.axet.audiorecorder.encoders.Format3GP;
|
||||
import com.github.axet.audiorecorder.encoders.FormatM4A;
|
||||
import com.github.axet.audiorecorder.encoders.FormatWAV;
|
||||
import com.github.axet.audiorecorder.services.RecordingService;
|
||||
import com.github.axet.audiorecorder.widgets.PitchView;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -58,16 +59,10 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
public static int MAXIMUM_ALTITUDE = 5000;
|
||||
|
||||
public static final String TAG = RecordingActivity.class.getSimpleName();
|
||||
public static final String START_RECORDING = RecordingActivity.class.getCanonicalName() + ".START_RECORDING";
|
||||
public static final String CLOSE_ACTIVITY = RecordingActivity.class.getCanonicalName() + ".CLOSE_ACTIVITY";
|
||||
public static final int NOTIFICATION_RECORDING_ICON = 0;
|
||||
public static String SHOW_ACTIVITY = RecordingActivity.class.getCanonicalName() + ".SHOW_ACTIVITY";
|
||||
public static String PAUSE = RecordingActivity.class.getCanonicalName() + ".PAUSE";
|
||||
public static String START_PAUSE = RecordingActivity.class.getCanonicalName() + ".START_PAUSE";
|
||||
|
||||
public static final String PHONE_STATE = "android.intent.action.PHONE_STATE";
|
||||
|
||||
RecordingReceiver receiver;
|
||||
PhoneStateChangeListener pscl = new PhoneStateChangeListener();
|
||||
Handler handle = new Handler();
|
||||
FileEncoder encoder;
|
||||
|
|
@ -104,24 +99,6 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
Storage storage;
|
||||
Sound sound;
|
||||
|
||||
public class RecordingReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
|
||||
// showRecordingActivity();
|
||||
}
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
// do nothing. do not annoy user. he will see alarm screen on next screen on event.
|
||||
}
|
||||
if (intent.getAction().equals(SHOW_ACTIVITY)) {
|
||||
showRecordingActivity();
|
||||
}
|
||||
if (intent.getAction().equals(PAUSE)) {
|
||||
pauseButton();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PhoneStateChangeListener extends PhoneStateListener {
|
||||
public boolean wasRinging;
|
||||
public boolean pausedByCall;
|
||||
|
|
@ -150,6 +127,15 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public static void startActivity(Context context, boolean pause) {
|
||||
Intent i = new Intent(context, RecordingActivity.class);
|
||||
if (pause)
|
||||
i.setAction(RecordingActivity.START_PAUSE);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
context.startActivity(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -175,14 +161,6 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
|
||||
title.setText(targetFile.getName());
|
||||
|
||||
receiver = new RecordingReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
filter.addAction(SHOW_ACTIVITY);
|
||||
filter.addAction(PAUSE);
|
||||
registerReceiver(receiver, filter);
|
||||
|
||||
SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
if (shared.getBoolean(MainApplication.PREFERENCE_CALL, false)) {
|
||||
|
|
@ -252,6 +230,17 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
|
||||
String a = intent.getAction();
|
||||
|
||||
if (a != null && a.equals(START_PAUSE)) {
|
||||
pauseButton();
|
||||
}
|
||||
}
|
||||
|
||||
void loadSamples() {
|
||||
if (!storage.getTempRecording().exists()) {
|
||||
updateSamples(0);
|
||||
|
|
@ -288,17 +277,6 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
return "goldfish".equals(Build.HARDWARE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
}
|
||||
|
||||
public void showRecordingActivity() {
|
||||
Intent intent = new Intent(this, RecordingActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
void pauseButton() {
|
||||
if (thread != null) {
|
||||
stopRecording("pause");
|
||||
|
|
@ -324,6 +302,8 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
}
|
||||
|
||||
RecordingService.startService(this, targetFile.getName(), thread != null);
|
||||
|
||||
if (thread != null)
|
||||
pitch.record();
|
||||
}
|
||||
|
|
@ -343,7 +323,7 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
|
||||
stopRecording();
|
||||
|
||||
showNotificationAlarm(true);
|
||||
RecordingService.startService(this, targetFile.getName(), thread != null);
|
||||
|
||||
pitch.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
|
|
@ -521,18 +501,13 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
|
||||
stopRecording();
|
||||
|
||||
if (receiver != null) {
|
||||
unregisterReceiver(receiver);
|
||||
receiver = null;
|
||||
}
|
||||
RecordingService.stopService(this);
|
||||
|
||||
if (pscl != null) {
|
||||
TelephonyManager tm = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
tm.listen(pscl, PhoneStateListener.LISTEN_NONE);
|
||||
pscl = null;
|
||||
}
|
||||
|
||||
showNotificationAlarm(false);
|
||||
}
|
||||
|
||||
void startRecording() {
|
||||
|
|
@ -671,7 +646,7 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}, "RecordingThread");
|
||||
thread.start();
|
||||
|
||||
showNotificationAlarm(true);
|
||||
RecordingService.startService(this, targetFile.getName(), thread != null);
|
||||
}
|
||||
|
||||
// calcuale buffer length dynamically, this way we can reduce thread cycles when activity in background
|
||||
|
|
@ -706,40 +681,6 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
return pa;
|
||||
}
|
||||
|
||||
// alarm dismiss button
|
||||
public void showNotificationAlarm(boolean show) {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
|
||||
if (!show) {
|
||||
notificationManager.cancel(NOTIFICATION_RECORDING_ICON);
|
||||
} else {
|
||||
PendingIntent main = PendingIntent.getBroadcast(this, 0,
|
||||
new Intent(SHOW_ACTIVITY),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
PendingIntent pe = PendingIntent.getBroadcast(this, 0,
|
||||
new Intent(PAUSE),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
RemoteViews view = new RemoteViews(getPackageName(), R.layout.notifictaion_recording);
|
||||
view.setOnClickPendingIntent(R.id.status_bar_latest_event_content, main);
|
||||
view.setTextViewText(R.id.notification_text, ".../" + targetFile.getName());
|
||||
view.setOnClickPendingIntent(R.id.notification_pause, pe);
|
||||
view.setImageViewResource(R.id.notification_pause, thread == null ? R.drawable.play : R.drawable.pause);
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
.setOngoing(true)
|
||||
.setContentTitle("Recording")
|
||||
.setSmallIcon(R.drawable.ic_mic_24dp)
|
||||
.setContent(view);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 21)
|
||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
|
||||
|
||||
notificationManager.notify(NOTIFICATION_RECORDING_ICON, builder.build());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
|
@ -841,4 +782,10 @@ public class RecordingActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
MainActivity.startActivity(this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,153 @@
|
|||
package com.github.axet.audiorecorder.services;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.github.axet.audiorecorder.R;
|
||||
import com.github.axet.audiorecorder.activities.RecordingActivity;
|
||||
|
||||
/**
|
||||
* RecordingActivity more likly to be removed from memory when paused then service. Notification button
|
||||
* does not handle getActvity without unlocking screen. The only option is to have Service.
|
||||
* <p/>
|
||||
* So, lets have it.
|
||||
* <p/>
|
||||
* Maybe later this class will be converted for fully feature recording service with recording thread.
|
||||
*/
|
||||
public class RecordingService extends Service {
|
||||
public static final String TAG = RecordingService.class.getSimpleName();
|
||||
|
||||
public static final int NOTIFICATION_RECORDING_ICON = 0;
|
||||
|
||||
public static String SHOW_ACTIVITY = RecordingService.class.getCanonicalName() + ".SHOW_ACTIVITY";
|
||||
public static String PAUSE_BUTTON = RecordingService.class.getCanonicalName() + ".PAUSE_BUTTON";
|
||||
|
||||
RecordingReceiver receiver;
|
||||
|
||||
String targetFile;
|
||||
boolean recording;
|
||||
|
||||
public class RecordingReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {
|
||||
// showRecordingActivity();
|
||||
}
|
||||
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {
|
||||
// do nothing. do not annoy user. he will see alarm screen on next screen on event.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void startService(Context context, String targetFile, boolean recording) {
|
||||
context.startService(new Intent(context, RecordingService.class)
|
||||
.putExtra("targetFile", targetFile)
|
||||
.putExtra("recording", recording));
|
||||
}
|
||||
|
||||
public static void stopService(Context context) {
|
||||
context.stopService(new Intent(context, RecordingService.class));
|
||||
}
|
||||
|
||||
public RecordingService() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.d(TAG, "onCreate");
|
||||
|
||||
receiver = new RecordingReceiver();
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_SCREEN_ON);
|
||||
filter.addAction(Intent.ACTION_SCREEN_OFF);
|
||||
registerReceiver(receiver, filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.d(TAG, "onStartCommand");
|
||||
|
||||
String a = intent.getAction();
|
||||
|
||||
if (a == null) {
|
||||
targetFile = intent.getStringExtra("targetFile");
|
||||
recording = intent.getBooleanExtra("recording", false);
|
||||
showNotificationAlarm(true);
|
||||
} else if (a.equals(PAUSE_BUTTON)) {
|
||||
RecordingActivity.startActivity(this, true);
|
||||
} else if (a.equals(SHOW_ACTIVITY)) {
|
||||
RecordingActivity.startActivity(this, false);
|
||||
}
|
||||
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public class Binder extends android.os.Binder {
|
||||
public RecordingService getService() {
|
||||
return RecordingService.this;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Log.d(TAG, "onDestory");
|
||||
|
||||
showNotificationAlarm(false);
|
||||
|
||||
unregisterReceiver(receiver);
|
||||
}
|
||||
|
||||
// alarm dismiss button
|
||||
public void showNotificationAlarm(boolean show) {
|
||||
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
|
||||
if (!show) {
|
||||
notificationManager.cancel(NOTIFICATION_RECORDING_ICON);
|
||||
} else {
|
||||
PendingIntent main = PendingIntent.getService(this, 0,
|
||||
new Intent(this, RecordingService.class).setAction(SHOW_ACTIVITY),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
PendingIntent pe = PendingIntent.getService(this, 0,
|
||||
new Intent(this, RecordingService.class).setAction(PAUSE_BUTTON),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
RemoteViews view = new RemoteViews(getPackageName(), R.layout.notifictaion_recording);
|
||||
view.setOnClickPendingIntent(R.id.status_bar_latest_event_content, main);
|
||||
view.setTextViewText(R.id.notification_text, ".../" + targetFile);
|
||||
view.setOnClickPendingIntent(R.id.notification_pause, pe);
|
||||
view.setImageViewResource(R.id.notification_pause, !recording ? R.drawable.play : R.drawable.pause);
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
.setOngoing(true)
|
||||
.setContentTitle("Recording")
|
||||
.setSmallIcon(R.drawable.ic_mic_24dp)
|
||||
.setContent(view);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 21)
|
||||
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
|
||||
|
||||
notificationManager.notify(NOTIFICATION_RECORDING_ICON, builder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue