Click here to Skip to main content
14,447,974 members

Create and Run Your First Smart Watch App in 5 Minutes or Less

Rate this:
5.00 (3 votes)
Please Sign up or sign in to vote.
5.00 (3 votes)
19 Sep 2015CPOL
Build and run a real smart watch app without even downloading an SDK

Introduction

This tip describes a simple technique for building and running a smart watch app in 5 minutes or less. Lacking a smart watch, you can even simulate it in jsfiddle!

Background

Requirements:

  1. A tizen os based Gear Smart Watch, such as the Samsung Gear 2 or Gear S
  2. A very low cost 3rd Party app called APE Pad, available from the Samsung Gear App Store
  3. A PC to connect the smart watch to using USB
  4. Notepad or similar text editor

Even if you do not have a smart watch, you can follow along and run the "smart watch app" on your PC any way.

Step 1 - The First 5 Minutes

Connect your Gear watch to your PC using the USB cable. The Gear watch should show up in File Explorer under this PC. Browse to the watch's Documents Folder.

Step 2

Fire up Notepad. Enter or copy and paste the following text:

alert("Hello World")

Save the file with the name HelloWorld.txt to a convenient location such as your desktop. Notepad will not allow you to save directly to the Documents folder of your watch.

Step 3

Using File Explorer, copy and paste the HelloWorld.txt file to the Documents folder of your watch.

Step 4

  1. Run the APE Pad app on your watch.
  2. Click the Menu Button
  3. Choose File... Open
  4. Choose the file HelloWorld.txt
  5. Click the Menu Button
  6. Choose Run (at the very bottom of the menu)
  7. Your watch will display the JavaScript alert "Hello World"
  8. You should have successfully built and run a smart watch app in five minutes or less!

Image 1

Step 5, The Next 5 Minutes and Beyond

Although you can conveniently edit and run the JavaScript directly on the watch in APE Pad, you can also edit and test the JavaScript on your PC using JS Fiddle.

  1. Browse to jsfiddle.net
  2. Copy and paste the following code to the HTML pane:
           <!DOCTYPE html>
    <body>
    <p>Click the button to run JavaScript.</p>
    <button onclick="myFunction()">Try it</button>
    <p id="demo"></p>
    <script>
    function myFunction() {
    //from here
    alert("Hello World")
    //to here
    }
    </script>
    </body>  
  3. Click the jsfiddle Run button to view the Result
  4. In the Result pane, click the Try it button
  5. Click Ok on the resulting JavaScript alert

Image 2

Time to Get Creative

You can enter almost any valid JavaScript code between the lines //from here and //to here, then test it using the jsfiddle Run button, followed by clicking the Result Try It button. Define code, variables and functions between those 2 lines as needed.

Test until satisfied, then copy and paste the lines between //from here and //to here into Notepad, then save as a txt file. Then copy to the documents folder of the watch, open and run (and edit if desired) in APE Pad.

The following code will use the 4 variables LFt, LIn, WFt and WIn to calculate and display square feet, square yards and square inches. In jsfiddle, or in APE Pad, modify the variable values as desired, then run again!

var LFt = 9
var LIn = 0
var WFt = 12
var WIn = 0

var SF = (LFt + LIn/12) * (WFt + WIn/12)

r = LFt + "' " + LIn + '" x '
 + WFt + "' " + WIn + '"'
 + '\n\n= ' + SF.toFixed(2) + " sq. ft"
 + '\n= '+ (SF/9).toFixed(2) + " sq. yds"
 + '\n= '+ (SF*144).toFixed(2) + " sq. in"
alert(r)

The following code simulates a somewhat sarcastic "magic 8 ball" in either jsfiddle, or in APE Pad.

var answers = [
"As If",
" Ask Me If I Care",
" Dumb Question Ask Another",
" Forget About It",
" Get A Clue",
" In Your Dreams",
" Not",
" Not A Chance",
" Obviously",
" Oh Please",
" Sure",
" That's Ridiculous",
" Well Maybe",
" What Do You Think?",
" Whatever",
" Who Cares?",
" Yeah And I'm The Pope",
" Yeah Right",
" You Wish",
" You've Got To Be Kidding..."
]
alert("Concentrate on ypur question,\nThen Click OK")
var i = Math.random() * answers.length
i = parseInt(i,10)
alert(answers[i])

Points of Interest

Note that there are some, but actually few restrictions on the JavaScript the watches will run.

Notably, they will run the JavaScript alert() function, but not the JavaScript prompt() function.

You can even use the JavaScript Math functions as desired, such as Math.random() as shown above.

If you feel text only apps are too limited, think back to the APPLE ][ and what was possible with it using just simple applesoft basic!

History

This is the first version.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

lschauer
President OutOfNoWare
United States United States
No Biography provided

Comments and Discussions

 
Generalcorrection about prompt() function Pin
lschauer27-Sep-15 4:39
Memberlschauer27-Sep-15 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Tip/Trick
Posted 19 Sep 2015

Stats

7.2K views
2 bookmarked