Search in sources :

Example 11 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class GesturePasswordLoginActivity method onConstellationPicker.

public void onConstellationPicker() {
    ArrayList<StorableWallet> storableWallets;
    if (type == 4) {
        storableWallets = WalletStorage.getInstance(NextApplication.mContext).getAll();
    } else {
        storableWallets = WalletStorage.getInstance(NextApplication.mContext).get();
    }
    if (storableWallets == null || storableWallets.size() <= 0) {
        return;
    }
    int index = -1;
    String[] nameArray = new String[storableWallets.size()];
    for (int i = 0; i < storableWallets.size(); i++) {
        String address = storableWallets.get(i).getPublicKey();
        if (storableWallets.get(i).isSelect()) {
            index = i;
        }
        if (!address.startsWith("0x")) {
            address = "0x" + address;
        }
        nameArray[i] = address.replace(address.substring(12, 30), "...");
    }
    OptionPicker picker = new OptionPicker(this, nameArray);
    // Do not disable loops
    picker.setCycleDisable(true);
    picker.setTopBackgroundColor(0xFFEEEEEE);
    picker.setTopHeight(40);
    picker.setTextSize(14);
    picker.setOffset(3);
    picker.setTopLineColor(getResources().getColor(R.color.textColorCard));
    picker.setTopLineHeight(1);
    picker.setCancelTextColor(getResources().getColor(R.color.textColorCard));
    picker.setCancelTextSize(13);
    picker.setSubmitTextColor(getResources().getColor(R.color.gesture_lock_select));
    picker.setSubmitTextSize(13);
    picker.setTextColor(getResources().getColor(R.color.black), getResources().getColor(R.color.textColorCard));
    WheelView.DividerConfig config = new WheelView.DividerConfig();
    // Line color
    config.setColor(getResources().getColor(R.color.tab_sep_line));
    // Line transparency
    config.setAlpha(140);
    // Line ratio
    config.setRatio(1);
    picker.setDividerConfig(config);
    picker.setBackgroundColor(0xFFE1E1E1);
    picker.setSelectedIndex(index);
    picker.setCanceledOnTouchOutside(true);
    picker.setOnOptionPickListener(new OptionPicker.OnOptionPickListener() {

        @Override
        public void onOptionPicked(int index, String item) {
            ArrayList<StorableWallet> storableWallets;
            if (type == 4) {
                storableWallets = WalletStorage.getInstance(NextApplication.mContext).getAll();
            } else {
                storableWallets = WalletStorage.getInstance(NextApplication.mContext).get();
            }
            for (int i = 0; i < storableWallets.size(); i++) {
                if (i != index) {
                    if (type == 4) {
                        WalletStorage.getInstance(NextApplication.mContext).getAll().get(i).setSelect(false);
                    } else {
                        WalletStorage.getInstance(getApplicationContext()).get().get(i).setSelect(false);
                    }
                } else {
                    if (type == 4) {
                        WalletStorage.getInstance(NextApplication.mContext).getAll().get(i).setSelect(true);
                    } else {
                        WalletStorage.getInstance(getApplicationContext()).get().get(i).setSelect(true);
                    }
                }
            }
            initWalletInfo();
            if (type != 4) {
                Utils.sendBroadcastReceiver(GesturePasswordLoginActivity.this, new Intent(Constants.WALLET_REFRESH_GESTURE), false);
            }
        }
    });
    picker.show();
}
Also used : OptionPicker(com.lingtuan.firefly.custom.picker.OptionPicker) WheelView(com.lingtuan.firefly.custom.picker.WheelView) StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) ArrayList(java.util.ArrayList) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint)

Example 12 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class GesturePasswordLoginActivity method initWalletInfo.

/**
 * Load or refresh the wallet information
 */
private void initWalletInfo() {
    ArrayList<StorableWallet> storableWallets;
    if (type == 4) {
        storableWallets = WalletStorage.getInstance(NextApplication.mContext).getAll();
    } else {
        storableWallets = WalletStorage.getInstance(NextApplication.mContext).get();
    }
    if (storableWallets == null || storableWallets.size() <= 0) {
        return;
    }
    for (int i = 0; i < storableWallets.size(); i++) {
        if (storableWallets.get(i).isSelect()) {
            index = i;
            int imgId = Utils.getWalletImg(GesturePasswordLoginActivity.this, i);
            walletImg.setImageResource(imgId);
            storableWallet = storableWallets.get(i);
            storableWallet.setImgId(imgId);
            walletName.setText(storableWallet.getWalletName());
            String address = storableWallet.getPublicKey();
            if (!address.startsWith("0x")) {
                address = "0x" + address;
            }
            walletAddress.setText(address);
            break;
        }
    }
    if (index == -1 && storableWallets.size() > 0) {
        int imgId = Utils.getWalletImg(GesturePasswordLoginActivity.this, 0);
        walletImg.setImageResource(imgId);
        storableWallet = storableWallets.get(0);
        storableWallet.setImgId(imgId);
        walletName.setText(storableWallet.getWalletName());
        String address = storableWallet.getPublicKey();
        if (!address.startsWith("0x")) {
            address = "0x" + address;
        }
        walletAddress.setText(address);
    }
}
Also used : StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) SuppressLint(android.annotation.SuppressLint)

Example 13 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class WalletHandler method handleMessage.

@Override
public void handleMessage(Message msg) {
    switch(msg.what) {
        case WALLET_ING:
            break;
        case WALLET_SUCCESS:
            Intent intent = new Intent(Constants.WALLET_SUCCESS);
            StorableWallet storableWallet = (StorableWallet) msg.obj;
            intent.putExtra(Constants.WALLET_INFO, storableWallet);
            Utils.sendBroadcastReceiver(mContext, intent, false);
            break;
        case WALLET_ERROR:
            Utils.sendBroadcastReceiver(mContext, new Intent(Constants.WALLET_ERROR), false);
            break;
        case NO_MEMORY:
            Utils.sendBroadcastReceiver(mContext, new Intent(Constants.NO_MEMORY), false);
            break;
        case WALLET_PWD_ERROR:
            Utils.sendBroadcastReceiver(mContext, new Intent(Constants.WALLET_PWD_ERROR), false);
            break;
        case WALLET_REPEAT_ERROR:
            Utils.sendBroadcastReceiver(mContext, new Intent(Constants.WALLET_REPEAT_ERROR), false);
            break;
    }
}
Also used : StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) Intent(android.content.Intent)

Example 14 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class WalletCreateSuccessActivity method onClick.

@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.walletCopy:
            int imgId = Utils.getWalletImg(WalletCreateSuccessActivity.this, (WalletStorage.getInstance(getApplicationContext()).get().size() - 1));
            Intent copyIntent = new Intent(WalletCreateSuccessActivity.this, WalletCopyActivity.class);
            ArrayList<StorableWallet> list = WalletStorage.getInstance(getApplicationContext()).get();
            copyIntent.putExtra(Constants.WALLET_INFO, list.get(list.size() - 1));
            copyIntent.putExtra(Constants.WALLET_ICON, imgId);
            startActivity(copyIntent);
            break;
        case R.id.app_back:
            startActivity(new Intent(WalletCreateSuccessActivity.this, MainFragmentUI.class));
            finish();
            break;
        default:
            super.onClick(v);
    }
}
Also used : StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) Intent(android.content.Intent) MainFragmentUI(com.lingtuan.firefly.ui.MainFragmentUI)

Example 15 with StorableWallet

use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.

the class WalletStorage method loadAll.

/**
 * Read in json
 * @param context context
 */
@SuppressWarnings("unchecked")
public synchronized ArrayList<StorableWallet> loadAll(Context context) {
    String walletList = MySharedPrefs.readWalletModeAllList(context);
    if (TextUtils.isEmpty(walletList)) {
        return null;
    }
    if (mapdbLogin == null) {
        mapdbLogin = new ArrayList<>();
    } else {
        mapdbLogin.clear();
    }
    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);
            }
            mapdbLogin.add(storableWallet);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return mapdbLogin;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) StorableWallet(com.lingtuan.firefly.wallet.vo.StorableWallet) JSONException(org.json.JSONException) File(java.io.File)

Aggregations

StorableWallet (com.lingtuan.firefly.wallet.vo.StorableWallet)15 Intent (android.content.Intent)5 File (java.io.File)5 JSONObject (org.json.JSONObject)4 SuppressLint (android.annotation.SuppressLint)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 MainFragmentUI (com.lingtuan.firefly.ui.MainFragmentUI)2 Handler (android.os.Handler)1 Message (android.os.Message)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 OptionPicker (com.lingtuan.firefly.custom.picker.OptionPicker)1 WheelView (com.lingtuan.firefly.custom.picker.WheelView)1 IOException (java.io.IOException)1 BigInteger (java.math.BigInteger)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 ArrayList (java.util.ArrayList)1 CipherException (org.web3j.crypto.CipherException)1