Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ static CallableWrapperType CreateType (TypeDefinition type, IMetadataResolver re
cwt.ExtendsType = GetJavaTypeName (type.BaseType, resolver);

// Implemented interfaces
foreach (var ifaceInfo in type.Interfaces) {
var iface = resolver.Resolve (ifaceInfo.InterfaceType);
if (iface is null)
var interfaces = type.Interfaces
.Select (iface => resolver.Resolve (iface.InterfaceType))
.Where (iface => iface is not null && CecilExtensions.GetTypeRegistrationAttributes (iface).Any ())
.ToList ();
var addedInterfaces = new HashSet<string> ();
foreach (var iface in interfaces) {
if (interfaces.Any (other => iface.FullName != other.FullName && iface.IsAssignableFrom (other, resolver)))
continue;

if (!CecilExtensions.GetTypeRegistrationAttributes (iface).Any ())
continue;

cwt.ImplementedInterfaces.Add (GetJavaTypeName (iface, resolver));
var javaTypeName = GetJavaTypeName (iface, resolver);
if (addedInterfaces.Add (javaTypeName))
cwt.ImplementedInterfaces.Add (javaTypeName);
}

// Application constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ public void monodroidClearReferences ()
Assert.AreEqual (expected, actual);
}

[Test]
public void GenerateOnlyMostDerivedInterfaces ()
{
var actual = Generate (typeof (OnTabSelectedListener));

Assert.That (actual, Does.Contain ("\t\tcom.xamarin.android.OnTabSelectedListener"));
Assert.That (actual, Does.Not.Contain ("\t\tcom.xamarin.android.BaseOnTabSelectedListener"));
}

static string Generate (Type type, string applicationJavaClass = null, string monoRuntimeInit = null, JavaPeerStyle style = JavaPeerStyle.XAJavaInterop1)
{
var reader_options = new CallableWrapperReaderOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ class AbstractClassInvoker : AbstractClass
{
}

[Register ("com/xamarin/android/BaseOnTabSelectedListener")]
interface IBaseOnTabSelectedListener : global::Android.Runtime.IJavaObject
{
}

[Register ("com/xamarin/android/OnTabSelectedListener")]
interface IOnTabSelectedListener : IBaseOnTabSelectedListener
{
}

class OnTabSelectedListener : Java.Lang.Object, IOnTabSelectedListener
{
}

[Activity (Name = "activity.Name")]
class ActivityName : Java.Lang.Object
{
Expand Down
51 changes: 51 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,57 @@ void Button_ViewTreeObserver_GlobalLayout (object sender, EventArgs e)
}, Path.Combine (Root, builder.ProjectDirectory, "startup-logcat.log"), 60), $"Output did not contain {expectedLogcatOutput}!");
}

[Test]
public void TabLayoutOnTabSelectedListener2_ShouldFire_OnActivityLaunch ()
{
const string expectedLogcatOutput = "OnTabSelected called!";

var proj = new XamarinAndroidApplicationProject {
PackageReferences = {
KnownPackages.XamarinGoogleAndroidMaterial,
},
};
proj.SetRuntime (AndroidRuntime.CoreCLR);
proj.SetRuntimeIdentifiers (new [] { DeviceAbi });
proj.SetDefaultTargetDevice ();
proj.AndroidResources.Add (new AndroidItem.AndroidResource ("Resources\\values\\styles.xml") {
TextContent = () => "<resources><style name=\"AppTheme\" parent=\"Theme.MaterialComponents.DayNight.NoActionBar\" /></resources>",
});
proj.MainActivity = proj.DefaultMainActivity
.Replace ("//${USINGS}", "using Google.Android.Material.Tabs;")
.Replace ("MainLauncher = true", "MainLauncher = true, Theme = \"@style/AppTheme\"")
.Replace ("public class MainActivity : Activity", "public class MainActivity : Activity, TabLayout.IOnTabSelectedListener2")
.Replace ("//${AFTER_ONCREATE}",
"""
var tabLayout = new TabLayout (this);
tabLayout.AddOnTabSelectedListener (this);
tabLayout.AddTab (tabLayout.NewTab (), true);
SetContentView (tabLayout);
}

public void OnTabSelected (TabLayout.Tab tab)
{
Android.Util.Log.Debug ("TabLayoutTest", "OnTabSelected called!");
}

public void OnTabUnselected (TabLayout.Tab tab)
{
}

public void OnTabReselected (TabLayout.Tab tab)
{
""");

builder = CreateApkBuilder (Path.Combine ("temp", "TabLayoutOnTabSelectedListener2"));
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
ClearAdbLogcat ();
RunProjectAndAssert (proj, builder);
Assert.IsTrue (WaitForActivityToStart (proj.PackageName, "MainActivity",
Path.Combine (Root, builder.ProjectDirectory, "startup-logcat.log"), ActivityStartTimeoutInSeconds), "Activity should have started.");
Assert.IsTrue (MonitorAdbLogcat (line => line.Contains (expectedLogcatOutput),
Path.Combine (Root, builder.ProjectDirectory, "tab-selected-logcat.log"), 60), $"Output did not contain {expectedLogcatOutput}!");
}

[Test]
public void SubscribeToAppDomainUnhandledException ([Values (AndroidRuntime.CoreCLR, AndroidRuntime.NativeAOT)] AndroidRuntime runtime)
{
Expand Down
Loading