[SampleApp] Skeleton of a sample application demonstrating cordova API usage.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 2 Dec 2015 09:06:39 +0000 (10:06 +0100)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Wed, 2 Dec 2015 09:08:23 +0000 (10:08 +0100)
Change-Id: I17125b35f2a25b915726b6211a5f7cae9c8bb97d
Signed-off-by: Pawel Andruszkiewicz <p.andruszkie@samsung.com>
27 files changed:
.gitignore
sample/.project [new file with mode: 0644]
sample/.tproject [new file with mode: 0644]
sample/config.xml [new file with mode: 0644]
sample/css/colors.css [new file with mode: 0644]
sample/css/colors_night.css [new file with mode: 0644]
sample/css/debug.css [new file with mode: 0644]
sample/css/style.css [new file with mode: 0644]
sample/icon.png [new file with mode: 0644]
sample/images/button_active.png [new file with mode: 0644]
sample/images/button_active_alt.png [new file with mode: 0644]
sample/images/button_normal.png [new file with mode: 0644]
sample/images/button_normal_night.png [new file with mode: 0644]
sample/images/button_source.xcf [new file with mode: 0644]
sample/images/button_specialA.png [new file with mode: 0644]
sample/images/button_specialB.png [new file with mode: 0644]
sample/images/button_specialC.png [new file with mode: 0644]
sample/images/button_specialD.png [new file with mode: 0644]
sample/index.html [new file with mode: 0644]
sample/js/SimpleLogger.js [new file with mode: 0644]
sample/js/main.js [new file with mode: 0644]
sample/js/remotemenu.js [new file with mode: 0644]
sample/js/stylechooser.js [new file with mode: 0644]
sample/lib [new symlink]
sample/plugins/media/media.css [new file with mode: 0644]
sample/plugins/media/media.html [new file with mode: 0644]
sample/plugins/media/media.js [new file with mode: 0644]

index acc6e8a..b97319d 100644 (file)
@@ -23,3 +23,8 @@
 /test/.sdk_delta.info
 /test/.settings
 /test/.sign
+/sample/.build
+/sample/.rds_delta
+/sample/.sdk_delta.info
+/sample/.settings
+/sample/.sign
diff --git a/sample/.project b/sample/.project
new file mode 100644 (file)
index 0000000..f4a92c0
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>CordovaSampleApp</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.tizen.web.privilege.nature.PrivilegeBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>json.validation.builder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+               <buildCommand>
+                       <name>org.tizen.web.project.builder.WebBuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.tizen.web.privilege.nature.PrivilegeNature</nature>
+               <nature>json.validation.nature</nature>
+               <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+               <nature>org.tizen.web.project.builder.WebNature</nature>
+       </natures>
+</projectDescription>
diff --git a/sample/.tproject b/sample/.tproject
new file mode 100644 (file)
index 0000000..824eaa1
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<tproject xmlns="http://www.tizen.org/tproject">
+    <platforms>
+        <platform>
+            <name>mobile-2.4</name>
+        </platform>
+    </platforms>
+    <package>
+        <blacklist/>
+        <resFallback autoGen="true"/>
+    </package>
+</tproject>
diff --git a/sample/config.xml b/sample/config.xml
new file mode 100644 (file)
index 0000000..876d246
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://yourdomain/CordovaSampleApp" version="0.2.1" viewmodes="maximized">
+    <access origin="*"></access>
+    <tizen:application id="WfigBlWDyf.CordovaSampleApp" package="WfigBlWDyf" required_version="2.3"/>
+    <content src="index.html"/>
+    <feature name="http://tizen.org/feature/screen.size.all"/>
+    <icon src="icon.png"/>
+    <tizen:metadata key="http://samsung.com/tv/metadata/prelaunch.support" value="true"/>
+    <name>CordovaSampleApp</name>
+    <tizen:privilege name="http://tizen.org/privilege/application.launch"/>
+    <tizen:privilege name="http://tizen.org/privilege/contact.read"/>
+    <tizen:privilege name="http://tizen.org/privilege/contact.write"/>
+    <tizen:privilege name="http://tizen.org/privilege/filesystem.read"/>
+    <tizen:privilege name="http://tizen.org/privilege/filesystem.write"/>
+    <tizen:privilege name="http://tizen.org/privilege/unlimitedstorage"/>
+    <tizen:privilege name="http://tizen.org/privilege/setting"/>
+    <tizen:privilege name="http://tizen.org/privilege/package.info"/>
+    <tizen:privilege name="http://tizen.org/privilege/notification"/>
+    <tizen:privilege name="http://tizen.org/privilege/system"/>
+    <tizen:privilege name="http://tizen.org/privilege/content"/>
+    <tizen:privilege name="http://tizen.org/privilege/content.read"/>
+    <tizen:privilege name="http://tizen.org/privilege/content.write"/>
+    <tizen:privilege name="http://tizen.org/privilege/mediacapture"/>
+    <tizen:privilege name="http://tizen.org/privilege/download"/>
+    <tizen:privilege name="http://tizen.org/privilege/internet"/>
+    <tizen:privilege name="http://tizen.org/privilege/tv.inputdevice"/>
+    <tizen:profile name="tv"/>
+    <tizen:setting screen-orientation="auto-rotation" context-menu="enable" background-support="disable" encryption="disable" install-location="auto" hwkey-event="enable"/>
+</widget>
diff --git a/sample/css/colors.css b/sample/css/colors.css
new file mode 100644 (file)
index 0000000..a5386b1
--- /dev/null
@@ -0,0 +1,93 @@
+body {
+       background-color: #fdf6e3; /* solarized-base3 */
+}
+
+p {
+    color: #073642; /* solarized-base02 */     
+}
+
+div#everything {
+       background-color: #eee8d5; /* solarized-base2 */
+       border: 1px solid #657b83; /* one-pixel wide border of solarized-base00 color. */
+}
+
+div#top {
+       
+}
+
+#top h1 {
+       color: #6c71c4; /* solarized-violet */
+}
+
+#top h2 {
+       color: #002b36; /* solarized-base03 */
+}
+
+div#right_column {
+       
+}
+
+div#special_buttons {
+       background-color: #cb4b16; /* solarized-orange */
+}
+
+a.normal, a:visited.normal {
+       color: #073642;
+       background: transparent url('../images/button_normal.png') no-repeat;
+}
+
+a.special, a:visited.special {
+       color: #073642;
+}
+
+a.special.red, a:visited.special.red {
+       background: transparent url('../images/button_specialA.png') no-repeat;
+}
+
+a.special.green, a:visited.special.green {
+       background: transparent url('../images/button_specialB.png') no-repeat;
+}
+
+a.special.yellow, a:visited.special.yellow {
+       background: transparent url('../images/button_specialC.png') no-repeat;
+}
+
+a.special.blue, a:visited.special.blue {
+       background: transparent url('../images/button_specialD.png') no-repeat;
+}
+
+a.active, a:visited.active {
+       color: #002b36;
+       background: transparent url('../images/button_active.png') no-repeat;
+}
+
+a:hover, a:visited:hover {
+       background: transparent url('../images/button_active_alt.png') no-repeat;
+}
+
+#resultsLog {
+       color: #586e75; /* solarized-base01 */
+}
+
+div#footer p{
+       color: #839496; /* solarized-base0 */
+}
+
+/* colors:
+color: #002b36; / solarized-base03 /
+color: #073642; / solarized-base02 /
+color: #586e75; / solarized-base01 /
+color: #657b83; / solarized-base00 /
+color: #839496; / solarized-base0 /
+color: #93a1a1; / solarized-base1 /
+color: #eee8d5; / solarized-base2 /
+color: #fdf6e3; / solarized-base3 /
+color: #b58900; / solarized-yellow /
+color: #cb4b16; / solarized-orange /
+color: #dc322f; / solarized-red /
+color: #d33682; / solarized-magenta /
+color: #6c71c4; / solarized-violet /
+color: #268bd2; / solarized-blue /
+color: #2aa198; / solarized-cyan /
+color: #859900; / solarized-green /
+*/
\ No newline at end of file
diff --git a/sample/css/colors_night.css b/sample/css/colors_night.css
new file mode 100644 (file)
index 0000000..9a9fccf
--- /dev/null
@@ -0,0 +1,92 @@
+body {
+       background-color: #002b36; /* solarized-base03 */
+}
+
+p {
+    color: #eee8d5; /* solarized-base2 */      
+}
+
+div#everything {
+       background-color: #073642; /* solarized-base02 */
+       border: 1px solid #839496; /* one pixel wide border, solarized-base0 */
+}
+
+div#top {
+       /* no rules needed yet. */
+}
+
+#top h1 {
+       color: #cb4b16; /* solarized-orange */
+}
+
+#top h2 {
+       color: #fdf6e3; /* solarized-base3 */
+}
+
+div#right_column {
+       
+}
+
+a.normal, a:visited.normal {
+       color: #eee8d5; /* solarized-base2 */
+       background: transparent url('../images/button_normal_night.png') no-repeat;
+}
+
+/* these rules are common for EVERY special-class button: */
+a.special, a:visited.special {
+       /* this color should remain the same as in "colors.css" stylesheet: base02 */
+       /* color: #eee8d5; /* solarized-base2 */
+       color: #073642; /* solarized-base02 */
+}
+
+a.special.red, a:visited.special.red {
+       background: transparent url('../images/button_specialA.png') no-repeat;
+}
+
+a.special.green, a:visited.special.green {
+       background: transparent url('../images/button_specialB.png') no-repeat;
+}
+
+a.special.yellow, a:visited.special.yellow {
+       background: transparent url('../images/button_specialC.png') no-repeat;
+}
+
+a.special.blue, a:visited.special.blue {
+       background: transparent url('../images/button_specialD.png') no-repeat;
+}
+
+a.active, a:visited.active {
+       color: #fdf6e3; /* solarized-base3 */
+       background: transparent url('../images/button_active.png') no-repeat;
+}
+
+a:hover, a:visited:hover {
+       background: transparent url('../images/button_hover.png') no-repeat;
+}
+
+#resultsLog {
+       color: #93a1a1; /* solarized-base1 */
+}
+
+div#footer p{
+       color: #657b83; /* solarized-base00 */
+}
+
+/* colors:
+color: #002b36; / solarized-base03 /
+color: #073642; / solarized-base02 /
+color: #586e75; / solarized-base01 /
+color: #657b83; / solarized-base00 /
+color: #839496; / solarized-base0 /
+color: #93a1a1; / solarized-base1 /
+color: #eee8d5; / solarized-base2 /
+color: #fdf6e3; / solarized-base3 /
+color: #b58900; / solarized-yellow /
+color: #cb4b16; / solarized-orange /
+color: #dc322f; / solarized-red /
+color: #d33682; / solarized-magenta /
+color: #6c71c4; / solarized-violet /
+color: #268bd2; / solarized-blue /
+color: #2aa198; / solarized-cyan /
+color: #859900; / solarized-green /
+*/
\ No newline at end of file
diff --git a/sample/css/debug.css b/sample/css/debug.css
new file mode 100644 (file)
index 0000000..9349c24
--- /dev/null
@@ -0,0 +1,19 @@
+div#everything {
+       background-color: #93a1a1; /* solarized-base1 */
+}
+
+div#top {
+       background-color: #859900; /* solarized-green */
+}
+
+div#left_column {
+       background-color: #268bd2; /* solarized-blue */
+}
+
+div#right_column {
+       background-color: #6c71c4; /* solarized-violet */
+}
+
+div#footer {
+       background-color: #b58900; /* solarized-yellow */
+}
\ No newline at end of file
diff --git a/sample/css/style.css b/sample/css/style.css
new file mode 100644 (file)
index 0000000..5fae309
--- /dev/null
@@ -0,0 +1,96 @@
+* {
+    font-family: Lucida Sans, Arial, Helvetica, sans-serif;
+}
+
+p {
+       margin: 3px 10px 3px 10px;
+}
+
+div#everything {
+       width: 80%;
+       margin: 100px auto 20px auto;
+}
+
+div#content {  
+}
+
+div#top {
+       height: 120px;
+}
+
+#top h1 {
+       text-align: center;
+       font-size: 3em;
+       font-variant: small-caps;
+       margin: 10px 0px 0px 0px;
+       padding: 0px;
+       letter-spacing: 5px;
+}
+
+div#left_column {
+       width: 300px;
+       float: left;
+}
+
+div#right_column {
+       float: left;
+       margin: 0px 0px 0px 50px;
+}
+
+a.normal, a:visited.normal, a.special, a:visited.special, a.active, a:visited.active {
+       display: block;
+       width: 250px;
+       height: 40px;
+       margin: 5px 20px 5px 20px;
+       padding: 0px 0px 0px 0px;
+       line-height: 40px;
+       font-size: 16pt;
+       font-weight: bold;
+       text-decoration: none;
+       text-align: center;
+}
+
+#content p {
+}
+
+.info {
+       font-size: 1.5em;
+}
+
+#resultsLog {
+       font-family: Monospace;
+       font-size: 1.7em;
+       margin: 15px 0px 0px 3em;
+}
+
+div#footer {
+       clear: both;
+}
+
+#footer p {
+    text-align: center;
+    font-size: 1.3em;
+    margin: 0px 0px 0px 0px;
+}
+
+.name {
+       font-weight: bold;
+}
+
+@media screen and (max-width:640px){
+    div#everything {
+       width: 100%;
+       margin: 0px auto;
+    }
+    
+    div#left_column {
+       width: 50%;
+       float: left;
+    }
+    
+    div#right_column {
+       width: 50%;
+        float: left;
+       margin: 0px 0px 0px 50px;
+    }
+}
diff --git a/sample/icon.png b/sample/icon.png
new file mode 100644 (file)
index 0000000..9765b1b
Binary files /dev/null and b/sample/icon.png differ
diff --git a/sample/images/button_active.png b/sample/images/button_active.png
new file mode 100644 (file)
index 0000000..62c6daa
Binary files /dev/null and b/sample/images/button_active.png differ
diff --git a/sample/images/button_active_alt.png b/sample/images/button_active_alt.png
new file mode 100644 (file)
index 0000000..b5d180d
Binary files /dev/null and b/sample/images/button_active_alt.png differ
diff --git a/sample/images/button_normal.png b/sample/images/button_normal.png
new file mode 100644 (file)
index 0000000..0164f02
Binary files /dev/null and b/sample/images/button_normal.png differ
diff --git a/sample/images/button_normal_night.png b/sample/images/button_normal_night.png
new file mode 100644 (file)
index 0000000..5b7ec2f
Binary files /dev/null and b/sample/images/button_normal_night.png differ
diff --git a/sample/images/button_source.xcf b/sample/images/button_source.xcf
new file mode 100644 (file)
index 0000000..298521e
Binary files /dev/null and b/sample/images/button_source.xcf differ
diff --git a/sample/images/button_specialA.png b/sample/images/button_specialA.png
new file mode 100644 (file)
index 0000000..ca2ddb6
Binary files /dev/null and b/sample/images/button_specialA.png differ
diff --git a/sample/images/button_specialB.png b/sample/images/button_specialB.png
new file mode 100644 (file)
index 0000000..ffc1cb7
Binary files /dev/null and b/sample/images/button_specialB.png differ
diff --git a/sample/images/button_specialC.png b/sample/images/button_specialC.png
new file mode 100644 (file)
index 0000000..6917506
Binary files /dev/null and b/sample/images/button_specialC.png differ
diff --git a/sample/images/button_specialD.png b/sample/images/button_specialD.png
new file mode 100644 (file)
index 0000000..901edb6
Binary files /dev/null and b/sample/images/button_specialD.png differ
diff --git a/sample/index.html b/sample/index.html
new file mode 100644 (file)
index 0000000..9eba781
--- /dev/null
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<!--
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+-->
+<html>
+<head>
+    <meta charset="utf-8" />
+    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
+    <meta name="description" content="Cordova demo app"/>
+
+    <title>Tizen Cordova WebAPI Demonstration</title>
+
+    <link rel="stylesheet" type="text/css" href="css/style.css" />
+    <link rel="stylesheet" type="text/css" href="css/colors.css" />
+    <!--   
+    <link rel="stylesheet" type="text/css" href="css/debug.css" />
+     -->
+    <script type="text/javascript" src="lib/cordova.js"></script>
+    <script src="js/SimpleLogger.js"></script>
+    <script src="js/remotemenu.js"></script>
+    
+    <script src="js/stylechooser.js"></script>
+    
+    <!-- load main.js as the last one: -->
+    <script src="js/main.js"></script>
+</head>
+
+<body>
+  <div id="everything">
+    <div id="top">
+      <h1>Cordova WebAPI</h1>
+    </div>
+    <div id="content">
+      <div id="left_column">
+          <a href="#" id="btn0" class="active">Console</a>
+          <a href="#" id="btn1" class="normal">Device</a>
+          <a href="#" id="btn8" class="normal">Device Motion</a>
+          <a href="#" id="btn2" class="normal">Dialogs</a>
+          <a href="#" id="btn9" class="normal">Events</a>
+          <a href="#" id="btn3" class="normal">File</a>
+          <a href="#" id="btn4" class="normal">FileTransfer</a>
+          <a href="#" id="btn5" class="normal">Globalization</a>
+          <a href="plugins/media/media.html" id="btn6" class="normal">Media</a>
+          <a href="#" id="btn7" class="normal">Network Information</a>
+          <hr />
+          <a href="#" id="btns0" class="special red" onClick="logger.clear();">Clear log</a>
+          <a href="#" id="btns1" class="special green" onClick="window.logger.log('Button B pressed.')">Quick Access B</a>
+          <a href="#" id="btns2" class="special yellow" onClick="window.logger.log('Button C pressed.');">Quick Access C</a>
+          <a href="#" id="btns3" class="special blue" onClick="window.styleChooser.setNextStyle();">Change appearance</a>
+      </div>
+      <div id="right_column">
+        <p class="info">Commands' output:</p>
+        <p id="resultsLog">Use the buttons on the left to see some output.</p>
+      </div>
+    </div>
+    <div id="footer">
+      <footer>
+        <p>Created by <span class="name">Cordova Tizen Team</span>, 2015</p>
+      </footer>  
+    </div>
+  </div>    
+</body>
+</html>
\ No newline at end of file
diff --git a/sample/js/SimpleLogger.js b/sample/js/SimpleLogger.js
new file mode 100644 (file)
index 0000000..ba5aa15
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+// a set of functions enabling the user to display
+// some (very) simple messages in a HTML object.
+// includes logging text and time, as well as clearing logs.
+// Creates a global reference: window.logger.
+
+// @author: Adam Szczerbiak (a.szczerbiak@samsung.com)
+// created: 2015-11-24
+// last modified: 2015-11-30
+
+var SimpleLogger = {};
+SimpleLogger.TARGET_ID = 'resultsLog';
+SimpleLogger.contents = '';
+
+SimpleLogger.clear = function() {
+  this.contents = '';
+  document.getElementById(this.TARGET_ID).innerHTML = this.contents;
+};
+
+SimpleLogger.getNiceTime = function() {
+  var time, nicetime;
+  time = new Date();
+  nicetime = ('0' + time.getHours()).slice(-2) + ':'
+      + ('0' + time.getMinutes()).slice(-2) + ':'
+      + ('0' + time.getSeconds()).slice(-2);
+  return nicetime;
+};
+
+SimpleLogger.log = function(text) {
+  this.contents += text + '<br>';
+  document.getElementById(this.TARGET_ID).innerHTML = this.contents;
+  console.log(text);
+};
+
+SimpleLogger.logWithTimestamp = function(text) {
+  this.log('[' + this.getNiceTime() + '] ' + text);
+};
+
+/////////////////////////////////////////////////////////////////////////
+
+window.logger = SimpleLogger;
\ No newline at end of file
diff --git a/sample/js/main.js b/sample/js/main.js
new file mode 100644 (file)
index 0000000..25290f8
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+var deviceReady = function() {
+  window.logger.log('Device ready');
+};
+
+var init = function () {
+  window.logger.log('Main window loaded');
+  document.addEventListener('deviceready', deviceReady, true);
+  window.logger.log('Listener device ready added');
+  // register TV remote keys for controlling the application with [UP], [DOWN], [LEFT], [RIGHT] keys:
+  window.stateController.registerTizenRemoteKeys();
+};
+
+window.onload = init;
diff --git a/sample/js/remotemenu.js b/sample/js/remotemenu.js
new file mode 100644 (file)
index 0000000..5e1625c
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+// a set of functions utilizing Tizen's TVInputDevice API.
+// Made to enable controlling the application via remote control
+// (especially important on TVs with disabled mouse support).
+// Creates a global reference: window.stateController.
+// @author: Adam Szczerbiak (a.szczerbiak@samsung.com)
+// created: 2015-11-24
+// last modified: 2015-11-30
+
+// remote control initialization function is called here on boot:
+// (@TODO) (@TODO_revised: not needed/?)
+// not needed. All the submodules' init functions will now be called
+// from main_init() method in main.js file.
+
+var stateController = {};
+stateController.NORMAL_BUTTONS_COUNT = 8;
+stateController.TOTAL_BUTTONS_COUNT = stateController.NORMAL_BUTTONS_COUNT;
+stateController.activeButtonNo = 0;
+
+// a helper function returning the full ID of currently active button:
+stateController.getActiveButtonID = function() {
+  var btnNo, activeButtonID;
+  btnNo = this.activeButtonNo;
+  if (btnNo < this.NORMAL_BUTTONS_COUNT) {
+    activeButtonID = 'btn' + btnNo;
+  } else {
+    // currently selected button is a special button.
+    // these are numbered independently, starting from 0.
+    // to get special button's ID one needs to substract
+    // normal buttons count from current menu position:
+    btnNo -= this.NORMAL_BUTTONS_COUNT;
+    activeButtonID = 'btns' + btnNo;
+  }
+  return activeButtonID;
+};
+
+stateController.updateButtonsState = function() {
+  var i, normalButtonID;
+  // change the class of every "normal" button to "normal":
+  if (this.NORMAL_BUTTONS_COUNT > 0) {
+    for (i = 0; i < this.NORMAL_BUTTONS_COUNT; i++) {
+      normalButtonID = 'btn' + i;
+      document.getElementById(normalButtonID).className = 'normal';
+      // logger.log('Set button id\'ed: ' + normalButtonID + ' to "normal".');
+    }
+  }
+
+  /*
+   * Decided to treat 'special colorful' buttons differently, they may not be
+   * accessed from the menu. Press A/B/C/D buttons on remote controller to use
+   * them. // change the class of every "special" button to "special":
+   * if(this.SPECIAL_BUTTONS_COUNT > 0) { for(i = 0; i <
+   * this.SPECIAL_BUTTONS_COUNT; i++) { specialButtonID = 'btns' + i;
+   * document.getElementById(specialButtonID).className = 'special'; //
+   * logger.log('set button id\'ed: ' + specialButtonID + ' to "special".'); } }
+   */
+
+  // change the class of currently active menu button to "active":
+  document.getElementById(this.getActiveButtonID()).className = 'active';
+
+  // logger.log('set button id\'ed: ' + activeButtonID + ' to "active".');
+};
+
+stateController.selectNextMenuItem = function() {
+  // select next menu item:
+  this.activeButtonNo += 1;
+
+  // but keep it in range [0, TOTAL_BUTTONS_COUNT-1]:
+  this.activeButtonNo %= this.TOTAL_BUTTONS_COUNT;
+
+  // redraw the menu:
+  this.updateButtonsState();
+
+  // logger.log('Active button: ' + this.activeButtonNo);
+};
+
+stateController.selectPrevMenuItem = function() {
+  // select previous menu item:
+  // similar to "-=1", but allows for modular arithmetics:
+  this.activeButtonNo += (this.TOTAL_BUTTONS_COUNT - 1);
+
+  // but keep it in range [0, TOTAL_BUTTONS_COUNT-1]:
+  this.activeButtonNo %= this.TOTAL_BUTTONS_COUNT;
+
+  // redraw the menu:
+  this.updateButtonsState();
+
+  // logger.log('Active button: ' + this.activeButtonNo);
+};
+
+stateController.invokeActiveButtonAction = function() {
+  var activeButtonID = this.getActiveButtonID();
+  document.getElementById(activeButtonID).click();
+};
+
+stateController.invokeSpecialButtonAction = function(specialButtonID) {
+  document.getElementById(specialButtonID).click();
+};
+
+// TizenTV remote control interface:
+stateController.registerTizenRemoteKeys = function() {
+  if (!tizen.tvinputdevice) {
+    window.logger.log('This is not a TV, skipping remote support...');
+    return;
+  }
+
+  window.logger.log('Adding a TV Remote support...');
+  // these are not present on the emulator:
+  // tizen.tvinputdevice.registerKey('Enter');
+  // tizen.tvinputdevice.registerKey('Back');
+  tizen.tvinputdevice.registerKey('ChannelUp');
+  tizen.tvinputdevice.registerKey('ChannelDown');
+  tizen.tvinputdevice.registerKey('ColorF0Red');
+  tizen.tvinputdevice.registerKey('ColorF1Green');
+  tizen.tvinputdevice.registerKey('ColorF2Yellow');
+  tizen.tvinputdevice.registerKey('ColorF3Blue');
+  window.addEventListener('keydown', function(keyEvent) {
+    if (keyEvent.keyCode === 37) { // left arrow
+      window.logger.log('ArrowLeft was pressed.');
+    } else if (keyEvent.keyCode === 38) { // UP arrow
+      stateController.selectPrevMenuItem();
+    } else if (keyEvent.keyCode === 39) { // right arrow
+      stateController.invokeActiveButtonAction();
+    } else if (keyEvent.keyCode === 40) { // arrow down
+      stateController.selectNextMenuItem();
+    } else if (keyEvent.keyCode === 427) { // ChannelUp: keycode 427
+      window.logger.log('Channel UP was pressed!');
+      // no idea what to do with these... may come in handy later.
+    } else if (keyEvent.keyCode === 428) { // ChannelDown: keycode 428
+      window.logger.log('Channel DOWN was pressed!');
+    }
+    // please note that there is no ENTER key support on this tizenTV
+    // else if(keyEvent.keyCode === 13) {
+    // logger.log('ENTER key was pressed.');
+    // }
+    // else if(keyEvent.keyCode === 10009) {
+    // log('BACK key was pressed.');
+    // }
+    else if (keyEvent.keyCode === 403) { // the red "A" button - keycode 403
+      stateController.invokeSpecialButtonAction('btns0');
+    } else if (keyEvent.keyCode === 404) { // the green "B" button - keycode
+                                            // 404
+      stateController.invokeSpecialButtonAction('btns1');
+    } else if (keyEvent.keyCode === 405) { // the yellow "C" button, keycode
+                                            // 405
+      stateController.invokeSpecialButtonAction('btns2');
+    } else if (keyEvent.keyCode === 406) { // the blue "D" button - keycode:
+                                            // 406
+      stateController.invokeSpecialButtonAction('btns3');
+    }
+  });
+
+  window.logger.log('EventListener has been added.');
+};
+
+//////////////////////////////////////////////////////////////////////////////////////
+
+// prints all the supported remote keys.
+// @requires privilege http://tizen.org/privilege/tv.inputdevice
+// post: a list of all supported remote keys is printed using SimpleLogger
+// interface.
+function printAllSupportedRemoteKeys() {
+  var keyCodes, supportedKeys, i;
+  keyCodes = {};
+  supportedKeys = tizen.tvinputdevice.getSupportedKeys();
+  if (supportedKeys.length > 0) {
+    window.logger.log('The list of all supported remote keys ('
+        + supportedKeys.length + '):');
+    for (i = 0; i < supportedKeys.length; i++) {
+      keyCodes[supportedKeys[i].name] = supportedKeys[i].code;
+      window.logger.log(supportedKeys[i].name + ': ' + supportedKeys[i].code);
+    }
+    window.logger.log('--- End of supported remote keys list ---');
+  } else {
+    window.logger.log('No supported keys have been found.');
+  }
+}
+//////////////////////////////////////////////////////////////////////////////////////
+window.stateController = stateController;
\ No newline at end of file
diff --git a/sample/js/stylechooser.js b/sample/js/stylechooser.js
new file mode 100644 (file)
index 0000000..288b9da
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+// a subsystem enabling dynamically changing CSS file with colours definitions.
+// its set of functions enable to either toggle through a predefined list of CSS files
+// or load an arbitrarily chosen one directly.
+// Creates a global reference: window.styleChooser.
+
+// @author: Adam Szczerbiak (a.szczerbiak@samsung.com)
+// created: 2015-11-30
+// last modified: 2015-11-30
+
+var styleChooser = {};
+styleChooser.STYLES = ['css/colors.css', 'css/colors_night.css'];
+styleChooser.STYLES_COUNT = styleChooser.STYLES.length;
+styleChooser.current = 0;
+styleChooser.debugLevel = 0; // set this to 1 to enable debug info outputting.
+
+// a function to change the CSS stylesheet with colour definitions.
+// it enables changing the "look and feel" of the application.
+// pre: cssFileName is a valid, existing css file name
+// given as either an absolute or relative to index.html path.
+// post: instead of colors.css, the file provided as an argument gets loaded
+// dynamically.
+styleChooser.changeCSS = function(cssFileName) {
+  var oldLink, newLink;
+
+  // whenever the debug info is needed:
+  if (this.debugLevel > 0) {
+    window.logger.log('styleChooser.changeCSS(' + cssFileName
+        + ') has been called.');
+  }
+
+  oldLink = document.getElementsByTagName('link').item(1);
+
+  /*
+   * // this function prints all the document's CSS files. // use this to
+   * determine the index of "colors.css" file if needed. for(var i = 0; i <
+   * oldLink.length; i++) { window.logger.log(oldLink.item(i).href); }
+   */
+
+  newLink = document.createElement('link');
+  newLink.setAttribute('REL', 'STYLESHEET');
+  newLink.setAttribute('type', 'text/css');
+  newLink.setAttribute('href', cssFileName);
+
+  document.getElementsByTagName('head').item(0).replaceChild(newLink, oldLink);
+
+  if (this.debugLevel > 0) {
+    window.logger.log('CSS style: ' + cssFileName
+        + ' has been set successfully.');
+  }
+};
+
+// a method to select next style from a list of predefined CSS files.
+// post: next CSS style from a list (this.STYLES) is loaded dynamically into
+// index.html's <head> section,
+// inner variables (namely this.current) are updated to reflect the new state.
+styleChooser.setNextStyle = function() {
+  var nextStyleIndex;
+
+  if (this.debugLevel > 0) {
+    // inform the user about this action (debug info):
+    window.logger.log('styleChooser.setNextStyle() has been called.');
+  }
+
+  // set styleChooser.current to next style from the list:
+  nextStyleIndex = (this.current + 1) % this.STYLES_COUNT;
+
+  // update index.html's head to reflect this change:
+  this.changeCSS(this.STYLES[nextStyleIndex]);
+  this.current = nextStyleIndex;
+};
+
+///////////////////////////////////////////////////////////////////////////////////////////////////
+
+// make the reference to this object global, so that it may be accessed from
+// other units:
+window.styleChooser = styleChooser;
\ No newline at end of file
diff --git a/sample/lib b/sample/lib
new file mode 120000 (symlink)
index 0000000..398ff21
--- /dev/null
@@ -0,0 +1 @@
+../src/lib
\ No newline at end of file
diff --git a/sample/plugins/media/media.css b/sample/plugins/media/media.css
new file mode 100644 (file)
index 0000000..1e82c72
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#progressBar {
+   border:1px solid #aaa;
+   color:#34baa4;
+   height:20px;
+}
+
+#progress {
+   background-color:#b53e3e;
+   height:20px;
+   display:inline-block;
+}
+
+input {
+    width:70%;
+}
+
+#player {
+    width: 100%;
+}
+
+#left {
+    width: 80%;
+    float: left;
+}
+
+#right {
+    width: 20%;
+    float:left;
+}
+
+#reload {
+    width:30%
+}
+
+input[type=range]
+{
+    writing-mode: bt-lr; /* IE */
+    -webkit-appearance: slider-vertical; /* WebKit */
+    width: 100%;
+    height: 100px;
+    background-color: red;
+    margin: 0px auto;
+}
+
+#back {
+    display:block;
+    color: #073642;
+    background: transparent url('../../images/button_normal.png') no-repeat;
+    width: 250px;
+    height: 40px;
+    margin: 5px 20px 5px 20px;
+    padding: 0px 0px 0px 0px;
+    line-height: 40px;
+    font-size: 16pt;
+    font-weight: bold;
+    text-decoration: none;
+    text-align: center;
+}
+
+.control {
+    width:10%;
+    height:20px;
+}
diff --git a/sample/plugins/media/media.html b/sample/plugins/media/media.html
new file mode 100644 (file)
index 0000000..54fbfa0
--- /dev/null
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<!--
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+-->
+<html>
+    <head>
+        <title>Media Sample App</title>
+        <meta charset="UTF-8">
+        <meta name="viewport" content="width=device-width, initial-scale=1.0">
+        <link rel="stylesheet" type="text/css" href="../../css/style.css" />
+        <link rel="stylesheet" type="text/css" href="../../css/colors.css" />
+        <link rel="stylesheet" type="text/css" href="media.css" />
+        <script type="text/javascript" src="../../lib/cordova.js"></script>
+        <script src="../../js/SimpleLogger.js"></script>
+        <script src="media.js"></script>
+    </head>
+    <body>
+        <div id="wrapper">
+            <div id="player">
+              <div id="left">  
+                <div id="playerInput">
+                    <span>Filename: </span>
+                    <input id="inputFile" value="http://cordova.apache.org/downloads/BlueZedEx.mp3" type="text">
+                </div>
+                <div id="progressBar">
+                    <span id="progress"></span>
+                </div>
+                <div id="playerControl">
+                    <button class="control" id="play" onclick="play();" >|></button>
+                    <button class="control" onclick="stop();" >|_|</button>
+                    <button class="control" onclick="recordAudio();" >O</button>
+                    <button class="control" id="reload" onclick="create();">Reload</button>
+                </div>
+              </div>
+              <div id="right">  
+                <input id="inputFile2" value="0" type="range" min="0" max="10" step="1">
+              </div>
+            </div>
+            <div >
+                <p class="info">Commands' output:</p>
+                <p id="resultsLog">Use the buttons on the left to see some output.</p>
+            </div>
+            <a id="back" href="../../index.html" >Back</a>
+        </div>
+    </body>
+</html>
diff --git a/sample/plugins/media/media.js b/sample/plugins/media/media.js
new file mode 100644 (file)
index 0000000..157df5d
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+var deviceReady = function() {
+  window.logger.log('Device ready');
+};
+
+var init = function () {
+  window.logger.log('Media window loaded');
+  document.addEventListener('deviceready', deviceReady, true);
+  window.logger.log('Listener device ready added');
+};
+
+window.onload = init;
+
+var success = function() {
+  window.logger.log('succes');
+};
+
+var error = function(e) {
+  window.logger.log(e);
+};
+
+var media;
+var myinterval;
+
+function status(s, pos) {
+  window.logger.log('status: ' + s + ', pos: ' + pos);
+  if (s === Media.MEDIA_STOPPED) {
+    window.logger.log('clearing interval');
+    clearInterval(myinterval);
+  }
+}
+
+function create() {
+  var file = document.getElementById('inputFile').value;
+  window.logger.log(file);
+  try {
+    media = new Media(file, success, error, status);
+    window.logger.log('Media: ' + media);
+  } catch (e) {
+    window.logger.log(e);
+  }
+}
+
+var clicked = false;
+
+function updateProgress() {
+  if (!media) {
+    return;
+  }
+
+  window.logger.log('update progress');
+  var progress = document.getElementById('progress'), value = 0;
+
+  media.getCurrentPosition(function(pos) {
+    window.logger.log('Get current position success 100 / ' + media.duration + " * "
+        + pos);
+    if (pos > 0) {
+      value = Math.floor((100 / media.getDuration()) * pos);
+    }
+    progress.style.width = value + '%';
+    window.logger.log('width: ' + progress.style.width);
+  });
+}
+
+function play() {
+  clicked = !clicked;
+  var playBtn = document.getElementById('play');
+  if (clicked) {
+    playBtn.textContent = '||';
+    window.logger.log('Playing: ');
+    try {
+      media.play();
+      myinterval = setInterval(updateProgress, 100);
+    } catch (e) {
+      window.logger.log('Error ' + e);
+    }
+  } else {
+    playBtn.textContent = '|>';
+    window.logger.log('Pausing: ');
+    try {
+      media.pause();
+    } catch (e) {
+      window.logger.log("Error " + e);
+    }
+  }
+}
+
+function stop() {
+  window.logger.log('clearing interval');
+  clearInterval(myinterval);
+  media.stop();
+  var playBtn = document.getElementById('play');
+  playBtn.textContent = '|>';
+  window.logger.log('play released');
+}
+
+function release() {
+  media.release();
+  window.logger.log('media released');
+}
+
+function getPos() {
+  window.logger.log('getPos');
+  media.getCurrentPosition(function(pos) {
+    window.logger.log(pos);
+    alert(pos);
+  }, function(err) {
+    window.logger.log(err);
+    alert(err);
+  });
+}
+
+function setPos() {
+  var pos = document.getElementById('setPosValue').value;
+  window.logger.log('setPos');
+  media.seekTo(pos);
+}
+
+function setVolume() {
+  var volume = document.getElementById('setVolValue').value;
+  window.logger.log('setVol: ' + volume);
+  media.setVolume(volume);
+}
+
+function expand() {
+  window.logger.log('expand');
+  var progress = document.getElementById('progress');
+  window.logger.log('width: ' + progress.style.width);
+  progress.style.width = 40 + '%';
+}
+
+function recordAudio() {
+  window.logger.log('recordAudio');
+  media.startRecord();
+}
+
+function stopRecAudio() {
+  window.logger.log('stopRecord');
+  media.stopRecord();
+}