Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
praveennagsethiya
Posts: 20
Registered: ‎05-21-2012
My Device: NA
My Carrier: NA

I want ad between Button(next and previous)

 hello, I want Blackberry ad between two button (next and previous) in the same horizontal field.bt how can apply this?

Blackberry ad coding is:-

Banner banner = new Banner(108023, null);
         banner.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
         banner.setTestModeFlag(true);
        add(banner);

 

 

this code is apply in below screen........code are:--------

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

 

package com.recharge.test;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
import javax.microedition.media.PlayerListener;
import net.rim.blackberry.api.browser.Browser;
import net.rim.blackberry.api.browser.BrowserSession;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.NullField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rimlib.blackberry.api.advertising.app.Banner;

public class Screen_1 extends MainScreen implements PlayerListener {
    private UiApplication mainApp;

Player p = null;
String mp3 = "";
String test=null;

public Screen_1(String test,UiApplication mainApp){
super(NO_VERTICAL_SCROLL);
this.mainApp = mainApp;
this.test=test;
buildUi();

}


private void buildUi() {
    

this.getMainManager().setBackground(BackgroundFactory.createBitmapBackground(ScreenConstant.FIRSTSCREEN));


RichTextField  topspace = new RichTextField (NON_FOCUSABLE)
{
    protected void layout(int width, int height) {
        super.layout(width, Display.getHeight()-((Display.getWidth()/10)+0));
        setExtent(width, Display.getHeight()-((Display.getWidth()/10)+0));
    }
};
RichTextField  centrespace = new RichTextField (NON_FOCUSABLE)
{
    protected void layout(int width, int height) {
        super.layout(Display.getWidth()-((Display.getHeight()/10)+25), height);
        setExtent(Display.getWidth()-((Display.getHeight()/10)+25), height);
    }
};

HorizontalFieldManager hfmButton = new HorizontalFieldManager();

FieldChangeListener listener1 =new FieldChangeListener() {
    
    public void fieldChanged(Field field, int context) {
            }
          };
          
final Bitmap startBitmap = Bitmap.getBitmapResource("prev.png");
BitmapField bm = new BitmapField(startBitmap,BitmapField.HIGHLIGHT_SELECT | BitmapField.FOCUSABLE)
  {
  protected boolean navigationClick(int status, int time)
  {
      if(test == "autoplay"){
          UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
          UiApplication.getUiApplication().pushScreen(new Demo_Screen(test, mainApp));
          try {
            p.stop();
        }
        catch (MediaException e) {
            
            e.printStackTrace();
        }
        
        p.close();
      
      }
      if(test == "listen"){
          UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
          UiApplication.getUiApplication().pushScreen(new Demo_Screen(test, mainApp));
          try {
            p.stop();
        }
        catch (MediaException e) {
            
            e.printStackTrace();
        }
        
        p.close();
      
      
      }
      if(test == "read"){
          UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
          UiApplication.getUiApplication().pushScreen(new Demo_Screen(test, mainApp));  
      }
      
                      
    return false;  
}
        
      };
      
     bm.isFocus();
     bm.setChangeListener(listener1);
     bm.setMargin(0,20,0,0);

     
     FieldChangeListener listener2 =new FieldChangeListener() {
            
            public void fieldChanged(Field field, int context) {
                           
                     }
                
              };
                          
        final Bitmap startBitmap1 = Bitmap.getBitmapResource("next.png");
        BitmapField bm1 = new BitmapField(startBitmap1,BitmapField.HIGHLIGHT_SELECT | BitmapField.FOCUSABLE   )
          {
          protected boolean navigationClick(int status, int time)
          {
              if(test == "autoplay"){
                  UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
                  UiApplication.getUiApplication().pushScreen(new Screen_2(test, mainApp));
                  try {
                    p.stop();
                }
                catch (MediaException e) {
                    
                    e.printStackTrace();
                }
                
                p.close();
              
              }
              if(test == "listen"){
                  UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
                  UiApplication.getUiApplication().pushScreen(new Screen_2(test, mainApp));
                  try {
                    p.stop();
                }
                catch (MediaException e) {
                    
                    e.printStackTrace();
                }
                
                p.close();
              
              
              }
              if(test == "read"){
                  UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
                  UiApplication.getUiApplication().pushScreen(new Screen_2(test, mainApp));  
              }
            
                                
            return true;  
        }
                
              };
              
             bm1.isFocus();
             bm1.setChangeListener(listener2);
             int disW = Display.getWidth();
             int disH = Display.getHeight();
             
            if(disW == 480 && disH == 800){
                bm1.setMargin(0,0,0,40);    
             }
            
            if(disW == 320 && disH == 240){
                bm1.setMargin(0,0,0,15);    
             }
            
            else{
              bm1.setMargin(0,0,0,50);
            }
             
           
    
             
  if(test == "autoplay")
{
       
String mp3="a2.mp3";
InputStream stream = (InputStream)this.getClass().getResourceAsStream("/" + mp3);
try {
p = Manager.createPlayer(stream,"audio/mpeg");
p.addPlayerListener(this);
p.prefetch();
p.start();
p.realize();

} catch (IOException e) {
System.out.println("IOException :: Screen_1 AutoPlay :: "+  e.toString());
e.printStackTrace();
} catch (MediaException e) {
System.out.println("MediaException :: Screen_1 AutoPlay :: "+  e.toString());
e.printStackTrace();
}

}

if (test == "read") {
        
hfmButton.add(bm);
hfmButton.add(centrespace);
hfmButton.add(bm1);



}

if (test == "listen") {

String mp3="a2.mp3";
InputStream stream = (InputStream)this.getClass().getResourceAsStream("/" + mp3);
try {
p = Manager.createPlayer(stream,"audio/mpeg");
p.addPlayerListener(this);
p.prefetch();
p.start();
p.realize();

} catch (IOException e) {

e.printStackTrace();
} catch (MediaException e) {

e.printStackTrace();
}


hfmButton.add(bm);
hfmButton.add(centrespace);
hfmButton.add(bm1);

}

Banner banner = new Banner(108023, null);
banner.setMMASize(Banner.MMA_SIZE_MEDIUM);
banner.setTestModeFlag(true);

hfmButton.add(banner);
add(topspace);
add(hfmButton);

}








protected boolean onSavePrompt() {
return true;
}

public void playerUpdate(Player p, String event, Object eventData) {
if(test == "autoplay")
{
if( event == PlayerListener.END_OF_MEDIA )
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
UiApplication.getUiApplication().pushScreen(new Screen_2(test, mainApp));
}
});
}
}

}
public boolean onClose() {
    
    if (test == "autoplay")
    {
    try {
        p.stop();
    }
    catch (MediaException e) {
        
        e.printStackTrace();
    }
    
    p.close();
    UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
    UiApplication.getUiApplication().pushScreen(new Screen_menu(mainApp));
    }
    
    if (test == "read")
    {
        UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
        UiApplication.getUiApplication().pushScreen(new Screen_menu(mainApp));
    }
    
    if (test == "listen")
    {
        
        try {
            p.stop();
        }
        catch (MediaException e) {
            
            e.printStackTrace();
        }
        
        p.close();
        UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
        UiApplication.getUiApplication().pushScreen(new Screen_menu(mainApp));
    }
    
    return false;
    }


//keycodes for the green and red keys
static final int GREEN_KEY = 1114112;
static final int RED_KEY = 1179648;

protected boolean keyDown(int keycode, int time)
//terminate the game if the green or red keys are pressed
{
//System.out.println(“keyDown: ” + keycode);
if ((keycode == GREEN_KEY) || (keycode == RED_KEY)) {
//boolean isRunning = false;
    System.exit(0);
    
return true;
}
return false;
}  // end of keyDown()
















}
















Please use plain text.