Permalink
Browse files

remove duplicate time which is returned by speech recognition

  • Loading branch information...
1 parent dd6f082 commit 72d4158b57b9fe16f82f0a06a09f73c752a33c96 @mamewotoko committed May 14, 2012
Showing with 34 additions and 22 deletions.
  1. +3 −5 README.md
  2. +31 −17 src/com/mamewo/malarm24/MalarmActivity.java
View
@@ -53,35 +53,33 @@ You can change path to playlist and music files by "Playlist directory" preferen
## TODO
- implement music player as Service to play long time
+- change webview into photo view, movie player...
- Design for tablets
- support HVGA, WVGA, WVGA+ resolution
-- http://developer.android.com/resources/dashboard/screens.html
-- hide time picker after malarm is set? (or count down?)
-- scale of web contents
- localize: French, Chinese
- add mode to display alert dialog if device is not charged when alarm is set
+- improve UI to edit playlist
- refactor class design, activity, player and playlist
- show notification while playing music
- fix UI update bug when sleep timer expires (broadcast -> activity)
-- remove duplicate time from list which is specified by voice
- conditional playlist
-- Sunday, holiday playlist etc...
- make COOL widget to set alarm (make clock widget?)
-- improve UI to edit playlist
- add more test cases
-- double touch of webview
-- label text is updated when music is stopped or alarm is canceled
-- check default config value
--- test landscape mode
- fix vibrator timing
-- fix bug when native player is used....
-- change webview into photo view, movie player...
- add source of malarm_test into this repository
- refactor code to clear browser history
- support podcast
- use Actionbar ?
- record wakeup time?
- support shuffle?
+- fix bug when native player is used....
## Appendix
### How To Build From Command Line
@@ -13,7 +13,10 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.app.Activity;
@@ -896,15 +899,17 @@ public TimePickerTime(int hour, int min, String speach) {
}
}
- private class ClickListener implements DialogInterface.OnClickListener {
- private ArrayList<TimePickerTime> mTimeList;
+ private class ClickListener
+ implements DialogInterface.OnClickListener
+ {
+ private TimePickerTime[] mTimeList;
- public ClickListener(ArrayList<TimePickerTime> time) {
+ public ClickListener(TimePickerTime[] time) {
mTimeList = time;
}
@Override
public void onClick(DialogInterface dialog, int which) {
- setTimePickerTime(mTimeList.get(which));
+ setTimePickerTime(mTimeList[which]);
}
}
@@ -921,9 +926,10 @@ private void setTimePickerTime(TimePickerTime time) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SPEECH_RECOGNITION_REQUEST_CODE && resultCode == RESULT_OK) {
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
- ArrayList<TimePickerTime> result = new ArrayList<TimePickerTime>();
- for (String speach : matches) {
- Matcher m = TIME_PATTERN.matcher(speach);
+ //ArrayList<TimePickerTime> result = new ArrayList<TimePickerTime>();
+ Map<String, TimePickerTime> result = new HashMap<String, TimePickerTime>();
+ for (String speech : matches) {
+ Matcher m = TIME_PATTERN.matcher(speech);
if (m.matches()) {
int hour = Integer.valueOf(m.group(1)) % 24;
int minute;
@@ -937,10 +943,13 @@ else if ("半".equals(min_part)) {
else {
minute = Integer.valueOf(m.group(3)) % 60;
}
- result.add(new TimePickerTime(hour, minute, speach));
+ String key = hour + ":" + minute;
+ if(! result.containsKey(key)){
+ result.put(key, new TimePickerTime(hour, minute, speech));
+ }
}
else {
- Matcher m2 = AFTER_TIME_PATTERN.matcher(speach);
+ Matcher m2 = AFTER_TIME_PATTERN.matcher(speech);
if (m2.matches()) {
final String hour_part = m2.group(2);
final String min_part = m2.group(3);
@@ -962,27 +971,32 @@ else if ("半".equals(min_part)) {
}
final Calendar cal = new GregorianCalendar();
cal.setTimeInMillis(System.currentTimeMillis() + after_millis);
- result.add(new TimePickerTime(cal.get(Calendar.HOUR_OF_DAY),
- cal.get(Calendar.MINUTE), speach));
+ int hour = cal.get(Calendar.HOUR_OF_DAY);
+ int min = cal.get(Calendar.MINUTE);
+ String key = hour + ":" + min;
+ if(!result.containsKey(key)){
+ result.put(key, new TimePickerTime(hour, min, speech));
+ }
}
}
}
if (result.isEmpty()) {
showMessage(this, getString(R.string.voice_fail));
}
else if (result.size() == 1) {
- setTimePickerTime(result.get(0));
+ setTimePickerTime(result.values().iterator().next());
}
else {
- String [] speach_array = new String[result.size()];
- for (int i = 0; i < result.size(); i++) {
- TimePickerTime time = result.get(i);
- speach_array[i] = time.mSpeach + String.format(" (%02d:%02d)", time.mHour, time.mMin);
+ String [] speechArray = new String[result.size()];
+ Iterator<TimePickerTime> iter = result.values().iterator();
+ for(int i = 0; i < result.size(); i++){
+ TimePickerTime time = iter.next();
+ speechArray[i] = time.mSpeach + String.format(" (%02d:%02d)", time.mHour, time.mMin);
}
//select from list dialog
new AlertDialog.Builder(this)
.setTitle(R.string.select_time_from_list)
- .setItems(speach_array, new ClickListener(result))
+ .setItems(speechArray, new ClickListener(result.values().toArray(new TimePickerTime[0])))
.create()
.show();
}

0 comments on commit 72d4158

Please sign in to comment.