Wit = new WindowInfoTrackerCallbackAdapter((this)) Initialize the window manager in your activity's OnCreate: protected override void OnCreate(Bundle savedInstanceState) The activity also implements IConsumer, see step 4 below for the code for the Accept method required by this interface. In the MainActivity class, declare a variable for the window information tracker: public class MainActivity : AppCompatActivity, IConsumerĮnsure that the correct using and using statements are added to the top of the file. Search for .Ĭhoose the highest version number to add to your project ( 1.0.0.7 is the first stable version of the API). Right-click on your Xamarin.Android project and choose Manage NuGet Packages. To add the NuGet that provides Jetpack Window Manager features: To use WindowInfoTracker in your code, follow the instructions below (from the Xamarin.Android Window Manager sample app): Add dependency Instead of using the ScreenHelper class to determine IsDualMode or to GetHingeBoundsDip(), you can use the methods and properties on WindowInfoTracker and related classes directly. The NuGet is intended to replace the need to add the Xamarin.DuoSDK NuGet to Xamarin.Android apps. Samples using Jetpack Window Manager are available in the surface-duo-sdk-xamarin-samples repo. The FoldingFeature class provides information about the state of that part of the device, with properties for Bounds and IsSeparating, and methods for OcclusionType, Orientation, and State. FoldingFeature - Provides information about a specific feature of the device - while the Surface Duo only has one folding feature, it's possible that other devices might have more.Window Manager will return a collection of display features from a layout change callback. DisplayFeature - Identifies disruptions in the continuous flat screen surface such as hinges or folds.Jetpack Window Manager provides a standard API for working with all foldable devices. Jetpack Window Manager is intended for developers working with Xamarin.Android projects. Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this users should reference the NuGet for Surface Duo support, with its DualScreenInfo and TwoPaneView classes. If the response is helpful, please click " Accept Answer" and upvote it. (requestCode, permissions, grantResults) īase.OnRequestPermissionsResult(requestCode, permissions, grantResults) Public override void OnRequestPermissionsResult(int requestCode, string permissions, .Permission grantResults) MSensorManager.UnregisterListener(this, mSensorGr) Public void UnRegisterOrientationListener() MSensorManager.RegisterListener(this, mSensorGr, SensorDelay.Game) Public void RegisterOrientationListener() Reverse portrait will not be used (mAccelerometerReading > 0) ? : If (Math.Abs(mAccelerometerReading) > Math.Abs(mAccelerometerReading))Īpp.Orientation = (mAccelerometerReading > 0) ? 1 : 2 Public void OnSensorChanged(SensorEvent sensorEvent) Public void OnAccurac圜hanged(Sensor sensor, SensorStatus sensorStatus) MSensorGr = mSensorManager.GetDefaultSensor(SensorType.Accelerometer) MSensorManager = GetSystemService(Context.SensorService) as SensorManager var windowManager = ApplicationContext.GetSystemService(Context.WindowService).JavaCast() Protected override void OnCreate(Bundle savedInstanceState) Private float mAccelerometerReading = new float Public class MainActivity : global:.FormsAppCompatActivity, ISensorEventListener IWindowManager windowManager = Context.GetSystemService(Context.WindowService).JavaCast() in the xamarin android or custom renderer, you can use following code as well. I find you use Camera2forms this demo, please do not forget to delete ScreenOrientation = ScreenOrientation.Portrait above the MainActivity.cs, then you can rotate.Īnd if you want to get the current orientation degree. Var orientation = mainDisplayInfo.Orientation ĭisplayAlert("Degree", rotation.ToString(), "OK") Orientation (Landscape, Portrait, Square, Unknown) Var mainDisplayInfo = DeviceDisplay.MainDisplayInfo private void Button_Clicked(object sender, EventArgs e) You can use Xamarin.Essentials: Device Display Information to get the current orientation degree.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |