diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/About.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/About.java new file mode 100644 index 00000000..8e5a5a74 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/About.java @@ -0,0 +1,14 @@ +package com.example.dictionary; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.TextView; + +public class About extends Activity { + private TextView text; + protected void onCreate(Bundle savedInstanceState){ + super.onCreate(savedInstanceState); + this.setContentView(R.layout.about); + text = (TextView) findViewById(R.id.text); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/EditWord.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/EditWord.java new file mode 100644 index 00000000..edd0b579 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/EditWord.java @@ -0,0 +1,114 @@ +package com.example.dictionary; + +import java.util.ArrayList; +import java.util.HashMap; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.Window; +import android.widget.Button; +import android.widget.EditText; +import android.widget.SimpleAdapter; +import android.widget.Toast; + +public class EditWord extends Activity implements OnClickListener { + private String action; + private EditText zhushi; + private EditText meanning; + private Button confirm; + private Button cancel; + int index = -1; + private Bundle bundle; + private ArrayList> arrayList; + + @SuppressWarnings("unchecked") + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // 设置隐藏标题 + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.edit); + Bundle bundle = this.getIntent().getExtras(); + action = bundle.getString("action"); + + initWidgets(); + } + + private void initWidgets() { + // spelling是单词,meanning是解释,confirm是确定,cancel是取消 + zhushi = (EditText) findViewById(R.id.zhushi); + meanning = (EditText) findViewById(R.id.meanning); + confirm = (Button) findViewById(R.id.button1); + cancel = (Button) findViewById(R.id.button2); + cancel.setOnClickListener(this); + confirm.setOnClickListener(this); + + } + + @Override + protected void onResume() { + // TODO Auto-generated method stub + super.onResume(); + if (action.equals("edit")) { + zhushi.setText(bundle.getString("word")); + meanning.setText(bundle.getString("explain")); + index = bundle.getInt("index"); + } + } + + @SuppressWarnings("unchecked") + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + + String word = meanning.getText().toString().trim(); + String explain = zhushi.getText().toString().trim(); + if (v == cancel) { + finish(); + } + if (v == confirm) { + if (meanning.getText().toString().equals("") + || zhushi.getText().toString().equals("")) { + Toast.makeText(EditWord.this, "信息不能为空", Toast.LENGTH_SHORT) + .show(); + } + + else { + Intent intent = getIntent(); + arrayList = (ArrayList>) new ObjectFile() + .readObjectFile(); + if (null == arrayList) { + arrayList = new ArrayList>(); + } + if (!TextUtils.isEmpty(word) && !TextUtils.isEmpty(explain)) { + if (index == -1) { + HashMap map = new HashMap(); + map.put("word", word); + map.put("explain", explain); + arrayList.add(map); + + }else{ + HashMap map = new HashMap(); + map.put("word", word); + map.put("explain", explain); + arrayList.set(index, map); + } + new ObjectFile().writeObjectFile(arrayList); + } + + SimpleAdapter adapter = new SimpleAdapter(this, arrayList, + android.R.layout.simple_list_item_2, new String[] { + "word", "explain" }, new int[] { + android.R.id.text1, android.R.id.text2 }); + Intent intent1 = new Intent(this, MainActivity.class); + intent.putExtra("word", word); + intent.putExtra("explain", explain); + startActivity(intent1); + EditWord.this.finish(); + } + } + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/EditWord.java.bak b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/EditWord.java.bak new file mode 100644 index 00000000..5737a221 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/EditWord.java.bak @@ -0,0 +1,71 @@ +package com.example.dictionary; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.Window; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.example.diy.Word; + +public class EditWord extends Activity implements OnClickListener { + private String action; + private EditText zhushi; + private EditText meanning; + private Button confirm; + private Button cancel; + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // 设置隐藏标题 + requestWindowFeature(Window.FEATURE_NO_TITLE); + setContentView(R.layout.edit); + Bundle bundle = this.getIntent().getExtras(); + action = bundle.getString("action"); + zhushi = (EditText) findViewById(R.id.zhushi); + meanning = (EditText) findViewById(R.id.meanning); + + initWidgets(); + } + + private void initWidgets() { + // spelling是单词,meanning是解释,confirm是确定,cancel是取消 + zhushi = (EditText) findViewById(R.id.zhushi); + meanning = (EditText) findViewById(R.id.meanning); + confirm = (Button) findViewById(R.id.button1); + cancel = (Button) findViewById(R.id.button2); + cancel.setOnClickListener(this); + confirm.setOnClickListener(this); + if (action.equals("edit")) { + } + } + + @Override + public void onClick(View v) { + // TODO Auto-generated method stub + + String word = meanning.getText().toString().trim(); + String explain = zhushi.getText().toString().trim(); + if (v == cancel) { + finish(); + } + if (v == confirm) { + if (meanning.getText().toString().equals("") + || zhushi.getText().toString().equals("")) { + Toast.makeText(EditWord.this, "信息不能为空", Toast.LENGTH_SHORT).show(); + } + + else { + Intent intent = new Intent(this, NoteBook.class); + intent.putExtra("word", word); + intent.putExtra("explain", explain); + startActivity(intent); + } + } + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/HomeActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/HomeActivity.java new file mode 100644 index 00000000..6fd841e3 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/HomeActivity.java @@ -0,0 +1,53 @@ +package com.example.dictionary; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.Menu; +import android.view.Window; +import android.view.WindowManager; + +public class HomeActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + //设置隐藏标题栏 + requestWindowFeature(Window.FEATURE_NO_TITLE); + //设置全屏 + this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + setContentView(R.layout.home); + + new Thread(new Runnable(){ + + @Override + public void run() { + // TODO Auto-generated method stub + try { + Thread.sleep(1000); + shiftActivityToHome(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + }).start(); + + } + + private void shiftActivityToHome(){ + Intent intent=new Intent(HomeActivity.this,MainActivity.class); + startActivity(intent); + //把当前也关闭 + HomeActivity.this.finish(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.main, menu); + return true; + } + +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/MainActivity.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/MainActivity.java new file mode 100644 index 00000000..c5e00736 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/MainActivity.java @@ -0,0 +1,47 @@ +package com.example.dictionary; +import android.os.Bundle; +import android.app.TabActivity; +import android.content.Intent; +import android.view.Menu; +import android.view.MenuItem; +import android.view.Window; +import android.view.WindowManager; +import android.widget.TabHost; + +public class MainActivity extends TabActivity { + TabHost mTabHost; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + // 设置隐藏标题 + requestWindowFeature(Window.FEATURE_NO_TITLE); + // 设置全屏 + /* + * this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + * WindowManager.LayoutParams.FLAG_FULLSCREEN); + */ + // 显示的布局是dier + setContentView(R.layout.dier); + // 取得TabHost对象 + mTabHost = getTabHost(); + // 将类OfflineQuery赋给intent,以便连接到这个页面上 + Intent intent = new Intent().setClass(this, OfflineQuery.class); + // 新建一个newTabSpec(newTabSpec) + // 设置其标签和图标(setIndicator) + // 设置内容(setContent) + mTabHost.addTab(mTabHost.newTabSpec("tab1") + .setIndicator("", getResources().getDrawable(R.drawable.img1)) + .setContent(intent)); + Intent intent1 = new Intent().setClass(this, OnlineQuery.class); + mTabHost.addTab(mTabHost.newTabSpec("tab2") + .setIndicator("", getResources().getDrawable(R.drawable.img2)) + .setContent(intent1)); + Intent intent2 = new Intent().setClass(this, NoteBook.class); + mTabHost.addTab(mTabHost.newTabSpec("tab3") + .setIndicator("", getResources().getDrawable(R.drawable.img3)) + .setContent(intent2)); + mTabHost.setCurrentTab(0); + + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/NoteBook.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/NoteBook.java new file mode 100644 index 00000000..b3169c4e --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/NoteBook.java @@ -0,0 +1,130 @@ +package com.example.dictionary; + +import java.util.ArrayList; +import java.util.HashMap; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.AlertDialog.Builder; +import android.content.DialogInterface; +import android.content.DialogInterface.OnClickListener; +import android.content.Intent; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.SimpleAdapter; + +public class NoteBook extends Activity { + public static final int MENU_ADD = 1; + public static final int MENU_TUICHU = MENU_ADD + 1; + private ArrayList> arrayList; + private ListView listView1; + + @SuppressWarnings("unchecked") + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.note_book); + + listView1 = (ListView) findViewById(R.id.listView1); + + } + + @Override + protected void onResume() { + // TODO Auto-generated method stub + super.onResume(); + Intent intent = getIntent(); + final String word = intent.getStringExtra("word"); + final String explain = intent.getStringExtra("explain"); + arrayList = (ArrayList>) new ObjectFile() + .readObjectFile(); + if (null == arrayList) { + arrayList = new ArrayList>(); + } + if (!TextUtils.isEmpty(word) && !TextUtils.isEmpty(explain)) { + HashMap map = new HashMap(); + map.put("word", word); + map.put("explain", explain); + arrayList.add(map); + new ObjectFile().writeObjectFile(arrayList); + } + + final SimpleAdapter adapter = new SimpleAdapter(this, arrayList, + android.R.layout.simple_list_item_2, new String[] { "word", + "explain" }, new int[] { android.R.id.text1, + android.R.id.text2 }); + listView1.setAdapter(adapter); + + // 为listView1视图添加setOnItemClickListener监听 + listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() { + + @Override + public void onItemClick(AdapterView arg0, View arg1, + final int arg2, long arg3) { + // 对于选中的项进行处理 + AlertDialog.Builder builder = new Builder(NoteBook.this); + builder.setIcon(R.drawable.dialog_icon); + builder.setMessage("确认操作"); + builder.setTitle("提示"); + builder.setPositiveButton("删除", new OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + arrayList.remove(arg2); + new ObjectFile().writeObjectFile(arrayList); + adapter.notifyDataSetChanged(); + dialog.dismiss(); + + } + }); + + builder.setNeutralButton("编辑", new OnClickListener() { + public void onClick(DialogInterface dialog, int which) { +// Intent intent = new Intent(); +// Bundle bundle = new Bundle(); +// bundle.putString("word", word); +// bundle.putString("explain", explain); +// intent.putExtras(bundle); +// intent.setClass(NoteBook.this, EditWord.class); +// startActivity(intent); +// dialog.dismiss(); + } + }); + builder.setNegativeButton("取消", null).show(); + // TODO Auto-generated method stub + + } + + }); + + } + + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + menu.add(0, MENU_ADD, 0, "添加新单词"); + menu.add(0, MENU_TUICHU, 1, "退出"); + return super.onCreateOptionsMenu(menu); + } + + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case MENU_ADD: { + Intent intent = new Intent(); + Bundle bundle = new Bundle(); + bundle.putString("action", "add"); + intent.putExtras(bundle); + intent.setClass(this, EditWord.class); + startActivity(intent); + break; + } + case MENU_TUICHU: { + finish(); + } + } + return super.onOptionsItemSelected(item); + } + +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/ObjectFile.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/ObjectFile.java new file mode 100644 index 00000000..ddf6ba0a --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/ObjectFile.java @@ -0,0 +1,68 @@ +package com.example.dictionary; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + + +public class ObjectFile { + private String path = "/sdcard/word/word.txt"; + + public File createFile() { + File file = new File(path); + File parentFile = file.getParentFile(); + if (!parentFile.exists()) { + parentFile.mkdirs(); + } + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return file; + } + + public Object readObjectFile() { + ObjectInputStream mis = null; + Object mObject = null; + File file = new File(path); + if (!file.exists()) { + return null; + } else { + try { + mis = new ObjectInputStream(new FileInputStream(file)); + mObject = mis.readObject(); + mis.close(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return mObject; + } + } + public void DeleteObjectFile(Object object){ + + + } + + public boolean writeObjectFile(Object object) { + ObjectOutputStream mos = null; + try { + mos = new ObjectOutputStream(new FileOutputStream(createFile())); + mos.writeObject(object); + mos.close(); + } catch (Exception e) { + // TODO: handle exception + e.printStackTrace(); + return false; + } + return true; + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/OfflineQuery.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/OfflineQuery.java new file mode 100644 index 00000000..550b76b1 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/OfflineQuery.java @@ -0,0 +1,285 @@ +package com.example.dictionary; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; + +import com.iflytek.speech.RecognizerResult; +import com.iflytek.speech.SpeechError; +import com.iflytek.ui.RecognizerDialog; +import com.iflytek.ui.RecognizerDialogListener; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.ViewGroup; +import android.widget.AutoCompleteTextView; +import android.widget.Button; +import android.widget.CursorAdapter; +import android.widget.SimpleAdapter; +import android.widget.TextView; +import android.widget.Toast; + +public class OfflineQuery extends Activity implements OnClickListener, + TextWatcher { + public static final int MENU_ABOUT = 1; + public static final int MENU_TUICHU = MENU_ABOUT + 2; + private final String DATABASE_PATH = android.os.Environment + .getExternalStorageDirectory().getAbsolutePath() + "/dictionary"; + private AutoCompleteTextView actvWord; + private final String DATABASE_FILENAME = "dictionary.db"; + private SQLiteDatabase database; + private Button btnSelectWord; + private Button Clear; + private TextView mTextView; + private String result; + private ArrayList> arrayList; + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.offline_query); + database = openDatabase(); + btnSelectWord = (Button) findViewById(R.id.ButtonGo); + actvWord = (AutoCompleteTextView) findViewById(R.id.seek); + Clear = (Button) findViewById(R.id.clearButton); + btnSelectWord.setOnClickListener(this); + actvWord.addTextChangedListener(this); + + Clear.setOnClickListener(new Button.OnClickListener() { + public void onClick(View v) { + actvWord.setText(""); + } + }); + } + + public class DictionaryAdapter extends CursorAdapter { + private LayoutInflater layoutInflater; + + public CharSequence convertToString(Cursor cursor) { + return cursor == null ? "" : cursor.getString(cursor + .getColumnIndex("_id")); + } + + private void setView(View view, Cursor cursor) { + TextView tvWordItem = (TextView) view; + tvWordItem.setText(cursor.getString(cursor.getColumnIndex("_id"))); + tvWordItem.setPadding(15, 10, 10, 15); + tvWordItem.setTextSize(18); + } + + public DictionaryAdapter(Context context, Cursor c, boolean autoRequery) { + super(context, c, autoRequery); + // TODO Auto-generated constructor stub + layoutInflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + // TODO Auto-generated method stub + setView(view, cursor); + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + // TODO Auto-generated method stub + View view = new TextView(OfflineQuery.this); + setView(view, cursor); + return view; + } + + } + + private SQLiteDatabase openDatabase() { + try { + // 获得dictionary.db文件的绝对路径 + String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME; + File dir = new File(DATABASE_PATH); + // 如果/sdcard/dictionary目录中存在,创建这个目录 + if (!dir.exists()) + dir.mkdir(); + // 如果在/sdcard/dictionary目录中不存在 + // dictionary.db文件,则从res\raw目录中复制这个文件到 + // SD卡的目录(/sdcard/dictionary) + if (!(new File(databaseFilename)).exists()) { + // 获得封装dictionary.db文件的InputStream对象 + InputStream is = getResources().openRawResource( + R.raw.dictionary); + FileOutputStream fos = new FileOutputStream(databaseFilename); + byte[] buffer = new byte[8192]; + int count = 0; + // 开始复制dictionary.db文件 + while ((count = is.read(buffer)) > 0) { + fos.write(buffer, 0, count); + } + + fos.close(); + is.close(); + } + // 打开/sdcard/dictionary目录中的dictionary.db文件 + SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase( + databaseFilename, null); + return database; + } catch (Exception e) { + } + return null; + } + + public void afterTextChanged(Editable s) { + // 必须将english字段的别名设为_id + Cursor cursor = database.rawQuery( + "select english as _id from t_words where english like ?", + new String[] { s.toString() + "%" }); + DictionaryAdapter dictionaryAdapter = new DictionaryAdapter(this, + cursor, true); + + actvWord.setAdapter(dictionaryAdapter); + } + + public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, + int arg3) { + // TODO Auto-generated method stub + + } + + public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { + // TODO Auto-generated method stub + + } + + public void onClick(View view) { + + // TODO Auto-generated method stub + String sql = "select chinese from t_words where english=?"; + Cursor cursor = database.rawQuery(sql, new String[] { actvWord + .getText().toString() }); + result = "未找到该单词."; + // 如果查找单词,显示其中文的意思 + if (cursor.getCount() > 0) { + // 必须使用moveToFirst方法将记录指针移动到第1条记录的位置 + cursor.moveToFirst(); + result = cursor.getString(cursor.getColumnIndex("chinese")); + } + if (actvWord.getText().toString().equals("")) { + Toast.makeText(OfflineQuery.this, "查询内容不能为空!", Toast.LENGTH_LONG) + .show(); + return; + } + + // 显示查询结果对话框 + new AlertDialog.Builder(this) + .setIcon(R.drawable.dialog_icon) + .setTitle("查询结果") + .setMessage(result) + .setPositiveButton("加入生词本", + new DialogInterface.OnClickListener() { + + @SuppressWarnings("unchecked") + @Override + public void onClick(DialogInterface dialog, + int which) { + Intent intent = getIntent(); + if (!result.equals("未找到该单词.")) { + String word = actvWord.getText().toString() + .trim(); + String explain = result; + arrayList = (ArrayList>) new ObjectFile() + .readObjectFile(); + if (null == arrayList) { + arrayList = new ArrayList>(); + } + if (!TextUtils.isEmpty(word) + && !TextUtils.isEmpty(result)) { + HashMap map = new HashMap(); + map.put("word", word); + map.put("explain", result); + arrayList.add(map); + new ObjectFile() + .writeObjectFile(arrayList); + } + } + } + + }).setNegativeButton("关闭", null).show(); + SimpleAdapter adapter = new SimpleAdapter(this, arrayList, + android.R.layout.simple_list_item_2, new String[] { "word", + "explain" }, new int[] { android.R.id.text1, + android.R.id.text2 }); + } + + // 语音部分 + private static final String APPID = "appid=4f2d3a06"; + private String text = ""; + + public void say(View view) { + RecognizerDialog isrDialog = new RecognizerDialog(this, APPID); + + /* + * 设置引擎目前支持五种 ”sms”:普通文本转写 “poi”:地名搜索 ”vsearch”:热词搜索 ”video”:视频音乐搜索 + * ”asr”:命令词识别 + */ + isrDialog.setEngine("sms", null, null); + isrDialog.setListener(recoListener); + isrDialog.show(); + + } + + // 语言识别监听器,有两个方法 + RecognizerDialogListener recoListener = new RecognizerDialogListener() { + + @Override + public void onResults(ArrayList results, + boolean isLast) { + // 服务器识别完成后会返回集合,我们这里就只得到最匹配的那一项 + text = results.get(0).text; + System.out.println(text); + } + + @Override + public void onEnd(SpeechError error) { + if (error == null) { + // 完成后就把结果显示在EditText上 + actvWord.setText(text); + } + + } + }; + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + menu.add(0, MENU_ABOUT, 0, "说明"); + menu.add(0, MENU_TUICHU, 1, "退出"); + return super.onCreateOptionsMenu(menu); + } + + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case MENU_ABOUT: { + Intent intent = new Intent(); + intent.setClass(this, About.class); + startActivity(intent); + break; + } + case MENU_TUICHU: { + finish(); + } + } + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/OnlineQuery.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/OnlineQuery.java new file mode 100644 index 00000000..74b69ce1 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/OnlineQuery.java @@ -0,0 +1,120 @@ +package com.example.dictionary; + +import java.util.ArrayList; + +import com.iflytek.speech.RecognizerResult; +import com.iflytek.speech.SpeechError; +import com.iflytek.ui.RecognizerDialog; +import com.iflytek.ui.RecognizerDialogListener; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.webkit.WebView; +import android.widget.AutoCompleteTextView; +import android.widget.Button; +import android.widget.Toast; + +public class OnlineQuery extends Activity{ + private Button ButtonGo; + private AutoCompleteTextView seek; + private WebView myWebView1; + private Button clearButton; + public static final int MENU_ABOUT = 1; + public static final int MENU_TUICHU = MENU_ABOUT + 2; + +public void onCreate(Bundle savedInstanceState) +{ + super.onCreate(savedInstanceState); + setContentView(R.layout.online_query); + ButtonGo = (Button)findViewById(R.id.ButtonGo); + seek = (AutoCompleteTextView) findViewById(R.id.seek); + clearButton = (Button)findViewById(R.id.clearButton); + myWebView1 = (WebView)findViewById(R.id.myWebView1); + + ButtonGo.setOnClickListener(new Button.OnClickListener(){ + + @Override + public void onClick(View arg0) { + String strURI = (seek.getText().toString()); + strURI = strURI.trim(); + if(strURI.length()==0) + { + Toast.makeText(OnlineQuery.this, "查询内容不能为空!", Toast.LENGTH_LONG).show(); + } + else + { + String strURL = "http://dict.youdao.com/m/search?keyfrom=dict.mindex&q="+strURI; + myWebView1.loadUrl(strURL); + } + } + + }); + http://dict.youdao.com/m/serch?keyfrom=dict.mindex&vendor=%24vendor&q=happy + clearButton.setOnClickListener(new Button.OnClickListener() + { + public void onClick(View v){ + seek.setText(""); + } + }); +} +//语音部分 + private static final String APPID = "appid=4f2d3a06"; + private String text=""; + public void say(View view) { + RecognizerDialog isrDialog = new RecognizerDialog(this, APPID); + + /* + * 设置引擎目前支持五种 ”sms”:普通文本转写 “poi”:地名搜索 ”vsearch”:热词搜索 ”video”:视频音乐搜索 + * ”asr”:命令词识别 + */ + isrDialog.setEngine("sms", null, null); + isrDialog.setListener(recoListener); + isrDialog.show(); + + } + // 语言识别监听器,有两个方法 + RecognizerDialogListener recoListener = new RecognizerDialogListener() { + + @Override + public void onResults(ArrayList results, + boolean isLast) { + // 服务器识别完成后会返回集合,我们这里就只得到最匹配的那一项 + text = results.get(0).text; + System.out.println(text); + } + + @Override + public void onEnd(SpeechError error) { + if (error == null) { + // 完成后就把结果显示在EditText上 + seek.setText(text); + } + + } + }; + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + menu.add(0, MENU_ABOUT, 0, "说明"); + menu.add(0, MENU_TUICHU, 1, "退出"); + return super.onCreateOptionsMenu(menu); + } + + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case MENU_ABOUT: { + Intent intent = new Intent(); + intent.setClass(this, About.class); + startActivity(intent); + break; + } + case MENU_TUICHU: { + finish(); + } + } + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/Word.java b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/Word.java new file mode 100644 index 00000000..fea816e9 --- /dev/null +++ b/app/src/main/java/edu/hzuapps/androidworks/homeworks/com1314080901214/Word.java @@ -0,0 +1,53 @@ +package com.example.diy; +public class Word { +private String ID; +private String meanning; +private String spelling; +private String phonetic_alphabet; +private String list; + +public Word(){ + +} +public Word(String ID,String meanning,String spelling,String phonetic_alphabet,String list){ + this.ID=ID; + this.meanning=meanning; + this.spelling=spelling; + this.phonetic_alphabet=phonetic_alphabet; + this.list=list; +} +public void setID(String ID){ + this.ID=ID; +} +public String getID(){ + return ID; +} + +public void setMeanning(String meanning){ + this.meanning=meanning; +} +public String getMeanning(){ + return meanning; +} + +public void setSpelling(String spelling){ + this.spelling=spelling; +} +public String getSpelling(){ + return spelling; +} + +public void setPhonetic_alphabet(String phonetic_alphabet){ + this.phonetic_alphabet=phonetic_alphabet; +} +public String getPhonetic_alphabet(){ + return phonetic_alphabet; +} + +public void setList(String list){ + this.list=list; +} +public String getList(){ + return list; +} +} diff --git a/app/src/main/res/layout/about.xml b/app/src/main/res/layout/about.xml new file mode 100644 index 00000000..3131d1f3 --- /dev/null +++ b/app/src/main/res/layout/about.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dier.xml b/app/src/main/res/layout/dier.xml new file mode 100644 index 00000000..fe623093 --- /dev/null +++ b/app/src/main/res/layout/dier.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/edit.xml b/app/src/main/res/layout/edit.xml new file mode 100644 index 00000000..44c5e903 --- /dev/null +++ b/app/src/main/res/layout/edit.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + +