Show the secret in a TextView to allow copying

This commit is contained in:
Jakob Nixdorf 2020-04-19 20:01:01 +02:00
parent 38c10bc497
commit 835db6daf6
No known key found for this signature in database
GPG key ID: BE99BF86574A7DBC
2 changed files with 26 additions and 4 deletions

View file

@ -36,6 +36,7 @@ import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import com.github.aakira.expandablelayout.ExpandableLayoutListenerAdapter; import com.github.aakira.expandablelayout.ExpandableLayoutListenerAdapter;
import com.github.aakira.expandablelayout.ExpandableLinearLayout; import com.github.aakira.expandablelayout.ExpandableLinearLayout;
@ -72,6 +73,7 @@ public class ManualEntryDialog {
final EditText issuerInput = inputView.findViewById(R.id.manual_issuer); final EditText issuerInput = inputView.findViewById(R.id.manual_issuer);
final EditText labelInput = inputView.findViewById(R.id.manual_label); final EditText labelInput = inputView.findViewById(R.id.manual_label);
final EditText secretInput = inputView.findViewById(R.id.manual_secret); final EditText secretInput = inputView.findViewById(R.id.manual_secret);
final TextView secretView = inputView.findViewById(R.id.manual_secret_view);
final EditText counterInput = inputView.findViewById(R.id.manual_counter); final EditText counterInput = inputView.findViewById(R.id.manual_counter);
final EditText periodInput = inputView.findViewById(R.id.manual_period); final EditText periodInput = inputView.findViewById(R.id.manual_period);
final EditText digitsInput = inputView.findViewById(R.id.manual_digits); final EditText digitsInput = inputView.findViewById(R.id.manual_digits);
@ -299,7 +301,7 @@ public class ManualEntryDialog {
typeInput.setSelection(typeAdapter.getPosition(oldType)); typeInput.setSelection(typeAdapter.getPosition(oldType));
issuerInput.setText(oldEntry.getIssuer()); issuerInput.setText(oldEntry.getIssuer());
labelInput.setText(oldEntry.getLabel()); labelInput.setText(oldEntry.getLabel());
secretInput.setText(oldEntry.getSecretEncoded()); secretView.setText(oldEntry.getSecretEncoded());
digitsInput.setText(Integer.toString(oldEntry.getDigits())); digitsInput.setText(Integer.toString(oldEntry.getDigits()));
algorithmInput.setSelection(algorithmAdapter.getPosition(oldEntry.getAlgorithm())); algorithmInput.setSelection(algorithmAdapter.getPosition(oldEntry.getAlgorithm()));
@ -318,8 +320,15 @@ public class ManualEntryDialog {
e.printStackTrace(); e.printStackTrace();
} }
typeInput.setEnabled(false); secretInput.setVisibility(View.GONE);
secretView.setVisibility(View.VISIBLE);
// Little hack: match the color and background of the TextView to that of a disabled EditText
secretInput.setEnabled(false); secretInput.setEnabled(false);
secretView.setBackground(secretInput.getBackground());
secretView.setTextColor(secretInput.getTextColors().getColorForState(secretInput.getDrawableState(), R.color.colorPrimary));
typeInput.setEnabled(false);
digitsInput.setEnabled(false); digitsInput.setEnabled(false);
algorithmInput.setEnabled(false); algorithmInput.setEnabled(false);
periodInput.setEnabled(false); periodInput.setEnabled(false);

View file

@ -86,13 +86,26 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/label_secret"/> android:text="@string/label_secret"/>
<TextView
android:id="@+id/manual_secret_view"
android:layout_weight="7"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/editTextBackground"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textIsSelectable="true"
android:fontFamily="monospace"
android:maxLines="3"
android:visibility="gone" />
<EditText <EditText
android:id="@+id/manual_secret" android:id="@+id/manual_secret"
android:layout_weight="7" android:layout_weight="7"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:lines="3" android:fontFamily="monospace"
android:inputType="textVisiblePassword" android:inputType="textMultiLine"
android:maxLines="3"
android:hint="@string/hint_secret" /> android:hint="@string/hint_secret" />
</LinearLayout> </LinearLayout>