├── .gitignore
├── .project
├── .settings
└── com.aptana.editor.common.prefs
├── CHANGELOG.txt
├── LICENSE
├── LICENSE.txt
├── README
├── README.md
├── Resources
├── alloy
│ └── CFG.js
├── android
│ ├── MarketplaceArtwork.png
│ ├── alloy.js
│ ├── alloy
│ │ ├── CFG.js
│ │ ├── backbone.js
│ │ ├── constants.js
│ │ ├── controllers
│ │ │ ├── BaseController.js
│ │ │ └── index.js
│ │ ├── styles
│ │ │ └── index.js
│ │ ├── sync
│ │ │ ├── localStorage.js
│ │ │ ├── properties.js
│ │ │ └── sql.js
│ │ ├── underscore.js
│ │ ├── widget.js
│ │ └── widgets
│ │ │ └── com.capnajax.vectorimage
│ │ │ ├── controllers
│ │ │ └── widget.js
│ │ │ ├── models
│ │ │ └── Images.js
│ │ │ └── styles
│ │ │ └── widget.js
│ ├── app.js
│ ├── com.capnajax.vectorimage
│ │ ├── svg.js
│ │ └── util.js
│ └── svg
│ │ ├── awesome_tiger copy.svg
│ │ ├── awesome_tiger.svg
│ │ ├── caution.css
│ │ ├── go.css
│ │ ├── light.svg
│ │ └── stop.css
├── app.js
├── blackberry
│ ├── Default-720x720.png
│ ├── Default-768x1280.png
│ ├── appicon.png
│ └── map
│ │ ├── bubble.png
│ │ ├── green_pin.png
│ │ ├── purple_pin.png
│ │ └── red_pin.png
├── iphone
│ ├── Default-568h@2x.png
│ ├── Default-667h@2x.png
│ ├── Default-Landscape-736h.png
│ ├── Default-Landscape.png
│ ├── Default-Landscape@2x.png
│ ├── Default-Portrait-736h@3x.png
│ ├── Default-Portrait.png
│ ├── Default-Portrait@2x.png
│ ├── Default@2x.png
│ ├── alloy.js
│ ├── alloy
│ │ ├── CFG.js
│ │ ├── backbone.js
│ │ ├── constants.js
│ │ ├── controllers
│ │ │ ├── BaseController.js
│ │ │ └── index.js
│ │ ├── styles
│ │ │ └── index.js
│ │ ├── sync
│ │ │ ├── localStorage.js
│ │ │ ├── properties.js
│ │ │ └── sql.js
│ │ ├── underscore.js
│ │ ├── widget.js
│ │ └── widgets
│ │ │ └── com.capnajax.vectorimage
│ │ │ ├── controllers
│ │ │ └── widget.js
│ │ │ ├── models
│ │ │ └── Images.js
│ │ │ └── styles
│ │ │ └── widget.js
│ ├── app.js
│ ├── appicon-60@2x.png
│ ├── appicon-60@3x.png
│ ├── appicon-76.png
│ ├── appicon-76@2x.png
│ ├── appicon-Small-40.png
│ ├── appicon-Small-40@2x.png
│ ├── appicon-Small.png
│ ├── appicon-Small@2x.png
│ ├── appicon-Small@3x.png
│ ├── com.capnajax.vectorimage
│ │ ├── svg.js
│ │ └── util.js
│ ├── iTunesArtwork
│ └── svg
│ │ ├── awesome_tiger copy.svg
│ │ ├── awesome_tiger.svg
│ │ ├── caution.css
│ │ ├── go.css
│ │ ├── light.svg
│ │ └── stop.css
└── mobileweb
│ ├── appicon.png
│ ├── apple_startup_images
│ ├── Default-Landscape.jpg
│ ├── Default-Landscape.png
│ ├── Default-Portrait.jpg
│ ├── Default-Portrait.png
│ ├── Default.jpg
│ ├── Default.png
│ └── README
│ └── splash
│ ├── README
│ ├── appc.png
│ ├── splash.css
│ ├── splash.html
│ └── titanium.png
├── app
├── README
├── alloy.js
├── assets
│ ├── android
│ │ └── MarketplaceArtwork.png
│ ├── blackberry
│ │ ├── Default-720x720.png
│ │ ├── Default-768x1280.png
│ │ ├── Ti.Manifest
│ │ ├── appicon.png
│ │ ├── map
│ │ │ ├── bubble.png
│ │ │ ├── green_pin.png
│ │ │ ├── purple_pin.png
│ │ │ └── red_pin.png
│ │ └── splash-600x1024.png
│ ├── iphone
│ │ ├── Default-568h@2x.png
│ │ ├── Default-667h@2x.png
│ │ ├── Default-Landscape-736h.png
│ │ ├── Default-Landscape.png
│ │ ├── Default-Landscape@2x.png
│ │ ├── Default-Portrait-736h@3x.png
│ │ ├── Default-Portrait.png
│ │ ├── Default-Portrait@2x.png
│ │ ├── Default@2x.png
│ │ ├── appicon-60@2x.png
│ │ ├── appicon-60@3x.png
│ │ ├── appicon-76.png
│ │ ├── appicon-76@2x.png
│ │ ├── appicon-Small-40.png
│ │ ├── appicon-Small-40@2x.png
│ │ ├── appicon-Small.png
│ │ ├── appicon-Small@2x.png
│ │ ├── appicon-Small@3x.png
│ │ └── iTunesArtwork
│ ├── mobileweb
│ │ ├── appicon.png
│ │ ├── apple_startup_images
│ │ │ ├── Default-Landscape.jpg
│ │ │ ├── Default-Landscape.png
│ │ │ ├── Default-Portrait.jpg
│ │ │ ├── Default-Portrait.png
│ │ │ ├── Default.jpg
│ │ │ ├── Default.png
│ │ │ └── README
│ │ └── splash
│ │ │ ├── README
│ │ │ ├── appc.png
│ │ │ ├── splash.css
│ │ │ ├── splash.html
│ │ │ └── titanium.png
│ └── svg
│ │ ├── awesome_tiger copy.svg
│ │ ├── awesome_tiger.svg
│ │ ├── caution.css
│ │ ├── go.css
│ │ ├── light.svg
│ │ └── stop.css
├── config.json
├── controllers
│ └── index.js
├── styles
│ └── index.tss
├── views
│ └── index.xml
└── widgets
│ └── com.capnajax.vectorimage
│ ├── controllers
│ └── widget.js
│ ├── lib
│ ├── svg.js
│ └── util.js
│ ├── models
│ └── images.js
│ ├── styles
│ └── widget.tss
│ ├── views
│ └── widget.xml
│ └── widget.json
├── manifest
├── platform
└── android
│ └── res
│ ├── drawable-hdpi
│ ├── appicon.png
│ └── background.9.png
│ ├── drawable-ldpi
│ ├── appicon.png
│ └── background.9.png
│ ├── drawable-mdpi
│ ├── appicon.png
│ └── background.9.png
│ ├── drawable-xhdpi
│ ├── appicon.png
│ └── background.9.png
│ └── drawable-xxhdpi
│ ├── appicon.png
│ └── background.9.png
├── plugins
└── ti.alloy
│ ├── hooks
│ └── alloy.js
│ └── plugin.py
└── tiapp.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | # Build folder and log file
2 | build/
3 | build.log
4 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | VectorImage
4 |
5 |
6 |
7 |
8 |
9 | com.appcelerator.titanium.core.builder
10 |
11 |
12 |
13 |
14 | com.aptana.ide.core.unifiedBuilder
15 |
16 |
17 |
18 |
19 |
20 | com.appcelerator.titanium.alloy.core.nature
21 | com.appcelerator.titanium.mobile.nature
22 | com.aptana.projects.webnature
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.settings/com.aptana.editor.common.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | selectUserAgents=com.appcelerator.titanium.mobile.nature\:android,blackberry,ipad,iphone,mobileweb
3 |
--------------------------------------------------------------------------------
/CHANGELOG.txt:
--------------------------------------------------------------------------------
1 | Place your change log text here. This file will be incorporated with your app at package time.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Place your license text here. This file will be incorporated with your app at package time.
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Welcome to your Appcelerator Titanium Mobile Project
2 |
3 | This is a blank project. Start by editing your application's app.js to
4 | make your first mobile project using Titanium.
5 |
6 |
7 |
8 | ----------------------------------
9 | Stuff our legal folk make us say:
10 |
11 | Appcelerator, Appcelerator Titanium and associated marks and logos are
12 | trademarks of Appcelerator, Inc.
13 |
14 | Titanium is Copyright (c) 2008-2013 by Appcelerator, Inc. All Rights Reserved.
15 |
16 | Titanium is licensed under the Apache Public License (Version 2). Please
17 | see the LICENSE file for the full license.
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vector Image Widget
2 |
3 | This widget uses SVG to render images.
4 |
5 | This is intended primarily for icon images where they are needed in multiple sizes, styles, colours, and need to look sharp on all platforms.
6 |
7 | Need an icon to be 40mm? What's the dpi on every device that exists and ever will exist?
8 |
9 | Need an icon in five different colours? How large would your app be if you were to generate five separate images in all the different scaling factors? What if you need to make a simple change? Tell your designers to spin up 25 new assets for you!
10 |
11 | ### What about font icons?
12 |
13 | Font icons have a few limitations. They cannot be positioned precisely, they can only be one colour, the cannot be styled, and they difficult to modify, and nearly impossible to change on the fly.
14 |
15 | By using SVG images and an optional style sheet, this widget can use a single image, and a handful of stylesheets to create rich vector images, that look sharp on every platform, without having to generate dozens of copies of every image for every platform.
16 |
17 | ## Getting started
18 |
19 | git clone git@github.com:appcelerator-services/VectorImage.git
20 |
21 | This git provides a sample app to explore that shows two different use cases.
22 |
23 | 1. The first case is three different icons, all looking sharp. These are done with a single SVG image and three style sheets.
24 | 2. The second case is a complex SVG image that renders sharp on all platforms.
25 |
26 | ### To use the widget
27 |
28 |
30 |
31 | That's all there is to it. The two parameters `svg` and `style` are the locations of the files, or the `svg` and `css` code itself.
32 |
33 | Alloy.createWidget({
34 | src:"com.capnajax.vectorimage",
35 | svg:"svg/light.svg",
36 | css:"circle{stroke:#f60}"
37 | });
38 |
39 | The image will scale to fit the space provided by the widget but will not change its aspect ratio.
40 |
41 | ## Known Issues
42 |
43 | This widget has a cacheing feature, the rendered SVG is saved as a blob in the app's cache. Unfortunately this is not working at the moment, and there will be a fix coming soon.
44 |
45 | The demonstration app uses rotation transforms which are not supported by an Android versions Jelly Bean or older.
46 |
--------------------------------------------------------------------------------
/Resources/alloy/CFG.js:
--------------------------------------------------------------------------------
1 | module.exports={"dependencies":{"com.capnajax.vectorimage":"1.0"}};
--------------------------------------------------------------------------------
/Resources/android/MarketplaceArtwork.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/appcelerator-archive/VectorImage/ddacb77acc67b62d355c2a80b812754356d49e2d/Resources/android/MarketplaceArtwork.png
--------------------------------------------------------------------------------
/Resources/android/alloy/CFG.js:
--------------------------------------------------------------------------------
1 | module.exports={"dependencies":{"com.capnajax.vectorimage":"1.0"}};
--------------------------------------------------------------------------------
/Resources/android/alloy/constants.js:
--------------------------------------------------------------------------------
1 | var isTitanium = typeof Titanium !== 'undefined';
2 | var _, generatePlatformArray;
3 |
4 | if (isTitanium) {
5 | _ = require('alloy/underscore')._;
6 | } else {
7 | var platforms = require('../../platforms/index');
8 | _ = require('../lib/alloy/underscore')._;
9 |
10 | // iterate through supported platforms to create specific constants
11 | generatePlatformArray = function(key) {
12 | var ret = [];
13 | _.each(_.keys(platforms), function(p) {
14 | ret.push(platforms[p][key]);
15 | });
16 | return ret;
17 | };
18 |
19 | // generate compile time constants based on supported platforms
20 | exports.PLATFORMS = generatePlatformArray('platform');
21 | exports.PLATFORM_FOLDERS_ALLOY = generatePlatformArray('alloyFolder');
22 | exports.PLATFORM_FOLDERS = generatePlatformArray('titaniumFolder');
23 | }
24 |
25 | // General default values
26 | exports.ALLOY_DIR = 'app';
27 | exports.ALLOY_RUNTIME_DIR = 'alloy';
28 | exports.RESOURCES_DIR = 'Resources';
29 | exports.NAME_DEFAULT = 'index';
30 | exports.NAME_WIDGET_DEFAULT = 'widget';
31 | exports.GLOBAL_STYLE = 'app.tss';
32 | exports.ROOT_NODE = 'Alloy';
33 | exports.NAMESPACE_DEFAULT = 'Ti.UI';
34 | exports.REQUIRE_TYPE_DEFAULT = 'view';
35 | exports.PLUGIN_NAME = 'ti.alloy';
36 | exports.EXPR_PREFIX = '#';
37 | exports.PLUGIN_FILE = 'plugin.py';
38 | exports.HOOK_FILE = 'alloy.js';
39 | exports.MINIMUM_TI_SDK = '3.0.0';
40 | exports.ITEM_TEMPLATE_VAR = '__itemTemplate';
41 | exports.PARENT_SYMBOL_VAR = '__parentSymbol';
42 | exports.WIDGET_OBJECT = 'Widget';
43 | exports.SKIP_EVENT_HANDLING = ['Ti.UI.ListItem','Alloy.Abstract.ItemTemplate'];
44 | exports.ADAPTERS = ['localStorage', 'properties', 'sql'];
45 | exports.CONTROLLER_NODES = ['Alloy.Require', 'Alloy.Widget'];
46 |
47 | // property names
48 | exports.CLASS_PROPERTY = 'classes';
49 | exports.APINAME_PROPERTY = 'apiName';
50 | exports.AUTOSTYLE_PROPERTY = 'autoStyle';
51 |
52 | // Constants related to model-view binding
53 | exports.BIND_PROPERTIES = ['dataCollection','dataFilter','dataTransform','dataFunction'];
54 | exports.BIND_COLLECTION = 'dataCollection';
55 | exports.BIND_WHERE = 'dataFilter';
56 | exports.BIND_TRANSFORM = 'dataTransform';
57 | exports.BIND_FUNCTION = 'dataFunction';
58 | exports.BIND_TRANSFORM_VAR = '__transform';
59 | exports.BIND_MODEL_VAR = '$model';
60 | exports.MODEL_ELEMENTS = ['Alloy.Collection','Alloy.Model'];
61 | exports.MODEL_BINDING_EVENTS = 'fetch change destroy';
62 | exports.COLLECTION_BINDING_EVENTS = 'fetch destroy change add remove reset';
63 |
64 | // Listings for supported platforms and commands
65 | exports.INSTALL_TYPES = ['plugin'];
66 | exports.GENERATE_TARGETS = ['controller', 'jmk', 'model', 'migration', 'view', 'widget', 'style'];
67 | exports.DEPLOY_TYPES = [
68 | { key: 'ENV_DEV', value: 'development' },
69 | { key: 'ENV_DEVELOPMENT', value: 'development' },
70 | { key: 'ENV_TEST', value: 'test' },
71 | { key: 'ENV_PROD', value: 'production' },
72 | { key: 'ENV_PRODUCTION', value: 'production' }
73 | ];
74 | exports.DIST_TYPES = [
75 | { key: 'DIST_ADHOC', value: ['dist-adhoc'] },
76 | { key: 'DIST_STORE', value: ['dist-appstore', 'dist-playstore'] }
77 | ];
78 |
79 | // mappings of file extensions and folders for each file type
80 | exports.FILE_EXT = {
81 | VIEW: 'xml',
82 | STYLE: 'tss',
83 | MODEL: 'js',
84 | MODELCODE: 'js',
85 | MIGRATION: 'js',
86 | CONTROLLER: 'js',
87 | COMPONENT: 'js',
88 | CONFIG: 'json',
89 | JMK: 'jmk',
90 | MAP: 'map'
91 | };
92 | exports.DIR = {
93 | VIEW: 'views',
94 | STYLE: 'styles',
95 | RUNTIME_STYLE: 'styles',
96 | CONTROLLER: 'controllers',
97 | MODEL: 'models',
98 | MODELCODE: 'models',
99 | MIGRATION: 'migrations',
100 | CONFIG: 'config',
101 | ASSETS: 'assets',
102 | WIDGET: 'widgets',
103 | LIB: 'lib',
104 | COMPONENT: 'controllers',
105 | MAP: 'build/map',
106 | VENDOR: 'vendor',
107 | THEME: 'themes',
108 | BUILD: 'build/alloy',
109 | I18N: 'i18n',
110 | PLATFORM: 'platform'
111 | };
112 | // folders/files to exclude when copying and processing files
113 | // RegEx format: must escape special chars - so use \.svn not .svn
114 | exports.EXCLUDED_FILES = [
115 | '\\.svn'
116 | ];
117 |
118 | // constants identifying JS reserved words
119 | exports.JS_RESERVED = [
120 | 'break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete',
121 | 'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof',
122 | 'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var',
123 | 'void', 'while', 'with'
124 | ];
125 | exports.JS_RESERVED_FUTURE = [
126 | 'class', 'enum', 'export', 'extends', 'import', 'super', 'implements',
127 | 'interface', 'let', 'package', 'private', 'protected', 'public',
128 | 'static', 'yield'
129 | ];
130 | exports.JS_RESERVED_ALL = _.union(exports.JS_RESERVED, exports.JS_RESERVED_FUTURE);
131 |
132 | // constants for implicit namespaces in markup
133 | var NS_ALLOY = 'Alloy',
134 | NS_ALLOY_ABSTRACT = 'Alloy.Abstract',
135 | NS_TI_ANDROID = 'Ti.Android',
136 | NS_TI_MAP = 'Ti.Map',
137 | NS_TI_MEDIA = 'Ti.Media',
138 | NS_TI_UI_IOS = 'Ti.UI.iOS',
139 | NS_TI_UI_IPAD = 'Ti.UI.iPad',
140 | NS_TI_UI_IPHONE = 'Ti.UI.iPhone',
141 | NS_TI_UI_MOBILEWEB = 'Ti.UI.MobileWeb';
142 |
143 | exports.IMPLICIT_NAMESPACES = {
144 | // Alloy
145 | Collection: NS_ALLOY,
146 | Model: NS_ALLOY,
147 | Module: NS_ALLOY,
148 | Require: NS_ALLOY,
149 | Widget: NS_ALLOY,
150 |
151 | // Alloy.Abstract
152 | ButtonNames: NS_ALLOY_ABSTRACT,
153 | ButtonName: NS_ALLOY_ABSTRACT,
154 | BarItemTypes: NS_ALLOY_ABSTRACT,
155 | BarItemType: NS_ALLOY_ABSTRACT,
156 | CoverFlowImageTypes: NS_ALLOY_ABSTRACT,
157 | CoverFlowImageType: NS_ALLOY_ABSTRACT,
158 | FlexSpace: NS_ALLOY_ABSTRACT,
159 | FixedSpace: NS_ALLOY_ABSTRACT,
160 | Images: NS_ALLOY_ABSTRACT,
161 | Item: NS_ALLOY_ABSTRACT,
162 | Items: NS_ALLOY_ABSTRACT,
163 | ItemTemplate: NS_ALLOY_ABSTRACT,
164 | Labels: NS_ALLOY_ABSTRACT,
165 | Option: NS_ALLOY_ABSTRACT,
166 | Options: NS_ALLOY_ABSTRACT,
167 | Templates: NS_ALLOY_ABSTRACT,
168 |
169 | // Ti.Android
170 | Menu: NS_TI_ANDROID,
171 | MenuItem: NS_TI_ANDROID,
172 | ActionBar: NS_TI_ANDROID,
173 |
174 | // Ti.Map
175 | Annotation: NS_TI_MAP,
176 |
177 | // Ti.Media
178 | VideoPlayer: NS_TI_MEDIA,
179 | MusicPlayer: NS_TI_MEDIA,
180 |
181 | // Ti.UI.iOS
182 | AdView: NS_TI_UI_IOS,
183 | CoverFlowView: NS_TI_UI_IOS,
184 | NavigationWindow: NS_TI_UI_IOS,
185 | TabbedBar: NS_TI_UI_IOS,
186 | Toolbar: NS_TI_UI_IOS,
187 |
188 | // Ti.UI.iPad
189 | DocumentViewer: NS_TI_UI_IPAD,
190 | Popover: NS_TI_UI_IPAD,
191 | SplitWindow: NS_TI_UI_IPAD,
192 |
193 | // Ti.UI.iPhone
194 | NavigationGroup: isTitanium && Ti.Platform.osname === 'mobileweb' ?
195 | NS_TI_UI_MOBILEWEB: NS_TI_UI_IPHONE,
196 | StatusBar: NS_TI_UI_IPHONE,
197 |
198 | // Ti.UI.Window
199 | LeftNavButton: 'Ti.UI.Window',
200 | RightNavButton: 'Ti.UI.Window',
201 | LeftNavButtons: 'Ti.UI.Window',
202 | RightNavButtons: 'Ti.UI.Window',
203 | TitleControl: 'Ti.UI.Window',
204 |
205 | // Ti.UI.iPad.Popover
206 | ContentView: 'Ti.UI.iPad.Popover',
207 |
208 | // Table and List proxy properties
209 | FooterView: '_ProxyProperty._Lists',
210 | HeaderView: '_ProxyProperty._Lists',
211 | HeaderPullView: '_ProxyProperty._Lists',
212 | PullView: '_ProxyProperty._Lists',
213 | Search: '_ProxyProperty._Lists',
214 | SearchView: '_ProxyProperty._Lists',
215 |
216 | // misc proxy properties
217 | RightButton: '_ProxyProperty',
218 | LeftButton: '_ProxyProperty',
219 | KeyboardToolbar: '_ProxyProperty',
220 |
221 | };
222 |
223 | // properties named with "on" that aren't used to signify event listeners
224 | exports.SPECIAL_PROPERTY_NAMES = [
225 | 'onHomeIconItemSelected',
226 | 'onTintColor',
227 | 'onCreateOptionsMenu',
228 | 'onPrepareOptionsMenu'
229 | ];
230 |
--------------------------------------------------------------------------------
/Resources/android/alloy/controllers/BaseController.js:
--------------------------------------------------------------------------------
1 | var Alloy = require('alloy'),
2 | Backbone = Alloy.Backbone,
3 | _ = Alloy._;
4 |
5 | /**
6 | * @class Alloy.Controller
7 | * @extends Backbone.Events
8 | * The base class for Alloy controllers.
9 | *
10 | * Each controller is associated with a UI hierarchy, defined in an XML file in the
11 | * `views` folder. Each element in the view hierarchy is either a Titanium {@link Titanium.UI.View View}
12 | * or another Alloy controller or widget. Each Alloy controller or widget can additionally contain
13 | * Titanium Views and/or more controllers and widgets.
14 | *
15 | */
16 | var Controller = function() {
17 | var roots = [];
18 | var self = this;
19 |
20 | function getControllerParam() {
21 | return self.__widgetId ? {
22 | widgetId: self.__widgetId,
23 | name: self.__controllerPath
24 | } : self.__controllerPath;
25 | }
26 |
27 | this.__iamalloy = true;
28 | _.extend(this, Backbone.Events, {
29 | __views: {},
30 | __proxyProperties: {},
31 | setParent: function(parent) {
32 | var len = roots.length;
33 |
34 | if (!len) { return; }
35 |
36 | if (parent.__iamalloy) {
37 | this.parent = parent.parent;
38 | } else {
39 | this.parent = parent;
40 | }
41 |
42 | for (var i = 0; i < len; i++) {
43 | if (roots[i].__iamalloy) {
44 | roots[i].setParent(this.parent);
45 | } else {
46 | this.parent.add(roots[i]);
47 | }
48 | }
49 | },
50 | addTopLevelView: function(view) {
51 | roots.push(view);
52 | },
53 | addProxyProperty: function(key, value) {
54 | this.__proxyProperties[key] = value;
55 | },
56 | removeProxyProperty: function(key) {
57 | delete this.__proxyProperties[key];
58 | },
59 |
60 | /**
61 | * @method getTopLevelViews
62 | * Returns a list of the root view elements associated with this controller.
63 | *
64 | * @return {Array.<(Titanium.UI.View|Alloy.Controller)>}
65 | */
66 | getTopLevelViews: function() {
67 | return roots;
68 | },
69 |
70 | /**
71 | * @method getView
72 | * Returns the specified view associated with this controller.
73 | *
74 | * If no `id` is specified, returns the first top-level view.
75 | *
76 | * @param {String} [id] ID of the view to return.
77 | * @return {Titanium.UI.View/Alloy.Controller}
78 | */
79 | getView: function(id) {
80 | if (typeof id === 'undefined' || id === null) {
81 | return roots[0];
82 | }
83 | return this.__views[id];
84 | },
85 | removeView: function(id) {
86 | delete this[id];
87 | delete this.__views[id];
88 | },
89 |
90 | getProxyProperty: function(name) {
91 | return this.__proxyProperties[name];
92 | },
93 |
94 | /**
95 | * @method getViews
96 | * Returns a list of all IDed view elements associated with this controller.
97 | *
98 | * @return {Array.<(Titanium.UI.View|Alloy.Controller)>}
99 | */
100 | getViews: function() {
101 | return this.__views;
102 | },
103 |
104 | /**
105 | * @method destroy
106 | * Frees binding resources associated with this controller and its
107 | * UI components. It is critical that this is called when employing
108 | * model/collection binding in order to avoid potential memory leaks.
109 | * $.destroy() should be called whenever a controller's UI is to
110 | * be "closed" or removed from the app. For more details, see the
111 | * example app found here:
112 | * https://github.com/appcelerator/alloy/tree/master/test/apps/models/binding_destroy
113 | */
114 | destroy: function(){
115 | // destroy() is defined during the compile process based on
116 | // the UI components and binding contained within the controller.
117 | },
118 |
119 | // getViewEx for advanced parsing and element traversal
120 | getViewEx: function(opts) {
121 | var recurse = opts.recurse || false;
122 | if (recurse) {
123 | var view = this.getView();
124 | if (!view) {
125 | return null;
126 | } else if (view.__iamalloy) {
127 | return view.getViewEx({ recurse: true });
128 | } else {
129 | return view;
130 | }
131 | } else {
132 | return this.getView();
133 | }
134 | },
135 |
136 | // getProxyPropertyEx for advanced parsing and element traversal
137 | getProxyPropertyEx: function(name, opts) {
138 | var recurse = opts.recurse || false;
139 | if (recurse) {
140 | var view = this.getProxyProperty(name);
141 | if (!view) {
142 | return null;
143 | } else if (view.__iamalloy) {
144 | return view.getProxyProperty(name, { recurse: true });
145 | } else {
146 | return view;
147 | }
148 | } else {
149 | return this.getView(name);
150 | }
151 | },
152 |
153 | /**
154 | * @method createStyle
155 | * Creates a dictionary of properties based on the specified styles.
156 | *
157 | * You can use this dictionary with the view object's
158 | * {@link Titanium.UI.View#method-applyProperties applyProperties} method
159 | * or a create object method, such as {@link Titanium.UI#method-createView Titanium.UI.createView}.
160 | * @param {AlloyStyleDict} opts Dictionary of styles to apply.
161 | * @return {Dictionary}
162 | * @since 1.2.0
163 | */
164 | createStyle: function(opts) {
165 | return Alloy.createStyle(getControllerParam(), opts);
166 | },
167 |
168 | /*
169 | * Documented in docs/apidoc/controller.js
170 | */
171 | UI: {
172 | create: function(apiName, opts) {
173 | return Alloy.UI.create(getControllerParam(), apiName, opts);
174 | }
175 | },
176 |
177 | /**
178 | * @method addClass
179 | * Adds a TSS class to the specified view object.
180 | *
181 | * You can apply additional styles with the `opts` parameter.
182 | * @param {Object} proxy View object to which to add class(es).
183 | * @param {Array/String} classes Array or space-separated list of classes to apply.
184 | * @param {Dictionary} [opts] Dictionary of properties to apply after classes have been added.
185 | * @since 1.2.0
186 | */
187 | addClass: function(proxy, classes, opts) {
188 | return Alloy.addClass(getControllerParam(), proxy, classes, opts);
189 | },
190 |
191 | /**
192 | * @method removeClass
193 | * Removes a TSS class from the specified view object.
194 | *
195 | * You can apply additional styles after the removal with the `opts` parameter.
196 | * @param {Object} proxy View object from which to remove class(es).
197 | * @param {Array/String} classes Array or space-separated list of classes to remove.
198 | * @param {Dictionary} [opts] Dictionary of properties to apply after the class removal.
199 | * @since 1.2.0
200 | */
201 | removeClass: function(proxy, classes, opts) {
202 | return Alloy.removeClass(getControllerParam(), proxy, classes, opts);
203 | },
204 |
205 | /**
206 | * @method resetClass
207 | * Sets the array of TSS classes for the target View object, adding the classes specified and
208 | * removing any applied classes that are not specified.
209 | *
210 | * You can apply classes or styles after the reset using the `classes` or `opts` parameters.
211 | * @param {Object} proxy View object to reset.
212 | * @param {Array/String} [classes] Array or space-separated list of classes to apply after the reset.
213 | * @param {Dictionary} [opts] Dictionary of properties to apply after the reset.
214 | * @since 1.2.0
215 | */
216 | resetClass: function(proxy, classes, opts) {
217 | return Alloy.resetClass(getControllerParam(), proxy, classes, opts);
218 | },
219 |
220 | /**
221 | * @method updateViews
222 | * Applies a set of properties to view elements associated with this controller
223 | * @param {Object} args An object whose keys are the IDs (in form '#id') of views to which the styles will be applied.
224 | * @since 1.4.0
225 | */
226 | updateViews: function(args) {
227 | var views = this.getViews();
228 | if(_.isObject(args)) {
229 | _.each(_.keys(args), function(key) {
230 | var elem = views[key.substring(1)];
231 | if (key.indexOf('#') === 0 && key !== '#' && _.isObject(elem) && typeof elem.applyProperties === 'function') {
232 | // apply the properties but make sure we're applying them to a Ti.UI object (not a controller)
233 | elem.applyProperties(args[key]);
234 | }
235 | });
236 | }
237 | return this;
238 | }
239 | });
240 | };
241 | module.exports = Controller;
242 |
--------------------------------------------------------------------------------
/Resources/android/alloy/controllers/index.js:
--------------------------------------------------------------------------------
1 | function __processArg(obj, key) {
2 | var arg = null;
3 | if (obj) {
4 | arg = obj[key] || null;
5 | delete obj[key];
6 | }
7 | return arg;
8 | }
9 |
10 | function Controller() {
11 | require("alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
12 | this.__controllerPath = "index";
13 | if (arguments[0]) {
14 | {
15 | __processArg(arguments[0], "__parentSymbol");
16 | }
17 | {
18 | __processArg(arguments[0], "$model");
19 | }
20 | {
21 | __processArg(arguments[0], "__itemTemplate");
22 | }
23 | }
24 | var $ = this;
25 | var exports = {};
26 | $.__views.index = Ti.UI.createWindow({
27 | backgroundColor: "white",
28 | id: "index"
29 | });
30 | $.__views.index && $.addTopLevelView($.__views.index);
31 | var __alloyId0 = [];
32 | $.__views.stylesheets = Ti.UI.createView({
33 | id: "stylesheets"
34 | });
35 | __alloyId0.push($.__views.stylesheets);
36 | $.__views.__alloyId1 = Ti.UI.createLabel({
37 | top: 20,
38 | height: 30,
39 | text: "Style Sheets",
40 | id: "__alloyId1"
41 | });
42 | $.__views.stylesheets.add($.__views.__alloyId1);
43 | $.__views.__alloyId2 = Ti.UI.createView({
44 | top: 50,
45 | left: 0,
46 | right: 0,
47 | bottom: 0,
48 | layout: "vertical",
49 | id: "__alloyId2"
50 | });
51 | $.__views.stylesheets.add($.__views.__alloyId2);
52 | $.__views.stop = Ti.UI.createView({
53 | height: "40%",
54 | id: "stop"
55 | });
56 | $.__views.__alloyId2.add($.__views.stop);
57 | $.__views.__alloyId3 = Alloy.createWidget("com.capnajax.vectorimage", "widget", {
58 | top: 0,
59 | left: 0,
60 | right: 0,
61 | bottom: 20,
62 | svg: "svg/light.svg",
63 | style: "svg/stop.css",
64 | id: "__alloyId3",
65 | __parentSymbol: $.__views.stop
66 | });
67 | $.__views.__alloyId3.setParent($.__views.stop);
68 | $.__views.caution = Ti.UI.createView({
69 | height: "30%",
70 | id: "caution"
71 | });
72 | $.__views.__alloyId2.add($.__views.caution);
73 | $.__views.__alloyId4 = Alloy.createWidget("com.capnajax.vectorimage", "widget", {
74 | top: 0,
75 | left: 0,
76 | right: 0,
77 | bottom: 20,
78 | svg: "svg/light.svg",
79 | style: "svg/caution.css",
80 | id: "__alloyId4",
81 | __parentSymbol: $.__views.caution
82 | });
83 | $.__views.__alloyId4.setParent($.__views.caution);
84 | $.__views.go = Ti.UI.createView({
85 | height: "30%",
86 | id: "go"
87 | });
88 | $.__views.__alloyId2.add($.__views.go);
89 | $.__views.__alloyId5 = Alloy.createWidget("com.capnajax.vectorimage", "widget", {
90 | top: 0,
91 | left: 0,
92 | right: 0,
93 | bottom: 20,
94 | svg: "svg/light.svg",
95 | style: "svg/go.css",
96 | id: "__alloyId5",
97 | __parentSymbol: $.__views.go
98 | });
99 | $.__views.__alloyId5.setParent($.__views.go);
100 | $.__views.tiger = Ti.UI.createView({
101 | top: 20,
102 | left: 20,
103 | right: 20,
104 | bottom: 20,
105 | backgroundColor: "white",
106 | id: "tiger"
107 | });
108 | __alloyId0.push($.__views.tiger);
109 | $.__views.__alloyId6 = Ti.UI.createLabel({
110 | top: 20,
111 | height: 30,
112 | text: "Tiger",
113 | id: "__alloyId6"
114 | });
115 | $.__views.tiger.add($.__views.__alloyId6);
116 | $.__views.__alloyId7 = Ti.UI.createView({
117 | top: 50,
118 | left: 0,
119 | right: 0,
120 | bottom: 0,
121 | layout: "vertical",
122 | id: "__alloyId7"
123 | });
124 | $.__views.tiger.add($.__views.__alloyId7);
125 | $.__views.__alloyId8 = Alloy.createWidget("com.capnajax.vectorimage", "widget", {
126 | svg: "svg/awesome_tiger.svg",
127 | id: "__alloyId8",
128 | __parentSymbol: $.__views.__alloyId7
129 | });
130 | $.__views.__alloyId8.setParent($.__views.__alloyId7);
131 | $.__views.scrollable = Ti.UI.createScrollableView({
132 | showPagingControl: true,
133 | views: __alloyId0,
134 | id: "scrollable"
135 | });
136 | $.__views.index.add($.__views.scrollable);
137 | exports.destroy = function() {};
138 | _.extend($, $.__views);
139 | $.index.open();
140 | _.extend($, exports);
141 | }
142 |
143 | var Alloy = require("alloy"), Backbone = Alloy.Backbone, _ = Alloy._;
144 |
145 | module.exports = Controller;
--------------------------------------------------------------------------------
/Resources/android/alloy/styles/index.js:
--------------------------------------------------------------------------------
1 | module.exports = [{"isClass":true,"priority":10000.0002,"key":"container","style":{backgroundColor:"white",}},{"isClass":true,"priority":10000.0003,"key":"topLabel","style":{top:20,height:30,}},{"isClass":true,"priority":10000.0004,"key":"vectorImageContainer","style":{top:50,left:0,right:0,bottom:0,layout:"vertical",}},{"isClass":true,"priority":10000.0011,"key":"light","style":{top:0,left:0,right:0,bottom:20,}},{"isClass":true,"priority":10000.0012,"key":"pageView","style":{}},{"isId":true,"priority":100000.0005,"key":"scrollable","style":{showPagingControl:true,}},{"isId":true,"priority":100000.0006,"key":"tiger","style":{top:20,left:20,right:20,bottom:20,backgroundColor:"white",}},{"isId":true,"priority":100000.0007,"key":"stylesheets","style":{}},{"isId":true,"priority":100000.0008,"key":"stop","style":{height:"40%",}},{"isId":true,"priority":100000.0009,"key":"caution","style":{height:"30%",}},{"isId":true,"priority":100000.001,"key":"go","style":{height:"30%",}}];
--------------------------------------------------------------------------------
/Resources/android/alloy/sync/localStorage.js:
--------------------------------------------------------------------------------
1 | function S4() {
2 | return (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
3 | }
4 |
5 | function guid() {
6 | return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
7 | }
8 |
9 | function InitAdapter() {
10 | throw "localStorage persistence supported only with MobileWeb.";
11 | }
12 |
13 | function Sync(method, model, opts) {
14 | function storeModel(data) {
15 | localStorage.setItem(name, JSON.stringify(data));
16 | }
17 | var name = model.config.adapter.collection_name, data = model.config.data, resp = null;
18 | switch (method) {
19 | case "create":
20 | if (!model.id) {
21 | model.id = guid();
22 | model.set(model.idAttribute, model.id);
23 | }
24 | data[model.id] = model;
25 | storeModel(data);
26 | resp = model.toJSON();
27 | break;
28 |
29 | case "read":
30 | var store = localStorage.getItem(name);
31 | var store_data = store && JSON.parse(store) || {};
32 | var len = 0;
33 | for (var key in store_data) {
34 | var m = new model.config.Model(store_data[key]);
35 | model.models.push(m);
36 | len++;
37 | }
38 | model.length = len;
39 | resp = 1 === len ? model.models[0] : model.models;
40 | break;
41 |
42 | case "update":
43 | data[model.id] = model;
44 | storeModel(data);
45 | resp = model.toJSON();
46 | break;
47 |
48 | case "delete":
49 | delete data[model.id];
50 | storeModel(data);
51 | resp = model.toJSON();
52 | }
53 | if (resp) {
54 | _.isFunction(opts.success) && opts.success(resp);
55 | "read" === method && model.trigger("fetch");
56 | } else _.isFunction(opts.error) && opts.error(resp);
57 | }
58 |
59 | var _ = require("alloy/underscore")._;
60 |
61 | module.exports.sync = Sync;
62 |
63 | module.exports.beforeModelCreate = function(config) {
64 | config = config || {};
65 | config.data = {};
66 | InitAdapter();
67 | return config;
68 | };
69 |
70 | module.exports.afterModelCreate = function(Model) {
71 | Model = Model || {};
72 | Model.prototype.config.Model = Model;
73 | return Model;
74 | };
--------------------------------------------------------------------------------
/Resources/android/alloy/sync/properties.js:
--------------------------------------------------------------------------------
1 | function S4() {
2 | return (65536 * (1 + Math.random()) | 0).toString(16).substring(1);
3 | }
4 |
5 | function guid() {
6 | return S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4();
7 | }
8 |
9 | function Sync(method, model, opts) {
10 | var prefix = model.config.adapter.collection_name ? model.config.adapter.collection_name : "default";
11 | var regex = new RegExp("^(" + prefix + ")\\-(.+)$");
12 | var resp = null;
13 | if ("read" === method) if (opts.parse) {
14 | var list = [];
15 | _.each(TAP.listProperties(), function(prop) {
16 | var match = prop.match(regex);
17 | null !== match && list.push(TAP.getObject(prop));
18 | });
19 | resp = list;
20 | } else {
21 | var obj = TAP.getObject(prefix + "-" + model.id);
22 | model.set(obj);
23 | resp = model.toJSON();
24 | } else if ("create" === method || "update" === method) {
25 | if (!model.id) {
26 | model.id = guid();
27 | model.set(model.idAttribute, model.id);
28 | }
29 | TAP.setObject(prefix + "-" + model.id, model.toJSON() || {});
30 | resp = model.toJSON();
31 | } else if ("delete" === method) {
32 | TAP.removeProperty(prefix + "-" + model.id);
33 | model.clear();
34 | resp = model.toJSON();
35 | }
36 | if (resp) {
37 | _.isFunction(opts.success) && opts.success(resp);
38 | "read" === method && model.trigger("fetch");
39 | } else _.isFunction(opts.error) && opts.error(resp);
40 | }
41 |
42 | var Alloy = require("alloy"), _ = require("alloy/underscore")._, TAP = Ti.App.Properties;
43 |
44 | module.exports.sync = Sync;
45 |
46 | module.exports.beforeModelCreate = function(config) {
47 | config = config || {};
48 | config.columns = config.columns || {};
49 | config.defaults = config.defaults || {};
50 | ("undefined" == typeof config.columns.id || null === config.columns.id) && (config.columns.id = "String");
51 | return config;
52 | };
--------------------------------------------------------------------------------
/Resources/android/alloy/widget.js:
--------------------------------------------------------------------------------
1 | var Alloy = require('alloy');
2 |
3 | // Hold a collection of widget objects instances. These
4 | // objects are not the widgets themselves, but a set of
5 | // auto-populated functions and properties that make
6 | // developing widgets easier.
7 | var widgets = {};
8 |
9 | function ucfirst(text) {
10 | if (!text) { return text; }
11 | return text[0].toUpperCase() + text.substr(1);
12 | }
13 |
14 | module.exports = function(widgetId) {
15 | var self = this;
16 |
17 | // return existing widget object, if present
18 | if (widgets[widgetId]) {
19 | return widgets[widgetId];
20 | }
21 |
22 | // properties
23 | this.widgetId = widgetId;
24 | this.Collections = {};
25 | this.Models = {};
26 | this.Shared = {};
27 |
28 | // functions
29 | this.createController = function(name, args) {
30 | return new (require('alloy/widgets/' + widgetId + '/controllers/' + name))(args);
31 | };
32 | this.createCollection = function(name, args) {
33 | return new (require('alloy/widgets/' + widgetId + '/models/' + ucfirst(name)).Collection)(args);
34 | };
35 | this.createModel = function(name, args) {
36 | return new (require('alloy/widgets/' + widgetId + '/models/' + ucfirst(name)).Model)(args);
37 | };
38 | this.createWidget = Alloy.createWidget; // just to be complete
39 | this.Collections.instance = function(name) {
40 | return self.Collections[name] || (self.Collections[name] = self.createCollection(name));
41 | };
42 | this.Models.instance = function(name) {
43 | return self.Models[name] || (self.Models[name] = self.createModel(name));
44 | };
45 |
46 | // add to widget object instances
47 | widgets[widgetId] = this;
48 | };
--------------------------------------------------------------------------------
/Resources/android/alloy/widgets/com.capnajax.vectorimage/controllers/widget.js:
--------------------------------------------------------------------------------
1 | function WPATH(s) {
2 | var index = s.lastIndexOf("/");
3 | var path = -1 === index ? "com.capnajax.vectorimage/" + s : s.substring(0, index) + "/com.capnajax.vectorimage/" + s.substring(index + 1);
4 | return true && 0 !== path.indexOf("/") ? "/" + path : path;
5 | }
6 |
7 | function __processArg(obj, key) {
8 | var arg = null;
9 | if (obj) {
10 | arg = obj[key] || null;
11 | delete obj[key];
12 | }
13 | return arg;
14 | }
15 |
16 | function Controller() {
17 | function init(obj) {
18 | $.widget.applyProperties(_.omit(obj, [ "svg", "style" ]));
19 | var width = obj.width, height = obj.height;
20 | draw(obj.svg, obj.style, width, height, obj.backgroundColor);
21 | }
22 | function cacheFile(svgString, styleString, width, height, backgroundColor) {
23 | var nameComponents = [];
24 | nameComponents.push(Ti.Utils.md5HexDigest(svgString));
25 | nameComponents.push(styleString && Ti.Utils.md5HexDigest(styleString) || "no-style");
26 | nameComponents.push(width && height ? width.toString() + "x" + height.toString() : width ? width.toString() + "w" : height ? height.toString() + "h" : "no-size");
27 | nameComponents.push(backgroundColor || "no-bg");
28 | var filename = "com.capnajax.vectorimage/imagecache/" + nameComponents.join(",");
29 | result = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, filename);
30 | return result;
31 | }
32 | function sourceText(source) {
33 | var result;
34 | if (_.isObject(source)) {
35 | if (source.apiName != Ti.Filesystem.File) throw new Error("com.capnajax.vectorimage::widget::sourceText invalid object, apiName " + source.apiName);
36 | result = source.read().text;
37 | } else {
38 | if (!_.isString(source)) throw new Error("com.capnajax.vectorimage::widget::sourceText invalid param of type " + typeof source);
39 | if (/[\<\{]/.test(source)) result = source; else {
40 | /^\//.test(source) || (source = Ti.Filesystem.resourcesDirectory + "/" + source);
41 | result = Ti.Filesystem.getFile(source).read().text;
42 | }
43 | }
44 | return result;
45 | }
46 | function draw(svg, style, width, height, backgroundColor, callback) {
47 | var svgString = svg && sourceText(svg);
48 | var styleString = style && sourceText(style);
49 | $.widget.removeAllChildren();
50 | if (v.willCache) {
51 | var file = cacheFile(svgString, styleString, width, height, backgroundColor);
52 | if (file.exists()) {
53 | Ti.API.info("com.capnajax.vectorimage drawing image from cache");
54 | var imageView = Ti.UI.createImageView({
55 | width: width,
56 | height: height,
57 | hires: true,
58 | image: file
59 | });
60 | _.defer(function() {
61 | $.widget.add(imageView);
62 | });
63 | } else {
64 | Ti.API.info("com.capnajax.vectorimage drawing image from svg");
65 | drawWebView(svgString, styleString, width, height, backgroundColor, function(imageBlob) {
66 | imageBlob && file.write(imageBlob);
67 | callback && callback(imageBlob);
68 | });
69 | }
70 | } else drawWebView(svgString, styleString, width, height, backgroundColor, callback);
71 | }
72 | function drawWebView(svg, style, width, height, backgroundColor, callback) {
73 | if (width || height) drawWebViewImpl(svg, style, width, height, backgroundColor, callback); else if ($.widget.rect.width || $.widget.rect.height) drawWebViewImpl(svg, style, $.widget.rect.width, $.widget.rect.height, backgroundColor, callback); else {
74 | var postlayout = function() {
75 | $.widget.removeEventListener("postlayout", postlayout);
76 | drawWebViewImpl(svg, style, $.widget.rect.width, $.widget.rect.height, backgroundColor, callback);
77 | };
78 | $.widget.addEventListener("postlayout", postlayout);
79 | }
80 | }
81 | function drawWebViewImpl(svg, style, width, height, backgroundColor) {
82 | var wvWidth = width || $.widget.rect.width, wvHeight = height || $.widget.rect.height;
83 | var SVGImage = require(WPATH("svg"));
84 | var svgImage = new SVGImage(svg, {
85 | styleString: style,
86 | width: wvWidth,
87 | height: wvHeight
88 | });
89 | var view = Ti.UI.createWebView({
90 | top: 0,
91 | left: 0,
92 | width: wvWidth,
93 | height: wvHeight,
94 | backgroundColor: backgroundColor || "transparent",
95 | showScrollbars: false,
96 | disableBounce: true,
97 | enableZoomControls: false,
98 | overScrollMode: Ti.UI.Android.OVER_SCROLL_NEVER
99 | });
100 | _.defer(function() {
101 | var svgSource = svgImage.serialize();
102 | view.html = '' + svgSource + "";
103 | $.widget.add(view);
104 | setTimeout(function() {}, 1e3);
105 | });
106 | }
107 | new (require("alloy/widget"))("com.capnajax.vectorimage");
108 | this.__widgetId = "com.capnajax.vectorimage";
109 | require("alloy/controllers/BaseController").apply(this, Array.prototype.slice.call(arguments));
110 | this.__controllerPath = "widget";
111 | if (arguments[0]) {
112 | __processArg(arguments[0], "__parentSymbol");
113 | __processArg(arguments[0], "$model");
114 | __processArg(arguments[0], "__itemTemplate");
115 | }
116 | var $ = this;
117 | var exports = {};
118 | $.__views.widget = Ti.UI.createView({
119 | id: "widget"
120 | });
121 | $.__views.widget && $.addTopLevelView($.__views.widget);
122 | exports.destroy = function() {};
123 | _.extend($, $.__views);
124 | var args = arguments[0] || {};
125 | Alloy.Globals["com.capnajax.vectorimage"] || (Alloy.Globals["com.capnajax.vectorimage"] = {});
126 | var v = Alloy.Globals["com.capnajax.vectorimage"];
127 | !function() {
128 | v.willCache = false;
129 | if (!v.cacheDirCreated) {
130 | v.cacheDirCreated = true;
131 | var createDir = function(path) {
132 | var dir = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, path);
133 | if (!dir.exists() && !dir.createDirectory()) {
134 | Ti.API.warn("com.capnajax.vectorimage cannot create image cache directory. Cache feature disabled");
135 | return false;
136 | }
137 | return true;
138 | };
139 | if (!(createDir("com.capnajax.vectorimage") && createDir("com.capnajax.vectorimage/imagecache"))) return;
140 | v.willCache = true;
141 | }
142 | }();
143 | init(args);
144 | _.extend($, exports);
145 | }
146 |
147 | var Alloy = require("alloy"), Backbone = Alloy.Backbone, _ = Alloy._;
148 |
149 | module.exports = Controller;
--------------------------------------------------------------------------------
/Resources/android/alloy/widgets/com.capnajax.vectorimage/models/Images.js:
--------------------------------------------------------------------------------
1 | var Alloy = require("alloy"), _ = require("alloy/underscore")._, model, collection;
2 |
3 | exports.definition = {
4 | config: {
5 | columns: {
6 | svg: "string",
7 | style: "string",
8 | widthpx: "int",
9 | heightpx: "int",
10 | png: "string"
11 | },
12 | adapter: {
13 | type: "sql",
14 | collection_name: "images"
15 | }
16 | },
17 | extendModel: function(Model) {
18 | _.extend(Model.prototype, {});
19 | return Model;
20 | },
21 | extendCollection: function(Collection) {
22 | _.extend(Collection.prototype, {});
23 | return Collection;
24 | }
25 | };
26 |
27 | model = Alloy.M("images", exports.definition, []);
28 |
29 | collection = Alloy.C("images", exports.definition, model);
30 |
31 | exports.Model = model;
32 |
33 | exports.Collection = collection;
--------------------------------------------------------------------------------
/Resources/android/alloy/widgets/com.capnajax.vectorimage/styles/widget.js:
--------------------------------------------------------------------------------
1 | function WPATH(s) {
2 | var index = s.lastIndexOf("/");
3 | var path = -1 === index ? "com.capnajax.vectorimage/" + s : s.substring(0, index) + "/com.capnajax.vectorimage/" + s.substring(index + 1);
4 | return true && 0 !== path.indexOf("/") ? "/" + path : path;
5 | }
6 |
7 | module.exports = [];
--------------------------------------------------------------------------------
/Resources/android/app.js:
--------------------------------------------------------------------------------
1 | var Alloy = require("alloy"), _ = Alloy._, Backbone = Alloy.Backbone;
2 |
3 | Alloy.createController("index");
--------------------------------------------------------------------------------
/Resources/android/com.capnajax.vectorimage/svg.js:
--------------------------------------------------------------------------------
1 | function SVGImage(svgString, options) {
2 | var _svgTag, _svgContent1, _defsContent, _svgContent2, _header, _footer;
3 | var _svgAttrs, _viewBox;
4 | var _style = options.styleString || "";
5 | var _serialized;
6 | this.getSvgTag = function() {
7 | _svgTag || parseSvg();
8 | return _svgTag;
9 | };
10 | this.getSvgContent1 = function() {
11 | _svgTag || parseSvg();
12 | return _svgContent1;
13 | };
14 | this.getDefsContent = function() {
15 | _svgTag || parseSvg();
16 | return _defsContent;
17 | };
18 | this.getSvgContent2 = function() {
19 | _svgTag || parseSvg();
20 | return _svgContent2;
21 | };
22 | this.getHeader = function() {
23 | _svgTag || parseSvg();
24 | return _header;
25 | };
26 | this.getFooter = function() {
27 | _svgTag || parseSvg();
28 | return _footer;
29 | };
30 | this.getStyle = function() {
31 | return _style;
32 | };
33 | this.setStyle = function(newStyle) {
34 | _serialized = null;
35 | _style = newStyle;
36 | };
37 | var parseSvg = function() {
38 | var headerEndIdx, footerIndex;
39 | if (-1 == (headerEndIdx = svgString.indexOf("