More Hacking Go To HACK-PC.BLOGSPOT.COM
Sample Ads Buzz City Site
http://hacks-pc.blogspot.com
/*
* Copyright (C) BuzzCity Pte Ltd
*
* Code may be used only under the Terms & Conditions of the
* BuzzCity Publisher Agreement. Usage of these codes, or part thereof,
* implies acceptance of the same Agreement.
*
* 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.
*
* Please refer to the Publisher Agreement governing permissions and
* limitations. You are also required to refer to our Partner site for
* the latest agreement, terms and conditions.
*/
//Sample Implementation in Form-based app
import buzzcity.java.mobile.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class BCAdsSample extends MIDlet implements CommandListener, ItemCommandListener {
private Display display;
private Form mainForm;
private Form nextForm;
private BCAdsClientBanner textAdClient;
private BCAdsClientBanner bannerAdClient;
private Banner textBanner;
private Banner bannerBanner;
//private String linkURL1;
//private String linkURL2;
private Image image;
private ImageItem imageItem;
private String adText;
private StringItem stringItem;
private StringItem title;
public BCAdsSample () {
mainForm = new Form("BCAdsSample");
title = new StringItem("Sexfile", "");
mainForm.insert(0, title);
//Instantiation of BCAdsClientBanner class
//BCAdsClientBanner(int partnerid, int imgsize)
//partnerid & imgsize are to be filled in by publisher.
//Notes: For imgize, 1(120 x 20 pixels), 2(168 x 28 pixels), 3(216 x 36 pixels) and 4(300 x 50 pixels), 0 (non-Image)
//this is the MIDlet of the app
bannerAdClient = new BCAdsClientBanner(13511, 3, this);
//Instantiation of Banner class
bannerBanner = bannerAdClient.getBanner();
if (bannerBanner != null) {
//Display ad based on its type
if (bannerBanner.getType().equals("image")) {
image = (Image) bannerBanner.getItem();
imageItem = new ImageItem("", image, ImageItem.LAYOUT_DEFAULT, "", Item.BUTTON);
mainForm.append(imageItem);
}
else {
adText = (String) bannerBanner.getItem();
stringItem = new StringItem("", adText, Item.BUTTON);
mainForm.append(stringItem);
}
imageItem.setDefaultCommand(new Command("Visit Ad 1", Command.OK, 2));
imageItem.setItemCommandListener(this);
}
else {
System.out.println("bannerBanner null");
}
//Instantiation of BCAdsClientBanner class
//BCAdsClientBanner(int partnerid, int imgsize)
//partnerId & imgsize are to be filled in by publisher.
//For imgize, 1(120 x 20 pixels), 2(168 x 28 pixels), 3(216 x 36 pixels) and 4(300 x 50 pixels), 0 (non-Image)
//this is the MIDlet of the app
textAdClient = new BCAdsClientBanner(13512, 0, this);
//Instantiation of Banner class
textBanner = textAdClient.getBanner();
if (textBanner != null) {
//Display ad based on its type
if (textBanner.getType().equals("image")) {
image = (Image) textBanner.getItem();
imageItem = new ImageItem("", image, ImageItem.LAYOUT_DEFAULT, "", Item.BUTTON);
mainForm.append(imageItem);
}
else {
adText = (String) textBanner.getItem();
stringItem = new StringItem("", adText, Item.BUTTON);
mainForm.append(stringItem);
}
stringItem.setDefaultCommand(new Command("Visit Ad 2", Command.OK, 2));
stringItem.setItemCommandListener(this);
}
else {
System.out.println("textBanner null");
}
mainForm.addCommand(new Command("NEXT", Command.OK, 1));
mainForm.addCommand(new Command("EXIT", Command.EXIT, 3));
mainForm.setCommandListener(this);
}
//Handle command action to visit ad
public void commandAction (Command com, Item item) {
if (item == imageItem) {
bannerAdClient.clickAd();
}
else if (item == stringItem) {
textAdClient.clickAd();
}
}
public void commandAction (Command com, Displayable dis) {
String label = com.getLabel();
if ("EXIT".equals(label)) {
destroyApp(true);
}
else if ("NEXT".equals(label)) {
displayNextForm();
}
}
public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
display.setCurrent(mainForm);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){
try {
textAdClient.saveExposures();
bannerAdClient.saveExposures();
}
catch (Exception e) {
e.printStackTrace();
}
notifyDestroyed();
}
public void displayNextForm () {
nextForm = new Form("BCAdsSample");
title = new StringItem("HELLO WORLD", "" );
nextForm.insert(0, title);
//Instantiation of Banner class
bannerBanner = bannerAdClient.getBanner();
if (bannerBanner != null) {
//Display ad based on its type
if (bannerBanner.getType().equals("image")) {
image = (Image) bannerBanner.getItem();
imageItem = new ImageItem("", image, ImageItem.LAYOUT_DEFAULT, "", Item.BUTTON);
nextForm.append(imageItem);
}
else {
adText = (String) bannerBanner.getItem();
stringItem = new StringItem("", adText, Item.BUTTON);
nextForm.append(stringItem);
}
imageItem.setDefaultCommand(new Command("Visit Ad 1", Command.OK, 2));
imageItem.setItemCommandListener(this);
}
//Instantiation of Banner class
textBanner = textAdClient.getBanner();
if (textBanner != null) {
//Display ad based on its type
if (textBanner.getType().equals("image")) {
image = (Image) textBanner.getItem();
imageItem = new ImageItem("", image, ImageItem.LAYOUT_DEFAULT, "", Item.BUTTON);
nextForm.append(imageItem);
}
else {
adText = (String) textBanner.getItem();
stringItem = new StringItem("", adText, Item.BUTTON);
nextForm.append(stringItem);
}
stringItem.setDefaultCommand(new Command("Visit Ad 2", Command.OK, 2));
stringItem.setItemCommandListener(this);
}
nextForm.addCommand(new Command("NEXT", Command.OK, 1));
nextForm.addCommand(new Command("EXIT", Command.EXIT, 2));
nextForm.setCommandListener(this);
display.setCurrent(nextForm);
}
}