@ -6,6 +6,8 @@ import android.os.Build;
import android.util.Log ;
import android.widget.Toast ;
import androidx.annotation.RequiresApi ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.http.client.methods.HttpGet ;
@ -21,108 +23,115 @@ public class Action
public static final String intentPairSeparator = "intPairSplit" ;
public static final String vibrateSeparator = "," ;
public enum Action_Enum {
setWifi ,
setBluetooth ,
setUsbTethering ,
setWifiTethering ,
setBluetoothTethering ,
setDisplayRotation ,
turnWifiOn , turnWifiOff ,
turnBluetoothOn , turnBluetoothOff ,
triggerUrl ,
changeSoundProfile ,
turnUsbTetheringOn , turnUsbTetheringOff ,
turnWifiTetheringOn , turnWifiTetheringOff ,
enableScreenRotation , disableScreenRotation ,
startOtherActivity ,
waitBeforeNextAction ,
turnScreenOnOrOff ,
setAirplaneMode ,
setDataConnection ,
speakText ,
playMusic ,
controlMediaPlayback ,
setScreenBrightness ,
playSound ,
vibrate ,
createNotification ,
closeNotification ,
sendTextMessage ;
public String getFullName ( Context context )
{
switch ( this )
{
case setWifi :
return context . getResources ( ) . getString ( R . string . actionSetWifi ) ;
case setBluetooth :
return context . getResources ( ) . getString ( R . string . actionSetBluetooth ) ;
case setWifiTethering :
return context . getResources ( ) . getString ( R . string . actionSetWifiTethering ) ;
case setBluetoothTethering :
return context . getResources ( ) . getString ( R . string . actionSetBluetoothTethering ) ;
case setUsbTethering :
return context . getResources ( ) . getString ( R . string . actionSetUsbTethering ) ;
case setDisplayRotation :
return context . getResources ( ) . getString ( R . string . actionSetDisplayRotation ) ;
case turnWifiOn :
return context . getResources ( ) . getString ( R . string . actionTurnWifiOn ) ;
case turnWifiOff :
return context . getResources ( ) . getString ( R . string . actionTurnWifiOff ) ;
case turnBluetoothOn :
return context . getResources ( ) . getString ( R . string . actionTurnBluetoothOn ) ;
case turnBluetoothOff :
return context . getResources ( ) . getString ( R . string . actionTurnBluetoothOff ) ;
case triggerUrl :
return context . getResources ( ) . getString ( R . string . actionTriggerUrl ) ;
case changeSoundProfile :
return context . getResources ( ) . getString ( R . string . actionChangeSoundProfile ) ;
case turnUsbTetheringOn :
return context . getResources ( ) . getString ( R . string . actionTurnUsbTetheringOn ) ;
case turnUsbTetheringOff :
return context . getResources ( ) . getString ( R . string . actionTurnUsbTetheringOff ) ;
case turnWifiTetheringOn :
return context . getResources ( ) . getString ( R . string . actionTurnWifiTetheringOn ) ;
case turnWifiTetheringOff :
return context . getResources ( ) . getString ( R . string . actionTurnWifiTetheringOff ) ;
case enableScreenRotation :
return context . getResources ( ) . getString ( R . string . actionEnableScreenRotation ) ;
case disableScreenRotation :
return context . getResources ( ) . getString ( R . string . actionDisableScreenRotation ) ;
case startOtherActivity :
return context . getResources ( ) . getString ( R . string . startOtherActivity ) ;
case waitBeforeNextAction :
return context . getResources ( ) . getString ( R . string . waitBeforeNextAction ) ;
case turnScreenOnOrOff :
return context . getResources ( ) . getString ( R . string . turnScreenOnOrOff ) ;
case vibrate :
return context . getResources ( ) . getString ( R . string . vibrate ) ;
case setAirplaneMode :
return context . getResources ( ) . getString ( R . string . airplaneMode ) ;
case setDataConnection :
return context . getResources ( ) . getString ( R . string . actionDataConnection ) ;
case speakText :
return context . getResources ( ) . getString ( R . string . actionSpeakText ) ;
case playMusic :
return context . getResources ( ) . getString ( R . string . actionPlayMusic ) ;
case controlMediaPlayback :
return context . getResources ( ) . getString ( R . string . actionMediaControl ) ;
case playSound :
return context . getResources ( ) . getString ( R . string . playSound ) ;
case sendTextMessage :
return context . getResources ( ) . getString ( R . string . sendTextMessage ) ;
case setScreenBrightness :
return context . getResources ( ) . getString ( R . string . setScreenBrightness ) ;
case createNotification :
return context . getResources ( ) . getString ( R . string . createNotification ) ;
case closeNotification :
return context . getResources ( ) . getString ( R . string . closeNotifications ) ;
default :
return "Unknown" ;
}
}
} ;
public enum Action_Enum
{
setWifi ,
setBluetooth ,
setUsbTethering ,
setWifiTethering ,
setBluetoothTethering ,
setDisplayRotation ,
turnWifiOn , turnWifiOff ,
turnBluetoothOn , turnBluetoothOff ,
triggerUrl ,
changeSoundProfile ,
turnUsbTetheringOn , turnUsbTetheringOff ,
turnWifiTetheringOn , turnWifiTetheringOff ,
enableScreenRotation , disableScreenRotation ,
startOtherActivity ,
waitBeforeNextAction ,
turnScreenOnOrOff ,
setAirplaneMode ,
setDataConnection ,
speakText ,
playMusic ,
controlMediaPlayback ,
setScreenBrightness ,
playSound ,
vibrate ,
createNotification ,
closeNotification ,
sendBroadcast ,
runExecutable ,
sendTextMessage ;
public String getFullName ( Context context )
{
switch ( this )
{
case setWifi :
return context . getResources ( ) . getString ( R . string . actionSetWifi ) ;
case setBluetooth :
return context . getResources ( ) . getString ( R . string . actionSetBluetooth ) ;
case setWifiTethering :
return context . getResources ( ) . getString ( R . string . actionSetWifiTethering ) ;
case setBluetoothTethering :
return context . getResources ( ) . getString ( R . string . actionSetBluetoothTethering ) ;
case setUsbTethering :
return context . getResources ( ) . getString ( R . string . actionSetUsbTethering ) ;
case setDisplayRotation :
return context . getResources ( ) . getString ( R . string . actionSetDisplayRotation ) ;
case turnWifiOn :
return context . getResources ( ) . getString ( R . string . actionTurnWifiOn ) ;
case turnWifiOff :
return context . getResources ( ) . getString ( R . string . actionTurnWifiOff ) ;
case turnBluetoothOn :
return context . getResources ( ) . getString ( R . string . actionTurnBluetoothOn ) ;
case turnBluetoothOff :
return context . getResources ( ) . getString ( R . string . actionTurnBluetoothOff ) ;
case triggerUrl :
return context . getResources ( ) . getString ( R . string . actionTriggerUrl ) ;
case changeSoundProfile :
return context . getResources ( ) . getString ( R . string . actionChangeSoundProfile ) ;
case turnUsbTetheringOn :
return context . getResources ( ) . getString ( R . string . actionTurnUsbTetheringOn ) ;
case turnUsbTetheringOff :
return context . getResources ( ) . getString ( R . string . actionTurnUsbTetheringOff ) ;
case turnWifiTetheringOn :
return context . getResources ( ) . getString ( R . string . actionTurnWifiTetheringOn ) ;
case turnWifiTetheringOff :
return context . getResources ( ) . getString ( R . string . actionTurnWifiTetheringOff ) ;
case enableScreenRotation :
return context . getResources ( ) . getString ( R . string . actionEnableScreenRotation ) ;
case disableScreenRotation :
return context . getResources ( ) . getString ( R . string . actionDisableScreenRotation ) ;
case startOtherActivity :
return context . getResources ( ) . getString ( R . string . startOtherActivity ) ;
case waitBeforeNextAction :
return context . getResources ( ) . getString ( R . string . waitBeforeNextAction ) ;
case turnScreenOnOrOff :
return context . getResources ( ) . getString ( R . string . turnScreenOnOrOff ) ;
case vibrate :
return context . getResources ( ) . getString ( R . string . vibrate ) ;
case setAirplaneMode :
return context . getResources ( ) . getString ( R . string . airplaneMode ) ;
case setDataConnection :
return context . getResources ( ) . getString ( R . string . actionDataConnection ) ;
case speakText :
return context . getResources ( ) . getString ( R . string . actionSpeakText ) ;
case playMusic :
return context . getResources ( ) . getString ( R . string . actionPlayMusic ) ;
case controlMediaPlayback :
return context . getResources ( ) . getString ( R . string . actionMediaControl ) ;
case playSound :
return context . getResources ( ) . getString ( R . string . playSound ) ;
case sendTextMessage :
return context . getResources ( ) . getString ( R . string . sendTextMessage ) ;
case setScreenBrightness :
return context . getResources ( ) . getString ( R . string . setScreenBrightness ) ;
case createNotification :
return context . getResources ( ) . getString ( R . string . createNotification ) ;
case closeNotification :
return context . getResources ( ) . getString ( R . string . closeNotifications ) ;
case sendBroadcast :
return context . getResources ( ) . getString ( R . string . sendBroadcast ) ;
case runExecutable :
return context . getResources ( ) . getString ( R . string . runExecutable ) ;
default :
return "Unknown" ;
}
}
} ;
private Action_Enum action ;
private boolean parameter1 = false ;
@ -258,6 +267,12 @@ public class Action
case closeNotification :
returnString . append ( Miscellaneous . getAnyContext ( ) . getResources ( ) . getString ( R . string . closeNotifications ) ) ;
break ;
case sendBroadcast :
returnString . append ( Miscellaneous . getAnyContext ( ) . getResources ( ) . getString ( R . string . sendBroadcast ) ) ;
break ;
case runExecutable :
returnString . append ( Miscellaneous . getAnyContext ( ) . getResources ( ) . getString ( R . string . runExecutable ) ) ;
break ;
default :
returnString . append ( action . toString ( ) ) ;
}
@ -315,7 +330,15 @@ public class Action
if ( parts . length > 4 & & ! StringUtils . isBlank ( parts [ 4 ] ) )
returnString . append ( ", " + Miscellaneous . getAnyContext ( ) . getResources ( ) . getString ( R . string . ifString ) + " " + Miscellaneous . getAnyContext ( ) . getResources ( ) . getString ( R . string . text ) + " " + Trigger . getMatchString ( parts [ 3 ] ) + " " + parts [ 4 ] ) ;
}
else if ( this . getAction ( ) . equals ( Action_Enum . setWifi ) )
{
if ( ! StringUtils . isEmpty ( this . parameter2 ) )
{
boolean useRoot = Boolean . parseBoolean ( this . parameter2 ) ;
if ( useRoot )
returnString . append ( " " + Miscellaneous . getAnyContext ( ) . getResources ( ) . getString ( R . string . usingRoot ) ) ;
}
}
else if ( this . getAction ( ) . equals ( Action_Enum . controlMediaPlayback ) )
{
@ -430,7 +453,7 @@ public class Action
return ( String [ ] ) actionTypesList . toArray ( new String [ actionTypesList . size ( ) ] ) ;
}
public void run ( Context context , boolean toggleActionIfPossible )
{
try
@ -533,6 +556,16 @@ public class Action
else
Miscellaneous . logEvent ( "w" , "Close notification" , "Close notification was requested, but OS version is too low: " + String . valueOf ( Build . VERSION . SDK_INT ) , 2 ) ;
break ;
case sendBroadcast :
Actions . sendBroadcast ( context , this . getParameter2 ( ) ) ;
break ;
case runExecutable :
String [ ] execParts = this . getParameter2 ( ) . split ( Action . actionParameter2Split ) ;
if ( execParts . length = = 1 )
Actions . runExecutable ( context , this . getParameter1 ( ) , execParts [ 0 ] , null ) ;
else if ( execParts . length = = 2 )
Actions . runExecutable ( context , this . getParameter1 ( ) , execParts [ 0 ] , execParts [ 1 ] ) ;
break ;
default :
Miscellaneous . logEvent ( "w" , "Action" , context . getResources ( ) . getString ( R . string . unknownActionSpecified ) , 3 ) ;
break ;
@ -636,7 +669,7 @@ public class Action
//Do something with result
//Toast.makeText(context, text, duration) result;
Miscellaneous . logEvent ( "i" , "HTTP RESULT" , result , 3 ) ;
Actions myAction = new Actions ( ) ;
Actions myAction = new Actions ( ) ;
myAction . useDownloadedWebpage ( result ) ;
}
}