package nativeapp;
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.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
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.Background;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class LoginScreen extends MainScreen {
/**
* Login page
*/
private ButtonField btnLogin;
//private EditField txtUserID;
CustomTextBox txtUserID;
CustomTextBox txtPassword;
// private PasswordEditField txtPassword;
private CheckboxField Chkbox;
private LabelField RememberMe;
public LoginScreen() {
super(NO_VERTICAL_SCROLL);
txtUserID = new CustomTextBox() {
protected void paint(Graphics g) {
// Border roundedBorder = BorderFactory
// .createRoundedBorder(new XYEdges(9, 9, 9, 9),
// Color.GRAY, Border.STYLE_SOLID);
// setBorder(roundedBorder);
// setBackground(BackgroundFactory
// .createSolidBackground(Color.WHITE));
if (getText().length() == 0) {
g.setColor(Color.GRAY);
g.drawText("UserName", 0, 0);
}
g.setColor(Color.BLACK);
//g.drawRect(0, 0, (int) (Display.getWidth() / 1.5),
//txtUserID.getHeight()/* (int)(Display.getHeight()/9) */);
super.paint(g);
}
};
txtPassword = new CustomTextBox() {
protected void paint(Graphics g) {
Border roundedBorder = BorderFactory
.createRoundedBorder(new XYEdges(9, 9, 9, 9),
Color.GRAY, Border.STYLE_SOLID);
setBorder(roundedBorder);
setBackground(BackgroundFactory
.createSolidBackground(Color.WHITE));
if (getText().length() == 0) {
g.setColor(Color.GRAY);
g.drawText("txtPassword", 0, 0);
}
g.setColor(Color.BLACK);
super.paint(g);
}
};
// btnLogin = new ButtonField("SignIn");
btnLogin = new ButtonField("Sign In", Field.FIELD_HCENTER);
Chkbox = new CheckboxField();
// Chkbox.setMargin(0, 0, 0, 30);
RememberMe = new LabelField("Remember Me");
// RememberMe.setMargin(10, 0, 0, 0);
FieldChangeListener login = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
String uname = txtUserID.getText().toString().trim();
String pword = txtPassword.getText().toString().trim();
if (!uname.equalsIgnoreCase("")
&& !uname.equalsIgnoreCase(null)
&& !pword.equalsIgnoreCase("")
&& !pword.equalsIgnoreCase(null)) {
boolean lgnStatus = (new httpClient()).loginStatus(uname,
pword, DataURL.smartURLloginchk);
if (lgnStatus) {
PersistentsStore ps = new PersistentsStore();
ps.setObject(DataURL.UserName, uname);
ps.setObject(DataURL.PassWord, pword);
UiApplication.getUiApplication().popScreen(
LoginScreen.this);
UiApplication.getUiApplication().pushScreen(
new WelcomeScreen());
} else {
Dialog.inform("Invalid UserID or Password");
}
} else {
Dialog.inform("UserID and Password shouldnot be Empty");
}
}
};
FieldChangeListener cancel = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
}
};
btnLogin.setChangeListener(login);
// btnCancel.setChangeListener(cancel);
setLoginScreen();
}
private void setLoginScreen() {
VerticalFieldManager vfmForCenterDisplay = new VerticalFieldManager(
Field.FIELD_HCENTER | Field.FIELD_VCENTER | Field.USE_ALL_WIDTH
| Field.USE_ALL_HEIGHT) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(maxWidth, maxHeight);
}
};
Background background = BackgroundFactory.createBitmapBackground(Bitmap
.getBitmapResource("bground.png"));
vfmForCenterDisplay.setBackground(background);
int topSpace = (Display.getHeight() / 4);
vfmForCenterDisplay.setPadding(topSpace, 0, 0, 0);
VerticalFieldManager vfmBasicInfoWithBorder1 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
}
};
BitmapField bitmapField = new BitmapField(
Bitmap.getBitmapResource("loginbg_01.png")) {
protected void layout(int width, int height) {
setExtent(250, 95);
}
};
vfmBasicInfoWithBorder1.add(bitmapField);
VerticalFieldManager vfmBasicInfoWithBorder2 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
}
};
vfmBasicInfoWithBorder2.setBackground(BackgroundFactory
.createBitmapBackground(Bitmap
.getBitmapResource("loginbg_02.jpg")));
VerticalFieldManager vfmBasicInfoWithBorder3 = new VerticalFieldManager(
FIELD_HCENTER | FIELD_VCENTER) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(250, 95);
setExtent(250, 95);
}
};
vfmBasicInfoWithBorder3.setBackground(BackgroundFactory
.createBitmapBackground(Bitmap
.getBitmapResource("loginbg_03.png")));
vfmBasicInfoWithBorder3.add(btnLogin);
// btnLogin.setMargin(0, 0, 0, 0);
// HorizontalFieldManager hfm1 = new HorizontalFieldManager(
// Field.FIELD_HCENTER);
HorizontalFieldManager hfm2 = new HorizontalFieldManager(
Field.FIELD_VCENTER);
hfm2.add(txtUserID);
// txtUserID.setMargin(0, 0, 0, 0);
HorizontalFieldManager hfm3 = new HorizontalFieldManager(FIELD_HCENTER
& FIELD_VCENTER);
hfm3.add(txtPassword);
// txtPassword.setMargin(0, 0, 0, 10);
HorizontalFieldManager hfm4 = new HorizontalFieldManager(
Field.FIELD_HCENTER);
hfm4.add(Chkbox);
Chkbox.setMargin(0, 0, 0, 10);
hfm4.add(RememberMe);
RememberMe.setMargin(0, 0, 0, 10);
// HorizontalFieldManager hfm5 = new
// HorizontalFieldManager(FIELD_HCENTER
// & FIELD_VCENTER) {
// protected void sublayout(int maxWidth, int maxHeight) {
// super.sublayout(250, 95);
// }
// };
// hfm5.add(btnLogin);
// btnLogin.setMargin(0, 0, 0, 0);
// hfm5.add(btnCancel);
// hfm5.setPadding(new XYEdges(0, 0, 0, ((250 - (70 + 75)) / 2)));
// btnCancel.setMargin(0, 0, 0, 15);
// vfmBasicInfoWithBorder1.add(hfm1);
vfmBasicInfoWithBorder2.add(hfm2);
vfmBasicInfoWithBorder2.add(hfm3);
vfmBasicInfoWithBorder3.add(hfm4);
// vfmBasicInfoWithBorder3.add(hfm5);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder1);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder2);
vfmForCenterDisplay.add(vfmBasicInfoWithBorder3);
add(vfmForCenterDisplay);
}
}