mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-17 08:13:05 +02:00
Merge heads
This commit is contained in:
@@ -38,40 +38,26 @@ public class DialogUtils {
|
||||
* Creates a confirmation dialog.
|
||||
*
|
||||
* @param context the context
|
||||
* @param messageId the message id
|
||||
* @param titleId the title
|
||||
* @param message the message
|
||||
* @param okListener the listener when OK is clicked
|
||||
*/
|
||||
public static Dialog createConfirmationDialog(
|
||||
Context context, int messageId, DialogInterface.OnClickListener okListener) {
|
||||
return createConfirmationDialog(
|
||||
context, R.string.generic_confirm_title, messageId, null, okListener, null);
|
||||
Context context, int titleId, String message, DialogInterface.OnClickListener okListener) {
|
||||
return createConfirmationDialog(context, titleId, message, null, okListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a confirmation dialog.
|
||||
*
|
||||
* @param context the context
|
||||
* @param titleId the titleId
|
||||
* @param messageId the messageId
|
||||
* @param titleId the title
|
||||
* @param view the view
|
||||
* @param okListener the listener when OK is clicked
|
||||
* @param cancelListener the listener when cancel is clicked
|
||||
*/
|
||||
public static Dialog createConfirmationDialog(Context context, int titleId, int messageId,
|
||||
View view, DialogInterface.OnClickListener okListener,
|
||||
DialogInterface.OnClickListener cancelListener) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context).setCancelable(true)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setNegativeButton(R.string.generic_no, cancelListener)
|
||||
.setPositiveButton(R.string.generic_yes, okListener).setTitle(titleId);
|
||||
if (messageId != -1) {
|
||||
builder.setMessage(messageId);
|
||||
}
|
||||
if (view != null) {
|
||||
builder.setView(view);
|
||||
}
|
||||
|
||||
return builder.create();
|
||||
public static Dialog createConfirmationDialog(
|
||||
Context context, int titleId, View view, DialogInterface.OnClickListener okListener) {
|
||||
return createConfirmationDialog(context, titleId, null, view, okListener);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,6 +85,21 @@ public class DialogUtils {
|
||||
return createProgressDialog(false, context, messageId, onCancelListener, formatArgs);
|
||||
}
|
||||
|
||||
private static Dialog createConfirmationDialog(Context context, int titleId, String message,
|
||||
View view, DialogInterface.OnClickListener okListener) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context).setCancelable(true)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert).setNegativeButton(R.string.generic_no, null)
|
||||
.setPositiveButton(R.string.generic_yes, okListener).setTitle(titleId);
|
||||
if (message != null) {
|
||||
builder.setMessage(message);
|
||||
}
|
||||
if (view != null) {
|
||||
builder.setView(view);
|
||||
}
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a progress dialog.
|
||||
*
|
||||
|
||||
@@ -94,9 +94,10 @@ public class ListItemUtils {
|
||||
} else {
|
||||
photo.setVisibility(View.VISIBLE);
|
||||
Display defaultDisplay = activity.getWindowManager().getDefaultDisplay();
|
||||
// Set the initial width to 35% of the display width
|
||||
int width = (int) (defaultDisplay.getWidth() * .35);
|
||||
PhotoUtils.setImageVew(photo, Uri.parse(photoUrl), width, 0, false);
|
||||
// Set the initial width to 33% of the display width.
|
||||
int width = (int) (defaultDisplay.getWidth() * .33);
|
||||
int height = 0;
|
||||
PhotoUtils.setImageVew(photo, Uri.parse(photoUrl), width, height);
|
||||
}
|
||||
|
||||
// Set date/time
|
||||
@@ -109,7 +110,8 @@ public class ListItemUtils {
|
||||
|
||||
// Set category/description
|
||||
TextView descriptionTextView = (TextView) view.findViewById(R.id.list_item_description);
|
||||
setTextView(descriptionTextView, getDescription(isRecording, category, description));
|
||||
setTextView(descriptionTextView,
|
||||
isRecording ? null : StringUtils.getCategoryDescription(category, description));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,30 +148,6 @@ public class ListItemUtils {
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the description text.
|
||||
*
|
||||
* @param isRecording true if recording
|
||||
* @param category the category
|
||||
* @param description the description
|
||||
*/
|
||||
private static String getDescription(boolean isRecording, String category, String description) {
|
||||
if (isRecording) {
|
||||
return null;
|
||||
}
|
||||
if (category == null || category.length() == 0) {
|
||||
return description;
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
buffer.append("[" + category + "]");
|
||||
if (description != null && description.length() != 0) {
|
||||
buffer.append(" " + description);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the start time text.
|
||||
*
|
||||
|
||||
@@ -44,12 +44,10 @@ public class PhotoUtils {
|
||||
* @param uri the image uri
|
||||
* @param displayWidth the display width
|
||||
* @param displayHeight the display height
|
||||
* @param fitWithIn true to fit within the display area. False to crop and fill
|
||||
* the display area.
|
||||
*/
|
||||
public static Bitmap setImageVew(
|
||||
ImageView imageView, Uri uri, int displayWidth, int displayHeight, boolean fitWithIn) {
|
||||
|
||||
ImageView imageView, Uri uri, int displayWidth, int displayHeight) {
|
||||
|
||||
// Get the image dimensions
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
|
||||
@@ -61,7 +59,6 @@ public class PhotoUtils {
|
||||
int targetHeight = displayHeight;
|
||||
if (targetHeight == 0) {
|
||||
targetHeight = (int) (targetWidth * ((float) options.outHeight / (float) options.outWidth));
|
||||
imageView.getLayoutParams().height = targetHeight;
|
||||
}
|
||||
|
||||
// Set imageWidth and imageHeight based on image rotation
|
||||
@@ -79,8 +76,7 @@ public class PhotoUtils {
|
||||
|
||||
// Get a scaled down version of the image
|
||||
options.inJustDecodeBounds = false;
|
||||
options.inSampleSize = getInSampleSize(
|
||||
imageWidth, imageHeight, targetWidth, targetHeight, fitWithIn);
|
||||
options.inSampleSize = getInSampleSize(imageWidth, imageHeight, targetWidth, targetHeight);
|
||||
options.inPurgeable = true;
|
||||
|
||||
Bitmap scaledBitmap = BitmapFactory.decodeFile(uri.getPath(), options);
|
||||
@@ -133,11 +129,9 @@ public class PhotoUtils {
|
||||
* @param imageHeight the image height
|
||||
* @param targetWidth the target width
|
||||
* @param targetHeight the target height
|
||||
* @param fitWithin true to fit within the target area. False to crop and fill
|
||||
* all target area.
|
||||
*/
|
||||
private static int getInSampleSize(
|
||||
int imageWidth, int imageHeight, int targetWidth, int targetHeight, boolean fitWithin) {
|
||||
int imageWidth, int imageHeight, int targetWidth, int targetHeight) {
|
||||
float widthRatio = 1;
|
||||
if (imageWidth > targetWidth) {
|
||||
widthRatio = (float) imageWidth / (float) targetWidth;
|
||||
@@ -150,11 +144,9 @@ public class PhotoUtils {
|
||||
|
||||
/*
|
||||
* To fit within the target area, return the larger sample ratio so the
|
||||
* image will not be larger than the target dimensions. To crop and fill the
|
||||
* target area, return the smaller sample ratio so the image will be greater
|
||||
* than the target dimensions. Use Math.floor to not under sample.
|
||||
* image will not be larger than the target dimensions. Use Math.floor to
|
||||
* not under sample.
|
||||
*/
|
||||
return (int) Math.floor(
|
||||
fitWithin ? Math.max(widthRatio, heightRatio) : Math.min(widthRatio, heightRatio));
|
||||
return (int) Math.floor(Math.max(widthRatio, heightRatio));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ public class PreferencesUtils {
|
||||
|
||||
public static final String BLUETOOTH_SENSOR_DEFAULT = "";
|
||||
|
||||
public static final boolean CHART_BY_DISTANCE_DEFAULT = true;
|
||||
public static final boolean CHART_SHOW_CADENCE_DEFAULT = true;
|
||||
public static final boolean CHART_SHOW_ELEVATION_DEFAULT = true;
|
||||
public static final boolean CHART_SHOW_HEART_RATE_DEFAULT = true;
|
||||
public static final boolean CHART_SHOW_POWER_DEFAULT = true;
|
||||
public static final boolean CHART_SHOW_SPEED_DEFAULT = true;
|
||||
public static final String CHART_X_AXIS_DEFAULT = "DISTANCE";
|
||||
|
||||
public static final boolean CONFIRM_PLAY_EARTH_DEFAULT = true;
|
||||
|
||||
@@ -91,7 +91,6 @@ public class PreferencesUtils {
|
||||
|
||||
public static final long RECORDING_TRACK_ID_DEFAULT = -1L;
|
||||
public static final boolean RECORDING_TRACK_PAUSED_DEFAULT = true;
|
||||
public static final boolean REPORT_SPEED_DEFAULT = true;
|
||||
public static final long SELECTED_TRACK_ID_DEFAULT = -1L;
|
||||
public static final String SENSOR_TYPE_DEFAULT = "NONE";
|
||||
|
||||
@@ -102,6 +101,7 @@ public class PreferencesUtils {
|
||||
public static final int SPLIT_FREQUENCY_DEFAULT = 0;
|
||||
|
||||
// Stats
|
||||
public static final String STATS_RATE_DEFAULT = "SPEED";
|
||||
public static final boolean STATS_SHOW_COORDINATE_DEFAULT = false;
|
||||
public static final boolean STATS_SHOW_GRADE_ELEVATION_DEFAULT = false;
|
||||
public static final String STATS_UNITS_DEFAULT = "METRIC";
|
||||
@@ -257,4 +257,25 @@ public class PreferencesUtils {
|
||||
return PreferencesUtils.STATS_UNITS_DEFAULT.equals(
|
||||
getString(context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the preferred rate is speed, false if the preferred rate is
|
||||
* pace.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static boolean isReportSpeed(Context context) {
|
||||
return PreferencesUtils.STATS_RATE_DEFAULT.equals(
|
||||
getString(context, R.string.stats_rate_key, PreferencesUtils.STATS_RATE_DEFAULT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if chart x axis is by distance, false if by time.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public static boolean isChartByDistance(Context context) {
|
||||
return PreferencesUtils.CHART_X_AXIS_DEFAULT.equals(
|
||||
getString(context, R.string.chart_x_axis_key, PreferencesUtils.CHART_X_AXIS_DEFAULT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,7 @@ public class StatsUtils {
|
||||
*/
|
||||
public static void setLocationValues(Activity activity, Location location, boolean isRecording) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
|
||||
|
||||
// Set speed/pace
|
||||
double speed = isRecording && location != null && location.hasSpeed() ? location.getSpeed()
|
||||
@@ -112,8 +111,7 @@ public class StatsUtils {
|
||||
*/
|
||||
public static void setTripStatisticsValues(Activity activity, TripStatistics tripStatistics) {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(activity);
|
||||
boolean reportSpeed = PreferencesUtils.getBoolean(
|
||||
activity, R.string.report_speed_key, PreferencesUtils.REPORT_SPEED_DEFAULT);
|
||||
boolean reportSpeed = PreferencesUtils.isReportSpeed(activity);
|
||||
|
||||
// Set total distance
|
||||
double totalDistance = tripStatistics == null ? Double.NaN : tripStatistics.getTotalDistance();
|
||||
|
||||
@@ -228,6 +228,26 @@ public class StringUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string for category and description.
|
||||
*
|
||||
* @param category the category
|
||||
* @param description the description
|
||||
*/
|
||||
public static String getCategoryDescription(String category, String description) {
|
||||
if (category == null || category.length() == 0) {
|
||||
return description;
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
buffer.append("[" + category + "]");
|
||||
if (description != null && description.length() != 0) {
|
||||
buffer.append(" " + description);
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the given text as a XML CDATA element. This includes adding the
|
||||
* starting and ending CDATA tags. Please notice that this may result in
|
||||
|
||||
Reference in New Issue
Block a user