Michael Champanis avatar Michael Champanis committed c409f65

New question type files

Comments (0)

Files changed (2)

j2me/form-entry/src/org/javarosa/formmanager/view/singlequestionscreen/screen/DateManualQuestionScreen.java

+/*
+ * Copyright (C) 2009 JavaRosa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.javarosa.formmanager.view.singlequestionscreen.screen;
+
+import java.util.Date;
+import java.util.Vector;
+
+import javax.microedition.lcdui.TextField;
+
+import org.javarosa.core.model.data.DateData;
+import org.javarosa.core.model.data.IAnswerData;
+import org.javarosa.core.model.data.StringData;
+import org.javarosa.core.model.utils.DateUtils;
+import org.javarosa.core.model.utils.DateUtils.DateFields;
+import org.javarosa.core.services.locale.Localization;
+import org.javarosa.form.api.FormEntryPrompt;
+
+import de.enough.polish.ui.StringItem;
+import de.enough.polish.ui.Style;
+import de.enough.polish.util.Locale;
+
+public class DateManualQuestionScreen extends SingleQuestionScreen {
+
+	protected StringItem label;
+	protected TextField tfDay, tfMonth, tfYear;
+	protected String delimiter;
+
+	public DateManualQuestionScreen(FormEntryPrompt prompt, String groupName, Style style) {
+		super(prompt, groupName, style);
+	}
+
+	public void createView() {
+		delimiter = "/";
+		
+		//#style textBox
+		tfDay = new TextField("", "", 50, TextField.NUMERIC);
+		//#style textBox
+		tfMonth= new TextField("", "", 200, TextField.NUMERIC);
+		//#style textBox
+		tfYear = new TextField("", "", 200, TextField.NUMERIC);
+		
+		tfDay.setLabel(Localization.get("formview.question.datemanual.day"));
+		tfMonth.setLabel(Localization.get("formview.question.datemanual.month"));
+		tfYear.setLabel(Localization.get("formview.question.datemanual.year"));		
+		
+		if (prompt.isRequired()) {
+			label = new StringItem("", "*" + prompt.getLongText());
+		} else {
+			label = new StringItem("", prompt.getLongText());
+		}
+
+		IAnswerData answerData = prompt.getAnswerValue();
+		
+		if ((answerData != null) && (answerData instanceof DateData)) {	
+			DateFields df = DateUtils.getFields((Date)(((DateData)answerData).getValue()));		
+			
+			tfDay.setString(String.valueOf(df.day));
+			tfMonth.setString(String.valueOf(df.month));
+			tfYear.setString(String.valueOf(df.year));
+		} else {
+			tfYear.setString(String.valueOf(DateUtils.getFields(new Date()).year));
+		}
+		
+		this.append(label);
+		this.append(tfDay);
+		this.append(tfMonth);
+		this.append(tfYear);
+		
+		this.addNavigationWidgets();
+		if (prompt.getHelpText() != null) {
+			setHint(prompt.getHelpText());
+		}
+	}
+
+	public IAnswerData getWidgetValue() {
+		String day = (tfDay.getString() != null) ? tfDay.getString() : "";
+		String month = (tfMonth.getString() != null) ? tfMonth.getString() : "";
+		String year = (tfYear.getString() != null) ? tfYear.getString() : "";
+		
+		if (!day.equals("") && !month.equals("") && !year.equals("")) {
+			Date ret = DateUtils.parseDate(year + "-" + month + "-" + day);
+			
+			if (ret != null) {
+				return new DateData(ret);
+			}
+		} 
+
+		return null;
+	}
+
+}

j2me/form-entry/src/org/javarosa/formmanager/view/singlequestionscreen/screen/ThreeCodeQuestionScreen.java

+/*
+ * Copyright (C) 2009 JavaRosa
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package org.javarosa.formmanager.view.singlequestionscreen.screen;
+
+import java.util.Vector;
+
+import javax.microedition.lcdui.TextField;
+
+import org.javarosa.core.model.data.IAnswerData;
+import org.javarosa.core.model.data.StringData;
+import org.javarosa.core.model.utils.DateUtils;
+import org.javarosa.form.api.FormEntryPrompt;
+
+import de.enough.polish.ui.StringItem;
+import de.enough.polish.ui.Style;
+
+public class ThreeCodeQuestionScreen extends SingleQuestionScreen {
+
+	protected StringItem label;
+	protected TextField tfCode1, tfCode2, tfCode3;
+	protected String delimiter;
+
+	public ThreeCodeQuestionScreen(FormEntryPrompt prompt, String groupName, Style style) {
+		super(prompt, groupName, style);
+	}
+
+	public void createView() {
+		delimiter = "/";
+		
+		//#style textBox
+		tfCode1 = new TextField("", "", 200, TextField.NUMERIC);
+		//#style textBox
+		tfCode2 = new TextField("", "", 200, TextField.NUMERIC);
+		//#style textBox
+		tfCode3 = new TextField("", "", 200, TextField.NUMERIC);
+		
+		tfCode2.setLabel(delimiter);
+		tfCode3.setLabel(delimiter);
+		
+		if (prompt.isRequired()) {
+			label = new StringItem("", "*" + prompt.getLongText());
+		} else {
+			label = new StringItem("", prompt.getLongText());
+		}
+
+		IAnswerData answerData = prompt.getAnswerValue();
+		
+		if ((answerData != null) && (answerData instanceof StringData)) {
+			String answer = ((StringData)answerData).getDisplayText();		
+			
+			if (answer != null && answer.length() > 0) {
+				Vector<String> split = DateUtils.split(answer, delimiter, false); 
+
+				tfCode1.setString(split.elementAt(0));
+				tfCode2.setString(split.elementAt(1));
+				tfCode3.setString(split.elementAt(2));						
+			}
+		}		
+		
+		this.append(label);
+		this.append(tfCode1);
+		this.append(tfCode2);
+		this.append(tfCode3);
+		
+		this.addNavigationWidgets();
+		if (prompt.getHelpText() != null) {
+			setHint(prompt.getHelpText());
+		}
+	}
+
+	public IAnswerData getWidgetValue() {
+		String code1 = (tfCode1.getString() != null) ? tfCode1.getString() : "";
+		String code2 = (tfCode2.getString() != null) ? tfCode2.getString() : "";
+		String code3 = (tfCode3.getString() != null) ? tfCode3.getString() : "";
+		
+		String value = "";
+			
+		int i;
+
+		try {		
+			i = Integer.parseInt(code1);
+		} catch (NumberFormatException nfe) {
+			code1 = "";
+		}			
+
+		try {		
+			i = Integer.parseInt(code2);
+		} catch (NumberFormatException nfe) {
+			code2 = "";
+		}			
+
+		try {		
+			i = Integer.parseInt(code3);
+		} catch (NumberFormatException nfe) {
+			code3 = "";
+		}			
+		
+		if (code1.equals("") && code2.equals("") && code3.equals("")) {
+			return null;
+		} else {
+			value = code1 + delimiter + code2 + delimiter + code3;
+		} 
+
+		return new StringData(value);
+	}
+
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.