use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class Utils method getWalletName.
/**
* Name to get the wallet
* @ param context context Wallet name name is empty
*/
public static String getWalletName(Context context) {
int index = 1;
String walletName;
while (true) {
walletName = context.getString(R.string.account) + index;
boolean foundSameName = false;
for (StorableWallet storableWallet : WalletStorage.getInstance(context).get()) {
if (walletName.equals(storableWallet.getWalletName())) {
foundSameName = true;
break;
}
}
if (foundSameName) {
index++;
} else {
break;
}
}
return walletName;
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class WalletCreateActivity method onClick.
//
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.clearWalletName:
walletName.setText("");
break;
case R.id.isShowPass:
isShowPassWorld = !isShowPassWorld;
if (isShowPassWorld) {
/* */
walletPwd.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
isShowPass.setImageResource(R.drawable.eye_open);
} else {
/* */
walletPwd.setTransformationMethod(PasswordTransformationMethod.getInstance());
isShowPass.setImageResource(R.drawable.eye_close);
}
break;
case R.id.createWallet:
if (walletName.length() > 12 || walletName.length() <= 0) {
showToast(getString(R.string.wallet_name_warning));
return;
}
if (walletPwd.length() > 16 || walletPwd.length() < 6) {
showToast(getString(R.string.wallet_pwd_warning));
return;
}
String password = walletPwd.getText().toString().trim();
String name = walletName.getText().toString().trim();
String pwdInfo = walletPwdInfo.getText().toString().trim();
if (TextUtils.equals(password, walletAgainPwd.getText().toString().trim())) {
for (StorableWallet storableWallet : WalletStorage.getInstance(getApplicationContext()).get()) {
if (name.equals(storableWallet.getWalletName())) {
showToast(getString(R.string.account_name_exist));
return;
}
}
LoadingDialog.show(WalletCreateActivity.this, getString(R.string.wallet_create_ing));
new WalletThread(mHandler, getApplicationContext(), name, password, pwdInfo, null, 0).start();
} else {
showToast(getString(R.string.account_pwd_again_warning));
}
break;
default:
super.onClick(v);
}
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class WalletScanFragment method onClick.
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.importWallet:
String address = walletAddress.getText().toString();
if (TextUtils.isEmpty(address) || address.length() != 42 || !address.startsWith("0x")) {
MyToast.showToast(getActivity(), getString(R.string.wallet_scan_warning));
return;
}
address = address.substring(2);
boolean exists = WalletStorage.getInstance(getActivity().getApplicationContext()).checkExists(address);
if (!exists) {
StorableWallet storableWallet = new StorableWallet();
storableWallet.setPublicKey(address);
storableWallet.setWalletType(1);
storableWallet.setWalletName(Utils.getWalletName(getActivity()));
if (WalletStorage.getInstance(getActivity().getApplicationContext()).get().size() <= 0) {
storableWallet.setSelect(true);
}
WalletStorage.getInstance(getActivity().getApplicationContext()).add(storableWallet, getActivity());
MyToast.showToast(getActivity(), getString(R.string.notification_wallimp_finished));
Utils.sendBroadcastReceiver(getActivity(), new Intent(Constants.WALLET_SUCCESS), false);
startActivity(new Intent(getActivity(), MainFragmentUI.class));
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
} else {
MyToast.showToast(getActivity(), getString(R.string.notification_wallimp_repeat));
}
break;
case R.id.walletQrImg:
Intent i = new Intent(getActivity(), CaptureActivity.class);
i.putExtra("type", 2);
startActivityForResult(i, 100);
break;
}
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class WalletStorage method addWalletArray.
/**
* load wallet list
* @param context context
* @param walletArray wallet json array
*/
private void addWalletArray(Context context, JSONArray walletArray, boolean needAdd) {
if (walletArray == null) {
return;
}
for (int i = 0; i < walletArray.length(); i++) {
JSONObject walletObj = walletArray.optJSONObject(i);
StorableWallet storableWallet = new StorableWallet();
storableWallet.setPublicKey(walletObj.optString(Constants.WALLET_ADDRESS));
storableWallet.setWalletName(walletObj.optString(Constants.WALLET_NAME));
storableWallet.setCanExportPrivateKey(walletObj.optInt(Constants.WALLET_EXTRA));
storableWallet.setBackup(walletObj.optBoolean(Constants.WALLET_BACKUP));
if (i == 0) {
storableWallet.setSelect(true);
} else {
storableWallet.setSelect(false);
}
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), storableWallet.getPublicKey());
if (!destination.exists()) {
storableWallet.setWalletType(1);
}
if (needAdd) {
addWalletToList(NextApplication.mContext, storableWallet);
}
mapdb.add(storableWallet);
}
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class WalletStorage method load.
/**
* Read in json
*/
@SuppressWarnings("unchecked")
public synchronized void load(Context context) throws IOException, ClassNotFoundException {
String walletList = MySharedPrefs.readWalletList(context);
if (TextUtils.isEmpty(walletList)) {
return;
}
try {
JSONObject object = new JSONObject(walletList);
JSONArray walletArray = object.optJSONArray("data");
for (int i = 0; i < walletArray.length(); i++) {
JSONObject walletObj = walletArray.optJSONObject(i);
StorableWallet storableWallet = new StorableWallet();
storableWallet.setPublicKey(walletObj.optString(Constants.WALLET_ADDRESS));
storableWallet.setWalletName(walletObj.optString(Constants.WALLET_NAME));
storableWallet.setCanExportPrivateKey(walletObj.optInt(Constants.WALLET_EXTRA));
storableWallet.setBackup(walletObj.optBoolean(Constants.WALLET_BACKUP));
if (i == 0) {
storableWallet.setSelect(true);
}
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), storableWallet.getPublicKey());
if (!destination.exists()) {
storableWallet.setWalletType(1);
}
mapdb.add(storableWallet);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Aggregations