BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-18-2010, 11:30 PM   #1
anuj866
Knows Where the Search Button Is
 
Join Date: Feb 2010
Model: 7100t
PIN: N/A
Carrier: VODAFONE
Posts: 18
Default Blackberry Registration and Login screen with xml

Please Login to Remove!

STARTS WITH SPLASH SCREEN




package BB.Registration;

import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.container.MainScreen;

public class SplashScreen extends MainScreen {

AccountDatabase acDb;

public SplashScreen() {

LabelField lblTitle = new LabelField("Splash Screen", FIELD_HCENTER);

setTitle(lblTitle);


add(new RichTextField("THIS IS SPLASH SCREEN", FIELD_HCENTER));
synchronized (RegistrationScreen.persistAccounts) {

acDb=(AccountDatabase) RegistrationScreen.persistAccounts.getContents();

}


UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {

synchronized (UiApplication.getEventLock()) {


UiApplication.getUiApplication().pushScreen(new SelectionScreen());

UiApplication.getUiApplication().popScreen(SplashS creen.this);

/* if(acDb==null || acDb.size()==0)
{
UiApplication.getUiApplication().pushScreen(
new RegistrationScreen());
UiApplication.getUiApplication().popScreen(
SplashScreen.this);
}
else
{
UiApplication.getUiApplication().pushScreen(
new LoginScreen());
UiApplication.getUiApplication().popScreen(
SplashScreen.this);
}*/
}

}
},3000,false);

}

}


=========//======================//======================//======================//======================//============



PUSHES THE SELECT SCREEN


package BB.Registration;

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.container.HorizontalFieldMan ager;
import net.rim.device.api.ui.container.MainScreen;

public class SelectionScreen extends MainScreen implements FieldChangeListener{

ButtonField btnRegister, btnLogin, btnContacts;

public SelectionScreen() {

HorizontalFieldManager hfmSelect = new HorizontalFieldManager();

btnRegister = new ButtonField("Register",ButtonField.CONSUME_CLICK);
hfmSelect.add(btnRegister);
btnRegister.setChangeListener(this);

btnLogin = new ButtonField("Login",ButtonField.CONSUME_CLICK);
hfmSelect.add(btnLogin);
btnLogin.setChangeListener(this);

btnContacts = new ButtonField("Contacts",ButtonField.CONSUME_CLICK);
hfmSelect.add(btnContacts);
btnContacts.setChangeListener(this);

setStatus(hfmSelect);

}

public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub

if(field== btnRegister)
{
UiApplication.getUiApplication().pushScreen(new RegistrationScreen());

}
else if(field==btnLogin)
{
UiApplication.getUiApplication().pushScreen(new LoginScreen());
}

else if(field==btnContacts)
{
UiApplication.getUiApplication().pushScreen(new ContactScreen());
}

}

}

=========//======================//======================//======================//======================//============

PUSHES REGISTRATION SCREEN


package BB.Registration;

import net.rim.device.api.system.PersistentObject;
import net.rim.device.api.system.PersistentStore;
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.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.HorizontalFieldMan ager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManag er;

public class RegistrationScreen extends MainScreen implements
FieldChangeListener {

final int lblHeight = 14;

LabelField lblTitle = new LabelField("Registration Screen", FIELD_HCENTER);
LabelField lblStatus = new LabelField("By: Anuj Mukul", FIELD_RIGHT);
EditField edtName;
PasswordEditField edtPass;
ButtonField btnEnter, btnCancel;

Font fontLblTitle = Font.getDefault().derive(Font.EXTRA_BOLD, lblHeight);
Font fontLblStatus = Font.getDefault().derive(Font.ITALIC, lblHeight);

static PersistentObject persistAccounts;

static {
// Hash of "net.rim.sample.AddressBook".
long KEY = 0xa3b311234f59a29L;
persistAccounts = PersistentStore.getPersistentObject(KEY);

}

public RegistrationScreen() {

lblTitle.setFont(fontLblTitle);
setTitle(lblTitle);

// MAIN MANAGER
VerticalFieldManager vfmMain = new VerticalFieldManager();

VerticalFieldManager vfmContentHolder = new VerticalFieldManager();

// HORIZONTAL MANAGER FOR NAME FIELDS
HorizontalFieldManager hfmName = new HorizontalFieldManager(FIELD_RIGHT);

// LBL FIELD FOR NAME
LabelField lblName = new LabelField("I.D.: ");
hfmName.add(lblName);

// EDIT FIELD FOR NAME
edtName = new EditField("", "enter here", 256, EditField.NO_NEWLINE) {
protected void onFocus(int direction) {

if (edtName.getText().equalsIgnoreCase("enter here"))
clear(256);

super.onFocus(direction);
}

protected void paint(Graphics graphics) {
graphics.setColor(Color.GRAY);
super.paint(graphics);
}

};
hfmName.add(edtName);
// vfmMain.add(hfmName);
vfmContentHolder.add(hfmName);

HorizontalFieldManager hfmPass = new HorizontalFieldManager();
// LBL FIELD FOR pass
LabelField lblPass = new LabelField("Pass: ");
hfmPass.add(lblPass);

// EDIT FIELD FOR pass
edtPass = new PasswordEditField("", "", 256, EditField.NO_NEWLINE) {

protected void onFocus(int direction) {
if (edtPass.getText().equalsIgnoreCase(""))
clear(256);
super.onFocus(direction);
}

};
hfmPass.add(edtPass);
// vfmMain.add(hfmPass);
vfmContentHolder.add(hfmPass);

vfmContentHolder.setMargin(50, 0, 0, 50);

vfmMain.add(vfmContentHolder);

HorizontalFieldManager hfmStatus = new HorizontalFieldManager(
FIELD_HCENTER);

btnEnter = new ButtonField("Enter!", FIELD_HCENTER
| ButtonField.CONSUME_CLICK);
btnEnter.setChangeListener(this);
hfmStatus.add(btnEnter);

btnCancel = new ButtonField("Cancel", FIELD_HCENTER
| ButtonField.CONSUME_CLICK);
btnCancel.setChangeListener(this);
hfmStatus.add(btnCancel);

add(vfmMain);

lblStatus.setFont(fontLblStatus);
// hfmStatus.add(lblStatus);

setStatus(hfmStatus);
btnCancel.setFocus();
}

public void fieldChanged(Field field, int context) {

String name = edtName.getText().trim();
String pass = edtPass.getText().trim();

if (field == btnEnter) {

if (name.equalsIgnoreCase("") || pass.equalsIgnoreCase("")||name.equalsIgnoreCase(" enter here"))
{
Dialog.inform("Please enter all fields");
}
else
{

NamePassStore nps = new NamePassStore();
nps.setName(name);
nps.setPass(pass);

AccountDatabase acDb;
synchronized (persistAccounts) {
acDb = (AccountDatabase) persistAccounts.getContents();

if (acDb != null) {
acDb.addElement(nps);
} else {
acDb = new AccountDatabase();
acDb.addElement(nps);
}

persistAccounts.setContents(acDb);
persistAccounts.commit();

}

UiApplication.getUiApplication().pushScreen(new ShowDatabase());
}
} else if (field == btnCancel) {
System.exit(0);
}
}

}

=========//======================//======================//======================//======================//============

PUSHES LOGIN SCREEN


package BB.Registration;

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.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.container.HorizontalFieldMan ager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManag er;

public class LoginScreen extends MainScreen implements FieldChangeListener {

final int lblHeight = 14;

LabelField lblTitle = new LabelField("Login Screen", FIELD_HCENTER);

EditField edtName;
PasswordEditField edtPass;
ButtonField btnEnter, btnCancel;
boolean flagAccountExists = false;

Font fontLblTitle = Font.getDefault().derive(Font.EXTRA_BOLD, lblHeight);
Font fontLblStatus = Font.getDefault().derive(Font.ITALIC, lblHeight);

AccountDatabase acDb;

public LoginScreen() {

lblTitle.setFont(fontLblTitle);
setTitle(lblTitle);

// MAIN MANAGER
VerticalFieldManager vfmMain = new VerticalFieldManager();

VerticalFieldManager vfmContentHolder = new VerticalFieldManager();

// HORIZONTAL MANAGER FOR NAME FIELDS
HorizontalFieldManager hfmName = new HorizontalFieldManager(FIELD_RIGHT);

// LBL FIELD FOR NAME
LabelField lblName = new LabelField("I.D.: ");
hfmName.add(lblName);

// EDIT FIELD FOR NAME
edtName = new EditField("", "enter here", 256, EditField.NO_NEWLINE) {
protected void onFocus(int direction) {

if (edtName.getText().equalsIgnoreCase("enter here"))
clear(256);

super.onFocus(direction);
}

protected void paint(Graphics graphics) {
graphics.setColor(Color.GRAY);
super.paint(graphics);
}

};
hfmName.add(edtName);
// vfmMain.add(hfmName);
vfmContentHolder.add(hfmName);

HorizontalFieldManager hfmPass = new HorizontalFieldManager();
// LBL FIELD FOR pass
LabelField lblPass = new LabelField("Pass: ");
hfmPass.add(lblPass);

// EDIT FIELD FOR pass
edtPass = new PasswordEditField("", "", 256, EditField.NO_NEWLINE) {

protected void onFocus(int direction) {
if (edtPass.getText().equalsIgnoreCase(""))
clear(256);
super.onFocus(direction);
}

};
hfmPass.add(edtPass);
// vfmMain.add(hfmPass);
vfmContentHolder.add(hfmPass);

vfmContentHolder.setMargin(50, 0, 0, 50);

vfmMain.add(vfmContentHolder);

HorizontalFieldManager hfmStatus = new HorizontalFieldManager(
FIELD_HCENTER);

btnEnter = new ButtonField("Login", FIELD_HCENTER
| ButtonField.CONSUME_CLICK);
btnEnter.setChangeListener(this);
hfmStatus.add(btnEnter);

btnCancel = new ButtonField("Cancel", FIELD_HCENTER
| ButtonField.CONSUME_CLICK);
btnCancel.setChangeListener(this);
hfmStatus.add(btnCancel);

add(vfmMain);

// hfmStatus.add(lblStatus);

setStatus(hfmStatus);
btnCancel.setFocus();

}

public void fieldChanged(Field field, int context) {
String name = edtName.getText().trim();
String pass = edtPass.getText().trim();
NamePassStore nps;
if (field == btnEnter) {
if (name.equalsIgnoreCase("") || pass.equalsIgnoreCase("")
|| name.equalsIgnoreCase("enter here")) {
Dialog.inform("Please enter all fields");
}

else {
synchronized (RegistrationScreen.persistAccounts) {

acDb = (AccountDatabase) RegistrationScreen.persistAccounts
.getContents();
}
for (int i = 0; i < acDb.size(); i++) {
System.out.println(i + " count size--> " + acDb.size());
nps = (NamePassStore) acDb.elementAt(i);
if (name.equalsIgnoreCase(nps.getName())
&& pass.equalsIgnoreCase(nps.getPass()))

{

System.out.println(name + " compare " + nps.getName());
System.out.println(pass + " compare " + nps.getPass());
flagAccountExists = true;
break;
}
}

if (flagAccountExists) {
UiApplication.getUiApplication().pushScreen(
new LoginSuccessScreen(name));
UiApplication.getUiApplication().popScreen(this);
} else {
UiApplication.getUiApplication().invokeLater(
new Runnable() {
public void run() {
Dialog.alert("Account Doesn't Exists");

}
});
}

}

}

}

}



=========//======================//======================//======================//======================//============

XML SCREEN FOR PARSING XML DATA


package BB.Registration;

import java.io.InputStream;

import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.xml.parsers.DocumentBuilder;
import net.rim.device.api.xml.parsers.DocumentBuilderFact ory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ContactScreen extends MainScreen {

private static String _xmlFileName = "/bookstore.xml";

InputStream inputStream = getClass().getResourceAsStream( _xmlFileName );

public ContactScreen() {







String _node,_element;

Document doc,doc_string;


try{


/*DocumentBuilderFactory docBuilderFactory= DocumentBuilderFactory. newInstance();
DocumentBuilder docBuilder= docBuilderFactory.newDocumentBuilder();*/

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
InputStream inputStream = getClass().getResourceAsStream( _xmlFileName );

docBuilder.isValidating();
doc = docBuilder.parse(inputStream);
doc.getDocumentElement ().normalize ();
doc_string=doc;



NodeList list=doc.getElementsByTagName("*");
// NodeList list_checkString=doc_string.getElementsByTagName(" string");


_node=new String();
_element = new String();
//this "for" loop is used to parse through the
//XML document and extract all elements and their
//value, so they can be displayed on the device



for (int check=0;check<list.getLength();check++)
{
Node value=list.item(check).getChildNodes().item(0);
_node=list.item(check).getNodeName();

if(_node.equalsIgnoreCase("thetext") && value==null)
_element=" ";

else
_element=value.getNodeValue();





// updateField(_node, _element);
// add(new RichTextField(bug_details.elements(_node).toString ()));
}



/* new EditTest(_element);
add(new RichTextField(EditTest.data));
*/


}
catch (Exception e) {
// TODO: handle exception
}




}




}


=========//======================//======================//======================//======================//============

CLASS DATABASE FOR THE ID PASSWORD


package BB.Registration;

import net.rim.device.api.util.Persistable;

public class NamePassStore implements Persistable{

private String Name;
private String Pass;

public String getName() {
return this.Name;
}

public void setName(String name) {
this.Name = name;
}

public String getPass() {
return this.Pass;
}

public void setPass(String pass) {
this.Pass = pass;
}

}


=========//======================//======================//======================//======================//============

MAIN DATABASE FOR THE ACCOUNTS


package BB.Registration;

import java.util.Vector;

import net.rim.device.api.util.Persistable;

public class AccountDatabase extends Vector implements Persistable {

public synchronized Object elementAt(int index) {

return super.elementAt(index);
}

public synchronized void addElement(Object obj) {

super.addElement(obj);
}

public int size() {

return super.size();
}


}

=========//======================//======================//======================//======================//============

FOR VALIDATION IN THE REGISTRATION USE



char temp,ch;
count=strings.length;
startchar=new char[count];
for(i=0;i<count;i++)
{
ch=strings[i].charAt(0);

int j=ch;
if(j>=65 && j<=90 )
{
j=j+32;
}
ch=(char) j;
startchar[c]= ch;
c++;
}
temp=startchar[0];
for(i=0;i<count-1;i++)
{

if(temp==startchar[i+1])
{
startchar[i+1]='~';
}
else
{
temp=startchar[i+1];
}
}
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M picture

iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M

$4.99



OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet  picture

OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet

$2.99



10 Feet/3M For iPhone 13 12 11 PRO MAX MINI  X XR XS 8 7 Fast Charging USB Cable picture

10 Feet/3M For iPhone 13 12 11 PRO MAX MINI X XR XS 8 7 Fast Charging USB Cable

$5.00



10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord picture

10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord

$4.98



Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 picture

Genuine A1417 OEM Battery Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013

$37.90



NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$31.90







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.