]>
Commit | Line | Data |
---|---|---|
947f0963 TL |
1 | /** |
2 | * @private | |
3 | */ | |
4 | Ext.define('Ext.device.device.Cordova', { | |
5 | alternateClassName: 'Ext.device.device.PhoneGap', | |
6 | ||
7 | extend: 'Ext.device.device.Abstract', | |
8 | ||
9 | availableListeners: [ | |
10 | 'pause', | |
11 | 'resume', | |
12 | 'backbutton', | |
13 | 'batterycritical', | |
14 | 'batterylow', | |
15 | 'batterystatus', | |
16 | 'menubutton', | |
17 | 'searchbutton', | |
18 | 'startcallbutton', | |
19 | 'endcallbutton', | |
20 | 'volumeupbutton', | |
21 | 'volumedownbutton' | |
22 | ], | |
23 | ||
24 | constructor: function() { | |
25 | // We can't get the device details until the device is ready, so lets wait. | |
26 | if (Ext.isReady) { | |
27 | this.onReady(); | |
28 | } | |
29 | else { | |
30 | Ext.onReady(this.onReady, this, { single: true }); | |
31 | } | |
32 | }, | |
33 | ||
34 | /** | |
35 | * @property {String} cordova | |
36 | * Returns the version of Cordova running on the device. | |
37 | * | |
38 | * alert('Device cordova: ' + Ext.device.Device.cordova); | |
39 | */ | |
40 | ||
41 | /** | |
42 | * @property {String} version | |
43 | * Returns the operating system version. | |
44 | * | |
45 | * alert('Device Version: ' + Ext.device.Device.version); | |
46 | */ | |
47 | ||
48 | /** | |
49 | * @property {String} model | |
50 | * Returns the device's model name. | |
51 | * | |
52 | * alert('Device Model: ' + Ext.device.Device.model); | |
53 | */ | |
54 | ||
55 | /** | |
56 | * @event pause | |
57 | * Fires when the application goes into the background | |
58 | */ | |
59 | ||
60 | /** | |
61 | * @event resume | |
62 | * Fires when the application goes into the foreground | |
63 | */ | |
64 | ||
65 | /** | |
66 | * @event batterycritical | |
67 | * This event that fires when a Cordova application detects the percentage of battery | |
68 | * has reached the critical battery threshold. | |
69 | */ | |
70 | ||
71 | /** | |
72 | * @event batterylow | |
73 | * This event that fires when a Cordova application detects the percentage of battery | |
74 | * has reached the low battery threshold. | |
75 | */ | |
76 | ||
77 | /** | |
78 | * @event batterystatus | |
79 | * This event that fires when a Cordova application detects the percentage of battery | |
80 | * has changed by at least 1 percent. | |
81 | */ | |
82 | ||
83 | /** | |
84 | * @event backbutton | |
85 | * This is an event that fires when the user presses the back button. | |
86 | */ | |
87 | ||
88 | /** | |
89 | * @event menubutton | |
90 | * This is an event that fires when the user presses the menu button. | |
91 | */ | |
92 | ||
93 | /** | |
94 | * @event searchbutton | |
95 | * This is an event that fires when the user presses the search button. | |
96 | */ | |
97 | ||
98 | /** | |
99 | * @event startcallbutton | |
100 | * This is an event that fires when the user presses the start call button. | |
101 | */ | |
102 | ||
103 | /** | |
104 | * @event endcallbutton | |
105 | * This is an event that fires when the user presses the end call button. | |
106 | */ | |
107 | ||
108 | /** | |
109 | * @event volumeupbutton | |
110 | * This is an event that fires when the user presses the volume up button. | |
111 | */ | |
112 | ||
113 | /** | |
114 | * @event volumedownbutton | |
115 | * This is an event that fires when the user presses the volume down button. | |
116 | */ | |
117 | ||
118 | onReady: function() { | |
119 | var me = this, | |
120 | device = window.device; | |
121 | ||
122 | me.name = device.name || device.model; | |
123 | me.cordova = device.cordova; | |
124 | me.platform = device.platform || Ext.os.name; | |
125 | me.uuid = device.uuid; | |
126 | me.version = device.version; | |
127 | me.model = device.model; | |
128 | }, | |
129 | ||
130 | privates: { | |
131 | doAddListener: function(name) { | |
132 | var me = this; | |
133 | ||
134 | if (!me.addedListeners) { | |
135 | me.addedListeners = []; | |
136 | } | |
137 | ||
138 | if (me.availableListeners.indexOf(name) != -1 && me.addedListeners.indexOf(name) == -1) { | |
139 | // Add the listeners | |
140 | me.addedListeners.push(name); | |
141 | ||
142 | document.addEventListener(name, function() { | |
143 | me.fireEvent(name, me); | |
144 | }); | |
145 | } | |
146 | ||
147 | Ext.device.Device.mixins.observable.doAddListener.apply(Ext.device.Device.mixins.observable, arguments); | |
148 | } | |
149 | } | |
150 | }); |