Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…plugins into CoreDump
  • Loading branch information
Joe Bowser committed Apr 20, 2011
2 parents 349cb06 + c7a8aa2 commit edea5b8
Show file tree
Hide file tree
Showing 169 changed files with 1,155 additions and 212 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,3 +1,4 @@
.DS_Store
.svn
*/.svn/*
*/.svn/*
build
File renamed without changes.
11 changes: 9 additions & 2 deletions iPhone/AdPlugin/SAiOSAdPlugin.h → AdPlugin/iOS/SAiOSAdPlugin.h
Expand Up @@ -12,18 +12,25 @@

@interface SAiOSAdPlugin : PhoneGapCommand <ADBannerViewDelegate> {

ADBannerView* adView;
ADBannerView* bannerView;

BOOL bannerIsVisible;
BOOL bannerIsInitialized;
BOOL bannerIsAtBottom;

NSString* portraitContentIndentifier;
NSString* landscapeContentIndentifier;

}

@property (nonatomic, retain) ADBannerView* adView;
@property (nonatomic, retain) ADBannerView* bannerView;
@property (assign) BOOL bannerIsVisible;
@property (assign) BOOL bannerIsInitialized;
@property (assign) BOOL bannerIsAtBottom;

@property (copy) NSString* portraitContentIndentifier;
@property (copy) NSString* landscapeContentIndentifier;


- (void) prepare:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void) showAd:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
Expand Down
File renamed without changes.
252 changes: 252 additions & 0 deletions AdPlugin/iOS/SAiOSAdPlugin.m
@@ -0,0 +1,252 @@
//
// SAiOSAdPlugin.m
// Ad Plugin for PhoneGap
//
// Created by shazron on 10-07-12.
// Copyright 2010 Shazron Abdullah. All rights reserved.
//

#import "SAiOSAdPlugin.h"

@interface SAiOSAdPlugin(PrivateMethods)

- (void) __prepare:(BOOL)atBottom;
- (void) __showAd:(BOOL)show;

@end


@implementation SAiOSAdPlugin

@synthesize bannerView;
@synthesize bannerIsVisible;
@synthesize bannerIsInitialized;
@synthesize bannerIsAtBottom;
@synthesize portraitContentIndentifier;
@synthesize landscapeContentIndentifier;


#pragma mark -
#pragma mark Public Methods

- (void) prepare:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{

// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(onOrientationChange)
// name:@"UIDeviceOrientationDidChangeNotification" object:nil];

NSUInteger argc = [arguments count];
if (argc > 1) {
return;
}

NSString* atBottomValue = [arguments objectAtIndex:0];
[self __prepare:[atBottomValue boolValue]];
}

- (void) showAd:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSUInteger argc = [arguments count];
if (argc > 1) {
return;
}

NSString* showValue = [arguments objectAtIndex:0];
[self __showAd:[showValue boolValue]];
}

#pragma mark -
#pragma mark Private Methods

-(NSString*) getADBannerContentSizeIdentifierPortrait
{
if ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 4.2 )
{
return ADBannerContentSizeIdentifierPortrait;
}

return ADBannerContentSizeIdentifier320x50;
}

-(NSString*) getADBannerContentSizeIdentifierLandscape
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.2)
{
return ADBannerContentSizeIdentifierLandscape;
}

return ADBannerContentSizeIdentifier480x32;
}

- (void) __prepare:(BOOL)atBottom
{
NSLog(@"SAiOSAdPlugin Prepare Ad At Bottom: %d", atBottom);

self.portraitContentIndentifier = [self getADBannerContentSizeIdentifierPortrait];
self.landscapeContentIndentifier = [self getADBannerContentSizeIdentifierLandscape];

Class adBannerViewClass = NSClassFromString(@"ADBannerView");
if (adBannerViewClass && !self.bannerView)
{
bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];

bannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: self.portraitContentIndentifier, self.landscapeContentIndentifier, nil];

bannerView.delegate = self;

self.bannerIsAtBottom = atBottom;
self.bannerIsVisible = NO;
self.bannerIsInitialized = YES;
}
}

- (void) __showAd:(BOOL)show
{
NSLog(@"SAiOSAdPlugin Show Ad: %d", show);

if (!self.bannerIsInitialized)
{
[self __prepare:NO];
}

if (!(NSClassFromString(@"ADBannerView") && self.bannerView))
{ // ad classes not available
return;
}

if (show == self.bannerIsVisible) { // same state, nothing to do
return;
}

CGRect bannerViewFrame = bannerView.frame;
CGRect webViewFrame = webView.frame;
CGRect screenFrame = [ [ UIScreen mainScreen ] applicationFrame ];

//CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;

[UIView beginAnimations:@"blah" context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

if (show)
{
CGFloat bannerHeight = 50.0;

// First, setup the banner's content size and adjustment based on the current orientation
if(UIInterfaceOrientationIsLandscape(self.appViewController.interfaceOrientation))
{
bannerView.currentContentSizeIdentifier = self.landscapeContentIndentifier;
bannerHeight = 32.0;
}
else
{
bannerView.currentContentSizeIdentifier = self.portraitContentIndentifier;
}

bannerViewFrame.size.height = bannerHeight;
bannerViewFrame.size.width = screenFrame.size.width;

if (self.bannerIsAtBottom)
{
bannerViewFrame.origin.y = screenFrame.size.height - bannerViewFrame.size.height;
}
else // aka: at the top
{
webViewFrame.origin.y += bannerViewFrame.size.height;
}

webViewFrame.size.height -= bannerViewFrame.size.height;
webView.frame = webViewFrame;

[ webView.superview addSubview:self.bannerView];

self.bannerView.frame = bannerViewFrame;

bannerView.backgroundColor = [UIColor blackColor];

self.bannerIsVisible = YES;
}
else
{
if (self.bannerIsAtBottom)
{

}
else // aka: at the top
{
webViewFrame.origin.y = screenFrame.origin.y;
}


webViewFrame.size.height += bannerViewFrame.size.height;

webView.frame = webViewFrame;
[ bannerView removeFromSuperview];


self.bannerIsVisible = NO;
}

[UIView commitAnimations];
}

//-(void)onOrientationChange
//{
// self.bannerIsVisible = !self.bannerIsVisible;
// [ self __showAd:(!self.bannerIsVisible)];
//
//}

#pragma mark -
#pragma ADBannerViewDelegate

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
Class adBannerViewClass = NSClassFromString(@"ADBannerView");
if (adBannerViewClass)
{
NSString* jsString =
@"(function(){"
"var e = document.createEvent('Events');"
"e.initEvent('iAdBannerViewDidLoadAdEvent');"
"document.dispatchEvent(e);"
"})();";

[super writeJavascript:jsString];
}
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError*)error
{
Class adBannerViewClass = NSClassFromString(@"ADBannerView");
if (adBannerViewClass)
{
NSString* jsString =
@"(function(){"
"var e = document.createEvent('Events');"
"e.initEvent('iAdBannerViewDidFailToReceiveAdWithErrorEvent');"
"e.error = '%@';"
"document.dispatchEvent(e);"
"})();";

[super writeJavascript:[NSString stringWithFormat:jsString, [error description]]];
}
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{

}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(@"Banner view is beginning an ad action");
BOOL shouldExecuteAction = YES;//[self allowActionToRun]; // your application implements this method
if (!willLeave && shouldExecuteAction)
{
// insert code here to suspend any services that might conflict with the advertisement
}
return shouldExecuteAction;
}

@end
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
66 changes: 66 additions & 0 deletions ClipboardManager/Android/ClipboardManagerPlugin.java
@@ -0,0 +1,66 @@
/**
* Phonegap ClipboardManager plugin
* Omer Saatcioglu 2011
*
*/

package com.saatcioglu.phonegap.clipboardmanager;

import org.json.JSONArray;
import org.json.JSONException;

import android.content.Context;
import android.text.ClipboardManager;

import com.phonegap.DroidGap;
import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;

public class ClipboardManagerPlugin extends Plugin {
private static final String actionCopy = "copy";
private static final String actionPaste = "paste";
private static final String errorParse = "Couldn't get the text to copy";
private static final String errorUnknown = "Unknown Error";

private ClipboardManager mClipboardManager;

public void setContext(DroidGap ctx) {
super.setContext(ctx);
mClipboardManager = (ClipboardManager) ctx
.getSystemService(Context.CLIPBOARD_SERVICE);
}

/**
* Executes the request and returns PluginResult.
*
* @param action
* The action to execute.
* @param args
* JSONArry of arguments for the plugin.
* @param callbackId
* The callback id used when calling back into JavaScript.
* @return A PluginResult object with a status and message.
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
if (action.equals(actionCopy)) {
String arg = "";
try {
arg = (String) args.get(0);
mClipboardManager.setText(arg);
} catch (JSONException e) {
return new PluginResult(PluginResult.Status.ERROR, errorParse);
} catch (Exception e) {
return new PluginResult(PluginResult.Status.ERROR, errorUnknown);
}
return new PluginResult(PluginResult.Status.OK, arg);
} else if (action.equals(actionPaste)) {
String arg = (String) mClipboardManager.getText();
if (arg == null) {
arg = "";
}
return new PluginResult(PluginResult.Status.OK, arg);
} else {
return new PluginResult(PluginResult.Status.INVALID_ACTION);
}
}
}

0 comments on commit edea5b8

Please sign in to comment.