mihai petrescu maad

Post on 11-Jul-2015

160 Views

Category:

Documents

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Native development process or 3rd party solution?

Pros/Cons

User necessary skill setTime requiredTools needed

Resources availableMaintenance

UpdatesBackend data and other tools

Fragmentation

Native Codepublic class MainActivity extends FragmentActivity{

public AddUserDialog addUserDialog;

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

LinearLayout mainLayout = new LinearLayout(this);

mainLayout.setId(R.id.mainWidget);

mainLayout.setLayoutParams(new

LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

mainLayout.setOrientation(LinearLayout.VERTICAL);

LinearLayout topLayout = new LinearLayout(this);

topLayout.setId(R.id.topWidget);

topLayout.setLayoutParams(new

LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

topLayout.setOrientation(LinearLayout.HORIZONTAL);

final float scale = this.getResources().getDisplayMetrics().density;

final int pixels = (int) (44 * scale + 0.5f);

RelativeLayout navBarRelativeLayout = new RelativeLayout(this);

navBarRelativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, pixels));

navBarRelativeLayout.setBackgroundColor(0xff999999);

Button addUser = new Button(this);

RelativeLayout.LayoutParams params = new

RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

params.addRule(RelativeLayout.CENTER_VERTICAL);

addUser.setLayoutParams(params); params = null;

addUser.setText("Add User");

addUser.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

addUserDialog = new

AddUserDialog(MainActivity.this);

addUserDialog.show();

}

});

navBarRelativeLayout.addView(addUser);

mainLayout.addView(navBarRelativeLayout);

mainLayout.addView(topLayout);

ListViewFragment listViewFragment = new ListViewFragment();

getSupportFragmentManager().beginTransaction().add(R.id.topWidget, listViewFragment, "listViewFragment").commit();

WebViewFragment webViewFragment = new WebViewFragment();

getSupportFragmentManager().beginTransaction().add(R.id.topWidget, webViewFragment, "webViewFragment").commit();

MapViewFragment mapViewFragment = new MapViewFragment();

getSupportFragmentManager().beginTransaction().add(R.id.mainWidget, mapViewFragment, "mapViewFragment").commit();

setContentView(mainLayout);

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

Log.d("test", requestCode+"");

Log.d("test", resultCode+"");

Log.d("test", data+"");

if(requestCode == 112 && resultCode == RESULT_OK)

if(data.getParcelableExtra("location") != null)

addUserDialog.updateDisplay((LatLng) data.getParcelableExtra("location"));

}

}

Appscend (Native) Code<?xml version="1.0" encoding="UTF-8"?>

<par>

<cfg>

<vt>wd</vt>

<avi>home</avi>

<dvs>yes</dvs>

</cfg>

<es>

<e>

<padlx>0</padlx>

<padly>0</padly>

<padlw>300</padlw>

<padlh>300</padlh>

<vt>l</vt>

<px>listview.xml.php</px>

</e>

<e>

<padlx>300</padlx>

<padly>0</padly>

<padlw>724</padlw>

<padlh>300</padlh>

<vt>w</vt>

<px>webview.xml.php</px>

<navz>webview</navz>

<nav>yes</nav>

</e>

<e>

<padlx>0</padlx>

<padly>300</padly>

<padlw>1024</padlw>

<padlh>424</padlh>

<vt>m</vt>

<px>mapview.xml.php</px>

<navz>mapview</navz>

<nav>yes</nav>

</e>

</es>

<b>

<p>ln</p>

<t>Add User</t>

<br>yes</br>

<a>m:</a>

<pr>addUser.xml.php</pr>

</b>

</par>

Complex and native apps with Appcelerator via Javascript code

VsLightweight apps with PhoneGap via HTML5, CSS &

Javascript

Appcelerator:• Learn a new programming language• Limited functionality because of the JavaScript callback

PhoneGap• Non-native apps• Limited functionality and compatibility because the apps are not

running native code

An innovative and dynamic RAD platformNative running apps

Backend servicesMobile marketing solution

• Visual interface for rapid development• IgniteMarkup – development language• Targeted Push Notifications• Cloud based Content Management System • Analytics & User segmentation• Connected Ad-Server, IAP• Deployment over iOS & Android

• Keep native feeling of the apps• Both Android and iOS must have the same

functionality• Bug free apps• Easy to implement and modify apps• We take care of fragmentation

• Native feeling on Android = Easter eggs• Take something good, popular and port it• Discover the limits imposed by Android OS and

it’s numerous devices and custom ROMs• Scale apps the right way• Memory management

• Activities cannot coexist -> FragmentActivity -> FragmentManager with Fragments ->

• Work with ViewGroups for minimum memory fingerprint

• MapView from Android Google Maps API v2 requires OpenGL 2.0 for know so all the apps need to have a permission which reduces the availability of the app

• Android is a very powerful OS• Only basic functionality offered• For complex or slightly different approaches

classes have to be extended and basic functionality rewritten

• Many bugs are still hidden all over and many more appear with each update

• API isn’t very well documented• Time and patience is of the essence

Our development process

BOOL useSentinel = (delegate.sentinelController != nil && !delegate.forceSelfNavigation);GenericNavbarViewController *target = useSentinel?(GenericNavbarViewController*)delegate.sentinelController:(GenericNavbarViewController*)delegate.navController;

if (useSentinel) navigationType = kAPSNavigationTypeReplaceAll;

NSString *viewType;if (appDelegate.deviceIsIPad && [parsedConfigs objectForKey:@"padvt"] && !delegate.forceSelfNavigation) viewType = [parsedConfigs objectForKey:@"padvt"];else viewType = [parsedConfigs objectForKey:@"vt"];

GenericViewController *newView = (GenericViewController*)[UtilitiesClass getViewControllerOfType:viewType withParams:request.resource withTitle:nil withIcon:nil withNavController:targetwithTabController:delegate.tabController];

if (navigationType != kAPSNavigationTypeReplace) newView.parent = delegate;else newView.parent = delegate.parent;

newView.configs = parsedConfigs;newView.paramXml = request.resource;if (configModifiers) newView.configModifiers = configModifiers;if (delegate.forceSelfNavigation) newView.sentinelController = delegate.sentinelController;delegate.forceSelfNavigation = NO;

if ([parsedConfigs objectForKey:@"lcst"]) newView.shouldLoadElements = YES;

newView.elements = [result objectForKey:@"e"];newView.buttons = [result objectForKey:@"b"];newView.actions = [result objectForKey:@"la"];newView.sections = [result objectForKey:@"s"];newView.menuElements = [result objectForKey:@"me"];if ([[result objectForKey:@"et"] count] > 0) newView.elementTemplate = [[result objectForKey:@"et"] objectAtIndex:0];if (request.data) newView.attachedRequestData = [[request.data copy] autorelease];newView.locationRequestData = request.sendLocation;newView.locationRequestAccuracy = request.accuracy;if (useSentinel) newView.isWidget = YES;

newView.page = delegate.selectedItem;if (delegate.selectedItem != -1 && delegate.selectedItem < [delegate.elements count]) newView.parentElement = [delegate.elements objectAtIndex:delegate.selectedItem];

NSDictionary *passData = [delegate passData];if (passData) newView.passedData = passData;

NSMutableArray *genericAction = [result objectForKey:@"ga"];if ([genericAction count] > 0) newView.genericAction = [UtilitiesClass actionFromDictionary:[genericAction objectAtIndex:0]];

int pa = [animation length] != 0 ? [animation intValue] : [delegate.configs objectForKey:@"pa"] ? [[delegate.configs objectForKey:@"pa"] intValue] : 0;

if (navigationType != kAPSNavigationTypeModal) {

NSObject<EPGLTransitionViewDelegate> *transition;EPGLTransitionView *glview;UIView *transitionView;for (UIView *view in [target.view subviews]) if (![view isKindOfClass:[UINavigationBar class]] && ![view isKindOfClass:[UIToolbar class]]

&& !view.hidden) transitionView = view;

// Start animationswitch (pa) {

case 1: case 2: case 3: case 4:[UIView beginAnimations:nil context:nil];[UIView setAnimationTransition:pa forView:target.view cache:YES];[UIView setAnimationDuration:.5];break;

case 8:transition = [[[FlipForward alloc] init] autorelease];glview = [[[EPGLTransitionView alloc] initWithView:target.view delegate:transition] autorelease];break;

case 10: case 20: case 30: case 40:[UIView beginAnimations:nil context:nil];[UIView setAnimationTransition:(pa/10) forView:transitionView cache:YES];[UIView setAnimationDuration:.5];break;

default:break;

}

// Navigateif (navigationType == kAPSNavigationTypePush) [target pushViewController:newView animated:(pa==0)];else if (navigationType == kAPSNavigationTypeReplace) [target replaceTopViewController:newView];else [target setViewControllers:[NSArray arrayWithObjects:newView,nil] animated:(pa==0)];

// End animationswitch (pa) {

case 1: case 2: case 3: case 4:[UIView commitAnimations];break;

case 5:[target.view popIn:.5 delegate:nil];break;

case 6:[target.view fallIn:.5 delegate:nil];break;

case 7:[target.view fadeIn:.5 delegate:nil];break;

case 8:[glview prepareTextureTo:target.view];[glview setClearColorRed:0.0 green:0.0 blue:0.0 alpha:1.0];[glview startTransition];break;

case 10: case 20: case 30: case 40:[UIView commitAnimations];break;

case 50:[transitionView popIn:.5 delegate:nil];break;

case 60:[transitionView fallIn:.5 delegate:nil];break;

case 70:[transitionView fadeIn:.5 delegate:nil];break;

default:break;

}}else {

UINavigationController *nController = [UINavigationController alloc];

newView.navController = nController;newView.isModal = YES;

[[nController initWithRootViewController:newView] autorelease];

//if ([nController respondsToSelector:@selector(modalTransitionStyle)]) nController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

nController.modalPresentationStyle = modalPresentation;nController.view.frame = CGRectMake(0, 0, appDelegate.mainWidth, appDelegate.mainHeight);

if (appDelegate.visiblePopover) {[appDelegate.visiblePopover dismissPopoverAnimated:NO];[appDelegate.visiblePopover.delegate popoverControllerDidDismissPopover:appDelegate.visiblePopover];

}

[target presentModalViewController:nController animated:YES];}

[self cleanup];

public final static int kAPSNavigationTypePush=1;public final static int kAPSNavigationTypeModal=2;public final static int kAPSNavigationTypeReplace=3;

public final static int AnimDefaultPush = 0;public final static int AnimDefaultReplace = -1;public final static int AnimDefaultModal = -2;public final static int AnimNone = -99;

public Object delegate;public DataRequest request = null;boolean started = false;boolean forceMaster = false;HashMap<String, Object> configModifiers = null;String animation;

int navigationType = kAPSNavigationTypePush;

public void navigate(){if (started) return;UtilitiesClass.DebugLog("Request to navigate to path " + request.resource);new DataSource(this, request);

}

public void modal(){if (started) return;

UtilitiesClass.DebugLog("Request for modal view with path " + request.resource);navigationType = kAPSNavigationTypeModal;new DataSource(this, request);

}

public void replace(){if (started) return;UtilitiesClass.DebugLog("Request to replace current view with view at path " + request.resource);navigationType = kAPSNavigationTypeReplace;new DataSource(this, request);

}

public void cleanup() {if (request != null) { request = null; }if (animation != null) { animation = null; }if (configModifiers != null) { configModifiers = null; }started = false;navigationType = kAPSNavigationTypePush;forceMaster = false;

}

public void dataLoaded(String XMLContents) {//AppBuilderAppDelegate *appDelegate = (AppBuilderAppDelegate *)[[UIApplication sharedApplication] delegate];

HashMap<String, Object> result = new XMLGetter().XMLParse(XMLContents, new ArrayList<String>(Arrays.asList("e", "b", "cfg", "la", "ga", "s", "et")));if(result!= null){UtilitiesClass.DebugLog("Interpreted received data: " + result.keySet());

if (UtilitiesClass.getWrapper(result, "cfg").size() == 0) {UtilitiesClass.DebugLog("No view configuration found, attempting to execute launch actions...");for (HashMap<String, Object> action : UtilitiesClass.getWrapper(result, "la")){ActionManager newAction = new ActionManager(); newAction.performAction(newAction.actionFromDictionary(action),delegate);newAction = null;}cleanup();return;}

HashMap<String, Object> parsedConfigs = UtilitiesClass.getWrapper(result, "cfg").get(0);

if (configModifiers != null) for (HashMap.Entry<String, Object> entry : configModifiers.entrySet()) parsedConfigs.put(entry.getKey(), entry.getValue());

/*GenericViewController target;if (delegate.isMaster && !forceMaster) target=[(SplitViewController *)delegate.splitRoot splitDetails];

else target = (GenericNavbarViewController*)delegate.navController;*/

String viewType;if (GlobalSettings.deviceIsTablet && parsedConfigs.get("padvt") != null && !forceMaster) viewType = GenericViewController.getString(parsedConfigs, "padvt");else viewType = GenericViewController.getString(parsedConfigs, "vt");

Bundle newView = new Bundle();

newView.putSerializable("configs", parsedConfigs);newView.putString("parentAvi" , ((GenericViewController)delegate).avi);newView.putString("paramXml" , request.resource);

if (configModifiers != null) newView.putSerializable("configModifiers", configModifiers);

if (parsedConfigs.get("lcst") != null) newView.putBoolean("shouldLoadElements", true);

newView.putSerializable("elements", UtilitiesClass.getWrapper(result, "e"));newView.putSerializable("buttons", UtilitiesClass.getWrapper(result, "b"));newView.putSerializable("actions", UtilitiesClass.getWrapper(result, "la"));newView.putSerializable("sections", UtilitiesClass.getWrapper(result, "s"));if (UtilitiesClass.getWrapper(result, "et") != null && UtilitiesClass.getWrapper(result, "et").size() > 0) newView.putSerializable("elementTemplate", UtilitiesClass.getWrapper(result, "et").get(0));if (request.data != null) newView.putSerializable("attachedRequestData", request.data);newView.putBoolean("locationRequestData", request.sendLocation);newView.putInt("locationRequestAccuracy", request.accuracy);newView.putInt("page", ((GenericViewController)delegate).selectedItem);if (((GenericViewController)delegate).selectedItem != -1 && ((GenericViewController)delegate).selectedItem < ((GenericViewController)delegate).elements.size()) newView.putSerializable("parentElement", ((GenericViewController)delegate).elements.get(((GenericViewController)delegate).selectedItem));HashMap<String, Object> passData = ((GenericViewController)delegate).passData();if (passData!= null){ newView.putSerializable("passedData", passData); passData = null;}

ArrayList<HashMap<String, Object>> genericAction = UtilitiesClass.getWrapper(result, "ga");try {if (genericAction != null && genericAction.size() > 0)newView.putString("genericAction", ObjectSerializer.serialize(new ActionManager().actionFromDictionary(genericAction.get(0))));} catch (IOException e) {e.printStackTrace();}

int pa;

Fragment newFragment = UtilitiesClass.getViewControllerOfType(viewType, request.resource);newFragment.setArguments(newView);

if (navigationType == kAPSNavigationTypePush){pa = animation.length() != 0 ? Integer.parseInt(animation) : ((GenericViewController)delegate).configs.get("pa") != null ? GenericViewController.getInteger(((GenericViewController)delegate).configs, "pa") : AnimDefaultPush;//((GenericViewController)delegate).parentActivity.push(newFragment);((GenericViewController)delegate).parentActivity.push(newFragment, ((GenericViewController)delegate).avi);} else if (navigationType == kAPSNavigationTypeReplace) {pa = animation.length() != 0 ? Integer.parseInt(animation) : ((GenericViewController)delegate).configs.get("pa") != null ? GenericViewController.getInteger(((GenericViewController)delegate).configs, "pa") : AnimDefaultReplace;((GenericViewController)delegate).parentActivity.replace(newFragment, ((GenericViewController)delegate).avi);} else if (navigationType == kAPSNavigationTypeModal) {newView.putBoolean("isModal", true);((GenericViewController)delegate).parentActivity.modal(newFragment, ((GenericViewController)delegate).avi);

}

cleanup();} else {Toast.makeText(((GenericViewController)delegate).parentActivity, "Error parsing file, perhaps unclosed tags!", Toast.LENGTH_LONG).show();}}

public void failed() {cleanup();Toast.makeText(((GenericViewController)delegate).parentActivity, "Network error!", Toast.LENGTH_SHORT).show();}

-(void) configureChild {NSArray *components;

mapIsLocationSelector = [[configs objectForKey:@"selector"] isEqualToString:@"yes"];

if (spotElements) [spotElements release];spotElements = [[NSMutableArray alloc] initWithArray:[self placesFromElements]];

if (locationManager) {locationManager.delegate = nil;[locationManager release];

}

// Initialize location service, don't start updateslocationManager=[[CLLocationManager alloc] init];locationManager.delegate=self;locationManager.desiredAccuracy=[configs objectForKey:@"acr"]!=nil?[[configs objectForKey:@"acr"] doubleValue]:0;

// Map initial locationif ([elements count]) {

if ([[configs objectForKey:@"fit"] isEqualToString:@"yes"]) [map setRegion:[self regionFromLocations:spotElements] animated:YES];

else {CLLocationCoordinate2D location;MKCoordinateSpan span;

if ([configs objectForKey:@"il"]!=nil) {

components = [[configs objectForKey:@"il"] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" ,"]];

location.latitude = [[components objectAtIndex:0] doubleValue];

location.longitude = [[components objectAtIndex:1] doubleValue];}

else {location.latitude = 0;location.longitude = 0;

}

if ([configs objectForKey:@"is"]!=nil) {

span.latitudeDelta = [[configs objectForKey:@"is"] doubleValue];

span.longitudeDelta = [[configs objectForKey:@"is"] doubleValue];}

else {

span.latitudeDelta=.05;

span.longitudeDelta=.05;}

MKCoordinateRegion region;region.center = location;region.span=span;

[map setRegion:region animated:YES];}

}else if (!mapIsLocationSelector) [self alert:@"Nothing to display!"];

// Map configurationsmap.mapType = [configs objectForKey:@"mt"]!=nil?[[configs objectForKey:@"mt"] intValue]:2;if ([[configs objectForKey:@"ze"] isEqualToString:@"no"]) map.zoomEnabled = NO;if ([[configs objectForKey:@"se"] isEqualToString:@"no"]) map.scrollEnabled = NO;if ([[configs objectForKey:@"tu"] isEqualToString:@"yes"]) [self track];else if (([[configs objectForKey:@"ul"] isEqualToString:@"yes"]) || (mapIsLocationSelector && [[configs objectForKey:@"il"] isEqualToString:@"0,0"])) {

[self trackonce];[self sloc];

}

// Add locations[map addAnnotations:spotElements];

if (mapIsLocationSelector) [map selectAnnotation:selectionMarker animated:NO];[spotElements release];

}

- (NSArray*)placesFromElements {NSMutableArray *sElements = [[[NSMutableArray alloc] initWithCapacity:1] autorelease];Placemark *spot;

if (mapIsLocationSelector) {[elements addObject:[NSDictionary dictionaryWithObjectsAndKeys:[configs objectForKey:@"il"], @"l", @"Hold and drag to position", @"n", nil]];

}

int i = 0;for (NSDictionary *place in elements) {

spot = [[Placemark alloc] initWithCoordinate:[place objectForKey:@"l"] setName:[place objectForKey:@"n"] setDescription:[place objectForKey:@"d"]];

spot.index = i++;[sElements addObject:spot];[spot release];

}

if (mapIsLocationSelector) selectionMarker = [[sElements lastObject] retain];

return sElements;}

- (MKCoordinateRegion)regionFromLocations:(NSArray*)sElements {CLLocationCoordinate2D upper = [[sElements objectAtIndex:0] coordinate];CLLocationCoordinate2D lower = [[sElements objectAtIndex:0] coordinate];

// FIND LIMITSfor(Placemark *eachLocation in sElements) {

if([eachLocation coordinate].latitude > upper.latitude) upper.latitude = [eachLocation coordinate].latitude;if([eachLocation coordinate].latitude < lower.latitude) lower.latitude = [eachLocation coordinate].latitude;if([eachLocation coordinate].longitude > upper.longitude) upper.longitude = [eachLocation coordinate].longitude;if([eachLocation coordinate].longitude < lower.longitude) lower.longitude = [eachLocation coordinate].longitude;

}

MKCoordinateSpan locationSpan;locationSpan.latitudeDelta = upper.latitude - lower.latitude;locationSpan.longitudeDelta = upper.longitude - lower.longitude;CLLocationCoordinate2D locationCenter;locationCenter.latitude = (upper.latitude + lower.latitude) / 2;locationCenter.longitude = (upper.longitude + lower.longitude) / 2;

MKCoordinateRegion region = MKCoordinateRegionMake(locationCenter, locationSpan);return region;

}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {if ( mapView.userLocation == annotation ) {

return nil; // display default image}static NSString *viewIdentifier = @"annotationView";

MKAnnotationView *annotationView;if (mapIsLocationSelector) {

annotationView = (DraggableAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:viewIdentifier];if (annotationView == nil) annotationView = [[[DraggableAnnotationView alloc] initWithAnnotation:annotation

reuseIdentifier:viewIdentifier] autorelease];annotationView.draggable = YES;

[(DraggableAnnotationView*)annotationView setDelegate:self];[(DraggableAnnotationView*)annotationView setMapView:map];

}else {

annotationView = (MovableAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier:viewIdentifier];if (annotationView == nil) annotationView = [[[MovableAnnotationView alloc] initWithAnnotation:annotation

reuseIdentifier:viewIdentifier] autorelease];[(MovableAnnotationView*)annotationView setMapView:map];

}

Placemark *spot = (Placemark*)annotation;NSDictionary *current = [elements objectAtIndex:spot.index];

UIImageView *pinImageView = [[[UIImageView alloc] init] autorelease];

annotationView.frame = CGRectMake(0, 0, [current objectForKey:@"pisw"]?[[current objectForKey:@"pisw"] intValue]:[configs objectForKey:@"pisw"]?[[configs objectForKey:@"pisw"] intValue]:40, [current objectForKey:@"pish"]?[[current objectForKey:@"pish"] intValue]:[configs objectForKey:@"pish"]?[[configs objectForKey:@"pish"] intValue]:40);

annotationView.canShowCallout = YES;pinImageView.frame = annotationView.frame;pinImageView.clipsToBounds = YES;[appDelegate.imageManager getImageFromURL:[current objectForKey:@"pin"]!=nil?[current objectForKey:@"pin"]:[configs

objectForKey:@"pin"]!=nil?[configs objectForKey:@"pin"]:@"pinRed.png" inView:pinImageView ofSize:CGSizeMake(pinImageView.frame.size.width, pinImageView.frame.size.height) cornerRadius:[current objectForKey:@"pir"]?[[current objectForKey:@"pir"] intValue]:[configs objectForKey:@"pir"]?[[configs objectForKey:@"pir"] intValue]:0 contentMode:[current objectForKey:@"picm"]!=nil?[current objectForKey:@"picm"]:[configs objectForKey:@"picm"]!=nil?[configs objectForKey:@"picm"]:@"aft" reflection:NO offset:CGSizeZero activity:YES fadein:YES forceAsync:NO];

[annotationView addSubview:pinImageView];

if ([current objectForKey:@"a"] != nil || [configs objectForKey:@"ga"]) {annotationView.rightCalloutAccessoryView = [UIButton

buttonWithType:UIButtonTypeDetailDisclosure];[(UIButton *)annotationView.rightCalloutAccessoryView addTarget:self

action:@selector(openSpot:) forControlEvents:UIControlEventTouchUpInside];}

if ([current objectForKey:@"i"] != nil) {UIImageView *imageView = [[[UIImageView alloc] init] autorelease];imageView.frame = CGRectMake(0, 0, [[configs objectForKey:@"isw"]

intValue], [[configs objectForKey:@"ish"] intValue]);[appDelegate.imageManager getImageFromURL:[current

objectForKey:@"i"] inView:imageView ofSize:CGSizeMake([[configs objectForKey:@"isw"] intValue], [[configs objectForKey:@"ish"] intValue]) cornerRadius:[current objectForKey:@"icr"]!=nil?[[current objectForKey:@"icr"] intValue]:[[configs objectForKey:@"icr"] intValue] contentMode:@"afl" reflection:NO offset:CGSizeMake(0, 0) activity:imageShowActivity fadein:imageFadeIn forceAsync:NO];

annotationView.leftCalloutAccessoryView = imageView;}

return annotationView;}}

// Map configurationsif(GenericViewController.getVarValueInteger(configs, configs, "mt", 2) == 2 ||

GenericViewController.getVarValueInteger(configs, configs, "mt", 2) == 1)

mapView.setSatellite(true);if(GenericViewController.getVarValueString(configs, configs, "ze",

"yes").equals("yes")){

if(!GlobalSettings.hasMultitouch){

mapView.displayZoomControls(true);

mapView.setBuiltInZoomControls(true);

}} else {

mapView.setOnTouchListener(new OnTouchListener() {public boolean onTouch(View v, MotionEvent event) {

if(event.getPointerCount() > 1) {return true;

}return false;

}});

}

if(GenericViewController.getVarValueString(configs, configs, "se", "yes").equals("yes")){

mapView.setEnabled(true);

mapView.setClickable(true);}if(GenericViewController.getVarValueString(configs, configs, "tu",

"no").equals("yes")){

ImageView imageView = new ImageView(this);

imageView.setImageResource(R.drawable.trackingdot);

int pis = (int) (20 * GlobalSettings.ratioForImages);

Drawable pinDraw = imageView.getDrawable();

pinDraw.setBounds(-(int) (pis/2), -(int) (pis/2),

pis -(int) (pis/2), pis - (int) (pis/2));

itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(MapViewController.this, pinDraw, mapView);

imageView = null; pinDraw = null;

List<String> providers = locationManager.getProviders(true);

Location l = null;

for (int i=providers.size()-1; i>=0; i--) {

l = locationManager.getLastKnownLocation(providers.get(i));

if (l != null) break;

}

if(l != null){

userPosition = new CustomOverlayItem(new GeoPoint((int) (l.getLatitude()*1E6), (int) (l.getLongitude()*1E6)), "Current Position");

itemizedOverlay.addOverlay(userPosition);

}

providers = null; l = null;

mapOverlays.add(itemizedOverlay);

track(null);} else if (GenericViewController.getVarValueString(configs, configs, "ul",

"no").equals("yes")) {

ImageView imageView = new ImageView(this);

imageView.setImageResource(R.drawable.trackingdot);

int pis = (int) (20 * GlobalSettings.ratioForImages);

Drawable pinDraw = imageView.getDrawable();

pinDraw.setBounds(-(int) (pis/2), -(int) (pis/2),

pis -(int) (pis/2), pis - (int) (pis/2));

pinDraw.setBounds(0, 0, (int) (20 * GlobalSettings.ratioForImages), (int) (20 * GlobalSettings.ratioForImages));

itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(MapViewController.this, pinDraw, mapView);

imageView = null; pinDraw = null;

List<String> providers = locationManager.getProviders(true);

Location l = null;

for (int i=providers.size()-1; i>=0; i--) {

l = locationManager.getLastKnownLocation(providers.get(i));

if (l != null) break;

}

if(l != null){

userPosition = new CustomOverlayItem(new GeoPoint((int) (l.getLatitude()*1E6), (int) (l.getLongitude()*1E6)), "Current Position");

itemizedOverlay.addOverlay(userPosition);

}

providers = null; l = null;

mapOverlays.add(itemizedOverlay);

sloc(null);}

}public void initializeCoordArray() {

this.coordArray = new ArrayList<GeoPoint>();this.pins = new HashMap<String, CustomItemizedOverlay<CustomOverlayItem>>();GeoPoint geoPoint = null;for(int i=0;i<elements.size();i++) {

String pinUrl = GenericViewController.getVarValueString(elements.get(i), configs, "pin", "Pin.png");

CustomItemizedOverlay<CustomOverlayItem> pinOverlay = pins.get(pinUrl);if(pinOverlay == null){

ImageView imageView = new ImageView(this);

ImageRequest imgreq = new ImageRequest();

imgreq.imageView = imageView;

imgreq.url = pinUrl;

imgreq.radius = GenericViewController.getVarValueInteger(elements.get(i), configs, "pir", 0);

imgreq.contentMode = GenericViewController.getVarValueString(elements.get(i), configs, "picm", "aft");

GlobalSettings.imageManager.getImage(this, imgreq);

//create new Pin Overlay if it doesn't exist already

int pisw = (int) (GenericViewController.getVarValueInteger(elements.get(i), configs, "pisw", 40) * GlobalSettings.ratioForImages);

int pish = (int) (GenericViewController.getVarValueInteger(elements.get(i), configs, "pish", 40) * GlobalSettings.ratioForImages);

Drawable pinDraw = imageView.getDrawable();

pinDraw.setBounds(-(int) (pisw/2), -(int) (pish/2),

pisw -(int) (pisw/2), pish - (int) (pish/2));

pinOverlay = new CustomItemizedOverlay<CustomOverlayItem>(MapViewController.this, pinDraw, mapView);

imageView = null; imgreq = null; pinDraw = null;}

if(elements.get(i).get("l") != null){

String coordsInString = GenericViewController.getString(elements.get(i), "l");

String[] coords = null;

if(coordsInString.contains(","))

coords = coordsInString.split(",");

else

coords = coordsInString.split(" ");

if(coords.length == 2){

try{

geoPoint = new GeoPoint((int) (Double.parseDouble(coords[0].trim())*1E6), (int) (Double.parseDouble(coords[1].trim())*1E6));

coordArray.add(geoPoint);

}catch(Exception e){

geoPoint = new GeoPoint(0, 0);

coordArray.add(geoPoint);

}

} else {

geoPoint = new GeoPoint(0, 0);

coordArray.add(geoPoint);

}

coords = null; coordsInString = null;} else {

geoPoint = new GeoPoint(0, 0);

coordArray.add(geoPoint);}

//create new OnClick Pin View ContentsCustomOverlayItem overlayItem = new CustomOverlayItem(geoPoint,

GenericViewController.getVarValueString(elements.get(i), elements.get(i), "n", ""),

GenericViewController.getVarValueString(elements.get(i), elements.get(i), "d", ""),

i);pinOverlay.addOverlay(overlayItem);pins.put(pinUrl, pinOverlay);

overlayItem = null; pinOverlay = null;}

}

public void fitElementsOnMap(Location newElement){int minLat = Integer.MAX_VALUE;int maxLat = Integer.MIN_VALUE;int minLon = Integer.MAX_VALUE;int maxLon = Integer.MIN_VALUE;

if(newElement != null)coordArray.add(new GeoPoint((int) (newElement.getLatitude()*1E6), (int)

(newElement.getLongitude()*1E6)));

for (GeoPoint item : coordArray){ int lat = item.getLatitudeE6();int lon = item.getLongitudeE6();

maxLat = Math.max(lat, maxLat);minLat = Math.min(lat, minLat);maxLon = Math.max(lon, maxLon);minLon = Math.min(lon, minLon);

}mapController.zoomToSpan((int) (Math.abs(maxLat - minLat) * 1.1), (int) (Math.abs(maxLon - minLon) * 1.1));mapController.animateTo(new GeoPoint( (maxLat + minLat)/2, (maxLon + minLon)/2 ));

}

public void track(ArrayList<String> args){if(!doTracking){

doTracking = true;String provider = locationManager.getBestProvider(criteria, true);if(provider == null){

Toast.makeText(this, "Please enable location services!", Toast.LENGTH_SHORT).show();

itemizedOverlay.removeOverlay(userPosition);

return;}

locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), 5000, 0, locationListener);

} else {doTracking = false;locationManager.removeUpdates(locationListener);itemizedOverlay.removeOverlay(userPosition);

}toggleSwap("track");

}

public void sloc(ArrayList<String> args){if(!doSloc){

doSloc = true;

if(isFitEnabled){

//mai fac un fit cand am prins prima oara pozitia

doSlocWithFit = true;} else {

//centrez pe prima pozitie pe care o prind doar o data

doSlocWithCenter = true;}String provider = locationManager.getBestProvider(criteria, true);if(provider == null){

Toast.makeText(this, "Please enable location services!", Toast.LENGTH_SHORT).show();

itemizedOverlay.removeOverlay(userPosition);

return;}

locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), 5000, 0, locationListener);

} else {doSloc = false;locationManager.removeUpdates(locationListener);itemizedOverlay.removeOverlay(userPosition);

}toggleSwap("sloc");

}

public void startRequestLocation(){if(doSloc || doTracking){

String provider = locationManager.getBestProvider(criteria, true);if(provider == null){

Toast.makeText(this, "Please enable location services!", Toast.LENGTH_SHORT).show();

itemizedOverlay.removeOverlay(userPosition);

return;}

locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), 5000, 0, locationListener);}

}

public void stopRequestLocation(){if(doSloc || doTracking){

locationManager.removeUpdates(locationListener);}

}

<?xml version=“1.0” encoding=“UTF-8”?><par><cfg> <title><![CDATA[Retea]]></title> <fit>no</fit> <isw>30</isw> <ish>30</ish> <ze>yes</ze> <roa>no</roa><se>yes</se> <tu>no</tu> <ul>yes</ul> <is>0.08</is> <nbv>yes</nbv> <nbtl>no</nbtl> <il>44.437711 26.097367</il> <mt>0</mt> <avi>sucursale</avi> <vt>m</vt><pin>pinretea.jpg</pin><nbt>006e58ff</nbt><nbl>navbar.png</nbl><padvt>split</padvt></cfg>

<bs> <b><p>rn</p><i>3030.png</i> </b></bs><es> <e> <n><![CDATA[PLUS AUTO]]></n> <d><![CDATA[Reprezentanta]]></d> <l><![CDATA[44.632856 22.6563]]></l> <a>p:a:d:</a><pr>companie/service.xml.php::::101</pr><pin>pin_service.png</pin></e> </es></par>

<?xml version=“1.0” encoding=“UTF-8”?><ARTICLES><ARTICLE><ARTICLEDATA><TITLE>Title 1</TITLE><AUTHOR>Author1</AUTHOR></ARTICLEDATA></ARTICLE>…</ARTICLES>

<?xml version=“1.0” encoding=“UTF-8”?><par><cfg><vt>wd</vt><avi>main</avi><padbi>bk.jpg</padbi><nbv>no</nbv><roa>yes</roa><cache>1080</cache></cfg>…</par>

mihai@appscend.com

top related