mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-17 00:03:07 +02:00
Add a clear button at the end of the weight field
This commit is contained in:
@@ -39,16 +39,29 @@ limitations under the License.
|
|||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:paddingLeft="12dp"
|
android:paddingLeft="12dp"
|
||||||
style="@style/TextMedium" />
|
style="@style/TextMedium" />
|
||||||
<EditText
|
<FrameLayout
|
||||||
android:id="@+id/choose_activity_type_weight"
|
android:layout_height="wrap_content"
|
||||||
android:inputType="numberDecimal"
|
android:layout_width="fill_parent" >
|
||||||
android:layout_marginBottom="4dp"
|
<EditText
|
||||||
android:layout_marginLeft="16dp"
|
android:id="@+id/choose_activity_type_weight"
|
||||||
android:layout_marginRight="16dp"
|
android:inputType="numberDecimal"
|
||||||
android:layout_marginTop="2dp"
|
android:layout_marginBottom="4dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_marginLeft="16dp"
|
||||||
android:selectAllOnFocus="true"
|
android:layout_marginRight="16dp"
|
||||||
android:singleLine="true"
|
android:layout_marginTop="2dp"
|
||||||
style="@style/TextMedium" />
|
android:layout_width="match_parent"
|
||||||
|
android:selectAllOnFocus="true"
|
||||||
|
android:singleLine="true"
|
||||||
|
style="@style/TextMedium" />
|
||||||
|
<ImageButton
|
||||||
|
android:background="@android:color/transparent"
|
||||||
|
android:id="@+id/choose_activity_type_weight_image_button"
|
||||||
|
android:layout_gravity="right|center_vertical"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:paddingRight="12dp"
|
||||||
|
android:src="@android:drawable/ic_menu_close_clear_cancel" />
|
||||||
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
+15
-1
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.fragments;
|
|||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.apps.mytracks.util.StringUtils;
|
import com.google.android.apps.mytracks.util.StringUtils;
|
||||||
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
import com.google.android.apps.mytracks.util.TrackIconUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.UnitConversions;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
@@ -33,6 +34,7 @@ import android.view.View;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.GridView;
|
import android.widget.GridView;
|
||||||
|
import android.widget.ImageButton;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -101,7 +103,19 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
|
|||||||
: R.string.description_weight_imperial);
|
: R.string.description_weight_imperial);
|
||||||
|
|
||||||
weight = (TextView) view.findViewById(R.id.choose_activity_type_weight);
|
weight = (TextView) view.findViewById(R.id.choose_activity_type_weight);
|
||||||
|
ImageButton imageButton = (ImageButton) view.findViewById(
|
||||||
|
R.id.choose_activity_type_weight_image_button);
|
||||||
|
imageButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
double weightDefault = PreferencesUtils.WEIGHT_DEFAULT;
|
||||||
|
if (!PreferencesUtils.isMetricUnits(getActivity())) {
|
||||||
|
weightDefault *= UnitConversions.KG_TO_LB;
|
||||||
|
}
|
||||||
|
weight.setText(StringUtils.formatWeight(weightDefault));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
List<Integer> imageIds = new ArrayList<Integer>();
|
List<Integer> imageIds = new ArrayList<Integer>();
|
||||||
for (String iconValue : TrackIconUtils.getAllIconValues()) {
|
for (String iconValue : TrackIconUtils.getAllIconValues()) {
|
||||||
imageIds.add(TrackIconUtils.getIconDrawable(iconValue));
|
imageIds.add(TrackIconUtils.getIconDrawable(iconValue));
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public class StringUtils {
|
|||||||
|
|
||||||
private static String formatDecimal(double value, int precision) {
|
private static String formatDecimal(double value, int precision) {
|
||||||
String result = String.format(Locale.getDefault(), "%1$,." + precision + "f", value);
|
String result = String.format(Locale.getDefault(), "%1$,." + precision + "f", value);
|
||||||
return value % 1 == 0 ? result.substring(0, result.lastIndexOf('.')) : result;
|
return result.replaceAll("[0]*$", "").replaceAll("\\.$", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user