Updated on 2026-08-14
This commit is contained in:
parent
ec39d1a437
commit
c9ffcd0e22
8 changed files with 529 additions and 256 deletions
|
|
@ -245,7 +245,7 @@ public class CreateNewWalletActivity extends AppCompatActivity implements NfcAda
|
|||
new NoExtendedLengthSupportDialog().show(getFragmentManager(), NoExtendedLengthSupportDialog.TAG);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getBaseContext(), R.string.try_to_scan_again, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getBaseContext(), R.string.try_to_scan_again, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
progressBar.setProgress(100);
|
||||
progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ public class SwapPINActivity extends AppCompatActivity implements NfcAdapter.Rea
|
|||
new NoExtendedLengthSupportDialog().show(getFragmentManager(), NoExtendedLengthSupportDialog.TAG);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getBaseContext(), R.string.try_to_scan_again, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getBaseContext(), R.string.try_to_scan_again, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
progressBar.setProgress(100);
|
||||
progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import android.content.ClipboardManager;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.nfc.Tag;
|
||||
|
|
@ -15,6 +14,7 @@ import android.nfc.tech.IsoDep;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
|
@ -24,21 +24,14 @@ import android.text.Html;
|
|||
import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.WriterException;
|
||||
import com.google.zxing.common.BitMatrix;
|
||||
import com.google.zxing.qrcode.QRCodeWriter;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.data.network.request.ExchangeRequest;
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
|
|
@ -68,7 +61,7 @@ import com.tangem.presentation.dialog.PINSwapWarningDialog;
|
|||
import com.tangem.presentation.dialog.WaitSecurityDelayDialog;
|
||||
import com.tangem.util.BTCUtils;
|
||||
import com.tangem.util.Util;
|
||||
import com.tangem.wallet.BuildConfig;
|
||||
import com.tangem.util.UtilHelper;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
|
@ -77,7 +70,7 @@ import org.json.JSONObject;
|
|||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Timer;
|
||||
|
|
@ -89,9 +82,10 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
public static final String TAG = LoadedWallet.class.getSimpleName();
|
||||
|
||||
private static final int REQUEST_CODE_SEND_PAYMENT = 1;
|
||||
private static final int REQUEST_CODE_VERIFY_CARD = 4;
|
||||
|
||||
private static final int REQUEST_CODE_PURGE = 2;
|
||||
private static final int REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = 3;
|
||||
private static final int REQUEST_CODE_VERIFY_CARD = 4;
|
||||
private static final int REQUEST_CODE_ENTER_NEW_PIN = 5;
|
||||
private static final int REQUEST_CODE_ENTER_NEW_PIN2 = 6;
|
||||
private static final int REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN = 7;
|
||||
|
|
@ -129,7 +123,8 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
private Timer timerHideErrorAndMessage = null;
|
||||
private String newPIN = "", newPIN2 = "";
|
||||
private AppCompatButton btnExtract;
|
||||
private FloatingActionButton fabPurge, fabNFC;
|
||||
private FloatingActionButton fabInfo;
|
||||
private Tag lastTag;
|
||||
|
||||
public LoadedWallet() {
|
||||
|
||||
|
|
@ -163,7 +158,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
}
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_Call)) {
|
||||
try {
|
||||
|
|
@ -191,7 +186,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
}
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_GetOutTransactionCount)) {
|
||||
try {
|
||||
|
|
@ -215,7 +210,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
JSONObject err = msg.getJSONObject("error");
|
||||
hashTX = err.getString("message");
|
||||
LastSignStorage.setLastMessage(mCard.getWallet(), hashTX);
|
||||
ErrorOnUpdate("Failed to send transaction. Try again");
|
||||
errorOnUpdate("Failed to send transaction. Try again");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -235,16 +230,16 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate("Failed to send transaction. Try again");
|
||||
errorOnUpdate("Failed to send transaction. Try again");
|
||||
}
|
||||
}
|
||||
updateViews();
|
||||
} else {
|
||||
ErrorOnUpdate(request.error);
|
||||
errorOnUpdate(request.error);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -351,12 +346,12 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter >= sharedCounter.allRequest) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
}
|
||||
|
|
@ -376,12 +371,12 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
} catch (Exception e) {
|
||||
engine.SwitchNode(mCard);
|
||||
ErrorOnUpdate("Failed to send transaction. Try again.");
|
||||
errorOnUpdate("Failed to send transaction. Try again.");
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate("Failed to send transaction. Try again.");
|
||||
errorOnUpdate("Failed to send transaction. Try again.");
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_ListUnspent)) {
|
||||
|
|
@ -401,7 +396,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
|
||||
|
|
@ -422,7 +417,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetHistory)) {
|
||||
|
|
@ -441,7 +436,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
|
||||
|
|
@ -463,7 +458,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
} else if (request.isMethod(ElectrumRequest.METHOD_GetHeader)) {
|
||||
|
|
@ -476,14 +471,14 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
jsHeader.getInt("timestamp")));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
|
||||
}
|
||||
|
|
@ -520,7 +515,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
tx.isInput = !isOur;
|
||||
} catch (BitcoinException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
}
|
||||
Log.e("TX", raw);
|
||||
}
|
||||
|
|
@ -528,7 +523,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
engine.SwitchNode(mCard);
|
||||
}
|
||||
}
|
||||
|
|
@ -537,12 +532,12 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
if (sharedCounter != null) {
|
||||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter >= sharedCounter.allRequest) {
|
||||
ErrorOnUpdate(request.error);
|
||||
errorOnUpdate(request.error);
|
||||
engine.SwitchNode(mCard);
|
||||
|
||||
}
|
||||
} else {
|
||||
ErrorOnUpdate(request.error);
|
||||
errorOnUpdate(request.error);
|
||||
engine.SwitchNode(mCard);
|
||||
|
||||
}
|
||||
|
|
@ -553,11 +548,11 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
int errCounter = sharedCounter.errorRequest.incrementAndGet();
|
||||
if (errCounter >= sharedCounter.allRequest) {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
}
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
errorOnUpdate(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -566,12 +561,22 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mNfcManager = new NfcManager(getActivity(), this);
|
||||
|
||||
mCard = new TangemCard(Objects.requireNonNull(getActivity()).getIntent().getStringExtra(TangemCard.EXTRA_CARD));
|
||||
mCard.LoadFromBundle(Objects.requireNonNull(getActivity().getIntent().getExtras()).getBundle(TangemCard.EXTRA_CARD));
|
||||
|
||||
lastTag = getActivity().getIntent().getParcelableExtra("lastTag123");
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fr_loaded_wallet, container, false);
|
||||
|
||||
mNfcManager = new NfcManager(getActivity(), this);
|
||||
|
||||
mSwipeRefreshLayout = v.findViewById(R.id.swipe_container);
|
||||
tvBalance = v.findViewById(R.id.tvBalance);
|
||||
tvOffline = v.findViewById(R.id.tvOffline);
|
||||
|
|
@ -596,18 +601,14 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
ivPIN2orSecurityDelay = v.findViewById(R.id.imgPIN2orSecurityDelay);
|
||||
ivDeveloperVersion = v.findViewById(R.id.imgDeveloperVersion);
|
||||
ImageView ivQR = v.findViewById(R.id.qrWallet);
|
||||
|
||||
fabPurge = v.findViewById(R.id.fabPurge);
|
||||
fabNFC = v.findViewById(R.id.fabNFC);
|
||||
fabInfo = v.findViewById(R.id.fabInfo);
|
||||
FloatingActionButton fabNFC = v.findViewById(R.id.fabNFC);
|
||||
AppCompatButton btnLoad = v.findViewById(R.id.btnLoad);
|
||||
btnExtract = v.findViewById(R.id.btnExtract);
|
||||
tvBalanceEquivalent = v.findViewById(R.id.tvBalanceEquivalent);
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
mCard = new TangemCard(Objects.requireNonNull(getActivity()).getIntent().getStringExtra(TangemCard.EXTRA_CARD));
|
||||
mCard.LoadFromBundle(Objects.requireNonNull(getActivity().getIntent().getExtras()).getBundle(TangemCard.EXTRA_CARD));
|
||||
|
||||
if (mCard.getBlockchain() == Blockchain.Token)
|
||||
tvBalance.setSingleLine(false);
|
||||
|
||||
|
|
@ -621,7 +622,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
// tvLastOutput.setVisibility(visibleIOPuts);
|
||||
|
||||
try {
|
||||
ivQR.setImageBitmap(generateQrCode(Objects.requireNonNull(engine).getShareWalletURI(mCard).toString()));
|
||||
ivQR.setImageBitmap(UtilHelper.INSTANCE.generateQrCode(Objects.requireNonNull(engine).getShareWalletURI(mCard).toString()));
|
||||
} catch (WriterException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -658,7 +659,16 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
);
|
||||
|
||||
fabPurge.setOnClickListener(v16 -> showMenu(fabPurge));
|
||||
fabInfo.setOnClickListener(v16 -> {
|
||||
if (mCardProtocol != null)
|
||||
openVerifyCard(mCardProtocol);
|
||||
else {
|
||||
scanTimes++;
|
||||
Toast.makeText(getContext(), R.string.need_attach_card_again, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
startVerify(lastTag);
|
||||
|
||||
fabNFC.setOnClickListener(view -> {
|
||||
Intent intent = new Intent(getContext(), MainActivity.class);
|
||||
|
|
@ -695,6 +705,14 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
return v;
|
||||
}
|
||||
|
||||
private void openVerifyCard(CardProtocol cardProtocol) {
|
||||
Intent intent = new Intent(getContext(), VerifyCardActivity.class);
|
||||
// // TODO обновить карту mCard
|
||||
intent.putExtra("UID", cardProtocol.getCard().getUID());
|
||||
intent.putExtra("Card", cardProtocol.getCard().getAsBundle());
|
||||
startActivityForResult(intent, REQUEST_CODE_VERIFY_CARD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -829,7 +847,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
} else {
|
||||
data.putExtra("modification", "update");
|
||||
}
|
||||
getActivity().setResult(Activity.RESULT_OK, data);
|
||||
Objects.requireNonNull(getActivity()).setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
} else {
|
||||
if (data != null && data.getExtras().containsKey("UID") && data.getExtras().containsKey("Card")) {
|
||||
|
|
@ -855,7 +873,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
break;
|
||||
case REQUEST_CODE_SEND_PAYMENT:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
mSwipeRefreshLayout.postDelayed(this::onRefresh, 10000);
|
||||
// mSwipeRefreshLayout.postDelayed(this::onRefresh, 10000);
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
mCard.clearInfo();
|
||||
updateViews();
|
||||
|
|
@ -881,6 +899,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
// update, showing refresh animation before making http call
|
||||
if (updateTasks.size() > 0) return;
|
||||
|
|
@ -910,7 +929,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
UpdateWalletInfoTask updateWalletInfoTask = new UpdateWalletInfoTask(nodeAddress, nodePort, data);
|
||||
updateTasks.add(updateWalletInfoTask);
|
||||
updateWalletInfoTask.execute(ElectrumRequest.ListUnspent(mCard.getWallet())
|
||||
,ElectrumRequest.ListHistory(mCard.getWallet())
|
||||
, ElectrumRequest.ListHistory(mCard.getWallet())
|
||||
);
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
|
|
@ -933,7 +952,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
updateTasks.add(updateWalletInfoTask);
|
||||
updateWalletInfoTask.execute(ElectrumRequest.ListUnspent(mCard.getWallet())
|
||||
,ElectrumRequest.ListHistory(mCard.getWallet())
|
||||
, ElectrumRequest.ListHistory(mCard.getWallet())
|
||||
);
|
||||
|
||||
RateInfoTask taskRate = new RateInfoTask();
|
||||
|
|
@ -986,6 +1005,10 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
@Override
|
||||
public void onTagDiscovered(Tag tag) {
|
||||
startVerify(tag);
|
||||
}
|
||||
|
||||
private void startVerify(Tag tag) {
|
||||
try {
|
||||
final IsoDep isoDep = IsoDep.get(tag);
|
||||
if (isoDep == null) {
|
||||
|
|
@ -1010,6 +1033,8 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
verifyCardTask = new VerifyCardTask(getContext(), mCard, mNfcManager, isoDep, this);
|
||||
verifyCardTask.start();
|
||||
|
||||
Log.i(TAG, "onTagDiscovered " + Arrays.toString(tag.getId()));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
@ -1022,12 +1047,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
return data;
|
||||
}
|
||||
|
||||
public void ErrorOnUpdate(String message) {
|
||||
mCard.setError(getString(R.string.cannot_obtain_data_from_blockchain));
|
||||
updateViews();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void OnReadStart(CardProtocol cardProtocol) {
|
||||
progressBar.post(() -> {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
|
|
@ -1035,8 +1055,13 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
});
|
||||
}
|
||||
|
||||
public void OnReadFinish(final CardProtocol cardProtocol) {
|
||||
private CardProtocol mCardProtocol;
|
||||
|
||||
// private boolean needOpenVerify;
|
||||
private int scanTimes = 0;
|
||||
|
||||
@Override
|
||||
public void OnReadFinish(final CardProtocol cardProtocol) {
|
||||
verifyCardTask = null;
|
||||
|
||||
if (cardProtocol != null) {
|
||||
|
|
@ -1044,11 +1069,16 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
progressBar.post(() -> {
|
||||
progressBar.setProgress(100);
|
||||
progressBar.setProgressTintList(ColorStateList.valueOf(Color.GREEN));
|
||||
Intent intent = new Intent(getContext(), VerifyCardActivity.class);
|
||||
// TODO обновить карту mCard
|
||||
intent.putExtra("UID", cardProtocol.getCard().getUID());
|
||||
intent.putExtra("Card", cardProtocol.getCard().getAsBundle());
|
||||
startActivityForResult(intent, REQUEST_CODE_VERIFY_CARD);
|
||||
|
||||
mCardProtocol = cardProtocol;
|
||||
|
||||
Log.i(TAG, "scanTimes " + scanTimes);
|
||||
if (scanTimes > 0)
|
||||
openVerifyCard(mCardProtocol);
|
||||
|
||||
scanTimes++;
|
||||
|
||||
|
||||
//addCard(cardProtocol.getCard());
|
||||
});
|
||||
} else {
|
||||
|
|
@ -1060,7 +1090,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
new NoExtendedLengthSupportDialog().show(Objects.requireNonNull(getActivity()).getFragmentManager(), NoExtendedLengthSupportDialog.TAG);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getContext(), R.string.try_to_scan_again, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getContext(), R.string.try_to_scan_again, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
progressBar.setProgress(100);
|
||||
progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));
|
||||
|
|
@ -1079,14 +1109,14 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnReadProgress(CardProtocol protocol, final int progress) {
|
||||
progressBar.post(() -> progressBar.setProgress(progress));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnReadCancel() {
|
||||
|
||||
verifyCardTask = null;
|
||||
|
||||
progressBar.postDelayed(() -> {
|
||||
try {
|
||||
progressBar.setProgress(0);
|
||||
|
|
@ -1098,141 +1128,19 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}, 500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnReadWait(int msec) {
|
||||
WaitSecurityDelayDialog.OnReadWait(getActivity(), msec);
|
||||
WaitSecurityDelayDialog.OnReadWait(Objects.requireNonNull(getActivity()), msec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnReadBeforeRequest(int timeout) {
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(getActivity(), timeout);
|
||||
WaitSecurityDelayDialog.onReadBeforeRequest(Objects.requireNonNull(getActivity()), timeout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void OnReadAfterRequest() {
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(getActivity());
|
||||
}
|
||||
|
||||
private void showMenu(View v) {
|
||||
final PopupMenu popup = new PopupMenu(getActivity(), v);
|
||||
MenuInflater inflater = popup.getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_loaded_wallet, popup.getMenu());
|
||||
|
||||
popup.getMenu().findItem(R.id.action_set_PIN1).setVisible(mCard.allowSwapPIN());
|
||||
popup.getMenu().findItem(R.id.action_reset_PIN1).setVisible(mCard.allowSwapPIN() && !mCard.useDefaultPIN1());
|
||||
popup.getMenu().findItem(R.id.action_set_PIN2).setVisible(mCard.allowSwapPIN2());
|
||||
popup.getMenu().findItem(R.id.action_reset_PIN2).setVisible(mCard.allowSwapPIN2() && !mCard.useDefaultPIN2());
|
||||
popup.getMenu().findItem(R.id.action_reset_PINs).setVisible(mCard.allowSwapPIN() && mCard.allowSwapPIN2() && !mCard.useDefaultPIN1() && !mCard.useDefaultPIN2());
|
||||
if (!mCard.isReusable())
|
||||
popup.getMenu().findItem(R.id.action_purge).setVisible(false);
|
||||
|
||||
popup.setOnMenuItemClickListener(item -> {
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_set_PIN1:
|
||||
doSetPin();
|
||||
return true;
|
||||
|
||||
case R.id.action_reset_PIN1:
|
||||
doResetPin();
|
||||
return true;
|
||||
|
||||
case R.id.action_set_PIN2:
|
||||
doSetPin2();
|
||||
return true;
|
||||
|
||||
case R.id.action_reset_PIN2:
|
||||
doResetPin2();
|
||||
return true;
|
||||
|
||||
case R.id.action_reset_PINs:
|
||||
doResetPins();
|
||||
return true;
|
||||
|
||||
case R.id.action_purge:
|
||||
doPurge();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
popup.getMenu().findItem(R.id.action_set_PIN2).setEnabled(true);
|
||||
popup.getMenu().findItem(R.id.action_reset_PIN2).setEnabled(true);
|
||||
}
|
||||
|
||||
popup.show();
|
||||
}
|
||||
|
||||
private void doSetPin() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestNewPIN.toString());
|
||||
newPIN = "";
|
||||
newPIN2 = "";
|
||||
startActivityForResult(intent, REQUEST_CODE_ENTER_NEW_PIN);
|
||||
}
|
||||
|
||||
private void doResetPin() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN = PINStorage.getDefaultPIN();
|
||||
newPIN2 = "";
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
}
|
||||
|
||||
private void doResetPin2() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN = "";
|
||||
newPIN2 = PINStorage.getDefaultPIN2();
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
}
|
||||
|
||||
private void doResetPins() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN = PINStorage.getDefaultPIN();
|
||||
newPIN2 = PINStorage.getDefaultPIN2();
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
}
|
||||
|
||||
|
||||
private void doSetPin2() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestNewPIN2.toString());
|
||||
newPIN = "";
|
||||
newPIN2 = "";
|
||||
startActivityForResult(intent, REQUEST_CODE_ENTER_NEW_PIN2);
|
||||
}
|
||||
|
||||
private void doPurge() {
|
||||
requestPIN2Count = 0;
|
||||
final CoinEngine engine = CoinEngineFactory.Create(mCard.getBlockchain());
|
||||
if (!mCard.hasBalanceInfo()) {
|
||||
return;
|
||||
} else if (engine.IsBalanceNotZero(mCard)) {
|
||||
Toast.makeText(getContext(), R.string.cannot_erase_wallet_with_non_zero_balance, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_PURGE);
|
||||
WaitSecurityDelayDialog.onReadAfterRequest(Objects.requireNonNull(getActivity()));
|
||||
}
|
||||
|
||||
private void updateViews() {
|
||||
|
|
@ -1309,13 +1217,9 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
// btnSend.setText(mCard.getOutputsDescription());
|
||||
// }
|
||||
|
||||
|
||||
tvLastInput.setText(mCard.getLastInputDescription());
|
||||
|
||||
|
||||
// tvLastOutput.setText(mCard.getLastOutputDescription());
|
||||
|
||||
|
||||
tvBlockchain.setText(mCard.getBlockchainName());
|
||||
ivBlockchain.setImageResource(mCard.getBlockchain().getImageResource(this.getContext(), mCard.getTokenSymbol()));
|
||||
|
||||
|
|
@ -1402,6 +1306,11 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
}
|
||||
}
|
||||
|
||||
private void errorOnUpdate(String message) {
|
||||
mCard.setError(getString(R.string.cannot_obtain_data_from_blockchain));
|
||||
updateViews();
|
||||
}
|
||||
|
||||
private void doShareWallet(boolean useURI) {
|
||||
if (useURI) {
|
||||
String txtShare = CoinEngineFactory.Create(mCard.getBlockchain()).getShareWalletURI(mCard).toString();
|
||||
|
|
@ -1420,7 +1329,8 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
|
||||
// create intent to show chooser
|
||||
Intent chooser = Intent.createChooser(intent, title);
|
||||
// Verify the intent will resolve to at least one activity
|
||||
|
||||
// verify the intent will resolve to at least one activity
|
||||
if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
|
||||
startActivity(chooser);
|
||||
}
|
||||
|
|
@ -1469,23 +1379,4 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
|
|||
startActivityForResult(intent, REQUEST_CODE_SWAP_PIN);
|
||||
}
|
||||
|
||||
private static Bitmap generateQrCode(String myCodeText) throws WriterException {
|
||||
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<>();
|
||||
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // H = 30% damage
|
||||
|
||||
QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
|
||||
int size = 256;
|
||||
|
||||
BitMatrix bitMatrix = qrCodeWriter.encode(myCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
|
||||
int width = bitMatrix.getWidth();
|
||||
Bitmap bmp = Bitmap.createBitmap(width, width, Bitmap.Config.RGB_565);
|
||||
for (int x = 0; x < width; x++) {
|
||||
for (int y = 0; y < width; y++) {
|
||||
bmp.setPixel(y, x, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -62,7 +62,7 @@ import java.util.Objects;
|
|||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardListAdapter.UiCallbacks, CardProtocol.Notifications, MainActivity.OnCardsClean {
|
||||
public static final String TAG = LoadedWallet.class.getSimpleName();
|
||||
public static final String TAG = Main.class.getSimpleName();
|
||||
|
||||
private static final int REQUEST_CODE_SHOW_CARD_ACTIVITY = 1;
|
||||
private static final int REQUEST_CODE_ENTER_PIN_ACTIVITY = 2;
|
||||
|
|
@ -626,6 +626,7 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
Log.i(TAG, "onViewCard " + "else");
|
||||
}
|
||||
|
||||
intent.putExtra("lastTag123", lastTag);
|
||||
intent.putExtras(cardInfo);
|
||||
startActivityForResult(intent, REQUEST_CODE_SHOW_CARD_ACTIVITY);
|
||||
|
||||
|
|
@ -643,7 +644,7 @@ public class Main extends Fragment implements NfcAdapter.ReaderCallback, CardLis
|
|||
// remove last UIDs because of error and no card read
|
||||
progressBar.post(() -> {
|
||||
if (getContext() != null) {
|
||||
Toast.makeText(getContext(), R.string.try_to_scan_again, Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getContext(), R.string.try_to_scan_again, Toast.LENGTH_SHORT).show();
|
||||
unsuccessReadCount++;
|
||||
progressBar.setProgress(100);
|
||||
progressBar.setProgressTintList(ColorStateList.valueOf(Color.RED));
|
||||
|
|
|
|||
|
|
@ -6,21 +6,33 @@ import android.nfc.NfcAdapter;
|
|||
import android.nfc.Tag;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.tangem.domain.cardReader.NfcManager;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
import com.tangem.domain.wallet.CoinEngineFactory;
|
||||
import com.tangem.domain.wallet.PINStorage;
|
||||
import com.tangem.domain.wallet.TangemCard;
|
||||
import com.tangem.presentation.activity.CreateNewWalletActivity;
|
||||
import com.tangem.presentation.activity.PurgeActivity;
|
||||
import com.tangem.presentation.activity.RequestPINActivity;
|
||||
import com.tangem.presentation.activity.SwapPINActivity;
|
||||
import com.tangem.presentation.dialog.PINSwapWarningDialog;
|
||||
import com.tangem.wallet.BuildConfig;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -28,21 +40,47 @@ import java.util.Objects;
|
|||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class VerifyCard extends Fragment implements SwipeRefreshLayout.OnRefreshListener, NfcAdapter.ReaderCallback {
|
||||
public class VerifyCard extends Fragment implements NfcAdapter.ReaderCallback {
|
||||
|
||||
private static final int REQUEST_CODE_SEND_PAYMENT = 1;
|
||||
private static final int REQUEST_CODE_PURGE = 2;
|
||||
private static final int REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = 3;
|
||||
private static final int REQUEST_CODE_VERIFY_CARD = 4;
|
||||
private static final int REQUEST_CODE_ENTER_NEW_PIN = 5;
|
||||
private static final int REQUEST_CODE_ENTER_NEW_PIN2 = 6;
|
||||
private static final int REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN = 7;
|
||||
private static final int REQUEST_CODE_SWAP_PIN = 8;
|
||||
|
||||
private String newPIN = "", newPIN2 = "";
|
||||
|
||||
private NfcManager mNfcManager;
|
||||
private TangemCard mCard;
|
||||
|
||||
private int requestPIN2Count = 0;
|
||||
|
||||
private Timer timerHideErrorAndMessage = null;
|
||||
|
||||
private TextView tvCardID, tvManufacturer, tvRegistrationDate, tvCardIdentity, tvLastSigned, tvRemainingSignatures, tvReusable, tvError, tvMessage,
|
||||
tvIssuer, tvIssuerData, tvFeatures, tvBlockchain, tvSignedTx, tvSigningMethod, tvFirmware, tvWalletIdentity, tvWallet;
|
||||
private ImageView ivBlockchain, ivPIN, ivPIN2orSecurityDelay, ivDeveloperVersion;
|
||||
private SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
private NfcManager mNfcManager;
|
||||
private Tag lastTag;
|
||||
|
||||
|
||||
public VerifyCard() {
|
||||
|
||||
}
|
||||
|
||||
public void onRefresh() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mNfcManager = new NfcManager(getActivity(), this);
|
||||
|
||||
mCard = new TangemCard(Objects.requireNonNull(getActivity()).getIntent().getStringExtra("UID"));
|
||||
mCard.LoadFromBundle(Objects.requireNonNull(getActivity().getIntent().getExtras()).getBundle("Card"));
|
||||
|
||||
|
||||
// LoadedWallet.needOpenVerify = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -50,13 +88,8 @@ public class VerifyCard extends Fragment implements SwipeRefreshLayout.OnRefresh
|
|||
|
||||
View v = inflater.inflate(R.layout.fr_verify_card, container, false);
|
||||
|
||||
mNfcManager = new NfcManager(getActivity(), this);
|
||||
|
||||
mSwipeRefreshLayout = v.findViewById(R.id.swipe_container);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(this);
|
||||
|
||||
mCard = new TangemCard(getActivity().getIntent().getStringExtra("UID"));
|
||||
mCard.LoadFromBundle(getActivity().getIntent().getExtras().getBundle("Card"));
|
||||
tvCardID = v.findViewById(R.id.tvCardID);
|
||||
|
||||
tvLastSigned = v.findViewById(R.id.tvLastSigned);
|
||||
|
|
@ -90,31 +123,29 @@ public class VerifyCard extends Fragment implements SwipeRefreshLayout.OnRefresh
|
|||
|
||||
Button btnOk = v.findViewById(R.id.btnOk);
|
||||
|
||||
btnOk.setOnClickListener(v1 -> {
|
||||
Intent data = prepareResultIntent();
|
||||
data.putExtra("modification", "update");
|
||||
getActivity().setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
});
|
||||
|
||||
|
||||
FloatingActionButton fabMenu = v.findViewById(R.id.fabMenu);
|
||||
|
||||
|
||||
tvWallet = v.findViewById(R.id.tvWallet);
|
||||
tvWalletIdentity = v.findViewById(R.id.tvWalletIdentity);
|
||||
|
||||
updateViews();
|
||||
btnOk.setOnClickListener(v1 -> {
|
||||
Intent data = prepareResultIntent();
|
||||
data.putExtra("modification", "update");
|
||||
Objects.requireNonNull(getActivity()).setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
});
|
||||
|
||||
// if (NeedUpdate) {
|
||||
// mSwipeRefreshLayout.setRefreshing(true);
|
||||
// mSwipeRefreshLayout.postDelayed(new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// onRefresh();
|
||||
// }
|
||||
// }, 1000);
|
||||
// }
|
||||
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
});
|
||||
|
||||
fabMenu.setOnClickListener(v16 -> showMenu(fabMenu));
|
||||
|
||||
|
||||
updateViews();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
@ -137,7 +168,182 @@ public class VerifyCard extends Fragment implements SwipeRefreshLayout.OnRefresh
|
|||
mNfcManager.onStop();
|
||||
}
|
||||
|
||||
void updateViews() {
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_ENTER_NEW_PIN:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
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());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN = data.getStringExtra("newPIN");
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
} else {
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("newPIN", data.getStringExtra("newPIN"));
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.ConfirmNewPIN.toString());
|
||||
startActivityForResult(intent, REQUEST_CODE_ENTER_NEW_PIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_ENTER_NEW_PIN2:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data != null) {
|
||||
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());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN2 = data.getStringExtra("newPIN2");
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
} else {
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("newPIN2", data.getStringExtra("newPIN2"));
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.ConfirmNewPIN2.toString());
|
||||
startActivityForResult(intent, REQUEST_CODE_ENTER_NEW_PIN2);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (newPIN.equals("")) newPIN = mCard.getPIN();
|
||||
|
||||
if (newPIN2.equals("")) newPIN2 = PINStorage.getPIN2();
|
||||
|
||||
PINSwapWarningDialog pinSwapWarningDialog = new PINSwapWarningDialog();
|
||||
pinSwapWarningDialog.setOnRefreshPage(this::startSwapPINActivity);
|
||||
Bundle bundle = new Bundle();
|
||||
if (!PINStorage.isDefaultPIN(newPIN) || !PINStorage.isDefaultPIN2(newPIN2))
|
||||
bundle.putString(PINSwapWarningDialog.EXTRA_MESSAGE, getString(R.string.if_you_forget));
|
||||
else
|
||||
bundle.putString(PINSwapWarningDialog.EXTRA_MESSAGE, getString(R.string.if_you_use_default));
|
||||
pinSwapWarningDialog.setArguments(bundle);
|
||||
pinSwapWarningDialog.show(Objects.requireNonNull(getActivity()).getFragmentManager(), PINSwapWarningDialog.TAG);
|
||||
}
|
||||
break;
|
||||
|
||||
case REQUEST_CODE_SWAP_PIN:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
data = new Intent();
|
||||
|
||||
data.putExtra("UID", mCard.getUID());
|
||||
data.putExtra("Card", mCard.getAsBundle());
|
||||
data.putExtra("modification", "delete");
|
||||
} else {
|
||||
data.putExtra("modification", "update");
|
||||
}
|
||||
Objects.requireNonNull(getActivity()).setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
} else {
|
||||
if (data != null && data.getExtras().containsKey("UID") && data.getExtras().containsKey("Card")) {
|
||||
TangemCard updatedCard = new TangemCard(data.getStringExtra("UID"));
|
||||
updatedCard.LoadFromBundle(data.getBundleExtra("Card"));
|
||||
mCard = updatedCard;
|
||||
}
|
||||
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
return;
|
||||
} else {
|
||||
if (data != null && data.getExtras().containsKey("message")) {
|
||||
mCard.setError(data.getStringExtra("message"));
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_REQUEST_PIN2_FOR_PURGE:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
Intent intent = new Intent(getContext(), PurgeActivity.class);
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
startActivityForResult(intent, REQUEST_CODE_PURGE);
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_PURGE:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
data = new Intent();
|
||||
|
||||
data.putExtra("UID", mCard.getUID());
|
||||
data.putExtra("Card", mCard.getAsBundle());
|
||||
data.putExtra("modification", "delete");
|
||||
} else {
|
||||
data.putExtra("modification", "update");
|
||||
}
|
||||
Objects.requireNonNull(getActivity()).setResult(Activity.RESULT_OK, data);
|
||||
getActivity().finish();
|
||||
} else {
|
||||
if (data != null && data.getExtras().containsKey("UID") && data.getExtras().containsKey("Card")) {
|
||||
TangemCard updatedCard = new TangemCard(data.getStringExtra("UID"));
|
||||
updatedCard.LoadFromBundle(data.getBundleExtra("Card"));
|
||||
mCard = updatedCard;
|
||||
}
|
||||
if (resultCode == CreateNewWalletActivity.RESULT_INVALID_PIN && requestPIN2Count < 2) {
|
||||
requestPIN2Count++;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_PURGE);
|
||||
return;
|
||||
} else {
|
||||
if (data != null && data.getExtras().containsKey("message")) {
|
||||
mCard.setError(data.getStringExtra("message"));
|
||||
}
|
||||
}
|
||||
updateViews();
|
||||
}
|
||||
break;
|
||||
case REQUEST_CODE_SEND_PAYMENT:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
// mSwipeRefreshLayout.postDelayed(this::onRefresh, 10000);
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
mCard.clearInfo();
|
||||
updateViews();
|
||||
}
|
||||
|
||||
if (data != null) {
|
||||
if (data.getExtras().containsKey("UID") && data.getExtras().containsKey("Card")) {
|
||||
TangemCard updatedCard = new TangemCard(data.getStringExtra("UID"));
|
||||
updatedCard.LoadFromBundle(data.getBundleExtra("Card"));
|
||||
mCard = updatedCard;
|
||||
}
|
||||
if (data.getExtras().containsKey("message")) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
mCard.setMessage(data.getStringExtra("message"));
|
||||
} else {
|
||||
mCard.setError(data.getStringExtra("message"));
|
||||
}
|
||||
}
|
||||
updateViews();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTagDiscovered(Tag tag) {
|
||||
try {
|
||||
Log.w(getClass().getName(), "Ignore discovered tag!");
|
||||
mNfcManager.ignoreTag(tag);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateViews() {
|
||||
try {
|
||||
if (timerHideErrorAndMessage != null) {
|
||||
timerHideErrorAndMessage.cancel();
|
||||
|
|
@ -308,7 +514,82 @@ public class VerifyCard extends Fragment implements SwipeRefreshLayout.OnRefresh
|
|||
}
|
||||
}
|
||||
|
||||
Timer timerHideErrorAndMessage = null;
|
||||
private void doSetPin() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestNewPIN.toString());
|
||||
newPIN = "";
|
||||
newPIN2 = "";
|
||||
startActivityForResult(intent, REQUEST_CODE_ENTER_NEW_PIN);
|
||||
}
|
||||
|
||||
private void doResetPin() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN = PINStorage.getDefaultPIN();
|
||||
newPIN2 = "";
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
}
|
||||
|
||||
private void doResetPin2() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN = "";
|
||||
newPIN2 = PINStorage.getDefaultPIN2();
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
}
|
||||
|
||||
private void doResetPins() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
newPIN = PINStorage.getDefaultPIN();
|
||||
newPIN2 = PINStorage.getDefaultPIN2();
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN);
|
||||
}
|
||||
|
||||
private void doSetPin2() {
|
||||
requestPIN2Count = 0;
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestNewPIN2.toString());
|
||||
newPIN = "";
|
||||
newPIN2 = "";
|
||||
startActivityForResult(intent, REQUEST_CODE_ENTER_NEW_PIN2);
|
||||
}
|
||||
|
||||
private void doPurge() {
|
||||
requestPIN2Count = 0;
|
||||
final CoinEngine engine = CoinEngineFactory.Create(mCard.getBlockchain());
|
||||
if (!mCard.hasBalanceInfo()) {
|
||||
return;
|
||||
} else if (engine.IsBalanceNotZero(mCard)) {
|
||||
Toast.makeText(getContext(), R.string.cannot_erase_wallet_with_non_zero_balance, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getContext(), RequestPINActivity.class);
|
||||
intent.putExtra("mode", RequestPINActivity.Mode.RequestPIN2.toString());
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
startActivityForResult(intent, REQUEST_CODE_REQUEST_PIN2_FOR_PURGE);
|
||||
}
|
||||
|
||||
private void startSwapPINActivity() {
|
||||
Intent intent = new Intent(getContext(), SwapPINActivity.class);
|
||||
intent.putExtra("UID", mCard.getUID());
|
||||
intent.putExtra("Card", mCard.getAsBundle());
|
||||
intent.putExtra("newPIN", newPIN);
|
||||
intent.putExtra("newPIN2", newPIN2);
|
||||
startActivityForResult(intent, REQUEST_CODE_SWAP_PIN);
|
||||
}
|
||||
|
||||
public Intent prepareResultIntent() {
|
||||
Intent data = new Intent();
|
||||
|
|
@ -317,14 +598,58 @@ public class VerifyCard extends Fragment implements SwipeRefreshLayout.OnRefresh
|
|||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTagDiscovered(Tag tag) {
|
||||
try {
|
||||
Log.w(getClass().getName(), "Ignore discovered tag!");
|
||||
mNfcManager.ignoreTag(tag);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
private void showMenu(View v) {
|
||||
final PopupMenu popup = new PopupMenu(getActivity(), v);
|
||||
MenuInflater inflater = popup.getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_loaded_wallet, popup.getMenu());
|
||||
|
||||
popup.getMenu().findItem(R.id.action_set_PIN1).setVisible(mCard.allowSwapPIN());
|
||||
popup.getMenu().findItem(R.id.action_reset_PIN1).setVisible(mCard.allowSwapPIN() && !mCard.useDefaultPIN1());
|
||||
popup.getMenu().findItem(R.id.action_set_PIN2).setVisible(mCard.allowSwapPIN2());
|
||||
popup.getMenu().findItem(R.id.action_reset_PIN2).setVisible(mCard.allowSwapPIN2() && !mCard.useDefaultPIN2());
|
||||
popup.getMenu().findItem(R.id.action_reset_PINs).setVisible(mCard.allowSwapPIN() && mCard.allowSwapPIN2() && !mCard.useDefaultPIN1() && !mCard.useDefaultPIN2());
|
||||
if (!mCard.isReusable())
|
||||
popup.getMenu().findItem(R.id.action_purge).setVisible(false);
|
||||
|
||||
popup.setOnMenuItemClickListener(item -> {
|
||||
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case R.id.action_set_PIN1:
|
||||
doSetPin();
|
||||
return true;
|
||||
|
||||
case R.id.action_reset_PIN1:
|
||||
doResetPin();
|
||||
return true;
|
||||
|
||||
case R.id.action_set_PIN2:
|
||||
doSetPin2();
|
||||
return true;
|
||||
|
||||
case R.id.action_reset_PIN2:
|
||||
doResetPin2();
|
||||
return true;
|
||||
|
||||
case R.id.action_reset_PINs:
|
||||
doResetPins();
|
||||
return true;
|
||||
|
||||
case R.id.action_purge:
|
||||
doPurge();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
popup.getMenu().findItem(R.id.action_set_PIN2).setEnabled(true);
|
||||
popup.getMenu().findItem(R.id.action_reset_PIN2).setEnabled(true);
|
||||
}
|
||||
|
||||
popup.show();
|
||||
}
|
||||
|
||||
}
|
||||
55
app/src/main/java/com/tangem/util/UtilHelper.kt
Normal file
55
app/src/main/java/com/tangem/util/UtilHelper.kt
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package com.tangem.util
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.google.zxing.EncodeHintType
|
||||
import com.google.zxing.WriterException
|
||||
import com.google.zxing.qrcode.QRCodeWriter
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
|
||||
import java.util.*
|
||||
|
||||
object UtilHelper {
|
||||
|
||||
@Throws(WriterException::class)
|
||||
fun generateQrCode(myCodeText: String): Bitmap {
|
||||
val hintMap = Hashtable<EncodeHintType, ErrorCorrectionLevel>()
|
||||
hintMap[EncodeHintType.ERROR_CORRECTION] = ErrorCorrectionLevel.H // H = 30% damage
|
||||
|
||||
val qrCodeWriter = QRCodeWriter()
|
||||
|
||||
val size = 256
|
||||
|
||||
val bitMatrix = qrCodeWriter.encode(myCodeText, BarcodeFormat.QR_CODE, size, size, hintMap)
|
||||
val width = bitMatrix.width
|
||||
val bmp = Bitmap.createBitmap(width, width, Bitmap.Config.RGB_565)
|
||||
for (x in 0 until width) {
|
||||
for (y in 0 until width) {
|
||||
bmp.setPixel(y, x, if (bitMatrix.get(x, y)) Color.BLACK else Color.WHITE)
|
||||
}
|
||||
}
|
||||
return bmp
|
||||
}
|
||||
|
||||
// private static Bitmap generateQrCode(String myCodeText) throws WriterException {
|
||||
// Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<>();
|
||||
// hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // H = 30% damage
|
||||
//
|
||||
// QRCodeWriter qrCodeWriter = new QRCodeWriter();
|
||||
//
|
||||
// int size = 256;
|
||||
//
|
||||
// BitMatrix bitMatrix = qrCodeWriter.encode(myCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
|
||||
// int width = bitMatrix.getWidth();
|
||||
// Bitmap bmp = Bitmap.createBitmap(width, width, Bitmap.Config.RGB_565);
|
||||
// for (int x = 0; x < width; x++) {
|
||||
// for (int y = 0; y < width; y++) {
|
||||
// bmp.setPixel(y, x, bitMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
|
||||
// }
|
||||
// }
|
||||
// return bmp;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -446,10 +446,10 @@
|
|||
android:text="@string/load"/>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fabPurge"
|
||||
android:layout_margin="10dp"
|
||||
android:id="@+id/fabInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
app:fabSize="mini"
|
||||
app:srcCompat="@drawable/ic_information_variant_white_24dp"/>
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
<string name="scan_again_to_verify_the_card">Scan again to verify the card</string>
|
||||
<string name="smart_cash_ag">Smart Cash AG</string>
|
||||
<string name="wallet">Wallet</string>
|
||||
<string name="need_attach_card_again">Need attach card again</string>
|
||||
|
||||
<!-- dialogs -->
|
||||
<string name="device_is_rooted">Your Android device is rooted. Security at risk!</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue