New MobileStocks app. A work in progress so it is not connected to the examples build yet.
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/c1682af6 Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/c1682af6 Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/c1682af6 Branch: refs/heads/develop Commit: c1682af60f20a3a76dce40841fbb34d848baa1ff Parents: 1dac615 Author: Peter Ent <p...@apache.org> Authored: Thu Sep 22 17:09:59 2016 -0400 Committer: Peter Ent <p...@apache.org> Committed: Thu Sep 22 17:09:59 2016 -0400 ---------------------------------------------------------------------- .../flexjs/MobileStocks/MobileStocks-app.xml | 252 ++++++++++++++++ examples/flexjs/MobileStocks/build-web.xml | 61 ++++ examples/flexjs/MobileStocks/build.xml | 94 ++++++ examples/flexjs/MobileStocks/pom.xml | 94 ++++++ .../flexjs/MobileStocks/src/MobileStocks.mxml | 43 +++ .../flexjs/MobileStocks/src/MyInitialView.mxml | 264 +++++++++++++++++ .../src/StockDataJSONItemConverter.as | 40 +++ .../MobileStocks/src/assets/arrow_left_24.png | Bin 0 -> 47785 bytes .../MobileStocks/src/assets/background.png | Bin 0 -> 49376 bytes .../flexjs/MobileStocks/src/assets/logo.png | Bin 0 -> 55223 bytes .../src/controller/AlertsViewController.as | 141 +++++++++ .../src/controller/LaunchViewController.as | 150 ++++++++++ .../src/controller/WatchListController.as | 139 +++++++++ .../flexjs/MobileStocks/src/models/Alert.as | 94 ++++++ .../flexjs/MobileStocks/src/models/Asset.as | 77 +++++ .../MobileStocks/src/models/AssetsModel.as | 57 ++++ .../MobileStocks/src/models/ProductsModel.as | 296 +++++++++++++++++++ .../flexjs/MobileStocks/src/models/Stock.as | 168 +++++++++++ .../MobileStocks/src/renderers/AlertRenderer.as | 44 +++ .../src/renderers/CompanyNameRenderer.as | 37 +++ .../src/renderers/SharesTotalRenderer.as | 37 +++ .../MobileStocks/src/renderers/StockRenderer.as | 47 +++ .../MobileStocks/src/views/AlertsView.mxml | 102 +++++++ .../MobileStocks/src/views/AssetsView.mxml | 125 ++++++++ .../MobileStocks/src/views/LaunchView.mxml | 161 ++++++++++ .../MobileStocks/src/views/SearchView.mxml | 37 +++ .../MobileStocks/src/views/StockView.mxml | 102 +++++++ .../MobileStocks/src/views/WatchListView.mxml | 154 ++++++++++ 28 files changed, 2816 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/MobileStocks-app.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/MobileStocks-app.xml b/examples/flexjs/MobileStocks/MobileStocks-app.xml new file mode 100644 index 0000000..e673bc5 --- /dev/null +++ b/examples/flexjs/MobileStocks/MobileStocks-app.xml @@ -0,0 +1,252 @@ +<?xml version="1.0" encoding="utf-8" standalone="no"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<application xmlns="http://ns.adobe.com/air/application/16.0"> + +<!-- Adobe AIR Application Descriptor File Template. + + Specifies parameters for identifying, installing, and launching AIR applications. + + xmlns - The Adobe AIR namespace: http://ns.adobe.com/air/application/3.8 + The last segment of the namespace specifies the version + of the AIR runtime required for this application to run. + + minimumPatchLevel - The minimum patch level of the AIR runtime required to run + the application. Optional. +--> + + <!-- A universally unique application identifier. Must be unique across all AIR applications. + Using a reverse DNS-style name as the id is recommended. (Eg. com.example.ExampleApplication.) Required. --> + <id>org.apache.flexjs.mobilestocks</id> + + <!-- Used as the filename for the application. Required. --> + <filename>Apache FlexJS Mobile Stocks Example</filename> + + <!-- The name that is displayed in the AIR application installer. + May have multiple values for each language. See samples or xsd schema file. Optional. --> + <name>Apache FlexJS Mobile Stocks Example</name> + + <!-- A string value of the format <0-999>.<0-999>.<0-999> that represents application version which can be used to check for application upgrade. + Values can also be 1-part or 2-part. It is not necessary to have a 3-part value. + An updated version of application must have a versionNumber value higher than the previous version. Required for namespace >= 2.5 . --> + <versionNumber>0.8.0</versionNumber> + + <!-- A string value (such as "v1", "2.5", or "Alpha 1") that represents the version of the application, as it should be shown to users. Optional. --> + <!-- <versionLabel></versionLabel> --> + + <!-- Description, displayed in the AIR application installer. + May have multiple values for each language. See samples or xsd schema file. Optional. --> + <!-- <description></description> --> + + <!-- Copyright information. Optional --> + <copyright>Copyright 2016 The Apache Software Foundation.</copyright> + + <!-- Publisher ID. Used if you're updating an application created prior to 1.5.3 --> + <!-- <publisherID></publisherID> --> + + <!-- Settings for the application's initial window. Required. --> + <initialWindow> + <!-- The main SWF or HTML file of the application. Required. --> + <!-- Note: In Flash Builder, the SWF reference is set automatically. --> + <content>MobileStocks.swf</content> + + <!-- The title of the main window. Optional. --> + <!-- <title></title> --> + + <!-- The type of system chrome to use (either "standard" or "none"). Optional. Default standard. --> + <!-- <systemChrome></systemChrome> --> + + <!-- Whether the window is transparent. Only applicable when systemChrome is none. Optional. Default false. --> + <!-- <transparent></transparent> --> + + <!-- Whether the window is initially visible. Optional. Default false. --> + <!-- <visible></visible> --> + + <!-- Whether the user can minimize the window. Optional. Default true. --> + <!-- <minimizable></minimizable> --> + + <!-- Whether the user can maximize the window. Optional. Default true. --> + <!-- <maximizable></maximizable> --> + + <!-- Whether the user can resize the window. Optional. Default true. --> + <!-- <resizable></resizable> --> + + <!-- The window's initial width in pixels. Optional. --> + <width>640</width> + + <!-- The window's initial height in pixels. Optional. --> + <height>720</height> + + <!-- The window's initial x position. Optional. --> + <!-- <x></x> --> + + <!-- The window's initial y position. Optional. --> + <!-- <y></y> --> + + <!-- The window's minimum size, specified as a width/height pair in pixels, such as "400 200". Optional. --> + <!-- <minSize></minSize> --> + + <!-- The window's initial maximum size, specified as a width/height pair in pixels, such as "1600 1200". Optional. --> + <!-- <maxSize></maxSize> --> + + <!-- The initial aspect ratio of the app when launched (either "portrait" or "landscape"). Optional. Mobile only. Default is the natural orientation of the device --> + + <!-- <aspectRatio></aspectRatio> --> + + <!-- Whether the app will begin auto-orienting on launch. Optional. Mobile only. Default false --> + + <!-- <autoOrients></autoOrients> --> + + <!-- Whether the app launches in full screen. Optional. Mobile only. Default false --> + + <!-- <fullScreen></fullScreen> --> + + <!-- The render mode for the app (either auto, cpu, gpu, or direct). Optional. Default auto --> + + <!-- <renderMode></renderMode> --> + + <!-- Whether or not to pan when a soft keyboard is raised or lowered (either "pan" or "none"). Optional. Defaults "pan." --> + <!-- <softKeyboardBehavior></softKeyboardBehavior> --> + <autoOrients>false</autoOrients> + <fullScreen>false</fullScreen> + <visible>true</visible> + </initialWindow> + + <!-- We recommend omitting the supportedProfiles element, --> + <!-- which in turn permits your application to be deployed to all --> + <!-- devices supported by AIR. If you wish to restrict deployment --> + <!-- (i.e., to only mobile devices) then add this element and list --> + <!-- only the profiles which your application does support. --> + <!-- <supportedProfiles>desktop extendedDesktop mobileDevice extendedMobileDevice</supportedProfiles> --> + <supportedProfiles>extendedDesktop desktop</supportedProfiles> + + <!-- The subpath of the standard default installation location to use. Optional. --> + <installFolder>Apache Flex</installFolder> + + <!-- The subpath of the Programs menu to use. (Ignored on operating systems without a Programs menu.) Optional. --> + <programMenuFolder>Apache Flex</programMenuFolder> + + <!-- The icon the system uses for the application. For at least one resolution, + specify the path to a PNG file included in the AIR package. Optional. --> + <icon> + <image16x16>assets/icons/16.png</image16x16> + <image29x29>assets/icons/29.png</image29x29> + <image32x32>assets/icons/32.png</image32x32> + <image36x36>assets/icons/36.png</image36x36> + <image48x48>assets/icons/48.png</image48x48> + <image57x57>assets/icons/57.png</image57x57> + <image72x72>assets/icons/72.png</image72x72> + <image114x114>assets/icons/114.png</image114x114> + <image128x128>assets/icons/128.png</image128x128> + </icon> + + <!-- Whether the application handles the update when a user double-clicks an update version + of the AIR file (true), or the default AIR application installer handles the update (false). + Optional. Default false. --> + <!-- <customUpdateUI></customUpdateUI> --> + + <!-- Whether the application can be launched when the user clicks a link in a web browser. + Optional. Default false. --> + <!-- <allowBrowserInvocation></allowBrowserInvocation> --> + + <!-- Listing of file types for which the application can register. Optional. --> + <!-- <fileTypes> --> + + <!-- Defines one file type. Optional. --> + <!-- <fileType> --> + + <!-- The name that the system displays for the registered file type. Required. --> + <!-- <name></name> --> + + <!-- The extension to register. Required. --> + <!-- <extension></extension> --> + + <!-- The description of the file type. Optional. --> + <!-- <description></description> --> + + <!-- The MIME content type. --> + <!-- <contentType></contentType> --> + + <!-- The icon to display for the file type. Optional. --> + <!-- <icon> + <image16x16></image16x16> + <image32x32></image32x32> + <image48x48></image48x48> + <image128x128></image128x128> + </icon> --> + + <!-- </fileType> --> + <!-- </fileTypes> --> + + <!-- iOS specific capabilities --> + <!-- <iPhone> --> + <!-- A list of plist key/value pairs to be added to the application Info.plist --> + <!-- <InfoAdditions> + <![CDATA[ + <key>UIDeviceFamily</key> + <array> + <string>1</string> + <string>2</string> + </array> + <key>UIStatusBarStyle</key> + <string>UIStatusBarStyleBlackOpaque</string> + <key>UIRequiresPersistentWiFi</key> + <string>YES</string> + ]]> + </InfoAdditions> --> + <!-- A list of plist key/value pairs to be added to the application Entitlements.plist --> + <!-- <Entitlements> + <![CDATA[ + <key>keychain-access-groups</key> + <array> + <string></string> + <string></string> + </array> + ]]> + </Entitlements> --> + <!-- Display Resolution for the app (either "standard" or "high"). Optional. Default "standard" --> + <!-- <requestedDisplayResolution></requestedDisplayResolution> --> + <!-- </iPhone> --> + + <!-- Specify Android specific tags that get passed to AndroidManifest.xml file. --> + <!--<android> --> + <!-- <manifestAdditions> + <![CDATA[ + <manifest android:installLocation="auto"> + <uses-permission android:name="android.permission.INTERNET"/> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> + <uses-feature android:required="true" android:name="android.hardware.touchscreen.multitouch"/> + <application android:enabled="true"> + <activity android:excludeFromRecents="false"> + <intent-filter> + <action android:name="android.intent.action.MAIN"/> + <category android:name="android.intent.category.LAUNCHER"/> + </intent-filter> + </activity> + </application> + </manifest> + ]]> + </manifestAdditions> --> + <!-- Color depth for the app (either "32bit" or "16bit"). Optional. Default 16bit before namespace 3.0, 32bit after --> + <!-- <colorDepth></colorDepth> --> + <!-- </android> --> + <!-- End of the schema for adding the android specific tags in AndroidManifest.xml file --> + +</application> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/build-web.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/build-web.xml b/examples/flexjs/MobileStocks/build-web.xml new file mode 100644 index 0000000..6892dc0 --- /dev/null +++ b/examples/flexjs/MobileStocks/build-web.xml @@ -0,0 +1,61 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> + + +<project name="mobilestocks" default="main" basedir="."> + <property name="FLEXJS_HOME" location="../../.."/> + <property name="example" value="MobileStocks" /> + + <property environment="env"/> + <property file="${FLEXJS_HOME}/build.properties"/> + <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> + <property name="opt1_arg" value="-remove-circulars" /> + + <include file="${basedir}/../../build_example.xml" /> + + <condition property="extlib_arg" value="-external-library-path=${FLEXJS_HOME}/js/libs/js.swc" > + <and> + <not> + <isset property="extlib_arg" /> + </not> + <available file="${FLEXJS_HOME}/js/libs/js.swc" type="file" /> + </and> + </condition> + <condition property="extlib_arg" value="-external-library-path=${FALCONJX_HOME}/../js/libs/js.swc" > + <and> + <not> + <isset property="extlib_arg" /> + </not> + <available file="${FALCONJX_HOME}/../js/libs/js.swc" type="file" /> + </and> + </condition> + <property name="extlib_arg" value="-external-library-path=${FALCONJX_HOME}/../externs/js/out/bin/js.swc"/> + + <target name="main" depends="clean,build_example.compile,build_example.compilejs" description="Clean build of ${example}"> + </target> + + <target name="clean"> + <delete dir="${basedir}/bin" failonerror="false" /> + <delete dir="${basedir}/bin-debug" failonerror="false" /> + <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> + </target> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/build.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/build.xml b/examples/flexjs/MobileStocks/build.xml new file mode 100644 index 0000000..62d465e --- /dev/null +++ b/examples/flexjs/MobileStocks/build.xml @@ -0,0 +1,94 @@ +<?xml version="1.0"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> + + +<project name="mobilestocks" default="main" basedir="."> + <property name="FLEXJS_HOME" location="../../.."/> + <property name="example" value="MobileStocks" /> + + <!-- this project needs AIR 3.4 FP 11.4 --> + <property name="swf.version" value="17" /> + <property name="playerglobal.version" value="11.4" /> + + <property file="${FLEXJS_HOME}/env.properties"/> + <property environment="env"/> + <property file="${FLEXJS_HOME}/build.properties"/> + <property name="FLEX_HOME" value="${FLEXJS_HOME}"/> + <property name="AIR_HOME" value="${env.AIR_HOME}"/> + + <condition property="adl" value="adl.exe"> + <os family="windows"/> + </condition> + + <condition property="adl" value="adl"> + <os family="mac"/> + </condition> + + <condition property="runtime" value="win"> + <os family="windows"/> + </condition> + + <condition property="runtime" value="mac"> + <os family="mac"/> + </condition> + + <include file="${basedir}/../../build_example.xml" /> + + <condition property="extlib_arg" value="-external-library-path=${FLEXJS_HOME}/js/libs/cordova.swc" > + <and> + <not> + <isset property="extlib_arg" /> + </not> + <available file="${FLEXJS_HOME}/js/libs/cordova.swc" type="file" /> + </and> + </condition> + <condition property="extlib_arg" value="-external-library-path=${FALCONJX_HOME}/../js/libs/cordova.swc" > + <and> + <not> + <isset property="extlib_arg" /> + </not> + <available file="${FALCONJX_HOME}/../js/libs/cordova.swc" type="file" /> + </and> + </condition> + <property name="extlib_arg" value="-external-library-path=${FALCONJX_HOME}/../externs/cordova/out/bin/cordova.swc"/> + <property name="opt1_arg" value="-remove-circulars" /> + +<!-- build_example.compileair, --> + <target name="main" depends="clean,build_example.compileair,build_example.compilejsair" description="Clean build of ${example}"> + </target> + + <target name="clean"> + <echo>playerglobal.version = ${playerglobal.version}</echo> + <delete dir="${basedir}/bin" failonerror="false" /> + <delete dir="${basedir}/bin-debug" failonerror="false" /> + <delete dir="${basedir}/bin-release" failonerror="false" /> + <delete dir="${basedir}/target" failonerror="false" /> + </target> + + <target name="run"> + <exec executable="${AIR_HOME}/bin/${adl}" dir="${basedir}/bin-debug" failonerror="true"> + <arg value="-runtime" /> + <arg value="${AIR_HOME}/runtimes/air/${runtime}" /> + <arg value="-profile" /> + <arg value="extendedDesktop" /> + <arg value="${basedir}/bin-debug/${example}-app.xml" /> + </exec> + </target> +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/pom.xml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/pom.xml b/examples/flexjs/MobileStocks/pom.xml new file mode 100644 index 0000000..7868f63 --- /dev/null +++ b/examples/flexjs/MobileStocks/pom.xml @@ -0,0 +1,94 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <!-- + TODO: + Flash Version: + Missing resources + --> + + <parent> + <groupId>org.apache.flex.flexjs.examples</groupId> + <artifactId>examples-flexjs</artifactId> + <version>0.8.0-SNAPSHOT</version> + </parent> + + <artifactId>MobileStocks</artifactId> + <version>0.8.0-SNAPSHOT</version> + <packaging>swf</packaging> + + <name>Apache Flex - FlexJS: Examples: FlexJS: MobileStocks</name> + + <build> + <plugins> + <plugin> + <groupId>org.apache.flex.flexjs.compiler</groupId> + <artifactId>flexjs-maven-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <mainClass>MobileStocks.mxml</mainClass> + <removeCirculars>true</removeCirculars> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-war-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>com.adobe.flash.framework</groupId> + <artifactId>playerglobal</artifactId> + <version>${flash.version}</version> + <type>swc</type> + <scope>provided</scope> + </dependency> + + <dependency> + <groupId>org.apache.flex.flexjs.framework</groupId> + <artifactId>Charts</artifactId> + <version>0.8.0-SNAPSHOT</version> + <type>swc</type> + </dependency> + <dependency> + <groupId>org.apache.flex.flexjs.framework</groupId> + <artifactId>Mobile</artifactId> + <version>0.8.0-SNAPSHOT</version> + <type>swc</type> + </dependency> + <dependency> + <groupId>org.apache.flex.flexjs.framework</groupId> + <artifactId>Network</artifactId> + <version>0.8.0-SNAPSHOT</version> + <type>swc</type> + </dependency> + </dependencies> + +</project> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/MobileStocks.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/MobileStocks.mxml b/examples/flexjs/MobileStocks/src/MobileStocks.mxml new file mode 100755 index 0000000..5b208ba --- /dev/null +++ b/examples/flexjs/MobileStocks/src/MobileStocks.mxml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<!--- +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +--> +<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:models="models.*" + xmlns:js="library://ns.apache.org/flexjs/basic" + > + + <js:valuesImpl> + <js:SimpleCSSValuesImpl /> + </js:valuesImpl> + + <js:model> + <models:ProductsModel /> + </js:model> + + <js:initialView> + <local:MyInitialView width="100%" height="100%" /> + </js:initialView> + + <js:beads> + <js:MixinManager /> + </js:beads> + +</js:Application> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/MyInitialView.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/MyInitialView.mxml b/examples/flexjs/MobileStocks/src/MyInitialView.mxml new file mode 100755 index 0000000..11873b1 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/MyInitialView.mxml @@ -0,0 +1,264 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +--> +<js:View xmlns:fx="http://ns.adobe.com/mxml/2009" + xmlns:local="*" + xmlns:js="library://ns.apache.org/flexjs/basic" + xmlns:views="views.*" + xmlns:apache="org.apache.flex.html.beads.*" + xmlns:html="org.apache.flex.html.*" + xmlns:controller="controller.*" + initComplete="onInitComplete()" xmlns:models="models.*" > + + <fx:Style> + @namespace js "library://ns.apache.org/flexjs/basic"; + @namespace views "views.*"; + + js|Container { + background-color: #FFFFFF; + } + + js|StackedViewManager { + padding-top: 0px; + padding-bottom: 0px; + padding-left: 0px; + padding-right: 0px; + } + + js|TabbedViewManager { + position : absolute ; + height : 100% ; + width : 100% ; + left : 0px ; + top : 0px ; + border: solid 1px #444444; + background-color: #FFFFFF; + } + + .NavigationBar { + background-image: url("assets/background.png"); + height: 55px; + IBeadLayout: ClassReference("org.apache.flex.html.beads.layouts.HorizontalLayout"); + } + + .TabBar { + background-color: #DEDEDE; + height: 55px; + vertical-align: middle; + line-height: 55px; + } + + .BackButton:hover { + background-image: url('assets/arrow_left_24.png'); + } + + .BackButton:active { + background-image: url('assets/arrow_left_24.png'); + } + + .BackButton { + background-image: url('assets/arrow_left_24.png'); + } + + .AssetsInner { + padding-top: 5px; + background-color: #FFFFFF; + } + + views|AssetsView { + width: 100%; + height: 100%; + } + + views|LaunchView { + width: 100%; + height: 100%; + IBeadController:ClassReference('controller.LaunchViewController'); + background-color: #FFFFFF; + } + + views|WatchListView { + width: 100%; + height: 100%; + IBeadController:ClassReference('controller.WatchListController'); + background-color: #FFFFFF; + } + + .WatchListInner { + height: 480px; + width: 100%; + background-color: #FFFFFF; + } + + .WatchListDataGrid { + height: 480px; + width: 100%; + } + + .WatchListInputArea { + background-color: #FFFFFF; + width: 480px; + height: 25px; + padding-top: 5px; + padding-bottom: 2px; + } + + views|StockView { + width: 100%; + height: 100%; + } + + views|AlertsView { + width: 100%; + height: 100%; + IBeadController:ClassReference('controller.AlertsViewController'); + } + + .redCell { + color: #FF0000; + } + + .greenCell { + color: #00FF00; + } + + .ViewTitle { + font-size: 18pt; + font-weight: bold; + padding: 10pt; + } + + .StockName { + font-size: 14pt; + font-weight: normal; + padding: 10pt; + } + + .StockDetailArea { + padding: 10pt; + } + + .StockLabel { + font-size: 18pt; + font-weight: normal; + color: #2255DD; + } + + .StockRemoveButton { + background-color: #FF5522; + font-size: 16pt; + font-weight: bold; + color: #FFFFFF; + width: 200px; + height: 50px; + } + + .StockRemoveButton:hover { + background-color: #DD3300; + } + + .StockValue { + font-size: 18pt; + font-weight: normal; + color: #999999; + } + + @media -flex-flash + { + .NavigationBar { + IBackgroundBead: ClassReference("org.apache.flex.html.beads.BackgroundImageBead"); + } + } + + </fx:Style> + + <fx:Script> + <![CDATA[ + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.events.Event; + import org.apache.flex.mobile.IViewManagerView; + import org.apache.flex.mobile.IViewManager; + import org.apache.flex.mobile.chrome.NavigationBar; + + import models.ProductsModel; + + private function onInitComplete():void + { + (applicationModel as ProductsModel).loadDataFromStorage(); + } + + private function onAssetsNext():void + { + + } + + private function tabbedViewChanged(event:org.apache.flex.events.Event):void + { + var manager:IViewManager = event.currentTarget as IViewManager; + trace("TabbedViewChanged for "+manager); + } + + private function watchListStackChanged(event:org.apache.flex.events.Event):void + { + trace("watchlist stack changed"); + var manager:StackedViewManager = event.currentTarget as StackedViewManager; + + var currentView:IViewManagerView = manager.selectedView; + backButton.visible = manager.views.length > 1; + } + + private function goBack(event:org.apache.flex.events.MouseEvent):void + { + if (navController.selectedIndex == 1) { + watchListStack.pop(); + } + } + ]]> + </fx:Script> + + <js:beads> + <js:ViewDataBinding /> + </js:beads> + + <js:TabbedViewManager id="navController" width="100%" height="100%" x="0" y="0" viewChanged="tabbedViewChanged(event)"> + <js:navigationBarItems> + <js:TextButton id="backButton" width="45" height="45" className="BackButton" visible="false" click="goBack(event)"> + <js:beads> + <apache:ImageButtonView /> + </js:beads> + </js:TextButton> + <js:Image source="assets/logo.png" width="218" height="55" /> + </js:navigationBarItems> + <js:views> + <js:StackedViewManager title="Assets"> + <js:views> + <views:LaunchView id="assetsView" title="Assets" next="onAssetsNext()" dataModel="{applicationModel}" /> + </js:views> + </js:StackedViewManager> + + <js:StackedViewManager id="watchListStack" title="Watch List" viewChanged="watchListStackChanged(event)"> + <js:views> + <views:WatchListView id="watchListView" dataModel="{applicationModel}"/> + </js:views> + </js:StackedViewManager> + </js:views> + </js:TabbedViewManager> + +</js:View> http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/StockDataJSONItemConverter.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/StockDataJSONItemConverter.as b/examples/flexjs/MobileStocks/src/StockDataJSONItemConverter.as new file mode 100755 index 0000000..5c21c26 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/StockDataJSONItemConverter.as @@ -0,0 +1,40 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package +{ + import org.apache.flex.collections.converters.JSONItemConverter; + + public class StockDataJSONItemConverter extends JSONItemConverter + { + public function StockDataJSONItemConverter() + { + super(); + } + + override public function convertItem(data:String):Object + { + var obj:Object = super.convertItem(data); + if (obj["query"]["count"] == 0) + return "No Data"; + + obj = obj["query"]["results"]["quote"]; + return obj; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/assets/arrow_left_24.png ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/assets/arrow_left_24.png b/examples/flexjs/MobileStocks/src/assets/arrow_left_24.png new file mode 100755 index 0000000..a3019ba Binary files /dev/null and b/examples/flexjs/MobileStocks/src/assets/arrow_left_24.png differ http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/assets/background.png ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/assets/background.png b/examples/flexjs/MobileStocks/src/assets/background.png new file mode 100755 index 0000000..87bbd59 Binary files /dev/null and b/examples/flexjs/MobileStocks/src/assets/background.png differ http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/assets/logo.png ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/assets/logo.png b/examples/flexjs/MobileStocks/src/assets/logo.png new file mode 100755 index 0000000..0fb0f21 Binary files /dev/null and b/examples/flexjs/MobileStocks/src/assets/logo.png differ http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/controller/AlertsViewController.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/controller/AlertsViewController.as b/examples/flexjs/MobileStocks/src/controller/AlertsViewController.as new file mode 100644 index 0000000..76f230a --- /dev/null +++ b/examples/flexjs/MobileStocks/src/controller/AlertsViewController.as @@ -0,0 +1,141 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package controller +{ + import models.Alert; + import models.ProductsModel; + import models.Stock; + + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.utils.Timer; + import org.apache.flex.collections.ArrayList; + + import views.AlertsView; + + public class AlertsViewController extends EventDispatcher implements IBeadController + { + public function AlertsViewController() + { + super(); + + timer = new Timer(updateInterval, 0); + timer.addEventListener("timer", timerHandler); + } + + public var updateInterval:Number = 5000; + + protected var timer:Timer; + + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + + var view:AlertsView = value as AlertsView; + view.addEventListener("alertSet", handleAlertSet); + } + + private var _model:IBeadModel; + public function set model(value:IBeadModel):void + { + _model = value; + } + public function get model():IBeadModel + { + return _model; + } + + private function handleAlertSet(event:Event):void + { + var view:AlertsView = _strand as AlertsView; + + var sym:String = view.symbolField.text.toUpperCase(); + var value:Number = Number(view.valueField.text); + + var alert:Alert = new Alert(); + alert.symbol = sym; + alert.value = value; + alert.greaterThan = view.higherCheck.selected; + + // add this stock to the watch list in case it isn't there already + alert.stock = (model as ProductsModel).addStockToWatchList(sym); + + // set up the alert for the stock + (model as ProductsModel).addAlert(alert); + + view.symbolField.text = ""; + view.valueField.text = ""; + + subscribe(); + } + + public function subscribe():void + { + if (!timer.running) + { + timer.start(); + } + } + + public function unsubscribe():void + { + if (timer.running) + { + timer.stop(); + } + } + + /** + * When the timer goes off, verify all of the alerts against each stocks' last + * price. + */ + protected function timerHandler(event:*):void + { + var alerts:ArrayList = (model as ProductsModel).alerts; + + if (alerts.length == 0) return; + + for (var i:int=0; i < alerts.length; i++) + { + var alert:Alert = alerts.getItemAt(i) as Alert; + alert.message = ""; + + if (alert.greaterThan) { + if (alert.stock.last >= alert.value) { + alert.message = "Now @"+alert.stock.last; + } + } + else { + if (alert.stock.last <= alert.value) { + alert.message = "Now @"+alert.stock.last; + } + } + alerts.itemUpdatedAt(i); + } + + var newEvent:Event = new Event("alertsUpdate"); + model.dispatchEvent(newEvent); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/controller/LaunchViewController.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/controller/LaunchViewController.as b/examples/flexjs/MobileStocks/src/controller/LaunchViewController.as new file mode 100644 index 0000000..2b88d26 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/controller/LaunchViewController.as @@ -0,0 +1,150 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package controller +{ + import models.ProductsModel; + import models.Stock; + + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.utils.Timer; + import org.apache.flex.collections.ArrayList; + + import views.LaunchView; + + public class LaunchViewController extends EventDispatcher implements IBeadController + { + public function LaunchViewController() + { + super(); + + timer = new Timer(updateInterval, 0); + timer.addEventListener("timer", timerHandler); + } + + public var updateInterval:Number = 5000; + + protected var timer:Timer; + + private var index:Number = 0; + private var selectedStock:Stock; + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + + var view:LaunchView = value as LaunchView; + view.addEventListener("addSymbol", handleAddSymbol); + view.addEventListener("removeSymbol", handleRemoveSymbol); + view.addEventListener("symbolSelected", handleGridSelection); + } + + private var _model:IBeadModel; + public function set model(value:IBeadModel):void + { + _model = value; + } + public function get model():IBeadModel + { + return _model; + } + + private function handleAddSymbol(event:Event):void + { + var view:LaunchView = _strand as LaunchView; + var symbol:String = view.symbolInput.text.toUpperCase(); + var shares:Number = Number(view.sharesInput.text); + if (isNaN(shares) || shares < 0) shares = 0; + + (model as ProductsModel).addStockToAssetList(symbol, shares); + (model as ProductsModel).saveDataToStorage(); + + subscribe(); + + view.symbolInput.text = ""; + view.sharesInput.text = ""; + view.addButton.text = "Add"; + } + + private function handleGridSelection(event:Event):void + { + var view:LaunchView = _strand as LaunchView; + var index:int = view.assetGrid.selectedIndex; + var data:Object = (model as ProductsModel).assetList.getItemAt(index); + view.symbolInput.text = data.symbol; + view.sharesInput.text = String(data.shares); + + view.addButton.text = "Change"; + } + + public function handleRemoveSymbol(event:Event):void + { + var view:LaunchView = _strand as LaunchView; + var index:int = view.assetGrid.selectedIndex; + if (index < 0) return; + + (model as ProductsModel).removeStockFromAssetListAtIndex(index); + + view.symbolInput.text = ""; + view.sharesInput.text = ""; + + view.addButton.text = "Add"; + } + + public function subscribe():void + { + if (!timer.running) + { + timer.start(); + } + } + + public function unsubscribe():void + { + if (timer.running) + { + timer.stop(); + } + } + + /** + * Each time the handler goes off a different stock in the list + * is updated. This keeps the app from sending too many requests + * all at once. + */ + protected function timerHandler(event:*):void + { + var stockList:ArrayList = (model as ProductsModel).assetList; + + if (stockList.length == 0) return; + + if (index >= stockList.length) index = 0; + + (model as ProductsModel).updateStockData(stockList.getItemAt(index) as Stock); + index++; + + var newEvent:Event = new Event("update"); + model.dispatchEvent(newEvent); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/controller/WatchListController.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/controller/WatchListController.as b/examples/flexjs/MobileStocks/src/controller/WatchListController.as new file mode 100644 index 0000000..0d94e5f --- /dev/null +++ b/examples/flexjs/MobileStocks/src/controller/WatchListController.as @@ -0,0 +1,139 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package controller +{ + import models.ProductsModel; + import models.Stock; + + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.utils.Timer; + import org.apache.flex.collections.ArrayList; + + import views.StockView; + import views.WatchListView; + + public class WatchListController extends EventDispatcher implements IBeadController + { + public function WatchListController() + { + super(); + + timer = new Timer(updateInterval, 0); + timer.addEventListener("timer", timerHandler); + } + + public var updateInterval:Number = 5000; + + protected var timer:Timer; + + private var index:Number = 0; + private var selectedStock:Stock; + private var _strand:IStrand; + + public function set strand(value:IStrand):void + { + _strand = value; + + var view:WatchListView = value as WatchListView; + view.addEventListener("addSymbol", handleAddSymbol); + view.addEventListener("stockSelected", handleGridSelection); + } + + private var _model:IBeadModel; + public function set model(value:IBeadModel):void + { + _model = value; + } + public function get model():IBeadModel + { + return _model; + } + + private function handleAddSymbol(event:Event):void + { + var view:WatchListView = _strand as WatchListView; + var symbol:String = view.symbolName.text.toUpperCase(); + + view.symbolName.text = ""; + + (model as ProductsModel).addStockToWatchList(symbol); + (model as ProductsModel).saveDataToStorage(); + + subscribe(); + } + + private function handleGridSelection(event:Event):void + { + var view:WatchListView = _strand as WatchListView; + selectedStock = (model as ProductsModel).watchList.getItemAt(view.selectedStockIndex) as Stock; + trace("Selected stock "+selectedStock.symbol); + + var stockView:StockView = view.showStockDetails(selectedStock); + stockView.addEventListener("removeFromList", handleRemoveFromList); + } + + public function handleRemoveFromList(event:Event):void + { + (model as ProductsModel).removeStockFromWatchList(selectedStock); + + var view:WatchListView = _strand as WatchListView; + view.popView(); + } + + public function subscribe():void + { + if (!timer.running) + { + timer.start(); + } + } + + public function unsubscribe():void + { + if (timer.running) + { + timer.stop(); + } + } + + /** + * Each time the handler goes off a different stock in the list + * is updated. This keeps the app from sending too many requests + * all at once. + */ + protected function timerHandler(event:*):void + { + var stockList:ArrayList = (model as ProductsModel).watchList; + + if (stockList.length == 0) return; + + if (index >= stockList.length) index = 0; + + (model as ProductsModel).updateStockData(stockList.getItemAt(index) as Stock); + index++; + + var newEvent:Event = new Event("update"); + model.dispatchEvent(newEvent); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/models/Alert.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/models/Alert.as b/examples/flexjs/MobileStocks/src/models/Alert.as new file mode 100644 index 0000000..7b9dc8b --- /dev/null +++ b/examples/flexjs/MobileStocks/src/models/Alert.as @@ -0,0 +1,94 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package models +{ + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + public class Alert extends EventDispatcher + { + public function Alert() + { + super(); + message = ""; + } + + private var _symbol:String; + private var _value:Number; + private var _greaterThan:Boolean; + private var _message:String; + private var _stock:Stock; + + [Binding("symbolChanged")] + public function get symbol():String + { + return _symbol; + } + public function set symbol(value:String):void + { + _symbol = value; + dispatchEvent(new Event("symbolChanged")); + } + + [Binding("messageChanged")] + public function get message():String + { + return _message; + } + public function set message(value:String):void + { + _message = value; + dispatchEvent(new Event("messageChanged")); + } + + [Binding("valueChanged")] + public function get value():Number + { + return _value; + } + public function set value(newValue:Number):void + { + _value = newValue; + dispatchEvent(new Event("valueChanged")); + } + + [Binding("greaterThanChanged")] + public function get greaterThan():Boolean + { + return _greaterThan; + } + public function set greaterThan(value:Boolean):void + { + _greaterThan = value; + dispatchEvent(new Event("greaterThanChanged")); + } + + [Binding("stockChanged")] + public function get stock():Stock + { + return _stock; + } + public function set stock(value:Stock):void + { + _stock = value; + dispatchEvent(new Event("stockChanged")); + } + + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/models/Asset.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/models/Asset.as b/examples/flexjs/MobileStocks/src/models/Asset.as new file mode 100644 index 0000000..869ba72 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/models/Asset.as @@ -0,0 +1,77 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package models +{ + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + public class Asset extends EventDispatcher + { + private var _label:String; + private var _value:Number; + private var _netChange:Number; + + public function Asset(newLabel:String, newValue:Number, newNetChange:Number) + { + _label = newLabel; + _value = newValue; + _netChange = newNetChange; + } + + [Bindable("labelChanged")] + public function get label():String + { + return _label; + } + public function set label(value:String):void + { + if (value != _label) { + _label = value; + dispatchEvent(new Event("labelChanged")); + } + } + + [Bindable("valueChanged")] + public function get value():Number + { + return _value; + } + public function set value(newValue:Number):void + { + if (_value != newValue) { + _value = newValue; + dispatchEvent(new Event("valueChanged")); + } + } + + [Bindable("netChangeChanged")] + public function get netChange():Number + { + return _netChange; + } + public function set netChange(value:Number):void + { + if (_netChange != value) { + _netChange = value; + dispatchEvent(new Event("netChangeChanged")); + } + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/models/AssetsModel.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/models/AssetsModel.as b/examples/flexjs/MobileStocks/src/models/AssetsModel.as new file mode 100755 index 0000000..3d72137 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/models/AssetsModel.as @@ -0,0 +1,57 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package models +{ + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.collections.ArrayList; + + public class AssetsModel extends EventDispatcher implements IBeadModel + { + public function AssetsModel() + { + super(); + _assetsData = new ArrayList(); + _assetsData.source = source; + } + private var source:Array = [ + new Asset("NetWorth:", 161984, 2.36), + new Asset("Last Month:", 165915, 10.98), + new Asset("6 Months Ago:", 145962, 16.56), + new Asset("Last Year:", 138972, 8.36) + ]; + private var _assetsData:ArrayList; + + public function get assetsData():ArrayList + { + return _assetsData; + } + + public function get assetsDataAsArray():Array + { + return source; + } + + public function set strand(value:IStrand):void + { + // not used + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/models/ProductsModel.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/models/ProductsModel.as b/examples/flexjs/MobileStocks/src/models/ProductsModel.as new file mode 100755 index 0000000..91bc792 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/models/ProductsModel.as @@ -0,0 +1,296 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package models +{ + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + import org.apache.flex.net.HTTPService; + import org.apache.flex.collections.parsers.JSONInputParser; + import org.apache.flex.collections.LazyCollection; + import org.apache.flex.collections.ArrayList; + + import org.apache.flex.storage.PermanentStorage; + import org.apache.flex.storage.events.FileEvent; + import org.apache.flex.storage.events.FileErrorEvent; + + public class ProductsModel extends EventDispatcher implements IBeadModel + { + public function ProductsModel() + { + super(); + + service = new HTTPService(); + collection = new LazyCollection; + collection.inputParser = new JSONInputParser(); + collection.itemConverter = new StockDataJSONItemConverter(); + + _watchList = new ArrayList(); + _assetList = new ArrayList(); + } + + public function loadDataFromStorage():void + { + var storage:PermanentStorage = new PermanentStorage(); + var useFile:String = "com.apache.flex.MobileStocks2"; + + storage.addEventListener("READ", handleRead); + storage.addEventListener("ERROR", handleReadError); + storage.readTextFromDataFile(useFile); + } + + private function handleRead(event:FileEvent):void + { + trace(event.data); + var result:XML = new XML(event.data); + trace("XML parsing:"); + trace(result); + + var assetItems:XMLList = result..asset; + trace("Got "+assetItems.length()+" assets"); + for each (var asset:XML in assetItems) { + trace("symbol = " + asset.@symbol + ", shares = " + asset.@shares); + addStockToAssetList(asset.@symbol, Number(asset.@shares)); + } + + var watchItems:XMLList = result..watch; + trace("Got "+watchItems.length()+" watches"); + for each (var watch:XML in watchItems) { + trace("symbol = "+watch.@symbol); + addStockToWatchList(watch.@symbol); + } + } + + private function handleReadError(event:FileErrorEvent):void + { + trace("Read error: "+event.errorMessage); + } + + public function saveDataToStorage():void + { + var storage:PermanentStorage = new PermanentStorage(); + var useFile:String = "com.apache.flex.MobileStocks2"; + var assets:String = ""; + + for (var i:int=0; i < _assetList.length; i++) { + var stock:Stock = _assetList.getItemAt(i) as Stock; + assets = assets + '<asset symbol="'+stock.symbol+'" shares="'+stock.shares+'" />'; + } + + var watches:String = ""; + for (i=0; i < _watchList.length; i++) { + stock = _watchList.getItemAt(i) as Stock; + watches = watches + '<watch symbol="'+stock.symbol+'" />'; + } + + var output:String = "<data><assets>"+assets+"</assets><watches>"+watches+"</watches></data>"; + + trace("Writing: "+output); + + storage.addEventListener("WRITE", handleSave); + storage.addEventListener("ERROR", handleSaveError); + storage.writeTextToDataFile(useFile, output); + } + + private function handleSave(event:FileEvent):void + { + trace("Save completed"); + } + + private function handleSaveError(event:FileErrorEvent):void + { + trace("Write error: "+event.errorMessage); + } + + private var service:HTTPService; + private var collection:LazyCollection; + private var queryBegin:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22"; + private var queryEnd:String = "%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json"; + + private var _strand:IStrand; + public function set strand(value:IStrand):void + { + _strand = value; + + service.addBead(collection); + _strand.addBead(service); + } + + private var _tabList:Array = ["Assets", "Watch", "Alerts"]; + public function get tabList():Array + { + return _tabList; + } + + private var _labelFields:Array = [ "id", "title", "detail" ]; + public function get labelFields():Array + { + return _labelFields; + } + + private var _watchList:ArrayList; + + public function get watchList():ArrayList + { + return _watchList; + } + + private var _assetList:ArrayList; + + public function get assetList():ArrayList + { + return _assetList; + } + + public function addStockToAssetList(symbol:String, shares:Number):Stock + { + for (var i:int=0; i < _assetList.length; i++) + { + var stock:Stock = _assetList.getItemAt(i) as Stock; + if (stock.symbol == symbol) { + stock.shares = shares; + _assetList.itemUpdatedAt(i); + return stock; + } + } + + stock = new Stock(symbol); + stock.shares = shares; + + _assetList.addItem(stock); + updateStockData(stock); + + return stock; + } + + public function addStockToWatchList(symbol:String):Stock + { + for (var i:int=0; i < _watchList.length; i++) + { + var stock:Stock = _watchList.getItemAt(i) as Stock; + if (stock.symbol == symbol) { + _watchList.itemUpdatedAt(i); + return stock; + } + } + + stock = new Stock(symbol); + _watchList.addItem(stock); + updateStockData(stock); + return stock; + } + + public function removeStockFromWatchList(stock:Stock):void + { + for (var i:int=0; i < _watchList.length; i++) + { + var s:Stock = _watchList.getItemAt(i) as Stock; + if (stock.symbol == s.symbol) { + _watchList.removeItemAt(i); + break; + } + } + + dispatchEvent(new Event("update")); + } + + public function removeStockFromAssetListAtIndex(index:int):void + { + if (index >= 0 && index < _assetList.length) { + _assetList.removeItemAt(index); + dispatchEvent(new Event("update")); + } + } + + // UPDATE STOCK INFORMATION FROM REMOTE SYSTEM + + public function updateStockData(value:Stock):void + { + var sym:String = value.symbol; + service.url = queryBegin + sym + queryEnd; + service.send(); + service.addEventListener("complete", completeHandler); + } + + private function completeHandler(event:Event):void + { + var responseData:Object = collection.getItemAt(0); + var sym:String = responseData["Symbol"]; + + var queueNext:Stock = null; + + for (var i:int=0; i < _watchList.length; i++) + { + var stock:Stock = _watchList.getItemAt(i) as Stock; + if (stock.symbol == sym) { + stock.updateFromData(responseData); + _watchList.itemUpdatedAt(i); + } + else if (stock.last == 0) { + queueNext = stock; + } + } + + for (i=0; i < _assetList.length; i++) + { + stock = _assetList.getItemAt(i) as Stock; + if (stock.symbol == sym) { + stock.updateFromData(responseData); + _assetList.itemUpdatedAt(i); + } + else if (stock.last == 0) { + queueNext = stock; + } + } + + if (queueNext != null) { + trace("--- queue: "+queueNext.symbol); + updateStockData(queueNext); + } + + } + + + + + // discard alerts + private var _alerts:ArrayList; + + public function get alerts():ArrayList + { + return _alerts; + } + + public function addAlert(value:Alert):void + { + for (var i:int =0; i < _alerts.length; i++) + { + var alert:Alert = _alerts.getItemAt(i) as Alert; + if (alert.symbol == value.symbol) { + _alerts.setItemAt(value, i); + return; + } + } + + _alerts.addItem(value); + dispatchEvent(new Event("alertsUpdate")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/models/Stock.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/models/Stock.as b/examples/flexjs/MobileStocks/src/models/Stock.as new file mode 100755 index 0000000..55f74cc --- /dev/null +++ b/examples/flexjs/MobileStocks/src/models/Stock.as @@ -0,0 +1,168 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package models +{ + import org.apache.flex.events.Event; + import org.apache.flex.events.EventDispatcher; + + public class Stock extends EventDispatcher + { + public var history:Array; + + public function Stock(symbol:String=null, last:Number=0) + { + this.symbol = symbol; + this.last = last; + this.low = last; + this.high = last; + this.open = last; + this.change = 0; + this.name = ""; + this.shares = 0; + } + + public function updateFromData(obj:Object):void + { + name = obj["Name"]; + low = obj["DaysLow"]; + high = obj["DaysHigh"]; + open = obj["Open"]; + change = obj["Change"]; + symbol = obj["Symbol"]; + last = obj["LastTradePriceOnly"]; + // shares do not change this way + } + + private var _symbol:String; + private var _name:String; + private var _low:Number; + private var _high:Number; + private var _open:Number; + private var _last:Number; + private var _change:Number; + private var _date:Date; + + private var _shares:Number; + + [Bindable("symbolChanged")] + public function get symbol():String + { + return _symbol; + } + public function set symbol(value:String):void + { + _symbol = value; + dispatchEvent(new Event("symbolChanged")); + } + + [Bindable("nameChanged")] + public function get name():String + { + return _name; + } + public function set name(value:String):void + { + _name = value; + dispatchEvent(new Event("nameChanged")); + } + + [Bindable("lowChanged")] + public function get low():Number + { + return _low; + } + public function set low(value:Number):void + { + _low = value; + dispatchEvent(new Event("lowChanged")); + } + + [Bindable("highChanged")] + public function get high():Number + { + return _high; + } + public function set high(value:Number):void + { + _high = value; + dispatchEvent(new Event("highChanged")); + } + + [Bindable("openChanged")] + public function get open():Number + { + return _open; + } + public function set open(value:Number):void + { + _open = value; + dispatchEvent(new Event("openChanged")); + } + + [Bindable("lastChanged")] + public function get last():Number + { + return _last; + } + public function set last(value:Number):void + { + _last = value; + dispatchEvent(new Event("lastChanged")); + } + + [Bindable("changeChanged")] + public function get change():Number + { + return _change; + } + public function set change(value:Number):void + { + _change = value; + dispatchEvent(new Event("changeChanged")); + } + + [Bindable("dateChanged")] + public function get date():Date + { + return _date; + } + public function set date(value:Date):void + { + _date = value; + dispatchEvent(new Event("dateChanged")); + } + + [Bindable("sharedChanged")] + public function get shares():Number + { + return _shares; + } + public function set shares(value:Number):void + { + _shares = value; + dispatchEvent(new Event("sharesChanged")); + } + + public function get total():Number + { + return _shares * _last; + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/renderers/AlertRenderer.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/renderers/AlertRenderer.as b/examples/flexjs/MobileStocks/src/renderers/AlertRenderer.as new file mode 100644 index 0000000..e683020 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/renderers/AlertRenderer.as @@ -0,0 +1,44 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package renderers +{ + import org.apache.flex.html.supportClasses.StringItemRenderer; + + public class AlertRenderer extends StringItemRenderer + { + public function AlertRenderer() + { + super(); + } + + override public function set data(value:Object):void + { + super.data = value; + + if (labelField == "greaterThan") { + if (Boolean(value[labelField])) { + text = "when over "+value["value"]; + } + else { + text = "when under "+value["value"]; + } + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/renderers/CompanyNameRenderer.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/renderers/CompanyNameRenderer.as b/examples/flexjs/MobileStocks/src/renderers/CompanyNameRenderer.as new file mode 100644 index 0000000..e899b57 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/renderers/CompanyNameRenderer.as @@ -0,0 +1,37 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package renderers +{ + import org.apache.flex.html.supportClasses.StringItemRenderer; + + public class CompanyNameRenderer extends StringItemRenderer + { + public function CompanyNameRenderer() + { + super(); + } + + override public function set data(value:Object):void + { + super.data = value; + + text = data.name + " (" + data.symbol + ")"; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/renderers/SharesTotalRenderer.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/renderers/SharesTotalRenderer.as b/examples/flexjs/MobileStocks/src/renderers/SharesTotalRenderer.as new file mode 100644 index 0000000..f6ac94b --- /dev/null +++ b/examples/flexjs/MobileStocks/src/renderers/SharesTotalRenderer.as @@ -0,0 +1,37 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package renderers +{ + import org.apache.flex.html.supportClasses.StringItemRenderer; + + public class SharesTotalRenderer extends StringItemRenderer + { + public function SharesTotalRenderer() + { + super(); + } + + override public function set data(value:Object):void + { + super.data = value; + + text = "$"+String( int(data.total*100)/100.0 ); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/renderers/StockRenderer.as ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/renderers/StockRenderer.as b/examples/flexjs/MobileStocks/src/renderers/StockRenderer.as new file mode 100755 index 0000000..afba26f --- /dev/null +++ b/examples/flexjs/MobileStocks/src/renderers/StockRenderer.as @@ -0,0 +1,47 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package renderers +{ + import org.apache.flex.html.supportClasses.StringItemRenderer; + + public class StockRenderer extends StringItemRenderer + { + public function StockRenderer() + { + super(); + } + + override public function set data(value:Object):void + { + super.data = value; + + var n1:Number = Number(value[labelField]); + if (!isNaN(n1)) { + n1 = Math.round(n1*100)/100.0; + + // something to keep in mind when using FlexJS for cross-platform + // use: make sure that public properties are used versus protected + // functions or properties. in most cases, internal vars and functions + // will be platform-specific whereas public properties and function + // should be cross-platform. + text = String(n1); + } + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/views/AlertsView.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/views/AlertsView.mxml b/examples/flexjs/MobileStocks/src/views/AlertsView.mxml new file mode 100755 index 0000000..3cc2b79 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/views/AlertsView.mxml @@ -0,0 +1,102 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +--> +<js:TitleView xmlns:fx="http://ns.adobe.com/mxml/2009" + title="Alerts" + xmlns:js="library://ns.apache.org/flexjs/basic" + xmlns:local="*" + className="AlertsView" xmlns:renderers="renderers.*"> + + <fx:Metadata> + [Event("next")] + </fx:Metadata> + + <fx:Script> + <![CDATA[ + import org.apache.flex.core.IBeadModel; + import org.apache.flex.core.IBeadController; + import org.apache.flex.events.Event; + import controller.AlertsViewController; + + public function set dataModel(value:IBeadModel):void + { + var cm:IBeadController = controller; + (cm as AlertsViewController).model = value; + } + public function get dataModel():IBeadModel + { + var cm:IBeadController = controller; + return (cm as AlertsViewController).model; + } + + private function onAlertSet():void + { + dispatchEvent(new org.apache.flex.events.Event("alertSet")); + } + ]]> + </fx:Script> + + <js:Container x="4" y="10" > + <js:beads> + <js:HorizontalLayout /> + </js:beads> + <js:Label text="Symbol:" /> + <js:TextInput id="symbolField" width="50" /> + <js:Label text="Value:" /> + <js:TextInput id="valueField" width="50" /> + <js:CheckBox text="Higher?" id="higherCheck" /> + <js:TextButton text="Set" click="onAlertSet()" /> + </js:Container> + + <js:DataGrid id="dataGrid" x="0" y="40" width="100%" height="200"> + <js:beads> + <js:DataProviderChangeNotifier sourceID="dataModel" propertyName="alerts" + destinationPropertyName="dataProvider" changeEventName="dataProviderChanged" /> + <js:SimpleBinding + eventName="alertsUpdate" + sourceID="dataModel" + sourcePropertyName="alerts" + destinationPropertyName="dataProvider" /> + </js:beads> + <js:columns> + <js:DataGridColumn label="Symbol" dataField="symbol"> + <js:itemRenderer> + <fx:Component> + <js:StringItemRenderer /> + </fx:Component> + </js:itemRenderer> + </js:DataGridColumn> + <js:DataGridColumn label="Alert" dataField="greaterThan"> + <js:itemRenderer> + <fx:Component> + <renderers:AlertRenderer /> + </fx:Component> + </js:itemRenderer> + </js:DataGridColumn> + <js:DataGridColumn label="Message" dataField="message"> + <js:itemRenderer> + <fx:Component> + <js:StringItemRenderer /> + </fx:Component> + </js:itemRenderer> + </js:DataGridColumn> + </js:columns> + </js:DataGrid> + +</js:TitleView> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/c1682af6/examples/flexjs/MobileStocks/src/views/AssetsView.mxml ---------------------------------------------------------------------- diff --git a/examples/flexjs/MobileStocks/src/views/AssetsView.mxml b/examples/flexjs/MobileStocks/src/views/AssetsView.mxml new file mode 100755 index 0000000..944e759 --- /dev/null +++ b/examples/flexjs/MobileStocks/src/views/AssetsView.mxml @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +--> +<js:TitleView xmlns:fx="http://ns.adobe.com/mxml/2009" + title="Assets" + xmlns:js="library://ns.apache.org/flexjs/basic" + xmlns:models="models.*" + xmlns:local="*" + className="AssetsView" xmlns:views="views.*"> + <fx:Script> + <![CDATA[ + import models.ProductsModel; + import models.Stock; + + import org.apache.flex.binding.SimpleBinding; + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IBeadModel; + import org.apache.flex.events.Event; + import org.apache.flex.events.ValueChangeEvent; + import org.apache.flex.mobile.IViewManager; + import org.apache.flex.mobile.StackedViewManager; + import org.apache.flex.html.beads.DataProviderChangeNotifier; + + private var localModel:ProductsModel; + + public function set dataModel(value:IBeadModel):void + { + localModel = value as ProductsModel; + + var newEvent:ValueChangeEvent = new ValueChangeEvent("valueChange", false, false, null, localModel); + newEvent.propertyName = "dataModel"; + dispatchEvent(newEvent); + } + public function get dataModel():IBeadModel + { + return localModel; + } + ]]> + </fx:Script> + + <fx:Metadata> + [Event("next")] + </fx:Metadata> + + <js:beads> + <js:VerticalLayout /> + </js:beads> + + <js:model> + <models:AssetsModel /> + </js:model> + + <js:Label text="Summary" height="10%" /> + + <js:DataGrid id="assetGrid" height="150" width="100%"> + <js:style> + <js:SimpleCSSStyles top="0" left="0" right="0" /> + </js:style> + <js:beads> + <js:SimpleBinding + eventName="update" + sourceID="dataModel" + sourcePropertyName="watchList" + destinationPropertyName="dataProvider" /> + <js:DataProviderChangeNotifier sourceID="dataModel" propertyName="watchList" + destinationPropertyName="dataProvider" changeEventName="dataProviderChanged" /> + </js:beads> + <js:columns> + <js:DataGridColumn label="Symbol" dataField="symbol" /> + <js:DataGridColumn label="Change" dataField="change" /> + <js:DataGridColumn label="Last Value" dataField="last" /> + </js:columns> + </js:DataGrid> + + <js:Label text="Performance History" height="10%" /> + + <js:ColumnChart id="barChart" width="100%" height="40%"> + <js:model> + <js:ChartArrayListSelectionModel /> + </js:model> + <js:beads> + <js:DataItemRendererFactoryForSeriesArrayListData /> + <js:ColumnChartLayoutForArrayList /> + <js:SimpleBinding + eventName="update" + sourceID="dataModel" + sourcePropertyName="watchList" + destinationPropertyName="dataProvider" /> + <js:DataProviderChangeNotifier sourceID="dataModel" propertyName="watchList" + destinationPropertyName="dataProvider" changeEventName="dataProviderChanged" /> + <js:VerticalLinearAxisForArrayListBead valueField="last" /> + <js:HorizontalCategoryAxisForArrayListBead categoryField="symbol" /> + </js:beads> + <js:series> + <js:ColumnSeries yField="last"> + <js:itemRenderer> + <fx:Component> + <js:BoxItemRenderer> + <js:fill> + <js:SolidColor color="#FF964D" alpha="1.0" /> + </js:fill> + </js:BoxItemRenderer> + </fx:Component> + </js:itemRenderer> + </js:ColumnSeries> + </js:series> + </js:ColumnChart> + +</js:TitleView> \ No newline at end of file