forked from upstream-mirrors/OpenTracks
Fix spacing in activity icon dialog.
This commit is contained in:
@@ -18,7 +18,6 @@ limitations under the License.
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:numColumns="4"
|
||||
android:paddingBottom="20dp"
|
||||
android:paddingTop="20dp"
|
||||
android:stretchMode="columnWidth"
|
||||
android:verticalSpacing="20dp" />
|
||||
android:padding="4dp"
|
||||
android:stretchMode="spacingWidth"
|
||||
android:verticalSpacing="4dp" />
|
||||
|
||||
+18
-8
@@ -22,6 +22,8 @@ import com.google.android.maps.mytracks.R;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.BitmapFactory.Options;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
@@ -34,14 +36,14 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* A DialogFragment to choose an activity type.
|
||||
*
|
||||
*
|
||||
* @author apoorvn
|
||||
*/
|
||||
public class ChooseActivityTypeDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
*
|
||||
* @author apoorvn
|
||||
*/
|
||||
public interface ChooseActivityTypeCaller {
|
||||
@@ -69,8 +71,8 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
GridView gridView = (GridView) getActivity()
|
||||
.getLayoutInflater().inflate(R.layout.choose_activity_type, null);
|
||||
GridView gridView =
|
||||
(GridView) getActivity().getLayoutInflater().inflate(R.layout.choose_activity_type, null);
|
||||
|
||||
final List<String> iconValues = TrackIconUtils.getAllIconValues();
|
||||
List<Integer> imageIds = new ArrayList<Integer>();
|
||||
@@ -78,11 +80,19 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
|
||||
imageIds.add(TrackIconUtils.getIconDrawable(iconValue));
|
||||
}
|
||||
|
||||
ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(
|
||||
getActivity(), imageIds);
|
||||
Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeResource(getResources(), R.drawable.track_airplane, options);
|
||||
int padding = 32;
|
||||
int width = options.outWidth + 2 * padding;
|
||||
int height = options.outHeight + 2 * padding;
|
||||
gridView.setColumnWidth(width);
|
||||
|
||||
ChooseActivityTypeImageAdapter imageAdapter =
|
||||
new ChooseActivityTypeImageAdapter(getActivity(), imageIds, width, height, padding);
|
||||
gridView.setAdapter(imageAdapter);
|
||||
gridView.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
|
||||
dismiss();
|
||||
caller.onChooseActivityTypeDone(iconValues.get(position));
|
||||
@@ -92,4 +102,4 @@ public class ChooseActivityTypeDialogFragment extends DialogFragment {
|
||||
return new AlertDialog.Builder(getActivity()).setNegativeButton(R.string.generic_cancel, null)
|
||||
.setTitle(R.string.track_edit_activity_type_hint).setView(gridView).create();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -26,17 +26,24 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Image adapter for choosing an activity type.
|
||||
*
|
||||
*
|
||||
* @author apoorvn
|
||||
*/
|
||||
public class ChooseActivityTypeImageAdapter extends BaseAdapter {
|
||||
|
||||
private final Context context;
|
||||
private final List<Integer> imageIds;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int padding;
|
||||
|
||||
public ChooseActivityTypeImageAdapter(Context context, List<Integer> imageIds) {
|
||||
public ChooseActivityTypeImageAdapter(
|
||||
Context context, List<Integer> imageIds, int width, int height, int padding) {
|
||||
this.context = context;
|
||||
this.imageIds = imageIds;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.padding = padding;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,6 +70,9 @@ public class ChooseActivityTypeImageAdapter extends BaseAdapter {
|
||||
imageView = (ImageView) convertView;
|
||||
}
|
||||
imageView.setImageResource(imageIds.get(position));
|
||||
imageView.setMinimumHeight(height);
|
||||
imageView.setMinimumWidth(width);
|
||||
imageView.setPadding(padding, padding, padding, padding);
|
||||
return imageView;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Utilities for track icon.
|
||||
*
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class TrackIconUtils {
|
||||
@@ -43,48 +43,52 @@ public class TrackIconUtils {
|
||||
|
||||
private TrackIconUtils() {}
|
||||
|
||||
private static LinkedHashMap<String, Pair<Integer, Integer>>
|
||||
map = new LinkedHashMap<String, Pair<Integer, Integer>>();
|
||||
private static LinkedHashMap<String, Pair<Integer, Integer>> map =
|
||||
new LinkedHashMap<String, Pair<Integer, Integer>>();
|
||||
|
||||
static {
|
||||
map.put(AIRPLANE,
|
||||
new Pair<Integer, Integer>(R.string.activity_type_airplane, R.drawable.track_airplane));
|
||||
map.put(RUN, new Pair<Integer, Integer>(R.string.activity_type_running, R.drawable.track_run));
|
||||
map.put(
|
||||
WALK, new Pair<Integer, Integer>(R.string.activity_type_walking, R.drawable.track_walk));
|
||||
map.put(BIKE, new Pair<Integer, Integer>(R.string.activity_type_biking, R.drawable.track_bike));
|
||||
map.put(BOAT, new Pair<Integer, Integer>(R.string.activity_type_boat, R.drawable.track_boat));
|
||||
map.put(
|
||||
DRIVE, new Pair<Integer, Integer>(R.string.activity_type_driving, R.drawable.track_drive));
|
||||
map.put(RUN, new Pair<Integer, Integer>(R.string.activity_type_running, R.drawable.track_run));
|
||||
map.put(SKI, new Pair<Integer, Integer>(R.string.activity_type_skiing, R.drawable.track_ski));
|
||||
map.put(SNOW_BOARDING, new Pair<Integer, Integer>(
|
||||
R.string.activity_type_snow_boarding, R.drawable.track_snow_boarding));
|
||||
map.put(
|
||||
WALK, new Pair<Integer, Integer>(R.string.activity_type_walking, R.drawable.track_walk));
|
||||
map.put(AIRPLANE,
|
||||
new Pair<Integer, Integer>(R.string.activity_type_airplane, R.drawable.track_airplane));
|
||||
map.put(BOAT, new Pair<Integer, Integer>(R.string.activity_type_boat, R.drawable.track_boat));
|
||||
}
|
||||
|
||||
private static int[] airplane = new int[] { R.string.activity_type_airplane,
|
||||
R.string.activity_type_commercial_airplane, R.string.activity_type_rc_airplane };
|
||||
private static int[] bike = new int[] { R.string.activity_type_biking,
|
||||
R.string.activity_type_cycling, R.string.activity_type_dirt_bike,
|
||||
R.string.activity_type_motor_bike, R.string.activity_type_mountain_biking,
|
||||
R.string.activity_type_road_biking, R.string.activity_type_track_cycling };
|
||||
private static int[] boat = new int[] { R.string.activity_type_boat, R.string.activity_type_ferry,
|
||||
R.string.activity_type_motor_boating, R.string.activity_type_rc_boat };
|
||||
private static int[] drive = new int[] { R.string.activity_type_atv,
|
||||
R.string.activity_type_driving, R.string.activity_type_driving_bus,
|
||||
R.string.activity_type_driving_car };
|
||||
private static int[] run = new int[] { R.string.activity_type_running,
|
||||
R.string.activity_type_street_running, R.string.activity_type_track_running,
|
||||
R.string.activity_type_trail_running };
|
||||
private static int[] ski = new int[] {
|
||||
R.string.activity_type_cross_country_skiing, R.string.activity_type_skiing };
|
||||
private static int[] snowBoarding = new int[] { R.string.activity_type_snow_boarding };
|
||||
private static int[] walk = new int[] { R.string.activity_type_hiking,
|
||||
private static int[] airplane = new int[] {
|
||||
R.string.activity_type_airplane, R.string.activity_type_commercial_airplane,
|
||||
R.string.activity_type_rc_airplane};
|
||||
private static int[] bike = new int[] {R.string.activity_type_biking,
|
||||
R.string.activity_type_cycling,
|
||||
R.string.activity_type_dirt_bike,
|
||||
R.string.activity_type_motor_bike,
|
||||
R.string.activity_type_mountain_biking,
|
||||
R.string.activity_type_road_biking,
|
||||
R.string.activity_type_track_cycling};
|
||||
private static int[] boat = new int[] {R.string.activity_type_boat, R.string.activity_type_ferry,
|
||||
R.string.activity_type_motor_boating, R.string.activity_type_rc_boat};
|
||||
private static int[] drive = new int[] {
|
||||
R.string.activity_type_atv, R.string.activity_type_driving,
|
||||
R.string.activity_type_driving_bus, R.string.activity_type_driving_car};
|
||||
private static int[] run = new int[] {
|
||||
R.string.activity_type_running, R.string.activity_type_street_running,
|
||||
R.string.activity_type_track_running, R.string.activity_type_trail_running};
|
||||
private static int[] ski =
|
||||
new int[] {R.string.activity_type_cross_country_skiing, R.string.activity_type_skiing};
|
||||
private static int[] snowBoarding = new int[] {R.string.activity_type_snow_boarding};
|
||||
private static int[] walk = new int[] {R.string.activity_type_hiking,
|
||||
R.string.activity_type_off_trail_hiking, R.string.activity_type_speed_walking,
|
||||
R.string.activity_type_trail_hiking, R.string.activity_type_walking };
|
||||
R.string.activity_type_trail_hiking, R.string.activity_type_walking};
|
||||
|
||||
/**
|
||||
* Gets the icon drawable.
|
||||
*
|
||||
*
|
||||
* @param iconValue the icon value
|
||||
*/
|
||||
public static int getIconDrawable(String iconValue) {
|
||||
@@ -97,7 +101,7 @@ public class TrackIconUtils {
|
||||
|
||||
/**
|
||||
* Gets the icon activity type.
|
||||
*
|
||||
*
|
||||
* @param iconValue the icon value
|
||||
*/
|
||||
public static int getIconActivityType(String iconValue) {
|
||||
@@ -121,7 +125,7 @@ public class TrackIconUtils {
|
||||
|
||||
/**
|
||||
* Gets the icon value.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param activityType the activity type
|
||||
*/
|
||||
@@ -155,7 +159,7 @@ public class TrackIconUtils {
|
||||
|
||||
/**
|
||||
* Returns true if the activity type is in the list.
|
||||
*
|
||||
*
|
||||
* @param context the context
|
||||
* @param activityType the activity type
|
||||
* @param list the list
|
||||
|
||||
Reference in New Issue
Block a user