Android ETH钱包助记词开发

UI今天给了个需求,把乱序的单词拼成一句话,如下图:


Android ETH钱包助记词开发_第1张图片

前期的思路是这样的:

1.测量每个单词的高度和宽度,计算出所有单词排列后的高*2,就是view 的高度

2.把文字写上去

Android ETH钱包助记词开发_第2张图片
Android ETH钱包助记词开发_第3张图片

哈哈,这个的确就是当时的想法,不要怂就是干~

那就来试试吧,话不多说,直接上代码:

package com.meetime.etherflyer.page;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.text.TextUtils;

import android.view.View;

import android.widget.RelativeLayout;

import android.widget.TextView;

import com.meetime.etherflyer.R;

import com.meetime.etherflyer.tools.AppConfigUtil;

import com.meetime.etherflyer.tools.AppLanguage;

import com.meetime.etherflyer.tools.SPUtils;

import com.meetime.etherflyer.tools.ToastUtils;

import com.per.flowlayout.AddTagActivity;

import com.per.flowlayout.FlowLayout;

import com.per.flowlayout.FlowLayoutAdapter;

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class MnHellpWordAcextends Activity {

private TextViewtv_remind,tv_copy_label,tv_copy_tip,tv_etherflyer_desc,tv_confirm;

    private FlowLayouttcy_my_label, tcy_hot_label;

    private FlowLayoutAdaptermMyLabelAdapter, mHotLabelAdapter;

    private ListHotLabelLists;

    private ArrayListlistArr =new ArrayList();

    private RelativeLayoutnext;

    private Stringmnemonic;

    private ListMyLabelLists =new ArrayList<>();

    private static int TAG_REQUESTCODE =0x101;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

        setContentView(R.layout.layout_mn_hellp_word);

        initView();

        initData();

    }

private void initView() {

next = findViewById(R.id.next);

        tv_remind = findViewById(R.id.tv_remind);

        tcy_my_label = findViewById(R.id.tcy_my_label);

        tcy_hot_label = findViewById(R.id.tcy_hot_label);

        setLanguage();

    }

private void initData() {

Intent intent = getIntent();

        mnemonic = intent.getStringExtra("mnemonic");

        HotLabelLists =new ArrayList<>();

        String[] splits =mnemonic.split(" ");

        for (int i =0; i < splits.length; i++) {

listArr.add(splits[i]);

        }

String[] split =mnemonic.split(" ");

        for (int i =0; i < split.length; i++) {

HotLabelLists.add(split[i]);

            Collections.shuffle(HotLabelLists);

        }

mHotLabelAdapter =new FlowLayoutAdapter(this, HotLabelLists);

        tcy_hot_label.setAdapter(mHotLabelAdapter);

        tcy_hot_label.setItemClickListener(new TagCloudLayoutItemOnClick(1));

        mMyLabelAdapter =new FlowLayoutAdapter(this, MyLabelLists);

        tcy_my_label.setAdapter(mMyLabelAdapter);

        tcy_my_label.setItemClickListener(new TagCloudLayoutItemOnClick(0));

        String labels = String.valueOf(getIntent().getStringExtra("labels"));

        if (!TextUtils.isEmpty(labels) && labels.length() >0 && !labels.equals("null")) {

String[] temp = labels.split(" ");

            for (int i =0; i < temp.length; i++) {

if (!MyLabelLists.contains(temp[i])){

MyLabelLists.add(temp[i]);

                    ChangeMyLabels();

                }

}

}

next.setOnClickListener(new View.OnClickListener() {

@Override

            public void onClick(View v) {

if (MyLabelLists.isEmpty()){

ToastUtils.toast("请您按顺序选择上一页的助记词");

                }else {

if (MyLabelLists.equals(listArr)){

for (String mn:listArr){

SPUtils.putStringValue("mnemonic", mn);

                        }

Intent intent =new Intent(getApplication(),CreateWalletSAc.class);startActivity(intent);

                    }else {

ToastUtils.toast("请您按顺序选择上一页的助记词");

                    }

}

}

});

    }

/**

* 刷新我的标签数据

    * @author dongwenlong

*/

    private void ChangeMyLabels() {

tv_remind.setVisibility(MyLabelLists.size() >0 ? View.GONE

                : View.VISIBLE);

        tcy_my_label.setVisibility(MyLabelLists.size() >0 ? View.VISIBLE

                : View.GONE);

        mMyLabelAdapter.notifyDataSetChanged();

    }

/**

* 标签的点击事件

*

    * @author dongwenlong

*/

    class TagCloudLayoutItemOnClickimplements FlowLayout.TagItemClickListener {

int index;

        public TagCloudLayoutItemOnClick(int index) {

this.index = index;

        }

@Override

        public void itemClick(int position) {

switch (index) {

case 0:

MyLabelLists.remove(MyLabelLists.get(position));

                    ChangeMyLabels();

break;

                case 1:

if (MyLabelLists.size() <12) {

if (HotLabelLists.get(position).equals("自定义")) {

startActivityForResult(

new Intent(MnHellpWordAc.this,

                                            AddTagActivity.class),

                                    TAG_REQUESTCODE);

                        }else {

Boolean isExits =isExist(MyLabelLists,

                                    HotLabelLists.get(position));

                            if (isExits) {

ToastUtils.toast("此助记词已经添加啦");

return;

                            }else {

MyLabelLists.add(HotLabelLists.get(position));

                                ChangeMyLabels();

                            }

}

}else {

ToastUtils.toast("最多只能添加12个助记词哦");

                    }

break;

                default:

break;

            }

}

}

/**

* 将数组里面的字符串遍历一遍,看是否存在相同标签

    * @param str

    * @param compareStr

    * @author dongwenlong

    * @return

    */

    public static BooleanisExist(List str, String compareStr) {

Boolean isExist =false;//默认沒有相同标签

        for (int i =0; i < str.size(); i++) {

if (compareStr.equals(str.get(i))) {

isExist =true;

            }

}

return isExist;

    }

/**

* 回传数据

    *@author dongwenlong

    @Override*/

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

String label = data.getStringExtra("tags");

        MyLabelLists.add(label);

        ChangeMyLabels();

    }

private void setLanguage() {

tv_copy_label = findViewById(R.id.tv_copy_label);

        tv_copy_tip = findViewById(R.id.tv_copy_tip);

        tv_etherflyer_desc = findViewById(R.id.tv_etherflyer_desc);

        tv_confirm = findViewById(R.id.tv_confirm);

        if (AppConfigUtil.getInstance().currentLanguage == AppLanguage.CN){

tv_copy_label.setText(AppConfigUtil.getInstance().localizedString("请立即抄写下你的备份助记词!"));

            tv_copy_tip.setText(AppConfigUtil.getInstance().localizedString("助记词可替代输入钱包私钥的方式导入钱包。请将它准确抄下并熟记,且存放到只有你知道的安全地方。"));

            tv_etherflyer_desc.setText(AppConfigUtil.getInstance().localizedString("ETHERFLYER是基于以太坊去中心化交易平台"));

            tv_confirm.setText(AppConfigUtil.getInstance().localizedString("确认"));

        }else {

tv_copy_label.setText(AppConfigUtil.getInstance().localizedString("Please copy down your backup mnemonics immediately!"));

            tv_copy_tip.setText(AppConfigUtil.getInstance().localizedString("Mnemonic words can be imported into a wallet instead of entering the private key of the wallet. Please copy it down accurately and memorize it, and store it in a safe place only you know."));

            tv_etherflyer_desc.setText(AppConfigUtil.getInstance().localizedString("ETHERFLYER is Decentralized trading platform based on ETF"));

            tv_confirm.setText(AppConfigUtil.getInstance().localizedString("confirm"));

        }

}

}

对于这么简单的需求来说这个代码量稍微有点多~ 里面有很多可以优化的地方,等有时间再来改改吧。

欢迎线下交流 wx:dwl-1591293009

你可能感兴趣的:(Android ETH钱包助记词开发)