Modify HDAccountHot Support For Importing Chinese
MODIFY
bither-android/src/net/bither/BitherApplication.java
bither-android/src/net/bither/BitherApplication.java
@@ -35,6 +35,7 @@ import net.bither.db.AndroidDbImpl;
import net.bither.db.TxDatabaseHelper;
import net.bither.exception.UEHandler;
import net.bither.mnemonic.MnemonicCodeAndroid;
+import net.bither.preference.AppSharedPreference;
import net.bither.service.BlockchainService;
import net.bither.xrandom.LinuxSecureRandom;
@@ -173,13 +174,15 @@ public class BitherApplication extends Application {
new Thread(new Runnable() {
@Override
public void run() {
- AddressManager.getInstance();
- initLogging();
try {
- MnemonicCode.setInstance(new MnemonicCodeAndroid(null));
+ MnemonicCode mnemonicCode = new MnemonicCodeAndroid();
+ mnemonicCode.setMnemonicWordList(AppSharedPreference.getInstance().getMnemonicWordList());
+ MnemonicCode.setInstance(mnemonicCode);
} catch (IOException e) {
e.printStackTrace();
}
+ AddressManager.getInstance();
+ initLogging();
}
}).start();
}

MODIFY
bither-android/src/net/bither/activity/cold/HdmImportWordListActivity.java
bither-android/src/net/bither/activity/cold/HdmImportWordListActivity.java
@@ -36,6 +36,7 @@ import net.bither.BitherSetting;
import net.bither.R;
import net.bither.bitherj.crypto.SecureCharSequence;
import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
+import net.bither.bitherj.crypto.mnemonic.MnemonicWordList;
import net.bither.bitherj.factory.ImportHDSeed;
import net.bither.bitherj.utils.Utils;
import net.bither.factory.ImportHDSeedAndroid;
@@ -145,8 +146,8 @@ public class HdmImportWordListActivity extends SwipeRightFragmentActivity implem
return;
}
try {
- mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(word));
- if (mnemonic.getWordList() == null) {
+ mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(), word);
+ if (mnemonic == null) {
DropdownMessage.showDropdownMessage(HdmImportWordListActivity.this,
R.string.hdm_import_word_list_wrong_word_warn);
return;
@@ -188,11 +189,11 @@ public class HdmImportWordListActivity extends SwipeRightFragmentActivity implem
private void isZhTw() {
try {
for (String word: words) {
- mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(word));
+ mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(), word);
ArrayList<String> zhCnWorsList = mnemonic.getWordListForInputStream(BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_cn));
ArrayList<String> zhTwWorsList = mnemonic.getWordListForInputStream(BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_tw));
if (!zhCnWorsList.contains(word) && zhTwWorsList.contains(word)) {
- mnemonic.wordList = zhTwWorsList;
+ mnemonic.setWordList(zhTwWorsList, MnemonicWordList.ZhTw);
return;
}
}

MODIFY
bither-android/src/net/bither/factory/ImportHDSeedAndroid.java
bither-android/src/net/bither/factory/ImportHDSeedAndroid.java
@@ -29,7 +29,6 @@ import net.bither.bitherj.core.HDMKeychain;
import net.bither.bitherj.crypto.SecureCharSequence;
import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
import net.bither.bitherj.factory.ImportHDSeed;
-import net.bither.mnemonic.MnemonicCodeAndroid;
import net.bither.preference.AppSharedPreference;
import net.bither.runnable.ThreadNeedService;
import net.bither.service.BlockchainService;
@@ -44,6 +43,7 @@ import java.util.List;
public class ImportHDSeedAndroid extends ImportHDSeed {
private DialogProgress dp;
private Activity activity;
+ private MnemonicCode mnemonicCode = MnemonicCode.instance();
public ImportHDSeedAndroid(Activity activity, DialogProgress dp, String content, SecureCharSequence password) {
super(ImportHDSeedType.HDMColdSeedQRCode, content, null, password);
@@ -63,6 +63,7 @@ public class ImportHDSeedAndroid extends ImportHDSeed {
super(importHDSeedType, content, worlds, password, mnemonicCode);
this.activity = activity;
this.dp = dp;
+ this.mnemonicCode = mnemonicCode;
}
@@ -135,6 +136,8 @@ public class ImportHDSeedAndroid extends ImportHDSeed {
}
}
if (success) {
+ AppSharedPreference.getInstance().setMnemonicWordList(mnemonicCode.getMnemonicWordList());
+ MnemonicCode.setInstance(mnemonicCode);
ThreadUtil.runOnMainThread(new Runnable() {
@Override
public void run() {

MODIFY
bither-android/src/net/bither/mnemonic/MnemonicCodeAndroid.java
bither-android/src/net/bither/mnemonic/MnemonicCodeAndroid.java
package net.bither.mnemonic;
+
import net.bither.BitherApplication;
import net.bither.R;
import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
+import net.bither.bitherj.crypto.mnemonic.MnemonicWordList;
-import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
-import java.io.InputStreamReader;
import java.util.ArrayList;
-import java.util.List;
+import java.util.HashMap;
/**
* Created by songchenwen on 14/12/31.
*/
public class MnemonicCodeAndroid extends MnemonicCode {
- private String word;
- public MnemonicCodeAndroid(String word) throws IOException {
+ public MnemonicCodeAndroid() throws IOException {
super();
- if (word != null) {
- this.word = word;
- this.wordList = openWordList();
- }
}
@Override
- protected ArrayList<String> openWordList() throws IOException, IllegalArgumentException {
- if (word == null) {
- return getWordListForInputStream(BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_english));
+ protected HashMap<MnemonicWordList, InputStream> openWordList() throws IOException, IllegalArgumentException {
+ return getAllMnemonicWordListRawResources();
}
- InputStream[] inputStreams = new InputStream[]{
- BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_english),
- BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_cn),
- BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_tw)};
- for (InputStream inputStream: inputStreams) {
- ArrayList<String> words = getWordListForInputStream(inputStream);
- if (words.contains(word)) {
- return words;
+
+ private HashMap<MnemonicWordList, InputStream> getAllMnemonicWordListRawResources() {
+ ArrayList<MnemonicWordList> mnemonicWordLists = MnemonicWordList.getAllMnemonicWordLists();
+ HashMap<MnemonicWordList, InputStream> inputStreamMap = new HashMap<>();
+ for (MnemonicWordList mnemonicWordList: mnemonicWordLists) {
+ inputStreamMap.put(mnemonicWordList, getMnemonicWordListRawResource(mnemonicWordList));
}
+ return inputStreamMap;
+ }
+
+ private InputStream getMnemonicWordListRawResource(MnemonicWordList wordList) {
+ switch (wordList) {
+ case English:
+ return BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_english);
+ case ZhCN:
+ return BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_cn);
+ case ZhTw:
+ return BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_tw);
}
- return null;
+ return BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_english);
}
}

MODIFY
bither-android/src/net/bither/preference/AppSharedPreference.java
bither-android/src/net/bither/preference/AppSharedPreference.java
@@ -25,6 +25,7 @@ import net.bither.BitherApplication;
import net.bither.BitherSetting;
import net.bither.bitherj.BitherjSettings;
import net.bither.bitherj.BitherjSettings.MarketType;
+import net.bither.bitherj.crypto.mnemonic.MnemonicWordList;
import net.bither.bitherj.qrcode.QRCodeUtil;
import net.bither.bitherj.utils.UnitUtil.BitcoinUnit;
import net.bither.bitherj.utils.Utils;
@@ -78,6 +79,8 @@ public class AppSharedPreference {
private static final String TOTAL_BALANCE_HIDE = "total_balance_hide";
+ private static final String MNEMONIC_WORD_LIST = "mnemonic_word_list";
+
private static AppSharedPreference mInstance = new AppSharedPreference();
private SharedPreferences mPreferences;
@@ -437,4 +440,13 @@ public class AppSharedPreference {
public TotalBalanceHide getTotalBalanceHide() {
return TotalBalanceHide.totalBalanceHide(mPreferences.getInt(TOTAL_BALANCE_HIDE, 0));
}
+
+ public MnemonicWordList getMnemonicWordList() {
+ String value = mPreferences.getString(MNEMONIC_WORD_LIST, "");
+ return MnemonicWordList.getMnemonicWordList(value);
+ }
+
+ public void setMnemonicWordList(MnemonicWordList wordList) {
+ mPreferences.edit().putString(MNEMONIC_WORD_LIST, wordList.getMnemonicWordListValue()).commit();
+ }
}

MODIFY
bither-android/src/net/bither/ui/base/dialog/DialogHdmImportWordListReplace.java
bither-android/src/net/bither/ui/base/dialog/DialogHdmImportWordListReplace.java
@@ -86,8 +86,8 @@ public class DialogHdmImportWordListReplace extends CenterDialog implements Dial
return;
}
try {
- MnemonicCode mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(word));
- if (mnemonic.getWordList() == null) {
+ MnemonicCode mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(), word);
+ if (mnemonic == null) {
tvError.setVisibility(View.VISIBLE);
shake();
return;

MODIFY
bitherj
bitherj
-Subproject commit da1da87178bab9fc8fd56a4f44a2f26d203a075c
+Subproject commit 627342641855db0a3a2fa0861a34a185529bf415

Modify HDAccountHot Support For Importing Chinese