Fix comments for ad70806c8dc7

This commit is contained in:
Jimmy Shih
2011-10-11 16:19:54 -07:00
parent 5572e07b34
commit 8dd3741fa7
7 changed files with 59 additions and 46 deletions
@@ -48,9 +48,7 @@ import java.util.Locale;
class DocsTagBuilder {
private static final DecimalFormatSymbols FORMAT_SYMBOLS =
ApiFeatures.getInstance().hasDecimalFormatSymbolsGetInstance()
? DecimalFormatSymbols.getInstance(Locale.ENGLISH)
: new DecimalFormatSymbols(Locale.ENGLISH);
ApiFeatures.getInstance().getApiPlatformAdapter().getDecimalFormatSysmbols(Locale.ENGLISH);
private static final NumberFormat LARGE_UNIT_FORMAT =
new DecimalFormat("#,###,###.00", FORMAT_SYMBOLS);
private static final NumberFormat SMALL_UNIT_FORMAT =
@@ -24,7 +24,7 @@ import java.util.Arrays;
* An implementation of a Sensor MessageParser for Zephyr.
*
* @author Sandor Dornbush
* @author Dominik R�ttsches
* @author Dominik Ršttsches
*/
public class ZephyrMessageParser implements MessageParser {
@@ -57,24 +57,13 @@ public class ZephyrMessageParser implements MessageParser {
return sds.build();
}
/**
* Copies a byte array. In case Arrays.copyOfRange is not available.
*/
private byte[] copyByteArray(byte[] input, int from, int to) {
int length = to - from;
byte[] output = new byte[length];
System.arraycopy(input, from, output, 0, length);
return output;
}
private void setCadence(Sensor.SensorDataSet.Builder sds, byte[] buffer) {
// Device Firmware ID, Firmware Version, Hardware ID, Hardware Version
// 0x1A00316550003162 produces erroneous values for Cadence and needs
// a workaround based on the stride counter.
// Firmware values range from field 3 to 10 (inclusive) of the byte buffer.
byte[] hardwareFirmwareId = ApiFeatures.getInstance().hasArraysCopyOfRange()
? Arrays.copyOfRange(buffer, 3, 11)
: copyByteArray(buffer, 3, 11);
byte[] hardwareFirmwareId = ApiFeatures.getInstance().getApiPlatformAdapter()
.copyByteArray(buffer, 3, 11);
Sensor.SensorData.Builder cadence = Sensor.SensorData.newBuilder();
if (Arrays.equals(hardwareFirmwareId, CADENCE_BUG_FW_ID)) {
@@ -24,9 +24,6 @@ import android.bluetooth.BluetoothDevice;
import android.os.Build;
import android.util.Log;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
/**
* Utility class for determining if newer-API features are available on the
* current device.
@@ -133,20 +130,6 @@ public class ApiFeatures {
return getApiLevel() >= 9;
}
/**
* Returns true if {@link DecimalFormatSymbols#getInstance} is available.
*/
public boolean hasDecimalFormatSymbolsGetInstance() {
return getApiLevel() >= 9;
}
/**
* Returns true if {@link Arrays#copyOfRange} is available.
*/
public boolean hasArraysCopyOfRange() {
return getApiLevel() >= 9;
}
// API Level 10 changes
/**
@@ -20,6 +20,9 @@ import android.app.NotificationManager;
import android.app.Service;
import android.content.SharedPreferences;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
/**
* A set of methods that may be implemented in a platform specific way.
*
@@ -60,4 +63,25 @@ public interface ApiPlatformAdapter {
* Enables strict mode where supported, only if this is a development build.
*/
void enableStrictMode();
/**
* Copies elements from the input byte array into a new byte array, from
* indexes start (inclusive) to end (exclusive). The end index must be less
* than or equal to input.length.
*
* @param input the input byte array
* @param start the start index
* @param end the end index
* @return a new array containing elements from the input byte array
*/
byte[] copyByteArray(byte[] input, int start, int end);
/**
* Gets an instance of {@link DecimalFormatSymbols} for a locale.
*
* @param locale the locale
* @return a new instance of {@link DecimalFormatSymbols}
*/
DecimalFormatSymbols getDecimalFormatSymbols(Locale locale);
}
@@ -25,6 +25,8 @@ import android.util.Log;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.DecimalFormatSymbols;
import java.util.Locale;
/**
* The Cupcake (API level 3) specific implementation of the
@@ -79,4 +81,17 @@ public class CupcakePlatformAdapter implements ApiPlatformAdapter {
public void enableStrictMode() {
// Not supported
}
@Override
public byte[] copyByteArray(byte[] input, int start, int end) {
int length = end - start;
byte[] output = new byte[length];
System.arraycopy(input, start, output, 0, length);
return output;
}
@Override
public DecimalFormatSymbols getDecimalFormatSysmbols(Locale locale) {
return new DecimalFormatSymbols(locale);
}
}
@@ -18,7 +18,6 @@ package com.google.android.apps.mytracks.util;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.SharedPreferences.Editor;
/**
* The Eclair (API level 5) specific implementation of the
@@ -26,7 +25,7 @@ import android.content.SharedPreferences.Editor;
*
* @author Bartlomiej Niechwiej
*/
public class EclairPlatformAdapter implements ApiPlatformAdapter {
public class EclairPlatformAdapter extends CupcakePlatformAdapter {
@Override
public void startForeground(Service service,
@@ -40,14 +39,4 @@ public class EclairPlatformAdapter implements ApiPlatformAdapter {
NotificationManager notificationManager, int id) {
service.stopForeground(id != -1);
}
@Override
public void applyPreferenceChanges(Editor editor) {
editor.commit();
}
@Override
public void enableStrictMode() {
// Not supported
}
}
@@ -6,6 +6,10 @@ import android.content.SharedPreferences.Editor;
import android.os.StrictMode;
import android.util.Log;
import java.text.DecimalFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
/**
* The Gingerbread (API level 9) specific implememntation of the
* {@link ApiPlatformAdapter}.
@@ -13,6 +17,7 @@ import android.util.Log;
* @author Rodrigo Damazio
*/
public class GingerbreadPlatformAdapter extends EclairPlatformAdapter {
@Override
public void applyPreferenceChanges(Editor editor) {
// Apply asynchronously
@@ -32,4 +37,14 @@ public class GingerbreadPlatformAdapter extends EclairPlatformAdapter {
.penaltyLog()
.build());
}
@Override
public byte[] copyByteArray(byte[] input, int start, int end) {
return Arrays.copyOfRange(input, start, end);
}
@Override
public DecimalFormatSymbols getDecimalFormatSysmbols(Locale locale) {
return DecimalFormatSymbols.getInstance(locale);
}
}