From a7d764c0af259925f3eb0f24ed25559db4acf6ca Mon Sep 17 00:00:00 2001 From: Tangem Date: Thu, 7 Jun 2018 12:21:37 +0300 Subject: [PATCH] Updated on 2026-08-14 --- .../presentation/activity/PurgeActivity.java | 451 ++++++++---------- .../presentation/adapter/CardListAdapter.java | 2 +- .../presentation/fragment/LoadedWallet.java | 135 ++---- app/src/main/res/values/strings.xml | 31 +- 4 files changed, 287 insertions(+), 332 deletions(-) diff --git a/app/src/main/java/com/tangem/presentation/activity/PurgeActivity.java b/app/src/main/java/com/tangem/presentation/activity/PurgeActivity.java index a472fae5b7..ff7e2aba3b 100644 --- a/app/src/main/java/com/tangem/presentation/activity/PurgeActivity.java +++ b/app/src/main/java/com/tangem/presentation/activity/PurgeActivity.java @@ -17,71 +17,124 @@ import android.widget.Toast; import com.tangem.domain.cardReader.CardProtocol; import com.tangem.domain.cardReader.NfcManager; -import com.tangem.domain.wallet.TangemCard; -import com.tangem.util.Util; -import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog; import com.tangem.domain.wallet.PINStorage; -import com.tangem.wallet.R; +import com.tangem.domain.wallet.TangemCard; +import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog; import com.tangem.presentation.dialog.WaitSecurityDelayDialog; +import com.tangem.util.Util; +import com.tangem.wallet.R; public class PurgeActivity extends AppCompatActivity implements NfcAdapter.ReaderCallback, CardProtocol.Notifications { + public static final String TAG = PurgeActivity.class.getSimpleName(); public static final int RESULT_INVALID_PIN = Activity.RESULT_FIRST_USER; private TangemCard mCard; - private TextView tvCardID; private NfcManager mNfcManager; - private static final String logTag = "Purge"; private ProgressBar progressBar; private PurgeTask purgeTask; + private class PurgeTask extends Thread { + private String txOutAddress; + + IsoDep mIsoDep; + CardProtocol.Notifications mNotifications; + private boolean isCancelled = false; + + PurgeTask(IsoDep isoDep, CardProtocol.Notifications notifications) { + mIsoDep = isoDep; + mNotifications = notifications; + } + + @Override + public void run() { + if (mIsoDep == null) { + return; + } + CardProtocol protocol = new CardProtocol(getBaseContext(), mIsoDep, mCard, mNotifications); + + mNotifications.OnReadStart(protocol); + try { + + // for Samsung's bugs - Workaround for the Samsung Galaxy S5 (since the first connection always hangs on transceive). + int timeout = mIsoDep.getTimeout(); + mIsoDep.connect(); + mIsoDep.close(); + mIsoDep.connect(); + mIsoDep.setTimeout(timeout); + try { + mNotifications.OnReadProgress(protocol, 5); + + Log.i(TAG, "[-- Start purge --]"); + + if (isCancelled) return; + + if (mCard.getPauseBeforePIN2() > 0) { + mNotifications.OnReadWait(mCard.getPauseBeforePIN2()); + } + +// try { + protocol.run_PurgeWallet(PINStorage.getPIN2()); +// } finally { +// mNotifications.OnReadWait(0); +// } + + mNotifications.OnReadProgress(protocol, 50); + + protocol.run_Read(); + + mNotifications.OnReadProgress(protocol, 100); + + if (isCancelled) return; + + } finally { + mNfcManager.ignoreTag(mIsoDep.getTag()); + } + } catch (Exception e) { + e.printStackTrace(); + protocol.setError(e); + + } finally { + Log.i(TAG, "[-- Finish purge --]"); + mNotifications.OnReadFinish(protocol); + } + } + + public void cancel(Boolean AllowInterrupt) { + try { + if (this.isAlive()) { + isCancelled = true; + join(500); + } + if (this.isAlive() && AllowInterrupt) { + interrupt(); + mNotifications.OnReadCancel(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_purge); + mNfcManager = new NfcManager(this, this); + MainActivity.commonInit(getApplicationContext()); + TextView tvCardID = findViewById(R.id.tvCardID); + progressBar = findViewById(R.id.progressBar); + + tvCardID.setText(mCard.getCIDDescription()); + progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); + progressBar.setVisibility(View.INVISIBLE); + mCard = new TangemCard(getIntent().getStringExtra("UID")); mCard.LoadFromBundle(getIntent().getExtras().getBundle("Card")); - - tvCardID = findViewById(R.id.tvCardID); - tvCardID.setText(mCard.getCIDDescription()); - - mNfcManager = new NfcManager(this, this); - - progressBar = findViewById(R.id.progressBar); - progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); - progressBar.setVisibility(View.INVISIBLE); - } - - @Override - public void onTagDiscovered(Tag tag) { - try { - // get IsoDep handle and run cardReader thread - final IsoDep isoDep = IsoDep.get(tag); - if (isoDep == null) { - throw new CardProtocol.TangemException(getString(R.string.wrong_tag_err)); - } - byte UID[] = tag.getId(); - String sUID = Util.byteArrayToHexString(UID); - Log.v(logTag, "UID: " + sUID); - - if (sUID.equals(mCard.getUID())) { - isoDep.setTimeout(mCard.getPauseBeforePIN2() + 65000); - purgeTask = new PurgeTask(isoDep, this); - - purgeTask.start(); - } else { - Log.d(logTag, "Mismatch card UID (" + sUID + " instead of " + mCard.getUID() + ")"); - mNfcManager.ignoreTag(isoDep.getTag()); - return; - } - - } catch (Exception e) { - e.printStackTrace(); - } - } @Override @@ -109,214 +162,33 @@ public class PurgeActivity extends AppCompatActivity implements NfcAdapter.Reade super.onStop(); } -// @Override -// public Dialog CreateNFCDialog(int id, AlertDialogWrapper.Builder builder, LayoutInflater li) { -// return mNfcManager.onCreateDialog(id, builder, li); -// } + @Override + public void onTagDiscovered(Tag tag) { + try { + // get IsoDep handle and run cardReader thread + final IsoDep isoDep = IsoDep.get(tag); + if (isoDep == null) { + throw new CardProtocol.TangemException(getString(R.string.wrong_tag_err)); + } + byte UID[] = tag.getId(); + String sUID = Util.byteArrayToHexString(UID); + Log.v(TAG, "UID: " + sUID); - private class PurgeTask extends Thread { + if (sUID.equals(mCard.getUID())) { + isoDep.setTimeout(mCard.getPauseBeforePIN2() + 65000); + purgeTask = new PurgeTask(isoDep, this); - - private String txOutAddress; - - IsoDep mIsoDep; - CardProtocol.Notifications mNotifications; - private boolean isCancelled = false; - - public PurgeTask(IsoDep isoDep, CardProtocol.Notifications notifications) { - mIsoDep = isoDep; - mNotifications = notifications; - } - - @Override - public void run() { - if (mIsoDep == null) { + purgeTask.start(); + } else { + Log.d(TAG, "Mismatch card UID (" + sUID + " instead of " + mCard.getUID() + ")"); + mNfcManager.ignoreTag(isoDep.getTag()); return; } - CardProtocol protocol = new CardProtocol(getBaseContext(), mIsoDep, mCard, mNotifications); - mNotifications.OnReadStart(protocol); - try { - - // for Samsung's bugs - - // Workaround for the Samsung Galaxy S5 (since the - // first connection always hangs on transceive). - int timeout = mIsoDep.getTimeout(); - mIsoDep.connect(); - mIsoDep.close(); - mIsoDep.connect(); - mIsoDep.setTimeout(timeout); - try { - - mNotifications.OnReadProgress(protocol, 5); - - Log.i("PurgeTask", "[-- Start purge --]"); - - if (isCancelled) return; - - if (mCard.getPauseBeforePIN2() > 0) { - mNotifications.OnReadWait(mCard.getPauseBeforePIN2()); - } - -// try { - protocol.run_PurgeWallet(PINStorage.getPIN2()); -// } finally { -// mNotifications.OnReadWait(0); -// } - - mNotifications.OnReadProgress(protocol, 50); - - protocol.run_Read(); - - mNotifications.OnReadProgress(protocol, 100); - - if (isCancelled) return; - - } finally { - mNfcManager.ignoreTag(mIsoDep.getTag()); - } - } catch (Exception e) { - e.printStackTrace(); - protocol.setError(e); - - } finally { - Log.i("PurgeTask", "[-- Finish purge --]"); - mNotifications.OnReadFinish(protocol); - } + } catch (Exception e) { + e.printStackTrace(); } - public void cancel(Boolean AllowInterrupt) { - try { - if (this.isAlive()) { - isCancelled = true; - join(500); - } - if (this.isAlive() && AllowInterrupt) { - interrupt(); - mNotifications.OnReadCancel(); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - } - - - public void OnReadStart(CardProtocol cardProtocol) { - progressBar.post(new Runnable() { - @Override - public void run() { - progressBar.setVisibility(View.VISIBLE); - progressBar.setProgress(5); - } - }); - } - - public void OnReadFinish(final CardProtocol cardProtocol) { - - purgeTask = null; - - if (cardProtocol != null) { - if (cardProtocol.getError() == null) { - progressBar.post(new Runnable() { - @Override - public void run() { - progressBar.setProgress(100); - progressBar.setProgressTintList(ColorStateList.valueOf(Color.GREEN)); - Intent intent = new Intent(); - intent.putExtra("UID", cardProtocol.getCard().getUID()); - intent.putExtra("Card", cardProtocol.getCard().getAsBundle()); - setResult(Activity.RESULT_OK, intent); - finish(); - } - }); - } else { - if (cardProtocol.getError() instanceof CardProtocol.TangemException_InvalidPIN) { - progressBar.post(new Runnable() { - @Override - public void run() { - progressBar.setProgress(100); - progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED)); - } - }); - progressBar.postDelayed(new Runnable() { - @Override - public void run() { - try { - progressBar.setProgress(0); - progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); - progressBar.setVisibility(View.INVISIBLE); - Intent intent = new Intent(); - intent.putExtra("UID", cardProtocol.getCard().getUID()); - intent.putExtra("Card", cardProtocol.getCard().getAsBundle()); - intent.putExtra("message", "Cannot erase wallet. Make sure you enter correct PIN2!"); - setResult(RESULT_INVALID_PIN, intent); - finish(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }, 500); - return; - } else { - progressBar.post(new Runnable() { - @Override - public void run() { - if (cardProtocol.getError() instanceof CardProtocol.TangemException_ExtendedLengthNotSupported) { - if (!NoExtendedLengthSupportDialog.allreadyShowed) { - new NoExtendedLengthSupportDialog().show(getFragmentManager(), "NoExtendedLengthSupportDialog"); - } - } else { - Toast.makeText(getBaseContext(), "Try to scan again", Toast.LENGTH_LONG).show(); - } - progressBar.setProgress(100); - progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED)); - } - }); - } - } - } - - progressBar.postDelayed(new Runnable() { - @Override - public void run() { - try { - progressBar.setProgress(0); - progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); - progressBar.setVisibility(View.INVISIBLE); - } catch (Exception e) { - e.printStackTrace(); - } - } - }, 500); - } - - public void OnReadProgress(CardProtocol protocol, final int progress) { - progressBar.post(new Runnable() { - @Override - public void run() { - progressBar.setProgress(progress); - } - }); - } - - public void OnReadCancel() { - - purgeTask = null; - - progressBar.postDelayed(new Runnable() { - @Override - public void run() { - try { - progressBar.setProgress(0); - progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); - progressBar.setVisibility(View.INVISIBLE); - } catch (Exception e) { - e.printStackTrace(); - } - } - }, 500); } @Override @@ -334,5 +206,92 @@ public class PurgeActivity extends AppCompatActivity implements NfcAdapter.Reade WaitSecurityDelayDialog.onReadAfterRequest(this); } -} + public void OnReadStart(CardProtocol cardProtocol) { + progressBar.post(() -> { + progressBar.setVisibility(View.VISIBLE); + progressBar.setProgress(5); + }); + } + public void OnReadFinish(final CardProtocol cardProtocol) { + + purgeTask = null; + + if (cardProtocol != null) { + if (cardProtocol.getError() == null) { + progressBar.post(() -> { + progressBar.setProgress(100); + progressBar.setProgressTintList(ColorStateList.valueOf(Color.GREEN)); + Intent intent = new Intent(); + intent.putExtra("UID", cardProtocol.getCard().getUID()); + intent.putExtra("Card", cardProtocol.getCard().getAsBundle()); + setResult(Activity.RESULT_OK, intent); + finish(); + }); + } else { + if (cardProtocol.getError() instanceof CardProtocol.TangemException_InvalidPIN) { + progressBar.post(() -> { + progressBar.setProgress(100); + progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED)); + }); + progressBar.postDelayed(() -> { + try { + progressBar.setProgress(0); + progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); + progressBar.setVisibility(View.INVISIBLE); + Intent intent = new Intent(); + intent.putExtra("UID", cardProtocol.getCard().getUID()); + intent.putExtra("Card", cardProtocol.getCard().getAsBundle()); + intent.putExtra("message", getString(R.string.cannot_erase_wallet)); + setResult(RESULT_INVALID_PIN, intent); + finish(); + } catch (Exception e) { + e.printStackTrace(); + } + }, 500); + return; + } else { + progressBar.post(() -> { + if (cardProtocol.getError() instanceof CardProtocol.TangemException_ExtendedLengthNotSupported) { + if (!NoExtendedLengthSupportDialog.allreadyShowed) { + new NoExtendedLengthSupportDialog().show(getFragmentManager(), NoExtendedLengthSupportDialog.TAG); + } + } else + Toast.makeText(getBaseContext(), R.string.try_to_scan_again, Toast.LENGTH_LONG).show(); + + progressBar.setProgress(100); + progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED)); + }); + } + } + } + + progressBar.postDelayed(() -> { + try { + progressBar.setProgress(0); + progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); + progressBar.setVisibility(View.INVISIBLE); + } catch (Exception e) { + e.printStackTrace(); + } + }, 500); + } + + public void OnReadProgress(CardProtocol protocol, final int progress) { + progressBar.post(() -> progressBar.setProgress(progress)); + } + + public void OnReadCancel() { + purgeTask = null; + progressBar.postDelayed(() -> { + try { + progressBar.setProgress(0); + progressBar.setProgressTintList(ColorStateList.valueOf(Color.DKGRAY)); + progressBar.setVisibility(View.INVISIBLE); + } catch (Exception e) { + e.printStackTrace(); + } + }, 500); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/tangem/presentation/adapter/CardListAdapter.java b/app/src/main/java/com/tangem/presentation/adapter/CardListAdapter.java index 3683278963..69f2d4d63d 100644 --- a/app/src/main/java/com/tangem/presentation/adapter/CardListAdapter.java +++ b/app/src/main/java/com/tangem/presentation/adapter/CardListAdapter.java @@ -305,7 +305,7 @@ public class CardListAdapter extends RecyclerView.Adapter PINSwapWarningDialog.this.dismiss()) + .setPositiveButton(R.string.contin, + (dialog, whichButton) -> { + if (activityFragment != null) + activityFragment.startSwapPINActivity(); } ) .create(); @@ -650,7 +644,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } try { - ivQR.setImageBitmap(generateQrCode(engine.getShareWalletURI(mCard).toString())); + ivQR.setImageBitmap(generateQrCode(Objects.requireNonNull(engine).getShareWalletURI(mCard).toString())); } catch (WriterException e) { e.printStackTrace(); } @@ -664,7 +658,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } CoinEngine engineClick = CoinEngineFactory.Create(mCard.getBlockchain()); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, engineClick.getShareWalletURIExplorer(mCard)); + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Objects.requireNonNull(engineClick).getShareWalletURIExplorer(mCard)); startActivity(browserIntent); }); @@ -677,7 +671,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } CoinEngine engineClick = CoinEngineFactory.Create(mCard.getBlockchain()); - Intent browserIntent = new Intent(Intent.ACTION_VIEW, engineClick.getShareWalletURIExplorer(mCard)); + Intent browserIntent = new Intent(Intent.ACTION_VIEW, Objects.requireNonNull(engineClick).getShareWalletURIExplorer(mCard)); startActivity(browserIntent); }); } @@ -686,7 +680,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre tvSend.setOnClickListener(v13 -> { if (!mCard.hasBalanceInfo()) { return; - } else if (!engine.IsBalanceNotZero(mCard)) { + } else if (!Objects.requireNonNull(engine).IsBalanceNotZero(mCard)) { Toast.makeText(getContext(), R.string.wallet_empty, Toast.LENGTH_LONG).show(); return; } else if (!engine.IsBalanceAlterNotZero(mCard)) { @@ -710,10 +704,8 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre }); } - tvPurge.setOnClickListener(v16 -> showMenu(tvPurge)); - updateViews(); if (!mCard.hasBalanceInfo()) { @@ -751,7 +743,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre case REQUEST_CODE_ENTER_NEW_PIN: if (resultCode == Activity.RESULT_OK) { if (data != null) { - if (data.getExtras().containsKey("confirmPIN")) { + if (Objects.requireNonNull(data.getExtras()).containsKey("confirmPIN")) { Intent intent = new Intent(getContext(), RequestPINActivity.class); intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString()); intent.putExtra("UID", mCard.getUID()); @@ -770,7 +762,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre case REQUEST_CODE_ENTER_NEW_PIN2: if (resultCode == Activity.RESULT_OK) { if (data != null) { - if (data.getExtras().containsKey("confirmPIN2")) { + if (Objects.requireNonNull(data.getExtras()).containsKey("confirmPIN2")) { Intent intent = new Intent(getContext(), RequestPINActivity.class); intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString()); intent.putExtra("UID", mCard.getUID()); @@ -788,21 +780,19 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre break; case REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN: if (resultCode == Activity.RESULT_OK) { - if (newPIN.equals("")) { + if (newPIN.equals("")) newPIN = mCard.getPIN(); - } - if (newPIN2.equals("")) { + + if (newPIN2.equals("")) newPIN2 = PINStorage.getPIN2(); - } PINSwapWarningDialog dialog = (new PINSwapWarningDialog()); dialog.activityFragment = this; - if (!PINStorage.isDefaultPIN(newPIN) || !PINStorage.isDefaultPIN2(newPIN2)) { - dialog.message = "If you forget your new PIN you will lose your money forever!"; - } else { - dialog.message = "If you use default PIN someone can steal your money!"; - } - dialog.show(getActivity().getFragmentManager(), "PINSwapWarningDialog"); + if (!PINStorage.isDefaultPIN(newPIN) || !PINStorage.isDefaultPIN2(newPIN2)) + dialog.message = getString(R.string.if_you_forget); + else + dialog.message = getString(R.string.if_you_use_default); + dialog.show(Objects.requireNonNull(getActivity()).getFragmentManager(), PINSwapWarningDialog.TAG); } break; @@ -912,8 +902,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } public void onRefresh() { - //Update - // Showing refresh animation before making http call + // update, showing refresh animation before making http call if (updateTasks.size() > 0) return; mSwipeRefreshLayout.setRefreshing(true); @@ -1050,7 +1039,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } public void ErrorOnUpdate(String message) { - mCard.setError("Cannot obtain data from blockchain"); + mCard.setError(getString(R.string.cannot_obtain_data_from_blockchain)); updateViews(); } @@ -1087,7 +1076,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre new NoExtendedLengthSupportDialog().show(getActivity().getFragmentManager(), "NoExtendedLengthSupportDialog"); } } else { - Toast.makeText(getContext(), "Try to scan again", Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), R.string.try_to_scan_again, Toast.LENGTH_LONG).show(); } progressBar.setProgress(100); progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED)); @@ -1251,7 +1240,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre if (!mCard.hasBalanceInfo()) { return; } else if (engine.IsBalanceNotZero(mCard)) { - Toast.makeText(getContext(), "Cannot erase wallet with non-zero balance", Toast.LENGTH_LONG).show(); + Toast.makeText(getContext(), R.string.cannot_erase_wallet_with_non_zero_balance, Toast.LENGTH_LONG).show(); return; } @@ -1285,7 +1274,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre tvMessage.setVisibility(View.GONE); } else { if (needResendTX) { - tvMessage.setText("Sending cached transaction..."); + tvMessage.setText(R.string.sending_cached_transaction); } else { tvMessage.setText(mCard.getMessage()); } @@ -1307,7 +1296,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } else { String offlineAmount = engine.ConvertByteArrayToAmount(mCard, mCard.getOfflineBalance()); if (mCard.getBlockchain() == Blockchain.Token) { - tvBalance.setText("NOT IMPLEMENTED"); + tvBalance.setText(R.string.not_implemented); } else { tvBalance.setText(engine.GetAmountDescription(mCard, offlineAmount)); } @@ -1352,10 +1341,10 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre if (mCard.useDefaultPIN1()) { ivPIN.setImageResource(R.drawable.unlock_pin1); - ivPIN.setOnClickListener(v -> Toast.makeText(getContext(), "This banknote is protected by default PIN1 code", Toast.LENGTH_LONG).show()); + ivPIN.setOnClickListener(v -> Toast.makeText(getContext(), R.string.this_banknote_protected_default_PIN1_code, Toast.LENGTH_LONG).show()); } else { ivPIN.setImageResource(R.drawable.lock_pin1); - ivPIN.setOnClickListener(v -> Toast.makeText(getContext(), "This banknote is protected by user's PIN1 code", Toast.LENGTH_LONG).show()); + ivPIN.setOnClickListener(v -> Toast.makeText(getContext(), R.string.this_banknote_protected_user_PIN1_code, Toast.LENGTH_LONG).show()); } if (mCard.getPauseBeforePIN2() > 0 && (mCard.useDefaultPIN2() || !mCard.useSmartSecurityDelay())) { @@ -1364,57 +1353,36 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } else if (mCard.useDefaultPIN2()) { ivPIN2orSecurityDelay.setImageResource(R.drawable.unlock_pin2); - ivPIN2orSecurityDelay.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(getContext(), "This banknote is protected by default PIN2 code", Toast.LENGTH_LONG).show(); - } - }); + ivPIN2orSecurityDelay.setOnClickListener(v -> Toast.makeText(getContext(), R.string.this_banknote_protected_default_PIN2_code, Toast.LENGTH_LONG).show()); } else { ivPIN2orSecurityDelay.setImageResource(R.drawable.lock_pin2); - ivPIN2orSecurityDelay.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(getContext(), "This banknote is protected by user's PIN2 code", Toast.LENGTH_LONG).show(); - } - }); + ivPIN2orSecurityDelay.setOnClickListener(v -> Toast.makeText(getContext(), R.string.this_banknote_protected_user_PIN2_code, Toast.LENGTH_LONG).show()); } - if (mCard.useDevelopersFirmware()) { ivDeveloperVersion.setImageResource(R.drawable.ic_developer_version); ivDeveloperVersion.setVisibility(View.VISIBLE); - ivDeveloperVersion.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(getContext(), "Unlocked banknote, only for development use", Toast.LENGTH_LONG).show(); - } - }); + ivDeveloperVersion.setOnClickListener(v -> Toast.makeText(getContext(), R.string.unlocked_banknote_only_development_use, Toast.LENGTH_LONG).show()); } else { ivDeveloperVersion.setVisibility(View.INVISIBLE); } - if (tvSend != null) { - if (mCard.hasBalanceInfo()) { + if (tvSend != null) + if (mCard.hasBalanceInfo()) tvSend.setEnabled(true); - } else { + else tvSend.setEnabled(false); - } - } - if (tvPurge != null) { - if (mCard.hasBalanceInfo()) { + if (tvPurge != null) + if (mCard.hasBalanceInfo()) tvPurge.setEnabled(true); - } else { + else tvPurge.setEnabled(false); - } - } tvIssuer.setText(mCard.getIssuerDescription()); timerHideErrorAndMessage = new Timer(); - timerHideErrorAndMessage.schedule(new TimerTask() { @Override public void run() { @@ -1428,20 +1396,20 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre }, 5000); if (mCard.isReusable()) { - tvHeader.setText("REUSABLE WALLET"); + tvHeader.setText(R.string.reusable_wallet); tvCaution.setVisibility(View.GONE); } else { if (mCard.getMaxSignatures() == mCard.getRemainingSignatures()) { - tvHeader.setText("BANKNOTE"); + tvHeader.setText(R.string.banknote); tvCaution.setVisibility(View.GONE); } else { - tvHeader.setText("NON-TRANSFERABLE BANKNOTE"); + tvHeader.setText(R.string.not_transferable_banknote); tvCaution.setVisibility(View.VISIBLE); } } if (mCard.useDevelopersFirmware()) { - tvHeader.setText("DEVELOPER KIT"); + tvHeader.setText(R.string.developer_kit); tvCaution.setVisibility(View.VISIBLE); } @@ -1459,13 +1427,14 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre intent.putExtra(Intent.EXTRA_SUBJECT, "Wallet address"); intent.putExtra(Intent.EXTRA_TEXT, txtShare); - PackageManager packageManager = getActivity().getPackageManager(); + PackageManager packageManager = Objects.requireNonNull(getActivity()).getPackageManager(); List activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_ALL); boolean isIntentSafe = activities.size() > 0; if (isIntentSafe) { - String title = "Share wallet address with:"; - // Create intent to show chooser + String title = getString(R.string.share_wallet_address_with); + + // create intent to show chooser Intent chooser = Intent.createChooser(intent, title); // Verify the intent will resolve to at least one activity if (intent.resolveActivity(getActivity().getPackageManager()) != null) { @@ -1473,14 +1442,14 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } } else { ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); - clipboard.setPrimaryClip(ClipData.newPlainText(txtShare, txtShare)); - Toast.makeText(getContext(), "Copied to clipboard", Toast.LENGTH_LONG).show(); + Objects.requireNonNull(clipboard).setPrimaryClip(ClipData.newPlainText(txtShare, txtShare)); + Toast.makeText(getContext(), R.string.copied_clipboard, Toast.LENGTH_LONG).show(); } } else { String txtShare = mCard.getWallet(); - ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(CLIPBOARD_SERVICE); - clipboard.setPrimaryClip(ClipData.newPlainText(txtShare, txtShare)); - Toast.makeText(getContext(), "Copied to clipboard", Toast.LENGTH_LONG).show(); + ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(getActivity()).getSystemService(CLIPBOARD_SERVICE); + Objects.requireNonNull(clipboard).setPrimaryClip(ClipData.newPlainText(txtShare, txtShare)); + Toast.makeText(getContext(), R.string.copied_clipboard, Toast.LENGTH_LONG).show(); } } @@ -1517,7 +1486,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre } private static Bitmap generateQrCode(String myCodeText) throws WriterException { - Hashtable hintMap = new Hashtable(); + Hashtable hintMap = new Hashtable<>(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // H = 30% damage QRCodeWriter qrCodeWriter = new QRCodeWriter(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65499d2d8e..553643a8e0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,8 @@ OK + Cancel + Continue Not found Not ISO tag! Card must be loaded first! @@ -34,12 +36,15 @@ verified offline Blockchain Last withdrawal + Try to scan again + Cannot erase wallet with non-zero balance Your Android device is rooted. Security at risk! Got it Warning The NFC adapter of the device does not support extended length APDU, it\'s possible that some functions will not work! + Your money is at risk! Clean up @@ -59,7 +64,6 @@ Tap Tangem card with your smartphone Scan a banknote with your \n smartphone as shown above - Try to scan again Wallet Last unspent @@ -68,7 +72,7 @@ ERASED WALLET INVALID CARD -            DEVELOPER     KIT      +            DEVELOPER     KIT        BANKNOTE        BANKNOTE    REUSABLE       REUSABLE    @@ -78,7 +82,10 @@ Please wait while previous transaction is confirmed in blockchain Please wait for confirmation of incoming transaction! Card hasn\'t remaining signature! + REUSABLE WALLET BANKNOTE + NON-TRANSFERABLE BANKNOTE + DEVELOPER KIT DO NOT ACCEPT EXPLORE IN \n BLOCKCHAIN \n ON WEB Unspents @@ -89,6 +96,18 @@ Error! Scan again to verify the card SEND + If you forget your new PIN you will lose your money forever! + If you use default PIN someone can steal your money! + Cannot obtain data from blockchain + Sending cached transaction… + NOT IMPLEMENTED + This banknote is protected by default PIN1 code + This banknote is protected by user\'s PIN1 code + This banknote is protected by default PIN2 code + This banknote is protected by user\'s PIN2 code + Unlocked banknote, only for development use + Share wallet address with: + Copied to clipboard BETA @@ -119,6 +138,14 @@ Please wait while the payment is sent… + + Cannot erase wallet. Make sure you enter correct PIN2! + + + + + +