Skip to content

Commit

Permalink
partial fix for #17
Browse files Browse the repository at this point in the history
  • Loading branch information
lochidev committed Jun 2, 2024
1 parent f3db2e0 commit 7cb66fe
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 151 deletions.
2 changes: 1 addition & 1 deletion MauiApp1/Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="19" android:versionName="6.8">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="20" android:versionName="6.8">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:supportsRtl="true"></application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down
86 changes: 23 additions & 63 deletions MauiApp1/Platforms/Android/Services/MyAccessibilityService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class MyAccessibilityService : AccessibilityService
{
private Dictionary<string, Match> dict;
private List<Var> globals;
//private LinearLayout inputLayout;
//private IWindowManager windowManager;
private static readonly char[] separator = [' ', '\n', ','];
//private static readonly char[] wordSeparator = [' ', /*'\n',*/ ','];

Expand Down Expand Up @@ -83,6 +81,17 @@ public override async void OnAccessibilityEvent(AccessibilityEvent e)
if (Text != null)
{
string og = Text[0].ToString();
const string cursorStr = "$|$";
int startIndex = og.IndexOf(cursorStr);
if(startIndex != -1)
{
Bundle cursorArgs = null;
cursorArgs = new Bundle();
cursorArgs.PutInt(AccessibilityNodeInfo.ActionArgumentSelectionStartInt, startIndex);
cursorArgs.PutInt(AccessibilityNodeInfo.ActionArgumentSelectionEndInt, startIndex + cursorStr.Length);

e.Source.PerformAction(Android.Views.Accessibility.Action.SetSelection, cursorArgs);
}
//quick brown fox
var arr = og.Split(separator, StringSplitOptions.RemoveEmptyEntries);
bool send = false;
Expand All @@ -95,7 +104,7 @@ public override async void OnAccessibilityEvent(AccessibilityEvent e)
// echo, random, clipboard and date only supported
string replace = match.Replace;
if (match.Word)
{
{
int index = 0;
for (int i = 0; i < wNum; i++)
{
Expand Down Expand Up @@ -143,29 +152,28 @@ public override async void OnAccessibilityEvent(AccessibilityEvent e)
}
if (send)
{
const string cursorStr = "$|$";
int startIndex = og.IndexOf(cursorStr);
Bundle args = new();
args.PutCharSequence(AccessibilityNodeInfo.ActionArgumentSetTextCharsequence, og);
Bundle cursorArgs = null;
if (startIndex != -1)
{
//og = og.Replace(cursorStr, " ");
cursorArgs = new Bundle();
cursorArgs.PutInt(AccessibilityNodeInfo.ActionArgumentSelectionStartInt, startIndex);
cursorArgs.PutInt(AccessibilityNodeInfo.ActionArgumentSelectionEndInt, startIndex + cursorStr.Length);
}
e.Source.PerformAction(Android.Views.Accessibility.Action.SetText, args);
if (cursorArgs is not null)

if (e.Source.Refresh())
{

//og has been modified with our new expansion
Bundle cursorArgs = null;
cursorArgs = new Bundle();
cursorArgs.PutInt(AccessibilityNodeInfo.ActionArgumentSelectionStartInt, og.Length);
cursorArgs.PutInt(AccessibilityNodeInfo.ActionArgumentSelectionEndInt, og.Length);

e.Source.PerformAction(Android.Views.Accessibility.Action.SetSelection, cursorArgs);

}
}
}
}

}
catch (Exception)
catch (Exception ex)
{

}
Expand Down Expand Up @@ -220,54 +228,6 @@ protected override void OnServiceConnected()
{
base.OnServiceConnected();
WeakReferenceMessenger.Default.Send(new AcServiceMessage(("_", null)));
// Create the input layout
//inputLayout = new LinearLayout(this) { Orientation = Orientation.Vertical }; // Use native LinearLayout
//inputLayout.SetBackgroundColor(Android.Graphics.Color.White); // Customize as needed

//// Create the Entry for input
//// Create the EditText for input
//EditText inputEditText = new EditText(this) { Hint = "Type here..." }; // Use EditText
//inputEditText.RequestFocus(); // Use RequestFocus instead of Focus
//inputEditText.TextChanged += (sender, e) =>
//{
// // Handle text changes, e.g., send text to other apps
//};

//// Add the EditText to the LinearLayout using AddView
//inputLayout.AddView(inputEditText);

//// Add the Entry to the LinearLayout using AddView

//// Request the overlay permission (if not already granted)
//if (Android.Provider.Settings.CanDrawOverlays(this))
//{
// //Intent intent = new Intent(Android.Provider.Settings.ActionManageOverlayPermission,
// // Android.Net.Uri.Parse("package:" + PackageName));
// //StartActivityForResult(intent, REQUEST_OVERLAY_PERMISSION);
//}
//else
//{
// ShowInputBox();
//}
}

//private void ShowInputBox()
//{
// windowManager = (IWindowManager)GetSystemService(WindowService);
// WindowManagerLayoutParams param = new WindowManagerLayoutParams(
// WindowManagerLayoutParams.WrapContent,
// WindowManagerLayoutParams.WrapContent,
// WindowManagerTypes.AccessibilityOverlay,
// WindowManagerFlags.NotFocusable,
// Android.Graphics.Format.Translucent);
// windowManager.AddView(inputLayout, param);
//}
//public override bool OnUnbind(Intent intent)
//{
// if (inputLayout != null)
// {
// windowManager.RemoveView(inputLayout);
// }
// return base.OnUnbind(intent);
//}
}
170 changes: 83 additions & 87 deletions MauiApp1/TextComparePro.csproj
Original file line number Diff line number Diff line change
@@ -1,96 +1,92 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFrameworks>net8.0-android34.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>MauiApp1</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<EnableDefaultCssItems>false</EnableDefaultCssItems>

<!-- Display name -->
<ApplicationTitle>Text Tools Pro</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.dingleinc.texttoolspro</ApplicationId>
<ApplicationIdGuid>A9E98E65-AE83-5428-9AB1-578DC0552CB8</ApplicationIdGuid>

<!-- Versions -->
<ApplicationDisplayVersion>6.8</ApplicationDisplayVersion>
<ApplicationVersion>19</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
<AndroidPackageFormat>aab</AndroidPackageFormat>
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
<AndroidPackageFormat>aab</AndroidPackageFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android34.0|AnyCPU'">
<AndroidPackageFormat>aab</AndroidPackageFormat>
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
<AndroidPackageFormat>aab</AndroidPackageFormat>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" BaseSize="512,512" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#D1F00F" BaseSize="512,512" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Remove="Platforms\Android\Resources\values\strings.xml" />
<None Remove="Platforms\Android\Resources\xml\accessibility_service.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PropertyGroup>
<TargetFrameworks>net8.0-android34.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>MauiApp1</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<EnableDefaultCssItems>false</EnableDefaultCssItems>

<!-- Display name -->
<ApplicationTitle>Text Tools Pro</ApplicationTitle>

<!-- App Identifier -->
<ApplicationId>com.dingleinc.texttoolspro</ApplicationId>
<ApplicationIdGuid>A9E98E65-AE83-5428-9AB1-578DC0552CB8</ApplicationIdGuid>

<!-- Versions -->
<ApplicationDisplayVersion>6.8</ApplicationDisplayVersion>
<ApplicationVersion>20</ApplicationVersion>

<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android|AnyCPU'">
<AndroidPackageFormat>aab</AndroidPackageFormat>
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android|AnyCPU'">
<AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
<AndroidPackageFormat>aab</AndroidPackageFormat>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android34.0|AnyCPU'">
<AndroidPackageFormat>apk</AndroidPackageFormat>
<AndroidCreatePackagePerAbi>True</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
<AndroidCreatePackagePerAbi>True</AndroidCreatePackagePerAbi>
<AndroidUseAapt2>True</AndroidUseAapt2>
<AndroidPackageFormat>apk</AndroidPackageFormat>
</PropertyGroup>

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" BaseSize="512,512" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#D1F00F" BaseSize="512,512" />

<!-- Images -->
<MauiImage Include="Resources\Images\*" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<None Remove="Platforms\Android\Resources\values\strings.xml" />
<None Remove="Platforms\Android\Resources\xml\accessibility_service.xml" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MudBlazor" Version="6.19.1" />
<PackageReference Include="YamlDotNet" Version="15.1.4" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.Maui" Version="7.0.1" />
<PackageReference Include="MudBlazor" Version="6.14.0" />
<PackageReference Include="YamlDotNet" Version="15.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.6" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.6" />
</ItemGroup>

<ItemGroup>
<Folder Include="Resources\Images\" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.Maui.Controls.Compatibility" Version="8.0.6" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\Images\" />
</ItemGroup>

</Project>

0 comments on commit 7cb66fe

Please sign in to comment.