Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code for CameraUI issue
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:s="library://ns.adobe.com/flex/spark" initialize="init(event)">
<s:titleContent>
<s:VGroup horizontalAlign="center" verticalAlign="middle" width="100%">
<s:Label text="iOS" fontSize.phone="14" fontSize.tablet="20" color="white" fontWeight="bold"> </s:Label>
</s:VGroup>
</s:titleContent>
<fx:Script>
<![CDATA[
import flash.utils.ByteArray;
import mx.collections.ArrayCollection;
import mx.core.FlexGlobals;
import mx.events.FlexEvent;
import mx.managers.PopUpManager;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import org.bytearray.images.JPEGEncoder;
import services.mobiledata2.MobileData2;
private var dataSave2:MobileData2 = new MobileData2();
[Bindable]
public var saveResult:String = "";
public var isTablet:Boolean;
public var isPortrait:Boolean;
public var ba:ByteArray;
private var cameraUI:CameraUI
private var jpgEncoder: JPEGEncoder;
protected function button1_clickHandler(event:MouseEvent):void
{
if( CameraUI.isSupported )
{
cameraUI = new CameraUI();
cameraUI.addEventListener(MediaEvent.COMPLETE, onComplete);
cameraUI.addEventListener(Event.CANCEL, cameraCancel);
cameraUI.addEventListener(ErrorEvent.ERROR, cameraError);
cameraUI.launch(MediaType.IMAGE);
}
else
{
var theAlert:AlertMsg1 = new AlertMsg1();
theAlert.open(this,true);
PopUpManager.centerPopUp(theAlert);
}
}
protected function onComplete(event:MediaEvent):void {
//imageProblem.source = event.data.file.url;
imageInfo.visible = true;
imageInfo.text = "";
imageInfo.text += "-20";
busyDesc2.visible = true;
busyDesc2.text += "before seconds: ";
var mediaPromise:MediaPromise = event.data;
imageInfo.text += "-19";
var mpLoader:Loader = new Loader();
imageInfo.text += "-18";
mpLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMediaPromiseLoaded);
imageInfo.text += "-17";
mpLoader.loadFilePromise(mediaPromise);
imageInfo.text += "-16";
}
private function onMediaPromiseLoaded(e:Event):void
{
var mpLoaderInfo:LoaderInfo = e.target as LoaderInfo;
imageInfo.text += "-15";
mpLoaderInfo.removeEventListener(Event.COMPLETE, onMediaPromiseLoaded);
var bitmap:Bitmap = mpLoaderInfo.loader.content as Bitmap;
imageInfo.text += "-11";
imageInfo.text += "-10.5";
jpgEncoder = new JPEGEncoder( 20 );
imageInfo.text += "-9";
ba = jpgEncoder.encode( bitmap.bitmapData);
imageInfo.text += "-8";
//j = null;
jpgEncoder = null;
bitmap = null;
doPictureSave();
}
private function doPictureSave():void
{
//do something with the data
imageInfo.visible = true;
imageInfo.text += "1";
var actionCollection:ArrayCollection = new ArrayCollection();
actionCollection.addItem(new String("")); //add a blank string so no null values are passed
if (registration.selected){
var theItem:String = "Registration";
actionCollection.addItem(theItem);
}
if (rebate.selected){
var theItem2:String = "Rebate";
actionCollection.addItem(theItem2);
}
if (demo.selected){
var theItem3:String = "Demo";
actionCollection.addItem(theItem3);
}
if (bid.selected){
var theItem4:String = "Bid";
actionCollection.addItem(theItem4);
}
if (fleet.selected){
var theItem5:String = "Fleet";
actionCollection.addItem(theItem5);
}
if (other.selected){
var theItem6:String = "Other - " + txtOther.text;
actionCollection.addItem(theItem6);
}
imageInfo.text += "2.5";
dataSave2.addEventListener("result", saveImage_Result);
dataSave2.addEventListener("fault", saveImage_Failed);
//*** HERE IS WHERE WE SEND TO A WEB SERVICE, code removed for proprietary reasons ***
}
private function saveImage_Result(evt:ResultEvent):void {
var idNum:int;
dataSave2.removeEventListener("result", saveImage_Result);
dataSave2.removeEventListener("fault", saveImage_Failed);
//imageInfo.text += "result from web service";
if (evt.result != null)
{
idNum = evt.result as int;
busy.visible = false;
busyDesc2.visible = true;
busyDesc.visible = true;
busyDesc.text = "Success - Image sent.";// + error.toString();
ba.clear();
init(new FlexEvent("Init"));
}
}
private function saveImage_Failed(evt:FaultEvent):void
{
dataSave2.removeEventListener("result", saveImage_Result);
dataSave2.removeEventListener("fault", saveImage_Failed);
//imageInfo.text += "failure from web service";
busy.visible = false;
busyDesc.visible = true;
busyDesc.text = "Image Save failed at web service level. Error: " + evt.message.toString();
}
private function cameraError(evt:FaultEvent):void
{
busy.visible = false;
busyDesc.visible = true;
busyDesc.text = "Camera IO error. Error: " + evt.message.toString();
}
private function cameraCancel(evt:Event):void
{
busy.visible = false;
busyDesc.visible = true;
busyDesc.text = "Camera cancelled.";
}
protected function init(event:FlexEvent):void
{
registration.selected = true;
rebate.selected = false;
bid.selected = false;
fleet.selected = false;
demo.selected = false;
other.selected = false;
txtOther.text = "";
}
protected function button2_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
navigator.pushView(views.ViewExistingRegistrationRequests);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:Component className="AlertMsg1">
<s:SkinnablePopUpContainer width="70%">
<s:Panel title="Camera Not Available">
<s:VGroup horizontalAlign="center" paddingTop="20" gap="20">
<s:Label id="alertLbl" width="200" textAlign="center" text="Camera is not supported on this device."/>
<s:Button label="OK" click="close();"/>
</s:VGroup>
</s:Panel>
</s:SkinnablePopUpContainer>
</fx:Component>
<fx:Component className="PictureMsg1">
<s:SkinnablePopUpContainer width="70%">
<s:Panel title="Picture Save">
<s:VGroup horizontalAlign="center" paddingTop="20" gap="20">
<s:Label id="picLabel" width="200" textAlign="center"/>
<s:Button label="OK" click="close();"/>
</s:VGroup>
</s:Panel>
</s:SkinnablePopUpContainer>
</fx:Component>
</fx:Declarations>
<s:states>
<s:State name="portraitPhone" stateGroups="phone,portrait"/>
<s:State name="landscapePhone" stateGroups="phone,landscape"/>
<s:State name="portraitTablet" stateGroups="tablet,portrait"/>
<s:State name="landscapeTablet" stateGroups="tablet,landscape"/>
</s:states>
<s:VGroup paddingTop="8" paddingLeft.tablet="8" paddingLeft.phone="4" width="100%">
<s:TextArea id="serviceDesc" fontSize.tablet="20" width="85%" fontSize="14" text="Please select what you would like KPM to submit this unit for:"></s:TextArea>
<s:VGroup paddingLeft="18">
<s:HGroup>
<s:CheckBox id="registration" width.phone="150" width.tablet="250" fontSize.phone="12" fontSize.tablet="16" label="Product Registration" selected="true" />
<s:Spacer width.phone="12%" width.tablet="20%">
</s:Spacer>
<s:CheckBox id="rebate" fontSize.phone="12" fontSize.tablet="16" label="Rebate" /> </s:HGroup>
<s:HGroup>
<s:CheckBox id="bid" width.phone="150" width.tablet="250" fontSize.phone="12" fontSize.tablet="16" label="Bid Credit" />
<s:Spacer width.phone="12%" width.tablet="20%">
</s:Spacer>
<s:CheckBox id="fleet" fontSize.phone="12" fontSize.tablet="16" label="Fleet Credit" /></s:HGroup>
<s:HGroup>
<s:CheckBox id="demo" width.phone="150" width.tablet="250" fontSize.phone="12" fontSize.tablet="16" label="Demo Credit" />
<s:Spacer width.phone="12%" width.tablet="20%">
</s:Spacer>
</s:HGroup>
<s:CheckBox id="other" fontSize.phone="12" fontSize.tablet="16" label="Other - Please enter below" />
<s:TextArea id="txtOther" softKeyboardType="default" width="85%" height="20%" verticalAlign="top" paddingBottom="15"></s:TextArea>
</s:VGroup>
<s:HGroup>
<s:Button label="Take Picture of Invoice" click="button1_clickHandler(event)" fontSize="11"/>
<s:Button label="View Existing Requests" click="button2_clickHandler(event)" fontSize="11"/>
</s:HGroup>
<s:VGroup paddingLeft="18">
<s:VGroup horizontalAlign="center" width="96%">
<s:HGroup verticalAlign="middle" horizontalAlign="center" width="96%">
<s:Label id="busyDesc" fontSize.tablet="20" fontSize="18" text="Please wait..." visible="false"></s:Label>
<s:BusyIndicator id="busy" height="50" width="50" visible="false"></s:BusyIndicator>
</s:HGroup>
<s:Label id="busyDesc2" fontSize.tablet="20" fontSize="14" text="This may take up to 20 seconds to complete." visible="false"></s:Label>
<s:Label id="imageInfo" fontSize.tablet="20" fontSize="11" text="" visible="true"></s:Label>
</s:VGroup>
</s:VGroup>
</s:VGroup>
</s:View>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment