Back to project page PasswordGen-LibGDX.
The source code is released under:
GNU General Public License
If you think the Android project PasswordGen-LibGDX listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mygdx.main; /*w ww .j a va 2 s . co m*/ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.CheckBox; import com.badlogic.gdx.scenes.scene2d.ui.CheckBox.CheckBoxStyle; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Slider; import com.badlogic.gdx.scenes.scene2d.ui.Slider.SliderStyle; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle; import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.utils.Align; import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener; import com.mygdx.generation.GeneratePassword; public class MainScreen implements Screen{ private Stage stage; private Skin skin; private BitmapFont font; private TextureAtlas menuAtlas; private Label passwordText; private TextButtonStyle style; private TextButton generatePasswordButton; private Table tableLayout; private LabelStyle labelStyle; private CheckBox lowerCaseCharactersCheckBox; private CheckBox upperCaseCharactersCheckBox; private CheckBox specialCharactersCheckBox; private CheckBox numberCharactersCheckBox; private CheckBoxStyle checkBoxStyle; private GeneratePassword generatePassword; private boolean lowercase; private boolean uppercase; private boolean specialChars; private boolean numbers; private Slider passwordLengthSlider; private SliderStyle sliderStyle; private Image background; public MainScreen(PassGenerate app){ stage = new Stage(); font = new BitmapFont(); skin = new Skin(); menuAtlas = new TextureAtlas("checkBoxImages/Menu.pack"); skin.addRegions(menuAtlas); tableLayout = new Table(); generatePassword = new GeneratePassword(); style = new TextButtonStyle(); style.font = font; style.up = skin.getDrawable("button"); style.down = skin.getDrawable("buttonpressed"); style.fontColor = Color.BLUE; labelStyle = new LabelStyle(); labelStyle.font = font; labelStyle.fontColor = Color.GREEN; passwordText = new Label("Password: ", labelStyle); passwordText.setPosition(Gdx.graphics.getWidth() / 2 - passwordText.getWidth() / 2, Gdx.graphics.getHeight() / 2 - passwordText.getHeight() / 2 + 350 ); generatePasswordButton = new TextButton("Generate password", style); generatePasswordButton.setPosition(Gdx.graphics.getWidth() / 2 - passwordText.getWidth() / 2 - 50, Gdx.graphics.getHeight() / 2 - passwordText.getHeight() / 2 + 300 ); /* Check box is currently using place holder images so it will need to be changed */ checkBoxStyle = new CheckBoxStyle(); checkBoxStyle.font = font; checkBoxStyle.up = skin.getDrawable("buttonBox"); checkBoxStyle.checkboxOff = skin.getDrawable("button"); checkBoxStyle.checkboxOn = skin.getDrawable("buttonpressed"); lowerCaseCharactersCheckBox = new CheckBox("Lower case characters", checkBoxStyle); lowerCaseCharactersCheckBox.setPosition(Gdx.graphics.getWidth() / 2 - lowerCaseCharactersCheckBox.getWidth() / 2, Gdx.graphics.getHeight() / 2 - passwordText.getHeight() / 2 + 100); upperCaseCharactersCheckBox = new CheckBox("Upper case characters", checkBoxStyle); upperCaseCharactersCheckBox.setPosition(Gdx.graphics.getWidth() / 2 - lowerCaseCharactersCheckBox.getWidth() / 2 , Gdx.graphics.getHeight() / 2 - passwordText.getHeight() / 2 - 10); specialCharactersCheckBox = new CheckBox("Special characters", checkBoxStyle); specialCharactersCheckBox.setPosition(Gdx.graphics.getWidth() / 2 - lowerCaseCharactersCheckBox.getWidth() / 2 , Gdx.graphics.getHeight() / 2 - passwordText.getHeight() / 2 - 120); numberCharactersCheckBox = new CheckBox("Number characters", checkBoxStyle); numberCharactersCheckBox.setPosition(Gdx.graphics.getWidth() / 2 - lowerCaseCharactersCheckBox.getWidth() / 2 , Gdx.graphics.getHeight() / 2 - passwordText.getHeight() / 2 - 230); background = new Image(skin, "Background"); sliderStyle = new SliderStyle(); sliderStyle.knob = skin.getDrawable("BulletTest2"); sliderStyle.background = skin.getDrawable("buttonBox"); passwordLengthSlider = new Slider(5, 25, 1, false, sliderStyle); passwordLengthSlider.setWidth(lowerCaseCharactersCheckBox.getWidth()); passwordLengthSlider.setPosition(Gdx.graphics.getWidth() / 2 - lowerCaseCharactersCheckBox.getWidth() / 2 , Gdx.graphics.getHeight() / 2 - passwordText.getHeight() / 2 - 340); generatePasswordButton.addListener(new InputListener(){ @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { generatePassword.resetPassword(); int passwordLength = (int) passwordLengthSlider.getValue(); generatePassword.createPassword(lowercase, uppercase, specialChars, numbers, passwordLength); return true; } }); passwordLengthSlider.addListener(new ChangeListener(){ @Override public void changed(ChangeEvent event, Actor actor) { System.out.println(passwordLengthSlider.getValue()); } }); Gdx.input.setInputProcessor(stage); stage.addActor(background); stage.addActor(passwordText); stage.addActor(generatePasswordButton); stage.addActor(lowerCaseCharactersCheckBox); stage.addActor(upperCaseCharactersCheckBox); stage.addActor(specialCharactersCheckBox); stage.addActor(numberCharactersCheckBox); stage.addActor(passwordLengthSlider); } public void render(float delta) { Gdx.gl.glClearColor(0.95f, 0.95f, 0.95f, 0.95f); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); getCheckBoxState(); passwordText.setText("Password: " + generatePassword.setPassword()); stage.act(); stage.draw(); } public void resize(int width, int height) { } public void getCheckBoxState(){ if(lowerCaseCharactersCheckBox.isChecked() == true){ lowercase = true; }else if(!lowerCaseCharactersCheckBox.isChecked()){ lowercase = false; } if(upperCaseCharactersCheckBox.isChecked() == true){ uppercase = true; }else if(!upperCaseCharactersCheckBox.isChecked()){ uppercase = false; } if(specialCharactersCheckBox.isChecked() == true){ specialChars = true; }else if(!specialCharactersCheckBox.isChecked()){ specialChars = false; } if(numberCharactersCheckBox.isChecked() == true){ numbers = true; }else if(!numberCharactersCheckBox.isChecked()){ numbers = false; } } public void show() { } public void hide() { } public void pause() { } public void resume() { } public void dispose() { skin.dispose(); font.dispose(); menuAtlas.dispose(); stage.dispose(); } }