2. Container logoContainer = BorderLayout.centerAbsolute(logo);
logoContainer.setUIID("LoginTitle");
signUp.addActionListener(e -> UIController.showSignup());
login.addActionListener(e -> {
User u = new User().password.set(password.getText());
if(user.getText().contains("@")) {
u.email.set(user.getText());
} else {
u.phone.set(user.getText());
}
Dialog d = new InfiniteProgress().showInifiniteBlocking();
ServerAPI.login(u, new Callback<User>() {
@Override
public void onSucess(User value) {
d.dispose();
UIController.showMainUI();
}
@Override
public void onError(Object sender, Throwable err,
int errorCode, String errorMessage) {
d.dispose();
ToastBar.showErrorMessage("Login Failed");
LoginForm
3. Container logoContainer = BorderLayout.centerAbsolute(logo);
logoContainer.setUIID("LoginTitle");
signUp.addActionListener(e -> UIController.showSignup());
login.addActionListener(e -> {
User u = new User().password.set(password.getText());
if(user.getText().contains("@")) {
u.email.set(user.getText());
} else {
u.phone.set(user.getText());
}
Dialog d = new InfiniteProgress().showInifiniteBlocking();
ServerAPI.login(u, new Callback<User>() {
@Override
public void onSucess(User value) {
d.dispose();
UIController.showMainUI();
}
@Override
public void onError(Object sender, Throwable err,
int errorCode, String errorMessage) {
d.dispose();
ToastBar.showErrorMessage("Login Failed");
LoginForm
4. Container logoContainer = BorderLayout.centerAbsolute(logo);
logoContainer.setUIID("LoginTitle");
signUp.addActionListener(e -> UIController.showSignup());
login.addActionListener(e -> {
User u = new User().password.set(password.getText());
if(user.getText().contains("@")) {
u.email.set(user.getText());
} else {
u.phone.set(user.getText());
}
Dialog d = new InfiniteProgress().showInifiniteBlocking();
ServerAPI.login(u, new Callback<User>() {
@Override
public void onSucess(User value) {
d.dispose();
UIController.showMainUI();
}
@Override
public void onError(Object sender, Throwable err,
int errorCode, String errorMessage) {
d.dispose();
ToastBar.showErrorMessage("Login Failed");
LoginForm
5. login.addActionListener(e -> {
User u = new User().password.set(password.getText());
if(user.getText().contains("@")) {
u.email.set(user.getText());
} else {
u.phone.set(user.getText());
}
Dialog d = new InfiniteProgress().showInifiniteBlocking();
ServerAPI.login(u, new Callback<User>() {
@Override
public void onSucess(User value) {
d.dispose();
UIController.showMainUI();
}
@Override
public void onError(Object sender, Throwable err,
int errorCode, String errorMessage) {
d.dispose();
ToastBar.showErrorMessage("Login Failed");
}
});
});
LoginForm
6. public class SignupForm extends Form {
Container content = new Container(BoxLayout.y(), "PaddedContainer");
Container south = new Container(BoxLayout.y());
protected SignupForm(String title, String backLabel, Form previous) {
super(title, new BorderLayout());
setUIID("SignupForm");
content.setScrollableY(true);
add(CENTER, content);
getToolbar().setBackCommand(backLabel,
Toolbar.BackCommandPolicy.WHEN_USES_TITLE_OTHERWISE_ARROW,
e -> previous.showBack());
getToolbar().getTitleComponent().setUIID("Title", "TitleLandscape");
Button problem = new Button("Report a Problem", "BlueLink");
south.add(problem);
problem.addActionListener(e ->
sendMessage("Problem with Facebook Clone",
new Message("Details..."),
"mark@facebook.com"));
SignupForm
7. next.addActionListener(al);
return next;
}
public static SignupForm createTerms() {
SignupForm s = new SignupForm("Create Account", "Sign In",
getCurrentForm());
Label title = new Label("Terms & Conditions", "SignupSubHeader");
RichTextView rt = new RichTextView(
"By signing up you agree to our " +
"<a href="terms">Facebook Terms</a> and that you have " +
"read our <a href="data-policy">Data Policy</a>, including " +
"our <a href="cookie-use">Cookie Use</a>.");
rt.setAlignment(CENTER);
rt.setUIID("PaddedContainer");
Button next = s.createNextButton(e -> createName().show());
next.setText("I Agree");
rt.addLinkListener(e -> {
String link = (String) e.getSource();
execute("https://www.codenameone.com/");
});
s.content.addAll(title, rt, next);
return s;
SignupForm
8. return s;
}
public static SignupForm createName() {
SignupForm s = new SignupForm("Name", "Terms",
getCurrentForm());
Label title = new Label("What's Your Name?", "SignupSubHeader");
TextComponent first = new TextComponent().
label("First Name").columns(12);
TextComponent last = new TextComponent().
label("Last Name").columns(12);
User currentUser = new User();
UiBinding uib = new UiBinding();
uib.bind(currentUser.firstName, first);
uib.bind(currentUser.familyName, last);
TextModeLayout layout = new TextModeLayout(1, 2);
Container textContainer = new Container(layout, "PaddedContainer");
textContainer.add(layout.createConstraint().
widthPercentage(50), first);
textContainer.add(layout.createConstraint().
widthPercentage(50), last);
SignupForm
9. return s;
}
public static SignupForm createName() {
SignupForm s = new SignupForm("Name", "Terms",
getCurrentForm());
Label title = new Label("What's Your Name?", "SignupSubHeader");
TextComponent first = new TextComponent().
label("First Name").columns(12);
TextComponent last = new TextComponent().
label("Last Name").columns(12);
User currentUser = new User();
UiBinding uib = new UiBinding();
uib.bind(currentUser.firstName, first);
uib.bind(currentUser.familyName, last);
TextModeLayout layout = new TextModeLayout(1, 2);
Container textContainer = new Container(layout, "PaddedContainer");
textContainer.add(layout.createConstraint().
widthPercentage(50), first);
textContainer.add(layout.createConstraint().
widthPercentage(50), last);
SignupForm
10. return s;
}
public static SignupForm createName() {
SignupForm s = new SignupForm("Name", "Terms",
getCurrentForm());
Label title = new Label("What's Your Name?", "SignupSubHeader");
TextComponent first = new TextComponent().
label("First Name").columns(12);
TextComponent last = new TextComponent().
label("Last Name").columns(12);
User currentUser = new User();
UiBinding uib = new UiBinding();
uib.bind(currentUser.firstName, first);
uib.bind(currentUser.familyName, last);
TextModeLayout layout = new TextModeLayout(1, 2);
Container textContainer = new Container(layout, "PaddedContainer");
textContainer.add(layout.createConstraint().
widthPercentage(50), first);
textContainer.add(layout.createConstraint().
widthPercentage(50), last);
SignupForm
11. TextModeLayout layout = new TextModeLayout(1, 2);
Container textContainer = new Container(layout, "PaddedContainer");
textContainer.add(layout.createConstraint().
widthPercentage(50), first);
textContainer.add(layout.createConstraint().
widthPercentage(50), last);
last.getField().setDoneListener(e ->
createBirthday(currentUser, uib).show());
s.content.addAll(title, textContainer,
s.createNextButton(e -> createBirthday(currentUser, uib).
show()));
return s;
}
public static SignupForm createBirthday(User currentUser, UiBinding uib) {
SignupForm s = new SignupForm("Birthday",
"Name",
getCurrentForm());
Label title = new Label("What's Your Birthday?", "SignupSubHeader");
Picker datePicker = new Picker();
datePicker.setType(PICKER_TYPE_DATE);
int twentyYears = 60000 * 60 * 24 * 365 * 20;
SignupForm
12. s.createNextButton(e -> createBirthday(currentUser, uib).
show()));
return s;
}
public static SignupForm createBirthday(User currentUser, UiBinding uib) {
SignupForm s = new SignupForm("Birthday",
"Name",
getCurrentForm());
Label title = new Label("What's Your Birthday?", "SignupSubHeader");
Picker datePicker = new Picker();
datePicker.setType(PICKER_TYPE_DATE);
int twentyYears = 60000 * 60 * 24 * 365 * 20;
datePicker.setDate(
new Date(System.currentTimeMillis() - twentyYears));
uib.bind(currentUser.birthday, datePicker);
s.content.addAll(title, datePicker,
s.createNextButton(e -> createGender(currentUser, uib).show()));
return s;
}
private static RadioButton createGenderButton(ButtonGroup bg,
SignupForm
13. s.createNextButton(e -> createBirthday(currentUser, uib).
show()));
return s;
}
public static SignupForm createBirthday(User currentUser, UiBinding uib) {
SignupForm s = new SignupForm("Birthday",
"Name",
getCurrentForm());
Label title = new Label("What's Your Birthday?", "SignupSubHeader");
Picker datePicker = new Picker();
datePicker.setType(PICKER_TYPE_DATE);
int twentyYears = 60000 * 60 * 24 * 365 * 20;
datePicker.setDate(
new Date(System.currentTimeMillis() - twentyYears));
uib.bind(currentUser.birthday, datePicker);
s.content.addAll(title, datePicker,
s.createNextButton(e -> createGender(currentUser, uib).show()));
return s;
}
private static RadioButton createGenderButton(ButtonGroup bg,
SignupForm
14. s.createNextButton(e -> createBirthday(currentUser, uib).
show()));
return s;
}
public static SignupForm createBirthday(User currentUser, UiBinding uib) {
SignupForm s = new SignupForm("Birthday",
"Name",
getCurrentForm());
Label title = new Label("What's Your Birthday?", "SignupSubHeader");
Picker datePicker = new Picker();
datePicker.setType(PICKER_TYPE_DATE);
int twentyYears = 60000 * 60 * 24 * 365 * 20;
datePicker.setDate(
new Date(System.currentTimeMillis() - twentyYears));
uib.bind(currentUser.birthday, datePicker);
s.content.addAll(title, datePicker,
s.createNextButton(e -> createGender(currentUser, uib).show()));
return s;
}
private static RadioButton createGenderButton(ButtonGroup bg,
SignupForm
15. rb.setUIID("GenderToggle");
return rb;
}
public static SignupForm createGender(User currentUser, UiBinding uib) {
SignupForm s = new SignupForm("Gender",
"Birthday",
getCurrentForm());
Label title = new Label("What's Your Gender?", "SignupSubHeader");
ButtonGroup bg = new ButtonGroup();
RadioButton female = createGenderButton(bg, "Female", "ue800");
RadioButton male = createGenderButton(bg, "Male", "ue801");
uib.bindGroup(currentUser.gender,
new String[]{"Male", "Female"}, male, female);
Container buttons = GridLayout.encloseIn(2, female, male);
buttons.setUIID("PaddedContainer");
s.content.addAll(title, buttons,
s.createNextButton(e -> createNumber(currentUser, uib).show()));
return s;
}
SignupForm
16. Container buttons = GridLayout.encloseIn(2, female, male);
buttons.setUIID("PaddedContainer");
s.content.addAll(title, buttons,
s.createNextButton(e -> createNumber(currentUser, uib).show()));
return s;
}
public static SignupForm createNumber(User currentUser, UiBinding uib) {
return createMobileOrEmail(currentUser, currentUser.phone, uib,
"Mobile Number",
"What's Your Mobile Number?",
"Sign Up With Email Address",
TextArea.PHONENUMBER,
e -> createEmail(currentUser, uib).show());
}
private static SignupForm createMobileOrEmail(User currentUser,
Property userProp, UiBinding uib, String formTitle,
String subtitle, String signUpWith, int constraint,
ActionListener goToOther) {
SignupForm s =
new SignupForm(formTitle, getCurrentForm().getTitle(),
SignupForm
17. TextArea.PHONENUMBER,
e -> createEmail(currentUser, uib).show());
}
private static SignupForm createMobileOrEmail(User currentUser,
Property userProp, UiBinding uib, String formTitle,
String subtitle, String signUpWith, int constraint,
ActionListener goToOther) {
SignupForm s =
new SignupForm(formTitle, getCurrentForm().getTitle(),
getCurrentForm());
Label title = new Label(subtitle, "SignupSubHeader");
TextComponent textEntry = new TextComponent().
label(formTitle).
columns(20).
constraint(constraint);
uib.bind(userProp, textEntry);
Container textContainer = new Container(new TextModeLayout(1, 1),
"PaddedContainer");
textContainer.add(textEntry);
Button mobile = new Button(signUpWith, "BoldBlueLink");
SignupForm
18. TextArea.EMAILADDR,
e -> createNumber(currentUser, uib).show());
}
public static SignupForm createPassword(
User currentUser, UiBinding uib, boolean phone, String value) {
SignupForm s = new SignupForm("Password",
getCurrentForm().getTitle(),
getCurrentForm());
Label title = new Label("Choose a Password", "SignupSubHeader");
TextComponent password = new TextComponent().
label("Password").
columns(20);
uib.bind(currentUser.password, password);
Container textContainer = new Container(new TextModeLayout(1, 1),
"PaddedContainer");
textContainer.add(password);
s.content.addAll(title, textContainer,
s.createNextButton(e -> {
Dialog dlg = new Dialog("Signing Up...",
new BorderLayout(
SignupForm
19. getCurrentForm().getTitle(),
getCurrentForm());
Label title = new Label("Choose a Password", "SignupSubHeader");
TextComponent password = new TextComponent().
label("Password").
columns(20);
uib.bind(currentUser.password, password);
Container textContainer = new Container(new TextModeLayout(1, 1),
"PaddedContainer");
textContainer.add(password);
s.content.addAll(title, textContainer,
s.createNextButton(e -> {
Dialog dlg = new Dialog("Signing Up...",
new BorderLayout(
BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
dlg.add(CENTER, new InfiniteProgress());
dlg.showModeless();
ServerAPI.signup(currentUser, new Callback<User>() {
@Override
public void onSucess(User result) {
dlg.dispose();
SignupForm
20. s.content.addAll(title, textContainer,
s.createNextButton(e -> {
Dialog dlg = new Dialog("Signing Up...",
new BorderLayout(
BorderLayout.CENTER_BEHAVIOR_CENTER_ABSOLUTE));
dlg.add(CENTER, new InfiniteProgress());
dlg.showModeless();
ServerAPI.signup(currentUser, new Callback<User>() {
@Override
public void onSucess(User result) {
dlg.dispose();
createConfirmation(currentUser, phone, value).show();
}
@Override
public void onError(Object sender, Throwable err,
int errorCode, String errorMessage) {
dlg.dispose();
ToastBar.showErrorMessage(
"Error in server connection");
}
});
}));
return s;
SignupForm