첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.15MB

▶ TestProject.csproj

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
        <OutputType>Exe</OutputType>
        <RootNamespace>TestProject</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>
        <ApplicationTitle>TestProject</ApplicationTitle>
        <ApplicationId>com.companyname.testproject</ApplicationId>
        <ApplicationIdGuid>307F785A-6EDE-4AEB-8813-DC0FFA886398</ApplicationIdGuid>
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
        <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
    </PropertyGroup>
    <ItemGroup>
        <MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512bd4" />
        <MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512bd4" BaseSize="128,128" />
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" />
        <MauiFont Include="Resources\Fonts\*" />
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>
    <ItemGroup Condition="$(TargetFramework.StartsWith('net6.0-android')) != true">
        <Compile Remove="**\**\*.Android.cs" />
        <None Include="**\**\*.Android.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
        <Compile Remove="**\Android\**\*.cs" />
        <None Include="**\Android\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    </ItemGroup>
    <ItemGroup Condition="$(TargetFramework.StartsWith('net6.0-ios')) != true AND $(TargetFramework.StartsWith('net6.0-maccatalyst')) != true">
        <Compile Remove="**\**\*.iOS.cs" />
        <None Include="**\**\*.iOS.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
        <Compile Remove="**\iOS\**\*.cs" />
        <None Include="**\iOS\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    </ItemGroup>
    <ItemGroup Condition="$(TargetFramework.Contains('-windows')) != true ">
        <Compile Remove="**\*.Windows.cs" />
        <None Include="**\*.Windows.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
        <Compile Remove="**\Windows\**\*.cs" />
        <None Include="**\Windows\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    </ItemGroup>
</Project>

 

728x90

 

▶ DeviceOrientation.cs

namespace TestProject.Services;

/// <summary>
/// 장치 방향
/// </summary>
public enum DeviceOrientation
{
    /// <summary>
    /// 미정의
    /// </summary>
    Undefined,

    /// <summary>
    /// 수평
    /// </summary>
    Landscape,

    /// <summary>
    /// 수직
    /// </summary>
    Portrait
}

 

300x250

 

▶ DeviceOrientationService.cs

namespace TestProject.Services;

/// <summary>
/// 장치 방향 서비스
/// </summary>
public partial class DeviceOrientationService
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 방향 구하기 - GetOrientation()

    /// <summary>
    /// 방향 구하기
    /// </summary>
    /// <returns>장치 방향</returns>
    public partial DeviceOrientation GetOrientation();

    #endregion
}

 

반응형

 

▶ DeviceOrientationService.Android.cs

using Android.Content;
using Android.Runtime;
using Android.Views;

namespace TestProject.Services;

/// <summary>
/// 장치 방향 서비스
/// </summary>
public partial class DeviceOrientationService
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 방향 구하기 - GetOrientation()

    /// <summary>
    /// 방향 구하기
    /// </summary>
    /// <returns>장치 방향</returns>
    public partial DeviceOrientation GetOrientation()
    {
        IWindowManager windowManager = Android.App.Application.Context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>();

        SurfaceOrientation orientation = windowManager.DefaultDisplay.Rotation;

        bool isLandscape = orientation == SurfaceOrientation.Rotation90 || orientation == SurfaceOrientation.Rotation270;

        return isLandscape ? DeviceOrientation.Landscape : DeviceOrientation.Portrait;
    }

    #endregion
}

 

▶ DeviceOrientationService.ios.cs

using UIKit;

namespace TestProject.Services;

/// <summary>
/// 장치 방향 서비스
/// </summary>
public partial class DeviceOrientationService
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 방향 구하기 - GetOrientation()

    /// <summary>
    /// 방향 구하기
    /// </summary>
    /// <returns>장치 방향</returns>
    public partial DeviceOrientation GetOrientation()
    {
        UIInterfaceOrientation orientation = UIApplication.SharedApplication.StatusBarOrientation;

        bool isPortrait = orientation == UIInterfaceOrientation.Portrait || orientation == UIInterfaceOrientation.PortraitUpsideDown;

        return isPortrait ? DeviceOrientation.Portrait : DeviceOrientation.Landscape;
    }

    #endregion
}

 

▶ DeviceOrientationService.Windows.cs

namespace TestProject.Services;

/// <summary>
/// 장치 방향 서비스
/// </summary>
public partial class DeviceOrientationService
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 방향 구하기 - GetOrientation()

    /// <summary>
    /// 방향 구하기
    /// </summary>
    /// <returns>장치 방향</returns>
    public partial DeviceOrientation GetOrientation()
    {
        return DeviceOrientation.Landscape; // 처리를 생략했다.
    }

    #endregion
}

 

▶ MainPage.xaml

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="TestProject.MainPage"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">
    <StackLayout
        HorizontalOptions="Center"
        VerticalOptions="Center"
        Spacing="10">
        <Button x:Name="testButton"
            HorizontalOptions="Center"
            Text="테스트" />
        <Label x:Name="label"
            HorizontalOptions="Center"
            Text="" />
    </StackLayout>
</ContentPage>

 

▶ MainPage.xaml.cs

using TestProject.Services;

namespace TestProject;

/// <summary>
/// 메인 페이지
/// </summary>
public partial class MainPage : ContentPage
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 생성자 - MainPage()

    /// <summary>
    /// 생성자
    /// </summary>
    public MainPage()
    {
        InitializeComponent();

        this.testButton.Clicked += testButton_Clicked;
    }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region 테스트 버튼 클릭시 처리하기 - testButton_Clicked(sender, e)

    /// <summary>
    /// 테스트 버튼 클릭시 처리하기
    /// </summary>
    /// <param name="sender">이벤트 발생자</param>
    /// <param name="e">이벤트 인자</param>
    private void testButton_Clicked(object sender, EventArgs e)
    {
        DeviceOrientationService service = new DeviceOrientationService();

        DeviceOrientation orientation = service.GetOrientation();

        this.label.Text = orientation.ToString();
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요