Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WindowManager] update to beta01 #19

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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

# ignore Xamarin.Android Resource.Designer.cs files
**/*.Droid/**/[Rr]esource.[Dd]esigner.cs
**/*.Android/**/[Rr]esource.[Dd]esigner.cs
**/Android/**/[Rr]esource.[Dd]esigner.cs
**/Droid/**/[Rr]esource.[Dd]esigner.cs
[Rr]esource.[Dd]esigner.cs

# Mono auto generated files
mono_crash.*

Expand Down Expand Up @@ -348,3 +355,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/

5 changes: 4 additions & 1 deletion CompanionPane/CompanionPane.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Window">
<Version>1.0.0-alpha09</Version>
<Version>1.0.0.1-beta01</Version>
</PackageReference>
<PackageReference Include="Xamarin.AndroidX.Window.WindowJava">
<Version>1.0.0.1-beta01</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
Expand Down
49 changes: 23 additions & 26 deletions CompanionPane/MainActivity.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@

using Android.Content.Res;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using AndroidX.AppCompat.App;
using AndroidX.Core.Util;
using AndroidX.Fragment.App;
using AndroidX.Window;
using AndroidX.Window.Layout;
using AndroidX.Window.Java.Layout;
using CompanionPane.Fragments;
using Java.Lang;
using Java.Util.Concurrent;
using System.Linq;

/*
23-Aug-21 Update to androidx.window-1.0.0-beta01
HACK: need to JavaCast IDisplayFeature to IFoldingFeature
*/
namespace CompanionPane
{
[Android.App.Activity(
Expand All @@ -24,8 +29,8 @@ namespace CompanionPane
public class MainActivity : AppCompatActivity, BaseFragment.IOnItemSelectedListener, IConsumer
{
const string TAG = "JWM"; // Jetpack Window Manager
WindowManager wm;
FoldingFeature.Orientation hingeOrientation = FoldingFeature.Orientation.Vertical;
WindowInfoRepositoryCallbackAdapter wir;
FoldingFeatureOrientation hingeOrientation = FoldingFeatureOrientation.Vertical;
bool isDuo, isDualMode;

SinglePortrait singlePortrait;
Expand All @@ -49,12 +54,13 @@ protected override void OnCreate(Bundle savedInstanceState)
dualLandscape = DualLandscape.NewInstance(slides);
dualLandscape.RegisterOnItemSelectedListener(this);

wm = new WindowManager(this);
wir = new WindowInfoRepositoryCallbackAdapter(WindowInfoRepository.Companion.GetOrCreate(this));
wir.AddWindowLayoutInfoListener(runOnUiThreadExecutor(), this);

SetupLayout();
}


#region Used by WindowInfoRepository callback
IExecutor runOnUiThreadExecutor()
{
return new MyExecutor();
Expand All @@ -67,6 +73,7 @@ public void Execute(IRunnable r)
handler.Post(r);
}
}
#endregion

public void Accept(Java.Lang.Object newLayoutInfo) // Object will be WindowLayoutInfo
{
Expand All @@ -78,15 +85,17 @@ public void Accept(Java.Lang.Object newLayoutInfo) // Object will be WindowLayo
}
else
{
foreach (var df in wli.DisplayFeatures)
foreach (var displayFeature in wli.DisplayFeatures)
{
Log.Info(TAG, "Bounds:" + df.Bounds);
var ff = df as FoldingFeature;
if (!(ff is null))
Log.Info(TAG, "Bounds:" + displayFeature.Bounds);

var foldingFeature = displayFeature.JavaCast<IFoldingFeature>();

if (!(foldingFeature is null))
{ // a hinge exists
Log.Info(TAG, "Orientation: " + ff.GetOrientation());
Log.Info(TAG, "Orientation: " + foldingFeature.Orientation);
isDualMode = true;
hingeOrientation = ff.GetOrientation();
hingeOrientation = foldingFeature.Orientation;
isDuo = true; //HACK: set first time we see the hinge, never un-set
}
else
Expand All @@ -98,18 +107,6 @@ public void Accept(Java.Lang.Object newLayoutInfo) // Object will be WindowLayo
SetupLayout();
}

protected override void OnStart()
{
base.OnStart();
wm.RegisterLayoutChangeCallback(runOnUiThreadExecutor(), this);
}

protected override void OnStop()
{
base.OnStop();
wm.UnregisterLayoutChangeCallback(this);
}

void ShowFragment(Fragment fragment)
{
var fragmentTransaction = SupportFragmentManager.BeginTransaction();
Expand All @@ -129,9 +126,9 @@ void HideFragment(Fragment fragment)
}
}

void UseDualMode(FoldingFeature.Orientation hingeOrientation)
void UseDualMode(FoldingFeatureOrientation hingeOrientation)
{
if (hingeOrientation == FoldingFeature.Orientation.Horizontal)
if (hingeOrientation == FoldingFeatureOrientation.Horizontal)
{
dualLandscape.setCurrentPosition(currentPosition);
ShowFragment(dualLandscape);
Expand Down
Loading