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
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

@amanarona I have as of now not using the is.Lock() method.Everything is working accordingly with the use of backlight.isenabled()?But when i dismmiss the screen,its not dismissing instantly.

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

There is a listener to get backlight event in blackberry use that

SystemListener2 

use this method in it : public void backlightStateChange(boolean on)

and do below things:


1) Make Application and Your mainscreen.

2) make your application run background when u click ur app icon

3) Either make a copy of your mainScreen or some other screen like pop up screen etc

4) Pop your copied new screen


try using this hope this will help you..

Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

Actually while making golbalscreen,request background doesnt seem to work

package mypackage;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;

import net.rim.device.api.memorycleaner.MemoryCleanerListener;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.DeviceInfo;
import net.rim.device.api.system.SystemListener;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngine;
import net.rim.device.api.ui.component.Dialog;

public class MyApp extends UiApplication implements SystemListener,MemoryCleanerListener
{
    public static void main(String[] args)
    {
    	
    	
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }
    public MyApp()
    {     
    	if (ApplicationManager.getApplicationManager().inStartup())
        {
    		addSystemListener(this);
        }
		else
		{ 
			doStartupWorkLater();	
		}
    }
	private void doStartupWorkLater() 
	{
        LockApp lck=new LockApp();
		Thread t = new Thread(lck);
		t.start();
	}
	public void batteryGood() {
		
	}
	public void batteryLow() {
		
	}
	public void batteryStatusChange(int status) {
		
	}
	public void powerOff() {
		
	}
	public void powerUp() 
	{
		removeSystemListener(this);
		doStartUpWork();
	}
	private void doStartUpWork() 
	{
		LockApp lck=new LockApp();
		Thread t = new Thread(lck);
		t.start();
	}
	public boolean cleanNow(int event) {
		// TODO Auto-generated method stub
		return false;
	}
	public String getDescription() {
		// TODO Auto-generated method stub
		return null;
	}    
}

 class LockApp implements Runnable {
	public void run() {
		// TODO Auto-generated method stub
		 if(ApplicationManager.getApplicationManager().isSystemLocked())
    	 {
     		UiApplication.getUiApplication().invokeLater(new Runnable() 
     		{	
 				public void run() 
 				{
 					Dialog.alert("LOCK");
 				}
 			}) ;
     	 }
     	 else 
     	 {
     		UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
					Calendar c11 = Calendar.getInstance();
					Date dt =  c11.getTime();    
					Timer tim = new Timer();
					System.out.println("Lockout time is---"+DeviceInfo.getLockTimeout());
					tim.schedule(new CD(),dt,1000);
					MyScreen myScreen = new MyScreen();
					
 					Ui.getUiEngine().pushGlobalScreen(myScreen, 1, UiEngine.GLOBAL_QUEUE);
				}
			});
     		
     	 }
	}
}

 

 

 

package mypackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngine;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class MyScreen extends MainScreen implements FieldChangeListener 
{
    /**
     * Creates a new MyScreen object
     */
	 ButtonField mOKButton;
	 public MyScreen() {
		 HorizontalFieldManager hfm=new HorizontalFieldManager();
		 VerticalFieldManager vfm=new VerticalFieldManager(USE_ALL_WIDTH|USE_ALL_HEIGHT);
		 vfm.setBackground(BackgroundFactory.createSolidBackground(Color.PURPLE));
		 BitmapField bmp1=new BitmapField(Bitmap.getBitmapResource("bsg1.png"),FIELD_VCENTER);
		 BitmapField bmp2=new BitmapField(Bitmap.getBitmapResource("bsg3.png"),FIELD_VCENTER);
		 BitmapField bmp3=new BitmapField(Bitmap.getBitmapResource("bsg5.png"),FIELD_VCENTER);
		 hfm.add(bmp1);
		 hfm.add(bmp2);
		 hfm.add(bmp3);
		 vfm.add(hfm);
		 
		  mOKButton = new ButtonField("Exit", ButtonField.CONSUME_CLICK
		            | FIELD_HCENTER);
	
	       mOKButton.setChangeListener(this);
	       vfm.add(mOKButton);
	       add(vfm);
	    }
	


public void fieldChanged(Field field, int context) {
	 if (mOKButton == field)
         // close();
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
        public void run()
        {
        	UiApplication.getUiApplication().popScreen(getScreen());
        }
        });
      
    }
	      
}

class GlobalDialog extends PopupScreen implements FieldChangeListener {
    ButtonField mOKButton = new ButtonField("OK", ButtonField.CONSUME_CLICK
            | FIELD_HCENTER);

    public GlobalDialog(String title, String text) {
        super(new VerticalFieldManager());
        add(new LabelField(title));
        add(new SeparatorField(SeparatorField.LINE_HORIZONTAL));
        add(new LabelField(text, DrawStyle.HCENTER));
        mOKButton.setChangeListener(this);
        add(mOKButton);
    }

    public void fieldChanged(Field field, int context) {
        if (mOKButton == field)
         // close();
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
        public void run()
        {
        	UiApplication.getUiApplication().requestBackground();
        }
        });
      
    }
}

 

 

package mypackage;

import java.util.TimerTask;

import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.Backlight;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngine;

public class CD extends TimerTask {
	public CD() {
	}

	/* For Every 1min the control will pass through this method */
	public void run() {

		
		if (Backlight.isEnabled() == false)/* if its idle for 10mins */
		{
			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
					System.out.println("LOCK");
					
					final MyScreen myScreen = new MyScreen();
					UiApplication.getUiApplication().invokeLater(
							new Runnable() {
								public void run() {
									UiEngine ui = Ui.getUiEngine();
							
							ui.pushGlobalScreen(myScreen, 1,
											UiEngine.GLOBAL_QUEUE);

								}
							});
				}
			});

		}
	}

}

  These are the three classes i am using.CD is a timer task class,which will excute after certail interval to whether backlight is on or off.So most of the things are working accordingly.Only issues is that when i click the exit button,for the first time it closes instantly,frm subsequent times it is not closing the screen

Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

by the way i am not using the below class

GlobalDialog 
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

just for information,i have also tried with close method instead of popscreen,but with no success

 

public void fieldChanged(Field field, int context) {
	 if (mOKButton == field)
         // close();
        UiApplication.getUiApplication().invokeLater(new Runnable()
        {
        public void run()
        {
        	UiApplication.getUiApplication().popScreen(getScreen());
        }
        });
      
    }
	      
}

 

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

Make one more screen that is copy of MainScreen that you use in TimerTask and pop that screen
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

ok but by doing so,there will be two screens?i want that when i click th exit button,i should see the home screen,ie that app should close

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

using System.exit(0); will close your app
Developer
Posts: 436
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: Showing my own app when i unlock the screen

no i dont want to close my app,than the timertask wont execute after certain interval to see whether backlight is on or off,but i followed ur earlier suggestion of making a copy,and it seems to work.Just tell me one thing,if my app has many internal screen,than also making the copy approach will work right?Presently i am displaying only one screen,so if i m multiple internal screen,do i need to create copy of each internal mainscreen?

Developer
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
My Carrier: Vodafone

Re: Showing my own app when i unlock the screen

no just make copy of main screen and no need of timer task if you are using back light there is an listener to check that