Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: custom dialog #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/osmdroid-android-3.0.8.jar"/>
<classpathentry kind="lib" path="libs/slf4j-android-1.5.8.jar"/>
@@ -12,5 +10,8 @@
<classpathentry kind="lib" path="libs/httpclient-4.2.1.jar"/>
<classpathentry kind="lib" path="libs/httpcore-4.2.1.jar"/>
<classpathentry kind="lib" path="libs/httpmime-4.2.1.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry kind="output" path="bin/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="me.guillaumin.android.osmtracker"
android:versionName="0.6.4" android:versionCode="28" android:installLocation="auto">

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16"/>
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
2 changes: 1 addition & 1 deletion project.properties
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions res/layout/customdialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:padding="6dp" >

<LinearLayout
android:id="@+id/custom_dialog_button_holder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">

<Button
android:id="@+id/custom_dialog_cancelButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"/>

<Button
android:id="@+id/custom_dialog_saveButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
</LinearLayout>

<ScrollView
android:id="@+id/custom_dialog_scrollview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/custom_dialog_button_holder"
android:fillViewport="true">

<LinearLayout
android:id="@+id/custom_dialog_elements"
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>



</RelativeLayout>
34 changes: 30 additions & 4 deletions res/xml/default_buttons_layout.xml
Original file line number Diff line number Diff line change
@@ -33,15 +33,28 @@
<row>
<button type="tag" label="@string/tag.misc_bus_stop" icon="button_misc_bus_stop" />
<button type="tag" label="@string/tag.misc_railway" icon="button_misc_railway" />
<button type="tag" label="@string/tag.misc_telephone" icon="button_misc_telephone" />
<button type="custom_tag" label="@string/tag.misc_telephone" icon="button_misc_telephone">
<element key="phone" type="text"/>
<element key="operator" type="text"/>
<element key="ref" type="text"/>
<element key="covered" type="boolean"/>
<element key="fee" type="boolean" value="yes"/>
</button>
</row>
<row>
<button type="tag" label="@string/tag.misc_post_box" icon="button_misc_post_box" />
<button type="tag" label="@string/tag.misc_atm" icon="button_misc_atm" />
<button type="custom_tag" label="@string/tag.misc_atm" icon="button_misc_atm">
<element key="operator" type="text"/>
<element key="cash_in" type="boolean"/>
</button>
<button type="tag" label="@string/tag.misc_bollard" icon="button_misc_bollard" />
</row>
<row>
<button type="tag" label="@string/tag.misc_toilets" icon="button_misc_toilets" />
<button type="custom_tag" label="@string/tag.misc_toilets" icon="button_misc_toilets">
<element key="fee" type="boolean"/>
<element key="wheelchair" type="boolean"/>
<element key="diaper" type="boolean"/>
</button>
<button type="tag" label="@string/tag.misc_shelter" icon="button_misc_shelter" />
<button type="tag" label="@string/tag.misc_surveillance" icon="button_misc_surveillance" />
</row>
@@ -77,7 +90,20 @@
<button type="textnote" icon="text_32x32" />
</row>
<row>
<button type="tag" label="@string/tag.car_fuel_station" icon="button_car_fuel_station" />
<button type="custom_tag" label="@string/tag.car_fuel_station" icon="button_car_fuel_station">
<element key="brand" type="text"/>
<element key="opening_hours" type="text"/>
<element key="name" type="text"/>
<element key="fuel:electricity" type="boolean"/>
<element key="fuel:diesel" type="boolean"/>
<element key="fuel:biodiesel" type="boolean"/>
<element key="fuel:e10" type="boolean"/>
<element key="fuel:e85" type="boolean"/>
<element key="fuel:ocatane_91" type="boolean"/>
<element key="fuel:ocatane_95" type="boolean"/>
<element key="fuel:ocatane_98" type="boolean"/>
<element key="lpg" type="boolean"/>
</button>
<button type="tag" label="@string/tag.car_parking" icon="button_car_parking" />
<button type="tag" label="@string/tag.car_emergency_phone" icon="button_car_emergency_phone" />
</row>
Original file line number Diff line number Diff line change
@@ -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<CustomDialogElement> elements = new ArrayList<CustomDialogElement>();

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";
Loading
Oops, something went wrong.