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
arunbiet
Posts: 384
Registered: ‎06-22-2010
My Device: na
Accepted Solution

show password in the login screen

I want to implement show password in my app.I have a login screen with username and password.I am taking a passwordeditfield for password.Now i want to add a checkbox called show password,so that if i check that box,instead of **** my passwordeditfield show show actual password like 1234 while i type.Can anyone help

Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: show password in the login screen

You can change your passwordeditfield at run time with EditField instance.

 

Lets say by default it is 

 

EditField pwdField = new PasswordEditField();

 

and if checkbox is checked, you can re-assign it as

 

pwdField = new EditField();

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
arunbiet
Posts: 384
Registered: ‎06-22-2010
My Device: na

Re: show password in the login screen

How can u assing 

EditField pwdField = new PasswordEditField();

 it will throw compile time error

Developer
pradeep_ch
Posts: 543
Registered: ‎12-23-2010
My Device: Z10

Re: show password in the login screen

"EditField pwdField = new PasswordEditField();"

 

I dont think the above mentioned line is allowed,

 

Try with BasicEditField, this is the super class for both EditField and Passwordfield.

Based on your requirement you can assign either of the child object.

 

 

Thanks.

Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: show password in the login screen

Yes, my mistake.. you will need to do 

 

BasicEditField pwdField = new PasswordEditField()

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
arunbiet
Posts: 384
Registered: ‎06-22-2010
My Device: na

Re: show password in the login screen

Ok thank you.But how will i invalidate the screen when i check the checkbox

 

 showPassword = new CheckboxField("Show Password",false){
	        	public void paint(Graphics g) {
					g.setColor(Color.WHITE);
					super.paint(g);
				}
	        	protected void drawFocus(Graphics graphics, boolean on) {
	        		
	        	};
	        };
	        showPassword.setFont(Utils.largestFont);
	        showPassword.setMargin(4, 0, 0, Display.getWidth() / 8);





if(!(showPassword.getChecked())){
			//UiApplication.getUiApplication().getActiveScreen().invalidate();
		pwdEditField = new PasswordEditField("", initialPWDVal, 10, PasswordEditField.FILTER_NUMERIC) {
			protected void paintBackground(Graphics g) {
				invalidate();
				g.setColor(Color.GRAY);
				g.fillRoundRect(0, 0, Display.getWidth() - Display.getWidth() / 3, getPreferredHeight(), 10, 10);
				// g.setColor(0xDC143C);
				g.drawRoundRect(0, 0, Display.getWidth() - Display.getWidth() / 3, getPreferredHeight(), 10, 10);
				g.setColor(Color.BLACK);
				super.paintBackground(g);
			}
		};
		
		}
		else {
			//UiApplication.getUiApplication().getActiveScreen().invalidate();
			pwdEditField = new EditField(EditField.FILTER_NUMERIC) {
				protected void paintBackground(Graphics g) {
					invalidate();
					g.setColor(Color.GRAY);
					g.fillRoundRect(0, 0, Display.getWidth() - Display.getWidth() / 3, getPreferredHeight(), 10, 10);
					// g.setColor(0xDC143C);
					g.drawRoundRect(0, 0, Display.getWidth() - Display.getWidth() / 3, getPreferredHeight(), 10, 10);
					g.setColor(Color.BLACK);
					super.paintBackground(g);
				}
			};
			
			
		}
		pwdEditField.setMargin(4, 0, 0, Display.getWidth() / 8);
		login.add(pwdEditField);

 This is what i am doing.But when i check the box and type in the password field,it still shows ******

Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: show password in the login screen

Implement FieldChangeListener in your Screen class.

 

Apply FieldChangeListener to your Checkboxfield instance - 

showPassword.setChangeListener(this);

Override fieldChanged() as FieldChangeListener  implementation - 

 

public void fieldChanged(Field field, int context) {

			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
					vfm.delete(pwdEditField);

					if(cbx.getChecked())
						pwdEditField = new EditField(EditField.FILTER_NUMERIC);
					else
						pwdEditField = new PasswordEditField();

					vfm.insert(pwdEditField, indexOfPasswordField);
				}
			});
		}

vfm is here an intance of VerticalFieldManager, in which all field are added. Now, its done..!!

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
arunbiet
Posts: 384
Registered: ‎06-22-2010
My Device: na

Re: show password in the login screen

Thank you so much,it helped me to great extent,the only thing i need is,now when i click on show password,the passwordfield gets empty,now suppose my password is of 5 char,and i type 2 char and its showing **,now if the check the check box i want instead of deleting the field it should be like **123.Now its deleting and re-entering freshly

Developer
kanaksony
Posts: 571
Registered: ‎04-11-2009
My Device: BB 10 Dev Alpha

Re: show password in the login screen

public void fieldChanged(Field field, int context) {

			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
					String text = pwdEditField.getText();
					
					vfm.delete(pwdEditField);

					if(cbx.getChecked())
						pwdEditField = new EditField(EditField.FILTER_NUMERIC);
					else
						pwdEditField = new PasswordEditField();
					
					pwdEditField.setText(text);
					
					vfm.insert(pwdEditField, 0);
				}
			});
		}
	}    

 

Regards,
Kanak Sony
------------------------------------------------------------------------------------------
http://dodevelopnshare.wordpress.com/ | http://www.linkedin.com/profile/view?id=188131481&trk=tab_pro
Developer
arunbiet
Posts: 384
Registered: ‎06-22-2010
My Device: na

Re: show password in the login screen

Thank you so much.It solved my problem smoothly.Kudos :Clap: