Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DroidKaigi2016 アプリを Xamarin に移植した話 #jxug

DroidKaigi2016 アプリを Xamarin に移植した話 #jxug

JXUGC #13 東京 緊急開催 Xamarin のすべて! - http://jxug.connpass.com/event/29734/ の発表資料です。

amay077

May 07, 2016
Tweet

More Decks by amay077

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • OKUYAMA Hironobu(@amay077) • Toyohashi, Aichi • Geospatial Engineer

    • VB/VC('00-), C#('05-), Android/iOS('11-), Xamarin('13-) • BUILD Insider - XamarinٯҾ͖Tips 2 © @amay077 , 2016
  2. DroidKaigi2016 ͷެࣜΞϓϦΛ Xamarin.Android ΁Ҡ২ͨ͠࿩ Λ͠·͢ • Android SDKͷബ͍ϥούʔ XamarinωΠςΟϒ ͷ࿩Ͱ͢

    • Xamarin.Forms Ͱ͸͋Γ·ͤΜ • MVVM ͱ͔ɺiOSଞͱͷڞ௨Խͷ࿩͸͠·ͤΜ • ࠷৽ͷ Android ΞϓϦ͕Ͳ͜·Ͱ Xamarin Ͱ։ൃՄೳ͔ʁ 3 © @amay077 , 2016
  3. DroidKaigi2016 ެࣜΞϓϦ ͱ͸ • github.com/xamarinhq/app-evolve • εϐʔΧʔ/ελοϑͷ @konifar ͞Μ ͕ओಋ͠༗ࢤʢ

    40໊ʂ ʣʹΑΓ։ൃ • ։ൃظؒɿ1/11ʙ2/12ʙ now • 6ը໘ɺ70Ϋϥεɺ4200ߦ(2/18࣌఺) Androidք۾ͷτοϓΤϯδχ Ξୡ͕࡞੒ͨ͠஌ݟͷմʂ 5 © @amay077 , 2016
  4. AndroidManifest.xml Xamarin.Android ʹ͓͍ͯɺը໘ͷ AndroidManifest.xml ΁ͷఆ ٛ͸ෆཁ • <activity> ͷఆٛ͸ɺ XXXActivity

    Ϋϥεͷଐੑ΁ • <application> ͷఆٛ͸ɺ XXXApplication Ϋϥεͷଐੑ΁ • ݖݶͷఆٛ͸ AndroidManifest.xml ʹ͢Δ͕ Xamarin Studio/ Visual Studio ͷઃఆը໘͔Βߦ͑Δ 9 © @amay077 , 2016
  5. // [BEFORE]AndroidManifest.xml in Java <application android:name=".MainApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">

    <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="${mapsApiKey}" /> <activity android:name=".activity.MainActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 10 © @amay077 , 2016
  6. // [AFTER]MainActivity.cs [Activity( ConfigurationChanges = ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenLayout

    | ConfigChanges.ScreenSize | ConfigChanges.Orientation, Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)] [IntentFilter (new []{ Intent.ActionMain }, Categories = new []{ Intent.CategoryDefault })] public class MainActivity : AppCompatActivity { // ... } 11 © @amay077 , 2016
  7. // [AFTER]MainApplication.cs [Android.App.Application( AllowBackup=true, Icon="@mipmap/ic_launcher", Theme="@style/AppTheme")] [MetaData("com.google.android.gms.version", Value = "@integer/google_play_services_version")]

    [MetaData("com.google.android.maps.v2.API_KEY", Value = "{your google maps api key}")] public class MainApplication : Android.App.Application { // ... } 12 © @amay077 , 2016
  8. ॲཧ • جຊతʹ͸ॻ͖௚͠ • ߏจ͸ࣅͯΔͷͰίϐϖͯ͠ΤϥʔΛফͯ͘͠ • Sharpen ͱ͍͏πʔϧ΋ https:/ /blog.xamarin.com/android-in-c-

    sharp/ ͋Δ͚ͲࠓͰ΋࢖͑Δͷ͔ͳʁ • ໘౗ͩͬͨΒػೳ୯ҐͰ Jar Խͯ͠ɺBinding ܦ༝Ͱ࢖༻ͨ͠ํ ͕Α͍͔΋ 13 © @amay077 , 2016
  9. ϥΠϒϥϦҠߦͷબ୒ࢶ 1. ಉ౳ػೳΛ࣋ͭ .NET੡ͷϥΠϒϥϦ Λ୳͢ 2. ಉ໊ͷ BindingϥΠϒϥϦ Λ୳͢ 3.

    ಉ౳ػೳΛ࣋ͭ BindingϥΠϒϥϦ Λ࡞Δ 4. ಉ౳ػೳΛ࣋ͭ .NET੡ͷϥΠϒϥϦ Λ࡞Δ 5. ಉ౳ػೳΛ͖͋ΒΊΔ 15 © @amay077 , 2016
  10. .NET੡ͷϥΠϒϥϦ Λ୳͢ • Gson → JSON.NET • RxJava → Reactive

    Extensions • Dagger2 → Stiletto • Retrofit2 → Refit ୳͢ͱ݁ߏ͋Δ twitter ΍ teratail, Stackoverflow.jp ͳͲͰฉ͍ͯΈΑ͏ حಛͳਓ͕୳ͯ͘͠ΕΔ͔΋͠Εͳ͍ ʛш´)ŧŽŕ 16 © @amay077 , 2016
  11. ಉ໊ͷ BindingϥΠϒϥϦ Λ୳͢ • Android Support Library / Google Play

    services • Picasso → Square.Picasso • AndroidFlowLayout → AndroidFlowLayout ɹ ஶ໊ͳϥΠϒϥϦͳΒطʹ XamarinରԠͷnugetύοέʔδ͕༻ҙ ͞Ε͍ͯΔʢಛʹViewؔ࿈͸Binding͔͠બ୒ࢶ͕ͳ͍ͷͰʣ Android Support Library ؔ࿈͸Ұ౓͸ඞͣϋϚΔͷͰམͪண͍ͯ 17 © @amay077 , 2016
  12. ಉ౳ػೳΛ࣋ͭ .NET੡ͷϥΠϒϥϦ Λ࡞Δ • ཧ૝ܥ͚ͩͲ࠷ऴखஈ • جຊతͳػೳͳΒʢJSON.NET ͷΑ͏ʹʣطʹଘࡏ͢ΔͩΖ͏͠ • Binding

    ΋࢖Θͳ͍ͱ͍͏͜ͱ͸ɺϚϧνϓϥοτϑΥʔϜΛҙ ࣝͯ͠ͷબ୒ͩΖ͏͠ɺ೉қ౓͸૬౰ߴ͍ • ʮҠ২͚ͩʯͷ༧ࢉͰ͸೉͍͠ͱࢥ͏ • ClosedXML, EPPlus Έ͍ͨͳͷΛ Xamarin ରԠ͢Δͷ͸χʔζ͋ Δͱࢥ͏ʢ΍͸Γ೉қ౓͸ߴ͍ʣ 19 © @amay077 , 2016
  13. ಉ౳ػೳΛ͖͋ΒΊΔ ͝ར༻͸ܭըతʹ • Android-ORM - ORMϥΠϒϥϦ • ୅ସϥΠϒϥϦͱͯ͠ SQLite.NET ORM

    ͕͋Δ͕ɺ࢖͍ํ͕໘ ౗ͩͬͨͷͰɺKey-Value ετΞͰ͋Δ Akavache Λ࢖༻ • parceler - ը໘ؒ௨৴σʔλͷγϦΞϥΠζΛॿ͚ΔϥΠϒϥϦ • ୅ସϥΠϒϥϦ͕ݟ͔ͭΒͳ͔ͬͨͷͰɺը໘ؒͷ௨৴σʔ λ͸ JSON(JSON.NET) ʹͨ͠ 20 © @amay077 , 2016
  14. Android DataBinding ʹ͍ͭͯ • Android Studio/gradle ͕ɺ<layout> ͰғΜͩൣғͷUIཁૉͷม ਺Λࣗಈίʔυੜ੒ •

    ͍ΘΏΔ MainForm.designer.cs తͳ • Xamarin.Android Ͱ͸ະରԠͳͷͰ <layout> λά͕Τϥʔʹ • <layout> Λ࡟আ͠ɺ஍ಓʹ FindViewById ͨ͠ 21 © @amay077 , 2016
  15. Google I/O 2015 App • github.com/google/iosched • Android ͷΈରԠ •

    I/O 2016 App ΋ͦͷ͏ͪ͘Δʁ 28 © @amay077 , 2016
  16. try! Swift App • github.com/tryswift/trySwiftApp • iOS ͷΈରԠ • 3/2-4

    ʹ։࠵͞ΕͨiOS/Swiftσϕϩο ύʔ޲͚ΠϕϯτͷެࣜΞϓϦ 29 © @amay077 , 2016