Day 5 of C++ Boot Camp - Stepping Up to Mobile
-
Upload
jim-mckeeth -
Category
Technology
-
view
137 -
download
1
Transcript of Day 5 of C++ Boot Camp - Stepping Up to Mobile
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
C++BUILDER BOOTCAMP8thto12thofAugust,2016
Moreinformationhttp://embt.co/2016cbootcamp
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
DAY5: STEPPINGUPTOMOBILE
&JimMcKeeth
Moreinfohttp://embt.co/2016cppbootcamp5
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
DAY5:AGENDA▪ Introductiontothemobileplatforms▪ PrototypingmobileappsonWindows▪Usingplatformservices▪ Conditionaldefines▪ Themobilecompilers▪UnderstandingARCmemorymanagement▪ Deploymentmanager▪Makingthemovetomobile
Moreinfohttp://embt.co/2016cppbootcamp5
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
ABOUTJIMMCKEETH▪ LeadWorldWideDeveloperEvangelist&Engineer▪ Longtimesoftwaredeveloper▪ Inventedandpatentedpatternandswipetounlock▪ USPatent#8352745&6766456,etc.
▪ BuiltthoughtcontrolleddronewithGoogleGlass▪ HostofPodcastatDelphi.org▪ LivesnearBoise,Idaho,USAwithhisfamily▪ ImprovisationalcomedyperformerwithCSzBoise▪ FollowonTwitter@JimMcKeeth▪ Availableviaemail:[email protected]
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
ABOUTDAVIDMILLINGTON▪ C++ProductManager,EmbarcaderoTechnologies▪ FromAustralia,livinginEurope▪ LongtimesoftwaredeveloperwithTurboPascal,
C++Builder,C,ObjectiveC,Java,PHPandothers▪ Projectsincludeautonomousunderwatervehicle
controls,dataprocessing,datavisualization,etc.▪ OwnerofParnassus,makersofRADStudioIDEPlugins▪ NavigatorandBookmarks.
▪ Availableviaemail:[email protected]
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
OBJECTIVEOFTHISSESSIONShowyoueverythingyouneedtogetmostoftheworkdoneonyourmobileappswithStarterEditionbeforeyouneedtoupgradetoProfessional+MobiletodeploytoAndroidandiOS.
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
INTRODUCTIONTOTHEMOBILEPLATFORMS
▪ BasiccharacteristicsofAndroidandiOS▪ Somedifferencesbetweenthetwo▪ Commonresolutions&orientations▪ Sensorsandfunctionality▪ Platformdefaultbehaviors▪ Moreresources
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
iOSINTRODUCEDRETINA(AKAHIDPI)▪ iPhonewasoriginally320x480▪ iPhoneRetinabecame640x960▪ Thedots(orpixels)perinchdoubled▪ Everythingstayedthesamesizeand
justgotmoredetailed▪ Thelogicalpixelsstayed320x480▪ Retinauseshigherdensitygraphics
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
ANDROIDSCREENSIZESANDDENSITIES▪ Densities• ldpi0.75x(low)~120dpi• mdpi1x(medium)~160dpi• hdpi1.5x(high)~240dpi• xhdpi2x(extra-high)~320dpi• xxhdpi3x(xx-high)~480dpi• xxxhdpi4x(xxx-high)~640dpi
▪ Sizes:• xlarge>960dpx720dp• large>640dpx480dp• normal>470dpx320dp• small>426dpx320dp
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
COMMONANDROIDDEVICERESOLUTIONS
▪ Nexus6p• Physical1440x2560• Logical411x731• 518ppior3.5x• Aspect16:9
▪ SamsungGalaxyS6• Physical1440x2560• Logical360x640• 576ppior4.0x• Aspect16:9
▪ SonyXperiaZ2/Z3• Physical1080x1920• Logical360x640• 424ppior3.0x• Aspect16:9
▪ Nexus7(2013)• Physical1200x1920• Logical600x960• 323ppior2.0x• Aspect16:10
https://design.google.com/devices/
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
COMMONIOSRESOLUTIONS
▪ iPhoneSE&iPhone5• Physical640x1136• Logical320x568• 326ppior2.0x• Aspect16:9
▪ iPhone6&6s• Physical750x1334• Logical375x667• 326ppior2.0x• Aspect16:9
▪ iPhone6Plus&6sPlue• Physical1242x2208• Logical414x736• 401ppior3.0x• Aspect16:9
▪ iPadMini&Air• Physical1536x2048• Logical768x1024• 326to264ppior2.0x• Aspect4:
http://iosres.com/
C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp© 2016 Embarcadero Technologies, Inc. All rights reserved.
THEMULTIRESOLUTIONBITMAP
▪ Supportsbitmapsofmultiplepixeldensities▪ Selectscorrectresolutionforcurrentdevice▪ Automaticallycalculatesintermediaries▪ Scalingdownisbetterthanup,
soprovidethe4xataminimum▪ Stylesnativelysupportmultipleresolutions
http://embt.co/MultiResBitmap
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
PLATFORMANDSENSORCOMPONENTS
▪ CommonSensors:▪ TLocationSensor(GPS)▪ TMotionSensor*(Accelerometer)▪ TOrientationSensor*(Gyroscope&Compass)▪ TSensorManagertoaccessallsensors&data
▪ TNotificationCenterforschedulingnotifications▪ TCameraComponentaccessthecamera▪ TMediaPlayerrecordaudio,playaudioandvideo▪ TGestureManagerforinteractivegestures▪ TStyleBookforcustomandpremiumstyles
*NotusuallyavailableonWindows
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
MEDIALIBRARYACTIONS
▪ Actionsprovidedtoaccess:▪ Camera▪ CameraRoll▪ Text&Imagesharingservices
▪ Mail,Facebook,Twitter,socialnetworking,etc.
▪ Message(SMSorMMS)▪ Printing
▪ AnimatedTransitions
Allspecifictomobile
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
STANDARDRTLPATHFUNCTIONS
▪ #include<System.IOUtils.hpp>▪ System::Ioutils::TPath::GetHomePath()▪ Windows:C:\Users\<username>\AppData\Roaming▪ OSX:/Users/<username>▪ iOS(Device):/private/var/mobile/Applications/<applicationID>▪ Android:/data/data/<applicationID>/files
▪ Othersinclude:NamedGet<X>Path▪ Temp,Library,Documents,SharedDocuments,Cache,Pictures,
SharedPictures,Public,Camera,SharedCamera,Music,SharedMusic,Movies,SharedMovies,Alarms,Ringtones,SharedRingtones,Downloads,andSharedDownloads
Moreinformation:http://embt.co/pathfunctions
C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp© 2016 Embarcadero Technologies, Inc. All rights reserved.
PROTOTYPINGMOBILEAPPSONWINDOWS
Followingamobiletutorial,onWindowsJimMcKeeth
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
MYPHOTOSANDEFFECTSAPP
▪ Usethecameratotakeapicture
▪ Selectfilterforimage
▪ Addafiltereffecttotheimage
▪ PrototypeonWindows
▪ UpgradetoMobile
▪ DeployoniOSandAndroid
C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp© 2016 Embarcadero Technologies, Inc. All rights reserved.
USINGPLATFORMSERVICESDefinessomefunctionalitythatmightormightnotbe
implementedonaparticularplatformDaveMillington
FMX Platform Services• FMXisacross-platformframework• Aimstosupportwidevarietyoffunctionality,evenifthatfunctionality
isveryplatform-specific• IfiOSdoessomethingthatWindowsdoesn’t,aFMXapponiOSshould
supportthat• Thus–platformservices
What are all the platform services?• Systemfonts,messageboxes,menus,clipboard,messagedialogs• Goingfullscreen,showingwindowchrome• Mouseposition,mousecursors,multipledisplays,textinput,keyboards,
virtualkeyboards,draganddrop,webbrowsing,gesturerecognition• Phonedialing,ads,camera,photos
Andmanymore!http://docwiki.embarcadero.com/RADStudio/Berlin/en/FireMonkey_Platform_Services
How do they work?• Eachhasaninterfacedefined• Eachinterfaceisimplementedforeachplatform(thatsupportsthat
functionality)• RegisteredwithFMX:canqueryifaninterfacehasanimplementation
registered,andgetthatimplementation• Canimplementandregisteryourown,includingreplacingdefaultones
Interfaces in C++ - a digression• C++doesn’thaveinterfaces–anothercompilerextensionofours• (Delphi:COMisfirst-classlanguagefeature,interfaceskey,irrelevantforthisbut
useful)• Keybits:• __interfacekeyword• EachhasaGUID• WrapinSystem::DelphiInterface<I>templateclass,eg:
InFMX.Platform.hpp:typedefSystem::DelphiInterface<IFMXLocaleService> _di_FMXLocaleService;Inyourcode:_di_FMXLocalServiceMyInterface;
FMX Platform Services• Interfacesandimplementationsforawidevarietyofplatform-specific
behaviour• Thingsthatmayormaynotexistonanyplatform• Thingsthataredifferentonvariousplatforms• UsedinternallybyFMX,butyoucanaccessanduse–andalsodefine
yourownimplementation!
C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp© 2016 Embarcadero Technologies, Inc. All rights reserved.
CONDITIONALDEFINESControlwhatcodegetscompiledondifferentplatformsbased
onthecompilersandconfigurations.DaveMillington
Platform-specific conditional compilation• Allowsyoutocompilecodeonlyforoneplatform(oranothercondition)• Whatisit?
#ifdefined(_PLAT_MSWINDOWS)//Thiscodewillonlybecompiledif_PLAT_MSWINDOWSis//defined,whichitonlyisforaWindowstarget.returnL”HellofromWindows!”#elsereturnL”HellofromanyotherOS!”#endif
• Macros(eg_PLAT_WINDOWS)canbedefinedincode,inthecompileroptions,orbythecompileritself.
• Seehttp://docwiki.embarcadero.com/RADStudio/Berlin/en/ Conditional_Compilation_Overview_Index
Key macrosPerplatform• _PLAT_MSWINDOWS• _PLAT_MACOS• _PLAT_IOS• _PLAT_ANDROID
Other• __clang__-anyClangcompiler• __APPLE__-anyAppleOS• __CONSOLE__-ifit’sacommand-line
app• Etc…
Foreachspecificcompiler• BCC32(old/classicWin32)• BCC32C(newClangWin32)• BCC64(newClangWin64)• BCCOSX(macOS)• BCCIOSARM(iOS,ARM32)• BCCIOSARM64(iOS,ARM64)• BCCAARM(Android)http://docwiki.embarcadero.com/RADStudio/ Seattle/en/Predefined_Macroshttp://docwiki.embarcadero.com/RADStudio/ Berlin/en/C%2B%2B_Compilers
Platform-specific compilation guidelines• Doyoureallyneedto?FMX,FireDAC,REST,Indyetcalldoagoodjob• Doyoureallyneedto?Wemightalreadyhavecodetodowhatyouneed,eg• Wantaplatform-specificfolder(Documents,say)thatvariesWin/Mac/iOS/Android?Try
System::IOUtils::TPath–GetDocumentsPath,GetPicturesPath,GetAlarmsPath,GetDownloadPath,…
• OrfileIO–concatenatingpathswith\or/(TPathagain)
• Isolateit• Useinterfacesandhidethattherearemultipleimplementations• Separateunitsperplatform,ifcodesizeismorethanalineortwo
But,itcanbenecessary/useful.It’seasy.Widevarietyofmacrosdefinedforplatforms,compilers,bitness,andmore.
C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp© 2016 Embarcadero Technologies, Inc. All rights reserved.
UNDERSTANDINGARCMEMORYMANAGEMENT
UsingAutomaticReferenceCountingtodeterministicallymanagememoryandobjectreferences
(BetterthanGarbageCollection)DaveMillington
Automatic Reference Counting (ARC)Notusuallysomethingtodealwith,butinteresting…
Dealswiththeproblemofleakedobject:voidLeak(){Foo*bar=newFoo();}‘bar’isneverdeleted!
• Garbagecollection(Android(notus!),.Net)• Referencecounting(Apple/iOS,Delphi)• Othertechniqueslikesmartpointers(C++)
How does it affect C++?Notmuch.Here’sanormalC++class:
classRealCppClass{};voidTest(){RealCppClass*test=newRealCppClass();}^leaks
voidTest(){unique_ptr<RealCppClass>test(newRealCppClass());}^safe
How does it affect C++?OnlywhenusingDelphiclassesfromC++(C++BuildercanconsumeDelphicode;theDelphicompileremitsheaders,thereismagic…twolanguagesmix!)Here,therearenoleaksineithercodesample:
voidTestDelphi(){TObject*obj=newTObject();}//1
voidTestDelphi(){TObject*a=newTObject();//1{TObject*b=newTObject();//2b=a;//3}//4}//5
Only when accessing Delphi frameworksMostframeworksimplementedinDelphi.NoneedtobeawareofARC,usually.Windows:never.Mobile:onlyDelphiclasses.
void__fastcallTForm1::ButtonClick(Tcomponent*Sender){TButton*button=dynamic_cast<TButton*>(Sender);//…}
‘button’isreferencecounted;FMXisaDelphi-implementedframework.
Questions…WhatifIcalldeleteonanARC-edobject?Itdecrementstherefcount.Butusesmartpointers,neverdelete!
Doesitworkwithsmartpointers?Absolutelyyes.Keepusingthem!
WhichclassesareDelphiones?FMXandotherframeworksareallimplementedinDelphi.Onehint:theclassnamesareprefixedwithT,egTForm,TFDConnection.
Howdoesitrelatedtoshared_ptr<>?Similarconcept;shared_ptrcountsexternally;ARCisfaster.
I like interesting compiler extensions…MakeaDelphi-styleclassinC++,itisARC-ed:class__declspec(delphiclass)RefCounted:publicTObject{}
__weak–weakpointer,norefcount,givesnilwhentheobjectisdeletedelsewhere__unsafe–unmanagedpointer,norefcount,noguarantees
__closuremethod=&(MyButton.Click);method(foo);//CallsMyButton.Click(foo)Objectinstanceinside‘method’isaweakpointer-isnullifMyButtonisdeleted.
Do I need to do anything?• Justuseasmartpointerasyounormallywould(bestpractice;manual
lifetimewithdeleteisevil!)• Noneedtochangecodestyle.• DoesnotaffectnormalC++.• BeawareDelphi-styleclasseswillbealiveuntiltheirlastreference
vanishes.
C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp© 2016 Embarcadero Technologies, Inc. All rights reserved.
DEPLOYINGTOMOBILEJimMcKeeth
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
USINGTHEDEPLOYMENTMANAGER
▪ Managesfilesandcreatesappbundles
C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp© 2016 Embarcadero Technologies, Inc. All rights reserved.
ANDROIDPERMISSIONS
▪ MustspecifypermissionforwhattheappwilldoonAndroid
▪ Failuretodosowillresultinerrororlackoffeatures
▪ Permissionsappearintheappstore▪ Commonpermissionsinclude
Location,Camera,Internet,Bluetooth,etc.
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
SETTINGUPFORMOBILEDEVELOPMENT▪ Basicsofgettingstarted▪ PAServer▪ AndroidUSBDrivers▪ Instructions▪ https://www.embarcadero.com/products/cbuilder/videos
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
MAKINGTHEMOVETOMOBILE
▪ Loadingourprototypeappintoprofessional▪ DeployingtoiOS▪ DeployingtoAndroid▪ DebuggingonMobile
© 2016 Embarcadero Technologies, Inc. All rights reserved.C++ Boot Camp - Aug 2016 - http://embt.co/2016cbootcamp
Q&AJoinusatCommunity.Embarcadero.com
[email protected]/cppbuilder
DavidMillington<[email protected]>&
JimMcKeeth<[email protected]>
Moreinfohttp://embt.co/2016cppbootcamp5