How can I lock the keypad in Blackberry application using "lockSystem" method in J2ME? - blackberry

How can I lock the keypad in Blackberry application using "lockSystem" method in J2ME ??
And also the brightness of the blackberry should reduce to Zero ??

its really easy. I know the answer. We can just use the method "lockSystem". I have coded as following to lock the keypad. It takes long time for me to find it, but u got this.
package net.asem;
import net.rim.device.api.system.ApplicationManager;
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.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class LockBlackberry extends UiApplication
{
public static void main(String[] args)
{
LockBlackberry lockB = new LockBlackberry();
lockB.enterEventDispatcher();
}
LockBlackberry()
{
pushScreen(new myBlackBerryClass());
}
}
final class myBlackBerryClass extends MainScreen implements FieldChangeListener<br>
{
LabelField title;
ButtonField btn1;
myBlackBerryClass()
{
LabelField title = new LabelField("Title : Locking the Device.",LabelField.USE_ALL_WIDTH | LabelField.USE_ALL_WIDTH);
setTitle(title);
btn1 = new ButtonField("KeyPad Loack ?",ButtonField.CONSUME_CLICK);
btn1.setChangeListener(this);
add(btn1);
}
public void fieldChanged(Field field, int context)
{
if(field == btn1)
{
Click();
}
}
private void Click()
{
ApplicationManager manager = ApplicationManager.getApplicationManager();
manager.lockSystem(true);
}
}

Related

Blackberry ObjectChoiceField Not Showing drop down list

ObjectChoiceField not working because the below code:
protected boolean navigationUnclick(int status, int time) {
return true;
}
I have added this code to remove the menus on touchevent. Means I have made a custom bottom tab and adding and deleting verticalfields on screen. When i touch any HorizontalField it shows menu that's why i added the above code.
This is my code contains ObjectChoiceField added in horizontalfield:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
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.Graphics;
import net.rim.device.api.ui.TouchEvent;
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.ObjectChoiceField;
import net.rim.device.api.ui.container.VerticalFieldManager;
import com.ec.pleasewaitpopup.PleaseWaitPopupScreen;
import com.np.naijapings.ApplicationFont;
import com.np.naijapings.Constant;
import com.np.naijapings.TabControlScreen;
import com.np.naijapings.intermediateclasses.GetUserListIntermediator;
import com.tv.servercommunication.WebServiceDetails;
public class FindUsersScreen extends VerticalFieldManager implements FieldChangeListener{
private VerticalFieldManager _mainVfm;
private VerticalFieldManager _contentVfm;
private BitmapField _headerBmp;
private EncodedImage _bitmap;
private LabelField _gender;
private LabelField _age;
private LabelField _religion;
private ObjectChoiceField _genderChoiceField;
private ObjectChoiceField _ageChoiceField;
private ObjectChoiceField _religionChoiceField;
private ButtonField _findUser;
private static String[] _genderChoices={"Both gender","Male","Female"};
private static String[] _ageChoices={"Any age","18-25","26-30","31-35","36-45","46-50"};
private String[] _religionChoices={"Any religion","Hindu","Muslim"};
public FindUsersScreen(){
//HEADER IMG
_bitmap = EncodedImage.
getEncodedImageResource("find-user_header.png");
_headerBmp = new BitmapField(Constant.sizePic(_bitmap, _bitmap.getHeight(), _bitmap.getWidth()));
//MAIN VFM
_mainVfm=new VerticalFieldManager();
//CONTENT VFM
final Bitmap tabBackGroundImage = Bitmap
.getBitmapResource("finduserscr_bg.png");
_contentVfm=new VerticalFieldManager(){
protected void paint(Graphics graphics) {
int y = FindUsersScreen.this.getManager().getVerticalScroll();
graphics.drawBitmap( 0, y, tabBackGroundImage.getWidth(), tabBackGroundImage.getHeight(), tabBackGroundImage, 0, 0 );
super.paint( graphics );
}
};
//CREATE WIDGETS
_gender=new LabelField("Gender");
_genderChoiceField=new ObjectChoiceField("Gender", _genderChoices,0){
protected boolean touchEvent(TouchEvent message) {
return super.touchEvent(message);
}
};
_age=new LabelField("Age");
_ageChoiceField=new ObjectChoiceField("Age", _ageChoices,0);
_religion=new LabelField("Religion");
_religionChoiceField=new ObjectChoiceField("Religion", _religionChoices,0);
_findUser=new ButtonField(" Find Users ",ButtonField.CONSUME_CLICK);
_findUser.setChangeListener(this);
//SET FONT TYPE
/*_gender.setFont(ApplicationFont.labelFont_16);
_genderChoiceField.setFont(ApplicationFont.labelFont_16);
_ageChoiceField.setFont(ApplicationFont.labelFont_16);
_age.setFont(ApplicationFont.labelFont_20);
_religionChoiceField.setFont(ApplicationFont.labelFont_20);
_religion.setFont(ApplicationFont.labelFont_20);
*/
//SET MARGIN
/*_gender.setMargin(5,20,5,20);
_age.setMargin(5,20,5,20);
_religion.setMargin(5,20,5,20);
*/
_contentVfm.setMargin(15,30,15,0);
_genderChoiceField.setMargin(10,5,5,5);
_religionChoiceField.setMargin(10,5,5,5);
_ageChoiceField.setMargin(10,5,5,5);
_findUser.setMargin(10,80,20,80);
_contentVfm.setMargin(30,10,30,10);
//ADD FIELDS TO CONTENT VFM
//_contentVfm.add(_gender);
_contentVfm.add(_genderChoiceField);
//_contentVfm.add(_age);
_contentVfm.add(_ageChoiceField);
//_contentVfm.add(_religion);
_contentVfm.add(_religionChoiceField);
_contentVfm.add(_findUser);
_mainVfm.add(_headerBmp);
_mainVfm.add(_contentVfm);
add(_mainVfm);
}
public void fieldChanged(Field field, int context) {
if(field==_findUser){
Object obAgeRange = _ageChoiceField.getChoice(_ageChoiceField.getSelectedIndex());
String ageRange = obAgeRange.toString();
Object obgender = _genderChoiceField.getChoice(_genderChoiceField.getSelectedIndex());
String gender = obgender.toString();
Object obReligion = _religionChoiceField.getChoice(_religionChoiceField.getSelectedIndex());
String religion = obReligion.toString();
GetUserListIntermediator getUserListIntermediator=new GetUserListIntermediator(ageRange,gender,religion);
PleaseWaitPopupScreen.showScreenAndWait(getUserListIntermediator, Constant.PLEASE_WAIT_TEXT);
}
}
}
could anyone answer me how to solve this problem.
You don't get drop-down list because the field code does not process unclick event. You have intercepted and consumed this event (via return true;) before your field can process it.
Try this code for your event handler.
protected boolean navigationUnclick(int status, int time) {
super.navigationUnclick(status, time);
return true;
}

Dialog creation in Blackberry

Hi, I want to create a Login Screen which has a Username and Password
and a Sign in Button
But when a user fails to enter correct information inside the TextField of Username or Password a pop up like the image chat dialog should pop up from corner of TextField's right side displaying appropriate message How can this Customization be achieved?
i am giving you a simple way. If it is not perfect to your question you just ignore this answer.
Here i made logic like following. i gave you two buttons
1)Login
2)remove
I think you know how to validate your text fields right or wrong; keep one if condition ,write your logic if right no need any field
else wrong then you have three conditions
1)id is wrong
2)password is wrong
or 3)both wrong
according two that condition you can add particular tooltip box on above text field .
I am providing sample for both wrong condition and remove condition also
make it as your requirements
Resources :
chat.png image is required for background
Sample code:
package mypackage;
import net.rim.device.api.system.Bitmap;
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.XYEdges;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
/**
* 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
*/
private BasicEditField id,password;
private ButtonField login,cancel;
private VerticalFieldManager id_mgr,pass_mgr;
private PopupField id_hint,pass_hint;
public static Bitmap img;
public MyScreen()
{
img=Bitmap.getBitmapResource("chat.png");
// Set the displayed title of the screen
setTitle("Login Page");
Border b=BorderFactory.createRoundedBorder(new XYEdges(5, 5, 5, 5), Border.STYLE_SOLID);
id_hint=new PopupField("Wrong Id", img);
pass_hint=new PopupField("Wrong password", img);
id_mgr=new VerticalFieldManager();
id=new BasicEditField(){
protected void layout(int width, int height) {
super.layout(120, 40);
setExtent(120, 40);
}
};
id.setBorder(b);
add(id_mgr);
add(id);
pass_mgr=new VerticalFieldManager();
password=new BasicEditField(){
protected void layout(int width, int height) {
super.layout(120, 40);
setExtent(120, 40);
}
};
password.setBorder(b);
add(pass_mgr);
add(password);
login=new ButtonField("Login");
login.setChangeListener(this);
add(login);
cancel=new ButtonField("Remove");
cancel.setChangeListener(this);
add(cancel);
}
public void fieldChanged(Field field, int context) {
if(field==login)
{
try {
// id_mgr.add(new NullField(Field.FOCUSABLE));
id_mgr.add(id_hint);
id_mgr.setPadding(0, 0, 0, 50);
pass_mgr.add(pass_hint);
pass_mgr.setPadding(0, 0, 0, 50);
id_hint.setFocus();
} catch (IllegalStateException e) {
return;
}
}else if(cancel==field)
{
synchronized (UiApplication.getEventLock()) {
id_mgr.deleteAll();
pass_mgr.deleteAll();
}
}
}
}
and class for PopupField.java is
package mypackage;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
public class PopupField extends BitmapField{
private Bitmap img,scalled_img;
private String message;
private int layout_width;
public PopupField(String message,Bitmap img)
{
this.message=message;
layout_width=this.getFont().getAdvance(message)+40;
scalled_img=new Bitmap(layout_width, img.getHeight());
img.scaleInto(scalled_img, Bitmap.FILTER_BILINEAR);
this.img=scalled_img;
}
protected void layout(int width, int height) {
super.layout(img.getWidth(), img.getHeight());
setExtent(img.getWidth(), img.getHeight());
}
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, img.getWidth(), img.getHeight(), img,0,0);
graphics.setColor(Color.RED);
graphics.drawText(message,20,20);
super.paint(graphics);
}
}
output image :
keep helping to others
Other solution is this link will tell you
http://v4ks1n.wordpress.com/2011/01/28/tooltips-class-for-blackberry/

Java Can't Find Symbol Errors

I can't figure out why I keep getting the following errors with the following code:
HelloWorldApp.java:9: pushScreen(net.rim.device.api.ui.Screen) in net.rim.device.api.ui.UiApplication cannot be applied to (com.beginningblackberry.helloworld.HelloWorldMainScreen)
pushScreen(mainScreen);
HelloWorldMainScreen.java:10: cannot find symbol
symbol : method add(net.rim.device.api.ui.component.LabelField)
location: class com.beginningblackberry.helloworld.HelloWorldMainScreen
add(labelField);
\\HelloWorldApp.java
package com.beginningblackberry.helloworld;
import net.rim.device.api.ui.UiApplication;
class HelloWorldApp extends UiApplication {
HelloWorldApp() {
HelloWorldMainScreen mainScreen = new HelloWorldMainScreen();
pushScreen(mainScreen);
}
public static void main(String[] args){
HelloWorldApp app = new HelloWorldApp();
app.enterEventDispatcher();
}
}
\\ HelloWorldMainScreen.java
package com.beginningblackberry.helloworld;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.LabelField;
class HelloWorldMainScreen {
HelloWorldMainScreen() {
LabelField labelField = new LabelField("Hello World");
add(labelField);
}
}
in HelloWorldMainScreen you probably need to extend some other class or need to provide the implementation of the add()

Trying to write a hello world CLDC blackberry program

I got the book Advance Black Berry 6 Development.
I was able to get the midlet example to work, but not the first example for a CLDC program. It seems like it never gets to the code and when I run the app I get a blank white screen.
I tried to put a break point but it never went off.
Here is the code
package test.org;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
public class cHelloUniverses extends UiApplication{
public static void main(String[] args)
{
(new cHelloUniverses()).start();
}
public void start()
{
MainScreen main = new MainScreen();
LabelField label= new LabelField("Hello Ted");
main.add(label);
UiApplication app = UiApplication.getUiApplication();
app.pushScreen(main);
app.enterEventDispatcher();
}
}
Replace your start() method with this:
public void start()
{
MainScreen main = new MainScreen();
LabelField label= new LabelField("Hello Ted");
main.add(label);
this.pushScreen(main);
this.enterEventDispatcher();
}

BlackBerry - Get current Process ID

I read Blackberry - How to get the background application process id but I'm not sure I understand it correctly. The following code gets the foreground process id;
ApplicationManager.getApplicationManager().getForegroundProcessId()
I have two processes which execute the same piece of code to make a connection, I want to log the process which made the calls along with all my usual logging data to get a better idea of how the flow is working.
Is it possible to get the id for the process which is currently running the code? One process is in the foreground (UI process) and the other is in the background but both use the same connection library shared via the runtime store.
Thanks in advance!
Gav
So you have three modules: application, library and service.
You need to get descriptor by module name, and then get process id.
UPDATE1
String moduleName = "application";
int handle = CodeModuleManager.getModuleHandle(moduleName);
ApplicationDescriptor[] descriptors = CodeModuleManager
.getApplicationDescriptors(handle);
if (descriptors.length > 0 && descriptors[0] != null) {
ApplicationManager.getApplicationManager().getProcessId(descriptors[0]);
}
Then, to log which module uses library, use
Application.getApplication().getProcessId();
inside library methods. I think its better to implement logging inside library.
When you got process id of application from library code, you can compare it with id's found by module name and then you will know what module uses library code.
UPDATE2
alt text http://img138.imageshack.us/img138/23/eventlog.jpg
library module code:
package library;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ApplicationManager;
import net.rim.device.api.system.CodeModuleManager;
import net.rim.device.api.system.EventLogger;
public class Logger {
// "AppLibSrvc" converted to long
long guid = 0xd4b6b5eeea339daL;
public Logger() {
EventLogger.register(guid, "AppLibSrvc", EventLogger.VIEWER_STRING);
}
public void log(String message) {
EventLogger.logEvent(guid, message.getBytes());
}
public void call() {
log("Library is used by " + getModuleName());
}
private String getModuleName() {
String moduleName = "";
String appModuleName = "application";
int appProcessId = getProcessIdByName(appModuleName);
String srvcModuleName = "service";
int srvcProcessId = getProcessIdByName(srvcModuleName);
int processId = Application.getApplication().getProcessId();
if (appProcessId == processId)
moduleName = appModuleName;
else if (srvcProcessId == processId)
moduleName = srvcModuleName;
return moduleName;
}
protected int getProcessIdByName(String moduleName) {
int processId = -1;
int handle = CodeModuleManager.getModuleHandle(moduleName);
ApplicationDescriptor[] descriptors = CodeModuleManager
.getApplicationDescriptors(handle);
if (descriptors.length > 0 && descriptors[0] != null) {
processId = ApplicationManager.getApplicationManager()
.getProcessId(descriptors[0]);
}
return processId;
}
}
application module code:
package application;
import java.util.Timer;
import java.util.TimerTask;
import library.Logger;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public class App extends UiApplication {
public App() {
pushScreen(new Scr());
}
public static void main(String[] args) {
App app = new App();
app.enterEventDispatcher();
}
}
class Scr extends MainScreen {
public Scr() {
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
Logger logger = new Logger();
logger.call();
}
};
timer.schedule(task, 3000, 3000);
}
}
service module code:
package service;
import java.util.Timer;
import java.util.TimerTask;
import library.Logger;
import net.rim.device.api.system.Application;
public class App extends Application {
public App() {
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
Logger logger = new Logger();
logger.call();
}
};
timer.schedule(task, 3000, 3000);
}
public static void main(String[] args) {
App app = new App();
app.enterEventDispatcher();
}
}

Resources