-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a specific row type instead of TextRow for the value widgets
- Loading branch information
1 parent
1380d1f
commit 6a8489d
Showing
4 changed files
with
176 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/main/java/de/blau/android/propertyeditor/tagform/ValueWidgetRow.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package de.blau.android.propertyeditor.tagform; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AlertDialog; | ||
import de.blau.android.R; | ||
import de.blau.android.presets.PresetComboField; | ||
import de.blau.android.presets.PresetItem; | ||
import de.blau.android.presets.PresetTagField; | ||
import de.blau.android.presets.ValueType; | ||
import de.blau.android.propertyeditor.TagChanged; | ||
import de.blau.android.util.StringWithDescription; | ||
import de.blau.android.util.StringWithDescriptionAndIcon; | ||
import de.blau.android.util.Value; | ||
import de.blau.android.views.CustomAutoCompleteTextView; | ||
|
||
public class ValueWidgetRow extends DialogRow implements TagChanged { | ||
|
||
private ValueType valueType; | ||
private PresetTagField field; | ||
|
||
/** | ||
* Construct a row that will display a Dialog when clicked | ||
* | ||
* @param context Android Context | ||
*/ | ||
public ValueWidgetRow(@NonNull Context context) { | ||
super(context); | ||
} | ||
|
||
/** | ||
* Construct a row that will display a Dialog when clicked | ||
* | ||
* @param context Android Context | ||
* @param attrs an AttributeSet | ||
*/ | ||
public ValueWidgetRow(@NonNull Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
/** | ||
* Add a row that displays a dialog for selecting a single when clicked | ||
* | ||
* @param caller the calling TagFormFragment instance | ||
* @param inflater the inflater to use | ||
* @param rowLayout the Layout holding the roes | ||
* @param preset the relevant PresetItem | ||
* @param field the current PresetTagField | ||
* @param value the current value | ||
* @param values all relevant values (preset MRU etc) | ||
* @param allTags all current tags | ||
* @return | ||
*/ | ||
static ValueWidgetRow getRow(@NonNull final TagFormFragment caller, @NonNull final LayoutInflater inflater, @NonNull final LinearLayout rowLayout, | ||
@NonNull final PresetItem preset, @NonNull final PresetTagField field, @NonNull final String value, @Nullable final List<String> values, | ||
final Map<String, String> allTags) { | ||
final ValueWidgetRow row = (ValueWidgetRow) inflater.inflate(R.layout.tag_form_value_widget_row, rowLayout, false); | ||
final String key = field.getKey(); | ||
final String hint = preset != null ? field.getHint() : key; | ||
row.keyView.setText(hint); | ||
row.keyView.setTag(key); | ||
row.setPreset(preset); | ||
row.valueType = preset != null ? preset.getValueType(key) : null; | ||
row.field = field; | ||
|
||
row.valueView.setHint(R.string.tag_dialog_value_hint); | ||
row.setValue(value == null ? "" : value); | ||
|
||
row.valueView.setFocusable(false); | ||
row.valueView.setFocusableInTouchMode(false); | ||
row.setOnClickListener(v -> { | ||
final View finalView = v; | ||
finalView.setEnabled(false); // debounce | ||
if (ValueType.INTEGER == row.valueType) { | ||
IntegerValueFragment.show(caller, hint, key, row.getValue(), values, preset, allTags); | ||
} | ||
if (ValueType.CARDINAL_DIRECTION == row.valueType) { | ||
DirectionValueFragment.show(caller, hint, key, row.getValue(), values, preset, allTags); | ||
} | ||
}); | ||
return row; | ||
} | ||
|
||
@Override | ||
public void changed(String key, String value) { | ||
if (key.equals(this.getKey())) { | ||
valueView.setEnabled(true); | ||
setValue(value); | ||
} | ||
} | ||
|
||
@Override | ||
public void setValue(@NonNull String value) { | ||
// it might be simpler to simply use the normal autocomplete adapter here | ||
if (field instanceof PresetComboField) { | ||
for (StringWithDescription swd : ((PresetComboField) field).getValues()) { | ||
if (value.equals(swd.getValue())) { | ||
setValue(swd); | ||
return; | ||
} | ||
} | ||
} | ||
super.setValue(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- inner classes must be specified using <view class="classname" /> due to dollar sign --> | ||
<view xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
class="de.blau.android.propertyeditor.tagform.ValueWidgetRow" | ||
android:orientation="horizontal" > | ||
|
||
<LinearLayout | ||
style="?attr/Layout" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:baselineAligned="false" | ||
android:orientation="horizontal" | ||
android:saveEnabled="false" > | ||
|
||
<TextView | ||
android:id="@+id/textKey" | ||
style="?attr/StaticText" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:layout_marginBottom="1dp" | ||
android:layout_marginRight="1dp" | ||
android:layout_marginEnd="1dp" | ||
android:layout_weight="3" | ||
android:gravity="center_vertical" | ||
android:maxLines="3" | ||
android:minHeight="34dp" | ||
android:paddingLeft="5dp" | ||
android:paddingRight="5dp" | ||
android:saveEnabled="false" /> | ||
|
||
<TextView | ||
android:id="@+id/textValue" | ||
style="?attr/StaticText" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:layout_marginBottom="1dp" | ||
android:layout_marginLeft="0dp" | ||
android:layout_marginRight="0dp" | ||
android:layout_weight="2" | ||
android:gravity="center_vertical" | ||
android:drawableEnd="?attr/edit" | ||
android:drawableRight="?attr/edit" | ||
android:focusable="false" | ||
android:focusableInTouchMode="false" | ||
android:minHeight="34dp" | ||
android:paddingLeft="5dp" | ||
android:paddingStart="5dp" | ||
android:paddingRight="3dp" | ||
android:paddingEnd="3dp" | ||
android:saveEnabled="false" | ||
android:singleLine="true" | ||
android:ellipsize="none" /> | ||
</LinearLayout> | ||
|
||
</view> |