mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
git-svn-id: https://zxing.googlecode.com/svn/trunk@868 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
b24fbdd7b0
commit
0c4c9fdb81
|
@ -40,9 +40,9 @@ import java.util.Date;
|
|||
* @author Yohann Coppel
|
||||
*/
|
||||
public class CalendarEventGenerator implements GeneratorSource {
|
||||
public final static String[] FULL_DAY_ONLY_IDS = { "fullDayOnlyInfo1",
|
||||
public static final String[] FULL_DAY_ONLY_IDS = { "fullDayOnlyInfo1",
|
||||
"fullDayOnlyInfo2", "fullDayOnlyInfo3", "fullDayOnlyInfo4" };
|
||||
private final static long ONE_HOUR = 60 * 60 * 1000;
|
||||
private static final long ONE_HOUR = 60L * 60 * 1000;
|
||||
|
||||
Grid table = null;
|
||||
TextBox eventName = new TextBox();
|
||||
|
@ -77,7 +77,7 @@ public class CalendarEventGenerator implements GeneratorSource {
|
|||
Date time2 = timePicker2.getDateTime();
|
||||
if (time2.after(time)) {
|
||||
// keep the same time difference if the interval is valid.
|
||||
long diff = timeDifference(time, time2);
|
||||
long diff = time2.getTime() - time.getTime();
|
||||
timePicker2.setDateTime(addMilliseconds(time1, diff));
|
||||
} else {
|
||||
// otherwise erase the end date and set it to startdate + one hour.
|
||||
|
@ -98,8 +98,7 @@ public class CalendarEventGenerator implements GeneratorSource {
|
|||
|
||||
private void buildTimeZoneList() {
|
||||
for (TimeZoneInfo info : TimeZoneList.TIMEZONES) {
|
||||
timeZones.addItem(info.GMTRelative + " " + info.abreviation, ""
|
||||
+ info.gmtDiff);
|
||||
timeZones.addItem(info.GMTRelative + ' ' + info.abreviation, String.valueOf(info.gmtDiff));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,10 +156,7 @@ public class CalendarEventGenerator implements GeneratorSource {
|
|||
private void setFullDay(boolean fullDay) {
|
||||
for (String s : FULL_DAY_ONLY_IDS) {
|
||||
Element element = DOM.getElementById(s);
|
||||
String style = "";
|
||||
if (fullDay) {
|
||||
style = "none";
|
||||
}
|
||||
String style = fullDay ? "none" : "";
|
||||
DOM.setStyleAttribute(element, "display", style);
|
||||
}
|
||||
}
|
||||
|
@ -168,13 +164,12 @@ public class CalendarEventGenerator implements GeneratorSource {
|
|||
public String getText() throws GeneratorException {
|
||||
String eventName = getEventNameField();
|
||||
String dates = getDateTimeFields();
|
||||
|
||||
String output = "";
|
||||
output += "BEGIN:VEVENT\n";
|
||||
output += eventName;
|
||||
output += dates;
|
||||
output += "END:VEVENT\n";
|
||||
return output;
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("BEGIN:VEVENT\r\n");
|
||||
output.append(eventName);
|
||||
output.append(dates);
|
||||
output.append("END:VEVENT\r\n");
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private String getEventNameField() throws GeneratorException {
|
||||
|
@ -186,7 +181,7 @@ public class CalendarEventGenerator implements GeneratorSource {
|
|||
throw new GeneratorException(
|
||||
"Event name should not contain \\n characters.");
|
||||
}
|
||||
return "SUMMARY:" + inputName + "\n";
|
||||
return "SUMMARY:" + inputName + "\r\n";
|
||||
}
|
||||
|
||||
private String getDateTimeFields() throws GeneratorException {
|
||||
|
@ -206,10 +201,14 @@ public class CalendarEventGenerator implements GeneratorSource {
|
|||
throw new GeneratorException("Ending date is after starting date.");
|
||||
}
|
||||
DateTimeFormat isoFormatter = DateTimeFormat.getFormat("yyyyMMdd");
|
||||
String output = "";
|
||||
output += "DTSTART:" + isoFormatter.format(date1) + "\n";
|
||||
output += "DTEND:" + isoFormatter.format(date2) + "\n";
|
||||
return output;
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("DTSTART:");
|
||||
output.append(isoFormatter.format(date1));
|
||||
output.append("\r\n");
|
||||
output.append("DTEND:");
|
||||
output.append(isoFormatter.format(date2));
|
||||
output.append("\r\n");
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private String getDateTimeValues() throws GeneratorException {
|
||||
|
@ -233,40 +232,41 @@ public class CalendarEventGenerator implements GeneratorSource {
|
|||
throw new GeneratorException("Ending date is after starting date.");
|
||||
}
|
||||
DateTimeFormat isoFormatter = DateTimeFormat
|
||||
.getFormat("yyyyMMdd'T'kkmmss'Z'");
|
||||
String output = "";
|
||||
output += "DTSTART:" + isoFormatter.format(dateTime1) + "\n";
|
||||
output += "DTEND:" + isoFormatter.format(dateTime2) + "\n";
|
||||
return output;
|
||||
.getFormat("yyyyMMdd'T'HHmmss'Z'");
|
||||
StringBuilder output = new StringBuilder();
|
||||
output.append("DTSTART:");
|
||||
output.append(isoFormatter.format(dateTime1));
|
||||
output.append("\r\n");
|
||||
output.append("DTEND:");
|
||||
output.append(isoFormatter.format(dateTime2));
|
||||
output.append("\r\n");
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private Date mergeDateAndTime(Date date, Date time) {
|
||||
private static Date mergeDateAndTime(Date date, Date time) {
|
||||
// Is that the only ugly way to do with GWT ? given that we don't
|
||||
// have java.util.Calendar for instance
|
||||
DateTimeFormat extractDate = DateTimeFormat.getFormat("yyyyMMdd");
|
||||
DateTimeFormat extractTime = DateTimeFormat.getFormat("kkmm");
|
||||
DateTimeFormat merger = DateTimeFormat.getFormat("yyyyMMddkkmmss");
|
||||
DateTimeFormat extractTime = DateTimeFormat.getFormat("HHmm");
|
||||
DateTimeFormat merger = DateTimeFormat.getFormat("yyyyMMddHHmmss");
|
||||
String d = extractDate.format(date);
|
||||
String t = extractTime.format(time) + "00";
|
||||
return merger.parse(d + t);
|
||||
}
|
||||
|
||||
public void validate(Widget widget) throws GeneratorException {
|
||||
if (widget == eventName)
|
||||
if (widget == eventName) {
|
||||
getEventNameField();
|
||||
if (widget == datePicker1 || widget == timePicker1 || widget == datePicker2
|
||||
|| widget == timePicker2)
|
||||
} else if (widget == datePicker1 || widget == timePicker1 || widget == datePicker2
|
||||
|| widget == timePicker2) {
|
||||
getDateTimeFields();
|
||||
}
|
||||
}
|
||||
|
||||
private static Date addMilliseconds(Date time1, long milliseconds) {
|
||||
return new Date(time1.getTime() + milliseconds);
|
||||
}
|
||||
|
||||
private static long timeDifference(Date time1, Date time2) {
|
||||
return time2.getTime() - time1.getTime();
|
||||
}
|
||||
|
||||
public void setFocus() {
|
||||
eventName.setFocus(true);
|
||||
}
|
||||
|
|
|
@ -66,7 +66,9 @@ public class EmailGenerator implements GeneratorSource {
|
|||
}
|
||||
|
||||
public void validate(Widget widget) throws GeneratorException {
|
||||
if (widget == email) getEmailField();
|
||||
if (widget == email) {
|
||||
getEmailField();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFocus() {
|
||||
|
|
|
@ -80,11 +80,11 @@ public class GeoLocationGenerator implements GeneratorSource, ChangeListener {
|
|||
String lat = getLatitudeField();
|
||||
String lon = getLongitudeField();
|
||||
|
||||
if (que.length() > 0) {
|
||||
return "geo:"+lat+","+lon+"?q="+que;
|
||||
if (null != que && que.length() > 0) {
|
||||
return "geo:"+lat+ ',' +lon+"?q="+que;
|
||||
}
|
||||
|
||||
return "geo:"+lat+","+lon;
|
||||
return "geo:"+lat+ ',' +lon;
|
||||
}
|
||||
|
||||
private String getQueryField() {
|
||||
|
@ -159,16 +159,16 @@ public class GeoLocationGenerator implements GeneratorSource, ChangeListener {
|
|||
}
|
||||
|
||||
protected void mapClick(MapClickEvent event) {
|
||||
latitude.setText("" + event.getLatLng().getLatitude());
|
||||
longitude.setText("" + event.getLatLng().getLongitude());
|
||||
latitude.setText(String.valueOf(event.getLatLng().getLatitude()));
|
||||
longitude.setText(String.valueOf(event.getLatLng().getLongitude()));
|
||||
setMapMarker(event.getLatLng().getLatitude(), event.getLatLng().getLongitude(), false);
|
||||
changeListener.onChange(latitude);
|
||||
changeListener.onChange(longitude);
|
||||
}
|
||||
|
||||
protected void mapMarkerMoved() {
|
||||
latitude.setText("" + mapMarker.getLatLng().getLatitude());
|
||||
longitude.setText("" + mapMarker.getLatLng().getLongitude());
|
||||
latitude.setText(String.valueOf(mapMarker.getLatLng().getLatitude()));
|
||||
longitude.setText(String.valueOf(mapMarker.getLatLng().getLongitude()));
|
||||
changeListener.onChange(latitude);
|
||||
changeListener.onChange(longitude);
|
||||
}
|
||||
|
@ -216,17 +216,17 @@ public class GeoLocationGenerator implements GeneratorSource, ChangeListener {
|
|||
String lat = "";
|
||||
String lon = "";
|
||||
if (link.matches(".*&s?ll=[^&]*&.*")) {
|
||||
boolean beforeComa = true;
|
||||
int start = 0;
|
||||
int start;
|
||||
if (link.indexOf("&sll=") == -1) {
|
||||
start = link.indexOf("&ll=") + 4;
|
||||
} else {
|
||||
start = link.indexOf("&sll=") + 5;
|
||||
}
|
||||
boolean beforeComma = true;
|
||||
for (int i = start; i < link.length() && link.charAt(i) != '&'; ++i) {
|
||||
if (beforeComa) {
|
||||
if (beforeComma) {
|
||||
if (link.charAt(i) == ',') {
|
||||
beforeComa = false;
|
||||
beforeComma = false;
|
||||
} else {
|
||||
lat += link.charAt(i);
|
||||
}
|
||||
|
@ -245,8 +245,12 @@ public class GeoLocationGenerator implements GeneratorSource, ChangeListener {
|
|||
}
|
||||
|
||||
public void validate(Widget widget) throws GeneratorException {
|
||||
if (widget == latitude) getLatitudeField();
|
||||
if (widget == longitude) getLongitudeField();
|
||||
if (widget == latitude) {
|
||||
getLatitudeField();
|
||||
}
|
||||
if (widget == longitude) {
|
||||
getLongitudeField();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFocus() {
|
||||
|
|
|
@ -67,7 +67,9 @@ public class PhoneNumberGenerator implements GeneratorSource {
|
|||
}
|
||||
|
||||
public void validate(Widget widget) throws GeneratorException {
|
||||
if (widget == number) getTelField();
|
||||
if (widget == number) {
|
||||
getTelField();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFocus() {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class SmsAddressGenerator implements GeneratorSource {
|
|||
String output = inputNumber;
|
||||
// we add the text only if there actually is something in the field.
|
||||
if (inputMessage.length() > 0) {
|
||||
output += ":" + inputMessage;
|
||||
output += ':' + inputMessage;
|
||||
}
|
||||
|
||||
return "smsto:" + output;
|
||||
|
@ -90,8 +90,12 @@ public class SmsAddressGenerator implements GeneratorSource {
|
|||
}
|
||||
|
||||
public void validate(Widget widget) throws GeneratorException {
|
||||
if (widget == number) getTelField();
|
||||
if (widget == message) getMessageField();
|
||||
if (widget == number) {
|
||||
getTelField();
|
||||
}
|
||||
if (widget == message) {
|
||||
getMessageField();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFocus() {
|
||||
|
|
|
@ -41,8 +41,7 @@ public class TextGenerator implements GeneratorSource {
|
|||
}
|
||||
|
||||
public String getText() throws GeneratorException {
|
||||
String message = getTextField();
|
||||
return message;
|
||||
return getTextField();
|
||||
}
|
||||
|
||||
public String getTextField() throws GeneratorException {
|
||||
|
@ -73,7 +72,9 @@ public class TextGenerator implements GeneratorSource {
|
|||
}
|
||||
|
||||
public void validate(Widget widget) throws GeneratorException {
|
||||
if (widget == text) getTextField();
|
||||
if (widget == text) {
|
||||
getTextField();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFocus() {
|
||||
|
|
|
@ -37,8 +37,8 @@ public class TimeZoneList {
|
|||
}
|
||||
}
|
||||
|
||||
private final static long ONE_HOUR = 60*60*1000;
|
||||
private final static long THIRTY_MIN = 30*60*1000;
|
||||
private static final long ONE_HOUR = 60L*60*1000;
|
||||
private static final long THIRTY_MIN = 30L*60*1000;
|
||||
|
||||
public static final TimeZoneInfo[] TIMEZONES = {
|
||||
new TimeZoneInfo("GMT", "Greenwich Mean Time", "GMT", 0 * ONE_HOUR + 0 * THIRTY_MIN), // 0
|
||||
|
|
|
@ -57,8 +57,7 @@ public class UrlGenerator implements GeneratorSource {
|
|||
}
|
||||
|
||||
public String getText() throws GeneratorException {
|
||||
String input = getUrlField();
|
||||
return input;
|
||||
return getUrlField();
|
||||
}
|
||||
|
||||
private String getUrlField() throws GeneratorException {
|
||||
|
@ -68,7 +67,9 @@ public class UrlGenerator implements GeneratorSource {
|
|||
}
|
||||
|
||||
public void validate(Widget widget) throws GeneratorException {
|
||||
if (widget == url) getUrlField();
|
||||
if (widget == url) {
|
||||
getUrlField();
|
||||
}
|
||||
}
|
||||
|
||||
public void setFocus() {
|
||||
|
|
Loading…
Reference in a new issue