Skip to content

Commit

Permalink
优化代码x
Browse files Browse the repository at this point in the history
  • Loading branch information
zogodo committed Jan 11, 2017
1 parent 48ed66a commit 232aa5b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/src/main/java/com/zogodo/myempty/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ protected void onCreate(Bundle savedInstanceState)
protected void onRestart() {
super.onRestart();
SearchView search_view = (SearchView)findViewById(R.id.search);
//search_view.setQuery(word_now, false);
//search_view.setQuery(word_now.word, false);
}

public static StarDict ec_dic;
public static String sd_dic_path = "/mnt/sdcard/Android/data/com.zogodo.jelly/files/dict/";
String word_now;
OneWord word_now;

public void updateListView(String tran) throws IOException
{
Expand All @@ -102,13 +102,13 @@ public void updateListView(String tran) throws IOException

ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();
int i = 0;
byte[] word_byte = new byte[48];
System.arraycopy(ec_dic.index_file_align, start + i*56, word_byte, 0, 48);
String word = new String(word_byte, StandardCharsets.UTF_8).trim();
word_now.word_byte = new byte[StarDict.word_width];
System.arraycopy(ec_dic.index_file_align, start + i*StarDict.index_width, word_now.word_byte, 0, StarDict.word_width);
String word = new String(word_now.word_byte, StandardCharsets.UTF_8).trim();

while(i < 100 && word.toLowerCase().indexOf(tran) == 0)
{
String meaning = ec_dic.GetMeaningOfWord(start + i*56);
String meaning = ec_dic.GetMeaningOfWord(start + i*StarDict.index_width);
meaning = meaning.replaceAll("\\s+", " ");
//meaning = meaning.replaceAll("^t(.+?)m", "[ $1 ] ");
//meaning = meaning.replaceAll("^m", "");
Expand All @@ -121,8 +121,8 @@ public void updateListView(String tran) throws IOException
listItem.add(map);
i++;

System.arraycopy(ec_dic.index_file_align, start + i*56, word_byte, 0, 48);
word = new String(word_byte, StandardCharsets.UTF_8).trim();
System.arraycopy(ec_dic.index_file_align, start + i*StarDict.index_width, word_now.word_byte, 0, StarDict.word_width);
word = new String(word_now.word_byte, StandardCharsets.UTF_8).trim();
}

SimpleAdapter mSimpleAdapter = new SimpleAdapter(this,
Expand All @@ -136,12 +136,12 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)

Class<?> aClass = parent.getItemAtPosition(position).getClass();
HashMap word_meaning = (HashMap)parent.getItemAtPosition(position);
word_now = word_meaning.get("word").toString();
String meaning = word_meaning.get("meaning").toString();
word_now.word = word_meaning.get("word").toString();
word_now.meaning = word_meaning.get("meaning").toString();

Intent intent = new Intent(MainActivity.this, WordDetail.class);
intent.putExtra("word", word_now);
intent.putExtra("meaning", meaning);
intent.putExtra("word", word_now.word);
intent.putExtra("meaning", word_now.meaning);
//打开新窗口
startActivity(intent);

Expand Down

0 comments on commit 232aa5b

Please sign in to comment.