forked from jens/Automation
Take screenshot action added
This commit is contained in:
@ -640,6 +640,9 @@ public class Action
|
||||
case copyToClipboard:
|
||||
Actions.copyToClipboard(context, Miscellaneous.replaceVariablesInText(this.getParameter2(), context));
|
||||
break;
|
||||
case takeScreenshot:
|
||||
Actions.takeScreenshot();
|
||||
break;
|
||||
default:
|
||||
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
||||
break;
|
||||
|
@ -2127,7 +2127,7 @@ public class ActivityManageRule extends Activity
|
||||
else if(types[i].toString().equals(Action_Enum.copyToClipboard.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.clipboard));
|
||||
else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.clipboard));
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.copier));
|
||||
else
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||
}
|
||||
|
@ -333,31 +333,33 @@ public class ActivityPermissions extends Activity
|
||||
{
|
||||
int accessibilityEnabled = 0;
|
||||
|
||||
final String service = mContext.getPackageName() + "/com.mytest.accessibility.MyAccessibilityService";
|
||||
final String service = mContext.getPackageName() + "/" + BuildConfig.APPLICATION_ID + ".MyAccessibilityService";
|
||||
|
||||
boolean accessibilityFound = false;
|
||||
try
|
||||
{
|
||||
accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
|
||||
Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
|
||||
// Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
|
||||
}
|
||||
catch (Settings.SettingNotFoundException e)
|
||||
{
|
||||
Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
|
||||
// Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
|
||||
}
|
||||
TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');
|
||||
|
||||
if (accessibilityEnabled == 1) {
|
||||
String settingValue = Settings.Secure.getString(mContext
|
||||
.getApplicationContext().getContentResolver(),
|
||||
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
|
||||
if (settingValue != null) {
|
||||
if (accessibilityEnabled == 1)
|
||||
{
|
||||
String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
|
||||
if (settingValue != null)
|
||||
{
|
||||
TextUtils.SimpleStringSplitter splitter = mStringColonSplitter;
|
||||
splitter.setString(settingValue);
|
||||
while (splitter.hasNext()) {
|
||||
String accessabilityService = splitter.next();
|
||||
while (splitter.hasNext())
|
||||
{
|
||||
String accessibilityService = splitter.next();
|
||||
|
||||
if (accessabilityService.equalsIgnoreCase(service)) {
|
||||
if (accessibilityService.equalsIgnoreCase(service))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1026,7 +1028,9 @@ public class ActivityPermissions extends Activity
|
||||
usingElements.add(getResources().getString(R.string.queryAllPackages));
|
||||
break;
|
||||
case Manifest.permission.BIND_ACCESSIBILITY_SERVICE:
|
||||
usingElements.add(getResources().getString(R.string.bindAccessibilityService));
|
||||
for(String ruleName : getRulesUsing(Action.Action_Enum.takeScreenshot))
|
||||
usingElements.add(String.format(getResources().getString(R.string.ruleXrequiresThis), ruleName));
|
||||
break;
|
||||
}
|
||||
|
||||
return usingElements;
|
||||
@ -1035,6 +1039,15 @@ public class ActivityPermissions extends Activity
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
/*
|
||||
All of the following permissions need to be "manually" activated by the user in some
|
||||
buried system menu.
|
||||
In my opinion by mistake the function will be called when the user has just landed
|
||||
on one of those screens, not when he exits it again. To compensate for that onResume()
|
||||
is overridden. This enables the permission screen to automatically close after all
|
||||
required permissions have been granted.
|
||||
*/
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
@ -1665,4 +1678,19 @@ public class ActivityPermissions extends Activity
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
|
||||
for(String p : getRequiredPermissions(false))
|
||||
{
|
||||
if(!havePermission(p, this))
|
||||
return;
|
||||
}
|
||||
|
||||
// have all
|
||||
setHaveAllPermissions();
|
||||
}
|
||||
}
|
@ -1,8 +1,14 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.accessibilityservice.AccessibilityService;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.Display;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
|
||||
public class MyAccessibilityService extends AccessibilityService
|
||||
{
|
||||
static MyAccessibilityService instance;
|
||||
@ -10,7 +16,9 @@ public class MyAccessibilityService extends AccessibilityService
|
||||
public static MyAccessibilityService getInstance()
|
||||
{
|
||||
if(instance == null)
|
||||
{
|
||||
instance = new MyAccessibilityService();
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
@ -26,4 +34,18 @@ public class MyAccessibilityService extends AccessibilityService
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
super.onCreate();
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceConnected()
|
||||
{
|
||||
super.onServiceConnected();
|
||||
Miscellaneous.logEvent("i", "Accessibility service", "Service started.", 4);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user