Fixed bug I introduced depending on later API.
Also added utility method to make checking a bit easier, and removed reference to SDK from DB (it mentioned in the comments that SDK_INT was only available in v5, but the Android docs say it was introduced in v4. Because FDroid now depends on the Android support library, which in turn depends on v4, it sould be okay to depen on this.
This commit is contained in:
parent
8dd337f345
commit
f4abb6389c
@ -249,7 +249,11 @@ public class AppDetails extends ListActivity {
|
||||
resetRequired = false;
|
||||
}
|
||||
resetViews();
|
||||
|
||||
if (Utils.hasApi(11)) {
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
if (downloadHandler != null) {
|
||||
downloadHandler.startUpdates();
|
||||
}
|
||||
|
@ -278,28 +278,23 @@ public class DB {
|
||||
// check if an APK is compatible with the user's device.
|
||||
public static abstract class CompatibilityChecker {
|
||||
|
||||
// Because Build.VERSION.SDK_INT requires API level 5
|
||||
@SuppressWarnings("deprecation")
|
||||
protected final static int SDK_INT = Integer
|
||||
.parseInt(Build.VERSION.SDK);
|
||||
|
||||
public abstract boolean isCompatible(Apk apk);
|
||||
|
||||
public static CompatibilityChecker getChecker(Context ctx) {
|
||||
CompatibilityChecker checker;
|
||||
if (SDK_INT >= 5)
|
||||
if (Utils.hasApi(5))
|
||||
checker = new EclairChecker(ctx);
|
||||
else
|
||||
checker = new BasicChecker();
|
||||
Log.d("FDroid", "Compatibility checker for API level "
|
||||
+ SDK_INT + ": " + checker.getClass().getName());
|
||||
+ Utils.getApi() + ": " + checker.getClass().getName());
|
||||
return checker;
|
||||
}
|
||||
}
|
||||
|
||||
private static class BasicChecker extends CompatibilityChecker {
|
||||
public boolean isCompatible(Apk apk) {
|
||||
return (apk.minSdkVersion <= SDK_INT);
|
||||
return (apk.minSdkVersion <= Utils.getApi());
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,7 +324,7 @@ public class DB {
|
||||
}
|
||||
|
||||
public boolean isCompatible(Apk apk) {
|
||||
if (apk.minSdkVersion > SDK_INT)
|
||||
if (apk.minSdkVersion > Utils.getApi())
|
||||
return false;
|
||||
if (apk.features != null) {
|
||||
for (String feat : apk.features) {
|
||||
|
@ -256,7 +256,7 @@ public class FDroid extends FragmentActivity {
|
||||
}
|
||||
|
||||
private void createTabs() {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
if (Utils.hasApi(11)) {
|
||||
createActionBarTabs();
|
||||
} else {
|
||||
createOldTabs();
|
||||
@ -264,7 +264,7 @@ public class FDroid extends FragmentActivity {
|
||||
}
|
||||
|
||||
private void selectTab(int index) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
if (Utils.hasApi(11)) {
|
||||
getActionBar().setSelectedNavigationItem(index);
|
||||
} else {
|
||||
tabHost.setCurrentTab(index);
|
||||
@ -274,7 +274,7 @@ public class FDroid extends FragmentActivity {
|
||||
public void refreshUpdateTabLabel() {
|
||||
final int INDEX = 2;
|
||||
CharSequence text = viewPager.getAdapter().getPageTitle(INDEX);
|
||||
if ( Build.VERSION.SDK_INT >= 11) {
|
||||
if (Utils.hasApi(11)) {
|
||||
getActionBar().getTabAt(INDEX).setText(text);
|
||||
} else {
|
||||
// Update the count on the 'Updates' tab to show the number available.
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
package org.fdroid.fdroid;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
@ -52,4 +54,12 @@ public final class Utils {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasApi(int apiLevel) {
|
||||
return Build.VERSION.SDK_INT >= apiLevel;
|
||||
}
|
||||
|
||||
public static int getApi() {
|
||||
return Build.VERSION.SDK_INT;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user