Skip to content

Commit

Permalink
Get ALL the views on android
Browse files Browse the repository at this point in the history
Including dialogs
  • Loading branch information
Redth committed Oct 20, 2022
1 parent bb84eb5 commit 3f8acfb
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/Agent/Platforms/Android/AndroidApplication.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Java.Lang;
using Kotlin.Reflect;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -46,8 +49,30 @@ public override Task<string> GetProperty(string elementId, string propertyName)
}

public override Task<IEnumerable<IElement>> GetElements()
{
return Task.FromResult<IEnumerable<IElement>>(LifecycleListener.Activities.Select(a => a.GetElement(this, 1, -1)));
{
var results = new List<IElement>();

//foreach (var a in LifecycleListener.Activities)
//{
// var window = a.GetElement(this, 1, -1);

// results.Add(window);
//}

// get the list from WindowManagerGlobal.mViews
var wmgClass = Class.ForName("android.view.WindowManagerGlobal");
var wmgInstance = wmgClass.GetMethod("getInstance").Invoke(null);
var viewsField = wmgClass.GetDeclaredField("mViews");
viewsField.Accessible = true;

var views = viewsField.Get(wmgInstance).JavaCast<JavaList<View>>();

foreach (var view in views)
{
results.Add(view.GetElement(this, view.EnsureUniqueId(), 1, -1));
}

return Task.FromResult<IEnumerable<IElement>>(results);
}

public override Task<IEnumerable<IElement>> FindElements(Predicate<IElement> matcher)
Expand Down

0 comments on commit 3f8acfb

Please sign in to comment.