use monospaced font for passwords

fix EditText being cast to textview
This commit is contained in:
Mohamed Zenadi 2015-07-18 20:11:18 +02:00
parent 62c20d323c
commit ba1ce73dba
2 changed files with 20 additions and 9 deletions

View file

@ -327,17 +327,17 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
if (showPassword) { if (showPassword) {
findViewById(R.id.crypto_container).setVisibility(View.VISIBLE); findViewById(R.id.crypto_container).setVisibility(View.VISIBLE);
Typeface type = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf"); Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
String[] passContent = os.toString("UTF-8").split("\n"); String[] passContent = os.toString("UTF-8").split("\n");
((TextView) findViewById(R.id.crypto_password_show)) ((TextView) findViewById(R.id.crypto_password_show))
.setTypeface(type); .setTypeface(monoTypeface);
((TextView) findViewById(R.id.crypto_password_show)) ((TextView) findViewById(R.id.crypto_password_show))
.setText(passContent[0]); .setText(passContent[0]);
String extraContent = os.toString("UTF-8").replaceFirst(".*\n", ""); String extraContent = os.toString("UTF-8").replaceFirst(".*\n", "");
if (extraContent.length() != 0) { if (extraContent.length() != 0) {
((TextView) findViewById(R.id.crypto_extra_show)) ((TextView) findViewById(R.id.crypto_extra_show))
.setTypeface(type); .setTypeface(monoTypeface);
((TextView) findViewById(R.id.crypto_extra_show)) ((TextView) findViewById(R.id.crypto_extra_show))
.setText(extraContent); .setText(extraContent);
} }
@ -499,6 +499,9 @@ public class PgpHandler extends AppCompatActivity implements OpenPgpServiceConne
decryptAndVerify(new Intent()); decryptAndVerify(new Intent());
} else if (extra.getString("Operation").equals("ENCRYPT")) { } else if (extra.getString("Operation").equals("ENCRYPT")) {
setContentView(R.layout.encrypt_layout); setContentView(R.layout.encrypt_layout);
Typeface monoTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodepro.ttf");
((EditText) findViewById(R.id.crypto_password_edit)).setTypeface(monoTypeface);
((EditText) findViewById(R.id.crypto_extra_edit)).setTypeface(monoTypeface);
String cat = extra.getString("FILE_PATH"); String cat = extra.getString("FILE_PATH");
cat = cat.replace(PasswordRepository.getWorkTree().getAbsolutePath(), ""); cat = cat.replace(PasswordRepository.getWorkTree().getAbsolutePath(), "");
cat = cat + "/"; cat = cat + "/";

View file

@ -1,16 +1,19 @@
package com.zeapo.pwdstore; package com.zeapo.pwdstore;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment; import android.app.DialogFragment;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import com.zeapo.pwdstore.pwgen.pwgen; import com.zeapo.pwdstore.pwgen.pwgen;
@ -30,8 +33,11 @@ public class pwgenDialogFragment extends DialogFragment {
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater(); final Activity callingActivity = getActivity();
LayoutInflater inflater = callingActivity.getLayoutInflater();
final View view = inflater.inflate(R.layout.fragment_pwgen, null); final View view = inflater.inflate(R.layout.fragment_pwgen, null);
Typeface monoTypeface = Typeface.createFromAsset(callingActivity.getAssets(), "fonts/sourcecodepro.ttf");
builder.setView(view); builder.setView(view);
SharedPreferences prefs SharedPreferences prefs
@ -55,11 +61,13 @@ public class pwgenDialogFragment extends DialogFragment {
TextView textView = (TextView) view.findViewById(R.id.lengthNumber); TextView textView = (TextView) view.findViewById(R.id.lengthNumber);
textView.setText(Integer.toString(prefs.getInt("length", 20))); textView.setText(Integer.toString(prefs.getInt("length", 20)));
((EditText) view.findViewById(R.id.passwordText)).setTypeface(monoTypeface);
builder.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
TextView edit = (TextView) pwgenDialogFragment.this.getActivity().findViewById(R.id.crypto_password_edit); EditText edit = (EditText) callingActivity.findViewById(R.id.crypto_password_edit);
TextView generate = (TextView) pwgenDialogFragment.this.getDialog().findViewById(R.id.passwordText); EditText generate = (EditText) callingActivity.findViewById(R.id.passwordText);
edit.append(generate.getText()); edit.append(generate.getText());
} }
}); });
@ -78,7 +86,7 @@ public class pwgenDialogFragment extends DialogFragment {
@Override @Override
public void onShow(DialogInterface dialog) { public void onShow(DialogInterface dialog) {
setPreferences(); setPreferences();
TextView textView = (TextView) view.findViewById(R.id.passwordText); EditText textView = (EditText) view.findViewById(R.id.passwordText);
textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0)); textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0));
Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL); Button b = ad.getButton(AlertDialog.BUTTON_NEUTRAL);
@ -86,7 +94,7 @@ public class pwgenDialogFragment extends DialogFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
setPreferences(); setPreferences();
TextView textView = (TextView) getDialog().findViewById(R.id.passwordText); EditText textView = (EditText) getDialog().findViewById(R.id.passwordText);
textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0)); textView.setText(pwgen.generate(getActivity().getApplicationContext()).get(0));
} }
}); });
@ -112,7 +120,7 @@ public class pwgenDialogFragment extends DialogFragment {
if (!((CheckBox) getDialog().findViewById(R.id.pronounceable)).isChecked()) { if (!((CheckBox) getDialog().findViewById(R.id.pronounceable)).isChecked()) {
preferences.add("s"); preferences.add("s");
} }
TextView textView = (TextView) getDialog().findViewById(R.id.lengthNumber); EditText textView = (EditText) getDialog().findViewById(R.id.lengthNumber);
try { try {
int length = Integer.valueOf(textView.getText().toString()); int length = Integer.valueOf(textView.getText().toString());
return pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length); return pwgen.setPrefs(getActivity().getApplicationContext(), preferences, length);