User Tools

Site Tools


sample_code:volume_box

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
sample_code:volume_box [2016/08/27 22:28]
196.103.199.158
sample_code:volume_box [2017/06/13 05:03] (current)
Line 1: Line 1:
 **Volume Box** **Volume Box**
  
- [[ http://mycode.ucoz.net/files/volume_box_v1.spk|Here]] is the spk+ [[ http://mycode.coolpage.biz/web/spk/VolumeBox_v2.spk|Here]] is the spk
 . .
 <code JavaScript Volume box.js> <code JavaScript Volume box.js>
-//Global variables +//Called when application is started
-var music = app.GetVolume("music") +function OnStart() 
-var alarm = app.GetVolume("alarm"+
-var notification = app.GetVolume("notification"+    app.SetOrientation("Portrait"); 
-var system = app.GetVolume("system"+    //Create a layout with objects vertically centered
-var ring = app.GetVolume("ring"+    lay = app.CreateLayout("linear", "TopCenter,FillXY"); 
-var dtmf = app.GetVolume("dtmf"+    lay.SetBackColor("#33ffffff"); 
-var voicecall = app.GetVolume("voicecall"+    //Create Top Layout 
-var other = app.GetVolume("other"+    lay1 = app.CreateLayout("Linear", "Horizontal"
-//Called when application is started. +    lay1.SetSize(1, .1); 
-function OnStart()  +    lay1.SetBackColor("#428544"); 
-{  +    //Create a text label and add it to layout
-       app.SetOrientation("Portrait"+    txt = app.CreateText("Volume Box"); 
-       //Create a layout with objects vertically centered+    txt.SetTextColor("#FFFFFF"); 
-    lay = app.CreateLayout( "linear", "TopCenter,FillXY" );    +    txt.SetTextSize(30); 
-      lay.SetBackColor("#33ffff00") +    lay1.AddChild(txt); 
-     //Create Top Layout +    //Set the menu items 
-      lay1 =app.CreateLayout("Linear","Horizontal"+    menu = app.SetMenu("About,Exit"); 
-    lay1.SetSize(1,.1) +    lay.AddChild(lay1); 
-    lay1.SetBackColor("#4285F4") +    //Create a text label and add it to layout
- //Create a text label and add it to layout+    txt1 = app.CreateText("Volume Box"); 
-    txt = app.CreateText( "Volume Box" ); +    txt1.SetTextColor("#00FF00"); 
-    txt.SetTextColor("#FFFFFF"+    txt1.SetTextSize(32); 
-    txt.SetTextSize( 30 ); +    lay.AddChild(txt1); 
-    lay1.AddChild( txt ); +    //Create volume bar and add to layout.  
-     +    skbVol1 = app.CreateSeekBar(0.8,1); 
-     //Set the menu items +    skbVol1.SetOnTouch(skbVol_OnTouch); 
-     menu = app.SetMenu("About,Exit"+    skbVol1.SetRange(1.0); 
-  +    lay.AddChild(skbVol1); 
-     lay.AddChild(lay1) +    //Create a text label and add it to layout
-     +    txt2 = app.CreateText(""); 
-      //Create a text label and add it to layout+    txt2.SetTextColor("#CCFF00"
-    txt1 = app.CreateText( "Volume Box" ); +    txt2.SetTextSize(20); 
-    txt1.SetTextColor("#00FF00"+    lay.AddChild(txt2); 
-    txt1.SetTextSize( 32 ); +    //Create volume bar and add to layout.  
-    lay.AddChild( txt1); +    skbVol2 = app.CreateSeekBar(0.8,1); 
-       //Create volume bar and add to layout.  +    skbVol2.SetOnTouch(skbVol_OnTouch1); 
-    skbVol = app.CreateSeekBar( 0.8, -1 );  +    skbVol2.SetRange(1.0); 
-    //skbVol.SetMargins( 0, 0.05, 0, 0 );  +    lay.AddChild(skbVol2); 
-    skbVol.SetOnTouch( skbVol_OnTouch );  +    //Create a text label and add it to layout
-    skbVol.SetRange( 1.);  +    txt3 = app.CreateText("Alarm"); 
-    +    txt3.SetTextColor("#FFFF00"); 
-    lay.AddChild( skbVol )  +    txt3.SetTextSize(20); 
-     skbVol.SetValue(music) +    lay.AddChild(txt3);
-      //Create a text label and add it to layout+
-    txt2 = app.CreateText( "Music"+" "+music*100+"%" ); +
-    txt2.SetTextColor("#CCFF00"+
-    txt2.SetTextSize( 20 ); +
-    lay.AddChild( txt2 +
-         //Create volume bar and add to layout.  +
-    skbVol = app.CreateSeekBar( 0.8, -);  +
-    //skbVol.SetMargins( 0, 0.05, 0, 0 );  +
-    skbVol.SetOnTouch( skbVol_OnTouch1 );  +
-    skbVol.SetRange( 1.0 );  +
-    skbVol.SetValue( alarm );  +
-    lay.AddChild( skbVol +
-    //Create a text label and add it to layout+
-    txt3 = app.CreateText( "Alarm" ); +
-    txt3.SetTextColor("#FFFF00"+
-    txt3.SetTextSize( 20 ); +
-    lay.AddChild( txt3 ); +
-   +
-        //Create volume bar and add to layout.  +
-    skbVol = app.CreateSeekBar( 0.8, -1 );  +
-    //skbVol.SetMargins( 0, 0.05, 0, 0 );  +
-    skbVol.SetOnTouch( skbVol_OnTouch2 );  +
-    skbVol.SetRange( 1.0 );  +
-    skbVol.SetValue( notification );  +
-    lay.AddChild( skbVol ) +
-       //Create a text label and add it to layout. +
-    txt4 = app.CreateText( "Notification" ); +
-    txt4.SetTextColor("#00FFFF"+
-    txt4.SetTextSize( 20 ); +
-    lay.AddChild( txt4 ); +
-        //Create volume bar and add to layout.  +
-    skbVol = app.CreateSeekBar( 0.8, -1 );  +
-    //skbVol.SetMargins( 0, 0.05, 0, 0 );  +
-    skbVol.SetOnTouch( skbVol_OnTouch3 );  +
-    skbVol.SetRange( 1.0 );  +
-    skbVol.SetValue( system );  +
-    lay.AddChild( skbVol ) +
-       //Create a text label and add it to layout. +
-    txt5 = app.CreateText( "System" ); +
-    txt5.SetTextColor("#0000FF"+
-    txt5.SetTextSize( 20 ); +
-    lay.AddChild( txt5 ); +
-        //Create volume bar and add to layout.  +
-    skbVol = app.CreateSeekBar( 0.8, -1 );  +
-    //skbVol.SetMargins( 0, 0.05, 0, 0 );  +
-    skbVol.SetOnTouch( skbVol_OnTouch4 );  +
-    skbVol.SetRange( 1.0 );  +
-    skbVol.SetValue( ring );  +
-    lay.AddChild( skbVol )   +
-      //Create a text label and add it to layout. +
-    txt6 = app.CreateText( "Ring" ); +
-     txt6.SetTextColor("#00FFAA"+
-    txt6.SetTextSize( 20 ); +
-    lay.AddChild( txt6 ); +
-       //Create volume bar and add to layout.  +
-    skbVol = app.CreateSeekBar( 0.8, -1 );  +
-    //skbVol.SetMargins( 0, 0.05, 0, 0 );  +
-    skbVol.SetOnTouch( skbVol_OnTouch5 );  +
-    skbVol.SetRange( 1.0 );  +
-    skbVol.SetValue( dtmf );  +
-    lay.AddChild( skbVol ) +
-      //Create a text label and add it to layout. +
-    txt7 = app.CreateText( "DTMF" ); +
-     txt7.SetTextColor("#AAAA00"+
-    txt7.SetTextSize( 20 ); +
-    lay.AddChild( txt7 ); +
-        //Create volume bar and add to layout.  +
-    skbVol = app.CreateSeekBar( 0.8, -1 );  +
-    //skbVol.SetMargins( 0, 0.05, 0, 0 );  +
-    skbVol.SetOnTouch( skbVol_OnTouch6 );  +
-    skbVol.SetRange( 1.0 );  +
-    skbVol.SetValue( voicecall );  +
-    lay.AddChild( skbVol )+
  
-    //Create a text label and add it to layout+    //Create volume bar and add to layout.  
-    txt8 = app.CreateText( "Voicecall" ); +    skbVol3 = app.CreateSeekBar(0.8, - 1); 
-    txt8.SetTextColor("#FF0000"+    skbVol3.SetOnTouch(skbVol_OnTouch2); 
-    txt8.SetTextSize( 20 ); +    skbVol3.SetRange(1.0); 
-    lay.AddChild( txt8 +    lay.AddChild(skbVol3); 
-    //Add layout to app    +    //Create a text label and add it to layout. 
-    app.AddLayout( lay ); +    txt4 = app.CreateText("Notification"); 
-   setInterval("update()")+    txt4.SetTextColor("#00FFFF"); 
 +    txt4.SetTextSize(20); 
 +    lay.AddChild(txt4); 
 +    //Create volume bar and add to layout.  
 +    skbVol4 = app.CreateSeekBar(0.8, - 1); 
 +    skbVol4.SetOnTouch(skbVol_OnTouch3); 
 +    skbVol4.SetRange(1.0); 
 +    lay.AddChild(skbVol4); 
 +    //Create a text label and add it to layout. 
 +    txt5 = app.CreateText("System"); 
 +    txt5.SetTextColor("#009975"); 
 +    txt5.SetTextSize(20); 
 +    lay.AddChild(txt5); 
 +    //Create volume bar and add to layout.  
 +    skbVol5 = app.CreateSeekBar(0.8, - 1); 
 +    skbVol5.SetOnTouch(skbVol_OnTouch4); 
 +    skbVol5.SetRange(1.0); 
 +    lay.AddChild(skbVol5); 
 +    //Create a text label and add it to layout. 
 +    txt6 = app.CreateText("Ring"); 
 +    txt6.SetTextColor("#00FFAA"
 +    txt6.SetTextSize(20); 
 +    lay.AddChild(txt6); 
 +    //Create volume bar and add to layout.  
 +    skbVol6 = app.CreateSeekBar(0.8, - 1); 
 +    skbVol6.SetOnTouch(skbVol_OnTouch5); 
 +    skbVol6.SetRange(1.0); 
 +    lay.AddChild(skbVol6); 
 +    //Create a text label and add it to layout. 
 +    txt7 = app.CreateText("DTMF"); 
 +    txt7.SetTextColor("#AAAA00"); 
 +    txt7.SetTextSize(20); 
 +    lay.AddChild(txt7); 
 +    //Create volume bar and add to layout.  
 +    skbVol7 = app.CreateSeekBar(0.8, - 1); 
 +    skbVol7.SetOnTouch(skbVol_OnTouch6); 
 +    skbVol7.SetRange(1.0); 
 +    lay.AddChild(skbVol7); 
 + 
 +    //Create a text label and add it to layout. 
 +    txt8 = app.CreateText("Voicecall"); 
 +    txt8.SetTextColor("#FF0000"); 
 +    txt8.SetTextSize(20); 
 +    lay.AddChild(txt8); 
 +    //Add layout to app    
 +    app.AddLayout(lay); 
 +    setInterval(update, 1000);
 } }
  
-   //Called when user touches volume bar.  +//Called when user touches volume bar.  
-function skbVol_OnTouchvalue )  +function skbVol_OnTouch(value
-{  +
-    app.SetVolume( "music", value, value );  +    app.SetVolume("music", value, value);
-+
  
-   //Called when user touches volume bar.  
-function skbVol_OnTouch1( value )  
- 
-    app.SetVolume( "alarm", value, value ); 
 } }
  
-//Called when user touches volume bar.  +//Called when user touches volume bar.  
-function skbVol_OnTouch2value )  +function skbVol_OnTouch1(value
-{  +
-    app.SetVolume( "notification", value, value );  +    app.SetVolume("alarm", value, value); 
-+}
  
 +//Called when user touches volume bar. 
 +function skbVol_OnTouch2(value)
 +{
 +    app.SetVolume("notification", value, value);
 +}
  
-//Called when user touches volume bar.  
-function skbVol_OnTouch3( value )  
- 
-    app.SetVolume( "system", value, value );  
- 
  
-//Called when user touches volume bar.  +//Called when user touches volume bar.  
-function skbVol_OnTouch4value )  +function skbVol_OnTouch3(value
-{  +
-    app.SetVolume( "ring", value, value );  +    app.SetVolume("system", value, value); 
-+}
  
-//Called when user touches volume bar.  +//Called when user touches volume bar.  
-function skbVol_OnTouch5value )  +function skbVol_OnTouch4(value
-{  +
-    app.SetVolume( "dtmf", value, value );  +    app.SetVolume("ring", value, value); 
-+}
  
 +//Called when user touches volume bar. 
 +function skbVol_OnTouch5(value)
 +{
 +    app.SetVolume("dtmf", value, value);
 +}
  
-//Called when user touches volume bar.  + 
-function skbVol_OnTouch6value )  +//Called when user touches volume bar.  
-{  +function skbVol_OnTouch6(value
-    app.SetVolume( "voicecall", value, value );  +
-}  +    app.SetVolume("voicecall", value, value);
-//About +
-function About()  { +
-app.Alert("Created by Titus Taiti","About"+
-+
-//Update values of volume +
-function update() { +
-var music = app.GetVolume("music").toString().slice(0,4) +
-var alarm = app.GetVolume("alarm").toString().slice(0,3) +
-var notification = app.GetVolume("notification").toString().slice(0,3) +
-var system = app.GetVolume("system").toString().slice(0,3) +
-var ring = app.GetVolume("ring").toString().slice(0,3) +
-var dtmf = app.GetVolume("dtmf").toString().slice(0,4) +
-var voicecall = app.GetVolume("voicecall").toString().slice(0,4) +
-txt2.SetText("Music="+" "+music*100+"%"+
-txt3.SetText("Alarm="+" "+alarm*100+"%"+
-txt4.SetText("Notification="+" "+notification*100+"%"+
-txt5.SetText("System="+" "+system*100+"%"+
-txt6.SetText("Ring="+" "+ring*100+"%"+
-txt7.SetText("DTMF="+" "+dtmf*100+"%"+
-txt8.SetText("Voicecall="+" "+voicecall*100+"%")+
 } }
-//Called when the menu key is pressed 
-function OnMenu(item)  { 
-var item; 
-switch(item)  { 
-case "About": About() 
-             break; 
-case "Exit" : app.Exit() 
-             break; 
- default : 
-}} 
  
 +//Update values of volume
 +function update()
 +{
 +    var music = (app.GetVolume("music") * 100).toString().slice(0, 4);
 +    var alarm = (app.GetVolume("alarm") * 100).toString().slice(0, 3);
 +    var notification = (app.GetVolume("notification") * 100).toString().slice(0, 3);
 +    var system = (app.GetVolume("system") * 100).toString().slice(0, 3);
 +    var ring = (app.GetVolume("ring") * 100).toString().slice(0, 3);
 +    var dtmf = (app.GetVolume("dtmf") * 100).toString().slice(0, 4);
 +    var voicecall = (app.GetVolume("voicecall") * 100).toString().slice(0, 4);
 +    txt2.SetText("Music=" + " " + music + "%");
 +    txt3.SetText("Alarm=" + " " + alarm + "%");
 +    txt4.SetText("Notification=" + " " + notification + "%");
 +    txt5.SetText("System=" + " " + system + "%");
 +    txt6.SetText("Ring=" + " " + ring + "%");
 +    txt7.SetText("DTMF=" + " " + dtmf + "%");
 +    txt8.SetText("Voicecall=" + " " + voicecall + "%")
 +    skbVol1.SetValue(music / 100);
 +    skbVol2.SetValue(alarm / 100);
 +    skbVol3.SetValue(notification / 100);
 +    skbVol4.SetValue(system / 100);
 +    skbVol5.SetValue(ring / 100);
 +    skbVol6.SetValue(dtmf / 100);
 +    skbVol7.SetValue(voicecall / 100);
 +}
 +//Called when the menu key is pressed
 +function OnMenu(item)
 +{
 +    var item;
 +    switch (item)
 +    {
 +    case "About":
 +        About();
 +        break;
 +    case "Exit":
 +        app.Exit();
 +        break;
 +    default:
 +    }
 +}
 +//About
 +function About()
 +{
 +    var dlg = app.CreateDialog("About");
 +    var lay = app.CreateLayout("linear", "");
 +    var text = app.CreateText("", - 1, - 1, "FontAwesome,Html,Link")
 +    text.SetTextSize(25);
 +    var txt = '<p>This program is developed by <strong>Titus Taiti</strong></p> <br> <p> Get more apps and tutorials <a href="http://mycode.coolpage.biz/web/droidscript">here</a>'
 +    text.SetHtml(txt);
 +    lay.AddChild(text);
 +    dlg.AddLayout(lay);
 +    dlg.Show();
 +}
 /* /*
-Note that values of notification, system, ring and dtmf all change values on adjusting one of them.+Note that values of notification, system, ring and dtmf all change values on adjusting one of them.
 */ */
 </code> </code>
  
 +[[:|Home]]>>[[sample_code:|Sample Code]]\\
sample_code/volume_box.1472336938.txt.gz · Last modified: 2016/08/28 06:28 (external edit)