diff options
| author | Harsh Shandilya <msfjarvis@gmail.com> | 2019-10-02 18:04:18 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-02 18:04:18 +0530 |
| commit | f1f59dc1ed26c2351dc31e55902ff8e4b5a6ed0e (patch) | |
| tree | 2afb98c921714ccefcd22f35a7340584d1bfba53 /app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java | |
| parent | 9a1a54a6fcfa6fd6cf142f2af9804375255d14cf (diff) | |
| download | HardenedPass-f1f59dc1ed26c2351dc31e55902ff8e4b5a6ed0e.tar.gz HardenedPass-f1f59dc1ed26c2351dc31e55902ff8e4b5a6ed0e.zip | |
Add Spotless to regulate codestyle (#550)
* Add Spotless to regulate codestyle
* treewide: Run spotless
* Add spotlessCheck to CI test
Signed-off-by: Harsh Shandilya <msfjarvis@gmail.com>
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java | 134 |
1 files changed, 80 insertions, 54 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java b/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java index 77fbcf27..3055d41f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java +++ b/app/src/main/java/com/zeapo/pwdstore/SshKeyGen.java @@ -21,7 +21,6 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; import android.widget.Toast; - import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; @@ -30,18 +29,15 @@ import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.preference.PreferenceManager; - import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.textfield.TextInputEditText; import com.jcraft.jsch.JSch; import com.jcraft.jsch.KeyPair; - -import org.apache.commons.io.FileUtils; - import java.io.File; import java.io.FileOutputStream; import java.lang.ref.WeakReference; import java.nio.charset.StandardCharsets; +import org.apache.commons.io.FileUtils; public class SshKeyGen extends AppCompatActivity { @@ -49,14 +45,15 @@ public class SshKeyGen extends AppCompatActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (getSupportActionBar() != null) - getSupportActionBar().setDisplayHomeAsUpEnabled(true); + if (getSupportActionBar() != null) getSupportActionBar().setDisplayHomeAsUpEnabled(true); setTitle("Generate SSH Key"); if (savedInstanceState == null) { - getSupportFragmentManager().beginTransaction() - .replace(android.R.id.content, new SshKeyGenFragment()).commit(); + getSupportFragmentManager() + .beginTransaction() + .replace(android.R.id.content, new SshKeyGenFragment()) + .commit(); } } @@ -64,45 +61,56 @@ public class SshKeyGen extends AppCompatActivity { // private and public key, then replaces the SshKeyGenFragment with a // ShowSshKeyFragment which displays the public key. public void generate(View view) { - String length = Integer.toString((Integer) ((Spinner) findViewById(R.id.length)).getSelectedItem()); + String length = + Integer.toString((Integer) ((Spinner) findViewById(R.id.length)).getSelectedItem()); String passphrase = ((EditText) findViewById(R.id.passphrase)).getText().toString(); String comment = ((EditText) findViewById(R.id.comment)).getText().toString(); new KeyGenerateTask(this).execute(length, passphrase, comment); - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + InputMethodManager imm = + (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } // SSH key generation UI public static class SshKeyGenFragment extends Fragment { - public SshKeyGenFragment() { - } + public SshKeyGenFragment() {} @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.fragment_ssh_keygen, container, false); - Typeface monoTypeface = Typeface.createFromAsset(requireContext().getAssets(), "fonts/sourcecodepro.ttf"); + Typeface monoTypeface = + Typeface.createFromAsset( + requireContext().getAssets(), "fonts/sourcecodepro.ttf"); Spinner spinner = v.findViewById(R.id.length); - Integer[] lengths = new Integer[]{2048, 4096}; - ArrayAdapter<Integer> adapter = new ArrayAdapter<>(requireContext(), - android.R.layout.simple_spinner_dropdown_item, lengths); + Integer[] lengths = new Integer[] {2048, 4096}; + ArrayAdapter<Integer> adapter = + new ArrayAdapter<>( + requireContext(), + android.R.layout.simple_spinner_dropdown_item, + lengths); spinner.setAdapter(adapter); ((TextInputEditText) v.findViewById(R.id.passphrase)).setTypeface(monoTypeface); final CheckBox checkbox = v.findViewById(R.id.show_passphrase); - checkbox.setOnCheckedChangeListener((buttonView, isChecked) -> { - final TextInputEditText editText = v.findViewById(R.id.passphrase); - final int selection = editText.getSelectionEnd(); - if (isChecked) { - editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); - } else { - editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - } - editText.setSelection(selection); - }); + checkbox.setOnCheckedChangeListener( + (buttonView, isChecked) -> { + final TextInputEditText editText = v.findViewById(R.id.passphrase); + final int selection = editText.getSelectionEnd(); + if (isChecked) { + editText.setInputType( + InputType.TYPE_CLASS_TEXT + | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); + } else { + editText.setInputType( + InputType.TYPE_CLASS_TEXT + | InputType.TYPE_TEXT_VARIATION_PASSWORD); + } + editText.setSelection(selection); + }); return v; } @@ -110,16 +118,17 @@ public class SshKeyGen extends AppCompatActivity { // Displays the generated public key .ssh_key.pub public static class ShowSshKeyFragment extends DialogFragment { - public ShowSshKeyFragment() { - } + public ShowSshKeyFragment() {} @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final FragmentActivity activity = requireActivity(); - final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()); + final MaterialAlertDialogBuilder builder = + new MaterialAlertDialogBuilder(requireContext()); LayoutInflater inflater = activity.getLayoutInflater(); - @SuppressLint("InflateParams") final View v = inflater.inflate(R.layout.fragment_show_ssh_key, null); + @SuppressLint("InflateParams") + final View v = inflater.inflate(R.layout.fragment_show_ssh_key, null); builder.setView(v); AppCompatTextView textView = v.findViewById(R.id.public_key); @@ -131,27 +140,35 @@ public class SshKeyGen extends AppCompatActivity { e.printStackTrace(); } - builder.setPositiveButton(getResources().getString(R.string.dialog_ok), (dialog, which) -> { - if (activity instanceof SshKeyGen) - activity.finish(); - }); - - builder.setNegativeButton(getResources().getString(R.string.dialog_cancel), (dialog, which) -> { + builder.setPositiveButton( + getResources().getString(R.string.dialog_ok), + (dialog, which) -> { + if (activity instanceof SshKeyGen) activity.finish(); + }); - }); + builder.setNegativeButton( + getResources().getString(R.string.dialog_cancel), (dialog, which) -> {}); builder.setNeutralButton(getResources().getString(R.string.ssh_keygen_copy), null); final AlertDialog ad = builder.setTitle("Your public key").create(); - ad.setOnShowListener(dialog -> { - Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL); - b.setOnClickListener(v1 -> { - AppCompatTextView textView1 = getDialog().findViewById(R.id.public_key); - ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("public key", textView1.getText().toString()); - clipboard.setPrimaryClip(clip); - }); - }); + ad.setOnShowListener( + dialog -> { + Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL); + b.setOnClickListener( + v1 -> { + AppCompatTextView textView1 = + getDialog().findViewById(R.id.public_key); + ClipboardManager clipboard = + (ClipboardManager) + activity.getSystemService( + Context.CLIPBOARD_SERVICE); + ClipData clip = + ClipData.newPlainText( + "public key", textView1.getText().toString()); + clipboard.setPrimaryClip(clip); + }); + }); return ad; } } @@ -206,17 +223,26 @@ public class SshKeyGen extends AppCompatActivity { Toast.makeText(weakReference.get(), "SSH-key generated", Toast.LENGTH_LONG).show(); DialogFragment df = new ShowSshKeyFragment(); df.show(weakReference.get().getSupportFragmentManager(), "public_key"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(weakReference.get()); + SharedPreferences prefs = + PreferenceManager.getDefaultSharedPreferences(weakReference.get()); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("use_generated_key", true); editor.apply(); } else { new MaterialAlertDialogBuilder(weakReference.get()) .setTitle("Error while trying to generate the ssh-key") - .setMessage(weakReference.get().getResources().getString(R.string.ssh_key_error_dialog_text) + e.getMessage()) - .setPositiveButton(weakReference.get().getResources().getString(R.string.dialog_ok), (dialogInterface, i) -> { - // pass - }).show(); + .setMessage( + weakReference + .get() + .getResources() + .getString(R.string.ssh_key_error_dialog_text) + + e.getMessage()) + .setPositiveButton( + weakReference.get().getResources().getString(R.string.dialog_ok), + (dialogInterface, i) -> { + // pass + }) + .show(); } } } |
