Tag Archives: Android

Hacking Flex 4.5 splash screen, put some animation on it

3
Filed under Flex, Flex Hacks, Flex Mobile

Got some free time this afternoon at company to investigate a further on splash screen at Flex 4.5 SDK.

By far is the must do feature on SDK for any Flex developer out there who doesn’t want to run out from mobile development with SDK, you have three properties to set up (splashScreenScaleMode=”" splashScreenMinimumDisplayTime=”" splashScreenImage=”") , and voilá, you have a great app introduction for any device with android.
Adobe Flex Team is working pretty well on mobile development, but sometimes I love to hack, and this hack anyone who are engage with mobile development with Flex can do, doesn’t involve any advanced code or class hacking, but it could get complicated if Adobe AIR 2.6 currently on my device doesn’t allow me because had the same behavior if I deep dive into SystemManager or simple embeding.

If read the documentation on behalf this topic, they teach you to only use static images, like jpg, png, of even animated gif if you which, but maybe someone spark this idea and have better ways, but my current target is swf support.

No matter what were the decisions, but the same documentation could let others know that they can embed simple SWF with no actionscript 3.0 at all to animate the splashscreen.

The fact of this hack is simple, the property splashScreenImage does support swf also, because it’s a generic Object at SystemManager Class.
If you open the Application class you will see:

   public function get splashScreenImage():Class
    {
        // When set through mxml, the compiler uses the value in the generated loader class.
        return systemManager.info()["splashScreenImage"];
    }
 
    /**
     *  @private
     */
    public function set splashScreenImage(value:Class):void
    {
        systemManager.info()["splashScreenImage"] = value;
    }

As you see, supports Class, which lets you support swf,and is registered in systemManager invoked by info() method.

The only circustence that Flex Team didn’t mentioned that I guess, was the fact AIR fps runs 15fps and by default the Flex SDk runs at 24, I believe when AIR 2.7 hit the Android Market, they will update the documentation, because applications will get like 45fps even more on iphone/ipad.
Why, because it’s chunk a little in the very first beginning of swf animated. than you need to calculate a little better timing. Or listeting the FlexEvent.COMPLETE from preloader to start the animation.

Guess what, splash Screen is just a Flex 4.5 preloader property, they also added that feature for Desktop version.

Here’s my little hack that can help you a little bit, my animation is simple swf of 3secs with average time 4000msecs on the definition for Splashscreen.

<?xml version="1.0" encoding="utf-8"?>
<s:ViewNavigatorApplication  splashScreenScaleMode=""
							splashScreenMinimumDisplayTime="4000" 
							splashScreenImage="@Embed('assets/splash2.swf')" xmlns:fx="http://ns.adobe.com/mxml/2009" 
							xmlns:s="library://ns.adobe.com/flex/spark" firstView="views.SplashHackHomeView">

Hacking Google maps to work on your Flex 4.5 /AIR mobile project

26
Filed under AIR, Android, Flash Builder, Flex, Flex Hacks, Flex Mobile

Recently I was building Flash Camp Brazil android version of app to attendees, and we came across a problem, using Google Maps on AIR mobile development. Since, theses days many developers are facing the problem, I’d like to demo and show you how to deal with that, even with other solutions around there.

Likely, I was authorize to open-source the application to the crowd, and many folks mailed us regarding Google Maps on air mobile project, they was in need help to solve a better propose and how to really work with Google Maps without facing 15 up to 30 seconds wait time. You of course don’t want your user waits this time to use your maps or app.

According to the official issue, Google uses SHA-1 encoding to locale somethings on the maps even collections of some sort of map data, which impacts in small devices with limited resources, since the .swc provided by Google Maps Team, is out of date and still uses Flex 3 architecture and component life cycle is hard to use on Mobile, since they are updated to Flex 4.5.

This particular problem isn’t only related to Flex problem actually is a problem on the .swc provided, which keeps you waits much longer than you expect. Since there’s no signal of update or fix, we have workarounds, that drive us for better safe and palliative solution for particular problem.

Google Maps is always update to Javascript developers, since is the main target for Google and of course they have this right, why not use those most recent release of js inside our project, it will of course help us a lot. The current version of Maps for Javascript developers in this time of blog post is V3, which is highly performance for Desktop and Mobile devices, Whooahhh!

Google always keep Javascript version update, and we can use that on our mobile Project. This way we can put in practice Adobe AIR StageWebView class in use and take advantage of using it with air mobile project.

Dealing with StageWebView is a little tricky because you have to remove it if you’re not in the current Screen and intend to remove it to show other view.

With your Flash Builder open, create a new Flex Mobile Project.
01-flexhack

I created two views, first one is just to push to the Maps View where resides my StageWebView class, and where I will deal with it. But if you’re new to Flex Mobile here’s the source code of each view.

First View

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
		xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
 
	<fx:Script>
		<![CDATA[
			protected function button1_clickHandler(event:MouseEvent):void
			{
				navigator.pushView(MapView);				
			}
		]]>
	</fx:Script>
 
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<s:layout>
		<s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="40"/>
	</s:layout>
	<s:Button label="Show my map" click="button1_clickHandler(event)"/>
</s:View>

MapView (Second View)

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
		xmlns:s="library://ns.adobe.com/flex/spark" viewDeactivate="removeStageWebViewHandler(event)" title="MapView" viewActivate="view1_viewActivateHandler(event)">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;
 
			import spark.events.ViewNavigatorEvent;
 
 
			private var myWebView:StageWebView;
 
 
			/**
			 * @protected 
			 * Just add and set site of my StageWebView 
			 * */
			protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
			{
				 myWebView = new StageWebView();
				 myWebView.stage = this.stage;
				 myWebView.loadURL("http://maps.google.com");
				 myWebView.viewPort = new Rectangle(0,70,stage.stageWidth,stage.stageHeight-150);
			}
 
 
			/** 
			 * @private
			 *  
			 * Just override to re-scale due to auto-orientation project nature
			 * */
			override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
 
 
				if (myWebView) {
					var point:Point = localToGlobal(new Point());
					myWebView.viewPort = new Rectangle(point.x, point.y, unscaledWidth, unscaledHeight);
				}
			}	
 
			protected function goBackHandler(event:MouseEvent):void
			{
 
				navigator.popToFirstView();
 
			}
 
			protected function removeStageWebViewHandler(event:ViewNavigatorEvent):void
			{
				myWebView.stage = null;
				// just remove the target and will leave.
 
			}
 
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<s:navigationContent>
		<s:Button label="Go Back" click="goBackHandler(event)"/>
	</s:navigationContent>
 
</s:View>

Great, by now you’re enabled to see the device showing the Google Maps optimize V3 map. And you hacked the Google Maps for Flash and used a better solution, but we have a serious problem, this just show you how to show the map, but if you want from a for example click on a item and show in the map that address. How to deal with that, Yeah! just use url parameters.

I can configure whatever I want in Google Maps V3 just by URL, when you search on “maps.google.com” directly on your browser you assume that hidden google Maps pass some parameters and those can be seen by clicking it at Link.

Well, I will use this URL “http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=”+ city + “&z=12&sensor=true”, to the demo, since “city” is a String property that I’ve created, I will pass throw navigator.pushToView to be setted, since my StageWebView is setted when the view is activate I will no need to worry about that.

Again, here’s my first view, with little list of special cities.

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
		xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
 
	<fx:Script>
		<![CDATA[
			protected function button1_clickHandler(event:MouseEvent):void
			{
				navigator.pushView(MapView);				
			}
 
			protected function list1_clickHandler(event:MouseEvent):void
			{
				navigator.pushView(MapView,mycities.selectedItem);
			}
 
		]]>
	</fx:Script>
 
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<s:layout>
		<s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="40"/>
	</s:layout>
	<s:actionContent>
		<s:Button label="Show my map" click="button1_clickHandler(event)"/>
	</s:actionContent>
	<s:Label fontSize="29" fontWeight="bold" text="Or select a city bellow:"/>
	<s:List id="mycities" width="100%" click="list1_clickHandler(event)">
			<s:dataProvider>
				<s:ArrayList>
						<fx:String>San Francisco,CA</fx:String>
						<fx:String>Petrolina,PE Brazil</fx:String>
						<fx:String>London,UK</fx:String>
						<fx:String>France,FR</fx:String>
				</s:ArrayList>
			</s:dataProvider>
	</s:List>
</s:View>

And my Map View (second view)

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
		xmlns:s="library://ns.adobe.com/flex/spark" viewDeactivate="removeStageWebViewHandler(event)" title="MapView" viewActivate="view1_viewActivateHandler(event)">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;
 
			import spark.events.ViewNavigatorEvent;
 
 
			private var myWebView:StageWebView;
			private var city:String;
 
			/**
			 * @protected 
			 * Just add and set site of my StageWebView 
			 * */
 
			protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
			{
 
				// set the city with data default property of each view
 
				city = data.toString();
 
				 myWebView = new StageWebView();
				 myWebView.stage = this.stage;
				// myWebView.loadURL("http://maps.google.com"); // default
				 myWebView.loadURL("http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q="+ city + "&z=12&sensor=true");
 
				 myWebView.viewPort = new Rectangle(0,70,stage.stageWidth,stage.stageHeight);
			}
 
 
			/** 
			 * @private
			 *  
			 * Just override to re-scale due to auto-orientation project nature
			 * */
			override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
 
 
				if (myWebView) {
					var point:Point = localToGlobal(new Point());
					myWebView.viewPort = new Rectangle(0,0,stage.stageWidth,stage.stageHeight);
				}
			}	
			override protected function stateChanged(oldState:String, newState:String, recursive:Boolean):void
			{
 
			}
 
			protected function goBackHandler(event:MouseEvent):void
			{
 
				navigator.popToFirstView();
 
			}
 
			protected function removeStageWebViewHandler(event:ViewNavigatorEvent):void
			{
				myWebView.stage = null;
				// just remove the target and will leave.
 
			}
 
 
		]]>
	</fx:Script>
	<fx:Declarations>
		<!-- Place non-visual elements (e.g., services, value objects) here -->
	</fx:Declarations>
	<s:navigationContent>
		<s:Button label="Go Back" click="goBackHandler(event)"/>
	</s:navigationContent>
 
</s:View>

Awesome, I no need to worry about setting Lat, Long, don’t need to get my location or any kind of trick, just use URL parameter and my StageWebView, couldn’t be simple isn’t.

Here’s some screenshots of the app.
flexhackfirstview
flexhacksecondivew

Good luck with your other projects. There’s always other ways like local files with markers, because via URL Google doesn’t provide that.

Open source Flex Mobile app for Flash Camps worldwide

1
Filed under AIR, Android, Flash Builder, Flex, Flex Mobile, Open Source Stuffs

During FlashCamp Brasil RIACycle where I’m CTO was in charge of doing the Android version for the event.
Was quick tough because we had very little time to do, to be honest we just had 2 days to create the app, test, deploy and publish. But we did it Oo-arh!!!

Before you go throw download link, keep in mind that this project was done with latest available version of Flex 4.5 SDK release, isn’t available to download right now, but Adobe soon will release it. If you try with Flash Burrito it won’t work.

So, our challenge begun with who was in charge of doing such thing in so little time. Lapsed some hours planning, actually 2 hours planing of what we could include or not, than rest time was spend on coding efforts.

Our second challenge was to choose the available frameworks on the market, decisions on what type to create, web or native or third-party vendor. Currently there are plenty of options for Android devices, which is cool because you have to choose which is the best one.

Coding with Flex framework for mobile devices is pretty simple as you’re self-used to desktop or web apps, the only concern we have to deal is against memory consumption, screen resolution, re-use of Views (which is tricky) and finally the persistence.

Project was deployed successfully in the Android Market, but we decide as contest suggest to open source the app to worldwide, soon as you get your code, you’re able to work on your version for other flash camps worldwide.

I’m really excited with other apps based on our work and really looking forward new endeavors.

Check out the source code here. Be sure to read the GPL V3 license.