Android ETH錢包助記詞開發(fā)

UI今天給了個需求,把亂序的單詞拼成一句話,如下圖:


前期的思路是這樣的:

1.測量每個單詞的高度和寬度,計算出所有單詞排列后的高*2蒜胖,就是view 的高度

2.把文字寫上去

哈哈,這個的確就是當時的想法抛蚤,不要慫就是干~

那就來試試吧,話不多說寻狂,直接上代碼:

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"));

? ? ? ? }

}

}

對于這么簡單的需求來說這個代碼量稍微有點多~ 里面有很多可以優(yōu)化的地方纠亚,等有時間再來改改吧塘慕。

歡迎線下交流 wx:dwl-1591293009

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市蒂胞,隨后出現(xiàn)的幾起案子图呢,更是在濱河造成了極大的恐慌,老刑警劉巖骗随,帶你破解...
    沈念sama閱讀 222,681評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蛤织,死亡現(xiàn)場離奇詭異,居然都是意外死亡鸿染,警方通過查閱死者的電腦和手機指蚜,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,205評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來涨椒,“玉大人摊鸡,你說我怎么就攤上這事绽媒。” “怎么了免猾?”我有些...
    開封第一講書人閱讀 169,421評論 0 362
  • 文/不壞的土叔 我叫張陵些椒,是天一觀的道長。 經常有香客問我掸刊,道長免糕,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,114評論 1 300
  • 正文 為了忘掉前任忧侧,我火速辦了婚禮石窑,結果婚禮上,老公的妹妹穿的比我還像新娘蚓炬。我一直安慰自己松逊,他們只是感情好,可當我...
    茶點故事閱讀 69,116評論 6 398
  • 文/花漫 我一把揭開白布肯夏。 她就那樣靜靜地躺著经宏,像睡著了一般。 火紅的嫁衣襯著肌膚如雪驯击。 梳的紋絲不亂的頭發(fā)上烁兰,一...
    開封第一講書人閱讀 52,713評論 1 312
  • 那天,我揣著相機與錄音徊都,去河邊找鬼沪斟。 笑死,一個胖子當著我的面吹牛暇矫,可吹牛的內容都是我干的主之。 我是一名探鬼主播,決...
    沈念sama閱讀 41,170評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼李根,長吁一口氣:“原來是場噩夢啊……” “哼槽奕!你這毒婦竟也來了?” 一聲冷哼從身側響起房轿,我...
    開封第一講書人閱讀 40,116評論 0 277
  • 序言:老撾萬榮一對情侶失蹤粤攒,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后冀续,有當地人在樹林里發(fā)現(xiàn)了一具尸體琼讽,經...
    沈念sama閱讀 46,651評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,714評論 3 342
  • 正文 我和宋清朗相戀三年洪唐,在試婚紗的時候發(fā)現(xiàn)自己被綠了钻蹬。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,865評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡凭需,死狀恐怖问欠,靈堂內的尸體忽然破棺而出肝匆,到底是詐尸還是另有隱情,我是刑警寧澤顺献,帶...
    沈念sama閱讀 36,527評論 5 351
  • 正文 年R本政府宣布旗国,位于F島的核電站,受9級特大地震影響注整,放射性物質發(fā)生泄漏能曾。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,211評論 3 336
  • 文/蒙蒙 一肿轨、第九天 我趴在偏房一處隱蔽的房頂上張望寿冕。 院中可真熱鬧,春花似錦椒袍、人聲如沸驼唱。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,699評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽玫恳。三九已至,卻和暖如春优俘,著一層夾襖步出監(jiān)牢的瞬間京办,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,814評論 1 274
  • 我被黑心中介騙來泰國打工兼吓, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留臂港,地道東北人。 一個月前我還...
    沈念sama閱讀 49,299評論 3 379
  • 正文 我出身青樓视搏,卻偏偏與公主長得像,于是被迫代替她去往敵國和親县袱。 傳聞我的和親對象是個殘疾皇子浑娜,可洞房花燭夜當晚...
    茶點故事閱讀 45,870評論 2 361

推薦閱讀更多精彩內容