|
|
|
|
@@ -2,6 +2,7 @@ package com.stardust.scriptdroid.external.notification.record;
|
|
|
|
|
|
|
|
|
|
import android.app.PendingIntent;
|
|
|
|
|
import android.app.Service;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.os.IBinder;
|
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
|
@@ -11,6 +12,7 @@ import com.stardust.scriptdroid.App;
|
|
|
|
|
import com.stardust.scriptdroid.R;
|
|
|
|
|
import com.stardust.scriptdroid.record.AccessibilityRecorderDelegate;
|
|
|
|
|
import com.stardust.scriptdroid.service.AccessibilityWatchDogService;
|
|
|
|
|
import com.stardust.scriptdroid.service.VolumeChangeListenService;
|
|
|
|
|
import com.stardust.scriptdroid.ui.main.MainActivity;
|
|
|
|
|
|
|
|
|
|
import static com.stardust.scriptdroid.external.notification.record.ActionRecordSwitchView.PAUSED;
|
|
|
|
|
@@ -21,10 +23,10 @@ import static com.stardust.scriptdroid.external.notification.record.ActionRecord
|
|
|
|
|
* Created by Stardust on 2017/2/15.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class ActionRecordNotificationHandleService extends Service {
|
|
|
|
|
public class ActionRecordSwitchHandleService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String EXTRA_INTENT_VALID = "ActionRecordNotificationHandleService.intentValid";
|
|
|
|
|
private static final String EXTRA_INTENT_VALID = "ActionRecordSwitchHandleService.intentValid";
|
|
|
|
|
private static final String EXTRA_ACTION = "action";
|
|
|
|
|
private static final int ACTION_STOP = 17771;
|
|
|
|
|
private static final int ACTION_START_OR_PAUSE = 17772;
|
|
|
|
|
@@ -32,21 +34,21 @@ public class ActionRecordNotificationHandleService extends Service {
|
|
|
|
|
private static final int ACTION_REDO = 17774;
|
|
|
|
|
|
|
|
|
|
public static PendingIntent getStartOrPauseIntent() {
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordNotificationHandleService.class)
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordSwitchHandleService.class)
|
|
|
|
|
.putExtra(EXTRA_INTENT_VALID, true)
|
|
|
|
|
.putExtra(EXTRA_ACTION, ACTION_START_OR_PAUSE);
|
|
|
|
|
return PendingIntent.getService(App.getApp(), ACTION_START_OR_PAUSE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PendingIntent getStopIntent() {
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordNotificationHandleService.class)
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordSwitchHandleService.class)
|
|
|
|
|
.putExtra(EXTRA_INTENT_VALID, true)
|
|
|
|
|
.putExtra(EXTRA_ACTION, ACTION_STOP);
|
|
|
|
|
return PendingIntent.getService(App.getApp(), ACTION_STOP, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PendingIntent getDeleteIntent() {
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordNotificationHandleService.class)
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordSwitchHandleService.class)
|
|
|
|
|
.putExtra(EXTRA_INTENT_VALID, true)
|
|
|
|
|
.putExtra(EXTRA_ACTION, ACTION_DELETE);
|
|
|
|
|
return PendingIntent.getService(App.getApp(), ACTION_DELETE, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
@@ -54,7 +56,7 @@ public class ActionRecordNotificationHandleService extends Service {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static PendingIntent getRedoIntent() {
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordNotificationHandleService.class)
|
|
|
|
|
Intent intent = new Intent(App.getApp(), ActionRecordSwitchHandleService.class)
|
|
|
|
|
.putExtra(EXTRA_INTENT_VALID, true)
|
|
|
|
|
.putExtra(EXTRA_ACTION, ACTION_REDO);
|
|
|
|
|
return PendingIntent.getService(App.getApp(), ACTION_REDO, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
|
|
|
@@ -74,19 +76,20 @@ public class ActionRecordNotificationHandleService extends Service {
|
|
|
|
|
private void performAction(int action) {
|
|
|
|
|
switch (action) {
|
|
|
|
|
case ACTION_STOP:
|
|
|
|
|
stopRecord();
|
|
|
|
|
stopRecord(this);
|
|
|
|
|
collapseNotificationBar();
|
|
|
|
|
break;
|
|
|
|
|
case ACTION_START_OR_PAUSE:
|
|
|
|
|
startOrPauseRecord();
|
|
|
|
|
startOrPauseRecord(this);
|
|
|
|
|
collapseNotificationBar();
|
|
|
|
|
break;
|
|
|
|
|
case ACTION_DELETE:
|
|
|
|
|
ActionRecordSwitchNotification.cancelNotification();
|
|
|
|
|
stopRecordIfNeeded();
|
|
|
|
|
VolumeChangeListenService.stopServiceIfNeeded();
|
|
|
|
|
break;
|
|
|
|
|
case ACTION_REDO:
|
|
|
|
|
redoRecord();
|
|
|
|
|
redoRecord(this);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -98,41 +101,53 @@ public class ActionRecordNotificationHandleService extends Service {
|
|
|
|
|
|
|
|
|
|
private void stopRecordIfNeeded() {
|
|
|
|
|
if (AccessibilityRecorderDelegate.getInstance().getState() != STOPPED) {
|
|
|
|
|
stopRecord();
|
|
|
|
|
stopRecord(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startOrPauseRecord() {
|
|
|
|
|
private static void startOrPauseRecord(Context context) {
|
|
|
|
|
int state = AccessibilityRecorderDelegate.getInstance().getState();
|
|
|
|
|
if (state == PAUSED) {
|
|
|
|
|
AccessibilityRecorderDelegate.getInstance().resumeRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(RECORDING);
|
|
|
|
|
resumeRecord(context);
|
|
|
|
|
} else if (state == RECORDING) {
|
|
|
|
|
AccessibilityRecorderDelegate.getInstance().pauseRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(PAUSED);
|
|
|
|
|
pauseRecord(context);
|
|
|
|
|
} else {
|
|
|
|
|
//state == STOPPED
|
|
|
|
|
if (AccessibilityWatchDogService.getInstance() == null) {
|
|
|
|
|
Toast.makeText(this, R.string.text_need_enable_accessibility_service, Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AccessibilityRecorderDelegate.getInstance().startRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(RECORDING);
|
|
|
|
|
Toast.makeText(this, R.string.text_start_record, Toast.LENGTH_SHORT).show();
|
|
|
|
|
startRecord(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void stopRecord() {
|
|
|
|
|
public static void startRecord(Context context) {
|
|
|
|
|
if (AccessibilityWatchDogService.getInstance() == null) {
|
|
|
|
|
Toast.makeText(context, R.string.text_need_enable_accessibility_service, Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
AccessibilityRecorderDelegate.getInstance().startRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(RECORDING);
|
|
|
|
|
Toast.makeText(context, R.string.text_start_record, Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void pauseRecord(Context context) {
|
|
|
|
|
AccessibilityRecorderDelegate.getInstance().pauseRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(PAUSED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void resumeRecord(Context context) {
|
|
|
|
|
AccessibilityRecorderDelegate.getInstance().resumeRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(RECORDING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void stopRecord(Context context) {
|
|
|
|
|
if (AccessibilityRecorderDelegate.getInstance().getState() != STOPPED) {
|
|
|
|
|
String script = AccessibilityRecorderDelegate.getInstance().stopRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(STOPPED);
|
|
|
|
|
MainActivity.onActionRecordStopped(this, script);
|
|
|
|
|
MainActivity.onActionRecordStopped(context, script);
|
|
|
|
|
} else {
|
|
|
|
|
Toast.makeText(App.getApp(), R.string.text_not_recording, Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void redoRecord() {
|
|
|
|
|
private static void redoRecord(Context context) {
|
|
|
|
|
if (AccessibilityRecorderDelegate.getInstance().getState() != STOPPED) {
|
|
|
|
|
AccessibilityRecorderDelegate.getInstance().stopRecord();
|
|
|
|
|
ActionRecordSwitchView.getInstance().setState(STOPPED);
|