Skip to content

Commit

Permalink
Release v3.1.10
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Feb 21, 2024
1 parent ae4842e commit b2823a8
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ body:
description: Specify the version of AdvancedSharpAdbClient you're using.
options:
- "Latest Source"
- "3.1.10"
- "3.0.9"
- "2.5.8"
- "2.5.7"
Expand Down Expand Up @@ -103,6 +104,7 @@ body:
- "MonoDevelop 5.x"
- "MonoDevelop 4.x"
- "MonoDevelop 3.x"
- "Rider 2024"
- "Rider 2023"
- "Rider 2022"
- "Rider 2021"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
</Choose>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.0" PrivateAssets="all">
<PackageReference Include="coverlet.msbuild" Version="6.0.1" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" PrivateAssets="all">
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
Expand Down
26 changes: 26 additions & 0 deletions AdvancedSharpAdbClient/DeviceCommands/DeviceClient.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,32 @@ public async Task SendTextAsync(string text, CancellationToken cancellationToken
}
}

/// <summary>
/// Asynchronously clear the input text. The input should be in focus. Use <see cref="Element.ClearInputAsync(int, CancellationToken)"/> if the element isn't focused.
/// </summary>
/// <param name="charCount">The length of text to clear.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public async Task ClearInputAsync(int charCount, CancellationToken cancellationToken = default)
{
await SendKeyEventAsync("KEYCODE_MOVE_END", cancellationToken).ConfigureAwait(false);
await SendKeyEventAsync(StringExtensions.Join(" ", Enumerable.Repeat<string?>("KEYCODE_DEL", charCount)), cancellationToken).ConfigureAwait(false);
}

/// <summary>
/// Asynchronously click BACK button.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public Task ClickBackButtonAsync(CancellationToken cancellationToken = default) => SendKeyEventAsync("KEYCODE_BACK", cancellationToken);

/// <summary>
/// Asynchronously click HOME button.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public Task ClickHomeButtonAsync(CancellationToken cancellationToken = default) => SendKeyEventAsync("KEYCODE_HOME", cancellationToken);

/// <summary>
/// Start an Android application on device asynchronously.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions AdvancedSharpAdbClient/DeviceCommands/DeviceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,26 @@ public void SendText(string text)
}
}

/// <summary>
/// Clear the input text. The input should be in focus. Use <see cref="Element.ClearInput(int)"/> if the element isn't focused.
/// </summary>
/// <param name="charCount">The length of text to clear.</param>
public void ClearInput(int charCount)
{
SendKeyEvent("KEYCODE_MOVE_END");
SendKeyEvent(StringExtensions.Join(" ", Enumerable.Repeat<string?>("KEYCODE_DEL", charCount)));
}

/// <summary>
/// Click BACK button.
/// </summary>
public void ClickBackButton() => SendKeyEvent("KEYCODE_BACK");

/// <summary>
/// Click HOME button.
/// </summary>
public void ClickHomeButton() => SendKeyEvent("KEYCODE_HOME");

/// <summary>
/// Start an Android application on device.
/// </summary>
Expand Down
12 changes: 4 additions & 8 deletions AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,8 @@ public static Task SendTextAsync(this IAdbClient client, DeviceData device, stri
/// <param name="charCount">The length of text to clear.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public static async Task ClearInputAsync(this IAdbClient client, DeviceData device, int charCount, CancellationToken cancellationToken = default)
{
DeviceClient deviceClient = new(client, device);
await deviceClient.SendKeyEventAsync("KEYCODE_MOVE_END", cancellationToken).ConfigureAwait(false);
await deviceClient.SendKeyEventAsync(StringExtensions.Join(" ", Enumerable.Repeat<string?>("KEYCODE_DEL", charCount)), cancellationToken).ConfigureAwait(false);
}
public static Task ClearInputAsync(this IAdbClient client, DeviceData device, int charCount, CancellationToken cancellationToken = default) =>
new DeviceClient(client, device).ClearInputAsync(charCount, cancellationToken);

/// <summary>
/// Asynchronously click BACK button.
Expand All @@ -165,7 +161,7 @@ public static async Task ClearInputAsync(this IAdbClient client, DeviceData devi
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public static Task ClickBackButtonAsync(this IAdbClient client, DeviceData device, CancellationToken cancellationToken = default) =>
new DeviceClient(client, device).SendKeyEventAsync("KEYCODE_BACK", cancellationToken);
new DeviceClient(client, device).ClickBackButtonAsync(cancellationToken);

/// <summary>
/// Asynchronously click HOME button.
Expand All @@ -175,7 +171,7 @@ public static Task ClickBackButtonAsync(this IAdbClient client, DeviceData devic
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
public static Task ClickHomeButtonAsync(this IAdbClient client, DeviceData device, CancellationToken cancellationToken = default) =>
new DeviceClient(client, device).SendKeyEventAsync("KEYCODE_HOME", cancellationToken);
new DeviceClient(client, device).ClickHomeButtonAsync(cancellationToken);

/// <summary>
/// Asynchronously start an Android application on device.
Expand Down
12 changes: 4 additions & 8 deletions AdvancedSharpAdbClient/DeviceCommands/DeviceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,24 @@ public static void SendText(this IAdbClient client, DeviceData device, string te
/// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
/// <param name="device">The device on which to clear the input text.</param>
/// <param name="charCount">The length of text to clear.</param>
public static void ClearInput(this IAdbClient client, DeviceData device, int charCount)
{
DeviceClient deviceClient = new(client, device);
deviceClient.SendKeyEvent("KEYCODE_MOVE_END");
deviceClient.SendKeyEvent(StringExtensions.Join(" ", Enumerable.Repeat<string?>("KEYCODE_DEL", charCount)));
}
public static void ClearInput(this IAdbClient client, DeviceData device, int charCount)=>
new DeviceClient(client, device).ClearInput(charCount);

/// <summary>
/// Click BACK button.
/// </summary>
/// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
/// <param name="device">The device on which to click BACK button.</param>
public static void ClickBackButton(this IAdbClient client, DeviceData device) =>
new DeviceClient(client, device).SendKeyEvent("KEYCODE_BACK");
new DeviceClient(client, device).ClickBackButton();

/// <summary>
/// Click HOME button.
/// </summary>
/// <param name="client">An instance of a class that implements the <see cref="IAdbClient"/> interface.</param>
/// <param name="device">The device on which to click HOME button.</param>
public static void ClickHomeButton(this IAdbClient client, DeviceData device) =>
new DeviceClient(client, device).SendKeyEvent("KEYCODE_HOME");
new DeviceClient(client, device).ClickHomeButton();

/// <summary>
/// Start an Android application on device.
Expand Down
8 changes: 4 additions & 4 deletions AdvancedSharpAdbClient/DeviceCommands/Models/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ public void SendText(string text)
}

/// <summary>
/// Clear the input text. Use <see cref="DeviceExtensions.ClearInput(IAdbClient, DeviceData, int)"/> if the element is focused.
/// Clear the input text. Use <see cref="DeviceClient.ClearInput(int)"/> if the element is focused.
/// </summary>
[MemberNotNull(nameof(Text))]
public void ClearInput() => ClearInput(Text!.Length);

/// <summary>
/// Clear the input text. Use <see cref="DeviceExtensions.ClearInput(IAdbClient, DeviceData, int)"/> if the element is focused.
/// Clear the input text. Use <see cref="DeviceClient.ClearInput(int)"/> if the element is focused.
/// </summary>
/// <param name="charCount">The length of text to clear.</param>
public void ClearInput(int charCount)
Expand Down Expand Up @@ -331,7 +331,7 @@ public async Task SendTextAsync(string text, CancellationToken cancellationToken
}

/// <summary>
/// Asynchronously clear the input text. Use <see cref="DeviceExtensions.ClearInputAsync(IAdbClient, DeviceData, int, CancellationToken)"/> if the element is focused.
/// Asynchronously clear the input text. Use <see cref="DeviceClient.ClearInputAsync(int, CancellationToken)"/> if the element is focused.
/// </summary>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
/// <returns>A <see cref="Task"/> which represents the asynchronous operation.</returns>
Expand All @@ -340,7 +340,7 @@ public Task ClearInputAsync(CancellationToken cancellationToken = default) =>
ClearInputAsync(Text!.Length, cancellationToken);

/// <summary>
/// Asynchronously clear the input text. Use <see cref="DeviceExtensions.ClearInputAsync(IAdbClient, DeviceData, int, CancellationToken)"/> if the element is focused.
/// Asynchronously clear the input text. Use <see cref="DeviceClient.ClearInputAsync(int, CancellationToken)"/> if the element is focused.
/// </summary>
/// <param name="charCount">The length of text to clear.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> which can be used to cancel the asynchronous operation.</param>
Expand Down
8 changes: 7 additions & 1 deletion AdvancedSharpAdbClient/Models/InstallProgress.EventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

namespace AdvancedSharpAdbClient.Models
Expand Down Expand Up @@ -87,7 +88,12 @@ public override string ToString()
split.Add(c);
}

StringBuilder builder = new(new string(split.ToArray()));
StringBuilder builder =
#if NET
new StringBuilder().Append(CollectionsMarshal.AsSpan(split));
#else
new(new string(split.ToArray()));
#endif

if (PackageRequired > 0)
{
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ The text field should be in focus
static void Main(string[] args)
{
...
adbClient.ClearInput(deviceData, 25); // The second argument is to specify the maximum number of characters to be erased
deviceClient.ClearInput(25); // The argument is to specify the maximum number of characters to be erased
...
}
```
Expand Down Expand Up @@ -294,9 +294,9 @@ catch (Exception ex)
static void Main(string[] args)
{
...
adbClient.ClickBackButton(device); // Click Back button
deviceClient.ClickBackButton(); // Click Back button
...
adbClient.ClickHomeButton(device); // Click Home button
deviceClient.ClickHomeButton(); // Click Home button
...
}
```
Expand Down

0 comments on commit b2823a8

Please sign in to comment.