forked from upstream-mirrors/OpenTracks
Refactor platform adapter logic
This commit is contained in:
@@ -71,9 +71,7 @@ public class ApiFeatures {
|
|||||||
apiPlatformAdapter = createPlatformAdapter(PLATFORM_ADAPTER_GINGERBREAD);
|
apiPlatformAdapter = createPlatformAdapter(PLATFORM_ADAPTER_GINGERBREAD);
|
||||||
} else if (getApiLevel() >= 5) {
|
} else if (getApiLevel() >= 5) {
|
||||||
apiPlatformAdapter = createPlatformAdapter(PLATFORM_ADAPTER_ECLAIR);
|
apiPlatformAdapter = createPlatformAdapter(PLATFORM_ADAPTER_ECLAIR);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (apiPlatformAdapter == null) {
|
|
||||||
// Cupcake adapter is always supported, so it's safe to do static linkage.
|
// Cupcake adapter is always supported, so it's safe to do static linkage.
|
||||||
apiPlatformAdapter = new CupcakePlatformAdapter();
|
apiPlatformAdapter = new CupcakePlatformAdapter();
|
||||||
}
|
}
|
||||||
@@ -81,13 +79,16 @@ public class ApiFeatures {
|
|||||||
Log.i(MyTracksConstants.TAG, "Using platform adapter " + apiPlatformAdapter.getClass());
|
Log.i(MyTracksConstants.TAG, "Using platform adapter " + apiPlatformAdapter.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiPlatformAdapter createPlatformAdapter(String className) {
|
private static ApiPlatformAdapter createPlatformAdapter(String className) {
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = Class.forName(className);
|
Class<?> clazz = Class.forName(className);
|
||||||
return (ApiPlatformAdapter) clazz.newInstance();
|
return (ApiPlatformAdapter) clazz.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (ClassNotFoundException e) {
|
||||||
Log.i(MyTracksConstants.TAG, "ApiFeatures: Unable to instantiate " + className, e);
|
throw new RuntimeException("ApiFeatures: Unable to find " + className, e);
|
||||||
return null;
|
} catch (InstantiationException e) {
|
||||||
|
throw new RuntimeException("ApiFeatures: Unable to instantiate " + className, e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
throw new RuntimeException("ApiFeatures: Unable to access " + className, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user