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
Posts: 13
Registered: ‎04-22-2010
My Device: Blackberry Bold
Accepted Solution

Phone Screen Action

So I have the following code provided by RIM ready to use in my application:

package com.rim.samples.device.phonescreendemo;

import net.rim.blackberry.api.phone.AbstractPhoneListener;
import net.rim.blackberry.api.phone.Phone;
import net.rim.blackberry.api.phone.PhoneCall;
import net.rim.blackberry.api.phone.phonegui.PhoneScreen;
import net.rim.blackberry.api.phone.phonegui.PhoneScreenVerticalManager;
import net.rim.blackberry.api.phone.phonegui.PhoneScreenHorizontalManager;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;


/**
 * This class listens for incoming calls.  When either of the callIncoming(),
 * callWaiting(), or callInitiated() callbacks have been invoked, this sample
 * application will send data to the incoming and active call screens. 
 */
public final class PhoneScreenAction extends AbstractPhoneListener
{  
    private Application _app;
    
    /**
     * Constructs a new PhoneScreenAction object
     * @param app A reference to the Application instance
     */
    public PhoneScreenAction(Application app)
    {
        _app = app;                     
    }
    
    
    /**
     * Creates various managers and fields contained within a PhoneScreen object
     * which then sends its data to the Phone application's foreground screen.
     * 
     * @param callid Id of an incoming call
     */
    private void sendPhoneScreenData(int callid)
    { 
        PhoneCall phoneCall = Phone.getCall(callid);
        
        if(phoneCall != null)
        {                       
            String phoneNumber = phoneCall.getPhoneNumber();
            
            if(phoneNumber.equals("5550111"))
            {                    
                // Initialize PhoneScreen 
                PhoneScreen phoneScreen = new PhoneScreen(callid, _app);
                phoneScreen.setScreenForeground(Color.POWDERBLUE);                                
                      
                // Create a PhoneScreenHorizontalManager
                PhoneScreenHorizontalManager phoneScreenHorizontalManager1 = new PhoneScreenHorizontalManager();
                                                
                // Create a Bitmap
                Bitmap bitmap = Bitmap.getBitmapResource("logo.jpg");
                
                // Get phone screen dimensions
                XYRect incomingLandscape = PhoneScreen.getDimensions(PhoneScreen.LANDSCAPE, PhoneScreen.INCOMING);
                XYRect activeLandscape = PhoneScreen.getDimensions(PhoneScreen.LANDSCAPE, PhoneScreen.ACTIVECALL);
                XYRect incomingPortrait = PhoneScreen.getDimensions(PhoneScreen.PORTRAIT, PhoneScreen.INCOMING);
                XYRect activePortrait = PhoneScreen.getDimensions(PhoneScreen.PORTRAIT, PhoneScreen.ACTIVECALL);              
                
                // Get phone screen widths                
                int incomingLandscapeWidth = 0;
                if(incomingLandscape != null)
                {
                    incomingLandscapeWidth = incomingLandscape.width; 
                }               
                int activeLandscapeWidth = 0;
                if(activeLandscape != null)
                {
                   activeLandscapeWidth =  activeLandscape.width;
                }                
                int incomingPortraitWidth = incomingPortrait.width;                
                int activePortraitWidth = activePortrait.width;             
                
                // Calculate minimum width for active and incoming phone screens in portrait or landscape orientation 
                int minWidth =  Math.min(incomingPortraitWidth, activePortraitWidth);
                if(activeLandscapeWidth > 0)
                {
                   minWidth =  Math.min(activeLandscapeWidth, minWidth);
                }
                if(incomingLandscapeWidth > 0)
                {
                   minWidth = Math.min(incomingLandscapeWidth, minWidth); 
                }
                
                int bitmapWidth = bitmap.getWidth();
                int bitmapHeight = bitmap.getHeight();
                    
                // Resize the bitmap if its width exceeds the minimum width                                   
                if(bitmapWidth > minWidth)
                {                    
                    Bitmap bitmapScaled = new Bitmap(minWidth, bitmapHeight);
            
                    // Scale the original Bitmap into the new Bitmap using
                    // a Lanczos filter.            
                    bitmap.scaleInto(bitmapScaled, Bitmap.FILTER_LANCZOS);
                    
                    // Assign the bitmap and bitmapWidth references
                    bitmap = bitmapScaled;          
                    bitmapWidth = bitmap.getWidth();          
                }                
                
                // Calculate and set padding
                int displayWidth = Display.getWidth();                
                int padding = (displayWidth - bitmapWidth) / 2;                
                phoneScreenHorizontalManager1.setPadding(0, padding, 0 , padding);
                
                // Add the bitmap image to the PhoneScreenHorizontalManager
                // and add to the phone screen.
                phoneScreenHorizontalManager1.addImage(bitmap);
                phoneScreen.add(phoneScreenHorizontalManager1);                             
                
                // Create a PhoneScreenVerticalManager and add fields
                PhoneScreenVerticalManager phoneScreenVerticalManager = new PhoneScreenVerticalManager();                        
                phoneScreenVerticalManager.add(new LabelField("Adam McCombs/Junior"));
                phoneScreenVerticalManager.add(new LabelField("Coach Notes: Loves Biking"));               
                
                // Create a PhoneScreenHorizontalManager, set padding and
                // add the PhoneScreenVerticalManager.
                PhoneScreenHorizontalManager phoneScreenHorizontalManager2 = new PhoneScreenHorizontalManager();
                phoneScreenHorizontalManager2.setPadding(0, 60, 0, 60);
                phoneScreenHorizontalManager2.add(phoneScreenVerticalManager);             
                
                // Add fields to PhoneScreen and display
                phoneScreen.add(phoneScreenHorizontalManager2);        
                phoneScreen.sendDataToScreen();             
            }
        }
    }
        

    /**
     * @see AbstractPhoneListener#callWaiting(int)
     */
    public void callWaiting(int callid)
    {
        sendPhoneScreenData(callid);
    }
    
    
     /**
     * @see AbstractPhoneListener#callInitiated(int)
     */
    public void callInitiated(int callid) 
    {
        sendPhoneScreenData(callid);
    }    
    

    /**
     * @see AbstractPhoneListener#callIncoming(int)
     */
    public void callIncoming(int callid)
    {
        sendPhoneScreenData(callid);
    }
}

 

Basically it brings up an action screen when a certain number calls. My question is can I perform a loop to take the variable "phoneNumber" and cross check it with numbers I have stored in a database using an XML request and choose to display the phone action if a boolean returns true?? If so how would I implement that using this code?

Developer
Posts: 74
Registered: ‎01-03-2010
My Device: Not Specified

Re: Phone Screen Action

one way.... 1. first........u should implement phoneListener where in appropriate call handing method you check the number with your database and mark a flag .....2. then show you screen in phonescreen depending on your flag ................ another way................ do you checking in phonescreen just before showing the popup, show it based on outcone of checking .......................................................................................................................... ...............................................mark 'solved' + kudoes