From 0f7d64bed65d64aa41f735e539ab893688eb1f86 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Sat, 11 Feb 2017 22:27:26 -0500 Subject: [PATCH 1/2] Show card data in a TextView when viewing Earlier when a card was viewed it was shown in an EditView which was disabled. This was not optimal, as the resulting text was dimmed. To help the text be easier to read, a TextView is now used to display the data. In addition, the layout of the card viewing screen has been adjusted --- .../card_locker/LoyaltyCardViewActivity.java | 64 +++++++----- .../res/layout/loyalty_card_view_activity.xml | 78 ++++++++------- .../LoyaltyCardViewActivityTest.java | 98 ++++++++++++------- 3 files changed, 145 insertions(+), 95 deletions(-) diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java index 6877b137..c4b759ce 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardViewActivity.java @@ -21,6 +21,7 @@ import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; +import android.widget.TextView; import com.google.zxing.BarcodeFormat; import com.google.zxing.integration.android.IntentIntegrator; @@ -74,9 +75,12 @@ public void onResume() } } - final EditText storeField = (EditText) findViewById(R.id.storeName); - final EditText noteField = (EditText) findViewById(R.id.note); - final EditText cardIdField = (EditText) findViewById(R.id.cardId); + final EditText storeFieldEdit = (EditText) findViewById(R.id.storeNameEdit); + final TextView storeFieldView = (TextView) findViewById(R.id.storeNameView); + final EditText noteFieldEdit = (EditText) findViewById(R.id.noteEdit); + final TextView noteFieldView = (TextView) findViewById(R.id.noteView); + final EditText cardIdFieldEdit = (EditText) findViewById(R.id.cardIdEdit); + final TextView cardIdFieldView = (TextView) findViewById(R.id.cardIdView); final EditText barcodeTypeField = (EditText) findViewById(R.id.barcodeType); final ImageView barcodeImage = (ImageView) findViewById(R.id.barcode); final View barcodeIdLayout = findViewById(R.id.barcodeIdLayout); @@ -95,19 +99,22 @@ public void onResume() { final LoyaltyCard loyaltyCard = db.getLoyaltyCard(loyaltyCardId); - if(storeField.getText().length() == 0) + if(storeFieldEdit.getText().length() == 0) { - storeField.setText(loyaltyCard.store); + storeFieldEdit.setText(loyaltyCard.store); + storeFieldView.setText(loyaltyCard.store); } - if(noteField.getText().length() == 0) + if(noteFieldEdit.getText().length() == 0) { - noteField.setText(loyaltyCard.note); + noteFieldEdit.setText(loyaltyCard.note); + noteFieldView.setText(loyaltyCard.note); } - if(cardIdField.getText().length() == 0) + if(cardIdFieldEdit.getText().length() == 0) { - cardIdField.setText(loyaltyCard.cardId); + cardIdFieldEdit.setText(loyaltyCard.cardId); + cardIdFieldView.setText(loyaltyCard.cardId); } if(barcodeTypeField.getText().length() == 0) @@ -115,15 +122,13 @@ public void onResume() barcodeTypeField.setText(loyaltyCard.barcodeType); } - if(viewLoyaltyCard) - { - storeField.setEnabled(false); - noteField.setEnabled(false); - } - if(updateLoyaltyCard) { setTitle(R.string.editCardTitle); + + storeFieldView.setVisibility(View.GONE); + noteFieldView.setVisibility(View.GONE); + cardIdFieldView.setVisibility(View.GONE); } else { @@ -132,25 +137,33 @@ public void onResume() saveButton.setVisibility(View.GONE); cancelButton.setVisibility(View.GONE); setTitle(R.string.viewCardTitle); + + storeFieldEdit.setVisibility(View.GONE); + noteFieldEdit.setVisibility(View.GONE); + cardIdFieldEdit.setVisibility(View.GONE); } } else { setTitle(R.string.addCardTitle); + + storeFieldView.setVisibility(View.GONE); + noteFieldView.setVisibility(View.GONE); + cardIdFieldView.setVisibility(View.GONE); } - if(cardIdField.getText().length() == 0) + if(cardIdFieldEdit.getText().length() == 0) { barcodeIdLayout.setVisibility(View.GONE); } barcodeTypeLayout.setVisibility(View.GONE); - if(cardIdField.getText().length() > 0 && barcodeTypeField.getText().length() > 0) + if(cardIdFieldEdit.getText().length() > 0 && barcodeTypeField.getText().length() > 0) { String formatString = barcodeTypeField.getText().toString(); final BarcodeFormat format = BarcodeFormat.valueOf(formatString); - final String cardIdString = cardIdField.getText().toString(); + final String cardIdString = cardIdFieldEdit.getText().toString(); if(barcodeImage.getHeight() == 0) { @@ -218,9 +231,9 @@ public void onClick(View v) @Override public void onClick(final View v) { - String store = storeField.getText().toString(); - String note = noteField.getText().toString(); - String cardId = cardIdField.getText().toString(); + String store = storeFieldEdit.getText().toString(); + String note = noteFieldEdit.getText().toString(); + String cardId = cardIdFieldEdit.getText().toString(); String barcodeType = barcodeTypeField.getText().toString(); if(store.isEmpty()) @@ -364,8 +377,13 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent) Log.i(TAG, "Read barcode id: " + contents); Log.i(TAG, "Read format: " + format); - final EditText cardIdField = (EditText) findViewById(R.id.cardId); - cardIdField.setText(contents); + for(TextView view : new TextView[]{ + (EditText) findViewById(R.id.cardIdEdit), + (TextView) findViewById(R.id.cardIdView)}) + { + view.setText(contents); + } + final EditText barcodeTypeField = (EditText) findViewById(R.id.barcodeType); barcodeTypeField.setText(format); onResume(); diff --git a/app/src/main/res/layout/loyalty_card_view_activity.xml b/app/src/main/res/layout/loyalty_card_view_activity.xml index c42b0213..4cfc1a80 100644 --- a/app/src/main/res/layout/loyalty_card_view_activity.xml +++ b/app/src/main/res/layout/loyalty_card_view_activity.xml @@ -29,79 +29,89 @@ android:layout_width="fill_parent" android:layout_height="wrap_content"> - - - - + + - - - - + + - - + android:inputType="text" + android:textSize="@dimen/text_size_medium"/> + - Date: Sat, 11 Feb 2017 22:32:45 -0500 Subject: [PATCH 2/2] Allow text to be selectable in view mode When text is long clicked it is now selectable, so that one can copy it to the clipboard. --- app/src/main/res/layout/loyalty_card_view_activity.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/loyalty_card_view_activity.xml b/app/src/main/res/layout/loyalty_card_view_activity.xml index 4cfc1a80..aeead689 100644 --- a/app/src/main/res/layout/loyalty_card_view_activity.xml +++ b/app/src/main/res/layout/loyalty_card_view_activity.xml @@ -51,7 +51,8 @@ android:layout_height="wrap_content" android:paddingTop="10dip" android:paddingBottom="10dip" - android:textSize="@dimen/text_size_medium"/> + android:textSize="@dimen/text_size_medium" + android:textIsSelectable="true"/> + android:textSize="@dimen/text_size_medium" + android:textIsSelectable="true"/> + android:textSize="@dimen/text_size_medium" + android:textIsSelectable="true"/>