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