The pictures for the marks are shown now in the app

This commit is contained in:
Armin Zamani committed 2013-03-23 23:44:55 +01:00
1 parent 5aeb30b1c9
commit 0e385260f1
20 files changed
+231 -92

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

@@ -14,7 +14,8 @@
<TextView android:id="@+id/Welter.Grid.Mark.Cell.txtTitle"
android:padding="5dp" android:textColor="@drawable/text_selector"
android:textSize="10pt"
android:layout_width="wrap_content" android:layout_height="wrap_content">
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textIsSelectable="false">
</TextView>
</LinearLayout>
@@ -12,74 +12,73 @@ import android.widget.TextView;
import com.sap.sailing.racecommittee.app.R;
import com.sap.sailing.racecommittee.app.domain.RoundingDirection;
import com.sap.sailing.racecommittee.app.utils.MarkImageHelper;
public class CourseElementListAdapter extends ArrayAdapter<CourseListDataElement> {
public CourseElementListAdapter(Context context, int textViewResourceId, List<CourseListDataElement> objects) {
super(context, textViewResourceId, objects);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
LayoutInflater li = (LayoutInflater) (getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
view = li.inflate(R.layout.welter_one_row_three_columns, null);
}
public CourseElementListAdapter(Context context, int textViewResourceId, List<CourseListDataElement> objects) {
super(context, textViewResourceId, objects);
}
CourseListDataElement courseElement = getItem(position);
TextView leftBuoyText = (TextView) view
.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnOne_txtLeftMark);
TextView roundingDirectionText = (TextView) view
.findViewById(R.id.Welter_Cell_OneRowThreeColumns_txtRoundingDirection);
TextView rightBuoyText = (TextView) view
.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnThree_txtRightMark);
ImageView leftBuoyImage = (ImageView) view.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnOne_imgImage);
ImageView rightBuoyImage = (ImageView) view.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnThree_imgImage);
leftBuoyText.setText(courseElement.getLeftMark().getName());
leftBuoyImage.setVisibility(View.INVISIBLE);
// if (courseElement.getLeftMark().getImage() != null) {
// Bitmap bitmap = BitmapFactory.decodeByteArray(courseElement.getLeftMark().getImage(), 0, courseElement.getLeftMark().getImage().length);
// leftBuoyImage.setImageBitmap(bitmap);
// }
if (courseElement.getRoundingDirection() != null)
roundingDirectionText.setText(getDisplayValueForRounding(courseElement.getRoundingDirection()));
else
roundingDirectionText.setText(R.string.empty);
if (courseElement.getRightMark() != null) {
rightBuoyText.setText(courseElement.getRightMark().getName());
// if (courseElement.getRightMark().getImage() != null) {
// Bitmap bitmap = BitmapFactory.decodeByteArray(courseElement.getRightMark().getImage(), 0, courseElement.getRightMark().getImage().length);
// rightBuoyImage.setVisibility(View.VISIBLE);
// rightBuoyImage.setImageBitmap(bitmap);
// }
} else {
rightBuoyText.setText(R.string.empty);
rightBuoyImage.setVisibility(View.INVISIBLE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
return view;
}
protected String getDisplayValueForRounding(RoundingDirection direction) {
if (direction.equals(RoundingDirection.Gate))
return "Gate";
else if (direction.equals(RoundingDirection.Port))
return "P";
else if (direction.equals(RoundingDirection.Starboard))
return "S";
return"";
}
LayoutInflater li = (LayoutInflater) (getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
view = li.inflate(R.layout.welter_one_row_three_columns, null);
}
CourseListDataElement courseElement = getItem(position);
TextView leftMarkText = (TextView) view
.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnOne_txtLeftMark);
TextView roundingDirectionText = (TextView) view
.findViewById(R.id.Welter_Cell_OneRowThreeColumns_txtRoundingDirection);
TextView rightMarkText = (TextView) view
.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnThree_txtRightMark);
ImageView leftMarkImage = (ImageView) view.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnOne_imgImage);
ImageView rightMarkImage = (ImageView) view.findViewById(R.id.Welter_Cell_OneRowThreeColumns_columnThree_imgImage);
leftMarkText.setText(courseElement.getLeftMark().getName());
leftMarkImage.setVisibility(View.INVISIBLE);
if (courseElement.getLeftMark() != null) {
int drawable = MarkImageHelper.INSTANCE.resolveMarkImage(courseElement.getLeftMark());
leftMarkImage.setImageResource(drawable);
leftMarkImage.setVisibility(View.VISIBLE);
}
if (courseElement.getRoundingDirection() != null)
roundingDirectionText.setText(getDisplayValueForRounding(courseElement.getRoundingDirection()));
else
roundingDirectionText.setText(R.string.empty);
if (courseElement.getRightMark() != null) {
rightMarkText.setText(courseElement.getRightMark().getName());
int drawable = MarkImageHelper.INSTANCE.resolveMarkImage(courseElement.getRightMark());
rightMarkImage.setImageResource(drawable);
rightMarkImage.setVisibility(View.VISIBLE);
} else {
rightMarkText.setText(R.string.empty);
rightMarkImage.setVisibility(View.INVISIBLE);
}
return view;
}
protected String getDisplayValueForRounding(RoundingDirection direction) {
if (direction.equals(RoundingDirection.Gate))
return "Gate";
else if (direction.equals(RoundingDirection.Port))
return "P";
else if (direction.equals(RoundingDirection.Starboard))
return "S";
return"";
}
}
@@ -7,42 +7,39 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.sap.sailing.domain.base.Mark;
import com.sap.sailing.racecommittee.app.R;
import com.sap.sailing.racecommittee.app.utils.MarkImageHelper;
public class MarkGridAdapter extends ArrayAdapter<Mark> {
public MarkGridAdapter(Context context, int textViewResourceId, List<Mark> marks) {
super(context, textViewResourceId, marks);
}
public MarkGridAdapter(Context context, int textViewResourceId, List<Mark> marks) {
super(context, textViewResourceId, marks);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
LayoutInflater li = (LayoutInflater) (getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE));
view = li.inflate(R.layout.welter_grid_mark_cell, null);
}
LayoutInflater li = (LayoutInflater) (getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
view = li.inflate(R.layout.welter_grid_mark_cell, null);
}
Mark mark = getItem(position);
Mark mark = getItem(position);
//TODO: First test the setup just with names, then we will bring images in the app
// ImageView image = (ImageView) view.findViewById(R.id.Welter_Grid_Mark_Cell_imgImage);
//
// if (mark.getImage() != null) {
// Bitmap bitmap = BitmapFactory.decodeByteArray(mark.getImage(), 0, mark.getImage().length);
// image.setImageBitmap(bitmap);
// }
TextView title = (TextView) view
.findViewById(R.id.Welter_Grid_Mark_Cell_txtTitle);
title.setText(mark.getName());
ImageView image = (ImageView) view.findViewById(R.id.Welter_Grid_Mark_Cell_imgImage);
int drawable = MarkImageHelper.INSTANCE.resolveMarkImage(mark);
image.setImageResource(drawable);
image.setVisibility(View.VISIBLE);
TextView title = (TextView) view.findViewById(R.id.Welter_Grid_Mark_Cell_txtTitle);
title.setText(mark.getName());
return view;
}
return view;
}
}
@@ -0,0 +1,78 @@
package com.sap.sailing.racecommittee.app.utils;
import com.sap.sailing.domain.common.MarkType;
public class MarkImageDescriptor {
private final int drawableId;
private final String color;
private final String shape;
private final String pattern;
private final MarkType type;
public MarkImageDescriptor(int drawableId, MarkType type, String color, String shape, String pattern) {
this.drawableId = drawableId;
this.type = type;
this.color = color;
this.shape = shape;
this.pattern = pattern;
}
public int getDrawableId() {
return drawableId;
}
public String getColor() {
return color;
}
public String getShape() {
return shape;
}
public String getPattern() {
return pattern;
}
public MarkType getType() {
return type;
}
/**
* An utility method to check if the mark icon has compatible display properties.
* In case of null values at least the mark type and the color must exist and fit.
*/
public int getCompatibilityLevel(MarkType typeToCheck, String colorToCheck, String shapeToCheck, String patternToCheck) {
boolean isSameType = false;
boolean isSameColor = false;
boolean isSameShape = false;
boolean isSamePattern = false;
int result = -1;
if(typeToCheck != null && type != null) {
isSameType = type == typeToCheck;
}
if(colorToCheck != null && color != null) {
isSameColor = color.equalsIgnoreCase(colorToCheck) ? true : false;
}
if(shapeToCheck != null && shape != null) {
isSameShape = shape.equalsIgnoreCase(shapeToCheck) ? true : false;
}
if(patternToCheck != null && pattern != null) {
isSamePattern = pattern.equalsIgnoreCase(patternToCheck) ? true : false;
}
if(isSameType && isSameColor) {
result = 1;
if(isSameShape) {
result += 1;
}
if(isSamePattern) {
result += 1;
}
}
return result;
}
}
@@ -0,0 +1,64 @@
package com.sap.sailing.racecommittee.app.utils;
import java.util.ArrayList;
import java.util.List;
import com.sap.sailing.domain.base.Mark;
import com.sap.sailing.domain.common.MarkType;
import com.sap.sailing.racecommittee.app.R;
public enum MarkImageHelper {
INSTANCE;
List<MarkImageDescriptor> markImageDescriptors;
private MarkImageDescriptor defaultCourseMarkDescriptor;
private MarkImageHelper() {
markImageDescriptors = new ArrayList<MarkImageDescriptor>();
defaultCourseMarkDescriptor = createMarkImageDescriptor(R.drawable.buoy_buoy, MarkType.BUOY, "undefined", null, null);
createMarkImageDescriptor(R.drawable.buoy_red, MarkType.BUOY, "red", null, null);
createMarkImageDescriptor(R.drawable.buoy_green, MarkType.BUOY, "green", null, null);
createMarkImageDescriptor(R.drawable.buoy_yellow, MarkType.BUOY, "yellow", null, null);
createMarkImageDescriptor(R.drawable.buoy_grey, MarkType.BUOY, "grey", null, null);
createMarkImageDescriptor(R.drawable.buoy_white_grey, MarkType.BUOY, "white", null, null);
createMarkImageDescriptor(R.drawable.buoy_white_grey_cone, MarkType.BUOY, "white", "conical", null);
createMarkImageDescriptor(R.drawable.buoy_black, MarkType.BUOY, "black", null, null);
createMarkImageDescriptor(R.drawable.buoy_black_cone, MarkType.BUOY, "black", "conical", null);
createMarkImageDescriptor(R.drawable.buoy_dark_orange, MarkType.BUOY, "orange", null, null);
createMarkImageDescriptor(R.drawable.buoy_black_cone, MarkType.BUOY, "black", "cylinder", "checkered");
createMarkImageDescriptor(R.drawable.buoy_cameraboat, MarkType.CAMERABOAT, null, null, null);
createMarkImageDescriptor(R.drawable.buoy_umpireboat, MarkType.UMPIREBOAT, null, null, null);
createMarkImageDescriptor(R.drawable.buoy_startboat, MarkType.STARTBOAT, null, null, null);
createMarkImageDescriptor(R.drawable.buoy_landmark, MarkType.LANDMARK, null, null, null);
}
public int resolveMarkImage(Mark mark) {
MarkImageDescriptor result = defaultCourseMarkDescriptor;
int highestCompatibilityLevel = -1;
for (MarkImageDescriptor imageDescriptor: markImageDescriptors) {
int compatibilityLevel = imageDescriptor.getCompatibilityLevel(mark.getType(), mark.getColor(), mark.getShape(), mark.getPattern());
if(compatibilityLevel > highestCompatibilityLevel) {
result = imageDescriptor;
highestCompatibilityLevel = compatibilityLevel;
if(highestCompatibilityLevel == 3) {
break;
}
}
}
return result.getDrawableId();
}
private MarkImageDescriptor createMarkImageDescriptor(int drawableId, MarkType type, String color, String shape, String pattern) {
MarkImageDescriptor markIconDescriptor = new MarkImageDescriptor(drawableId, type, color, shape, pattern);
markImageDescriptors.add(markIconDescriptor);
return markIconDescriptor;
}
}