diff --git a/.classpath b/.classpath
index b09fd4a7d..0a0229bf7 100644
--- a/.classpath
+++ b/.classpath
@@ -1,7 +1,5 @@
-
-
@@ -12,5 +10,8 @@
+
+
+
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c9c419311..794557fdd 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2,7 +2,7 @@
-
+
diff --git a/project.properties b/project.properties
index 8f816735d..fd44ee5ef 100644
--- a/project.properties
+++ b/project.properties
@@ -10,4 +10,4 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
-target=android-16
+target=android-17
diff --git a/res/layout/customdialog.xml b/res/layout/customdialog.xml
new file mode 100644
index 000000000..b5402e273
--- /dev/null
+++ b/res/layout/customdialog.xml
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/res/xml/default_buttons_layout.xml b/res/xml/default_buttons_layout.xml
index 5ee91425f..3c3709a0d 100644
--- a/res/xml/default_buttons_layout.xml
+++ b/res/xml/default_buttons_layout.xml
@@ -33,15 +33,28 @@
-
+
-
+
-
+
@@ -77,7 +90,20 @@
-
+
diff --git a/src/me/guillaumin/android/osmtracker/util/UserDefinedLayoutReader.java b/src/me/guillaumin/android/osmtracker/util/UserDefinedLayoutReader.java
index 099088967..0d6e3589d 100644
--- a/src/me/guillaumin/android/osmtracker/util/UserDefinedLayoutReader.java
+++ b/src/me/guillaumin/android/osmtracker/util/UserDefinedLayoutReader.java
@@ -1,7 +1,9 @@
package me.guillaumin.android.osmtracker.util;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import me.guillaumin.android.osmtracker.OSMTracker;
import me.guillaumin.android.osmtracker.R;
@@ -14,6 +16,10 @@
import me.guillaumin.android.osmtracker.listener.TextNoteOnClickListener;
import me.guillaumin.android.osmtracker.listener.VoiceRecOnClickListener;
import me.guillaumin.android.osmtracker.service.resources.IconResolver;
+import me.plutoz.android.osmtracker.customdialog.CustomDialogElement;
+import me.plutoz.android.osmtracker.customdialog.CustomDialogElement.ElementType;
+import me.plutoz.android.osmtracker.customdialog.CustomDialogSettings;
+import me.plutoz.android.osmtracker.customdialog.CustomTagButtonOnClickListener;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@@ -236,6 +242,7 @@ private void inflateRow(TableLayout layout) throws XmlPullParserException, IOExc
String currentTagName = null;
// int eventType = parser.next();
+
while (!XmlSchema.TAG_ROW.equals(currentTagName)) {
int eventType = parser.next();
switch (eventType) {
@@ -262,8 +269,10 @@ private void inflateRow(TableLayout layout) throws XmlPullParserException, IOExc
*
* @param row
* The table row to attach the button to
+ * @throws IOException
+ * @throws XmlPullParserException
*/
- public void inflateButton(TableRow row) {
+ public void inflateButton(TableRow row) throws XmlPullParserException, IOException {
Button button = new Button(row.getContext());
button.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
TableRow.LayoutParams.FILL_PARENT, 1));
@@ -283,7 +292,40 @@ public void inflateButton(TableRow row) {
button.setText(findLabel(parser.getAttributeValue(null, XmlSchema.ATTR_LABEL), resources));
buttonIcon = iconResolver.getIcon(parser.getAttributeValue(null, XmlSchema.ATTR_ICON));
button.setOnClickListener(new TagButtonOnClickListener(currentTrackId));
- } else if (XmlSchema.ATTR_VAL_VOICEREC.equals(buttonType)) {
+ } else if (XmlSchema.ATTR_VAL_CUSTOM_TAG.equals(buttonType)){
+ // Custom dialog button
+ String label = findLabel(parser.getAttributeValue(null, XmlSchema.ATTR_LABEL), resources);
+ button.setText(label);
+ buttonIcon = iconResolver.getIcon(parser.getAttributeValue(null, XmlSchema.ATTR_ICON));
+
+ // TODO: need to parse settings from file
+ List elements = new ArrayList();
+
+ int eventType = parser.nextTag();
+ String tagName = parser.getName();
+ while(tagName.equals(XmlSchema.TAG_ELEMENT)){
+ if (eventType==XmlPullParser.START_TAG){
+ String key = parser.getAttributeValue(null, XmlSchema.ATTR_VAL_CUSTOM_TAG_ELEMENT_KEY);
+ String value = parser.getAttributeValue(null, XmlSchema.ATTR_VAL_CUSTOM_TAG_ELEMENT_VALUE);
+ String typeString = parser.getAttributeValue(null, XmlSchema.ATTR_VAL_CUSTOM_TAG_ELEMENT_TYPE);
+ ElementType type;
+ if (typeString.equals(XmlSchema.ATTR_VAL_CUSTOM_TAG_ELEMENT_TYPE_TEXT)){
+ type=ElementType.TEXT;
+ }else if (typeString.equals(XmlSchema.ATTR_VAL_CUSTOM_TAG_ELEMENT_TYPE_BOOLEAN)){
+ type=ElementType.BOOLEAN;
+ }else throw new XmlPullParserException("Unknown element type: "+typeString);
+
+ CustomDialogElement e = new CustomDialogElement(key,value,type);
+ elements.add(e);
+ }
+ eventType = parser.nextTag();
+ tagName = parser.getName();
+ }
+
+ CustomDialogSettings settings = new CustomDialogSettings(label,elements);
+
+ button.setOnClickListener(new CustomTagButtonOnClickListener(settings,currentTrackId));
+ }else if (XmlSchema.ATTR_VAL_VOICEREC.equals(buttonType)) {
// Voice record button
button.setText(resources.getString(R.string.gpsstatus_record_voicerec));
buttonIcon = resources.getDrawable(R.drawable.voice_32x32);
@@ -362,6 +404,7 @@ private static final class XmlSchema {
public static final String TAG_LAYOUT = "layout";
public static final String TAG_ROW = "row";
public static final String TAG_BUTTON = "button";
+ public static final String TAG_ELEMENT = "element";
public static final String ATTR_NAME = "name";
public static final String ATTR_TYPE = "type";
@@ -371,6 +414,12 @@ private static final class XmlSchema {
public static final String ATTR_ICONPOS = "iconpos";
public static final String ATTR_VAL_TAG = "tag";
+ public static final String ATTR_VAL_CUSTOM_TAG = "custom_tag";
+ public static final String ATTR_VAL_CUSTOM_TAG_ELEMENT_KEY = "key";
+ public static final String ATTR_VAL_CUSTOM_TAG_ELEMENT_VALUE = "value";
+ public static final String ATTR_VAL_CUSTOM_TAG_ELEMENT_TYPE = "type";
+ public static final String ATTR_VAL_CUSTOM_TAG_ELEMENT_TYPE_TEXT = "text";
+ public static final String ATTR_VAL_CUSTOM_TAG_ELEMENT_TYPE_BOOLEAN = "boolean";
public static final String ATTR_VAL_PAGE = "page";
public static final String ATTR_VAL_VOICEREC = "voicerec";
public static final String ATTR_VAL_TEXTNOTE = "textnote";
diff --git a/src/me/plutoz/android/osmtracker/customdialog/CustomDialog.java b/src/me/plutoz/android/osmtracker/customdialog/CustomDialog.java
new file mode 100644
index 000000000..d2d13a6da
--- /dev/null
+++ b/src/me/plutoz/android/osmtracker/customdialog/CustomDialog.java
@@ -0,0 +1,196 @@
+package me.plutoz.android.osmtracker.customdialog;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import me.guillaumin.android.osmtracker.OSMTracker;
+import me.guillaumin.android.osmtracker.R;
+import me.guillaumin.android.osmtracker.db.TrackContentProvider.Schema;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.Intent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.RadioGroup;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+//TODO: replace hard coded strings to resources
+public class CustomDialog extends Dialog {
+ CustomDialogSettings settings;
+ long currentTrackId;
+
+ LinearLayout elementsContainer;
+
+ Map elementsByKey;
+
+ public CustomDialog(Context context, CustomDialogSettings settings, long currentTrackId) {
+ super(context);
+ this.settings = settings;
+ this.currentTrackId = currentTrackId;
+
+ this.setContentView(buildContent(context,settings));
+ this.setTitle(settings.getLabel());
+ }
+
+ private View buildContent(Context context, CustomDialogSettings settings){
+ LayoutInflater li = LayoutInflater.from(context);
+ RelativeLayout root = (RelativeLayout) li.inflate(R.layout.customdialog, null);
+
+ this.elementsContainer = (LinearLayout) root.findViewById(R.id.custom_dialog_elements);
+ this.elementsByKey = new HashMap();
+
+ //add each elements to dialog from settings
+ for(CustomDialogElement de : settings.elements){
+ elementsContainer.addView(buildElement(context,de));
+ }
+
+ //set save and cancel button actions
+ Button cancelButton = (Button) root.findViewById(R.id.custom_dialog_cancelButton);
+ cancelButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ dismiss();
+ }
+ });
+
+ Button saveButton = (Button) root.findViewById(R.id.custom_dialog_saveButton);
+ saveButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ onSaveButtonClick();
+ }
+ });
+ return root;
+ }
+
+ private View buildElement(Context context, CustomDialogElement element){
+ switch (element.type){
+ case TEXT:{
+ LinearLayout result = new LinearLayout(context);
+ result.setOrientation(LinearLayout.VERTICAL);
+
+ TextView title = new TextView(context);
+ title.setText(element.getKey());
+
+ EditText value = new EditText(context);
+ value.setText(element.value);
+
+ result.addView(title);
+ result.addView(value);
+
+ elementsByKey.put(element.key, value);
+
+ return result;
+ }
+ case BOOLEAN:{
+ LinearLayout result = new LinearLayout(context);
+ result.setOrientation(LinearLayout.VERTICAL);
+
+ TextView title = new TextView(context);
+ title.setText(element.getKey());
+
+ RadioGroup rGroup = new RadioGroup(context);
+ rGroup.setOrientation(RadioGroup.HORIZONTAL);
+
+ RadioButton r1 = new RadioButton(context);
+ RadioButton r2 = new RadioButton(context);
+ RadioButton r3 = new RadioButton(context);
+
+ r1.setText("Yes");
+ r2.setText("No");
+ r3.setText("N/A");
+
+ rGroup.addView(r1);
+ rGroup.addView(r2);
+ rGroup.addView(r3);
+
+ //TODO: remove hard coded values
+ if (element.getValue()!=null){
+ if(element.getValue().equals("yes")) r1.setChecked(true);
+ else if (element.getValue().equals("no")) r2.setChecked(true);
+ else r3.setChecked(true);
+ }
+ else r3.setChecked(true);
+
+ result.addView(title);
+ result.addView(rGroup);
+
+ elementsByKey.put(element.key, rGroup);
+
+ return result;
+ }
+ default:{
+ TextView result = new TextView(context);
+ result.setText("Unknown property type");
+ return result;
+ }
+ }
+ }
+
+ public String getContent(){
+ StringBuilder sb = new StringBuilder();
+ //add POI key-pair
+ sb.append(settings.getLabel());
+ sb.append(": ");
+
+ //process additional fields
+ for (String key : elementsByKey.keySet()){
+ View v = elementsByKey.get(key);
+
+ if(v instanceof TextView){
+ TextView tv = (TextView) v;
+ String value = tv.getText().toString();
+ if(value.length()>0){
+ sb.append(key);
+ sb.append("= ");
+ sb.append(value);
+ sb.append("; ");
+ }
+ }
+
+ else if(v instanceof RadioGroup){
+ RadioGroup rg = (RadioGroup) v;
+ int checkedId = rg.getCheckedRadioButtonId();
+ View activeButton = rg.findViewById(checkedId);
+ int checkedIndex = rg.indexOfChild(activeButton);
+
+ switch (checkedIndex){
+ case 0:{
+ sb.append(key);
+ sb.append("= yes; ");
+ break;
+ }
+ case 1:{
+ sb.append(key);
+ sb.append("= no; ");
+ break;
+ }
+ }
+ }
+
+ }
+ return sb.toString();
+ }
+
+ private void onSaveButtonClick(){
+ String label = getContent().replaceAll("\n", " ");
+
+ // Send an intent to inform service to track the waypoint.
+ Intent intent = new Intent(OSMTracker.INTENT_TRACK_WP);
+ intent.putExtra(Schema.COL_TRACK_ID, currentTrackId);
+ intent.putExtra(OSMTracker.INTENT_KEY_NAME, label);
+ getContext().sendBroadcast(intent);
+
+ // Inform user that the waypoint was tracked
+ Toast.makeText(getContext(), getContext().getResources().getString(R.string.tracklogger_tracked) + " " + label, Toast.LENGTH_SHORT).show();
+ dismiss();
+ }
+}
diff --git a/src/me/plutoz/android/osmtracker/customdialog/CustomDialogElement.java b/src/me/plutoz/android/osmtracker/customdialog/CustomDialogElement.java
new file mode 100644
index 000000000..b8ab643f4
--- /dev/null
+++ b/src/me/plutoz/android/osmtracker/customdialog/CustomDialogElement.java
@@ -0,0 +1,44 @@
+package me.plutoz.android.osmtracker.customdialog;
+
+public class CustomDialogElement {
+ public enum ElementType{
+ TEXT,
+ BOOLEAN
+ }
+
+ protected String key;
+ protected String value;
+ protected ElementType type;
+
+ public CustomDialogElement(String key, String value, ElementType type) {
+ super();
+ this.key = key;
+ this.value = value;
+ this.type = type;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public ElementType getType() {
+ return type;
+ }
+
+ public void setType(ElementType type) {
+ this.type = type;
+ }
+}
+
diff --git a/src/me/plutoz/android/osmtracker/customdialog/CustomDialogSettings.java b/src/me/plutoz/android/osmtracker/customdialog/CustomDialogSettings.java
new file mode 100644
index 000000000..3476db104
--- /dev/null
+++ b/src/me/plutoz/android/osmtracker/customdialog/CustomDialogSettings.java
@@ -0,0 +1,30 @@
+package me.plutoz.android.osmtracker.customdialog;
+
+import java.util.List;
+
+public class CustomDialogSettings {
+ protected String label;
+ protected List elements;
+
+ public CustomDialogSettings(String label, List elements) {
+ super();
+ this.label = label;
+ this.elements = elements;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public void setLabel(String label) {
+ this.label = label;
+ }
+
+ public List getElements() {
+ return elements;
+ }
+
+ public void setElements(List elements) {
+ this.elements = elements;
+ }
+}
diff --git a/src/me/plutoz/android/osmtracker/customdialog/CustomTagButtonOnClickListener.java b/src/me/plutoz/android/osmtracker/customdialog/CustomTagButtonOnClickListener.java
new file mode 100644
index 000000000..c89616d83
--- /dev/null
+++ b/src/me/plutoz/android/osmtracker/customdialog/CustomTagButtonOnClickListener.java
@@ -0,0 +1,30 @@
+package me.plutoz.android.osmtracker.customdialog;
+
+import me.guillaumin.android.osmtracker.R;
+import android.app.AlertDialog;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+public class CustomTagButtonOnClickListener implements OnClickListener {
+
+ CustomDialogSettings settings;
+ long currentTrackId;
+
+
+ public CustomTagButtonOnClickListener(CustomDialogSettings settings, long currentTrackId) {
+ super();
+ this.settings = settings;
+ this.currentTrackId = currentTrackId;
+ }
+
+ @Override
+ public void onClick(View v) {
+ CustomDialog cd = new CustomDialog(v.getContext(), settings, currentTrackId);
+ cd.show();
+ }
+
+}