├── .classpath
├── .gitignore
├── AndroidManifest.xml
├── LICENSE-GPL-2
├── README.md
├── libs
├── android-support-v4.jar
└── simplecontentprovider.jar
├── proguard.cfg
├── project.properties
├── res
├── drawable-hdpi
│ ├── ic_allapps.png
│ ├── ic_allapps_pressed.png
│ └── ic_launcher.png
├── drawable-mdpi
│ ├── ic_allapps.png
│ ├── ic_allapps_pressed.png
│ └── ic_launcher.png
├── drawable
│ └── all_apps_button_icon.xml
├── layout
│ ├── launcher_item.xml
│ ├── main.xml
│ └── password.xml
├── menu
│ └── main.xml
├── values
│ └── strings.xml
└── xml
│ └── preferences.xml
└── src
├── com
├── example
│ └── android
│ │ └── home
│ │ └── ApplicationInfo.java
└── google
│ └── zxing
│ └── integration
│ └── android
│ ├── IntentIntegrator.java
│ └── IntentResult.java
└── edu
└── mit
└── mobile
└── android
└── demomode
├── DemoMode.java
├── HomescreenProvider.java
├── LauncherItem.java
└── Preferences.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin/
2 | gen/
3 | deploy/
4 | .project
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
14 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/LICENSE-GPL-2:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Demo Mode
2 | =========
3 |
4 | Free kiosk or demo mode for Android.
5 |
6 | Demo Mode is an Android homescreen replacement that lets you deploy devices in
7 | the field without worrying about people being distracted by the other apps or
8 | other features on the phone. A restricted set of apps can easily be placed on
9 | the homescreen and protected by an unlock code.
10 |
11 | The default password is `meldemo` and can be changed interactively in the
12 | settings or by editing `res/xml/preferences.xml` in the source. You should
13 | probably change it; the QR code provisioner will copy your password to all
14 | the devices for you so you only need to enter it once.
15 |
16 | Provisioning
17 | ------------
18 |
19 | One device can be configured and its configuration can be shared to provision
20 | multiple devices by way of a QR code. This allows for provisioning in
21 | environments without a network connection and without the need for a central
22 | provisioning server.
23 |
24 | Currently, the provisioner copies the following:
25 |
26 | * password
27 | * homescreen configuration
28 |
29 | Demo Mode and the [ZXing barcode reader][zxing] must first be installed on each
30 | device to use this functionality.
31 |
32 | Disclaimer
33 | ----------
34 |
35 | While Demo Mode makes every attempt to restrict the device, Android is an open
36 | ecosystem and individual devices will be more or less possible to restrict. For
37 | example, HTC's Sense UI has a bug in it that make it possible to get at a
38 | standard homescreen when the device reboots. This is not something that one can
39 | easily workaround, but is also not something that a person using the device
40 | for a short period of time would commonly encounter.
41 |
42 | This tool is designed to help steer the focus of the device's usage toward a
43 | single set of applications and is not designed to be an entirely foolproof
44 | lock-down mechanism.
45 |
46 | Building
47 | --------
48 |
49 | Demo Mode requires [SimpleContentProvider][simplecontentprovider]. A
50 | pre-compiled copy comes with this app for convenience, but one can easily link
51 | it in via source.
52 |
53 | License
54 | -------
55 | Android Demo Mode
56 | Copyright (C) 2012-2013 [MIT Mobile Experience Lab][mel]
57 |
58 | This program is free software; you can redistribute it and/or
59 | modify it under the terms of the GNU General Public License Version 2
60 | as published by the Free Software Foundation.
61 |
62 | This program is distributed in the hope that it will be useful,
63 | but WITHOUT ANY WARRANTY; without even the implied warranty of
64 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65 | GNU General Public License for more details.
66 |
67 | You should have received a copy of the GNU General Public License
68 | along with this program. If not, see .
69 |
70 | [zxing]: http://code.google.com/p/zxing/
71 | [simplecontentprovider]: https://github.com/mitmel/SimpleContentProvider
72 | [mel]: http://mobile.mit.edu/
73 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/simplecontentprovider.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/libs/simplecontentprovider.jar
--------------------------------------------------------------------------------
/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembers class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembers class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers class * extends android.app.Activity {
30 | public void *(android.view.View);
31 | }
32 |
33 | -keepclassmembers enum * {
34 | public static **[] values();
35 | public static ** valueOf(java.lang.String);
36 | }
37 |
38 | -keep class * implements android.os.Parcelable {
39 | public static final android.os.Parcelable$Creator *;
40 | }
41 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-17
12 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_allapps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/res/drawable-hdpi/ic_allapps.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_allapps_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/res/drawable-hdpi/ic_allapps_pressed.png
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_allapps.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/res/drawable-mdpi/ic_allapps.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_allapps_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/res/drawable-mdpi/ic_allapps_pressed.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mitmel/Demo-Mode/4b5baba9d38b827f5ac52b7eeea5cde7410604e8/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable/all_apps_button_icon.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/res/layout/launcher_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
--------------------------------------------------------------------------------
/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
19 |
20 |
21 |
27 |
28 |
34 |
35 |
40 |
41 |
49 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/res/layout/password.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Demo Mode
5 | Settings
6 | Lock
7 | Unlock
8 | password
9 | Enable Demo Mode
10 | Share Config
11 | Scan Config
12 | Configure Demo Mode
13 | Incorrect password
14 |
15 |
16 |
--------------------------------------------------------------------------------
/res/xml/preferences.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/com/example/android/home/ApplicationInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.home;
18 |
19 | import android.content.ComponentName;
20 | import android.content.Intent;
21 | import android.graphics.drawable.Drawable;
22 |
23 | /**
24 | * Represents a launchable application. An application is made of a name (or title), an intent
25 | * and an icon.
26 | */
27 | public class ApplicationInfo {
28 | /**
29 | * The application name.
30 | */
31 | public CharSequence title;
32 |
33 | /**
34 | * The intent used to start the application.
35 | */
36 | public Intent intent;
37 |
38 | /**
39 | * The application icon.
40 | */
41 | public Drawable icon;
42 |
43 | /**
44 | * When set to true, indicates that the icon has been resized.
45 | */
46 | public boolean filtered;
47 |
48 | /**
49 | * Creates the application intent based on a component name and various launch flags.
50 | *
51 | * @param className the class name of the component representing the intent
52 | * @param launchFlags the launch flags
53 | */
54 | public final void setActivity(ComponentName className, int launchFlags) {
55 | intent = new Intent(Intent.ACTION_MAIN);
56 | intent.addCategory(Intent.CATEGORY_LAUNCHER);
57 | intent.setComponent(className);
58 | intent.setFlags(launchFlags);
59 | }
60 |
61 | @Override
62 | public boolean equals(Object o) {
63 | if (this == o) {
64 | return true;
65 | }
66 | if (!(o instanceof ApplicationInfo)) {
67 | return false;
68 | }
69 |
70 | final ApplicationInfo that = (ApplicationInfo) o;
71 | return title.equals(that.title) &&
72 | intent.getComponent().getClassName().equals(
73 | that.intent.getComponent().getClassName());
74 | }
75 |
76 | @Override
77 | public int hashCode() {
78 | int result;
79 | result = (title != null ? title.hashCode() : 0);
80 | final String name = intent.getComponent().getClassName();
81 | result = 31 * result + (name != null ? name.hashCode() : 0);
82 | return result;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/com/google/zxing/integration/android/IntentIntegrator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.integration.android;
18 |
19 | import java.util.Arrays;
20 | import java.util.Collection;
21 | import java.util.Collections;
22 | import java.util.List;
23 |
24 | import android.app.Activity;
25 | import android.app.AlertDialog;
26 | import android.content.ActivityNotFoundException;
27 | import android.content.DialogInterface;
28 | import android.content.Intent;
29 | import android.content.pm.PackageManager;
30 | import android.content.pm.ResolveInfo;
31 | import android.net.Uri;
32 | import android.util.Log;
33 |
34 | /**
35 | *
A utility class which helps ease integration with Barcode Scanner via {@link Intent}s. This is a simple
36 | * way to invoke barcode scanning and receive the result, without any need to integrate, modify, or learn the
37 | * project's source code.
38 | *
39 | *
Initiating a barcode scan
40 | *
41 | *
To integrate, create an instance of {@code IntentIntegrator} and call {@link #initiateScan()} and wait
42 | * for the result in your app.
43 | *
44 | *
It does require that the Barcode Scanner (or work-alike) application is installed. The
45 | * {@link #initiateScan()} method will prompt the user to download the application, if needed.
46 | *
47 | *
There are a few steps to using this integration. First, your {@link Activity} must implement
48 | * the method {@link Activity#onActivityResult(int, int, Intent)} and include a line of code like this:
49 | *
50 | *
{@code
51 | * public void onActivityResult(int requestCode, int resultCode, Intent intent) {
52 | * IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
53 | * if (scanResult != null) {
54 | * // handle scan result
55 | * }
56 | * // else continue with any other code you need in the method
57 | * ...
58 | * }
59 | * }
60 | *
61 | *
This is where you will handle a scan result.
62 | *
63 | *
Second, just call this in response to a user action somewhere to begin the scan process:
Note that {@link #initiateScan()} returns an {@link AlertDialog} which is non-null if the
71 | * user was prompted to download the application. This lets the calling app potentially manage the dialog.
72 | * In particular, ideally, the app dismisses the dialog if it's still active in its {@link Activity#onPause()}
73 | * method.
74 | *
75 | *
You can use {@link #setTitle(String)} to customize the title of this download prompt dialog (or, use
76 | * {@link #setTitleByID(int)} to set the title by string resource ID.) Likewise, the prompt message, and
77 | * yes/no button labels can be changed.
78 | *
79 | *
By default, this will only allow applications that are known to respond to this intent correctly
80 | * do so. The apps that are allowed to response can be set with {@link #setTargetApplications(Collection)}.
81 | * For example, set to {@link #TARGET_BARCODE_SCANNER_ONLY} to only target the Barcode Scanner app itself.
82 | *
83 | *
Sharing text via barcode
84 | *
85 | *
To share text, encoded as a QR Code on-screen, similarly, see {@link #shareText(CharSequence)}.
86 | *
87 | *
Some code, particularly download integration, was contributed from the Anobiit application.
88 | *
89 | * @author Sean Owen
90 | * @author Fred Lin
91 | * @author Isaac Potoczny-Jones
92 | * @author Brad Drehmer
93 | * @author gcstang
94 | */
95 | public class IntentIntegrator {
96 |
97 | public static final int REQUEST_CODE = 0x0000c0de; // Only use bottom 16 bits
98 | private static final String TAG = IntentIntegrator.class.getSimpleName();
99 |
100 | public static final String DEFAULT_TITLE = "Install Barcode Scanner?";
101 | public static final String DEFAULT_MESSAGE =
102 | "This application requires Barcode Scanner. Would you like to install it?";
103 | public static final String DEFAULT_YES = "Yes";
104 | public static final String DEFAULT_NO = "No";
105 |
106 | private static final String BS_PACKAGE = "com.google.zxing.client.android";
107 |
108 | // supported barcode formats
109 | public static final Collection PRODUCT_CODE_TYPES = list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "RSS_14");
110 | public static final Collection ONE_D_CODE_TYPES =
111 | list("UPC_A", "UPC_E", "EAN_8", "EAN_13", "CODE_39", "CODE_93", "CODE_128",
112 | "ITF", "RSS_14", "RSS_EXPANDED");
113 | public static final Collection QR_CODE_TYPES = Collections.singleton("QR_CODE");
114 | public static final Collection DATA_MATRIX_TYPES = Collections.singleton("DATA_MATRIX");
115 |
116 | public static final Collection ALL_CODE_TYPES = null;
117 |
118 | public static final Collection TARGET_BARCODE_SCANNER_ONLY = Collections.singleton(BS_PACKAGE);
119 | public static final Collection TARGET_ALL_KNOWN = list(
120 | BS_PACKAGE, // Barcode Scanner
121 | "com.srowen.bs.android", // Barcode Scanner+
122 | "com.srowen.bs.android.simple" // Barcode Scanner+ Simple
123 | // TODO add more -- what else supports this intent?
124 | );
125 |
126 | private final Activity activity;
127 | private String title;
128 | private String message;
129 | private String buttonYes;
130 | private String buttonNo;
131 | private Collection targetApplications;
132 |
133 | public IntentIntegrator(Activity activity) {
134 | this.activity = activity;
135 | title = DEFAULT_TITLE;
136 | message = DEFAULT_MESSAGE;
137 | buttonYes = DEFAULT_YES;
138 | buttonNo = DEFAULT_NO;
139 | targetApplications = TARGET_ALL_KNOWN;
140 | }
141 |
142 | public String getTitle() {
143 | return title;
144 | }
145 |
146 | public void setTitle(String title) {
147 | this.title = title;
148 | }
149 |
150 | public void setTitleByID(int titleID) {
151 | title = activity.getString(titleID);
152 | }
153 |
154 | public String getMessage() {
155 | return message;
156 | }
157 |
158 | public void setMessage(String message) {
159 | this.message = message;
160 | }
161 |
162 | public void setMessageByID(int messageID) {
163 | message = activity.getString(messageID);
164 | }
165 |
166 | public String getButtonYes() {
167 | return buttonYes;
168 | }
169 |
170 | public void setButtonYes(String buttonYes) {
171 | this.buttonYes = buttonYes;
172 | }
173 |
174 | public void setButtonYesByID(int buttonYesID) {
175 | buttonYes = activity.getString(buttonYesID);
176 | }
177 |
178 | public String getButtonNo() {
179 | return buttonNo;
180 | }
181 |
182 | public void setButtonNo(String buttonNo) {
183 | this.buttonNo = buttonNo;
184 | }
185 |
186 | public void setButtonNoByID(int buttonNoID) {
187 | buttonNo = activity.getString(buttonNoID);
188 | }
189 |
190 | public Collection getTargetApplications() {
191 | return targetApplications;
192 | }
193 |
194 | public void setTargetApplications(Collection targetApplications) {
195 | this.targetApplications = targetApplications;
196 | }
197 |
198 | public void setSingleTargetApplication(String targetApplication) {
199 | this.targetApplications = Collections.singleton(targetApplication);
200 | }
201 |
202 | /**
203 | * Initiates a scan for all known barcode types.
204 | */
205 | public AlertDialog initiateScan() {
206 | return initiateScan(ALL_CODE_TYPES);
207 | }
208 |
209 | /**
210 | * Initiates a scan only for a certain set of barcode types, given as strings corresponding
211 | * to their names in ZXing's {@code BarcodeFormat} class like "UPC_A". You can supply constants
212 | * like {@link #PRODUCT_CODE_TYPES} for example.
213 | */
214 | public AlertDialog initiateScan(Collection desiredBarcodeFormats) {
215 | Intent intentScan = new Intent(BS_PACKAGE + ".SCAN");
216 | intentScan.addCategory(Intent.CATEGORY_DEFAULT);
217 |
218 | // check which types of codes to scan for
219 | if (desiredBarcodeFormats != null) {
220 | // set the desired barcode types
221 | StringBuilder joinedByComma = new StringBuilder();
222 | for (String format : desiredBarcodeFormats) {
223 | if (joinedByComma.length() > 0) {
224 | joinedByComma.append(',');
225 | }
226 | joinedByComma.append(format);
227 | }
228 | intentScan.putExtra("SCAN_FORMATS", joinedByComma.toString());
229 | }
230 |
231 | String targetAppPackage = findTargetAppPackage(intentScan);
232 | if (targetAppPackage == null) {
233 | return showDownloadDialog();
234 | }
235 | intentScan.setPackage(targetAppPackage);
236 | intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
237 | intentScan.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
238 | startActivityForResult(intentScan, REQUEST_CODE);
239 | return null;
240 | }
241 |
242 | /**
243 | * Start an activity.
244 | * This method is defined to allow different methods of activity starting for
245 | * newer versions of Android and for compatibility library.
246 | *
247 | * @param intent Intent to start.
248 | * @param code Request code for the activity
249 | * @see android.app.Activity#startActivityForResult(Intent, int)
250 | * @see android.app.Fragment#startActivityForResult(Intent, int)
251 | */
252 | protected void startActivityForResult(Intent intent, int code) {
253 | activity.startActivityForResult(intent, code);
254 | }
255 |
256 | private String findTargetAppPackage(Intent intent) {
257 | PackageManager pm = activity.getPackageManager();
258 | List availableApps = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
259 | if (availableApps != null) {
260 | for (ResolveInfo availableApp : availableApps) {
261 | String packageName = availableApp.activityInfo.packageName;
262 | if (targetApplications.contains(packageName)) {
263 | return packageName;
264 | }
265 | }
266 | }
267 | return null;
268 | }
269 |
270 | private AlertDialog showDownloadDialog() {
271 | AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
272 | downloadDialog.setTitle(title);
273 | downloadDialog.setMessage(message);
274 | downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
275 | @Override
276 | public void onClick(DialogInterface dialogInterface, int i) {
277 | Uri uri = Uri.parse("market://details?id=" + BS_PACKAGE);
278 | Intent intent = new Intent(Intent.ACTION_VIEW, uri);
279 | try {
280 | activity.startActivity(intent);
281 | } catch (ActivityNotFoundException anfe) {
282 | // Hmm, market is not installed
283 | Log.w(TAG, "Android Market is not installed; cannot install Barcode Scanner");
284 | }
285 | }
286 | });
287 | downloadDialog.setNegativeButton(buttonNo, new DialogInterface.OnClickListener() {
288 | @Override
289 | public void onClick(DialogInterface dialogInterface, int i) {}
290 | });
291 | return downloadDialog.show();
292 | }
293 |
294 |
295 | /**
296 | *
Call this from your {@link Activity}'s
297 | * {@link Activity#onActivityResult(int, int, Intent)} method.
298 | *
299 | * @return null if the event handled here was not related to this class, or
300 | * else an {@link IntentResult} containing the result of the scan. If the user cancelled scanning,
301 | * the fields will be null.
302 | */
303 | public static IntentResult parseActivityResult(int requestCode, int resultCode, Intent intent) {
304 | if (requestCode == REQUEST_CODE) {
305 | if (resultCode == Activity.RESULT_OK) {
306 | String contents = intent.getStringExtra("SCAN_RESULT");
307 | String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
308 | byte[] rawBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTES");
309 | int intentOrientation = intent.getIntExtra("SCAN_RESULT_ORIENTATION", Integer.MIN_VALUE);
310 | Integer orientation = intentOrientation == Integer.MIN_VALUE ? null : intentOrientation;
311 | String errorCorrectionLevel = intent.getStringExtra("SCAN_RESULT_ERROR_CORRECTION_LEVEL");
312 | return new IntentResult(contents,
313 | formatName,
314 | rawBytes,
315 | orientation,
316 | errorCorrectionLevel);
317 | }
318 | return new IntentResult();
319 | }
320 | return null;
321 | }
322 |
323 |
324 | /**
325 | * Shares the given text by encoding it as a barcode, such that another user can
326 | * scan the text off the screen of the device.
327 | *
328 | * @param text the text string to encode as a barcode
329 | */
330 | public void shareText(CharSequence text) {
331 | Intent intent = new Intent();
332 | intent.addCategory(Intent.CATEGORY_DEFAULT);
333 | intent.setAction(BS_PACKAGE + ".ENCODE");
334 | intent.putExtra("ENCODE_TYPE", "TEXT_TYPE");
335 | intent.putExtra("ENCODE_DATA", text);
336 | String targetAppPackage = findTargetAppPackage(intent);
337 | if (targetAppPackage == null) {
338 | showDownloadDialog();
339 | } else {
340 | intent.setPackage(targetAppPackage);
341 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
342 | intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
343 | activity.startActivity(intent);
344 | }
345 | }
346 |
347 | private static Collection list(String... values) {
348 | return Collections.unmodifiableCollection(Arrays.asList(values));
349 | }
350 |
351 | }
352 |
--------------------------------------------------------------------------------
/src/com/google/zxing/integration/android/IntentResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2009 ZXing authors
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.zxing.integration.android;
18 |
19 | /**
20 | *
Encapsulates the result of a barcode scan invoked through {@link IntentIntegrator}.
21 | *
22 | * @author Sean Owen
23 | */
24 | public final class IntentResult {
25 |
26 | private final String contents;
27 | private final String formatName;
28 | private final byte[] rawBytes;
29 | private final Integer orientation;
30 | private final String errorCorrectionLevel;
31 |
32 | IntentResult() {
33 | this(null, null, null, null, null);
34 | }
35 |
36 | IntentResult(String contents,
37 | String formatName,
38 | byte[] rawBytes,
39 | Integer orientation,
40 | String errorCorrectionLevel) {
41 | this.contents = contents;
42 | this.formatName = formatName;
43 | this.rawBytes = rawBytes;
44 | this.orientation = orientation;
45 | this.errorCorrectionLevel = errorCorrectionLevel;
46 | }
47 |
48 | /**
49 | * @return raw content of barcode
50 | */
51 | public String getContents() {
52 | return contents;
53 | }
54 |
55 | /**
56 | * @return name of format, like "QR_CODE", "UPC_A". See {@code BarcodeFormat} for more format names.
57 | */
58 | public String getFormatName() {
59 | return formatName;
60 | }
61 |
62 | /**
63 | * @return raw bytes of the barcode content, if applicable, or null otherwise
64 | */
65 | public byte[] getRawBytes() {
66 | return rawBytes;
67 | }
68 |
69 | /**
70 | * @return rotation of the image, in degrees, which resulted in a successful scan. May be null.
71 | */
72 | public Integer getOrientation() {
73 | return orientation;
74 | }
75 |
76 | /**
77 | * @return name of the error correction level used in the barcode, if applicable
78 | */
79 | public String getErrorCorrectionLevel() {
80 | return errorCorrectionLevel;
81 | }
82 |
83 | @Override
84 | public String toString() {
85 | StringBuilder dialogText = new StringBuilder(100);
86 | dialogText.append("Format: ").append(formatName).append('\n');
87 | dialogText.append("Contents: ").append(contents).append('\n');
88 | int rawBytesLength = rawBytes == null ? 0 : rawBytes.length;
89 | dialogText.append("Raw bytes: (").append(rawBytesLength).append(" bytes)\n");
90 | dialogText.append("Orientation: ").append(orientation).append('\n');
91 | dialogText.append("EC level: ").append(errorCorrectionLevel).append('\n');
92 | return dialogText.toString();
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/edu/mit/mobile/android/demomode/DemoMode.java:
--------------------------------------------------------------------------------
1 | package edu.mit.mobile.android.demomode;
2 |
3 | /*
4 | * Copyright (C) 2012 MIT Mobile Experience Lab
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU General Public License Version 2
8 | * as published by the Free Software Foundation.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.List;
22 |
23 | import android.app.AlertDialog;
24 | import android.app.Dialog;
25 | import android.content.ComponentName;
26 | import android.content.ContentUris;
27 | import android.content.ContentValues;
28 | import android.content.Context;
29 | import android.content.DialogInterface;
30 | import android.content.DialogInterface.OnCancelListener;
31 | import android.content.Intent;
32 | import android.content.SharedPreferences;
33 | import android.content.pm.ActivityInfo;
34 | import android.content.pm.PackageManager;
35 | import android.content.pm.PackageManager.NameNotFoundException;
36 | import android.content.pm.ResolveInfo;
37 | import android.content.res.Resources;
38 | import android.database.Cursor;
39 | import android.graphics.Bitmap;
40 | import android.graphics.Canvas;
41 | import android.graphics.Paint;
42 | import android.graphics.PaintFlagsDrawFilter;
43 | import android.graphics.PixelFormat;
44 | import android.graphics.Rect;
45 | import android.graphics.drawable.BitmapDrawable;
46 | import android.graphics.drawable.Drawable;
47 | import android.graphics.drawable.PaintDrawable;
48 | import android.os.Bundle;
49 | import android.preference.PreferenceManager;
50 | import android.support.v4.app.FragmentActivity;
51 | import android.support.v4.app.LoaderManager.LoaderCallbacks;
52 | import android.support.v4.content.CursorLoader;
53 | import android.support.v4.content.Loader;
54 | import android.support.v4.widget.CursorAdapter;
55 | import android.view.KeyEvent;
56 | import android.view.LayoutInflater;
57 | import android.view.Menu;
58 | import android.view.MenuItem;
59 | import android.view.View;
60 | import android.view.ViewGroup;
61 | import android.view.WindowManager;
62 | import android.widget.AdapterView;
63 | import android.widget.AdapterView.OnItemClickListener;
64 | import android.widget.AdapterView.OnItemLongClickListener;
65 | import android.widget.ArrayAdapter;
66 | import android.widget.EditText;
67 | import android.widget.GridView;
68 | import android.widget.SlidingDrawer;
69 | import android.widget.TextView;
70 | import android.widget.Toast;
71 |
72 | import com.example.android.home.ApplicationInfo;
73 |
74 | public class DemoMode extends FragmentActivity implements LoaderCallbacks,
75 | OnItemClickListener, OnItemLongClickListener {
76 | @SuppressWarnings("unused")
77 | private static final String TAG = DemoMode.class.getSimpleName();
78 |
79 | private GridView mGridView;
80 | private GridView mAllApps;
81 |
82 | private LauncherItemAdapter mAdapter;
83 |
84 | private static ArrayList mApplications;
85 |
86 | private boolean mLocked;
87 | private String mPassword;
88 | private SharedPreferences mPrefs;
89 |
90 | private SlidingDrawer mDrawer;
91 |
92 | /** Called when the activity is first created. */
93 | @Override
94 | public void onCreate(Bundle savedInstanceState) {
95 | super.onCreate(savedInstanceState);
96 | setContentView(R.layout.main);
97 | mGridView = (GridView) findViewById(R.id.grid);
98 |
99 | getSupportLoaderManager().initLoader(0, null, this);
100 | mAdapter = new LauncherItemAdapter(this, R.layout.launcher_item, null);
101 | mGridView.setAdapter(mAdapter);
102 | mGridView.setOnItemClickListener(this);
103 | mGridView.setOnItemLongClickListener(this);
104 |
105 | mAllApps = (GridView) findViewById(R.id.all_apps);
106 |
107 | loadApplications(true);
108 |
109 | mDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
110 |
111 | mAllApps.setAdapter(new ApplicationsAdapter(this, mApplications));
112 |
113 | mAllApps.setOnItemClickListener(this);
114 | mAllApps.setOnItemLongClickListener(this);
115 |
116 | mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
117 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
118 | mPassword = mPrefs.getString(Preferences.KEY_PASSWORD, null);
119 | mLocked = mPrefs.getBoolean(Preferences.KEY_LOCKED, false);
120 |
121 | updateLocked();
122 | }
123 |
124 | /**
125 | * Loads the list of installed applications in mApplications.
126 | */
127 | private void loadApplications(boolean isLaunching) {
128 | if (isLaunching && mApplications != null) {
129 | return;
130 | }
131 |
132 | final PackageManager manager = getPackageManager();
133 |
134 | final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
135 | mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
136 |
137 | final List apps = manager.queryIntentActivities(mainIntent, 0);
138 | Collections.sort(apps, new ResolveInfo.DisplayNameComparator(manager));
139 |
140 | if (apps != null) {
141 | final int count = apps.size();
142 |
143 | if (mApplications == null) {
144 | mApplications = new ArrayList(count);
145 | }
146 | mApplications.clear();
147 |
148 | for (int i = 0; i < count; i++) {
149 | final ApplicationInfo application = new ApplicationInfo();
150 | final ResolveInfo info = apps.get(i);
151 |
152 | application.title = info.loadLabel(manager);
153 | application.setActivity(new ComponentName(
154 | info.activityInfo.applicationInfo.packageName, info.activityInfo.name),
155 | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
156 | application.icon = info.activityInfo.loadIcon(manager);
157 |
158 | mApplications.add(application);
159 | }
160 | }
161 | }
162 |
163 | private static class LauncherItemAdapter extends CursorAdapter {
164 | private final LayoutInflater mLayoutInflater;
165 | private final int mLayout;
166 | private final PackageManager mPackageManager;
167 | private final int mAppIconWidth;
168 | private final int mAppIconHeight;
169 |
170 | public LauncherItemAdapter(Context context, int layout, Cursor c) {
171 | super(context, c, 0);
172 | mLayout = layout;
173 | mLayoutInflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
174 | mPackageManager = context.getPackageManager();
175 |
176 | final Resources resources = context.getResources();
177 | mAppIconWidth = (int) resources.getDimension(android.R.dimen.app_icon_size);
178 | mAppIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
179 | }
180 |
181 | private Drawable scaleDrawableToAppIconSize(Drawable icon) {
182 | int width = mAppIconWidth;
183 | int height = mAppIconHeight;
184 |
185 | final int iconWidth = icon.getIntrinsicWidth();
186 | final int iconHeight = icon.getIntrinsicHeight();
187 |
188 | if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
189 | final float ratio = (float) iconWidth / iconHeight;
190 |
191 | if (iconWidth > iconHeight) {
192 | height = (int) (width / ratio);
193 | } else if (iconHeight > iconWidth) {
194 | width = (int) (height * ratio);
195 | }
196 | }
197 | icon.setBounds(0, 0, width, height);
198 | return icon;
199 | }
200 |
201 | @Override
202 | public void bindView(View v, Context context, Cursor c) {
203 | final String pkg = c.getString(c.getColumnIndex(LauncherItem.PACKAGE_NAME));
204 | final String cls = c.getString(c.getColumnIndex(LauncherItem.ACTIVITY_NAME));
205 | final ComponentName activity = new ComponentName(pkg, cls);
206 | try {
207 | final ActivityInfo i = mPackageManager.getActivityInfo(activity, 0);
208 | final android.content.pm.ApplicationInfo appInfo = mPackageManager
209 | .getApplicationInfo(pkg, 0);
210 | final TextView label = (TextView) v.findViewById(R.id.label);
211 | final Drawable icon = i.loadIcon(mPackageManager);
212 |
213 | scaleDrawableToAppIconSize(icon);
214 |
215 | label.setCompoundDrawables(null, icon, null, null);
216 |
217 | label.setText(mPackageManager.getText(cls,
218 | i.labelRes == 0 ? i.applicationInfo.labelRes : i.labelRes, appInfo));
219 |
220 | } catch (final NameNotFoundException e) {
221 | e.printStackTrace();
222 | }
223 | }
224 |
225 | @Override
226 | public View newView(Context context, Cursor cursor, ViewGroup parent) {
227 | final View v = mLayoutInflater.inflate(mLayout, parent, false);
228 | bindView(v, context, cursor);
229 | return v;
230 | }
231 |
232 | }
233 |
234 | @Override
235 | public Loader onCreateLoader(int arg0, Bundle arg1) {
236 | return new CursorLoader(this, LauncherItem.CONTENT_URI, null, null, null, null);
237 | }
238 |
239 | @Override
240 | public void onLoadFinished(Loader loader, Cursor c) {
241 | mAdapter.swapCursor(c);
242 |
243 | }
244 |
245 | @Override
246 | public void onLoaderReset(Loader arg0) {
247 | mAdapter.swapCursor(null);
248 |
249 | }
250 |
251 | @Override
252 | public boolean onPrepareOptionsMenu(Menu menu) {
253 | super.onPrepareOptionsMenu(menu);
254 |
255 | menu.findItem(R.id.lock).setVisible(!mLocked);
256 | menu.findItem(R.id.unlock).setVisible(mLocked);
257 | menu.findItem(R.id.settings).setVisible(!mLocked);
258 | menu.findItem(R.id.preferences).setVisible(!mLocked);
259 |
260 | return true;
261 | }
262 |
263 | @Override
264 | public boolean onCreateOptionsMenu(Menu menu) {
265 | super.onCreateOptionsMenu(menu);
266 | getMenuInflater().inflate(R.menu.main, menu);
267 | return true;
268 | }
269 |
270 | @Override
271 | public void onBackPressed() {
272 | if (!mLocked) {
273 | super.onBackPressed();
274 | }
275 | }
276 |
277 | @SuppressWarnings("deprecation")
278 | @Override
279 | public boolean onOptionsItemSelected(MenuItem item) {
280 | switch (item.getItemId()) {
281 | case R.id.settings:
282 | startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
283 | return true;
284 |
285 | case R.id.lock:
286 | setLocked(true);
287 | return true;
288 |
289 | case R.id.unlock:
290 | showDialog(DIALOG_PASSWORD, null);
291 | return true;
292 |
293 | case R.id.preferences:
294 | startActivity(new Intent(this, Preferences.class));
295 | return true;
296 |
297 | default:
298 | return super.onOptionsItemSelected(item);
299 | }
300 | }
301 |
302 | private void setLocked(boolean locked) {
303 | mPrefs.edit().putBoolean(Preferences.KEY_LOCKED, locked).commit();
304 |
305 | mLocked = locked;
306 |
307 | updateLocked();
308 | }
309 |
310 | private void updateLocked() {
311 | findViewById(R.id.slidingDrawer1).setVisibility(mLocked ? View.GONE : View.VISIBLE);
312 | if (mLocked) {
313 | getWindow().addFlags(
314 | WindowManager.LayoutParams.FLAG_FULLSCREEN
315 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
316 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
317 |
318 | } else {
319 | getWindow().clearFlags(
320 | WindowManager.LayoutParams.FLAG_FULLSCREEN
321 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
322 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
323 |
324 | }
325 | }
326 |
327 | @Override
328 | public boolean onKeyDown(int keyCode, KeyEvent event) {
329 | if (mLocked && keyCode != KeyEvent.KEYCODE_MENU) {
330 | return true;
331 | } else {
332 | return super.onKeyDown(keyCode, event);
333 | }
334 | }
335 |
336 | @Override
337 | public boolean onKeyLongPress(int keyCode, KeyEvent event) {
338 | if (mLocked) {
339 | return true;
340 | } else {
341 | return super.onKeyLongPress(keyCode, event);
342 | }
343 | }
344 |
345 | /**
346 | * GridView adapter to show the list of all installed applications.
347 | */
348 | private class ApplicationsAdapter extends ArrayAdapter {
349 | private final Rect mOldBounds = new Rect();
350 | private final int mAppIconHeight;
351 | private final int mAppIconWidth;
352 |
353 | public ApplicationsAdapter(Context context, ArrayList apps) {
354 | super(context, 0, apps);
355 | final Resources resources = getContext().getResources();
356 | mAppIconWidth = (int) resources.getDimension(android.R.dimen.app_icon_size);
357 | mAppIconHeight = (int) resources.getDimension(android.R.dimen.app_icon_size);
358 | }
359 |
360 | @Override
361 | public View getView(int position, View convertView, ViewGroup parent) {
362 | final ApplicationInfo info = mApplications.get(position);
363 |
364 | if (convertView == null) {
365 | final LayoutInflater inflater = getLayoutInflater();
366 | convertView = inflater.inflate(R.layout.launcher_item, parent, false);
367 | }
368 |
369 | Drawable icon = info.icon;
370 |
371 | if (!info.filtered) {
372 | int width = mAppIconWidth;
373 | int height = mAppIconHeight;
374 |
375 | final int iconWidth = icon.getIntrinsicWidth();
376 | final int iconHeight = icon.getIntrinsicHeight();
377 |
378 | if (icon instanceof PaintDrawable) {
379 | final PaintDrawable painter = (PaintDrawable) icon;
380 | painter.setIntrinsicWidth(width);
381 | painter.setIntrinsicHeight(height);
382 | }
383 |
384 | if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
385 | final float ratio = (float) iconWidth / iconHeight;
386 |
387 | if (iconWidth > iconHeight) {
388 | height = (int) (width / ratio);
389 | } else if (iconHeight > iconWidth) {
390 | width = (int) (height * ratio);
391 | }
392 |
393 | final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
394 | : Bitmap.Config.RGB_565;
395 | final Bitmap thumb = Bitmap.createBitmap(width, height, c);
396 | final Canvas canvas = new Canvas(thumb);
397 | canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
398 | // Copy the old bounds to restore them later
399 | // If we were to do oldBounds = icon.getBounds(),
400 | // the call to setBounds() that follows would
401 | // change the same instance and we would lose the
402 | // old bounds
403 | mOldBounds.set(icon.getBounds());
404 | icon.setBounds(0, 0, width, height);
405 | icon.draw(canvas);
406 | icon.setBounds(mOldBounds);
407 | icon = info.icon = new BitmapDrawable(getResources(), thumb);
408 | info.filtered = true;
409 | }
410 | }
411 |
412 | final TextView textView = (TextView) convertView.findViewById(R.id.label);
413 | textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
414 | textView.setText(info.title);
415 |
416 | return convertView;
417 | }
418 | }
419 |
420 | private static final int DIALOG_PASSWORD = 100;
421 |
422 | @SuppressWarnings("deprecation")
423 | @Override
424 | protected Dialog onCreateDialog(int id, Bundle args) {
425 | switch (id) {
426 | case DIALOG_PASSWORD: {
427 | final EditText v = (EditText) getLayoutInflater().inflate(R.layout.password, null);
428 | return new AlertDialog.Builder(this)
429 | .setView(v)
430 | .setCancelable(true)
431 | .setOnCancelListener(new OnCancelListener() {
432 |
433 | @Override
434 | public void onCancel(DialogInterface dialog) {
435 | v.getEditableText().clear();
436 |
437 | }
438 | })
439 | .setPositiveButton(android.R.string.ok,
440 | new DialogInterface.OnClickListener() {
441 |
442 | @Override
443 | public void onClick(DialogInterface dialog, int which) {
444 | if (mPassword.equals(v.getText().toString())) {
445 | setLocked(false);
446 | } else {
447 | Toast.makeText(getApplicationContext(),
448 | R.string.toast_incorrect_password,
449 | Toast.LENGTH_SHORT).show();
450 | }
451 | v.getEditableText().clear();
452 | }
453 | }).create();
454 | }
455 | default:
456 | return super.onCreateDialog(id, args);
457 |
458 | }
459 |
460 | }
461 |
462 | @Override
463 | public void onItemClick(AdapterView> adapter, View v, int position, long id) {
464 | switch (adapter.getId()) {
465 | case R.id.grid: {
466 | final Intent launch = new Intent();
467 | final Cursor c = mAdapter.getCursor();
468 | launch.setClassName(c.getString(c.getColumnIndex(LauncherItem.PACKAGE_NAME)),
469 | c.getString(c.getColumnIndex(LauncherItem.ACTIVITY_NAME)));
470 | launch.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
471 | | Intent.FLAG_ACTIVITY_NEW_TASK);
472 | startActivity(launch);
473 | }
474 | break;
475 |
476 | case R.id.all_apps: {
477 | final ApplicationInfo appInfo = (ApplicationInfo) mAllApps.getAdapter().getItem(
478 | position);
479 | startActivity(appInfo.intent);
480 | }
481 | break;
482 | }
483 |
484 | }
485 |
486 | @Override
487 | public boolean onItemLongClick(AdapterView> adapter, View v, int position, long id) {
488 | switch (adapter.getId()) {
489 | case R.id.grid: {
490 | if (!mLocked) {
491 | getContentResolver().delete(
492 | ContentUris.withAppendedId(LauncherItem.CONTENT_URI, id), null, null);
493 | return true;
494 | }
495 | }
496 | break;
497 |
498 | case R.id.all_apps: {
499 | final ApplicationInfo appInfo = (ApplicationInfo) mAllApps
500 | .getItemAtPosition(position);
501 | final ContentValues cv = new ContentValues();
502 | final ComponentName c = appInfo.intent.getComponent();
503 |
504 | cv.put(LauncherItem.ACTIVITY_NAME, c.getClassName());
505 | cv.put(LauncherItem.PACKAGE_NAME, c.getPackageName());
506 | getContentResolver().insert(LauncherItem.CONTENT_URI, cv);
507 | mDrawer.close();
508 | return true;
509 |
510 | }
511 | }
512 | return false;
513 | }
514 |
515 | }
516 |
--------------------------------------------------------------------------------
/src/edu/mit/mobile/android/demomode/HomescreenProvider.java:
--------------------------------------------------------------------------------
1 | package edu.mit.mobile.android.demomode;
2 |
3 | /*
4 | * Copyright (C) 2012 MIT Mobile Experience Lab
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU General Public License Version 2
8 | * as published by the Free Software Foundation.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | import edu.mit.mobile.android.content.GenericDBHelper;
19 | import edu.mit.mobile.android.content.SimpleContentProvider;
20 |
21 | public class HomescreenProvider extends SimpleContentProvider {
22 |
23 | public static final String AUTHORITY = "edu.mit.mobile.android.demomode";
24 |
25 | private static final int DB_VERSION = 1;
26 |
27 | public HomescreenProvider() {
28 | super(AUTHORITY, DB_VERSION);
29 | }
30 |
31 | @Override
32 | public boolean onCreate() {
33 | super.onCreate();
34 |
35 | final GenericDBHelper items = new GenericDBHelper(LauncherItem.class);
36 | addDirAndItemUri(items, LauncherItem.PATH);
37 |
38 | return true;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/edu/mit/mobile/android/demomode/LauncherItem.java:
--------------------------------------------------------------------------------
1 | package edu.mit.mobile.android.demomode;
2 |
3 | /*
4 | * Copyright (C) 2012 MIT Mobile Experience Lab
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU General Public License Version 2
8 | * as published by the Free Software Foundation.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | import android.net.Uri;
19 | import edu.mit.mobile.android.content.ContentItem;
20 | import edu.mit.mobile.android.content.ProviderUtils;
21 | import edu.mit.mobile.android.content.UriPath;
22 | import edu.mit.mobile.android.content.column.DBColumn;
23 | import edu.mit.mobile.android.content.column.TextColumn;
24 |
25 | @UriPath(LauncherItem.PATH)
26 | public class LauncherItem implements ContentItem {
27 |
28 | @DBColumn(type = TextColumn.class)
29 | public static final String PACKAGE_NAME = "package";
30 |
31 | @DBColumn(type = TextColumn.class)
32 | public static final String ACTIVITY_NAME = "activity";
33 |
34 | public static final String PATH = "apps";
35 |
36 | public static Uri CONTENT_URI = ProviderUtils.toContentUri(HomescreenProvider.AUTHORITY, PATH);
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/src/edu/mit/mobile/android/demomode/Preferences.java:
--------------------------------------------------------------------------------
1 | package edu.mit.mobile.android.demomode;
2 |
3 | /*
4 | * Copyright (C) 2012 MIT Mobile Experience Lab
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU General Public License Version 2
8 | * as published by the Free Software Foundation.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | import java.io.IOException;
19 | import java.io.UnsupportedEncodingException;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | import org.apache.http.NameValuePair;
24 | import org.apache.http.client.utils.URLEncodedUtils;
25 | import org.apache.http.entity.StringEntity;
26 | import org.apache.http.message.BasicNameValuePair;
27 |
28 | import android.content.ComponentName;
29 | import android.content.ContentProviderOperation;
30 | import android.content.Intent;
31 | import android.content.OperationApplicationException;
32 | import android.content.SharedPreferences;
33 | import android.content.SharedPreferences.Editor;
34 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
35 | import android.content.pm.PackageManager;
36 | import android.content.pm.PackageManager.NameNotFoundException;
37 | import android.database.Cursor;
38 | import android.net.Uri;
39 | import android.os.Bundle;
40 | import android.os.RemoteException;
41 | import android.preference.Preference;
42 | import android.preference.Preference.OnPreferenceClickListener;
43 | import android.preference.PreferenceActivity;
44 | import android.util.Log;
45 |
46 | import com.google.zxing.integration.android.IntentIntegrator;
47 | import com.google.zxing.integration.android.IntentResult;
48 |
49 | public class Preferences extends PreferenceActivity implements OnPreferenceClickListener {
50 | private static final String TAG = Preferences.class.getSimpleName();
51 |
52 | private SharedPreferences mPrefs;
53 |
54 | public static final String KEY_PASSWORD = "password";
55 | public static final String KEY_LOCKED = "locked";
56 | public static final String KEY_SHARE_CONFIG = "share_config";
57 | public static final String KEY_SCAN_CONFIG = "scan_config";
58 | public static final String KEY_ENABLED = "enable";
59 |
60 | private static String CFG_PKG_SEP = ",";
61 |
62 | @SuppressWarnings("deprecation")
63 | @Override
64 | protected void onCreate(Bundle savedInstanceState) {
65 |
66 | super.onCreate(savedInstanceState);
67 | this.addPreferencesFromResource(R.xml.preferences);
68 | mPrefs = getPreferenceManager().getSharedPreferences();
69 |
70 | findPreference(KEY_SHARE_CONFIG).setOnPreferenceClickListener(this);
71 | findPreference(KEY_SCAN_CONFIG).setOnPreferenceClickListener(this);
72 |
73 | mPrefs.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
74 |
75 | @Override
76 | public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
77 | if (KEY_ENABLED.equals(key)) {
78 | updateDemoModeEnabled();
79 | }
80 | }
81 | });
82 | }
83 |
84 | @Override
85 | protected void onResume() {
86 | super.onResume();
87 |
88 | if (mPrefs.getBoolean(KEY_LOCKED, false)) {
89 | finish();
90 | }
91 | }
92 |
93 | private static final String CFG_K_VER = "v", CFG_K_SECRETKEY = "k", CFG_K_APPS = "a";
94 | public static final String CFG_MIME_TYPE = "application/x-demo-mode";
95 |
96 | private String toConfigString() {
97 |
98 | final String password = mPrefs.getString(KEY_PASSWORD, null);
99 |
100 | final ArrayList nvp = new ArrayList();
101 |
102 | int ver;
103 | try {
104 | ver = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
105 |
106 | } catch (final NameNotFoundException e) {
107 | // this should never happen
108 | ver = 0;
109 | e.printStackTrace();
110 | }
111 | nvp.add(new BasicNameValuePair(CFG_K_VER, String.valueOf(ver)));
112 | nvp.add(new BasicNameValuePair(CFG_K_SECRETKEY, password));
113 | final Cursor c = getContentResolver().query(LauncherItem.CONTENT_URI, null, null, null,
114 | null);
115 |
116 | try {
117 | final int pkgCol = c.getColumnIndex(LauncherItem.PACKAGE_NAME);
118 | final int actCol = c.getColumnIndex(LauncherItem.ACTIVITY_NAME);
119 |
120 | for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
121 | nvp.add(new BasicNameValuePair(CFG_K_APPS, c.getString(pkgCol) + CFG_PKG_SEP
122 | + c.getString(actCol)));
123 | }
124 |
125 | return "data:" + CFG_MIME_TYPE + "," + URLEncodedUtils.format(nvp, "utf-8");
126 |
127 | } finally {
128 | c.close();
129 | }
130 |
131 | }
132 |
133 | private void shareConfig() {
134 | startActivity(Intent.createChooser(
135 | new Intent(Intent.ACTION_SEND).setType("text/plain")
136 | .putExtra(Intent.EXTRA_TEXT, toConfigString())
137 | .putExtra(Intent.EXTRA_SUBJECT, getText(R.string.app_name) + " Config"),
138 | getText(R.string.share_config)));
139 | }
140 |
141 | private void fromCfgString(String cfg) {
142 | final Uri cfgUri = Uri.parse(cfg);
143 | if ("data".equals(cfgUri.getScheme())) {
144 | final String[] cfgParts = cfgUri.getEncodedSchemeSpecificPart().split(",", 2);
145 | if (CFG_MIME_TYPE.equals(cfgParts[0])) {
146 | final Editor ed = mPrefs.edit();
147 | final ArrayList cpos = new ArrayList();
148 |
149 | // first erase everything
150 | cpos.add(ContentProviderOperation.newDelete(LauncherItem.CONTENT_URI).build());
151 |
152 | try {
153 | final StringEntity entity = new StringEntity(cfgParts[1]);
154 | entity.setContentType("application/x-www-form-urlencoded");
155 | final List nvp = URLEncodedUtils.parse(entity);
156 | for (final NameValuePair pair : nvp) {
157 | final String name = pair.getName();
158 | Log.d(TAG, "parsed pair: " + pair);
159 | if (CFG_K_SECRETKEY.equals(name)) {
160 | ed.putString(KEY_PASSWORD, pair.getValue());
161 |
162 | } else if (CFG_K_APPS.equals(name)) {
163 | final String[] app = pair.getValue().split(CFG_PKG_SEP, 2);
164 | final ContentProviderOperation cpo = ContentProviderOperation
165 | .newInsert(LauncherItem.CONTENT_URI)
166 | .withValue(LauncherItem.PACKAGE_NAME, app[0])
167 | .withValue(LauncherItem.ACTIVITY_NAME, app[1]).build();
168 | cpos.add(cpo);
169 | Log.d(TAG, "adding " + cpo);
170 | }
171 | }
172 |
173 | ed.commit();
174 | getContentResolver().applyBatch(HomescreenProvider.AUTHORITY, cpos);
175 | } catch (final UnsupportedEncodingException e) {
176 | // TODO Auto-generated catch block
177 | e.printStackTrace();
178 | } catch (final IOException e) {
179 | // TODO Auto-generated catch block
180 | e.printStackTrace();
181 | } catch (final RemoteException e) {
182 | // TODO Auto-generated catch block
183 |
184 | e.printStackTrace();
185 | } catch (final OperationApplicationException e) {
186 | // TODO Auto-generated catch block
187 | e.printStackTrace();
188 | }
189 |
190 | } else {
191 | Log.e(TAG, "unknown MIME type for data URI: " + cfgParts[0]);
192 | }
193 |
194 | } else {
195 | Log.e(TAG, "not a data URI");
196 | }
197 | }
198 |
199 | private void scanQRCode() {
200 | final IntentIntegrator integrator = new IntentIntegrator(this);
201 | integrator.initiateScan();
202 |
203 | }
204 |
205 | @Override
206 | public void onActivityResult(int requestCode, int resultCode, Intent intent) {
207 | final IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode,
208 | resultCode, intent);
209 | if (scanResult != null && scanResult.getContents() != null) {
210 |
211 | fromCfgString(scanResult.getContents());
212 |
213 | }
214 | }
215 |
216 | @Override
217 | public boolean onPreferenceClick(Preference preference) {
218 | final String pref = preference.getKey();
219 | if (KEY_SCAN_CONFIG.equals(pref)) {
220 | scanQRCode();
221 | return true;
222 | } else if (KEY_SHARE_CONFIG.equals(pref)) {
223 | shareConfig();
224 | return true;
225 | }
226 |
227 | return false;
228 | }
229 |
230 | private void updateDemoModeEnabled() {
231 | getPackageManager()
232 | .setComponentEnabledSetting(
233 | new ComponentName(this, DemoMode.class),
234 | mPrefs.getBoolean(KEY_ENABLED, true) ? PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
235 | : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
236 | PackageManager.DONT_KILL_APP);
237 | }
238 |
239 | }
240 |
--------------------------------------------------------------------------------