SlideShare une entreprise Scribd logo
1  sur  33
Scala on Your Phone:
    Making Mobile
Development Suck Less
      Michael Galpin, eBay
          @michaelg
Example: Event Handlers
Just a Click
iPhone
Android
Objective-C
@synthesize textInput;
@synthesize label;
@synthesize name;

- (IBAction)changeGreeting:(id)sender {
  self.name = textInput.text;

    NSString *nameString = name;
    if([nameString length] == 0) {
      nameString = @"Code Camp";
    }
    NSString *greeting = [[NSString alloc]
                           initWithFormat:@"Hello %@!", nameString];
    label.text = greeting;
    [greeting release];
}

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
  if(theTextField == textInput) {
    [textInput resignFirstResponder];
  }
  return YES;
}

- (void)dealloc {
  [textInput release];
  [label release];
  [name release];
  [super dealloc];
}
Java
@Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button sayButton = (Button) findViewById(R.id.say_button);
            sayButton.setOnClickListener(new OnClickListener(){

	   	    	    public void onClick(View v) {
	   	    	    	 EditText nameBox = (EditText) findViewById(R.id.name);
	   	              String name = nameBox.getText().toString();
	   	              TextView greeting = (TextView) findViewById(R.id.greeting);
	   	              greeting.setText("Hello " + name);
	   	    	    }
             	
             });
     }
Scala
override def onCreate(savedInstanceState:Bundle){
    import R.id._
    super.onCreate(savedInstanceState)
    setContentView(R.layout.main)
    val sayButton = findViewById(say_button).asInstanceOf[Button]
    sayButton.setOnClickListener( () => {
        val user = findViewById(name).asInstanceOf[EditText].text
        findViewById(greeting).asInstanceOf[TextView].text = "Hello " + user
    })
}
Advantages
Closures
•   Strongly typed handlers   •   Forget one-method
                                  interfaces
•   Lexical scoping
Closures
          •   Strongly typed handlers           •   Forget one-method
                                                    interfaces
          •   Lexical scoping

val computedValue = parseInt(findViewById(foo).asInstanceOf[EditText].text)
this.post( () => {
    val url = new URL("http://foo.com?qs=" + computedValue)
    Source.fromStream(url.openStream).getLines.foreach(findViewById(results).text += _)
})

mainMenu.onClick = (item:MenuItem) => { startActivity(item.activity) }
Getters, Setters, Updates

mapImage.alpha = if (topLevelGroup.searchButton.clickable) BLENDED else OPAQUE

allTiles(selectedTileIndex) = throbberImageView
Operators

resultsLabelView += "Read more..."

keywordInput -= eventListener

mainMenu ++ fileMenuItems
Traits

class SearchDetailsActivity extends Activty with JsonParser, Trackable
XML
val results = for (suggested <- responseXml"Suggested"){
    yield Term(sugested"Term" text, suggested"Priority" text)
}

nextNode   match {
    case   <code>{txt}</code> => this.status = parseInt(txt)
    case   <state>{txt}</state> => this.state = txt
    case   _ =>
}
Trade Secrets
*    Compiler   Dex Compiler         Compress




Source Code Class files        Dex File              APK
Implicits
object Activity{

    implicit def funcToClicker1(f:_root_.android.view.View => Unit):OnClickListener =
      new OnClickListener(){ def onClick(v:_root_.android.view.View)=f.apply(v)}

    implicit def funcToClicker0(f:() => Unit):OnClickListener =
      new OnClickListener() { def onClick(v:_root_.android.view.View)=f.apply}

    implicit def funcToLongClicker0(f:() => Boolean):OnLongClickListener =
      new OnLongClickListener() { def onLongClick(v:_root_.android.view.View) = f.apply}

    implicit def funcToLongClicker1(f:_root_.android.view.View => Boolean):OnLongClickListener =
      new OnLongClickListener() { def onLongClick(v:_root_.android.view.View) = f.apply(v)}

  implicit def viewToRichView(v:_root_.android.view.View):scala.android.view.View = new
scala.android.view.View(v)

    implicit def richViewToView(view:scala.android.view.View):_root_.android.view.View = view.base
}
Bag o’ Tricks
class ViewGroup(base:_root_.android.view.ViewGroup) extends View(base){
   object views{
     def +=(v:_root_.android.view.View){
       base.addView(v)
     }

      def apply(index:Int) = new {
          def update(v:_root_.android.view.View) = base.addView(index,v)
      }
   }
...
}
Bag o’ Tricks
class ViewGroup(base:_root_.android.view.ViewGroup) extends View(base){
   object views{
     def +=(v:_root_.android.view.View){
       base.addView(v)
     }

      def apply(index:Int) = new {
          def update(v:_root_.android.view.View) = base.addView(index,v)
      }
   }
...
}

myGroup.views += someOtherView
myGroup.views(3) = yetAnotherView
Scala on Android

• More Correct
• More Concise
• Simpler
• Perfect Fit
Challenges
2500+ Classes
Hey, What About?

Contenu connexe

Tendances

Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
Dmitry Buzdin
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Jon Kruger
 

Tendances (20)

The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Jason parsing
Jason parsingJason parsing
Jason parsing
 
Specs2
Specs2Specs2
Specs2
 
resume_Alexey_Zaytsev
resume_Alexey_Zaytsevresume_Alexey_Zaytsev
resume_Alexey_Zaytsev
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
C++ practical
C++ practicalC++ practical
C++ practical
 
Mozilla とブラウザゲーム
Mozilla とブラウザゲームMozilla とブラウザゲーム
Mozilla とブラウザゲーム
 
Javascript Execution Context Flow
Javascript Execution Context FlowJavascript Execution Context Flow
Javascript Execution Context Flow
 
The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181
 
Funcitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional WayFuncitonal Swift Conference: The Functional Way
Funcitonal Swift Conference: The Functional Way
 
SPFx: Working with SharePoint Content
SPFx: Working with SharePoint ContentSPFx: Working with SharePoint Content
SPFx: Working with SharePoint Content
 
SPFx working with SharePoint data
SPFx working with SharePoint dataSPFx working with SharePoint data
SPFx working with SharePoint data
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwo
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
“iOS 11 в App in the Air”, Пронин Сергей, App in the Air
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with Slick
 
The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202The Ring programming language version 1.8 book - Part 49 of 202
The Ring programming language version 1.8 book - Part 49 of 202
 

En vedette

Adv06 f dnk_project_guide
Adv06 f dnk_project_guideAdv06 f dnk_project_guide
Adv06 f dnk_project_guide
dnaveda
 
Marketing strategies to increase the ROI on mobile
Marketing strategies to increase the ROI on mobileMarketing strategies to increase the ROI on mobile
Marketing strategies to increase the ROI on mobile
Amit Ambastha
 
SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...
SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...
SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...
Keiichiro Ono
 
Incline & Pacific - なぜ作るのか
Incline & Pacific - なぜ作るのかIncline & Pacific - なぜ作るのか
Incline & Pacific - なぜ作るのか
Kazuho Oku
 

En vedette (20)

Integracija poslovnega sistema
Integracija poslovnega sistemaIntegracija poslovnega sistema
Integracija poslovnega sistema
 
Funny
FunnyFunny
Funny
 
Rexona City Tracks Mobile App Concept
Rexona City Tracks Mobile App ConceptRexona City Tracks Mobile App Concept
Rexona City Tracks Mobile App Concept
 
3rd Workshop on Social Information Retrieval for Technology-Enhanced Learnin...
3rd Workshop onSocial  Information Retrieval for Technology-Enhanced Learnin...3rd Workshop onSocial  Information Retrieval for Technology-Enhanced Learnin...
3rd Workshop on Social Information Retrieval for Technology-Enhanced Learnin...
 
Presentation1
Presentation1Presentation1
Presentation1
 
Learning Analytics and Linked Data Workshop at LAK12
Learning Analytics and Linked Data Workshop at LAK12Learning Analytics and Linked Data Workshop at LAK12
Learning Analytics and Linked Data Workshop at LAK12
 
WordPress: Beyond Blogging
WordPress: Beyond BloggingWordPress: Beyond Blogging
WordPress: Beyond Blogging
 
Más allá del Pokémon Go: Realidad Aumentada y Virtual en el Aula
Más allá del Pokémon Go: Realidad Aumentada y Virtual en el AulaMás allá del Pokémon Go: Realidad Aumentada y Virtual en el Aula
Más allá del Pokémon Go: Realidad Aumentada y Virtual en el Aula
 
Adv06 f dnk_project_guide
Adv06 f dnk_project_guideAdv06 f dnk_project_guide
Adv06 f dnk_project_guide
 
ASP.NET MVC 3 in area of Javascript and Ajax improvement
ASP.NET MVC 3 in area of Javascript and Ajax improvementASP.NET MVC 3 in area of Javascript and Ajax improvement
ASP.NET MVC 3 in area of Javascript and Ajax improvement
 
Marketing strategies to increase the ROI on mobile
Marketing strategies to increase the ROI on mobileMarketing strategies to increase the ROI on mobile
Marketing strategies to increase the ROI on mobile
 
Institutions Struggeling with Web2.0
Institutions Struggeling with Web2.0Institutions Struggeling with Web2.0
Institutions Struggeling with Web2.0
 
SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...
SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...
SDCSB Advanced Tutorial: Reproducible Data Visualization Workflow with Cytosc...
 
Incline & Pacific - なぜ作るのか
Incline & Pacific - なぜ作るのかIncline & Pacific - なぜ作るのか
Incline & Pacific - なぜ作るのか
 
Devops down-under
Devops down-underDevops down-under
Devops down-under
 
Slavery Module: Lesson ten
Slavery Module:  Lesson tenSlavery Module:  Lesson ten
Slavery Module: Lesson ten
 
What Do We Know About IPL Users?
What Do We Know About IPL Users?What Do We Know About IPL Users?
What Do We Know About IPL Users?
 
Examenopleiding energieconsulent mfl
Examenopleiding energieconsulent mflExamenopleiding energieconsulent mfl
Examenopleiding energieconsulent mfl
 
Web 2.0 for Learning
Web 2.0 for LearningWeb 2.0 for Learning
Web 2.0 for Learning
 
Unit 2.3 Part 2
Unit 2.3 Part 2Unit 2.3 Part 2
Unit 2.3 Part 2
 

Similaire à Scala on Your Phone

EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
Heiko Behrens
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomer
zefhemel
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
IndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
vhazrati
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
Leonardo Soto
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
zefhemel
 

Similaire à Scala on Your Phone (20)

Android crashcourse
Android crashcourseAndroid crashcourse
Android crashcourse
 
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with EclipseEclipseCon2011 Cross-Platform Mobile Development with Eclipse
EclipseCon2011 Cross-Platform Mobile Development with Eclipse
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
mobl presentation @ IHomer
mobl presentation @ IHomermobl presentation @ IHomer
mobl presentation @ IHomer
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentation
 
Building complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and ReactBuilding complex User Interfaces with Sitecore and React
Building complex User Interfaces with Sitecore and React
 
Intorduction of Playframework
Intorduction of PlayframeworkIntorduction of Playframework
Intorduction of Playframework
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
 
Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
droidparts
droidpartsdroidparts
droidparts
 
mobl
moblmobl
mobl
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
Connect.js - Exploring React.Native
Connect.js - Exploring React.NativeConnect.js - Exploring React.Native
Connect.js - Exploring React.Native
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)Jython: Python para la plataforma Java (EL2009)
Jython: Python para la plataforma Java (EL2009)
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
mobl - model-driven engineering lecture
mobl - model-driven engineering lecturemobl - model-driven engineering lecture
mobl - model-driven engineering lecture
 

Plus de Michael Galpin

Plus de Michael Galpin (12)

Android lessons you won't learn in school
Android lessons you won't learn in schoolAndroid lessons you won't learn in school
Android lessons you won't learn in school
 
Design Patterns for Tablets and Smartphones
Design Patterns for Tablets and SmartphonesDesign Patterns for Tablets and Smartphones
Design Patterns for Tablets and Smartphones
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Scala on Android: Experiences at Bump Technologies
Scala on Android: Experiences at Bump TechnologiesScala on Android: Experiences at Bump Technologies
Scala on Android: Experiences at Bump Technologies
 
That’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your BatteryThat’s My App - Running in Your Background - Draining Your Battery
That’s My App - Running in Your Background - Draining Your Battery
 
Mobile Web 5.0
Mobile Web 5.0Mobile Web 5.0
Mobile Web 5.0
 
Persistent Data Structures And Managed References
Persistent Data Structures And Managed ReferencesPersistent Data Structures And Managed References
Persistent Data Structures And Managed References
 
Mobile Development 101
Mobile Development 101Mobile Development 101
Mobile Development 101
 
RIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWTRIAs Done Right: Grails, Flex, and EXT GWT
RIAs Done Right: Grails, Flex, and EXT GWT
 
Eclipse @eBay 2009
Eclipse @eBay 2009Eclipse @eBay 2009
Eclipse @eBay 2009
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
 
Eclipse@eBay
Eclipse@eBayEclipse@eBay
Eclipse@eBay
 

Dernier

Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Dipal Arora
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
dlhescort
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
lizamodels9
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
dlhescort
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
dollysharma2066
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
Abortion pills in Kuwait Cytotec pills in Kuwait
 

Dernier (20)

Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
Phases of negotiation .pptx
 Phases of negotiation .pptx Phases of negotiation .pptx
Phases of negotiation .pptx
 
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
Russian Call Girls In Gurgaon ❤️8448577510 ⊹Best Escorts Service In 24/7 Delh...
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
 
A DAY IN THE LIFE OF A SALESMAN / WOMAN
A DAY IN THE LIFE OF A  SALESMAN / WOMANA DAY IN THE LIFE OF A  SALESMAN / WOMAN
A DAY IN THE LIFE OF A SALESMAN / WOMAN
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
 
Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1Katrina Personal Brand Project and portfolio 1
Katrina Personal Brand Project and portfolio 1
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Cracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptxCracking the Cultural Competence Code.pptx
Cracking the Cultural Competence Code.pptx
 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabiunwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
unwanted pregnancy Kit [+918133066128] Abortion Pills IN Dubai UAE Abudhabi
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 

Scala on Your Phone

  • 1. Scala on Your Phone: Making Mobile Development Suck Less Michael Galpin, eBay @michaelg
  • 5.
  • 7.
  • 9. @synthesize textInput; @synthesize label; @synthesize name; - (IBAction)changeGreeting:(id)sender { self.name = textInput.text; NSString *nameString = name; if([nameString length] == 0) { nameString = @"Code Camp"; } NSString *greeting = [[NSString alloc] initWithFormat:@"Hello %@!", nameString]; label.text = greeting; [greeting release]; } - (BOOL)textFieldShouldReturn:(UITextField *)theTextField { if(theTextField == textInput) { [textInput resignFirstResponder]; } return YES; } - (void)dealloc { [textInput release]; [label release]; [name release]; [super dealloc]; }
  • 10.
  • 11. Java
  • 12. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button sayButton = (Button) findViewById(R.id.say_button); sayButton.setOnClickListener(new OnClickListener(){ public void onClick(View v) { EditText nameBox = (EditText) findViewById(R.id.name); String name = nameBox.getText().toString(); TextView greeting = (TextView) findViewById(R.id.greeting); greeting.setText("Hello " + name); } }); }
  • 13. Scala
  • 14. override def onCreate(savedInstanceState:Bundle){ import R.id._ super.onCreate(savedInstanceState) setContentView(R.layout.main) val sayButton = findViewById(say_button).asInstanceOf[Button] sayButton.setOnClickListener( () => { val user = findViewById(name).asInstanceOf[EditText].text findViewById(greeting).asInstanceOf[TextView].text = "Hello " + user }) }
  • 16. Closures • Strongly typed handlers • Forget one-method interfaces • Lexical scoping
  • 17. Closures • Strongly typed handlers • Forget one-method interfaces • Lexical scoping val computedValue = parseInt(findViewById(foo).asInstanceOf[EditText].text) this.post( () => { val url = new URL("http://foo.com?qs=" + computedValue) Source.fromStream(url.openStream).getLines.foreach(findViewById(results).text += _) }) mainMenu.onClick = (item:MenuItem) => { startActivity(item.activity) }
  • 18. Getters, Setters, Updates mapImage.alpha = if (topLevelGroup.searchButton.clickable) BLENDED else OPAQUE allTiles(selectedTileIndex) = throbberImageView
  • 19. Operators resultsLabelView += "Read more..." keywordInput -= eventListener mainMenu ++ fileMenuItems
  • 20. Traits class SearchDetailsActivity extends Activty with JsonParser, Trackable
  • 21. XML val results = for (suggested <- responseXml"Suggested"){ yield Term(sugested"Term" text, suggested"Priority" text) } nextNode match { case <code>{txt}</code> => this.status = parseInt(txt) case <state>{txt}</state> => this.state = txt case _ => }
  • 23. * Compiler Dex Compiler Compress Source Code Class files Dex File APK
  • 24. Implicits object Activity{ implicit def funcToClicker1(f:_root_.android.view.View => Unit):OnClickListener = new OnClickListener(){ def onClick(v:_root_.android.view.View)=f.apply(v)} implicit def funcToClicker0(f:() => Unit):OnClickListener = new OnClickListener() { def onClick(v:_root_.android.view.View)=f.apply} implicit def funcToLongClicker0(f:() => Boolean):OnLongClickListener = new OnLongClickListener() { def onLongClick(v:_root_.android.view.View) = f.apply} implicit def funcToLongClicker1(f:_root_.android.view.View => Boolean):OnLongClickListener = new OnLongClickListener() { def onLongClick(v:_root_.android.view.View) = f.apply(v)} implicit def viewToRichView(v:_root_.android.view.View):scala.android.view.View = new scala.android.view.View(v) implicit def richViewToView(view:scala.android.view.View):_root_.android.view.View = view.base }
  • 25. Bag o’ Tricks class ViewGroup(base:_root_.android.view.ViewGroup) extends View(base){ object views{ def +=(v:_root_.android.view.View){ base.addView(v) } def apply(index:Int) = new { def update(v:_root_.android.view.View) = base.addView(index,v) } } ... }
  • 26. Bag o’ Tricks class ViewGroup(base:_root_.android.view.ViewGroup) extends View(base){ object views{ def +=(v:_root_.android.view.View){ base.addView(v) } def apply(index:Int) = new { def update(v:_root_.android.view.View) = base.addView(index,v) } } ... } myGroup.views += someOtherView myGroup.views(3) = yetAnotherView
  • 27. Scala on Android • More Correct • More Concise • Simpler • Perfect Fit
  • 30.
  • 31.
  • 32.